5#ifndef PBT_INDIVIDUAL_HPP_
6#define PBT_INDIVIDUAL_HPP_
8#include "random_fwd.hpp"
14#include <unordered_map>
29 void read(std::istream&);
31 std::ostream&
write(std::ostream&)
const;
62 const std::shared_ptr<Individual>& mother,
63 int_fast32_t year,
bool is_male) noexcept
70 double death_rate(
const int_fast32_t year,
const int_fast32_t season)
const {
71 const auto q_age = 4 *
age(year) + season;
76 uint_fast32_t
migrate(uint_fast32_t loc, int_fast32_t year, URBG&);
79 void trace_back(std::ostream& ost, std::unordered_map<const Individual*, uint_fast32_t>* ids,
80 uint_fast32_t loc, int_fast32_t year)
const;
82 std::ostream&
write(std::ostream&)
const;
84 std::ostream&
write(std::ostream&,
const std::unordered_map<const Individual*, uint_fast32_t>&)
const;
92 constexpr static inline int_fast32_t
MAX_AGE = 80;
98 static bool is_ready(
const uint_fast32_t years) {
108 static double DEATH_RATE(
const int_fast32_t q_age,
const int_fast32_t year) {
111 return 1.0 - std::exp(-m - f);
118 int_fast32_t
age(
const int_fast32_t year)
const noexcept {
122 double weight(int_fast32_t year)
const noexcept {
131 using PairDestDist=std::pair<int_fast32_t, std::discrete_distribution<uint_fast32_t>>;
146 const std::shared_ptr<Individual>
father_ =
nullptr;
148 const std::shared_ptr<Individual>
mother_ =
nullptr;
Individual class.
Definition individual.hpp:54
Individual(bool is_male) noexcept
for initial population
Definition individual.hpp:59
Individual()=delete
Alias.
static std::ostream & write_names(std::ostream &)
Write column names for write()
Definition individual.cpp:70
double death_rate(const int_fast32_t year, const int_fast32_t season) const
Finite death rate per quarter year: .
Definition individual.hpp:70
static std::vector< double > FISHING_COEF_
Fluctuation of fishing mortality by year.
Definition individual.hpp:139
static IndividualJson JSON
Parameters shared among instances (JSON file).
Definition individual.hpp:94
uint_fast32_t migrate(uint_fast32_t loc, int_fast32_t year, URBG &)
Generate random number for new location.
Definition individual.cpp:48
Individual(const std::shared_ptr< Individual > &father, const std::shared_ptr< Individual > &mother, int_fast32_t year, bool is_male) noexcept
for sexual reproduction
Definition individual.hpp:61
std::ostream & write(std::ostream &) const
Write all the data members in TSV.
Definition individual.cpp:77
static std::vector< std::vector< PairDestDist > > MIGRATION_DESTINATION_
Discrete distributions for migration.
Definition individual.hpp:143
static void set_static_migration()
Prepare MIGRATION_DESTINATION_.
Definition individual.cpp:96
const std::shared_ptr< Individual > mother_
Pointer to mother.
Definition individual.hpp:148
static void set_static_weight()
Prepare WEIGHT_FOR_AGE_.
Definition individual.cpp:117
int_fast32_t age(const int_fast32_t year) const noexcept
Age in the given year.
Definition individual.hpp:118
static double DEATH_RATE(const int_fast32_t q_age, const int_fast32_t year)
Finite death rate per quarter year.
Definition individual.hpp:108
int_fast32_t birth_year_
Year of birth.
Definition individual.hpp:150
static constexpr int_fast32_t MAX_AGE
No individual lives longer than this.
Definition individual.hpp:92
friend std::ostream & operator<<(std::ostream &, const Individual &)
Shortcut of Individual::write.
Definition individual.cpp:92
const bool is_male_
Sex.
Definition individual.hpp:152
bool is_male() const noexcept
Just returns is_male_.
Definition individual.hpp:126
static bool is_ready(const uint_fast32_t years)
Test if static variables are ready.
Definition individual.hpp:98
static void set_dependent_static(const uint_fast32_t years)
Set static variables that depend on others.
Definition individual.cpp:126
static std::ostream & write_trace_back_header(std::ostream &)
Write column names for trace_back()
Definition individual.cpp:66
static void set_static_mortality()
Prepare mortality vectors.
Definition individual.cpp:111
const std::shared_ptr< Individual > father_
Pointer to father.
Definition individual.hpp:146
static std::vector< double > WEIGHT_FOR_AGE_
year version of IndividualJson::weight_for_age
Definition individual.hpp:141
double weight(int_fast32_t year) const noexcept
Weight for year age.
Definition individual.hpp:122
std::pair< int_fast32_t, std::discrete_distribution< uint_fast32_t > > PairDestDist
Alias for readability.
Definition individual.hpp:131
void trace_back(std::ostream &ost, std::unordered_map< const Individual *, uint_fast32_t > *ids, uint_fast32_t loc, int_fast32_t year) const
Write ancestors recursively.
Definition individual.cpp:53
Parameters for Individual class (JSON file)
Definition individual.hpp:23
void read(std::istream &)
Read class variables from stream in json.
Definition individual.cpp:142
std::vector< std::vector< double > > RowMatrix
Alias for readability.
Definition individual.hpp:34
std::ostream & write(std::ostream &) const
Write class variables to stream in json.
Definition individual.cpp:152
IndividualJson()
Constructor.
Definition individual.cpp:137
std::vector< RowMatrix > migration_matrices
Transition matrix for migration.
Definition individual.hpp:48
std::vector< double > fishing_mortality
Array of for quarter age: instantaneous mortality due to fishing activities.
Definition individual.hpp:41
std::vector< double > fishing_coef
Definition individual.hpp:44
std::vector< double > weight_for_age
Weight in kg for quarter age.
Definition individual.hpp:46
std::vector< double > natural_mortality
Array of for quarter age: instantaneous mortality due to natural causes.
Definition individual.hpp:39