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

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

◆ ~Metapop()

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

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.

843{
844 _vPatch.push_back(patch);
845}
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:94

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.

848{
849 for (unsigned int i = 0; i < num; i++)
850 _vPatch.push_back(new Patch());
851}
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.

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

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.

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

References _patchNbr, _source, _source_filetype, _vPatch, and message().

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.
833{
834 delete _vPatch[i];
835 for (unsigned int k = i; k < _vPatch.size() -1; k++) {
836 _vPatch[k] = _vPatch[k + 1];
837 _vPatch[k]->setID(k);
838 }
839 _vPatch.pop_back();
840}

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.
864{
865 age_idx in_age = (AGE == OFFSPRG? OFFSx : ADLTx);
866 age_idx to_age = (_requiredAge | AGE? in_age : ADLTx);//this to be sure we load some
867
868 Individual* new_ind;
869
870 for(unsigned int j = 0; j < src->size(SEX, in_age); ++j) {
871
872 new_ind = getNewIndividual(); //this correctly sets pointers to TProto's, and params
873
874 (*new_ind) = (*src->get(SEX, in_age, j)); //this should only copy genes
875
876 patch->add(SEX , to_age, new_ind );
877 }
878}
Individual * getNewIndividual()
Creates a blank individual which has to be "decorated" later.
Definition: indfactory.h:85
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
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
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
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
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

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.
930{
931 unsigned int Ktot = 0;
932 unsigned int ind_pos ;
933 Individual* new_ind;
934
935 for(unsigned int i = 0; i < _patchNbr; ++i)
936 Ktot += _vPatch[i]->get_K(SEX);
937
938 if(src_pool.size() < Ktot)
939 warning("Number of %s %s in source metapop (%i) not enough to fill current metapop (%i).\n",
940 (SEX ? "female" : "male"), (AGE == OFFSx ? "offspring" : "adults"),
941 src_pool.size(), Ktot);
942
943 for(unsigned int i = 0; i < _patchNbr; ++i) {
944
945 for(unsigned int j = 0, psize = _vPatch[i]->get_K(SEX); j < psize && src_pool.size() != 0; ++j) {
946
947 new_ind = getNewIndividual();
948
949 ind_pos = RAND::Uniform( src_pool.size() );
950
951 _vPatch[i]->add( SEX, AGE, &( (*new_ind) = *(src_pool[ ind_pos ]) ) );
952
953 src_pool.erase( src_pool.begin() + ind_pos ); //this is without replacement!!!!
954
955 }
956 }
957
958}
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:58

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

References _patchNbr, _vPatch, and flush().

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

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

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

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

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 
)
1225{
1226
1227 for(unsigned int i = 0; i < _vPatch.size(); ++i) {
1228
1229 for(unsigned int j = 0, psize = _vPatch[i]->size(MAL, AGE); j < psize; ++j)
1230 mal_pool.push_back( _vPatch[i]->get(MAL, AGE, j) );
1231
1232 for(unsigned int j = 0, psize = _vPatch[i]->size(FEM, AGE); j < psize; ++j)
1233 fem_pool.push_back( _vPatch[i]->get(FEM, AGE, j) );
1234
1235 }
1236
1237}
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

◆ getPatch()

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

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

