1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
template<typename Space, typename Time, typename Value>
class Demography
{
public:
using coord_type = Space;
using time_type = Time;
using N_type = Value;
using value_type = double;
Demography(Coords const& x0, N_type N0, time_type t0){
populations[t0][x0] = N0;
}
time_type begin_time() const {
return populations.begin()->first;
}
time_type end_time() const {
return (--(populations.end()))->first;
}
std::vector<coord_type> inhabited_demes(time_type time) const {
std::vector<coord_type> v;
if(populations.find( time ) != populations.end()){ // return empty vector if time not found
for(auto const& it : populations.at(time) ){
v.push_back(it.first);
}
}
return v;
}
value_type operator()(coord_type const& x, time_type t) const {
return pop_size(x,t);
}
N_type pop_size(coord_type const& where, time_type time) const {
return populations.at(time).at(where);
}
N_type& pop_size(coord_type const& where, time_type time) {
return populations[time][where];
}
N_type flux_from_to(coord_type const& from, coord_type const& to, time_type time) const {
return flux.at(time).at(to).at(from);
}
N_type& flux_from_to(coord_type const& from, coord_type const& to, time_type time){
return flux[time][to][from];
}
std::unordered_map<coord_type, N_type> const& flux_to(coord_type const& to, time_type time) const {
return flux.at(time).at(to);
}
private:
template<typename coord_type, typename time_type, typename N_type>
friend std::ostream& operator <<(std::ostream& Stream, Demography<coord_type, time_type, N_type> const& demo);
// period//to_deme/from_deme
std::map<time_type,
std::unordered_map<coord_type,
std::unordered_map<coord_type, N_type> > > flux;
// period / deme / size
std::map<time_type, std::unordered_map<coord_type, N_type> > populations;
}; |
Partager