Nemo  2.4.2
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 ( )
53  : _mpimgr(0), _statHandler(), _writer(0),_loader(), _source(0),
58 {
59  set_paramset("population", true, this);
61  add_parameter("patch_capacity",INT,false,false,0,0, upd);
62  add_parameter("patch_nbfem",INT,false,false,0,0, upd);
63  add_parameter("patch_nbmal",INT,false,false,0,0, upd);
64  add_parameter("patch_number",INT,false,false,0,0, upd);
65 
66  add_parameter("pop_output", BOOL, false, false, 0, 0);
67  add_parameter("pop_output_dir", STR, false, false, 0, 0);
68  add_parameter("pop_output_logtime", INT, false, false, 0, 0);
69  add_parameter("pop_output_sample_size", INT, false, false, 0, 0);
70 
72  add_parameter("source_pop",STR,false,false,0,0, upd);
73  add_parameter("source_file_type",STR,false,false,0,0, upd);
74  add_parameter("source_preserve",BOOL,false,false,0,0, upd);
75  add_parameter("source_replicates",INT,false,false,0,0, upd);
76  add_parameter("source_replicate_digit",INT,false,false,0,0, upd);
77  add_parameter("source_start_at_replicate",INT,false,false,0,0, upd);
78  add_parameter("source_generation",INT,false,false,0,0, upd);
79  add_parameter("source_fill_age_class",STR,false,false,0,0, upd);
80  add_parameter("source_parameter_override", STR, false, false, 0, 0, upd);
81 }
MPStatHandler _statHandler
The stat handler for the population stats.
Definition: metapop.h:86
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:101
MPFileHandler * _writer
The file handler used to save pedigree info.
Definition: metapop.h:89
unsigned int _patchKmal
Definition: metapop.h:135
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:106
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:135
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:120
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:131
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:133
bool _source_load
Flage to specify that the population should be built from the binary loaded source population.
Definition: metapop.h:103
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:127
bool updatePopulationParameters()
Called during simulation to change the population's parameters (temporal argument).
Definition: metapop.cc:254
MPImanager * _mpimgr
Definition: metapop.h:83
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:142
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:108
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:147
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:150
BinaryDataLoader _loader
A BinaryDataLoader to load a population from a binary data file.
Definition: metapop.h:97
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:112
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:110
bool setSourceParameters()
Setter for source population parameters.
Definition: metapop.cc:122
unsigned int _generations
Number of generations to iterate.
Definition: metapop.h:140
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: metapop.h:145
Implementation of the ParamUpdaterBase interface.
Definition: param.h:371
virtual void set_paramset(ParamSet *paramset)
Sets the ParamSet member.
Definition: simcomponent.h:84
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:110
#define NONE
No age flag.
Definition: types.h:46
@ BOOL
Definition: types.h:76
@ STR
Definition: types.h:76
@ INT
Definition: types.h:76

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
86 {
87 #ifdef _DEBUG_
88  message("Metapop::~Metapop\n");
89 #endif
90  clear();
91 }
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1190
void message(const char *message,...)
Definition: output.cc:38

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.

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

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.

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

References _vPatch.

◆ buildPatchArray()

void Metapop::buildPatchArray ( )

Builds the new population from parameter values.