257{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_Disperse_EvolDisp::evoldisp(), 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_QuantiModifier::execute(), LCE_Selection_base::execute(), TTDeletMutBitstrFH::FHread(), TTNeutralGenesFH::FHread(), TTQuantiFH::FHread(), LCE_SelectionFH::FHwrite(), MPFileHandler::FHwrite(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTQFreqExtractor::FHwrite(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Cross::generatePedigree(), MPStatHandler::getEmigrantInPatch(), MPStatHandler::getImigrateInPatch(), MPStatHandler::getKolonisersInPatch(), TTDeletMutBitstrSH::getLoad(), LCE_Selection_base::getMaxPatchFitness(), MPStatHandler::getMeanAssignedFecundity(), TTDispersalSH::getMeanDispRate(), MPStatHandler::getMeanEmigrantPerPatch(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTWolbachiaSH::getMeanFemaleInfection_perPatch(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), MPStatHandler::getMeanImigrantPerPatch(), MPStatHandler::getMeanKolonisersPerPatch(), MPStatHandler::getMeanKolonisersProportion(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanMaleInfection_perPatch(), MPStatHandler::getMeanMatings(), TTWolbachiaSH::getMeanOffsprgFemaleInfection_perPatch(), TTWolbachiaSH::getMeanOffsprgInfection(), TTWolbachiaSH::getMeanOffsprgMaleInfection_perPatch(), MPStatHandler::getMeanPatchAge(), MPStatHandler::getMeanPatchDensity(), MPStatHandler::getMeanPatchDensityVariance(), LCE_Selection_base::getMeanPatchFitness(), MPStatHandler::getMeanResidantPerPatch(), TTDispersalSH::getOffsprgMeanDispRate(), MPStatHandler::getPatchAge(), TTDeletMutBitstrSH::getPatchLoad(), MPStatHandler::getResidantInPatch(), 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(), TTQuantiFH::print(), LCE_Disperse_base::reset_counters(), LCE_Selection_base::set_std_rate_of_change(), TTNeutralGenesSH::setAdults_Theta(), TTNeutralGenesSH::setAlleleTables(), TTNeutralGenesSH::setCoaMatrix(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTDeletMutBitstrSH::setDeletStats(), TTDeletMutBitstrSH::setFst(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), TTWolbachiaSH::setInfectionStats(), MPStatHandler::setKinship(), TTDeletMutBitstrSH::setMeanViability(), MPStatHandler::setObsrvdExtinctionRate(), MPStatHandler::setPedegreeCount(), MPStatHandler::setReproductiveStats(), TTNeutralGenesSH::setSibStats(), 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_PLINK_BED(), and TTNeutralGenesFH::write_TAB().

◆ getPatchArray()

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

References _vPatch.

◆ getPatchArraySize()

unsigned int Metapop::getPatchArraySize ( )
inline
270{return _vPatch.size();}

References _vPatch.

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

+ Here is the caller graph for this function:

◆ getPatchCapacities()

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

References _patchK.

◆ getPatchCapacity() [2/2]

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

References _patchSizes, and TMatrix::get().

◆ getPatchKFem()

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

References _patchKfem.

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ getPatchKMal()

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

References _patchKmal.

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ getPatchNbr()

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

References _patchNbr.

Referenced by TTQuantiSH::addAvgPerPatch(), TTQuantiSH::addCovarPerPatch(), TTDispersalSH::addDispPerPatch(), TTQuantiSH::addEigenPerPatch(), TTQuantiSH::addEigenValuesPerPatch(), TTQuantiSH::addEigenVect1PerPatch(), 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::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_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(), TTQFreqExtractor::FHwrite(), LCE_Resize::fillPop(), TTNeutralGenesSH::getDxy(), TTDeletMutBitstrSH::getLoad(), LCE_Selection_base::getMaxFitness(), MPStatHandler::getMeanAssignedFecundity(), TTDispersalSH::getMeanDispRate(), MPStatHandler::getMeanEmigrantPerPatch(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), MPStatHandler::getMeanImigrantPerPatch(), MPStatHandler::getMeanKolonisersPerPatch(), MPStatHandler::getMeanKolonisersProportion(), TTDispersalSH::getMeanMalDispRate(), MPStatHandler::getMeanMatings(), TTWolbachiaSH::getMeanOffsprgInfection(), MPStatHandler::getMeanPatchAge(), MPStatHandler::getMeanPatchDensity(), MPStatHandler::getMeanPatchDensityVariance(), MPStatHandler::getMeanPatchSize(), MPStatHandler::getMeanPatchSizePerSex(), MPStatHandler::getMeanResidantPerPatch(), TTDispersalSH::getOffsprgMeanDispRate(), FileServices::getSampledPop(), LCE_Breed_Wolbachia::hasInfectedFemale(), TTQuantiSH::init(), LCE_Breed_Wolbachia::inoculate_wolbachia(), LCE_Breed_Disperse::mate_selfing(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), TTQuantiFH::print(), LCE_Resize::regulate(), LCE_Cross::sampleAmongPop(), LCE_Selection_base::set_local_optima(), LCE_Patch_Extinction::set_matrix_param(), LCE_Selection_base::set_param_rate_of_change(), LCE_Selection_base::set_std_rate_of_change(), TTNeutralGenesSH::setAdults_Theta(), TTNeutralGenesSH::setAlleleTables(), LCE_Disperse_base::setBaseParameters(), TTNeutralGenesSH::setCoaMatrix(), TTNeutralGenesSH::setCoaMatrixRecorders(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTDeletMutBitstrSH::setDeletStats(), TTNeutralGenesSH::setDxyRecorders(), LCE_Breed_base::setFecundity(), TTDeletMutBitstrSH::setFst(), TTNeutralGenesSH::setFst_li(), TTNeutralGenesSH::setFstat(), TTNeutralGenesSH::setFstat2(), TTNeutralGenesSH::setFstatWeirCockerham(), TTNeutralGenesSH::setFstatWeirCockerham_MS(), TTNeutralGenesSH::setFstMatrix(), TTNeutralGenesSH::setFstMatrixRecorders(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), TTWolbachiaSH::setInfectionStats(), MPStatHandler::setKinship(), TTNeutralGenesSH::setLociDivCounter(), TTDeletMutBitstrSH::setMeanViability(), TTNeutralGenesSH::setNeiGeneticDistance(), TTNeutralGenesSH::setNeiGeneticDistanceRecorders(), MPStatHandler::setObsrvdExtinctionRate(), LCE_Breed_Disperse::setParameters(), LCE_Disperse_EvolDisp::setParameters(), LCE_QuantiInit::setParameters(), LCE_Init_BDMI::setParameters(), LCE_NtrlInit::setParameters(), LCE_Breed_Wolbachia::setParameters(), MPStatHandler::setPedegreeCount(), setPopulationFromSourceInPreserveMode(), LCE_Disperse_base::setPropaguleTargets(), MPStatHandler::setReproductiveStats(), LCE_Selection_base::setSelectionMatrix(), TTNeutralGenesSH::setSibStats(), 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_PLINK_BED(), TTNeutralGenesFH::write_TAB(), and TTNeutralGenesFH::write_varcompWC().

◆ getPatchPtr()

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

A secure version of the getPatch() method.

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

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

◆ getSourceFileType()

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

References _source_filetype.

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ getSourceName()

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

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.

98{
99 if( !(_paramSet->isSet()) ) {
100 return error("parameters in \"population\" are not properly set!\n");
101 }
102
103 if(!setParameters()) return false;
104
106
107 //empty and clean the RecyclingPOOL, safer...
109
110 return true;
111}
void purgeRecyclingPOOL()
Empty the recycling pool.
Definition: indfactory.h:66
void buildPatchArray()
Builds the new population from parameter values.
Definition: metapop.cc:308
virtual bool setParameters()
Definition: metapop.cc:115
bool isSet()
Accessor to the status flag.
Definition: param.h:288
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
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().

+ 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(), TTBDMI_FH::FHwrite(), TTNeutralGenesFH::FHwrite(), TTQuantiFH::FHwrite(), and SimRunner::Replicate_LOOP().

+ Here is the caller graph for this function:

◆ isSourceLoad()

bool Metapop::isSourceLoad ( )
inline
282{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.

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

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

◆ loadPopFromBinarySource()

void Metapop::loadPopFromBinarySource ( string &  filename)

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

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

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

Referenced by loadSourcePopulation().

+ Here is the caller graph for this function:

◆ loadPopFromTraitFile()

void Metapop::loadPopFromTraitFile ( string &  filename)

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

1132{
1133 if(_source != NULL) _source = NULL;
1134//
1135// _source = new Metapop();
1136// _source->setMPImanager( _mpimgr );
1137//
1138// //the population's parameters from current params
1139// _source->set_paramsetFromCopy((*this->get_paramset()));
1140//
1141// //we need this to be able to create new individuals in the source:
1142// _source->init( );
1143// _source->makePrototype(this->getTraitPrototypes());
1144
1145 //now read data from genotype file:
1147
1149
1150 if(!file)
1151 fatal("no file reader exists with source file extension \"%s\".\n",_source_filetype.c_str());
1152
1153 //attach the source pop to the reader
1154 file->set_pop_ptr(this);
1155
1156// cout << "\n --- pop size BEFORE loading inds from genotype file: "<<size()<<endl;
1157
1158 //read the genotypes from files into the source metapop object
1159 file->FHread(filename);
1160
1161
1162// cout << "\n --- pop size AFTER loading inds from genotype file: "<<size()<<endl;
1163
1164 if(size() == 0)
1165 fatal("source population in file \"%s\" is empty.\n",filename.c_str());
1166
1167
1168 if(size( ADULTS ) != 0)
1170
1171 if(size( OFFSPRG ) != 0)
1173
1174// if(_source->size() == 0)
1175// fatal("source population in file \"%s\" is empty.\n",filename.c_str());
1176}
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
void set_pop_ptr(Metapop *pop_ptr)
Definition: filehandler.h:133
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:52
FileHandler * getReader(string &type)
Accessor to a specific file handler specified by its extension string.
Definition: fileservices.cc:456
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:148
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54

References _currentAge, _source, _source_filetype, ADULTS, fatal(), FileHandler::FHread(), SimRunner::get_FileServices(), FileServices::getReader(), SIMenv::MainSim, OFFSPRG, FileHandler::set_pop_ptr(), and size().

Referenced by loadSourcePopulation().

+ Here is the caller graph for this function:

◆ loadSourcePopulation()

void Metapop::loadSourcePopulation ( )

Loads a population from a soure population.

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

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.

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

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
797{//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
798 _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
799 //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
800 _vPatch[from_deme]->remove(SEX, from_age, at);
801 //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
802 // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
803}
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:792

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.

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

References _vPatch, and getPatchPtr().

Referenced by LCE_Resize::buildNewPatchArrayWithBackup(), FileServices::getSampledPop(), 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.

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

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.

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

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

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.

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

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.
1217{
1218 _currentAge ^= LCE->removeAgeClass();
1219 _currentAge |= LCE->addAgeClass();
1220}
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

◆ 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
272{_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
174{_mpimgr = mgr;}

References _mpimgr.

Referenced by BinaryDataLoader::extractPop().

+ Here is the caller graph for this function:

◆ setParameters()

bool Metapop::setParameters ( )
virtual

Implements SimComponent.

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

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.

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

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

Referenced by setPopulationParameters().

+ Here is the caller graph for this function:

◆ setPatchCapacities() [2/4]

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

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

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

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

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

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

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

References _patchNbr.

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ setPatchSizes()

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

References _patchSizes, and TMatrix::copy().

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ setPopulation()

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

Sets the population for the first generation of each replicates.

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

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

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

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.

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

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

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

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

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

Referenced by FileServices::getSampledPop(), and show_up().

+ 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_Cross::create_individual_ancestors(), LCE_Breed::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(), MPStatHandler::getAdultSexRatio(), getAllIndividuals(), TTNeutralGenesSH::getDxy(), MPStatHandler::getFemNumber(), MPStatHandler::getMalNumber(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanOffsprgInfection(), MPStatHandler::getMeanPatchDensity(), MPStatHandler::getMeanPatchDensityVariance(), MPStatHandler::getMeanPatchSize(), MPStatHandler::getMeanPatchSizePerSex(), MPStatHandler::getOffFemNumber(), MPStatHandler::getOffMalNumber(), TTDispersalSH::getOffsprgMeanDispRate(), MPStatHandler::getOffsprgSexRatio(), MPStatHandler::getPatchSize(), MPStatHandler::getPopulationSize(), FileServices::getSampledPop(), isAlive(), loadFileServices(), loadPopFromTraitFile(), loadSourcePopulation(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), retrieve_data(), TTNeutralGenesSH::setAlleleTables(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTNeutralGenesSH::setFst_li(), TTNeutralGenesSH::setFstat(), TTNeutralGenesSH::setFstat2(), TTNeutralGenesSH::setFstatWeirCockerham(), TTNeutralGenesSH::setFstatWeirCockerham_MS(), TTNeutralGenesSH::setFstMatrix(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs2(), TTWolbachiaSH::setInfectionStats(), MPStatHandler::setKinship(), TTDeletMutBitstrSH::setLethalEquivalents(), TTNeutralGenesSH::setLociDivCounter(), TTNeutralGenesSH::setNeiGeneticDistance(), setPopulation(), setPopulationFromSource(), setPopulationFromSourceInPreserveMode(), MPStatHandler::setReproductiveStats(), TTQuantiSH::setStats(), show_up(), size(), store_data(), LCE_Breed_base::WrightFisherPopulation(), LCE_Breed_Quanti::WrightFisherPopulation(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_PLINK_BED(), 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
756{
757 return size(FEM, IDX) + size(MAL, IDX);
758}

References FEM, MAL, and size().

◆ size() [3/9]

unsigned int Metapop::size ( age_idx  IDX,
unsigned int  deme 
)
inline
761{
762 return size(FEM, IDX, deme) + size(MAL, IDX, deme);
763}

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
766{
767 unsigned int s = 0;
768 for(unsigned int i = 0; i < _patchNbr; i++)
769 s += _vPatch[i]->size(SEX, IDX);
770 return s;
771}

References _patchNbr, _vPatch, and size().

◆ size() [7/9]

unsigned int Metapop::size ( sex_t  SEX,
age_idx  IDX,
unsigned int  deme 
)
inline
774{
775 return _vPatch[deme]->size(SEX, IDX);
776}

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
779{
780 unsigned int s = 0;
781 for(unsigned int i = 0; i < _vPatch.size(); i++)
782 s += _vPatch[i]->size(SEX, AGE);
783 return s;
784}

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

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

◆ store_data()

void Metapop::store_data ( BinaryStorageBuffer saver)
virtual

Implements StorableComponent.

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

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.

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

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

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

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

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

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

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

◆ _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.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR