9#ifndef __HISTORY_H_INCLUDED__
10#define __HISTORY_H_INCLUDED__
12#include "HistoryBase.hpp"
13#include "demographic_policy.hpp"
28template <
typename Space,
typename DispersalPolicy,
typename MemoryPolicy>
40template <
typename Space,
typename Memory>
41class History<Space, demographic_policy::individual_based, Memory>
42 :
public HistoryBase<Space, demographic_policy::individual_based, Memory>
67 template <
typename T,
typename U,
typename V>
void simulate_forward(T sim_growth, U kernel, V &gen)
71 unsigned int landscape_individuals_count = 0;
74 auto N_tilde = sim_growth(gen, x, t);
75 landscape_individuals_count += N_tilde;
78 for (
unsigned int ind = 1; ind <= N_tilde; ++ind)
80 auto y = kernel(gen, x);
81 this->m_flows->add_to_flow_from_to(x, y, t, 1);
86 if (landscape_individuals_count == 0)
88 throw std::domain_error(
"Landscape populations went extinct before sampling");
99template <
typename Space,
typename Memory>
100class History<Space, demographic_policy::mass_based, Memory>
101 :
public HistoryBase<Space, demographic_policy::mass_based, Memory>
127 template <
typename T,
typename U,
typename V>
void simulate_forward(T sim_growth, U kernel, V &gen)
131 unsigned int landscape_individuals_count = 0;
134 auto N_tilde = sim_growth(gen, x, t);
135 for (
auto const &y : kernel.arrival_space(x))
137 auto m = kernel(x, y);
138 assert(m >= 0.0 && m <= 1.0);
140 double nb_migrants = std::ceil(m *
static_cast<double>(N_tilde));
141 if (nb_migrants >= 0)
143 landscape_individuals_count += nb_migrants;
144 this->m_flows->set_flow_from_to(x, y, t, nb_migrants);
145 this->
pop_size(y, t + 1) += nb_migrants;
149 if (landscape_individuals_count == 0)
151 throw std::domain_error(
"Landscape populations went extinct before sampling");
Base class for simulating and recording spatial population history, encpasulating backward migration ...
Definition HistoryBase.hpp:40
auto & pop_size(coord_type const &x, time_type const &t)
Population size at deme x at time t.
Definition HistoryBase.hpp:83
auto distribution_area(time_type t) const
Retrieve demes where N > 0 at time t.
Definition HistoryBase.hpp:74
unsigned int const & nb_generations() const
Last time recorded in the foward-in-time database history.
Definition HistoryBase.hpp:112
void simulate_forward(T sim_growth, U kernel, V &gen)
Expands the demographic database.
Definition History.hpp:67
void simulate_forward(T sim_growth, U kernel, V &gen)
Simulate forward the demographic history.
Definition History.hpp:127
Unspecialized class (CRTP design pattern)
Definition History.hpp:30
Policy class to specialize the quetzal::demography::History class for expansion of populations with v...
Definition demographic_policy.hpp:40
Policy class to specialize the quetzal::demography::History class for simulation of population with l...
Definition demographic_policy.hpp:207
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21