44 mutable std::pair<Time, Time> m_RAM_window = {0, 1};
46 mutable std::unordered_map<Time, std::unordered_map<Space, Value>> m_populations;
50 using time_type =
Time;
52 using coord_type =
Space;
54 using value_type =
Value;
62 void set(coord_type
const &
x, time_type
const &t, value_type N)
65 slide_RAM_window_to(t);
66 m_populations[t][
x] = N;
73 value_type &
operator()(coord_type
const &
x, time_type
const &t)
75 slide_RAM_window_to(t);
76 return m_populations[t][
x];
81 value_type
get(coord_type
const &
x, time_type
const &t)
const
83 slide_RAM_window_to(t);
85 return m_populations.at(t).at(
x);
91 value_type
operator()(coord_type
const &
x, time_type
const &t)
const
101 slide_RAM_window_to(t);
102 std::vector<coord_type>
v;
103 for (
auto const &
it : m_populations.at(t))
107 v.push_back(
it.first);
119 return (!m_populations.empty()) && (m_populations.find(t) != m_populations.end()) &&
120 (m_populations.at(t).find(
x) != m_populations.at(t).end());
124 std::string get_archive_name(time_type t)
const
126 const std::string
prefix =
"N-";
127 const std::string
extension =
".archive";
131 void serialize_layer(time_type t)
const
133 const std::string
filename = get_archive_name(t);
137 boost::archive::binary_oarchive
oa(
ofs);
139 oa << m_populations.at(t);
141 m_populations.erase(t);
144 void deserialize_layer(time_type t)
const
146 std::string
filename = get_archive_name(t);
149 boost::archive::binary_iarchive
ia(
ifs);
151 std::unordered_map<Space, Value> layer;
154 m_populations[t] = layer;
157 void slide_RAM_window_to(time_type t)
const
160 if (t == m_RAM_window.first || t == m_RAM_window.second)
166 else if (t == m_RAM_window.second + 1)
169 serialize_layer(m_RAM_window.first);
171 m_RAM_window.first += 1;
172 m_RAM_window.second += 1;
176 deserialize_layer(m_RAM_window.second);
178 catch (
const std::exception &
e)
184 else if (t == m_RAM_window.first - 1)
187 serialize_layer(m_RAM_window.second);
189 deserialize_layer(m_RAM_window.first - 1);
191 m_RAM_window.first -= 1;
192 m_RAM_window.second -= 1;
198 serialize_layer(m_RAM_window.first);
199 serialize_layer(m_RAM_window.second);
203 m_RAM_window.first = 0;
204 m_RAM_window.second = 1;
208 m_RAM_window.first = t - 1;
209 m_RAM_window.second = t;
212 deserialize_layer(m_RAM_window.first);
213 deserialize_layer(m_RAM_window.second);
void set(coord_type const &x, time_type const &t, value_type N)
Set population size value at deme x at time t.
Definition PopulationSizeOnDiskImplementation.hpp:62