tekka
population.hpp
Go to the documentation of this file.
1
4#pragma once
5#ifndef PBT_POPULATION_HPP_
6#define PBT_POPULATION_HPP_
7
8#include "random_fwd.hpp"
9
10#include <cstdint>
11#include <iosfwd>
12#include <vector>
13#include <map>
14#include <memory>
15
17
18namespace pbf {
19
20class Individual;
21
25 public:
27 Population(const size_t initial_size, std::random_device::result_type seed,
28 const double carrying_capacity = 1e3,
29 const double recruitment_coef = 2.0,
30 const double negative_binom_k = -1.0);
32
34 void run(const int_fast32_t simulating_duration,
35 const std::vector<size_t>& sample_size_adult={1u, 1u},
36 const std::vector<size_t>& sample_size_juvenile={1u,1u},
37 const int_fast32_t recording_duration=1);
38
42 std::ostream& write_sample_family(std::ostream& ost) const;
44 std::ostream& write_demography(std::ostream&) const;
46 std::ostream& write(std::ostream&) const;
47 friend std::ostream& operator<<(std::ostream&, const Population&);
48
49 private:
51 void reproduce();
52
57 void reproduce(uint_fast32_t location, size_t popsize);
58
60 void survive(int_fast32_t season);
61
63 void migrate();
64
66 void sample(std::vector<std::vector<std::shared_ptr<Individual>>>* subpops,
67 const std::vector<size_t>& sample_sizes);
68
70 void append_demography(int_fast32_t season);
71
73 std::vector<std::vector<uint_fast32_t>> count(int_fast32_t season) const;
74
76 size_t num_subpops() const noexcept {return subpopulations_.size();}
77
79 std::vector<std::vector<std::shared_ptr<Individual>>> subpopulations_;
82 std::vector<std::vector<std::shared_ptr<Individual>>> juveniles_subpops_;
84 std::vector<std::vector<uint_fast32_t>> juveniles_demography_ = {};
86 std::vector<std::map<int_fast32_t, std::vector<std::shared_ptr<Individual>>>> loc_year_samples_ = {};
88 std::map<std::pair<int_fast32_t, int_fast32_t>, std::vector<std::vector<uint_fast32_t>>> demography_ = {};
89
92
94 const double carrying_capacity_;
96 const double recruitment_coef_;
99 const double k_nbinom_;
102 int_fast32_t year_ = 0;
104 std::unique_ptr<URBG> engine_;
105};
106
107} // namespace pbf
108
109#endif /* PBT_POPULATION_HPP_ */
Population class.
Definition population.hpp:24
void reproduce()
give birth to children
Definition population.cpp:81
std::unique_ptr< URBG > engine_
Uniform Random Bit Generator.
Definition population.hpp:104
std::vector< std::vector< uint_fast32_t > > juveniles_demography_
Counts of juveniles of the year: [[number for each location] for each season].
Definition population.hpp:84
std::vector< std::vector< std::shared_ptr< Individual > > > subpopulations_
Individual array for each subpopulation.
Definition population.hpp:79
Population(const size_t initial_size, std::random_device::result_type seed, const double carrying_capacity=1e3, const double recruitment_coef=2.0, const double negative_binom_k=-1.0)
Constructor.
Definition population.cpp:14
void migrate()
Evaluate migration. Individuals in juveniles_subpops_ moves to subpopulations_.
Definition population.cpp:154
int_fast32_t year_
Definition population.hpp:102
std::ostream & write(std::ostream &) const
Write subpopulations_ and juveniles_subpops_ for debugging.
Definition population.cpp:270
std::vector< std::vector< std::shared_ptr< Individual > > > juveniles_subpops_
Definition population.hpp:82
void survive(int_fast32_t season)
Evaluate survival.
Definition population.cpp:139
void append_demography(int_fast32_t season)
Append current state to demography_.
Definition population.cpp:244
std::map< std::pair< int_fast32_t, int_fast32_t >, std::vector< std::vector< uint_fast32_t > > > demography_
(year, season) => [[count for each age] for each location]
Definition population.hpp:88
size_t num_subpops() const noexcept
Return size of subpopulations_.
Definition population.hpp:76
std::ostream & write_sample_family(std::ostream &ost) const
Definition population.cpp:204
void run(const int_fast32_t simulating_duration, const std::vector< size_t > &sample_size_adult={1u, 1u}, const std::vector< size_t > &sample_size_juvenile={1u, 1u}, const int_fast32_t recording_duration=1)
Main iteration.
Definition population.cpp:32
std::vector< std::map< int_fast32_t, std::vector< std::shared_ptr< Individual > > > > loc_year_samples_
Samples: [{capture_year => individuals} for each location].
Definition population.hpp:86
std::ostream & write_demography(std::ostream &) const
Write demography_.
Definition population.cpp:252
void sample(std::vector< std::vector< std::shared_ptr< Individual > > > *subpops, const std::vector< size_t > &sample_sizes)
Sample individuals.
Definition population.cpp:188
friend std::ostream & operator<<(std::ostream &, const Population &)
Shortcut for Population::write(ost)
Definition population.cpp:281
std::vector< std::vector< uint_fast32_t > > count(int_fast32_t season) const
Count individuals for each location and age.
Definition population.cpp:227
const double recruitment_coef_
: coefficient used in reproduce()
Definition population.hpp:96
const double k_nbinom_
Definition population.hpp:99
const double carrying_capacity_
: carrying capacity used in reproduce()
Definition population.hpp:94