Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
Metapop Class Reference

Top class of the metapopulation structure, contains the patches. More...

#include <metapop.h>

+ Inheritance diagram for Metapop:
+ Collaboration diagram for Metapop:

Public Member Functions

 Metapop ()
 
virtual ~Metapop ()
 
bool init ()
 Inits the population parameters from the ParamSet and builds the pop (adds patches), the prototypes and the life cycle. More...
 
virtual bool setParameters ()
 
bool setPopulationParameters ()
 Population's size parameters initializing procedure. More...
 
bool setSourceParameters ()
 Setter for source population parameters. More...
 
bool updatePopulationParameters ()
 Called during simulation to change the population's parameters (temporal argument). More...
 
void reset ()
 Called to empty the patches, individuals are move to the garbage collector. More...
 
void clear ()
 Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are destroyed. More...
 
void setMPImanager (MPImanager *mgr)
 
void store_trait (int trait_idx, BinaryStorageBuffer *saver)
 Iterates through the individuals containers to store the trait data to a binary file. More...
 
void read_trait (int trait_idx, BinaryStorageBuffer *loader)
 Iterates through the individuals containers to retrieve the trait data from a binary file. More...
 
void show_up ()
 
Population builders
void resizePatchArray ()
 Resets the patch container to the right number of patches as set by _patchNbr. More...
 
void buildPatchArray ()
 Builds the new population from parameter values. More...
 
void updatePatchArray ()
 Called during simulation to modify the meta-population size. More...
 
void updatePatchState ()
 Update the patch capacities and patch ID (reset to array position). More...
 
void setPatchCapacities ()
 Sets the deme capacity matrix from parameter values. More...
 
void setPatchCapacities (string param)
 Builds the new population from a single matrix of deme sizes. More...
 
void setPatchCapacities (sex_t SEX, string param)
 Builds the new population from a matrix of deme sizes but for one sex only. More...
 
void setPatchCapacities (string paramfem, string parammal)
 Builds the new population from matrices of deme sizes. More...
 
void loadSourcePopulation ()
 Loads a population from a soure population. More...
 
void loadPopFromBinarySource (string &filename)
 Loads the population from a binary data file when setting the first generation of a replicate. More...
 
void loadPopFromTraitFile (string &filename)
 Loads a population from a trait's data file (text file). More...
 
void setPopulation (unsigned int currentReplicate, unsigned int replicates)
 Sets the population for the first generation of each replicates. More...
 
void setPopulationFromSourceInPreserveMode ()
 
void setPopulationFromSource ()
 
void fillPopulationFromSource (age_idx AGE, sex_t SEX, deque< Individual * > &src_pool)
 Fills the population of the first generation of each replicates with individuals from a population source. More...
 
void fillPatchFromSource (sex_t SEX, Patch *src, Patch *patch, age_t AGE)
 Fills a patch from a source patch loaded from a binary file, used when setting the population in preserve mode. More...
 
Implementations
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
virtual void store_data (BinaryStorageBuffer *saver)
 
virtual bool retrieve_data (BinaryStorageBuffer *reader)
 
Getters
PatchgetPatch (unsigned int i)
 Patch accessor, return the ith+1 patch in the metapop. More...
 
PatchgetPatchPtr (unsigned int patch)
 A secure version of the getPatch() method. More...
 
deque< Patch * > * getPatchArray ()
 
unsigned int getPatchArraySize ()
 
void getAllIndividuals (age_idx AGE, deque< Individual * > &fem_pool, deque< Individual * > &mal_pool)
 
void setGenerations (unsigned int gen)
 
unsigned int getGenerations ()
 
void setReplicates (unsigned int repl)
 
unsigned int getReplicates ()
 
unsigned int getPatchNbr ()
 
unsigned int getPatchKFem ()
 
unsigned int getPatchKMal ()
 
unsigned int getPatchCapacity ()
 
unsigned int getPatchCapacity (sex_t SEX, unsigned int patch)
 
TMatrixgetPatchCapacities ()
 
bool isSourceLoad ()
 
string getSourceName ()
 
string getSourceFileType ()
 
unsigned int getSourceReplDigits ()
 
void setPatchNbr (unsigned int val)
 
void setPatchSizes (TMatrix &mat)
 
unsigned int getNumAgeClasses ()
 
Population state interface
unsigned int getCurrentReplicate ()
 
unsigned int getCurrentGeneration ()
 
void setCurrentReplicate (unsigned int repl)
 
void setCurrentGeneration (unsigned int gen)
 
age_t getCurrentAge ()
 
void setCurrentAge (age_t age)
 Sets the age flag. More...
 
void setCurrentAge (LifeCycleEvent *LCE)
 Set the age flag from a LifeCycleEvent object. More...
 
bool isAlive ()
 Checks if the population still contains at least one individual in any sex or age class. More...
 
unsigned int size ()
 Get the total number of individuals present in the population, all sex and age classes together. More...
 
unsigned int size (sex_t SEX, age_t AGE)
 Interface to get the size of a praticular age and sex class(es). More...
 
unsigned int size (sex_t SEX, age_idx IDX)
 Interface to get the size of a praticular age class and sex class. More...
 
unsigned int size (age_idx IDX)
 Returns the size of the container for the appropriate age class for both sexes. More...
 
unsigned int size (age_idx IDX, unsigned int deme)
 
unsigned int size (sex_t SEX, age_idx IDX, unsigned int deme)
 
unsigned int size (sex_t SEX, age_t AGE, unsigned int deme)
 Interface to get the size of a praticular age and sex class within a patch. More...
 
unsigned int size (age_t AGE)
 Simplified interface to get the size of both sexes of the appropriate age class(es) in the whole population. More...
 
unsigned int size (age_t AGE, unsigned int deme)
 Simplified interface to get the size of both sexes of the appropriate age class(es) in one patch. More...
 