Supernumerary patches are deleted. All patches are empty.

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

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.

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

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.
875 {
876  delete _vPatch[i];
877  for (unsigned int k = i; k < _vPatch.size() -1; k++) {
878  _vPatch[k] = _vPatch[k + 1];
879  _vPatch[k]->setID(k);
880  }
881  _vPatch.pop_back();
882 }

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.
869 {
870  age_idx in_age = (AGE == OFFSPRG? OFFSx : ADLTx);
871  age_idx to_age = (_requiredAge | AGE? in_age : ADLTx);//this to be sure we load some
872 
873  Individual* new_ind;
874 
875  for(unsigned int j = 0; j < src->size(SEX, in_age); ++j) {
876 
877  new_ind = getNewIndividual(); //this correctly sets pointers to TProto's, and params
878 
879  (*new_ind) = (*src->get(SEX, in_age, j)); //this should only copy genes
880 
881  patch->add(SEX , to_age, new_ind );
882  }
883 }
Individual * getNewIndividual()
Creates a blank individual which has to be "decorated" later.
Definition: indfactory.h:83
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:496
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:532
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:549
#define OFFSPRG
Offspring age class flag.
Definition: types.h:48
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:39
@ OFFSx
Definition: types.h:40
@ ADLTx
Definition: types.h:40

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

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

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
858 {
859  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
860 }

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
863 {
864  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
865 }

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
853 {
854  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
855 }

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
835 { return getPatchPtr(deme)->get(SEX, AGE, at); }
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:258

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 
)
1223 {
1224 
1225  for(unsigned int i = 0; i < _vPatch.size(); ++i) {
1226 
1227  for(unsigned int j = 0, psize = _vPatch[i]->size(MAL, AGE); j < psize; ++j)
1228  mal_pool.push_back( _vPatch[i]->get(MAL, AGE, j) );
1229 
1230  for(unsigned int j = 0, psize = _vPatch[i]->size(FEM, AGE); j < psize; ++j)
1231  fem_pool.push_back( _vPatch[i]->get(FEM, AGE, j) );
1232 
1233  }
1234 
1235 }
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:310

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
271 {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
288 {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.

255 {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_PLINK(), 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
267 {return &_vPatch;}

References _vPatch.

◆ getPatchArraySize()

unsigned int Metapop::getPatchArraySize ( )
inline

◆ getPatchCapacities()

TMatrix* Metapop::getPatchCapacities ( )
inline
279 {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
277 {return _patchK;}

References _patchK.

◆ getPatchCapacity() [2/2]

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

References _patchSizes, and TMatrix::get().

◆ getPatchKFem()

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

References _patchKfem.

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ getPatchKMal()

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

References _patchKmal.

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ getPatchNbr()

unsigned int Metapop::getPatchNbr ( )
inline
274 {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_PLINK(), 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.

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

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
273 {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
282 {return _source_filetype;}

References _source_filetype.

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ getSourceName()

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

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.

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

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.

307 {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
280 {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.

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

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.

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

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::getInputArg(), 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).

1137 {
1138  if(_source != NULL) delete _source;
1139 
1140  _source = new Metapop();
1142 
1143  //the population's parameters from current params
1145 
1146  //we need this to be able to create new individuals in the source:
1147  _source->init( );
1149 
1150  //now read data from genotype file:
1152 
1153  FileHandler* file = FS->getReader(_source_filetype);
1154 
1155  if(!file)
1156  fatal("no file reader exists with source file extension \"%s\".\n",_source_filetype.c_str());
1157 
1158  message("\n>>>> Reading trait's genetics from file \"%s\"\n", filename.c_str());
1159 
1160  //attach the source pop to the reader
1161  file->set_pop_ptr(_source);
1162 
1163 // cout << "\n --- pop size BEFORE loading inds from genotype file: "<<size()<<endl;
1164 
1165  //read the genotypes from files into the source metapop object
1166  file->FHread(filename);
1167 
1168  if(_source->size() == 0)
1169  fatal("source population in file \"%s\" is empty.\n",filename.c_str());
1170 
1171 // cout << "\n --- pop size AFTER loading inds from genotype file: "<<size()<<endl;
1172 
1173 }
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:51
void set_pop_ptr(Metapop *pop_ptr)
Definition: filehandler.h:135
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:50
FileHandler * getReader(string &type)
Accessor to a specific file handler specified by its extension string.
Definition: fileservices.cc:531
void makePrototype(map< trait_t, TraitPrototype * > TTlist)
Creates the individuals prototype from the selected trait prototypes.
Definition: indfactory.cc:48
std::map< trait_t, TraitPrototype * > & getTraitPrototypes()
Accessor to the list of TraitPrototype's.
Definition: indfactory.h:138
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches),...
Definition: metapop.cc:95
void setMPImanager(MPImanager *mgr)
Definition: metapop.h:172
Metapop()
Definition: metapop.cc:53
virtual void set_paramsetFromCopy(const ParamSet &PSet)
Reset the set of parameters from a another set.
Definition: simcomponent.h:101
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:106
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:152

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.

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

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.

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

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
839 {//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
840  _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
841  //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
842  _vPatch[from_deme]->remove(SEX, from_age, at);
843  //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
844  // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
845 }
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:834

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.

683 {
684  for(unsigned int i = 0; i < _patchNbr; ++i) {
685 
686  //first offspring:
687  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, OFFSx); ++j){
688  _vPatch[i]->get(FEM, OFFSx, j)->getTrait(trait_idx)->retrieve_data(loader);
689  }
690 
691  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, OFFSx); ++j){
692  _vPatch[i]->get(MAL, OFFSx, j)->getTrait(trait_idx)->retrieve_data(loader);
693  }
694 
695  //then adults:
696  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
697  _vPatch[i]->get(FEM, ADLTx, j)->getTrait(trait_idx)->retrieve_data(loader);
698 
699  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
700  _vPatch[i]->get(MAL, ADLTx, j)->getTrait(trait_idx)->retrieve_data(loader);
701  }
702 }
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:275
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.
868 {
869  Patch* patch = getPatchPtr(i);
870  _vPatch.erase(_vPatch.begin() + i);
871  return patch;
872 }

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.

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

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.

236 {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.

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

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.

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

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.
301 {_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.
1215 {
1216  _currentAge ^= LCE->removeAgeClass();
1217  _currentAge |= LCE->addAgeClass();
1218 }
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
296 {_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
295 {_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
270 {_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
172 {_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.

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

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.

356 {
358 
359  for(unsigned int i = 0; i < _patchNbr; ++i) {
362  }
363 }
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:159
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:101

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.
392 {
393  double* size_array;
394  unsigned int size_, Knum;
395  TMatrix popK;
396 
397  _paramSet->getMatrix(param, &popK);
398 
399  Knum = popK.length();
400 
401  if(_patchNbr == 0 || _patchNbr < Knum) _patchNbr = Knum;
402 
404 
405  size_array = popK.get();
406 
407  if(SEX == FEM)
408  size_ = _patchKmal;
409  else
410  size_ = _patchKfem;
411 
412  for(unsigned int i = 0; i < _patchNbr; ++i) {
413  _patchSizes.set(SEX, i, (unsigned int)size_array[i % Knum]);
414  _patchSizes.set(!SEX, i, size_);
415  }
416 }
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:312
unsigned int length() const
Returns the number of elements in the matrix.
Definition: tmatrix.h:216

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.
368 {
369  double* size_array;
370  unsigned int Knum;
371  TMatrix popK;
372 
373  _paramSet->getMatrix(param, &popK);
374 
375  Knum = popK.length();
376 
377  if(_patchNbr == 0 || _patchNbr < Knum) _patchNbr = Knum;
378 
380 
381  size_array = popK.get();
382 
383  for(unsigned int i = 0; i < _patchNbr; ++i) {
384  _patchSizes.set(FEM, i, (unsigned int)size_array[i % Knum]/2);
385  _patchSizes.set(MAL, i, (unsigned int)size_array[i % Knum]/2);
386  }
387 }

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

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
285 {_patchNbr = val;}

References _patchNbr.

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ setPatchSizes()

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

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.

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

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

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

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.

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

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
272 {_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.

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

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

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.

310 {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
798 {
799  return size(FEM, IDX) + size(MAL, IDX);
800 }

References FEM, MAL, and size().

◆ size() [3/9]

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

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
342  { 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
349  { 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
808 {
809  unsigned int s = 0;
810  for(unsigned int i = 0; i < _patchNbr; i++)
811  s += _vPatch[i]->size(SEX, IDX);
812  return s;
813 }

References _patchNbr, _vPatch, and size().

◆ size() [7/9]

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

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
821 {
822  unsigned int s = 0;
823  for(unsigned int i = 0; i < _vPatch.size(); i++)
824  s += _vPatch[i]->size(SEX, AGE);
825  return s;
826 }

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
829 {
830  Patch* patch = getPatch(deme);
831  return (patch!=0? patch->size(SEX, AGE) : 0);
832 }
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:255

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

◆ store_data()

void Metapop::store_data ( BinaryStorageBuffer saver)
virtual

Implements StorableComponent.

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

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.

532 {
533  for(unsigned int i = 0; i < _patchNbr; ++i) {
534  //first offspring:
535  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, OFFSx); ++j) {
536  _vPatch[i]->get(FEM, OFFSx, j)->getTrait(trait_idx)->store_data(saver);
537  }
538 
539  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, OFFSx); ++j) {
540  _vPatch[i]->get(MAL, OFFSx, j)->getTrait(trait_idx)->store_data(saver);
541  }
542  //then adults:
543  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
544  _vPatch[i]->get(FEM, ADLTx, j)->getTrait(trait_idx)->store_data(saver);
545 
546  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
547  _vPatch[i]->get(MAL, ADLTx, j)->getTrait(trait_idx)->store_data(saver);
548  }
549 }
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.

333 {
334  //remove or add patches as needed:
336  //reset the patch capacities and patch ID:
338 }
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:342

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).

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

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).

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

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.2 by  doxygen 1.9.1

Catalogued on GSR