Individualget (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
 Returns a pointer to the appropriate individual. More...
 
void move (sex_t SEX, age_idx from_age, unsigned int from_deme, age_idx to_age, unsigned int to_deme, unsigned int at)
 Moves an individual from a deme to an other one, both demes sizes are modified. More...
 
void flush ()
 Removes all individual pointers and flush them into the recycling pool. More...
 
void flush (sex_t SEX, age_idx AGE)
 Removes all individual pointers of the appropriate sex and age class and flush them into the recycling pool. More...
 
void flush (age_idx AGE)
 Removes all individual pointers of both sexes and specified age class and flush them into the recycling pool. More...
 
void flush (age_t AGE)
 Removes all individual pointers of both sexes and specified age class(es) and flush them into the recycling pool. More...
 
PatchremovePatch (unsigned int i)
 Removes a patch from the patch array and returns it pointer. More...
 
void deletePatch (unsigned int i)
 Removes a patch from the patch array and deletes it and its content. More...
 
void addPatch (Patch *patch)
 Adds a patch to the population. More...
 
void addPatch (unsigned int num)
 Adds num patches to the population. More...
 
- Public Member Functions inherited from StorableComponent
virtual ~StorableComponent ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 Sets a new ParamSet and name it. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 
virtual bool has_parameter (std::string name)
 Param getter. More...
 
- Public Member Functions inherited from IndFactory
 IndFactory ()
 
virtual ~IndFactory ()
 
void recycle (Individual *ind)
 Put an individual in the recycling pool. More...
 
void purgeRecyclingPOOL ()
 Empty the recycling pool. More...
 
void makePrototype (map< trait_t, TraitPrototype * > TTlist)
 Creates the individuals prototype from the selected trait prototypes. More...
 
void clearPrototype ()
 Reset the trait prototypes, mostly done to unregister the genetic maps. More...
 
IndividualgetPrototypeClone ()
 Return an uninitialized copy of the individual prototype. More...
 
IndividualgetNewIndividual ()
 Creates a blank individual which has to be "decorated" later. More...
 
IndividualmakeNewIndividual (Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
 Creates an individual from existing pointer with new ID. More...
 
IndividualdecorateNewIndividual (Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
 Sets the internals of a new individual with pointers to parents, sex and home ID set. More...
 
IndividualmakeNewIndividual (Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
 Creates an individual with pointers to parents, sex and home ID set but no genetic data. More...
 
IndividualmakeOffsprg (Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
 Completely creates an individual with inheritance and mutations on all traits. More...
 
IndividualgetIndividualProtoype ()
 Individual prototype accessor. More...
 
TraitPrototypegetTraitPrototype (trait_t type)
 Accessor to a TraitPrototype. More...
 
std::map< trait_t, TraitPrototype * > & getTraitPrototypes ()
 Accessor to the list of TraitPrototype's. More...
 
int getTraitIndex (trait_t type)
 Gives the index of trait with type. More...
 

Private Attributes

MPImanager_mpimgr
 
MPStatHandler _statHandler
 The stat handler for the population stats. More...
 
MPFileHandler_writer
 The file handler used to save pedigree info. More...
 
deque< Patch * > _vPatch
 The Patch container. More...
 
age_t _requiredAge
 The age class flag that is required to fill the population at the beginning of a replicate. More...
 
unsigned int _patchNbr
 Number of patches in the population. More...
 
unsigned int _patchK
 Patch carrying capacity. More...
 
unsigned int _patchKfem
 Sex specific carrying capacities. More...
 
unsigned int _patchKmal
 
TMatrix _patchSizes
 Matrix of the deme sizes, row 0 for the males, row 1 for the females. More...
 
unsigned int _generations
 Number of generations to iterate. More...
 
unsigned int _replicates
 Number of replicates to iterate. More...
 
unsigned int _currentGeneration
 The current generation in the generation loop, starts at 1. More...
 
unsigned int _currentReplicate
 The current replicate in the replicate loop, starts at 1. More...
 
age_t _currentAge
 The current age class, might be changed by the LCEs. More...
 
binary source loader:
BinaryDataLoader _loader
 A BinaryDataLoader to load a population from a binary data file. More...
 
Metapop_source
 A source population as loaded from a binary data file, used to build a population. More...
 
bool _source_preserve
 Flag to specify the loading mode, true means the source pop is the actual population. More...
 
bool _source_load
 Flage to specify that the population should be built from the binary loaded source population. More...
 
unsigned int _source_replicates
 The number of source files, each file being a different replicate of the source population. More...
 
unsigned int _source_replicate_digits
 Number of digits in the replicate counter filename extension. More...
 
unsigned int _source_start_at_replicate
 The replicate number to start loading from. More...
 
unsigned int _source_generation
 The generation to load from the binary file source file. More...
 
std::string _source_name
 The base filename of source population files. More...
 
std::string _source_filetype
 The trait type to load from. More...
 
std::string _source_required_age
 The age class to fill with the source population. More...
 
unsigned int _source_load_periodicity
 The number of replicates to source from a single source replicate. More...
 
vector< string > _source_param_override
 List of parameters whose values in the source should override local values in the loading pop. More...
 

Friends

MetapopBinaryDataLoader::extractPop (std::string &, unsigned int, SimBuilder *, Metapop *)
 

Additional Inherited Members

- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 
- Protected Attributes inherited from IndFactory
std::map< trait_t, TraitPrototype * > _protoTraits
 Map of the trait prototypes. More...
 
std::map< trait_t, int > _TraitsIndex
 Table containing the index of each trait. More...
 
Individual _protoIndividual
 The individuals prototype used to create any new individual in a simulation. More...
 
std::deque< Individual * > RecyclingPOOL
 Garbage collector for unused Individual's. More...
 

Detailed Description

Top class of the metapopulation structure, contains the patches.

The basic design for the metapopulation structure is a top-down chain of responsibility where the Metapop class takes care of the patches it contains which are themselves concerned by the management of their individual containers. The Individual class is only concerned by the management of its traits. Thereby, a metapopulation can be viewed as an interleaving of containers where one container class takes care of its directly contained class only, without knowledge of the upward container state.

The Metapop class thus implements methods used to manage and get information from the patches, to manage the parameters necessary to build a population and to get the population state information. It also implements the methods used to load a population from different source files.

Population states: given by the number and the position of the individuals (both spatially in demes and temporally in age class containers). The Metapop::_currentAge flag is set according to the age state of the metapopulation. The life cycle events modify that state by moving individuals among individuals containers within the metatpopulation. The Metapop::_currentAge flag can contain the following age class bits as defined in types.h. The OFFSPRNG (=1) age class bit is set whenever the offspring containers are not empty. The ADULTS (=4) age class bit is set whenever the adult containers are not empty. The POSTDISP (=2) age class bit informs about the content of the post-dispersal containers. The ALL (=7) age class is the addition of the previous tags and NONE (=0) is the negation of them. The individual containers are stored in the patches and handled through the Patch class interface. Each age class is represented by two containers, one for the males (index 0) and the other for the females (index 1). These containers are store in a table and are accessed through their age class index as defined by the age_idx enum (see types.h). These indexes are as follows: The OFFSPRNG age class has index OFFSx = 0, the POSTDISP age class has index PDISPx = 1 and the ADULTS age class has index ADLTx = 2.

Constructor & Destructor Documentation

◆ Metapop()

Metapop::Metapop ( )
54  : _mpimgr(0), _statHandler(), _writer(0),_loader(), _source(0),
59 {
60  set_paramset("population", true, this);
62  add_parameter("patch_capacity",INT,false,false,0,0, upd);
63  add_parameter("patch_nbfem",INT,false,false,0,0, upd);
64  add_parameter("patch_nbmal",INT,false,false,0,0, upd);
65  add_parameter("patch_number",INT,false,false,0,0, upd);
66 
67  add_parameter("pop_output", BOOL, false, false, 0, 0);
68  add_parameter("pop_output_dir", STR, false, false, 0, 0);
69  add_parameter("pop_output_logtime", INT, false, false, 0, 0);
70  add_parameter("pop_output_sample_size", INT, false, false, 0, 0);
71 
73  add_parameter("source_pop",STR,false,false,0,0, upd);
74  add_parameter("source_file_type",STR,false,false,0,0, upd);
75  add_parameter("source_preserve",BOOL,false,false,0,0, upd);
76  add_parameter("source_replicates",INT,false,false,0,0, upd);
77  add_parameter("source_replicate_digit",INT,false,false,0,0, upd);
78  add_parameter("source_start_at_replicate",INT,false,false,0,0, upd);
79  add_parameter("source_generation",INT,false,false,0,0, upd);
80  add_parameter("source_fill_age_class",STR,false,false,0,0, upd);
81  add_parameter("source_parameter_override", STR, false, false, 0, 0, upd);
82 }
MPStatHandler _statHandler
The stat handler for the population stats.
Definition: metapop.h:87
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:102
MPFileHandler * _writer
The file handler used to save pedigree info.
Definition: metapop.h:90
unsigned int _patchKmal
Definition: metapop.h:136
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:107
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:136
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:121
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:132
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:100
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:134
bool _source_load
Flage to specify that the population should be built from the binary loaded source population.
Definition: metapop.h:104
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:128
bool updatePopulationParameters()
Called during simulation to change the population's parameters (temporal argument).
Definition: metapop.cc:255
MPImanager * _mpimgr
Definition: metapop.h:84
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:143
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:109
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:148
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:151
BinaryDataLoader _loader
A BinaryDataLoader to load a population from a binary data file.
Definition: metapop.h:98
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:113
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:111
bool setSourceParameters()
Setter for source population parameters.
Definition: metapop.cc:123
unsigned int _generations
Number of generations to iterate.
Definition: metapop.h:141
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: metapop.h:146
Implementation of the ParamUpdaterBase interface.
Definition: param.h:362
virtual void set_paramset(ParamSet *paramset)
Sets the ParamSet member.
Definition: simcomponent.h:85
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
#define NONE
No age flag.
Definition: types.h:47
@ BOOL
Definition: types.h:77
@ STR
Definition: types.h:77
@ INT
Definition: types.h:77

References SimComponent::add_parameter(), BOOL, INT, SimComponent::set_paramset(), setSourceParameters(), STR, and updatePopulationParameters().

Referenced by loadPopFromTraitFile().

+ Here is the caller graph for this function:

◆ ~Metapop()

Metapop::~Metapop ( )
virtual
87 {
88 #ifdef _DEBUG_
89  message("Metapop::~Metapop\n");
90 #endif
91  clear();
92 }
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1191
void message(const char *message,...)
Definition: output.cc:39

References clear(), and message().

Member Function Documentation

◆ addPatch() [1/2]

void Metapop::addPatch ( Patch patch)
inline

Adds a patch to the population.

The patch is added at the end of the array and it is empty.

886 {
887  _vPatch.push_back(patch);
888 }
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93

References _vPatch.

Referenced by LCE_Resize::buildNewPatchArrayWithBackup(), FileServices::getSampledPop(), and LCE_Resize::removeDesignatedPatch().

+ Here is the caller graph for this function:

◆ addPatch() [2/2]

void Metapop::addPatch ( unsigned int  num)
inline

Adds num patches to the population.

891 {
892  for (unsigned int i = 0; i < num; i++)
893  _vPatch.push_back(new Patch());
894 }
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431

References _vPatch.

◆ buildPatchArray()

void Metapop::buildPatchArray ( )

Builds the new population from parameter values.

Supernumerary patches are deleted. All patches are empty.

308 {
310 
311  //set the population capacities:
312  for(unsigned int i = 0; i < _patchNbr; ++i) {
313  _vPatch[i]->flush(this);
314  _vPatch[i]->init((unsigned int)_patchSizes.get(FEM,i), (unsigned int)_patchSizes.get(MAL,i), i);
315  }
316 }
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:138
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc:320
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:192
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36

References _patchNbr, _patchSizes, _vPatch, FEM, TMatrix::get(), MAL, and resizePatchArray().

Referenced by BinaryDataLoader::extractPop(), init(), and setPopulation().

+ Here is the caller graph for this function:

◆ clear()

void Metapop::clear ( )

Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are destroyed.

1192 {
1193 #ifdef _DEBUG_
1194  message("Metapop::clear\n");
1195 #endif
1196 
1197  for(unsigned int i = 0; i < _vPatch.size(); ++i)
1198  delete _vPatch[i];
1199 
1200  _vPatch.clear();
1201 
1202  _patchNbr = 0;
1203 
1204  // clean up source metapop only when the source is NOT a binary file
1205  if(_source && _source_filetype != ".bin") {
1206  delete _source;
1207  _source = NULL;
1208  }
1209 
1211 }
void purgeRecyclingPOOL()
Empty the recycling pool.
Definition: indfactory.h:65
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:117

References _patchNbr, _source, _source_filetype, _vPatch, message(), and IndFactory::purgeRecyclingPOOL().

Referenced by SimRunner::Replicate_LOOP(), and ~Metapop().

+ Here is the caller graph for this function:

◆ deletePatch()

void Metapop::deletePatch ( unsigned int  i)
inline

Removes a patch from the patch array and deletes it and its content.


The IDs of the remaining patches are updated.

Parameters
ithe index of the patch to remove.
876 {
877  delete _vPatch[i];
878  for (unsigned int k = i; k < _vPatch.size() -1; k++) {
879  _vPatch[k] = _vPatch[k + 1];
880  _vPatch[k]->setID(k);
881  }
882  _vPatch.pop_back();
883 }

References _vPatch.

Referenced by LCE_Resize::removeDesignatedPatch().

+ Here is the caller graph for this function:

◆ fillPatchFromSource()

void Metapop::fillPatchFromSource ( sex_t  SEX,
Patch src,
Patch patch,
age_t  AGE 
)

Fills a patch from a source patch loaded from a binary file, used when setting the population in preserve mode.

Parameters
SEXsex of the individuals to fetch from the source pop
srcthe source patch that will be copied.
patchthe local patch to be filled with individuals copied from the source patch.
AGEage class to copy individuals from the source.
870 {
871  age_idx in_age = (AGE == OFFSPRG? OFFSx : ADLTx);
872  age_idx to_age = (_requiredAge | AGE? in_age : ADLTx);//this to be sure we load some
873 
874  Individual* new_ind;
875 
876  for(unsigned int j = 0; j < src->size(SEX, in_age); ++j) {
877 
878  new_ind = getNewIndividual(); //this correctly sets pointers to TProto's, and params
879 
880  (*new_ind) = (*src->get(SEX, in_age, j)); //this should only copy genes
881 
882  patch->add(SEX , to_age, new_ind );
883  }
884 }
Individual * getNewIndividual()
Creates a blank individual which has to be "decorated" later.
Definition: indfactory.h:84
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:497
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:533
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it.
Definition: metapop.h:550
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:40
@ OFFSx
Definition: types.h:41
@ ADLTx
Definition: types.h:41

References _requiredAge, Patch::add(), ADLTx, Patch::get(), IndFactory::getNewIndividual(), OFFSPRG, OFFSx, and Patch::size().

Referenced by setPopulationFromSourceInPreserveMode().

+ Here is the caller graph for this function:

◆ fillPopulationFromSource()

void Metapop::fillPopulationFromSource ( age_idx  AGE,
sex_t  SEX,
deque< Individual * > &  src_pool 
)

Fills the population of the first generation of each replicates with individuals from a population source.

Parameters
AGEage of the individuals to fetch from the source pop
SEXsex of the individuals to fetch from the source pop
src_poolthe container where the source individuals will be placed, they are not removed from the source.
936 {
937  unsigned int Ktot = 0;
938  unsigned int ind_pos ;
939  Individual* new_ind;
940 
941  for(unsigned int i = 0; i < _patchNbr; ++i)
942  Ktot += _vPatch[i]->get_K(SEX);
943 
944  if(src_pool.size() < Ktot)
945  warning("Number of %s %s in source metapop (%i) not enough to fill current metapop (%i).\n",
946  (SEX ? "female" : "male"), (AGE == OFFSx ? "offspring" : "adults"),
947  src_pool.size(), Ktot);
948 
949  for(unsigned int i = 0; i < _patchNbr; ++i) {
950 
951  for(unsigned int j = 0, psize = _vPatch[i]->get_K(SEX); j < psize && src_pool.size() != 0; ++j) {
952 
953  new_ind = getNewIndividual();
954 
955  ind_pos = RAND::Uniform( src_pool.size() );
956 
957  _vPatch[i]->add( SEX, AGE, &( (*new_ind) = *(src_pool[ ind_pos ]) ) );
958 
959  src_pool.erase( src_pool.begin() + ind_pos ); //this is without replacement!!!!
960 
961  }
962  }
963 
964 }
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:126
void warning(const char *str,...)
Definition: output.cc:57

References _patchNbr, _vPatch, IndFactory::getNewIndividual(), OFFSx, RAND::Uniform(), and warning().

Referenced by setPopulationFromSource().

+ Here is the caller graph for this function:

◆ flush() [1/4]

void Metapop::flush ( )
inline

Removes all individual pointers and flush them into the recycling pool.

Container sizes are reset to null values.

See also
Patch::flush()
849 {
850  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(this);
851 }
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:848

References _patchNbr, and _vPatch.

Referenced by LCE_Breed::execute(), LCE_Breed_Selection::execute(), LCE_Cross::execute(), LCE_Breed_Quanti::execute(), LCE_Breed_Wolbachia::execute(), flush(), and LCE_Cross::generatePedigree().

+ Here is the caller graph for this function:

◆ flush() [2/4]

void Metapop::flush ( age_idx  AGE)
inline

Removes all individual pointers of both sexes and specified age class and flush them into the recycling pool.

Container sizes are reset to null values.

See also
Patch::flush()
Parameters
AGEthe index of the age class to be flushed
859 {
860  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
861 }

References _patchNbr, _vPatch, and flush().

◆ flush() [3/4]

void Metapop::flush ( age_t  AGE)
inline

Removes all individual pointers of both sexes and specified age class(es) and flush them into the recycling pool.

Container sizes are reset to null values.

See also
Patch::flush()
Parameters
AGEthe age class(es) to be flushed
864 {
865  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
866 }

References _patchNbr, _vPatch, and flush().

◆ flush() [4/4]

void Metapop::flush ( sex_t  SEX,
age_idx  AGE 
)
inline

Removes all individual pointers of the appropriate sex and age class and flush them into the recycling pool.

Container sizes are reset to null values.

See also
Patch::flush()
Parameters
SEXthe sex class of the individual
AGEthe index of the age class to be flushed
854 {
855  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
856 }

References _patchNbr, _vPatch, and flush().

◆ get()

Individual * Metapop::get ( sex_t  SEX,
age_idx  AGE,
unsigned int  at,
unsigned int  deme 
)
inline

Returns a pointer to the appropriate individual.

Parameters
SEXsex class container index
AGEage class container index
atthe index of the individual in its container
demethe patch where to grab the individual
836 { return getPatchPtr(deme)->get(SEX, AGE, at); }
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:259

References Patch::get(), and getPatchPtr().

Referenced by LCE_Cross::create_individual_ancestors(), LCE_NtrlInit::init_allele_freq(), LCE_QuantiInit::init_allele_freq(), LCE_QuantiInit::init_trait_value(), LCE_Init_BDMI::init_value(), move(), read_trait(), store_data(), and store_trait().

+ Here is the caller graph for this function:

◆ getAllIndividuals()

void Metapop::getAllIndividuals ( age_idx  AGE,
deque< Individual * > &  fem_pool,
deque< Individual * > &  mal_pool 
)
1224 {
1225 
1226  for(unsigned int i = 0; i < _vPatch.size(); ++i) {
1227 
1228  for(unsigned int j = 0, psize = _vPatch[i]->size(MAL, AGE); j < psize; ++j)
1229  mal_pool.push_back( _vPatch[i]->get(MAL, AGE, j) );
1230 
1231  for(unsigned int j = 0, psize = _vPatch[i]->size(FEM, AGE); j < psize; ++j)
1232  fem_pool.push_back( _vPatch[i]->get(FEM, AGE, j) );
1233 
1234  }
1235 
1236 }
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311

References _vPatch, FEM, MAL, and size().

Referenced by setPopulationFromSource().

+ Here is the caller graph for this function:

◆ getCurrentAge()

◆ getCurrentGeneration()

◆ getCurrentReplicate()

◆ getGenerations()

unsigned int Metapop::getGenerations ( )
inline
272 {return _generations;}

References _generations.

Referenced by TTQFreqExtractor::FHwrite(), FileServices::getGenerationCounter(), BinaryDataSaver::ifExist(), and BinaryDataSaver::setParameters().

+ Here is the caller graph for this function:

◆ getNumAgeClasses()

unsigned int Metapop::getNumAgeClasses ( )
inline
289 {return 2;}

Referenced by LCE_PhenotypeExpression::execute(), LCE_FileServicesNotifier::setSamplingParameters(), and TTQuantiFH::write_PLINK().

+ Here is the caller graph for this function:

◆ getPatch()

Patch* Metapop::getPatch ( unsigned int  i)
inline

Patch accessor, return the ith+1 patch in the metapop.

256 {return (i > _vPatch.size() -1 ? 0 : _vPatch[i]);}

References _vPatch.

Referenced by LCE_Selection_base::addPhenotypicSD(), LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Breed_Disperse::do_breed_disperse(), LCE_Breed_base::doAgingInWFpop(), LCE_Disperse_EvolDisp::evoldisp(), LCE_BreedAssortativeMating::execute(), LCE_Breed_Disperse::execute(), LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_Disperse_ConstDisp::execute(), LCE_Disperse_EvolDisp::execute(), LCE_Regulation::execute(), LCE_Aging::execute(), LCE_Patch_Extinction::execute(), LCE_Cross::execute(), LCE_PhenotypeExpression::execute(), LCE_QuantiModifier::execute(), LCE_Selection_base::execute(), TTDeletMutBitstrFH::FHread(), TTNeutralGenesFH::FHread(), TTQuantiFH::FHread(), LCE_SelectionFH::FHwrite(), MPFileHandler::FHwrite(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTNOhtaStats::FHwrite(), TTQFreqExtractor::FHwrite(), TTQOhtaStats::FHwrite(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Cross::generatePedigree(), TTDeletMutBitstrSH::getLoad(), LCE_Selection_base::getMaxPatchFitness(), TTDispersalSH::getMeanDispRate(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTWolbachiaSH::getMeanFemaleInfection_perPatch(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanMaleInfection_perPatch(), TTWolbachiaSH::getMeanOffsprgFemaleInfection_perPatch(), TTWolbachiaSH::getMeanOffsprgInfection(), TTWolbachiaSH::getMeanOffsprgMaleInfection_perPatch(), LCE_Selection_base::getMeanPatchFitness(), TTDispersalSH::getOffsprgMeanDispRate(), TTDeletMutBitstrSH::getPatchLoad(), FileServices::getSampledPop(), LCE_Breed_Wolbachia::hasInfectedFemale(), LCE_Breed_Wolbachia::inoculate_wolbachia(), LCE_Disperse_ConstDisp::Migrate(), LCE_Disperse_ConstDisp::MigratePatch(), LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder(), LCE_Disperse_ConstDisp::MigratePatchByNumber(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), GenotyperFH::prepare_data_table(), GenotyperFH::print_genotypes(), GenotyperFH::print_snp_genotypes(), GenotyperFH::print_snp_id(), LCE_Disperse_base::reset_counters(), LCE_Selection_base::set_std_rate_of_change(), TTNeutralGenesSH::setAlleleTables(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTDeletMutBitstrSH::setDeletStats(), TTDeletMutBitstrSH::setFst(), TTNeutralGenesSH::setFstat_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham_bitstring(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), TTWolbachiaSH::setInfectionStats(), TTDeletMutBitstrSH::setMeanViability(), LCE_Selection_base::setScalingFactorForLinearSelection(), TTBDMI_SH::setStats(), TTDeletMutBitstrSH::setViability(), size(), LCE_Disperse_base::swapPostDisp(), LCE_Breed_Wolbachia::wolbachia_model_1(), LCE_Breed_Wolbachia::wolbachia_model_2(), LCE_Breed_base::WrightFisherPopulation(), LCE_Breed_Quanti::WrightFisherPopulation(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_PLINK(), TTQuantiFH::write_PLINK(), TTNeutralGenesFH::write_TAB(), and TTQuantiFH::write_TABLE().

◆ getPatchArray()

deque< Patch* >* Metapop::getPatchArray ( )
inline
268 {return &_vPatch;}

References _vPatch.

◆ getPatchArraySize()

unsigned int Metapop::getPatchArraySize ( )
inline

◆ getPatchCapacities()

TMatrix* Metapop::getPatchCapacities ( )
inline
280 {return &_patchSizes;}

References _patchSizes.

Referenced by FileServices::getSampledPop(), and LCE_Resize::updatePatchCapacities().

+ Here is the caller graph for this function:

◆ getPatchCapacity() [1/2]

unsigned int Metapop::getPatchCapacity ( )
inline
278 {return _patchK;}

References _patchK.

◆ getPatchCapacity() [2/2]

unsigned int Metapop::getPatchCapacity ( sex_t  SEX,
unsigned int  patch 
)
inline
279 {return (unsigned int)_patchSizes.get(SEX, patch);}

References _patchSizes, and TMatrix::get().

◆ getPatchKFem()

unsigned int Metapop::getPatchKFem ( )
inline
276 {return _patchKfem;}

References _patchKfem.

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ getPatchKMal()

unsigned int Metapop::getPatchKMal ( )
inline
277 {return _patchKmal;}

References _patchKmal.

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ getPatchNbr()

unsigned int Metapop::getPatchNbr ( )
inline
275 {return _patchNbr;}

References _patchNbr.

Referenced by TTQuantiSH::addAvgPerPatch(), TTQuantiSH::addCovarPerPatch(), TTDispersalSH::addDispPerPatch(), TTQuantiSH::addEigenPerPatch(), TTQuantiSH::addEigenValuesPerPatch(), TTQuantiSH::addEigenVect1PerPatch(), TTQuantiSH::addGenotPerPatch(), MPStatHandler::addIndNumPerPatch(), LCE_SelectionSH::addMeanPerPatch(), MPStatHandler::addPatchAge(), TTQuantiSH::addQuanti(), TTQuantiSH::addSkewPerPatch(), TTBDMI_SH::addStats(), LCE_SelectionSH::addVarPerPatch(), TTQuantiSH::addVarPerPatch(), TTNeutralGenesSH::allocateTables(), LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Resize::buildNewPatchArrayWithBackup(), LCE_Breed_Disperse::do_breed_disperse(), LCE_Breed_base::doAgingInWFpop(), LCE_Breed::execute(), LCE_BreedAssortativeMating::execute(), LCE_Breed_Disperse::execute(), LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_Disperse_ConstDisp::execute(), LCE_Disperse_EvolDisp::execute(), LCE_Regulation::execute(), LCE_Aging::execute(), LCE_Patch_Extinction::execute(), LCE_Cross::execute(), LCE_Resize::execute(), LCE_PhenotypeExpression::execute(), LCE_QuantiInit::execute(), LCE_QuantiModifier::execute(), LCE_Breed_Quanti::execute(), LCE_Selection_base::execute(), LCE_Init_BDMI::execute(), LCE_NtrlInit::execute(), TTDeletMutBitstrFH::FHread(), TTNeutralGenesFH::FHread(), TTQuantiFH::FHread(), LCE_SelectionFH::FHwrite(), MPFileHandler::FHwrite(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTNOhtaStats::FHwrite(), TTQFreqExtractor::FHwrite(), TTQOhtaStats::FHwrite(), LCE_Resize::fillPop(), TTNeutralGenesSH::getDxy(), TTDeletMutBitstrSH::getLoad(), LCE_Selection_base::getMaxFitness(), TTDispersalSH::getMeanDispRate(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanOffsprgInfection(), TTDispersalSH::getOffsprgMeanDispRate(), LCE_Breed_Wolbachia::hasInfectedFemale(), TTQuantiSH::init(), LCE_Breed_Wolbachia::inoculate_wolbachia(), LCE_Breed_Disperse::mate_selfing(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), GenotyperFH::prepare_data_table(), GenotyperFH::print_genotypes(), GenotyperFH::print_snp_genotypes(), GenotyperFH::print_snp_id(), LCE_Resize::regulate(), SimRunner::run(), LCE_Cross::sampleAmongPop(), LCE_PhenotypeExpression::set_env_cue(), LCE_Selection_base::set_local_optima(), LCE_Patch_Extinction::set_matrix_param(), LCE_Selection_base::set_param_rate_of_change(), LCE_Selection_base::set_sel_model(), LCE_Selection_base::set_std_rate_of_change(), TTNeutralGenesSH::setAlleleTables(), LCE_Disperse_base::setBaseParameters(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTDeletMutBitstrSH::setDeletStats(), TTNeutralGenesSH::setDxyRecorders(), LCE_Breed_base::setFecundity(), TTDeletMutBitstrSH::setFst(), TTNeutralGenesSH::setFst_li(), TTNeutralGenesSH::setFstat(), TTNeutralGenesSH::setFstat_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham(), TTNeutralGenesSH::setFstatWeirCockerham_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham_MS(), TTNeutralGenesSH::setFstMatrix(), TTNeutralGenesSH::setFstMatrixRecorders(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), TTWolbachiaSH::setInfectionStats(), TTNeutralGenesSH::setLociDivCounter(), TTDeletMutBitstrSH::setMeanViability(), TTNeutralGenesSH::setNeiGeneticDistance(), TTNeutralGenesSH::setNeiGeneticDistanceRecorders(), LCE_Breed_Disperse::setParameters(), LCE_Disperse_EvolDisp::setParameters(), LCE_PhenotypeExpression::setParameters(), LCE_QuantiInit::setParameters(), LCE_Init_BDMI::setParameters(), LCE_NtrlInit::setParameters(), LCE_Breed_Wolbachia::setParameters(), setPopulationFromSourceInPreserveMode(), LCE_Disperse_base::setPropaguleTargets(), LCE_FileServicesNotifier::setSamplingParameters(), LCE_Selection_base::setSelectionMatrix(), LCE_Selection_base::setSelectionOffset(), TTWolbachiaSH::setStatRecorders(), TTBDMI_SH::setStats(), TTQuantiSH::setStats(), MPStatHandler::setStatsForMigrantsPerPatch(), TTDeletMutBitstrSH::setViability(), LCE_Resize::updateParameters(), LCE_Resize::updatePatchCapacities(), LCE_Breed_Wolbachia::wolbachia_model_1(), LCE_Breed_Wolbachia::wolbachia_model_2(), LCE_Breed_base::WrightFisherPopulation(), LCE_Breed_Quanti::WrightFisherPopulation(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_PLINK(), TTQuantiFH::write_PLINK(), TTNeutralGenesFH::write_TAB(), TTQuantiFH::write_TABLE(), and TTNeutralGenesFH::write_varcompWC().

◆ getPatchPtr()

Patch* Metapop::getPatchPtr ( unsigned int  patch)
inline

A secure version of the getPatch() method.

259  {
260  if(!(patch < _vPatch.size()))
261  fatal("Metapop::getPatchPtr()::_vPatch overflow (id=%i nb=%i)\n", patch, _vPatch.size());
262 
263  if (_vPatch[patch] == NULL) fatal("Metapop::getPatchPtr()::NULL ptr\n");
264 
265  return _vPatch[patch];
266  }
void fatal(const char *str,...)
Definition: output.cc:99

References _vPatch, and fatal().

Referenced by LCE_Resize::buildNewPatchArrayWithBackup(), LCE_Resize::fillPatchNoBackup(), LCE_Resize::fillPatchWithBackup(), get(), LCE_Breed_Disperse::get_parent(), TTNeutralGenesSH::getDxyPerPatch(), TTDispersalSH::getMeanDispRateInPatch(), LCE_SelectionSH::getMeanPatchFitness(), LCE_SelectionSH::getVarPatchFitness(), LCE_Resize::regulate(), LCE_Resize::removeDesignatedPatch(), removePatch(), LCE_Cross::sampleAmongPop(), setPopulationFromSourceInPreserveMode(), and LCE_Resize::updatePatchCapacities().

+ Here is the caller graph for this function:

◆ getReplicates()

unsigned int Metapop::getReplicates ( )
inline
274 {return _replicates;}

References _replicates.

Referenced by FileServices::getFirstReplicateFileName(), FileServices::getReplicateCounter(), and BinaryDataSaver::ifExist().

+ Here is the caller graph for this function:

◆ getSourceFileType()

string Metapop::getSourceFileType ( )
inline
283 {return _source_filetype;}

References _source_filetype.

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ getSourceName()

string Metapop::getSourceName ( )
inline
282 {return _source_name;}
std::string _source_name
The base filename of source population files.
Definition: metapop.h:115

References _source_name.

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ getSourceReplDigits()

unsigned int Metapop::getSourceReplDigits ( )
inline

◆ init()

bool Metapop::init ( )

Inits the population parameters from the ParamSet and builds the pop (adds patches), the prototypes and the life cycle.

Called at the start of each simulation, resets the individual garbage collector.

97 {
98  if( !(_paramSet->isSet()) ) {
99  return error("parameters in \"population\" are not properly set!\n");
100  }
101 
102  if(!setParameters()) return false;
103 
104  buildPatchArray();
105 
106  //empty and clean the RecyclingPOOL, safer...
108 
109  return true;
110 }
void buildPatchArray()
Builds the new population from parameter values.
Definition: metapop.cc:307
virtual bool setParameters()
Definition: metapop.cc:114
bool isSet()
Accessor to the status flag.
Definition: param.h:287
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47
int error(const char *str,...)
Definition: output.cc:78

References SimComponent::_paramSet, buildPatchArray(), error(), ParamSet::isSet(), IndFactory::purgeRecyclingPOOL(), and setParameters().

Referenced by SimRunner::init_components(), and loadPopFromTraitFile().

+ Here is the caller graph for this function:

◆ isAlive()

bool Metapop::isAlive ( )
inline

Checks if the population still contains at least one individual in any sex or age class.

308 {return size() != 0;}

References size().

Referenced by SimRunner::Cycle(), MPFileHandler::FHwrite(), GenotyperFH::FHwrite(), TTBDMI_FH::FHwrite(), TTNeutralGenesFH::FHwrite(), TTNOhtaStats::FHwrite(), TTQuantiFH::FHwrite(), TTQOhtaStats::FHwrite(), and SimRunner::Replicate_LOOP().

+ Here is the caller graph for this function:

◆ isSourceLoad()

bool Metapop::isSourceLoad ( )
inline
281 {return _source_load;}

References _source_load.

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ loadFileServices()

void Metapop::loadFileServices ( FileServices loader)
virtual

Implements SimComponent.

268 {
269 
270  if(get_parameter("pop_output")->isSet()){
271 
272  if(!get_parameter("pop_output_logtime")->isSet())
273  fatal("parameter \"pop_output_logtime\" is missing when pop_output is set\n");
274 
275 
276  if(_writer == 0) _writer = new MPFileHandler();
277 
278  int size = 0;
279 
280  if(get_parameter("pop_output_sample_size")->isSet())
281  size = get_parameter_value("pop_output_sample_size");
282 
284 
285  Param* param = get_parameter("pop_output_logtime");
286 
287  if(param->isMatrix()) {
288 
289  TMatrix temp;
290  param->getMatrix(&temp);
291  _writer->set_multi(true, true, 1, &temp, get_parameter("pop_output_dir")->getArg());
292 
293  } else // rpl_per, gen_per, rpl_occ, gen_occ, rank (0), path, self-ref
294  _writer->set(true, true, 1, (param->isSet() ? (int)param->getValue() : 0),
295  0, get_parameter("pop_output_dir")->getArg());
296 
297  loader->attach(_writer);
298 
299  } else if(_writer) {
300  delete _writer;
301  _writer = NULL;
302  }
303 }
virtual void set_multi(bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path)
Definition: filehandler.h:200
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
Sets the hanlder parameters.
Definition: filehandler.h:196
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:60
Definition: metapop.h:775
void setOption(int size)
Definition: metapop.h:784
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
double getValue()
Returns the argument value according to its type.
Definition: param.cc:367
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:171
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:377
bool isSet()
Definition: param.h:139
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49

References _writer, FileServices::attach(), fatal(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), Param::getMatrix(), Param::getValue(), Param::isMatrix(), Param::isSet(), FileHandler::set(), FileHandler::set_multi(), MPFileHandler::setOption(), and size().

◆ loadPopFromBinarySource()

void Metapop::loadPopFromBinarySource ( string &  filename)

Loads the population from a binary data file when setting the first generation of a replicate.

1023 {
1024  Individual *new_ind, *src_tmp;
1025 
1026  // EXTRACT DATA FROM SOURCE -------------------------------------------------------------
1027 
1028  // here the data is put in the _source Metapop, it is not yet copied to fill the current pop
1029 
1031  fatal("Metapop::loadPopFromBinarySource:could not extract pop from binary file \"%s\"\n",filename.c_str());
1032 
1033 #ifdef _DEBUG_
1034  message("+++Metapop::loadPopFromBinarySource::data read from %s\n",filename.c_str());
1035 #endif
1036 
1037  // PERFORM CHECKS -----------------------------------------------------------------------
1038 
1039  //check trait parameters; we want to have equal genetic architecture for the traits
1040  new_ind = getNewIndividual();
1041  src_tmp = _source->getNewIndividual();
1042 
1043  if( (*new_ind) != (*src_tmp) ) { //the operator= for each trait is called within operator= of Individual
1044  fatal("loading population from source file failed: trait genetic architecture differs.\n");
1045  }
1046 
1047  delete new_ind;
1048  delete src_tmp;
1049 
1050 
1051  // PARAMETER OVERRIDE FROM SOURCE -------------------------------------------------------
1052 
1053  // check if we need to override some local parameter values with the values from the source
1054  if(get_parameter("source_parameter_override")->isSet() )
1055  {
1056  string param;
1057  bool checked = false;
1058  SimComponent *cmpt = NULL, *localcmpt = NULL;
1059 
1060  for( unsigned int p; p < _source_param_override.size(); ++p )
1061  {
1062  param = _source_param_override[p];
1063 
1064  // check among the traits:
1066 
1067  if( cmpt ) {
1068 
1069  // find the local corresponding trait to reset its parameter
1070  localcmpt = SIMenv::MainSim->get_current_trait(dynamic_cast<TraitPrototype*> (cmpt)->get_type());
1071 
1072  if( localcmpt ) {
1073  // we found it, reset;
1074  checked = localcmpt->resetParameterFromSource(param, cmpt);
1075  }
1076 
1077  }
1078 
1079  //check among the LCEs
1080  if( !checked ){
1082 
1083  if( cmpt ) {
1084 
1085  // find the local corresponding trait to reset its parameter
1086  localcmpt = SIMenv::MainSim->get_current_event(dynamic_cast<LifeCycleEvent*> (cmpt)->get_event_name());
1087 
1088  if( localcmpt ) {
1089  // we found it, reset;
1090  checked = localcmpt->resetParameterFromSource(param, cmpt);
1091  }
1092 
1093  }
1094  }
1095 
1096  if( !checked ){
1097  if( _loader.getPop()->has_parameter(param) ) {
1098 
1099  cmpt = _loader.getPop();
1100 
1101  checked = resetParameterFromSource(param, cmpt);
1102  }
1103  }
1104 
1105  string message = "while loading population from binary source: resetting parameter value\
1106  from the source value failed for parameter";
1107 
1108  if(!checked) //resetting failed
1109  fatal("%s \"%s\" (a specific routine may need to be implemented, contact the developers)\n",
1110  message.c_str(), param.c_str());
1111 
1112  if(!localcmpt) //we didn't find a corresponding local component, abort;
1113  fatal("%s \"%s\", no corresponding local component could be found.\n",
1114  message.c_str(), param.c_str());
1115 
1116  if(!cmpt) //no source component has this parameter
1117  fatal("%s \"%s\", no component holding this parameter exists in the source.\n",
1118  message.c_str(), param.c_str());
1119 
1120 
1121  // need to log the new parameter value into the simulation .log file
1122  // because the log file is written before the replicate loop starts
1123  SIMenv::MainSim->_FileServices.log("## " + param + " set from binary source value at replicate "
1125  SIMenv::MainSim->_FileServices.log("# " + param + " " + cmpt->get_parameter(param)->getArg());
1126 
1127  cmpt = localcmpt = NULL;
1128  checked = false;
1129 
1130  }
1131  }
1132 
1133 }
SimBuilder * getSim() const
Definition: binarydataloader.h:81
Metapop * extractPop(string &filename, unsigned int generation, SimBuilder *sim, Metapop *popPtr)
Definition: binarydataloader.cc:162
Metapop * getPop() const
Definition: binarydataloader.h:79
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:435
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: metapop.h:237
vector< string > _source_param_override
List of parameters whose values in the source should override local values in the loading pop.
Definition: metapop.h:123
string getArg()
Definition: param.h:137
static SimRunner * MainSim
Definition: simenv.h:41
LifeCycleEvent * get_current_event(string &name)
Accessor to the list of current LCEs.
Definition: basicsimulation.cc:857
LifeCycleEvent * get_current_eventWithParameter(string &param)
Accessor to the current LCEs conditioned on ownership of a specified parameter.
Definition: basicsimulation.cc:872
TraitPrototype * get_current_traitWithParameter(string &param)
Accessor to the current trait prototypes conditioned on ownership of a specified parameter.
Definition: basicsimulation.cc:840
TraitPrototype * get_current_trait(trait_t type)
Accessor to the list of current trait prototypes.
Definition: basicsimulation.cc:828
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:44
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)=0
virtual bool has_parameter(std::string name)
Param getter.
Definition: simcomponent.h:149
FileServices _FileServices
Definition: simulation.h:99
TTrait setter.
Definition: ttrait.h:130
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:94

References _currentReplicate, SimRunner::_FileServices, _loader, _source, _source_generation, _source_param_override, BinaryDataLoader::extractPop(), fatal(), SimBuilder::get_current_event(), SimBuilder::get_current_eventWithParameter(), SimBuilder::get_current_trait(), SimBuilder::get_current_traitWithParameter(), SimComponent::get_parameter(), Param::getArg(), IndFactory::getNewIndividual(), BinaryDataLoader::getPop(), BinaryDataLoader::getSim(), SimComponent::has_parameter(), tstring::int2str(), FileServices::log(), SIMenv::MainSim, message(), resetParameterFromSource(), and SimComponent::resetParameterFromSource().

Referenced by loadSourcePopulation().

+ Here is the caller graph for this function:

◆ loadPopFromTraitFile()

void Metapop::loadPopFromTraitFile ( string &  filename)

Loads a population from a trait's data file (text file).

1138 {
1139  if(_source != NULL) delete _source;
1140 
1141  _source = new Metapop();
1143 
1144  //the population's parameters from current params
1146 
1147  //we need this to be able to create new individuals in the source:
1148  _source->init( );
1150 
1151  //now read data from genotype file:
1153 
1154  FileHandler* file = FS->getReader(_source_filetype);
1155 
1156  if(!file)
1157  fatal("no file reader exists with source file extension \"%s\".\n",_source_filetype.c_str());
1158 
1159  message("\n>>>> Reading trait's genetics from file \"%s\"\n", filename.c_str());
1160 
1161  //attach the source pop to the reader
1162  file->set_pop_ptr(_source);
1163 
1164 // cout << "\n --- pop size BEFORE loading inds from genotype file: "<<size()<<endl;
1165 
1166  //read the genotypes from files into the source metapop object
1167  file->FHread(filename);
1168 
1169  if(_source->size() == 0)
1170  fatal("source population in file \"%s\" is empty.\n",filename.c_str());
1171 
1172 // cout << "\n --- pop size AFTER loading inds from genotype file: "<<size()<<endl;
1173 
1174 }
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:52
void set_pop_ptr(Metapop *pop_ptr)
Definition: filehandler.h:136
virtual void FHread(string &filename)=0
Default input function.
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
FileHandler * getReader(string &type)
Accessor to a specific file handler specified by its extension string.
Definition: fileservices.cc:532
void makePrototype(map< trait_t, TraitPrototype * > TTlist)
Creates the individuals prototype from the selected trait prototypes.
Definition: indfactory.cc:49
std::map< trait_t, TraitPrototype * > & getTraitPrototypes()
Accessor to the list of TraitPrototype's.
Definition: indfactory.h:139
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches),...
Definition: metapop.cc:96
void setMPImanager(MPImanager *mgr)
Definition: metapop.h:173
Metapop()
Definition: metapop.cc:54
virtual void set_paramsetFromCopy(const ParamSet &PSet)
Reset the set of parameters from a another set.
Definition: simcomponent.h:102
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:107
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:147

References _mpimgr, _source, _source_filetype, fatal(), FileHandler::FHread(), SimRunner::get_FileServices(), SimComponent::get_paramset(), FileServices::getReader(), IndFactory::getTraitPrototypes(), init(), SIMenv::MainSim, IndFactory::makePrototype(), message(), Metapop(), SimComponent::set_paramsetFromCopy(), FileHandler::set_pop_ptr(), setMPImanager(), and size().

Referenced by loadSourcePopulation().

+ Here is the caller graph for this function:

◆ loadSourcePopulation()

void Metapop::loadSourcePopulation ( )

Loads a population from a soure population.

969 {
970  std::string filename;
971 
972  if(_source_replicates != 0) {
973  //find the replicate string of the source file
974  ostringstream rpl;
975  rpl.fill('0');
976  rpl.width(_source_replicate_digits);
977 
980  else if (_source_replicates != 1)
981  //less replicates in source, reload the same repl every `source_replicates'
982  rpl << ((_currentReplicate-1) / _source_load_periodicity) + 1;
983  else
984  rpl << 1; //a bit dumb but just in case...
985 
986  filename = _source_name + "_" + rpl.str() + _source_filetype;
987 
988  } else {
989 
990  filename = _source_name;
991 
992  }
993 
994  if(_source_filetype == ".bin") {
995 
996  // loading pop from a binary file
997 
998  loadPopFromBinarySource(filename);
999 
1000  if(_source->size() == 0) fatal("source population is empty!\n");
1001  else {
1002  if(_source->size(OFFSPRG) != 0)
1004 
1005  if(_source->size(ADULTS) != 0)
1007  }
1008 
1009  } else
1010  // loading pop from a trait's genotype text file
1011  loadPopFromTraitFile(filename);
1012 
1013 #ifdef _DEBUG_
1014  if(_source)
1015  message("+++source pop loaded: offspring: %i f, %i m; adults: %i f, %i m\n", _source->size(FEM,OFFSPRG),
1017 #endif
1018 }
void loadPopFromBinarySource(string &filename)
Loads the population from a binary data file when setting the first generation of a replicate.
Definition: metapop.cc:1022
void loadPopFromTraitFile(string &filename)
Loads a population from a trait's data file (text file).
Definition: metapop.cc:1137
age_t getCurrentAge()
Definition: metapop.h:298
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:302
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:53

References _currentReplicate, _replicates, _source, _source_filetype, _source_load_periodicity, _source_name, _source_replicate_digits, _source_replicates, _source_start_at_replicate, ADULTS, fatal(), FEM, getCurrentAge(), loadPopFromBinarySource(), loadPopFromTraitFile(), MAL, message(), OFFSPRG, setCurrentAge(), and size().

Referenced by setPopulation().

+ Here is the caller graph for this function:

◆ loadStatServices()

virtual void Metapop::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

235 {loader->attach(&_statHandler);}
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:176

References _statHandler, and StatServices::attach().

◆ move()

void Metapop::move ( sex_t  SEX,
age_idx  from_age,
unsigned int  from_deme,
age_idx  to_age,
unsigned int  to_deme,
unsigned int  at 
)
inline

Moves an individual from a deme to an other one, both demes sizes are modified.

Parameters
SEXsex class container index
from_ageage class container index in the deme of origin
from_demeindex of the deme of origin
to_ageage class container index in the destination deme
to_demeindex of the destination deme
atindex of the focal individual in the 'from' deme
840 {//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
841  _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
842  //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
843  _vPatch[from_deme]->remove(SEX, from_age, at);
844  //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
845  // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
846 }
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:835

References _vPatch, and get().

Referenced by LCE_Disperse_EvolDisp::evoldisp(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Disperse_ConstDisp::MigratePatch(), LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder(), and LCE_Disperse_ConstDisp::MigratePatchByNumber().

+ Here is the caller graph for this function:

◆ read_trait()

void Metapop::read_trait ( int  trait_idx,
BinaryStorageBuffer loader 
)

Iterates through the individuals containers to retrieve the trait data from a binary file.

684 {
685  for(unsigned int i = 0; i < _patchNbr; ++i) {
686 
687  //first offspring:
688  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, OFFSx); ++j){
689  _vPatch[i]->get(FEM, OFFSx, j)->getTrait(trait_idx)->retrieve_data(loader);
690  }
691 
692  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, OFFSx); ++j){
693  _vPatch[i]->get(MAL, OFFSx, j)->getTrait(trait_idx)->retrieve_data(loader);
694  }
695 
696  //then adults:
697  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
698  _vPatch[i]->get(FEM, ADLTx, j)->getTrait(trait_idx)->retrieve_data(loader);
699 
700  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
701  _vPatch[i]->get(MAL, ADLTx, j)->getTrait(trait_idx)->retrieve_data(loader);
702  }
703 }
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:276
virtual bool retrieve_data(BinaryStorageBuffer *reader)=0
Interface to retrieve the same data from the binary buffer.

References _patchNbr, _vPatch, ADLTx, FEM, get(), Individual::getTrait(), MAL, OFFSx, and StorableComponent::retrieve_data().

Referenced by retrieve_data().

+ Here is the caller graph for this function:

◆ removePatch()

Patch * Metapop::removePatch ( unsigned int  i)
inline

Removes a patch from the patch array and returns it pointer.

The patch and its content are NOT deleted. The IDs of the remaining patches are NOT updated.

Parameters
ithe index of the patch to remove.
869 {
870  Patch* patch = getPatchPtr(i);
871  _vPatch.erase(_vPatch.begin() + i);
872  return patch;
873 }

References _vPatch, and getPatchPtr().

Referenced by LCE_Resize::buildNewPatchArrayWithBackup(), FileServices::empty_sampled_pop(), and LCE_Resize::removeDesignatedPatch().

+ Here is the caller graph for this function:

◆ reset()

void Metapop::reset ( )

Called to empty the patches, individuals are move to the garbage collector.

Resets each Patch, all individuals are moved to the POOL.

1180 {
1181  unsigned int i;
1182 
1183  for(i = 0; i < _patchNbr; ++i) {
1184  _vPatch[i]->flush(this);
1185  _vPatch[i]->reset_counters();
1186  }
1187 }

References _patchNbr, and _vPatch.

Referenced by LCE_Breed_Wolbachia::execute().

+ Here is the caller graph for this function:

◆ resetParameterFromSource()

virtual bool Metapop::resetParameterFromSource ( std::string  param,
SimComponent cmpt 
)
inlinevirtual

Implements SimComponent.

237 {return false;}

Referenced by loadPopFromBinarySource().

+ Here is the caller graph for this function:

◆ resizePatchArray()

void Metapop::resizePatchArray ( )

Resets the patch container to the right number of patches as set by _patchNbr.

Called at the beginning of each new simulation. Extra patches are destroyed and new ones are added if missing.

321 {
322  //reset the right number of patches for the new simulation
323  if(_vPatch.size() > _patchNbr) {
324  while(_vPatch.size() > _patchNbr) {
325  delete _vPatch[0];
326  _vPatch.pop_front();
327  }
328  } else while(_vPatch.size() < _patchNbr) _vPatch.push_back(new Patch());
329 }

References _patchNbr, and _vPatch.

Referenced by buildPatchArray(), and updatePatchArray().

+ Here is the caller graph for this function:

◆ retrieve_data()

bool Metapop::retrieve_data ( BinaryStorageBuffer reader)
virtual

Implements StorableComponent.

555 {
556 #ifdef _DEBUG_
557  message("Metapop::retrieve_data, %iB of data read so far\n",loader->getBytesOut());
558 #endif
559  unsigned int *sizes[3], dummy_int;
560  unsigned char separator[2];
561 
562  sizes[0] = new unsigned int [_patchNbr];
563  sizes[1] = new unsigned int [_patchNbr];
564  sizes[2] = new unsigned int [_patchNbr];
565 
566  loader->read(&separator, 2 * sizeof(unsigned char));
567 
568  if(separator[0] != '@' || separator[1] != 'P')
569  return error("Binary file appears corrupted:\n\
570  >>>> Metapop::retrieve_data::wrong population seprarator\n");
571 
572  // read patch number
573  loader->read(&dummy_int, sizeof(unsigned int));
574 
575  if(dummy_int != _patchNbr)
576  return error("Population in binary file differs from simulation settings:\n\
577  >>>> Metapop::retrieve_data:number of Patch differ from parameter value\n");
578 
579  //get the Patch sizes
580  //offspring
581  loader->read(sizes[0], _patchNbr * sizeof(unsigned int));
582  //females adults
583  loader->read(sizes[1], _patchNbr * sizeof(unsigned int));
584  //males adults
585  loader->read(sizes[2], _patchNbr * sizeof(unsigned int));
586 
587  Individual* ind;
588  unsigned int bytes_cnt = loader->getBytesOut();
589  //retrieve all individual informations: IDs, matings, etc.
590  for(unsigned int i = 0; i < _patchNbr; ++i) {
591  //first, offspring:
592  for(unsigned int j = 0; j < sizes[0][i]; ++j) {
593  ind = this->getNewIndividual();
594  ind->retrieve_data(loader);
595  _vPatch[i]->add(ind->getSex(), OFFSx, ind);
596  }
597  //then adult females:
598  for(unsigned int j = 0; j < sizes[1][i]; ++j) {
599  ind = this->getNewIndividual();
600  ind->retrieve_data(loader);
601  _vPatch[i]->add(FEM, ADLTx, ind);
602  }
603  //and adult males:
604  for(unsigned int j = 0; j < sizes[2][i]; ++j) {
605  ind = this->getNewIndividual();
606  ind->retrieve_data(loader);
607  _vPatch[i]->add(MAL, ADLTx, ind);
608  }
609 
610  }
611 
612 #ifdef _DEBUG_
613  message("Metapop::retrieve_data::retrieved %ikB of ind data (%i individuals)\n",
614  (loader->getBytesOut()-bytes_cnt)/1024, size());
615 #endif
616  //retrieve traits sequences
617  map<trait_t, TraitPrototype *>::iterator tt = _protoTraits.begin();
618 
619  char trait_name[6] = {'\0','\0','\0','\0','\0','\0'};
620 
621  unsigned int trait_cntr = 0;
622 
623  loader->read(&separator, 2 * sizeof(unsigned char));
624 
625  if(separator[0] != '@' || separator[1] != 'T') {
626  error("Binary file appears corrupted:\n >>>> Metapop::retrieve_data::wrong trait seprarator\n");
627  return false;
628  }
629 
630  bytes_cnt = loader->getBytesOut();
631 
632  do {
633  //get the trait type:
634  loader->read(&trait_name[0], TRAIT_T_MAX);
635 
636  string dummy_trait(trait_name);
637 
638  //get the prototype:
639  tt = _protoTraits.find(dummy_trait);
640 
641  if( tt == _protoTraits.end() )
642  return error("Trait(s) in binary file differ from simulation settings:\n\
643  >>>> Metapop::retrieve_data::trait in file not present in prototype\n");
644 
645  //then ask the prototype to retrieve its data:
646  tt->second->retrieve_data(loader);
647 
648 #ifdef _DEBUG_
649  message("%iB of trait data read so far (trait %s)\n",loader->getBytesOut()-bytes_cnt,tt->first.c_str());
650 #endif
651 
652  //get the traits data:
653  read_trait(tt->second->get_index(), loader);
654 
655  trait_cntr++;
656 
657  //get the next separator, should be present if right number of bytes have been read
658  loader->read(&separator, 2 * sizeof(unsigned char));
659 
660 
661  } while (separator[0] == '@' && separator[1] == 'T') ;
662 
663 #ifdef _DEBUG_
664  message("Metapop::retrieve_data::retrieved %ikB of trait data\n",(loader->getBytesOut()-bytes_cnt)/1024);
665 #endif
666 
667  if(trait_cntr != _protoTraits.size())
668  return error("Trait(s) in binary file differ from simulation settings:\n\
669  >>>> Metapop::retrieve_data::some traits are missing from binary file\n");
670 
671  if(separator[0] != '@')
672  return error("Binary file appears corrupted:\n\
673  >>>> Metapop::retrieve_data::separator not found at end of pop record!\n");
674 
675  for(unsigned int i = 0; i < 3; i++)
676  delete [] sizes[i];
677 
678  return true;
679 }
std::map< trait_t, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:45
void retrieve_data(BinaryStorageBuffer *reader)
Definition: individual.cc:116
sex_t getSex()
Definition: individual.h:128
void read_trait(int trait_idx, BinaryStorageBuffer *loader)
Iterates through the individuals containers to retrieve the trait data from a binary file.
Definition: metapop.cc:683
#define TRAIT_T_MAX
Max number of characters in the trait's type descriptor.
Definition: types.h:64

References _patchNbr, IndFactory::_protoTraits, _vPatch, ADLTx, error(), FEM, BinaryStorageBuffer::getBytesOut(), IndFactory::getNewIndividual(), Individual::getSex(), MAL, message(), OFFSx, BinaryStorageBuffer::read(), read_trait(), Individual::retrieve_data(), size(), and TRAIT_T_MAX.

Referenced by BinaryDataLoader::extractPop().

+ Here is the caller graph for this function:

◆ setCurrentAge() [1/2]

void Metapop::setCurrentAge ( age_t  age)
inline

Sets the age flag.

Parameters
agethe current age.
302 {_currentAge = age;}

References _currentAge.

Referenced by LCE_Cross::generatePedigree(), FileServices::getSampledPop(), loadSourcePopulation(), and SimRunner::step().

+ Here is the caller graph for this function:

◆ setCurrentAge() [2/2]

void Metapop::setCurrentAge ( LifeCycleEvent LCE)

Set the age flag from a LifeCycleEvent object.

Parameters
LCEthe LifeCycleEvent object.
1216 {
1217  _currentAge ^= LCE->removeAgeClass();
1218  _currentAge |= LCE->addAgeClass();
1219 }
virtual age_t removeAgeClass()=0
Removes the returned age-class flag(s) from the current Metapop age-class flags.
virtual age_t addAgeClass()=0
Adds the returned age-class flag(s) to the current Metapop age-class flags.

References _currentAge, LifeCycleEvent::addAgeClass(), and LifeCycleEvent::removeAgeClass().

◆ setCurrentGeneration()

void Metapop::setCurrentGeneration ( unsigned int  gen)
inline
297 {_currentGeneration = gen;}

References _currentGeneration.

Referenced by SimRunner::Cycle(), SimRunner::Replicate_LOOP(), SimRunner::setCurrentGeneration(), and SimRunner::setForFirstGeneration().

+ Here is the caller graph for this function:

◆ setCurrentReplicate()

void Metapop::setCurrentReplicate ( unsigned int  repl)
inline
296 {_currentReplicate = repl;}

References _currentReplicate.

Referenced by SimRunner::Replicate_LOOP(), and SimRunner::setCurrentReplicate().

+ Here is the caller graph for this function:

◆ setGenerations()

void Metapop::setGenerations ( unsigned int  gen)
inline
271 {_generations = gen;}

References _generations.

Referenced by SimRunner::init_components(), and SimRunner::setGenerations().

+ Here is the caller graph for this function:

◆ setMPImanager()

void Metapop::setMPImanager ( MPImanager mgr)
inline
173 {_mpimgr = mgr;}

References _mpimgr.

Referenced by BinaryDataLoader::extractPop(), and loadPopFromTraitFile().

+ Here is the caller graph for this function:

◆ setParameters()

bool Metapop::setParameters ( )
virtual

Implements SimComponent.

115 {
116  if(!setPopulationParameters()) return false;
117  if(!setSourceParameters()) return false;
118  return true;
119 }
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:195

References setPopulationParameters(), and setSourceParameters().

Referenced by BinaryDataLoader::extractPop(), and init().

+ Here is the caller graph for this function:

◆ setPatchCapacities() [1/4]

void Metapop::setPatchCapacities ( )

Sets the deme capacity matrix from parameter values.

357 {
359 
360  for(unsigned int i = 0; i < _patchNbr; ++i) {
363  }
364 }
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:160
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102

References _patchKfem, _patchKmal, _patchNbr, _patchSizes, FEM, MAL, TMatrix::reset(), and TMatrix::set().

Referenced by setPopulationParameters().

+ Here is the caller graph for this function:

◆ setPatchCapacities() [2/4]

void Metapop::setPatchCapacities ( sex_t  SEX,
string  param 
)

Builds the new population from a matrix of deme sizes but for one sex only.

Sizes for the other sex class(es) must be given separately.

Parameters
SEXthe sex class of the given deme sizes.
paramthe name of the parameter to take the matrix argument from.
393 {
394  double* size_array;
395  unsigned int size_, Knum;
396  TMatrix popK;
397 
398  _paramSet->getMatrix(param, &popK);
399 
400  Knum = popK.length();
401 
402  if(_patchNbr == 0 || _patchNbr < Knum) _patchNbr = Knum;
403 
405 
406  size_array = popK.get();
407 
408  if(SEX == FEM)
409  size_ = _patchKmal;
410  else
411  size_ = _patchKfem;
412 
413  for(unsigned int i = 0; i < _patchNbr; ++i) {
414  _patchSizes.set(SEX, i, (unsigned int)size_array[i % Knum]);
415  _patchSizes.set(!SEX, i, size_);
416  }
417 }
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:303
unsigned int length() const
Returns the number of elements in the matrix.
Definition: tmatrix.h:217

References SimComponent::_paramSet, _patchKfem, _patchKmal, _patchNbr, _patchSizes, FEM, TMatrix::get(), ParamSet::getMatrix(), TMatrix::length(), TMatrix::reset(), and TMatrix::set().

◆ setPatchCapacities() [3/4]

void Metapop::setPatchCapacities ( string  param)

Builds the new population from a single matrix of deme sizes.

The sex-specific patch capacities will be half of the numbers given in the matrix.

Parameters
paramthe name of the parameter to take the matrix argument from.
369 {
370  double* size_array;
371  unsigned int Knum;
372  TMatrix popK;
373 
374  _paramSet->getMatrix(param, &popK);
375 
376  Knum = popK.length();
377 
378  if(_patchNbr == 0 || _patchNbr < Knum) _patchNbr = Knum;
379 
381 
382  size_array = popK.get();
383 
384  for(unsigned int i = 0; i < _patchNbr; ++i) {
385  _patchSizes.set(FEM, i, (unsigned int)size_array[i % Knum]/2);
386  _patchSizes.set(MAL, i, (unsigned int)size_array[i % Knum]/2);
387  }
388 }

References SimComponent::_paramSet, _patchNbr, _patchSizes, FEM, TMatrix::get(), ParamSet::getMatrix(), TMatrix::length(), MAL, TMatrix::reset(), and TMatrix::set().

◆ setPatchCapacities() [4/4]

void Metapop::setPatchCapacities ( string  paramfem,
string  parammal 
)

Builds the new population from matrices of deme sizes.

Parameters
paramfemthe name of the parameter to take the matrix argument from.
parammalthe name of the parameter to take the matrix argument from.
422 {
423  double *size_fem, *size_mal;
424  unsigned int KFnum, KMnum;
425  TMatrix popKfem, popKmal;
426 
427  _paramSet->getMatrix(paramfem,&popKfem);
428  _paramSet->getMatrix(parammal,&popKmal);
429 
430  KFnum = popKfem.length();
431  KMnum = popKmal.length();
432 
433  if(_patchNbr == 0 && KFnum != KMnum){
434  warning("not same number of elements in females and males capacity matrices!\n");
435  warning("setting the number of populations from size of longest capacity array (= %i).\n",max(KFnum, KMnum));
436  }
437  if(_patchNbr < max(KFnum, KMnum)) _patchNbr = max(KFnum, KMnum);
438 
440 
441  size_fem = popKfem.get();
442  size_mal = popKmal.get();
443 
444  for(unsigned int i = 0; i < _patchNbr; ++i) {
445  _patchSizes.set(FEM, i, (unsigned int)size_fem[i % KFnum]);
446  _patchSizes.set(MAL, i, (unsigned int)size_mal[i % KMnum]);
447  }
448 }

References SimComponent::_paramSet, _patchNbr, _patchSizes, FEM, TMatrix::get(), ParamSet::getMatrix(), TMatrix::length(), MAL, TMatrix::reset(), TMatrix::set(), and warning().

◆ setPatchNbr()

void Metapop::setPatchNbr ( unsigned int  val)
inline
286 {_patchNbr = val;}

References _patchNbr.

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ setPatchSizes()

void Metapop::setPatchSizes ( TMatrix mat)
inline
287 {_patchSizes.copy(mat);}
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:77

References _patchSizes, and TMatrix::copy().

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ setPopulation()

void Metapop::setPopulation ( unsigned int  currentReplicate,
unsigned int  replicates 
)

Sets the population for the first generation of each replicates.

708 {
709 #ifdef _DEBUG_
710  message("\n+++Metapop::setPopulation: ");
711  fflush(stdout);
712 #endif
713 
714  _currentReplicate = currentReplicate;
715 
716 
717  //reset the population parameters, they may have changed during the life cycle
719 
720 
721  //reset the patch array, flush the patches and reset the patch capacities.
722  buildPatchArray();
723 
724  _currentAge = NONE;
725 
726  //find the age class required to start the life cycle with:
727  if(_requiredAge == NONE)
729 
730 
731 #ifdef _DEBUG_
732  message("required age is: %i ", _requiredAge);
733  fflush(stdout);
734 #endif
735 
736  //load first generation from a source population
737  if(_source_load) {
738 
739  //delete ind in recycler, needed when dealing with large source pop and lots of replicates:
740 
742 
743  if(_source_replicates >= replicates) {
745 
746  } else if( _source_replicates != 0) {
747  _source_load_periodicity = (unsigned int)ceil((double)replicates/_source_replicates);
748 
749  } else
750  _source_load_periodicity = replicates; // when _source_replicates == 0; create and load source pop only once for all replicates
751 
752  // check whether we need to read in a new (binary) source file, always do at first replicate
753  if( !( (currentReplicate - 1) % _source_load_periodicity) ) {
754 
755  //change source every _source_load_periodicity-nth replicates
756 
757  // load the population from the input file
758  // a new metapop object will be created to hold the individuals
759  // from the source
760  // _loader.extractPop() will be called
761  // some current parameters may be reset to match parameter values in the source pop
762 
764  }
765 
766 
767 
768  // once the data is loaded in the _source Metapop, we can use it to fill in the current Metapop:
769  // this only applies to binary file loading, trait file loading is done directly
770  if(_source_preserve) {
771 
772  //load in preserve mode
773  // i.e. make a copy of the saved pop
774  // the population structure in the source is preserved
775  // patches are loaded sequentially using the same patch index as in the source
776  // the number of individuals loaded per patch will match that of the source
777 
779 
780  } else {
781 
782  // the individuals are put in a big bag, destroying the existing structure
783  // individuals will be randomly drawn from this bag with replacement
784 
786 
787  }
788 
789 
790 
791  } else {
792 
793  //not source_load, use regular set routine
794 
795  for(unsigned int i = 0; i < _patchNbr; ++i)
796  _vPatch[i]->setNewGeneration( _requiredAge, this );
797 
799 
800  }
801 
802 #ifdef _DEBUG_
803  message("+++loaded age is: %i \n", _currentAge);
804 #endif
805 
806  if(_currentAge == NONE && size() == 0)
807  warning("Metapop::setPopulation: generation 0 is empty!!\n");
808 }
void setPopulationFromSource()
Definition: metapop.cc:888
void setPopulationFromSourceInPreserveMode()
Definition: metapop.cc:812
void loadSourcePopulation()
Loads a population from a soure population.
Definition: metapop.cc:968
age_t getFirstRequiredAgeInLifeCycle()
Definition: basicsimulation.cc:973

References _currentAge, _currentReplicate, _patchNbr, _requiredAge, _source_load, _source_load_periodicity, _source_preserve, _source_replicates, _vPatch, buildPatchArray(), SimBuilder::getFirstRequiredAgeInLifeCycle(), loadSourcePopulation(), SIMenv::MainSim, message(), NONE, IndFactory::purgeRecyclingPOOL(), setPopulationFromSource(), setPopulationFromSourceInPreserveMode(), setPopulationParameters(), size(), and warning().

Referenced by SimRunner::setForFirstGeneration().

+ Here is the caller graph for this function:

◆ setPopulationFromSource()

void Metapop::setPopulationFromSource ( )
889 {
890  //load in non-preserve mode, i.e. use saved pop as a source of new individuals
891  //individuals are drawn without replacement, sex and age are preserved.
892  deque< Individual* > src_fem_pool;
893  deque< Individual* > src_mal_pool;
894 
895  if( _requiredAge & OFFSPRG ) {
896 
897  if(_source->size(OFFSPRG) != 0)
898  _source->getAllIndividuals(OFFSx, src_fem_pool, src_mal_pool);
899  else {
900  warning("source population does not contain offspring individuals, using adults instead.\n");
901  //total size of source has been checked before
902  _source->getAllIndividuals(ADLTx, src_fem_pool, src_mal_pool);
903  }
904 
905  fillPopulationFromSource(OFFSx, FEM, src_fem_pool);
906  fillPopulationFromSource(OFFSx, MAL, src_mal_pool);
907  src_fem_pool.clear();
908  src_mal_pool.clear();
909 
910  _currentAge |= OFFSPRG;
911  }
912 
913  if( _requiredAge & ADULTS ) {
914 
915  if(_source->size(ADULTS) != 0)
916  _source->getAllIndividuals(ADLTx, src_fem_pool, src_mal_pool);
917  else {
918  warning("source population does not contain adult individuals, using offspring instead.\n");
919  //total size of source has been checked before
920  _source->getAllIndividuals(OFFSx, src_fem_pool, src_mal_pool);
921  }
922 
923  fillPopulationFromSource(ADLTx, FEM, src_fem_pool);
924  fillPopulationFromSource(ADLTx, MAL, src_mal_pool);
925  src_fem_pool.clear();
926  src_mal_pool.clear();
927 
928  _currentAge |= ADULTS;
929  }
930 
931 }
void fillPopulationFromSource(age_idx AGE, sex_t SEX, deque< Individual * > &src_pool)
Fills the population of the first generation of each replicates with individuals from a population so...
Definition: metapop.cc:935
void getAllIndividuals(age_idx AGE, deque< Individual * > &fem_pool, deque< Individual * > &mal_pool)
Definition: metapop.cc:1223

References _currentAge, _requiredAge, _source, ADLTx, ADULTS, FEM, fillPopulationFromSource(), getAllIndividuals(), MAL, OFFSPRG, OFFSx, size(), and warning().

Referenced by setPopulation().

+ Here is the caller graph for this function:

◆ setPopulationFromSourceInPreserveMode()

void Metapop::setPopulationFromSourceInPreserveMode ( )
813 {
814  Patch* src_patch;
815  age_t source_age;
816 
817  // set the number of patches to load relative to the number present in the source
818  unsigned int num_patch = (unsigned int)min((double)_vPatch.size(), (double)_source->getPatchNbr());
819 
820  if(_requiredAge != NONE && _source->size(_requiredAge) == 0 && _source->size() != 0) {
821 
822  source_age = _source->getCurrentAge();
823 
824  warning("required age %i not present in source, using age class %i instead (preserve mode).\n"
825  ,_requiredAge,source_age);
826 
827  for(unsigned int i = 0; i < num_patch; ++i) {
828 
829  src_patch = _source->getPatchPtr(i);
830 
831  fillPatchFromSource(FEM, src_patch, _vPatch[i], source_age);
832  fillPatchFromSource(MAL, src_patch, _vPatch[i], source_age);
833  }
834 
835  } else {
836 
837  if (_requiredAge == NONE) _requiredAge = ALL;
838 
839  for(unsigned int i = 0; i < num_patch; ++i) {
840 
841  src_patch = _source->getPatchPtr(i);
842 
843  if(_requiredAge & OFFSPRG) {
844  fillPatchFromSource(FEM, src_patch, _vPatch[i], OFFSPRG);
845  fillPatchFromSource(MAL, src_patch, _vPatch[i], OFFSPRG);
846  }
847 
848  if(_requiredAge & ADULTS) {
849  fillPatchFromSource(FEM, src_patch, _vPatch[i], ADULTS);
850  fillPatchFromSource(MAL, src_patch, _vPatch[i], ADULTS);
851  }
852  }
853  }
854 
855  if(size( ADULTS ) != 0)
856  _currentAge |= ADULTS;
857 
858  if(size( OFFSPRG ) != 0)
859  _currentAge |= OFFSPRG;
860 
861 #ifdef _DEBUG_
862  message("+++pop set from source: offspring: %i f, %i m; adults: %i f, %i m\n", size(FEM,OFFSPRG),
864 #endif
865 }
unsigned int getPatchNbr()
Definition: metapop.h:275
void fillPatchFromSource(sex_t SEX, Patch *src, Patch *patch, age_t AGE)
Fills a patch from a source patch loaded from a binary file, used when setting the population in pres...
Definition: metapop.cc:869
#define ALL
All ages age class flag.
Definition: types.h:55
unsigned int age_t
Age class flags.
Definition: types.h:45

References _currentAge, _requiredAge, _source, _vPatch, ADULTS, ALL, FEM, fillPatchFromSource(), getCurrentAge(), getPatchNbr(), getPatchPtr(), MAL, message(), NONE, OFFSPRG, size(), and warning().

Referenced by setPopulation().

+ Here is the caller graph for this function:

◆ setPopulationParameters()

bool Metapop::setPopulationParameters ( )

Population's size parameters initializing procedure.

196 {
197 
198  //population structure:
199  if(_paramSet->isSet("patch_number"))
200  _patchNbr = (unsigned int)_paramSet->getValue("patch_number");
201  else _patchNbr = 0;
202 
203  if(_paramSet->isSet("patch_capacity")) {
204 
205  if( _paramSet->isMatrix("patch_capacity") ) {
206 
207  setPatchCapacities("patch_capacity");
208 
209  } else if( !(_paramSet->isSet("patch_number")) ) {
210 
211  return error("param \"patch_number\" is missing!\n");;
212 
213  } else {
214  _patchK = (unsigned int)_paramSet->getValue("patch_capacity");
217  }
218 
219  } else if(_paramSet->isSet("patch_nbfem") && _paramSet->isSet("patch_nbmal")) {
220 
221  if( !(_paramSet->isMatrix("patch_nbfem")) && !(_paramSet->isMatrix("patch_nbmal")) ) {
222 
223  if( !(_paramSet->isSet("patch_number")) ) {
224 
225  return error("param \"patch_number\" is missing!\n");;
226 
227  } else {
228  _patchKfem = (unsigned int)_paramSet->getValue("patch_nbfem");
229  _patchKmal = (unsigned int)_paramSet->getValue("patch_nbmal");
232  }
233 
234  } else {
235 
236  if( !(_paramSet->isMatrix("patch_nbfem")) && _paramSet->isMatrix("patch_nbmal") ) {
237  _patchKfem = (unsigned int)_paramSet->getValue("patch_nbfem");
238  setPatchCapacities(MAL,"patch_nbmal");
239  } else if( _paramSet->isMatrix("patch_nbfem") && !(_paramSet->isMatrix("patch_nbmal")) ) {
240  _patchKmal = (unsigned int)_paramSet->getValue("patch_nbmal");
241  setPatchCapacities(FEM,"patch_nbfem");
242  } else
243  setPatchCapacities("patch_nbfem","patch_nbmal");
244  }
245 
246  } else {
247  return error("population parameters are not properly set!\n");;
248  }
249 
250  return true;
251 }
void setPatchCapacities()
Sets the deme capacity matrix from parameter values.
Definition: metapop.cc:356
double getValue(string name)
Accessor the parameters value.
Definition: param.h:301
bool isMatrix(string name)
Check if the parameter "name" is of matrix type.
Definition: param.h:295

References SimComponent::_paramSet, _patchK, _patchKfem, _patchKmal, _patchNbr, error(), FEM, ParamSet::getValue(), ParamSet::isMatrix(), ParamSet::isSet(), MAL, and setPatchCapacities().

Referenced by LCE_Resize::execute(), setParameters(), setPopulation(), and updatePopulationParameters().

+ Here is the caller graph for this function:

◆ setReplicates()

void Metapop::setReplicates ( unsigned int  repl)
inline
273 {_replicates = repl;}

References _replicates.

Referenced by SimRunner::init_components(), and SimRunner::setReplicates().

+ Here is the caller graph for this function:

◆ setSourceParameters()

bool Metapop::setSourceParameters ( )

Setter for source population parameters.

124 {
125  if(_paramSet->isSet("source_pop")) {
126 
127  _source_load = true;
128  _source_name = _paramSet->getArg("source_pop");
129  _source_preserve = _paramSet->isSet("source_preserve");
130  _source_replicates = _paramSet->isSet("source_replicates") ?
131  (unsigned int)_paramSet->getValue("source_replicates") : 0;
132 
133  _source_replicate_digits = _paramSet->isSet("source_replicate_digit") ?
134  (unsigned int)_paramSet->getValue("source_replicate_digit") : 1;
135 
136  _source_start_at_replicate = _paramSet->isSet("source_start_at_replicate") ?
137  (unsigned int)_paramSet->getValue("source_start_at_replicate") : 1;
138 
139  _source_generation = _paramSet->isSet("source_generation") ?
140  (unsigned int)_paramSet->getValue("source_generation") : 0;
141 
142  if(_paramSet->isSet("source_file_type"))
143  _source_filetype = _paramSet->getArg("source_file_type");
144  else
145  _source_filetype = ".bin";
146 
147  _source_required_age = _paramSet->getArg("source_fill_age_class");
148 
149  if(_source_required_age.length() == 0) _requiredAge = NONE;
150  else if(_source_required_age == "OFFSPRG" || _source_required_age == "offspring" ||
151  _source_required_age == "0"){
153  } else if(_source_required_age=="ADULTS" || _source_required_age=="adults" ||
154  _source_required_age=="1") {
156  } else if(_source_required_age=="ALL" || _source_required_age=="all") {
157  _requiredAge = ALL;
158  } else
159  _requiredAge = NONE;
160 
161 
162  // source parameter override:
163  // a set of parameters that need to be set from the values stored in the source
164  // e.g. the fitness effects of the deleterious mutations
165  _source_param_override.clear();
166 
167  if( _paramSet->isSet("source_parameter_override")) {
168 
169  if( get_parameter("source_parameter_override")->hasMultipleArgs() )
170  {
171  _source_param_override = get_parameter("source_parameter_override")->getMultiArgs();
172  }
173  else
174  {
175  _source_param_override.push_back(get_parameter("source_parameter_override")->getArg());
176  }
177  }
178 
179 
180  } else {
181  _source = NULL;
182  _source_preserve = false;
183  _source_load = false;
184  _source_replicates = 0;
185  _source_generation = 0;
186  _source_name = "";
187  _source_filetype = ".bin";
188  _source_param_override.clear();
189  }
190  return true;
191 }
std::string _source_required_age
The age class to fill with the source population.
Definition: metapop.h:119
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:299
bool hasMultipleArgs()
Definition: param.h:143
vector< string > getMultiArgs()
Definition: param.cc:119

References SimComponent::_paramSet, _requiredAge, _source, _source_filetype, _source_generation, _source_load, _source_name, _source_param_override, _source_preserve, _source_replicate_digits, _source_replicates, _source_required_age, _source_start_at_replicate, ADULTS, ALL, SimComponent::get_parameter(), ParamSet::getArg(), Param::getMultiArgs(), ParamSet::getValue(), Param::hasMultipleArgs(), ParamSet::isSet(), NONE, and OFFSPRG.

Referenced by Metapop(), and setParameters().

+ Here is the caller graph for this function:

◆ show_up()

void Metapop::show_up ( )
1242 {
1243  message("Metapop:\n");
1244  message("nbre. of patches: %i(%i)\n", _vPatch.size(),_patchNbr);
1245  message("population size : %i\n", size());
1246  message("K = %i, K_fem = %i, K_mal = %i\n",_patchK, _patchKfem, _patchKmal);
1247  message("patch capacities: \n");
1248  _patchSizes.show_up();
1249  message("Patches:\n");
1250  for(unsigned int i = 0; i < _vPatch.size(); i++)
1251  _vPatch[i]->show_up();
1252 }
void show_up()
Definition: metapop.cc:1241
void show_up()
Definition: tmatrix.h:363

References _patchK, _patchKfem, _patchKmal, _patchNbr, _patchSizes, _vPatch, message(), TMatrix::show_up(), and size().

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ size() [1/9]

unsigned int Metapop::size ( )
inline

Get the total number of individuals present in the population, all sex and age classes together.

311 {return size(ALL);}

References ALL, and size().

Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Cross::create_individual_ancestors(), LCE_Breed_Selection_Disperse::do_breed(), LCE_Breed_Disperse::do_breed_disperse_in_empty_patch(), LCE_Breed::execute(), LCE_BreedAssortativeMating::execute(), LCE_Breed_Disperse::execute(), LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_Disperse_ConstDisp::execute(), LCE_Disperse_EvolDisp::execute(), LCE_Regulation::execute(), LCE_Aging::execute(), LCE_Cross::execute(), LCE_Resize::execute(), LCE_QuantiInit::execute(), LCE_Breed_Quanti::execute(), LCE_Selection_base::execute(), LCE_Init_BDMI::execute(), LCE_NtrlInit::execute(), LCE_Breed_Wolbachia::execute(), TTNeutralGenesFH::FHread(), LCE_Breed_Disperse::get_parent(), getAllIndividuals(), TTNeutralGenesSH::getDxy(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanOffsprgInfection(), TTDispersalSH::getOffsprgMeanDispRate(), FileServices::getSampledPop(), isAlive(), loadFileServices(), loadPopFromTraitFile(), loadSourcePopulation(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), GenotyperFH::prepare_data_table(), retrieve_data(), TTNeutralGenesSH::setAlleleTables(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTNeutralGenesSH::setFst_li(), TTNeutralGenesSH::setFstat(), TTNeutralGenesSH::setFstat_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham(), TTNeutralGenesSH::setFstatWeirCockerham_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham_MS(), TTNeutralGenesSH::setFstMatrix(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs2(), TTWolbachiaSH::setInfectionStats(), TTDeletMutBitstrSH::setLethalEquivalents(), TTNeutralGenesSH::setLociDivCounter(), TTNeutralGenesSH::setNeiGeneticDistance(), setPopulation(), setPopulationFromSource(), setPopulationFromSourceInPreserveMode(), TTQuantiSH::setStats(), show_up(), size(), store_data(), LCE_Breed_base::WrightFisherPopulation(), LCE_Breed_Quanti::WrightFisherPopulation(), TTNeutralGenesFH::write_Fst_i(), and TTNeutralGenesFH::write_varcompWC().

◆ size() [2/9]

unsigned int Metapop::size ( age_idx  IDX)
inline

Returns the size of the container for the appropriate age class for both sexes.

Parameters
IDXthe index of the age class
799 {
800  return size(FEM, IDX) + size(MAL, IDX);
801 }

References FEM, MAL, and size().

◆ size() [3/9]

unsigned int Metapop::size ( age_idx  IDX,
unsigned int  deme 
)
inline
804 {
805  return size(FEM, IDX, deme) + size(MAL, IDX, deme);
806 }

References FEM, MAL, and size().

◆ size() [4/9]

unsigned int Metapop::size ( age_t  AGE)
inline

Simplified interface to get the size of both sexes of the appropriate age class(es) in the whole population.

Parameters
AGEage class flags
343  { return size( FEM, AGE ) + size( MAL, AGE );}

References FEM, MAL, and size().

◆ size() [5/9]

unsigned int Metapop::size ( age_t  AGE,
unsigned int  deme 
)
inline

Simplified interface to get the size of both sexes of the appropriate age class(es) in one patch.

Parameters
AGEage class flags
demethe focal deme
350  { return size( FEM, AGE, deme ) + size( MAL, AGE, deme );}

References FEM, MAL, and size().

◆ size() [6/9]

unsigned int Metapop::size ( sex_t  SEX,
age_idx  IDX 
)
inline

Interface to get the size of a praticular age class and sex class.

Parameters
SEXsex class
IDXindex of age class
809 {
810  unsigned int s = 0;
811  for(unsigned int i = 0; i < _patchNbr; i++)
812  s += _vPatch[i]->size(SEX, IDX);
813  return s;
814 }

References _patchNbr, _vPatch, and size().

◆ size() [7/9]

unsigned int Metapop::size ( sex_t  SEX,
age_idx  IDX,
unsigned int  deme 
)
inline
817 {
818  return _vPatch[deme]->size(SEX, IDX);
819 }

References _vPatch.

◆ size() [8/9]

unsigned int Metapop::size ( sex_t  SEX,
age_t  AGE 
)
inline

Interface to get the size of a praticular age and sex class(es).

Parameters
AGEage class flags
SEXsex class
822 {
823  unsigned int s = 0;
824  for(unsigned int i = 0; i < _vPatch.size(); i++)
825  s += _vPatch[i]->size(SEX, AGE);
826  return s;
827 }

References _vPatch, and size().

◆ size() [9/9]

unsigned int Metapop::size ( sex_t  SEX,
age_t  AGE,
unsigned int  deme 
)
inline

Interface to get the size of a praticular age and sex class within a patch.

Parameters
AGEage class flags
SEXsex class
demethe focal patch
830 {
831  Patch* patch = getPatch(deme);
832  return (patch!=0? patch->size(SEX, AGE) : 0);
833 }
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:256

References getPatch(), and Patch::size().

◆ store_data()

void Metapop::store_data ( BinaryStorageBuffer saver)
virtual

Implements StorableComponent.

453 {
454  unsigned int *sizes[3];
455  unsigned char separator[2] = {'@','P'};
456 
457  sizes[0] = new unsigned int [_patchNbr];
458  sizes[1] = new unsigned int [_patchNbr];
459  sizes[2] = new unsigned int [_patchNbr];
460 
461  for(unsigned int i = 0; i < _patchNbr; ++i) {
462  sizes[0][i] = size(OFFSPRG,i);
463  sizes[1][i] = size(FEM,ADULTS,i);
464  sizes[2][i] = size(MAL,ADULTS,i);
465  }
466  //store the data, begin with pop separator and number of patches:
467  saver->store(&separator, 2 * sizeof(unsigned char));
468 
469  saver->store(&_patchNbr, sizeof(unsigned int));
470  //store the Patch sizes
471  //offspring
472  saver->store(sizes[0], _patchNbr * sizeof(unsigned int));
473  //females adults
474  saver->store(sizes[1], _patchNbr * sizeof(unsigned int));
475  //males adults
476  saver->store(sizes[2], _patchNbr * sizeof(unsigned int));
477 
478  int byte_count = saver->getTotByteRecorded();
479  //record all individual informations: IDs, matings, etc.
480  for(unsigned int i = 0; i < _patchNbr; ++i) {
481  //first offspring:
482  for(unsigned int j = 0; j < _vPatch[i]->size(FEM,OFFSx); ++j)
483  _vPatch[i]->get(FEM, OFFSx, j)->store_data(saver);
484 
485  for(unsigned int j = 0; j < _vPatch[i]->size(MAL,OFFSx); ++j)
486  _vPatch[i]->get(MAL, OFFSx, j)->store_data(saver);
487 
488  //then adults:
489  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
490  _vPatch[i]->get(FEM, ADLTx, j)->store_data(saver);
491 
492  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
493  _vPatch[i]->get(MAL, ADLTx, j)->store_data(saver);
494  }
495 
496 #ifdef _DEBUG_
497  message("Metapop::store_data :stored %ikB of individual data (%i individuals)\n",
498  (saver->getTotByteRecorded()-byte_count)/1024, size());
499 #endif
500 
501  //records the trait sequences:
502  map<trait_t, TraitPrototype *> traits = this->getTraitPrototypes();
503  map<trait_t, TraitPrototype *>::iterator tt = traits.begin();
504  // trait_t type;
505  separator[1] = 'T'; //trait separator = '@T'
506 
507  byte_count = saver->getTotByteRecorded();
508 
509  while(tt != traits.end()) {
510  saver->store(&separator, 2 * sizeof(unsigned char));
511  //store the trait type:
512  saver->store((void*)tt->first.c_str(), TRAIT_T_MAX);
513 
514  //then ask the prototype to store its data:
515  tt->second->store_data(saver);
516  //store the traits data:
517  store_trait(tt->second->get_index(), saver);
518 
519  tt++;
520  }
521 #ifdef _DEBUG_
522  message("Metapop::store_data :stored %ikB of traits data\n",
523  (saver->getTotByteRecorded()-byte_count)/1024);
524 #endif
525 
526  for(unsigned int i = 0; i < 3; i++)
527  delete [] sizes[i];
528 }
off_t getTotByteRecorded() const
Definition: binarystoragebuffer.h:60
void store(void *stream, unsigned int nb_bytes)
Definition: binarystoragebuffer.cc:37
void store_data(BinaryStorageBuffer *saver)
Definition: individual.cc:101
void store_trait(int trait_idx, BinaryStorageBuffer *saver)
Iterates through the individuals containers to store the trait data to a binary file.
Definition: metapop.cc:532

References _patchNbr, _vPatch, ADLTx, ADULTS, FEM, get(), BinaryStorageBuffer::getTotByteRecorded(), IndFactory::getTraitPrototypes(), MAL, message(), OFFSPRG, OFFSx, size(), BinaryStorageBuffer::store(), Individual::store_data(), store_trait(), and TRAIT_T_MAX.

Referenced by BinaryDataSaver::storeData().

+ Here is the caller graph for this function:

◆ store_trait()

void Metapop::store_trait ( int  trait_idx,
BinaryStorageBuffer saver 
)

Iterates through the individuals containers to store the trait data to a binary file.

533 {
534  for(unsigned int i = 0; i < _patchNbr; ++i) {
535  //first offspring:
536  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, OFFSx); ++j) {
537  _vPatch[i]->get(FEM, OFFSx, j)->getTrait(trait_idx)->store_data(saver);
538  }
539 
540  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, OFFSx); ++j) {
541  _vPatch[i]->get(MAL, OFFSx, j)->getTrait(trait_idx)->store_data(saver);
542  }
543  //then adults:
544  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
545  _vPatch[i]->get(FEM, ADLTx, j)->getTrait(trait_idx)->store_data(saver);
546 
547  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
548  _vPatch[i]->get(MAL, ADLTx, j)->getTrait(trait_idx)->store_data(saver);
549  }
550 }
virtual void store_data(BinaryStorageBuffer *saver)=0
Interface to store the component data (e.g. gene values) into a binary buffer.

References _patchNbr, _vPatch, ADLTx, FEM, get(), Individual::getTrait(), MAL, OFFSx, and StorableComponent::store_data().

Referenced by store_data().

+ Here is the caller graph for this function:

◆ updatePatchArray()

void Metapop::updatePatchArray ( )

Called during simulation to modify the meta-population size.

Patch number and capacities are updated, new patches are empty, existing patches containers are untouched.

334 {
335  //remove or add patches as needed:
337  //reset the patch capacities and patch ID:
339 }
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:343

References resizePatchArray(), and updatePatchState().

Referenced by LCE_Resize::buildNewPatchArrayNoBackup(), and updatePopulationParameters().

+ Here is the caller graph for this function:

◆ updatePatchState()

void Metapop::updatePatchState ( )

Update the patch capacities and patch ID (reset to array position).

344 {
345  //reset the patch capacities and patch ID:
346  for(unsigned int i = 0; i < _patchNbr; ++i) {
347  _vPatch[i]->setID(i);
348  _vPatch[i]->set_K((unsigned int)_patchSizes.get(FEM,i) + (unsigned int)_patchSizes.get(MAL,i));
349  _vPatch[i]->set_KFem((unsigned int)_patchSizes.get(FEM,i));
350  _vPatch[i]->set_KMal((unsigned int)_patchSizes.get(MAL,i));
351  }
352 }

References _patchNbr, _patchSizes, _vPatch, FEM, TMatrix::get(), and MAL.

Referenced by LCE_Resize::buildNewPatchArrayWithBackup(), and updatePatchArray().

+ Here is the caller graph for this function:

◆ updatePopulationParameters()

bool Metapop::updatePopulationParameters ( )

Called during simulation to change the population's parameters (temporal argument).

256 {
257  if(!setPopulationParameters()) return false;
259  //if we added patches, they will be empty
260  //fusion of existing pop is not possible here,
261  //the individuals are flushed when deleting the patches
262  return true;
263 }
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:333

References setPopulationParameters(), and updatePatchArray().

Referenced by Metapop().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ BinaryDataLoader::extractPop

Metapop* BinaryDataLoader::extractPop ( std::string &  ,
unsigned int  ,
SimBuilder ,
Metapop  
)
friend

Member Data Documentation

◆ _currentAge

age_t Metapop::_currentAge
private

The current age class, might be changed by the LCEs.

Referenced by getCurrentAge(), setCurrentAge(), setPopulation(), setPopulationFromSource(), and setPopulationFromSourceInPreserveMode().

◆ _currentGeneration

unsigned int Metapop::_currentGeneration
private

The current generation in the generation loop, starts at 1.

Referenced by getCurrentGeneration(), and setCurrentGeneration().

◆ _currentReplicate

unsigned int Metapop::_currentReplicate
private

The current replicate in the replicate loop, starts at 1.

Referenced by getCurrentReplicate(), loadPopFromBinarySource(), loadSourcePopulation(), setCurrentReplicate(), and setPopulation().

◆ _generations

unsigned int Metapop::_generations
private

Number of generations to iterate.

Referenced by getGenerations(), and setGenerations().

◆ _loader

BinaryDataLoader Metapop::_loader
private

A BinaryDataLoader to load a population from a binary data file.

Referenced by loadPopFromBinarySource().

◆ _mpimgr

MPImanager* Metapop::_mpimgr
private

◆ _patchK

unsigned int Metapop::_patchK
private

Patch carrying capacity.

Referenced by getPatchCapacity(), setPopulationParameters(), and show_up().

◆ _patchKfem

unsigned int Metapop::_patchKfem
private

Sex specific carrying capacities.

Referenced by getPatchKFem(), setPatchCapacities(), setPopulationParameters(), and show_up().

◆ _patchKmal

unsigned int Metapop::_patchKmal
private

◆ _patchNbr

◆ _patchSizes

TMatrix Metapop::_patchSizes
private

Matrix of the deme sizes, row 0 for the males, row 1 for the females.

Referenced by buildPatchArray(), getPatchCapacities(), getPatchCapacity(), setPatchCapacities(), setPatchSizes(), show_up(), and updatePatchState().

◆ _replicates

unsigned int Metapop::_replicates
private

Number of replicates to iterate.

Referenced by getReplicates(), loadSourcePopulation(), and setReplicates().

◆ _requiredAge

age_t Metapop::_requiredAge
private

The age class flag that is required to fill the population at the beginning of a replicate.

Referenced by fillPatchFromSource(), setPopulation(), setPopulationFromSource(), setPopulationFromSourceInPreserveMode(), and setSourceParameters().

◆ _source

Metapop* Metapop::_source
private

A source population as loaded from a binary data file, used to build a population.

Referenced by clear(), loadPopFromBinarySource(), loadPopFromTraitFile(), loadSourcePopulation(), setPopulationFromSource(), setPopulationFromSourceInPreserveMode(), and setSourceParameters().

◆ _source_filetype

std::string Metapop::_source_filetype
private

◆ _source_generation

unsigned int Metapop::_source_generation
private

The generation to load from the binary file source file.

Referenced by loadPopFromBinarySource(), and setSourceParameters().

◆ _source_load

bool Metapop::_source_load
private

Flage to specify that the population should be built from the binary loaded source population.

Referenced by isSourceLoad(), setPopulation(), and setSourceParameters().

◆ _source_load_periodicity

unsigned int Metapop::_source_load_periodicity
private

The number of replicates to source from a single source replicate.

Referenced by loadSourcePopulation(), and setPopulation().

◆ _source_name

std::string Metapop::_source_name
private

The base filename of source population files.

Referenced by getSourceName(), loadSourcePopulation(), and setSourceParameters().

◆ _source_param_override

vector< string > Metapop::_source_param_override
private

List of parameters whose values in the source should override local values in the loading pop.

Referenced by loadPopFromBinarySource(), and setSourceParameters().

◆ _source_preserve

bool Metapop::_source_preserve
private

Flag to specify the loading mode, true means the source pop is the actual population.

Referenced by setPopulation(), and setSourceParameters().

◆ _source_replicate_digits

unsigned int Metapop::_source_replicate_digits
private

Number of digits in the replicate counter filename extension.

Referenced by getSourceReplDigits(), loadSourcePopulation(), and setSourceParameters().

◆ _source_replicates

unsigned int Metapop::_source_replicates
private

The number of source files, each file being a different replicate of the source population.

Used to automatically build the source filename.

Referenced by loadSourcePopulation(), setPopulation(), and setSourceParameters().

◆ _source_required_age

std::string Metapop::_source_required_age
private

The age class to fill with the source population.

Referenced by setSourceParameters().

◆ _source_start_at_replicate

unsigned int Metapop::_source_start_at_replicate
private

The replicate number to start loading from.

Referenced by loadSourcePopulation(), and setSourceParameters().

◆ _statHandler

MPStatHandler Metapop::_statHandler
private

The stat handler for the population stats.

Referenced by loadStatServices().

◆ _vPatch

◆ _writer

MPFileHandler* Metapop::_writer
private

The file handler used to save pedigree info.

Referenced by loadFileServices().


The documentation for this class was generated from the following files:

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR