Nemo  2.3.46
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 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 ()
 
Population state interface
unsigned int getCurrentReplicate ()
 
unsigned int getCurrentGeneration ()
 
void setCurrentReplicate (unsigned int repl)
 
void setCurrentGeneration (unsigned int gen)
 
age_t getCurrentAge ()
 
void setCurrentAge (age_t age)
 Sets the age flag. More...
 
void setCurrentAge (LifeCycleEvent *LCE)
 Set the age flag from a LifeCycleEvent object. More...
 
bool isAlive ()
 Checks if the population still contains at least one individual in any sex or age class. More...
 
unsigned int size ()
 Get the total number of individuals present in the population, all sex and age classes together. More...
 
unsigned int size (sex_t SEX, age_t AGE)
 Interface to get the size of a praticular age and sex class(es). More...
 
unsigned int size (sex_t SEX, age_idx IDX)
 Interface to get the size of a praticular age class and sex class. More...
 
unsigned int size (age_idx IDX)
 Returns the size of the container for the appropriate age class for both sexes. More...
 
unsigned int size (age_idx IDX, unsigned int deme)
 
unsigned int size (sex_t SEX, age_idx IDX, unsigned int deme)
 
unsigned int size (sex_t SEX, age_t AGE, unsigned int deme)
 Interface to get the size of a praticular age and sex class within a patch. More...
 
unsigned int size (age_t AGE)
 Simplified interface to get the size of both sexes of the appropriate age class(es) in the whole population. More...
 
unsigned int size (age_t AGE, unsigned int deme)
 Simplified interface to get the size of both sexes of the appropriate age class(es) in one patch. More...
 
Individualget (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
 Returns a pointer to the appropriate individual. More...
 
void move (sex_t SEX, age_idx from_age, unsigned int from_deme, age_idx to_age, unsigned int to_deme, unsigned int at)
 Moves an individual from a deme to an other one, both demes sizes are modified. More...
 
void flush ()
 Removes all individual pointers and flush them into the recycling pool. More...
 
void flush (sex_t SEX, age_idx AGE)
 Removes all individual pointers of the appropriate sex and age class and flush them into the recycling pool. More...
 
void flush (age_idx AGE)
 Removes all individual pointers of both sexes and specified age class and flush them into the recycling pool. More...
 
void flush (age_t AGE)
 Removes all individual pointers of both sexes and specified age class(es) and flush them into the recycling pool. More...
 
PatchremovePatch (unsigned int i)
 Removes a patch from the patch array and returns it pointer. More...
 
void deletePatch (unsigned int i)
 Removes a patch from the patch array and deletes it and its content. More...
 
void addPatch (Patch *patch)
 Adds a patch to the population. More...
 
void addPatch (unsigned int num)
 Adds num patches to the population. More...
 
- Public Member Functions inherited from StorableComponent
virtual ~StorableComponent ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 Sets a new ParamSet and name it. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 
- 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...
 
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...
 
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
 Patch init sizes. 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...
 

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

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

Referenced by loadPopFromTraitFile().

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

References clear(), and message().

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

Member Function Documentation

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.

References _vPatch.

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

834 {
835  _vPatch.push_back(patch);
836 }
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
void Metapop::addPatch ( unsigned int  num)
inline

Adds num patches to the population.

References _vPatch.

839 {
840  for (unsigned int i = 0; i < num; i++)
841  _vPatch.push_back(new Patch());
842 }
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
void Metapop::buildPatchArray ( )

Builds the new population from parameter values.

Supernumerary patches are deleted. All patches are empty.

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

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

283 {
285 
286  //set the population capacities:
287  for(unsigned int i = 0; i < _patchNbr; ++i) {
288  _vPatch[i]->flush(this);
289  _vPatch[i]->init((unsigned int)_patchSizes.get(FEM,i), (unsigned int)_patchSizes.get(MAL,i), i);
290  }
291 }
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc:295
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
Definition: types.h:37
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
Definition: types.h:37
void Metapop::clear ( )

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

References _patchNbr, and _vPatch.

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

1017 {
1018  unsigned int i;
1019 
1020  for(i = 0; i < _vPatch.size(); ++i) delete _vPatch[i];
1021 
1022  _vPatch.clear();
1023 
1024  _patchNbr = 0;
1025 
1026  // purgeRecyclingPOOL();
1027 
1028  // if(_source) delete _source;
1029  // _source = NULL;
1030 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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.

References _vPatch.

Referenced by LCE_Resize::removeDesignatedPatch().

824 {
825  delete _vPatch[i];
826  for (unsigned int k = i; k < _vPatch.size() -1; k++) {
827  _vPatch[k] = _vPatch[k + 1];
828  _vPatch[k]->setID(k);
829  }
830  _vPatch.pop_back();
831 }
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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.

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

Referenced by setPopulationFromSourceInPreserveMode().

800 {
801  age_idx in_age = (AGE == OFFSPRG? OFFSx : ADLTx);
802  age_idx to_age = (_requiredAge | AGE? in_age : ADLTx);//this to be sure we load some
803 
804  Individual* new_ind;
805 
806  for(unsigned int j = 0; j < src->size(SEX, in_age); ++j) {
807  new_ind = getNewIndividual(); //this correctly sets pointers to TProto's, and params
808  (*new_ind) = (*src->get(SEX, in_age, j)); //this should only copy genes
809  patch->add(SEX , to_age, new_ind );
810  }
811 }
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
Individual * getNewIndividual()
Creates a blank individual which has to be "decorated" later.
Definition: indfactory.h:85
Definition: types.h:42
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:123
Definition: types.h:42
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:523
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
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:540
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.

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

Referenced by setPopulationFromSource().

863 {
864  unsigned int Ktot = 0;
865  unsigned int ind_pos ;
866  Individual* new_ind;
867 
868  for(unsigned int i = 0; i < _patchNbr; ++i)
869  Ktot += _vPatch[i]->get_K(SEX);
870 
871  if(src_pool.size() < Ktot)
872  warning("Number of %s %s in source metapop (%i) not enough to fill current metapop (%i).\n",
873  (SEX ? "female" : "male"), (AGE == OFFSx ? "offspring" : "adults"),
874  src_pool.size(), Ktot);
875 
876  for(unsigned int i = 0; i < _patchNbr; ++i) {
877 
878  for(unsigned int j = 0, psize = _vPatch[i]->get_K(SEX); j < psize && src_pool.size() != 0; ++j) {
879 
880  new_ind = getNewIndividual();
881 
882  ind_pos = RAND::Uniform( src_pool.size() );
883 
884  _vPatch[i]->add( SEX, AGE, &( (*new_ind) = *(src_pool[ ind_pos ]) ) );
885 
886  src_pool.erase( src_pool.begin() + ind_pos ); //this is without replacement!!!!
887 
888  }
889  }
890 
891 }
Individual * getNewIndividual()
Creates a blank individual which has to be "decorated" later.
Definition: indfactory.h:85
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void warning(const char *str,...)
Definition: output.cc:56
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
Definition: types.h:42
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
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()

References _patchNbr, and _vPatch.

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

797 {
798  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(this);
799 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:796
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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

References _patchNbr, _vPatch, and flush().

802 {
803  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
804 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:796
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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

References _patchNbr, _vPatch, and flush().

807 {
808  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
809 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:796
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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

References _patchNbr, _vPatch, and flush().

812 {
813  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
814 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:796
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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

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

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

784 { return getPatchPtr(deme)->get(SEX, AGE, at); }
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
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:523
void Metapop::getAllIndividuals ( age_idx  AGE,
deque< Individual * > &  fem_pool,
deque< Individual * > &  mal_pool 
)

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

Referenced by setPopulationFromSource().

1043 {
1044 
1045  for(unsigned int i = 0; i < _vPatch.size(); ++i) {
1046 
1047  for(unsigned int j = 0, psize = _vPatch[i]->size(MAL, AGE); j < psize; ++j)
1048  mal_pool.push_back( _vPatch[i]->get(MAL, AGE, j) );
1049 
1050  for(unsigned int j = 0, psize = _vPatch[i]->size(FEM, AGE); j < psize; ++j)
1051  fem_pool.push_back( _vPatch[i]->get(FEM, AGE, j) );
1052 
1053  }
1054 
1055 }
Definition: types.h:37
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
Definition: types.h:37
age_t Metapop::getCurrentAge ( )
inline

References _currentAge.

Referenced by LCE_Resize::execute(), TTQuantiFH::FHwrite(), LCE_Resize::fillPop(), loadSourcePopulation(), setPopulationFromSourceInPreserveMode(), TTNeutralGenesFH::write_freq(), and TTNeutralGenesFH::write_varcompWC().

289 {return _currentAge;}
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:148
unsigned int Metapop::getCurrentReplicate ( )
inline
unsigned int Metapop::getGenerations ( )
inline

References _generations.

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

267 {return _generations;}
unsigned int _generations
Patch init sizes.
Definition: metapop.h:138
Patch* Metapop::getPatch ( unsigned int  i)
inline

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

Referenced by LCE_Selection_base::addPhenotypicSD(), LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Breed_Disperse::do_breed_disperse(), LCE_Disperse_EvolDisp::evoldisp(), LCE_Regulation::execute(), LCE_Aging::execute(), LCE_Disperse_ConstDisp::execute(), LCE_Patch_Extinction::execute(), LCE_Cross::execute(), LCE_Breed_Disperse::execute(), LCE_Disperse_EvolDisp::execute(), LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_Selection_base::execute(), LCE_Breed::execute(), TTNeutralGenesFH::FHread(), TTDeletMutBitstrFH::FHread(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTQFreqExtractor::FHwrite(), LCE_SelectionFH::FHwrite(), MPFileHandler::FHwrite(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Cross::generatePedigree(), TTDeletMutBitstrSH::getLoad(), LCE_Selection_base::getMaxPatchFitness(), TTDispersalSH::getMeanDispRate(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTWolbachiaSH::getMeanFemaleInfection_perPatch(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanMaleInfection_perPatch(), TTWolbachiaSH::getMeanOffsprgFemaleInfection_perPatch(), TTWolbachiaSH::getMeanOffsprgInfection(), TTWolbachiaSH::getMeanOffsprgMaleInfection_perPatch(), LCE_Selection_base::getMeanPatchFitness(), TTDispersalSH::getOffsprgMeanDispRate(), TTDeletMutBitstrSH::getPatchLoad(), LCE_Breed_Wolbachia::hasInfectedFemale(), LCE_Breed_Wolbachia::inoculate_wolbachia(), LCE_Disperse_ConstDisp::Migrate(), LCE_Disperse_ConstDisp::MigratePatch(), LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder(), TTQuantiFH::print(), LCE_Disperse_base::reset_counters(), LCE_Selection_base::set_std_rate_of_change(), TTNeutralGenesSH::setAlleleTables(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTDeletMutBitstrSH::setDeletStats(), TTDeletMutBitstrSH::setFst(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), TTWolbachiaSH::setInfectionStats(), TTDeletMutBitstrSH::setMeanViability(), TTBDMI_SH::setStats(), TTDeletMutBitstrSH::setViability(), size(), LCE_Disperse_base::swapPostDisp(), LCE_Breed_Wolbachia::wolbachia_model_1(), LCE_Breed_Wolbachia::wolbachia_model_2(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), and TTNeutralGenesFH::write_TAB().

251 {return (i > _vPatch.size() -1 ? 0 : _vPatch[i]);}
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
deque< Patch* >* Metapop::getPatchArray ( )
inline

References _vPatch.

263 {return &_vPatch;}
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
unsigned int Metapop::getPatchArraySize ( )
inline

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

264 {return _vPatch.size();}
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
TMatrix* Metapop::getPatchCapacities ( )
inline

References _patchSizes.

Referenced by LCE_Resize::updatePatchCapacities().

275 {return &_patchSizes;}
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
unsigned int Metapop::getPatchCapacity ( )
inline

References _patchK.

273 {return _patchK;}
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:129
unsigned int Metapop::getPatchCapacity ( sex_t  SEX,
unsigned int  patch 
)
inline

References TMatrix::get().

274 {return (unsigned int)_patchSizes.get(SEX, patch);}
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
unsigned int Metapop::getPatchKFem ( )
inline

References _patchKfem.

Referenced by LCE_Resize::execute().

271 {return _patchKfem;}
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:131
unsigned int Metapop::getPatchKMal ( )
inline

References _patchKmal.

Referenced by LCE_Resize::execute().

272 {return _patchKmal;}
unsigned int _patchKmal
Definition: metapop.h:131
unsigned int Metapop::getPatchNbr ( )
inline

References _patchNbr.

Referenced by TTQuantiSH::addAvgPerPatch(), TTQuantiSH::addCovarPerPatch(), TTQuantiSH::addEigenPerPatch(), TTQuantiSH::addEigenValuesPerPatch(), TTQuantiSH::addEigenVect1PerPatch(), MPStatHandler::addIndNumPerPatch(), LCE_SelectionSH::addMeanPerPatch(), MPStatHandler::addPatchAge(), TTQuantiSH::addSkewPerPatch(), TTBDMI_SH::addStats(), TTQuantiSH::addVarPerPatch(), LCE_SelectionSH::addVarPerPatch(), TTNeutralGenesSH::allocateTables(), LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Resize::buildNewPatchArrayWithBackup(), LCE_Breed_Disperse::do_breed_disperse(), LCE_QuantiInit::execute(), LCE_Regulation::execute(), LCE_NtrlInit::execute(), LCE_Aging::execute(), LCE_Disperse_ConstDisp::execute(), LCE_Patch_Extinction::execute(), LCE_Cross::execute(), LCE_Breed_Disperse::execute(), LCE_Disperse_EvolDisp::execute(), LCE_Breed_Selection::execute(), LCE_Resize::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_Selection_base::execute(), LCE_Init_BDMI::execute(), LCE_Breed::execute(), TTNeutralGenesFH::FHread(), TTDeletMutBitstrFH::FHread(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTQFreqExtractor::FHwrite(), LCE_SelectionFH::FHwrite(), MPFileHandler::FHwrite(), LCE_Resize::fillPop(), TTNeutralGenesSH::getDxy(), TTDeletMutBitstrSH::getLoad(), LCE_Selection_base::getMaxFitness(), TTDispersalSH::getMeanDispRate(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanOffsprgInfection(), TTDispersalSH::getOffsprgMeanDispRate(), LCE_Breed_Wolbachia::hasInfectedFemale(), TTQuantiSH::init(), LCE_Breed_Wolbachia::inoculate_wolbachia(), LCE_Breed_Disperse::mate_selfing(), TTQuantiFH::print(), LCE_Resize::regulate(), LCE_Cross::sampleAmongPop(), LCE_Selection_base::set_local_optima(), LCE_Patch_Extinction::set_matrix_param(), LCE_Selection_base::set_std_rate_of_change(), TTNeutralGenesSH::setAlleleTables(), LCE_Disperse_base::setBaseParameters(), 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(), TTNeutralGenesSH::setLociDivCounter(), TTDeletMutBitstrSH::setMeanViability(), TTNeutralGenesSH::setNeiGeneticDistance(), TTNeutralGenesSH::setNeiGeneticDistanceRecorders(), LCE_QuantiInit::setParameters(), LCE_NtrlInit::setParameters(), LCE_Breed_Disperse::setParameters(), LCE_Disperse_EvolDisp::setParameters(), LCE_Breed_Wolbachia::setParameters(), LCE_Init_BDMI::setParameters(), setPopulationFromSourceInPreserveMode(), LCE_Disperse_base::setPropaguleTargets(), LCE_Selection_base::setSelectionMatrix(), 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(), TTNeutralGenesFH::write_freq(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_TAB(), and TTNeutralGenesFH::write_varcompWC().

270 {return _patchNbr;}
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
Patch* Metapop::getPatchPtr ( unsigned int  patch)
inline

A secure version of the getPatch() method.

References fatal().

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

254  {
255  if(!(patch < _vPatch.size()))
256  fatal("Metapop::getPatchPtr()::_vPatch overflow (id=%i nb=%i)\n", patch, _vPatch.size());
257 
258  if (_vPatch[patch] == NULL) fatal("Metapop::getPatchPtr()::NULL ptr\n");
259 
260  return _vPatch[patch];
261  }
void fatal(const char *str,...)
Definition: output.cc:90
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
unsigned int Metapop::getReplicates ( )
inline

References _replicates.

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

269 {return _replicates;}
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:140
string Metapop::getSourceFileType ( )
inline

References _source_filetype.

Referenced by SimRunner::run().

278 {return _source_filetype;}
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:116
string Metapop::getSourceName ( )
inline

References _source_name.

Referenced by SimRunner::run().

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

References _source_replicate_digits.

279 {return _source_replicate_digits;}
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:108
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.

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

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

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

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

References size().

Referenced by SimRunner::Cycle(), TTNeutralGenesFH::FHwrite(), TTQuantiFH::FHwrite(), MPFileHandler::FHwrite(), and SimRunner::Replicate_LOOP().

299 {return size() != 0;}
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
bool Metapop::isSourceLoad ( )
inline

References _source_load.

Referenced by SimRunner::run().

276 {return _source_load;}
bool _source_load
Flage to specify that the population should be built from the binary loaded source population...
Definition: metapop.h:103
void Metapop::loadFileServices ( FileServices loader)
virtual

Implements SimComponent.

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

247 {
248 
249  if(get_parameter("pop_output")->isSet()){
250 
251  if(_writer == 0) _writer = new MPFileHandler();
252 
253  int size = 0;
254 
255  if(get_parameter("pop_output_patch_sample_size")->isSet())
256  size = get_parameter_value("pop_output_patch_sample_size");
257 
258  _writer->setOption(size);
259 
260  Param* param = get_parameter("pop_output_logtime");
261 
262  if(param->isMatrix()) {
263 
264  TMatrix temp;
265  param->getMatrix(&temp);
266  _writer->set_multi(true, true, 1, &temp, get_parameter("pop_output_dir")->getArg());
267 
268  } else // rpl_per, gen_per, rpl_occ, gen_occ, rank (0), path, self-ref
269  _writer->set(true, true, 1, (param->isSet() ? (int)param->getValue() : 0),
270  0, get_parameter("pop_output_dir")->getArg());
271 
272  loader->attach(_writer);
273 
274  } else if(_writer) {
275  delete _writer;
276  _writer = NULL;
277  }
278 }
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:57
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
double getValue()
Returns the argument value according to its type.
Definition: param.cc:319
MPFileHandler * _writer
The file handler used to save pedigree info.
Definition: metapop.h:90
void setOption(int size)
Definition: metapop.h:732
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
Definition: metapop.h:723
virtual void set_multi(bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path)
Definition: filehandler.h:197
string getArg()
Definition: param.h:136
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 Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
bool isSet()
Definition: param.h:138
void Metapop::loadPopFromBinarySource ( string &  filename)

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

References _loader, _source, _source_generation, BinaryDataLoader::extractPop(), fatal(), IndFactory::getNewIndividual(), and SIMenv::MainSim.

Referenced by loadSourcePopulation().

941 {
942  Individual *new_ind, *src_tmp;
943 
945  fatal("Metapop::loadPopFromBinarySource:could not extract pop from binary file \"%s\"\n",filename.c_str());
946 
947  //check traits parameters (mainly sizes)
948  new_ind = getNewIndividual();
949  src_tmp = _source->getNewIndividual();
950 
951  if( (*new_ind) != (*src_tmp) ) {
952  fatal("loading population from source file failed: trait genetic architecture differs.\n");
953  }
954 
955  delete new_ind;
956  delete src_tmp;
957 
958 // if(_source_preserve) {
959 
960  //basic checks:
961 // if(_source->getPatchNbr() != _patchNbr)
962 // fatal("loading population from source file failed: preserve mode forbids difference in number of patches\n");
963 
964 // if(_source->getPatchKFem() != _patchKfem || _source->getPatchKMal() != _patchKmal)
965 // fatal("loading population from source file failed: preserve mode forbids difference in patch sizes\n");
966 // }
967 
968 }
BinaryDataLoader _loader
A BinaryDataLoader to load a population from a binary data file.
Definition: metapop.h:97
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:112
static SimRunner * MainSim
Definition: simenv.h:42
void fatal(const char *str,...)
Definition: output.cc:90
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, etc. ).
Definition: individual.h:49
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
Metapop * extractPop(string &filename, unsigned int generation, SimBuilder *sim, Metapop *popPtr)
Definition: binarydataloader.cc:130
void Metapop::loadPopFromTraitFile ( string &  filename)

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

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

Referenced by loadSourcePopulation().

974 {
975  if(_source != NULL) delete _source;
976 
977  _source = new Metapop();
979 
980  //the population's parameters from current params
982 
983  //we need this to be able to create new individuals in the source:
984  _source->init( );
986 
987  //now read data from genotype file:
989 
991 
992  if(!file) fatal("no file reader exists with source file extension \"%s\".\n",_source_filetype.c_str());
993 
994  file->set_pop_ptr(_source);
995 
996  file->FHread(filename);
997 
998  if(_source->size() == 0) fatal("source population in file \"%s\" is empty.\n",filename.c_str());
999 }
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:116
MPImanager * _mpimgr
Definition: metapop.h:84
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
void set_pop_ptr(Metapop *pop_ptr)
Definition: filehandler.h:133
void makePrototype(map< trait_t, TraitPrototype * > TTlist)
Creates the individuals prototype from the selected trait prototypes.
Definition: indfactory.cc:50
static SimRunner * MainSim
Definition: simenv.h:42
void fatal(const char *str,...)
Definition: output.cc:90
std::map< trait_t, TraitPrototype * > & getTraitPrototypes()
Accessor to the list of TraitPrototype's.
Definition: indfactory.h:117
Metapop()
Definition: metapop.cc:54
void setMPImanager(MPImanager *mgr)
Definition: metapop.h:170
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:108
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches), the prototypes and the life cycle.
Definition: metapop.cc:95
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
virtual void set_paramsetFromCopy(const ParamSet &PSet)
Reset the set of parameters from a another set.
Definition: simcomponent.h:103
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
virtual void FHread(string &filename)=0
Default input function.
FileHandler * getReader(string &type)
Accessor to a specific file handler specified by its extension string.
Definition: fileservices.cc:284
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:146
void Metapop::loadSourcePopulation ( )

Loads a population from a soure population.

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

896 {
897  std::string filename;
898 
899  if(_source_replicates != 0) {
900  //find the replicate string of the source file
901  ostringstream rpl;
902  rpl.fill('0');
903  rpl.width(_source_replicate_digits);
904 
907  else if (_source_replicates != 1)
908  //less replicates in source, reload the same repl every `source_replicates'
909  rpl << ((_currentReplicate-1) / _source_load_periodicity) + 1;
910  else
911  rpl << 1; //a bit dumb but just in case...
912 
913  filename = _source_name + "_" + rpl.str() + _source_filetype;
914 
915  } else {
916 
917  filename = _source_name;
918 
919  }
920 
921  if(_source_filetype.compare(".bin") == 0)
922  loadPopFromBinarySource(filename);
923  else
924  loadPopFromTraitFile(filename);
925 
926  if(_source->size() == 0) fatal("source population is empty!\n");
927  else {
930  }
931 
932 #ifdef _DEBUG_
933  message("source pop loaded: offspring: %i f, %i m; adults: %i f, %i m\n", _source->size(FEM,OFFSPRG),
935 #endif
936 }
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:116
void message(const char *message,...)
Definition: output.cc:40
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:120
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:106
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:110
void fatal(const char *str,...)
Definition: output.cc:90
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:145
std::string _source_name
The base filename of source population files.
Definition: metapop.h:114
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:293
Definition: types.h:37
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
void loadPopFromTraitFile(string &filename)
Loads a population from a trait's data file (text file).
Definition: metapop.cc:973
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:140
void loadPopFromBinarySource(string &filename)
Loads the population from a binary data file when setting the first generation of a replicate...
Definition: metapop.cc:940
age_t getCurrentAge()
Definition: metapop.h:289
Definition: types.h:37
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:108
virtual void Metapop::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

References StatServices::attach().

232 {loader->attach(&_statHandler);}
MPStatHandler _statHandler
The stat handler for the population stats.
Definition: metapop.h:87
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:177
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

References _vPatch.

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

788 {//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
789  _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
790  //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
791  _vPatch[from_deme]->remove(SEX, from_age, at);
792  //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
793  // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
794 }
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
void Metapop::read_trait ( int  trait_idx,
BinaryStorageBuffer loader 
)

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

References _patchNbr, _vPatch, ADLTx, FEM, MAL, and OFFSx.

Referenced by retrieve_data().

659 {
660  for(unsigned int i = 0; i < _patchNbr; ++i) {
661 
662  //first offspring:
663  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, OFFSx); ++j){
664  _vPatch[i]->get(FEM, OFFSx, j)->getTrait(trait_idx)->retrieve_data(loader);
665  }
666 
667  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, OFFSx); ++j){
668  _vPatch[i]->get(MAL, OFFSx, j)->getTrait(trait_idx)->retrieve_data(loader);
669  }
670 
671  //then adults:
672  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
673  _vPatch[i]->get(FEM, ADLTx, j)->getTrait(trait_idx)->retrieve_data(loader);
674 
675  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
676  _vPatch[i]->get(MAL, ADLTx, j)->getTrait(trait_idx)->retrieve_data(loader);
677  }
678 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
Definition: types.h:42
Definition: types.h:37
Definition: types.h:42
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
Definition: types.h:37
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.

References _vPatch, and getPatchPtr().

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

817 {
818  Patch* patch = getPatchPtr(i);
819  _vPatch.erase(_vPatch.begin() + i);
820  return patch;
821 }
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
void Metapop::reset ( )

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

References _patchNbr, and _vPatch.

Referenced by LCE_Breed_Wolbachia::execute().

1005 {
1006  unsigned int i;
1007 
1008  for(i = 0; i < _patchNbr; ++i) {
1009  _vPatch[i]->flush(this);
1010  _vPatch[i]->reset_counters();
1011  }
1012 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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.

References _patchNbr, and _vPatch.

Referenced by buildPatchArray(), and updatePatchArray().

296 {
297  //reset the right number of patches for the new simulation
298  if(_vPatch.size() > _patchNbr) {
299  while(_vPatch.size() > _patchNbr) {
300  delete _vPatch[0];
301  _vPatch.pop_front();
302  }
303  } else while(_vPatch.size() < _patchNbr) _vPatch.push_back(new Patch());
304 }
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
bool Metapop::retrieve_data ( BinaryStorageBuffer reader)
virtual

Implements StorableComponent.

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

530 {
531 #ifdef _DEBUG_
532  message("Metapop::retrieve_data, %iB of data read so far\n",loader->getBytesOut());
533 #endif
534  unsigned int *sizes[3], dummy_int;
535  unsigned char separator[2];
536 
537  sizes[0] = new unsigned int [_patchNbr];
538  sizes[1] = new unsigned int [_patchNbr];
539  sizes[2] = new unsigned int [_patchNbr];
540 
541  loader->read(&separator, 2 * sizeof(unsigned char));
542 
543  if(separator[0] != '@' || separator[1] != 'P') {
544  error("Binary file appears corrupted:\n >>>> Metapop::retrieve_data::wrong population seprarator\n");
545  return false;
546  }
547 
548  loader->read(&dummy_int, sizeof(unsigned int));
549 
550  if(dummy_int != _patchNbr) {
551  error("Population in binary file differs from simulation settings:\n >>>> Metapop::retrieve_data:number of Patch differ from parameter value\n");
552  return false;
553  }
554  //get the Patch sizes
555  //offspring
556  loader->read(sizes[0], _patchNbr * sizeof(unsigned int));
557  //females adults
558  loader->read(sizes[1], _patchNbr * sizeof(unsigned int));
559  //males adults
560  loader->read(sizes[2], _patchNbr * sizeof(unsigned int));
561 
562  Individual* ind;
563  unsigned int bytes_cnt = loader->getBytesOut();
564  //retrieve all individual informations: IDs, matings, etc.
565  for(unsigned int i = 0; i < _patchNbr; ++i) {
566  //first, offspring:
567  for(unsigned int j = 0; j < sizes[0][i]; ++j) {
568  ind = this->getNewIndividual();
569  ind->retrieve_data(loader);
570  _vPatch[i]->add(ind->getSex(), OFFSx, ind);
571  }
572  //then adult females:
573  for(unsigned int j = 0; j < sizes[1][i]; ++j) {
574  ind = this->getNewIndividual();
575  ind->retrieve_data(loader);
576  _vPatch[i]->add(FEM, ADLTx, ind);
577  }
578  //and adult males:
579  for(unsigned int j = 0; j < sizes[2][i]; ++j) {
580  ind = this->getNewIndividual();
581  ind->retrieve_data(loader);
582  _vPatch[i]->add(MAL, ADLTx, ind);
583  }
584 
585  }
586 
587 #ifdef _DEBUG_
588  message("Metapop::retrieve_data::retrieved %ikB of ind data (%i individuals)\n",
589  (loader->getBytesOut()-bytes_cnt)/1024, size());
590 #endif
591  //retrieve traits sequences
592  map<trait_t, TraitPrototype *>::iterator tt = _protoTraits.begin();
593 
594  char trait_name[6] = {'\0','\0','\0','\0','\0','\0'};
595 
596  unsigned int trait_cntr = 0;
597 
598  loader->read(&separator, 2 * sizeof(unsigned char));
599 
600  if(separator[0] != '@' || separator[1] != 'T') {
601  error("Binary file appears corrupted:\n >>>> Metapop::retrieve_data::wrong trait seprarator\n");
602  return false;
603  }
604 
605  bytes_cnt = loader->getBytesOut();
606 
607  do {
608  //get the trait type:
609  loader->read(&trait_name[0], TRAIT_T_MAX);
610 
611  string dummy_trait(trait_name);
612 
613  //get the prototype:
614  tt = _protoTraits.find(dummy_trait);
615 
616  if( tt == _protoTraits.end() ) {
617  error("Trait(s) in binary file differ from simulation settings:\n >>>> Metapop::retrieve_data::trait in file not present in protoype\n");
618  return false;
619  }
620  //then ask the prototype to retrieve its data:
621  tt->second->retrieve_data(loader);
622 
623 #ifdef _DEBUG_
624  message("%iB of trait data read so far (trait %s)\n",loader->getBytesOut()-bytes_cnt,tt->first.c_str());
625 #endif
626 
627  //get the traits data:
628  read_trait(tt->second->get_index(), loader);
629 
630  trait_cntr++;
631 
632  //get the next separator, should be present if right number of bytes have been read
633  loader->read(&separator, 2 * sizeof(unsigned char));
634 
635 
636  } while (separator[0] == '@' && separator[1] == 'T') ;
637 
638 #ifdef _DEBUG_
639  message("Metapop::retrieve_data::retrieved %ikB of trait data\n",(loader->getBytesOut()-bytes_cnt)/1024);
640 #endif
641 
642  if(trait_cntr != _protoTraits.size()){
643  error("Trait(s) in binary file differ from simulation settings:\n >>>> Metapop::retrieve_data::some traits are missing from binary file\n");
644  return false;
645  }
646 
647  if(separator[0] != '@')
648  error("Binary file appears corrupted:\n >>>> Metapop::retrieve_data::separator not found at end of pop record!\n");
649 
650  for(unsigned int i = 0; i < 3; i++)
651  delete [] sizes[i];
652 
653  return true;
654 }
void message(const char *message,...)
Definition: output.cc:40
std::map< trait_t, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:46
Individual * getNewIndividual()
Creates a blank individual which has to be "decorated" later.
Definition: indfactory.h:85
int error(const char *str,...)
Definition: output.cc:73
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
Definition: types.h:42
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:658
Definition: types.h:37
Definition: types.h:42
void retrieve_data(BinaryStorageBuffer *reader)
Definition: individual.cc:117
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
sex_t getSex()
Definition: individual.h:129
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
Definition: types.h:37
#define TRAIT_T_MAX
Max number of characters in the trait's type descriptor.
Definition: types.h:65
void Metapop::setCurrentAge ( age_t  age)
inline

Sets the age flag.

Parameters
agethe current age.

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

293 {_currentAge = age;}
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:148
void Metapop::setCurrentAge ( LifeCycleEvent LCE)

Set the age flag from a LifeCycleEvent object.

Parameters
LCEthe LifeCycleEvent object.

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

1035 {
1036  _currentAge ^= LCE->removeAgeClass();
1037  _currentAge |= LCE->addAgeClass();
1038 }
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:148
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.
void Metapop::setCurrentGeneration ( unsigned int  gen)
inline

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

288 {_currentGeneration = gen;}
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: metapop.h:143
void Metapop::setCurrentReplicate ( unsigned int  repl)
inline

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

287 {_currentReplicate = repl;}
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:145
void Metapop::setGenerations ( unsigned int  gen)
inline

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

266 {_generations = gen;}
unsigned int _generations
Patch init sizes.
Definition: metapop.h:138
void Metapop::setMPImanager ( MPImanager mgr)
inline

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

170 {_mpimgr = mgr;}
MPImanager * _mpimgr
Definition: metapop.h:84
bool Metapop::setParameters ( )
virtual

Implements SimComponent.

References setPopulationParameters(), and setSourceParameters().

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

115 {
116  if(!setPopulationParameters()) return false;
117  if(!setSourceParameters()) return false;
118  return true;
119 }
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:172
bool setSourceParameters()
Setter for source population parameters.
Definition: metapop.cc:123
void Metapop::setPatchCapacities ( )

Sets the deme capacity matrix from parameter values.

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

Referenced by setPopulationParameters().

332 {
334 
335  for(unsigned int i = 0; i < _patchNbr; ++i) {
338  }
339 }
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:131
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
unsigned int _patchKmal
Definition: metapop.h:131
Definition: types.h:37
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
Definition: types.h:37
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.

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

344 {
345  double* size_array;
346  unsigned int Knum;
347  TMatrix popK;
348 
349  _paramSet->getMatrix(param, &popK);
350 
351  Knum = popK.length();
352 
353  if(_patchNbr == 0 || _patchNbr < Knum) _patchNbr = Knum;
354 
356 
357  size_array = popK.get();
358 
359  for(unsigned int i = 0; i < _patchNbr; ++i) {
360  _patchSizes.set(FEM, i, (unsigned int)size_array[i % Knum]/2);
361  _patchSizes.set(MAL, i, (unsigned int)size_array[i % Knum]/2);
362  }
363 }
unsigned int length()
Returns the number of elements in the matrix.
Definition: tmatrix.h:145
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
Definition: types.h:37
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
Definition: types.h:37
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 seperately.

Parameters
SEXthe sex class of the given deme sizes.
paramthe name of the parameter to take the matrix argument from.

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

368 {
369  double* size_array;
370  unsigned int size_, Knum;
371  TMatrix popK;
372 
373  _paramSet->getMatrix(param, &popK);
374 
375  Knum = popK.length();
376 
377  if(_patchNbr == 0 || _patchNbr < Knum) _patchNbr = Knum;
378 
380 
381  size_array = popK.get();
382 
383  if(SEX == FEM)
384  size_ = _patchKmal;
385  else
386  size_ = _patchKfem;
387 
388  for(unsigned int i = 0; i < _patchNbr; ++i) {
389  _patchSizes.set(SEX, i, (unsigned int)size_array[i % Knum]);
390  _patchSizes.set(!SEX, i, size_);
391  }
392 }
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:131
unsigned int length()
Returns the number of elements in the matrix.
Definition: tmatrix.h:145
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
unsigned int _patchKmal
Definition: metapop.h:131
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
Definition: types.h:37
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.

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

397 {
398  double *size_fem, *size_mal;
399  unsigned int KFnum, KMnum;
400  TMatrix popKfem, popKmal;
401 
402  _paramSet->getMatrix(paramfem,&popKfem);
403  _paramSet->getMatrix(parammal,&popKmal);
404 
405  KFnum = popKfem.length();
406  KMnum = popKmal.length();
407 
408  if(_patchNbr == 0 && KFnum != KMnum){
409  warning("not same number of elements in females and males capacity matrices!\n");
410  warning("setting the number of populations from size of longest capacity array (= %i).\n",max(KFnum, KMnum));
411  }
412  if(_patchNbr < max(KFnum, KMnum)) _patchNbr = max(KFnum, KMnum);
413 
415 
416  size_fem = popKfem.get();
417  size_mal = popKmal.get();
418 
419  for(unsigned int i = 0; i < _patchNbr; ++i) {
420  _patchSizes.set(FEM, i, (unsigned int)size_fem[i % KFnum]);
421  _patchSizes.set(MAL, i, (unsigned int)size_mal[i % KMnum]);
422  }
423 }
unsigned int length()
Returns the number of elements in the matrix.
Definition: tmatrix.h:145
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
void warning(const char *str,...)
Definition: output.cc:56
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
Definition: types.h:37
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
Definition: types.h:37
void Metapop::setPopulation ( unsigned int  currentReplicate,
unsigned int  replicates 
)

Sets the population for the first generation of each replicates.

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

Referenced by SimRunner::setForFirstGeneration().

683 {
684 #ifdef _DEBUG_
685  message("Metapop::setPopulation: ");
686  fflush(stdout);
687 #endif
688 
689  _currentReplicate = currentReplicate;
690 
691  //reset the population parameters, they may have changed during the life cycle
693  //reset the patch array, flush the patches and reset the patch capacities.
694  buildPatchArray();
695 
696  _currentAge = NONE;
697 
698  //find the age class required to start the life cycle with:
699  if(_requiredAge == NONE)
701 
702 #ifdef _DEBUG_
703  message("required age is: %i ", _requiredAge);
704  fflush(stdout);
705 #endif
706  //load first generation from a source population
707  if(_source_load) {
708 
709  //delete ind in recycler, needed when dealing with large source pop and lots of replicates:
711 
712  _source_load_periodicity = (unsigned int)ceil((double)replicates/_source_replicates);
713 
714  if(currentReplicate == 1 ||
715  _source_replicates >= replicates || //load from a different source every replicate
716  !(_source_replicates != 0 && (currentReplicate - 1) % _source_load_periodicity) ) //change source every _source_replicates-nth replicates
718 
719  //load in preserve mode, i.e. make a copy of the saved pop
720  if(_source_preserve) {
721  //basic checks:
722  //not necessary anymore, after all...
723 // if(_source->getPatchNbr() != _patchNbr)
724 // fatal("loading population from source file failed: preserve mode forbids difference in number of patches\n");
725 
726  //have to remove check as K parameters might not reflect state of stored pop
727  //this happens when temporal params are present in init files
728 // if(_source->getPatchKFem() != _patchKfem || _source->getPatchKMal() != _patchKmal)
729 // fatal("loading population from source file failed: preserve mode forbids difference in patch sizes\n");
730 
732 
733  } else setPopulationFromSource();
734 
735  } else { //not source_load
736 
737  for(unsigned int i = 0; i < _patchNbr; ++i)
738  _vPatch[i]->setNewGeneration( _requiredAge, this );
739 
741 
742  }
743 
744 #ifdef _DEBUG_
745  message("loaded age is: %i \n",_currentAge);
746 #endif
747 
748  if(_currentAge == NONE) warning("Metapop::setPopulation: generation 0 is empty!!\n");
749 }
void message(const char *message,...)
Definition: output.cc:40
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:148
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:172
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:120
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:106
void setPopulationFromSource()
Definition: metapop.cc:815
static SimRunner * MainSim
Definition: simenv.h:42
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:145
#define NONE
No age flag.
Definition: types.h:48
void buildPatchArray()
Builds the new population from parameter values.
Definition: metapop.cc:282
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:101
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
void loadSourcePopulation()
Loads a population from a soure population.
Definition: metapop.cc:895
void warning(const char *str,...)
Definition: output.cc:56
void setPopulationFromSourceInPreserveMode()
Definition: metapop.cc:753
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:123
void purgeRecyclingPOOL()
Empty the recycling pool.
Definition: indfactory.h:66
age_t getFirstRequiredAgeInLifeCycle()
Definition: basicsimulation.cc:690
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
bool _source_load
Flage to specify that the population should be built from the binary loaded source population...
Definition: metapop.h:103
void Metapop::setPopulationFromSource ( )

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

Referenced by setPopulation().

816 {
817  //load in non-preserve mode, i.e. use saved pop as a source of new individuals
818  //individuals are drawn without replacement, sex and age are preserved.
819  deque< Individual* > src_fem_pool;
820  deque< Individual* > src_mal_pool;
821 
822  if( _requiredAge & OFFSPRG ) {
823 
824  if(_source->size(OFFSPRG) != 0)
825  _source->getAllIndividuals(OFFSx, src_fem_pool, src_mal_pool);
826  else {
827  warning("source population does not contain offspring individuals, using adults instead.\n");
828  //total size of source has been checked before
829  _source->getAllIndividuals(ADLTx, src_fem_pool, src_mal_pool);
830  }
831 
832  fillPopulationFromSource(OFFSx, FEM, src_fem_pool);
833  fillPopulationFromSource(OFFSx, MAL, src_mal_pool);
834  src_fem_pool.clear();
835  src_mal_pool.clear();
836 
837  _currentAge |= OFFSPRG;
838  }
839 
840  if( _requiredAge & ADULTS ) {
841 
842  if(_source->size(ADULTS) != 0)
843  _source->getAllIndividuals(ADLTx, src_fem_pool, src_mal_pool);
844  else {
845  warning("source population does not contain adult individuals, using offspring instead.\n");
846  //total size of source has been checked before
847  _source->getAllIndividuals(OFFSx, src_fem_pool, src_mal_pool);
848  }
849 
850  fillPopulationFromSource(ADLTx, FEM, src_fem_pool);
851  fillPopulationFromSource(ADLTx, MAL, src_mal_pool);
852  src_fem_pool.clear();
853  src_mal_pool.clear();
854 
855  _currentAge |= ADULTS;
856  }
857 
858 }
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:148
void warning(const char *str,...)
Definition: output.cc:56
Definition: types.h:42
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:123
Definition: types.h:37
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
void getAllIndividuals(age_idx AGE, deque< Individual * > &fem_pool, deque< Individual * > &mal_pool)
Definition: metapop.cc:1042
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:862
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Definition: types.h:37
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
void Metapop::setPopulationFromSourceInPreserveMode ( )

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

Referenced by setPopulation().

754 {
755  Patch* src_patch;
756  age_t source_age;
757  unsigned int num_patch = (unsigned int)min((double)_vPatch.size(), (double)_source->getPatchNbr());
758 
759  if(_requiredAge != NONE && _source->size(_requiredAge) == 0 && _source->size() != 0) {
760 
761  source_age = _source->getCurrentAge();
762 
763  warning("required age %i not present in source, using age class %i instead (preserve mode).\n"
764  ,_requiredAge,source_age);
765 
766  for(unsigned int i = 0; i < num_patch; ++i) {
767  src_patch = _source->getPatchPtr(i);
768  fillPatchFromSource(FEM, src_patch, _vPatch[i], source_age);
769  fillPatchFromSource(MAL, src_patch, _vPatch[i], source_age);
770  }
771 
772  } else {
773 
774  if (_requiredAge == NONE) _requiredAge = ALL;
775 
776  for(unsigned int i = 0; i < num_patch; ++i) {
777  src_patch = _source->getPatchPtr(i);
778  if(_requiredAge & OFFSPRG) {
779  fillPatchFromSource(FEM, src_patch, _vPatch[i], OFFSPRG);
780  fillPatchFromSource(MAL, src_patch, _vPatch[i], OFFSPRG);
781  }
782  if(_requiredAge & ADULTS) {
783  fillPatchFromSource(FEM, src_patch, _vPatch[i], ADULTS);
784  fillPatchFromSource(MAL, src_patch, _vPatch[i], ADULTS);
785  }
786  }
787  }
788 
789  if(size( ADULTS ) != 0)
790  _currentAge |= ADULTS;
791 
792  if(size( OFFSPRG ) != 0)
793  _currentAge |= OFFSPRG;
794 
795 }
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:148
unsigned int age_t
Age class flags.
Definition: types.h:46
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
#define NONE
No age flag.
Definition: types.h:48
unsigned int getPatchNbr()
Definition: metapop.h:270
void warning(const char *str,...)
Definition: output.cc:56
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:123
#define ALL
All ages age class flag.
Definition: types.h:56
Definition: types.h:37
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
age_t getCurrentAge()
Definition: metapop.h:289
Definition: types.h:37
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
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:799
bool Metapop::setPopulationParameters ( )

Population's size parameters initializing procedure.

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

173 {
174 
175  if(_paramSet->isSet("patch_number"))
176  _patchNbr = (unsigned int)_paramSet->getValue("patch_number");
177  else _patchNbr = 0;
178 
179  if(_paramSet->isSet("patch_capacity")) {
180 
181  if( _paramSet->isMatrix("patch_capacity") ) {
182 
183  setPatchCapacities("patch_capacity");
184 
185  } else if( !(_paramSet->isSet("patch_number")) ) {
186 
187  error("param \"patch_number\" is missing!\n");
188  return false;
189 
190  } else {
191  _patchK = (unsigned int)_paramSet->getValue("patch_capacity");
194  }
195 
196  } else if(_paramSet->isSet("patch_nbfem") && _paramSet->isSet("patch_nbmal")) {
197 
198  if( !(_paramSet->isMatrix("patch_nbfem")) && !(_paramSet->isMatrix("patch_nbmal")) ) {
199 
200  if( !(_paramSet->isSet("patch_number")) ) {
201 
202  error("param \"patch_number\" is missing!\n");
203  return false;
204 
205  } else {
206  _patchKfem = (unsigned int)_paramSet->getValue("patch_nbfem");
207  _patchKmal = (unsigned int)_paramSet->getValue("patch_nbmal");
210  }
211 
212  } else {
213 
214  if( !(_paramSet->isMatrix("patch_nbfem")) && _paramSet->isMatrix("patch_nbmal") ) {
215  _patchKfem = (unsigned int)_paramSet->getValue("patch_nbfem");
216  setPatchCapacities(MAL,"patch_nbmal");
217  } else if( _paramSet->isMatrix("patch_nbfem") && !(_paramSet->isMatrix("patch_nbmal")) ) {
218  _patchKmal = (unsigned int)_paramSet->getValue("patch_nbmal");
219  setPatchCapacities(FEM,"patch_nbfem");
220  } else
221  setPatchCapacities("patch_nbfem","patch_nbmal");
222  }
223 
224  } else {
225  error("population parameters are not properly set!\n");
226  return false;
227  }
228 
229  return true;
230 }
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:131
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:129
int error(const char *str,...)
Definition: output.cc:73
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
unsigned int _patchKmal
Definition: metapop.h:131
bool isMatrix(string name)
Check if the parameter "name" is of matrix type.
Definition: param.h:281
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
Definition: types.h:37
double getValue(string name)
Accessor the parameters value.
Definition: param.h:287
bool isSet()
Accessor to the status flag.
Definition: param.h:273
void setPatchCapacities()
Sets the deme capacity matrix from parameter values.
Definition: metapop.cc:331
Definition: types.h:37
void Metapop::setReplicates ( unsigned int  repl)
inline

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

268 {_replicates = repl;}
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:140
bool Metapop::setSourceParameters ( )

Setter for source population parameters.

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

Referenced by Metapop(), and setParameters().

124 {
125  if(_paramSet->isSet("source_pop")) {
126  _source_load = true;
127  _source_name = _paramSet->getArg("source_pop");
128  _source_preserve = _paramSet->isSet("source_preserve");
129  _source_replicates = _paramSet->isSet("source_replicates") ?
130  (unsigned int)_paramSet->getValue("source_replicates") : 0;
131 
132  _source_replicate_digits = _paramSet->isSet("source_replicate_digit") ?
133  (unsigned int)_paramSet->getValue("source_replicate_digit") : 1;
134 
135  _source_start_at_replicate = _paramSet->isSet("source_start_at_replicate") ?
136  (unsigned int)_paramSet->getValue("source_start_at_replicate") : 1;
137 
138  _source_generation = _paramSet->isSet("source_generation") ?
139  (unsigned int)_paramSet->getValue("source_generation") : 0;
140 
141  _source_filetype = _paramSet->getArg("source_file_type");
142 
143  if(_source_filetype.length() == 0) _source_filetype = ".bin";
144 
145  _source_required_age = _paramSet->getArg("source_fill_age_class");
146 
147  if(_source_required_age.length() == 0) _requiredAge = NONE;
148  else if(_source_required_age.compare("OFFSPRG") == 0 || _source_required_age.compare("offspring") == 0 ||
149  _source_required_age.compare("0") == 0){
151  } else if(_source_required_age.compare("ADULTS") == 0 || _source_required_age.compare("adults") == 0 ||
152  _source_required_age.compare("1") == 0) {
154  } else
155  _requiredAge = NONE; //for now...
156 
157 
158  } else {
159  _source = NULL;
160  _source_preserve = false;
161  _source_load = false;
162  _source_replicates = 0;
163  _source_generation = 0;
164  _source_name = "";
165  _source_filetype = ".bin";
166  }
167  return true;
168 }
std::string _source_required_age
The age class to fill with the source population.
Definition: metapop.h:118
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:116
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:106
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:110
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:112
#define NONE
No age flag.
Definition: types.h:48
std::string _source_name
The base filename of source population files.
Definition: metapop.h:114
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:101
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:123
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
double getValue(string name)
Accessor the parameters value.
Definition: param.h:287
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:285
bool isSet()
Accessor to the status flag.
Definition: param.h:273
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:108
bool _source_load
Flage to specify that the population should be built from the binary loaded source population...
Definition: metapop.h:103
void Metapop::show_up ( )

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

1058 {
1059  message("Metapop:\n");
1060  message("nbre. of patches: %i(%i)\n", _vPatch.size(),_patchNbr);
1061  message("population size : %i\n", size());
1062  message("K = %i, K_fem = %i, K_mal = %i\n",_patchK, _patchKfem, _patchKmal);
1063  message("patch capacities: \n");
1064  _patchSizes.show_up();
1065  message("Patches:\n");
1066  for(unsigned int i = 0; i < _vPatch.size(); i++)
1067  _vPatch[i]->show_up();
1068 }
void message(const char *message,...)
Definition: output.cc:40
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:131
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:129
void show_up()
Definition: metapop.cc:1057
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
unsigned int _patchKmal
Definition: metapop.h:131
void show_up()
Definition: tmatrix.h:246
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
unsigned int Metapop::size ( )
inline

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

References ALL, and size().

Referenced by LCE_Cross::create_individual_ancestors(), LCE_QuantiInit::execute(), LCE_Regulation::execute(), LCE_NtrlInit::execute(), LCE_Aging::execute(), LCE_Disperse_ConstDisp::execute(), LCE_Cross::execute(), LCE_Breed_Disperse::execute(), LCE_Disperse_EvolDisp::execute(), LCE_Breed_Wolbachia::execute(), LCE_Breed_Selection::execute(), LCE_Resize::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_Selection_base::execute(), LCE_Init_BDMI::execute(), LCE_Breed::execute(), TTDeletMutBitstrFH::FHread(), getAllIndividuals(), TTNeutralGenesSH::getDxy(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanOffsprgInfection(), TTDispersalSH::getOffsprgMeanDispRate(), isAlive(), loadFileServices(), loadPopFromTraitFile(), loadSourcePopulation(), 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(), TTDeletMutBitstrSH::setLethalEquivalents(), TTNeutralGenesSH::setLociDivCounter(), TTNeutralGenesSH::setNeiGeneticDistance(), setPopulationFromSource(), setPopulationFromSourceInPreserveMode(), TTQuantiSH::setStats(), show_up(), size(), store_data(), TTNeutralGenesFH::write_freq(), TTNeutralGenesFH::write_Fst_i(), and TTNeutralGenesFH::write_varcompWC().

302 {return size(ALL);}
#define ALL
All ages age class flag.
Definition: types.h:56
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
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

References _vPatch, and size().

770 {
771  unsigned int s = 0;
772  for(unsigned int i = 0; i < _vPatch.size(); i++)
773  s += _vPatch[i]->size(SEX, AGE);
774  return s;
775 }
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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

References _patchNbr, _vPatch, and size().

757 {
758  unsigned int s = 0;
759  for(unsigned int i = 0; i < _patchNbr; i++)
760  s += _vPatch[i]->size(SEX, IDX);
761  return s;
762 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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

References FEM, MAL, and size().

747 {
748  return size(FEM, IDX) + size(MAL, IDX);
749 }
Definition: types.h:37
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Definition: types.h:37
unsigned int Metapop::size ( age_idx  IDX,
unsigned int  deme 
)
inline

References FEM, MAL, and size().

752 {
753  return size(FEM, IDX, deme) + size(MAL, IDX, deme);
754 }
Definition: types.h:37
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Definition: types.h:37
unsigned int Metapop::size ( sex_t  SEX,
age_idx  IDX,
unsigned int  deme 
)
inline

References _vPatch.

765 {
766  return _vPatch[deme]->size(SEX, IDX);
767 }
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
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

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

778 {
779  Patch* patch = getPatch(deme);
780  return (patch!=0? patch->size(SEX, AGE) : 0);
781 }
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
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

References FEM, MAL, and size().

334  { return size( FEM, AGE ) + size( MAL, AGE );}
Definition: types.h:37
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Definition: types.h:37
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

References FEM, MAL, and size().

341  { return size( FEM, AGE, deme ) + size( MAL, AGE, deme );}
Definition: types.h:37
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Definition: types.h:37
void Metapop::store_data ( BinaryStorageBuffer saver)
virtual

Implements StorableComponent.

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

Referenced by BinaryDataSaver::storeData().

428 {
429  unsigned int *sizes[3];
430  unsigned char separator[2] = {'@','P'};
431 
432  sizes[0] = new unsigned int [_patchNbr];
433  sizes[1] = new unsigned int [_patchNbr];
434  sizes[2] = new unsigned int [_patchNbr];
435 
436  for(unsigned int i = 0; i < _patchNbr; ++i) {
437  sizes[0][i] = size(OFFSPRG,i);
438  sizes[1][i] = size(FEM,ADULTS,i);
439  sizes[2][i] = size(MAL,ADULTS,i);
440  }
441  //store the data, begin with pop separator and number of patches:
442  saver->store(&separator, 2 * sizeof(unsigned char));
443 
444  saver->store(&_patchNbr, sizeof(unsigned int));
445  //store the Patch sizes
446  //offspring
447  saver->store(sizes[0], _patchNbr * sizeof(unsigned int));
448  //females adults
449  saver->store(sizes[1], _patchNbr * sizeof(unsigned int));
450  //males adults
451  saver->store(sizes[2], _patchNbr * sizeof(unsigned int));
452 
453  int byte_count = saver->getByteLength();
454  //record all individual informations: IDs, matings, etc.
455  for(unsigned int i = 0; i < _patchNbr; ++i) {
456  //first offspring:
457  for(unsigned int j = 0; j < _vPatch[i]->size(FEM,OFFSx); ++j)
458  _vPatch[i]->get(FEM, OFFSx, j)->store_data(saver);
459 
460  for(unsigned int j = 0; j < _vPatch[i]->size(MAL,OFFSx); ++j)
461  _vPatch[i]->get(MAL, OFFSx, j)->store_data(saver);
462 
463  //then adults:
464  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
465  _vPatch[i]->get(FEM, ADLTx, j)->store_data(saver);
466 
467  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
468  _vPatch[i]->get(MAL, ADLTx, j)->store_data(saver);
469  }
470 
471 #ifdef _DEBUG_
472  message("Metapop::store_data :stored %ikB of individual data (%i individuals)\n",
473  (saver->getByteLength()-byte_count)/1024, size());
474 #endif
475 
476  //records the trait sequences:
477  map<trait_t, TraitPrototype *> traits = this->getTraitPrototypes();
478  map<trait_t, TraitPrototype *>::iterator tt = traits.begin();
479  // trait_t type;
480  separator[1] = 'T'; //trait separator = '@T'
481 
482  byte_count = saver->getByteLength();
483 
484  while(tt != traits.end()) {
485  saver->store(&separator, 2 * sizeof(unsigned char));
486  //store the trait type:
487  saver->store((void*)tt->first.c_str(), TRAIT_T_MAX);
488 
489  //then ask the prototype to store its data:
490  tt->second->store_data(saver);
491  //store the traits data:
492  store_trait(tt->second->get_index(), saver);
493 
494  tt++;
495  }
496 #ifdef _DEBUG_
497  message("Metapop::store_data :stored %ikB of traits data\n",
498  (saver->getByteLength()-byte_count)/1024);
499 #endif
500 
501  for(unsigned int i = 0; i < 3; i++)
502  delete [] sizes[i];
503 }
void message(const char *message,...)
Definition: output.cc:40
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
void store(void *stream, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:130
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
std::map< trait_t, TraitPrototype * > & getTraitPrototypes()
Accessor to the list of TraitPrototype's.
Definition: indfactory.h:117
Definition: types.h:42
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:507
Definition: types.h:37
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
Definition: types.h:37
unsigned int getByteLength() const
Definition: binarystoragebuffer.h:52
#define TRAIT_T_MAX
Max number of characters in the trait's type descriptor.
Definition: types.h:65
void Metapop::store_trait ( int  trait_idx,
BinaryStorageBuffer saver 
)

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

References _patchNbr, _vPatch, ADLTx, FEM, MAL, and OFFSx.

Referenced by store_data().

508 {
509  for(unsigned int i = 0; i < _patchNbr; ++i) {
510  //first offspring:
511  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, OFFSx); ++j) {
512  _vPatch[i]->get(FEM, OFFSx, j)->getTrait(trait_idx)->store_data(saver);
513  }
514 
515  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, OFFSx); ++j) {
516  _vPatch[i]->get(MAL, OFFSx, j)->getTrait(trait_idx)->store_data(saver);
517  }
518  //then adults:
519  for(unsigned int j = 0; j < _vPatch[i]->size(FEM, ADLTx); ++j)
520  _vPatch[i]->get(FEM, ADLTx, j)->getTrait(trait_idx)->store_data(saver);
521 
522  for(unsigned int j = 0; j < _vPatch[i]->size(MAL, ADLTx); ++j)
523  _vPatch[i]->get(MAL, ADLTx, j)->getTrait(trait_idx)->store_data(saver);
524  }
525 }
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
Definition: types.h:42
Definition: types.h:37
Definition: types.h:42
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
Definition: types.h:37
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.

References resizePatchArray(), and updatePatchState().

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

309 {
310  //remove or add patches as needed:
312  //reset the patch capacities and patch ID:
314 }
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc:295
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:318
void Metapop::updatePatchState ( )

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

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

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

319 {
320  //reset the patch capacities and patch ID:
321  for(unsigned int i = 0; i < _patchNbr; ++i) {
322  _vPatch[i]->setID(i);
323  _vPatch[i]->set_K((unsigned int)_patchSizes.get(FEM,i) + (unsigned int)_patchSizes.get(MAL,i));
324  _vPatch[i]->set_KFem((unsigned int)_patchSizes.get(FEM,i));
325  _vPatch[i]->set_KMal((unsigned int)_patchSizes.get(MAL,i));
326  }
327 }
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
Definition: types.h:37
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
Definition: types.h:37
bool Metapop::updatePopulationParameters ( )

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

References setPopulationParameters(), and updatePatchArray().

Referenced by Metapop().

235 {
236  if(!setPopulationParameters()) return false;
238  //if we added patches, they will be empty
239  //fusion of existing pop is not possible here,
240  //the individuals are flushed when deleting the patches
241  return true;
242 }
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:172
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:308

Friends And Related Function Documentation

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

Member Data Documentation

age_t Metapop::_currentAge
private

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

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

unsigned int Metapop::_currentGeneration
private

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

Referenced by getCurrentGeneration().

unsigned int Metapop::_currentReplicate
private

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

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

unsigned int Metapop::_generations
private

Patch init sizes.

Number of generations to iterate.

Referenced by getGenerations().

BinaryDataLoader Metapop::_loader
private

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

Referenced by loadPopFromBinarySource().

MPImanager* Metapop::_mpimgr
private
unsigned int Metapop::_patchK
private

Patch carrying capacity.

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

unsigned int Metapop::_patchKfem
private

Sex specific carrying capacities.

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

unsigned int Metapop::_patchKmal
private
TMatrix Metapop::_patchSizes
private

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

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

unsigned int Metapop::_replicates
private

Number of replicates to iterate.

Referenced by getReplicates(), and loadSourcePopulation().

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

Metapop* Metapop::_source
private

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

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

std::string Metapop::_source_filetype
private

The trait type to load from.

Referenced by getSourceFileType(), loadPopFromTraitFile(), loadSourcePopulation(), and setSourceParameters().

unsigned int Metapop::_source_generation
private

The generation to load from the binary file source file.

Referenced by loadPopFromBinarySource(), and setSourceParameters().

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

unsigned int Metapop::_source_load_periodicity
private

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

Referenced by loadSourcePopulation(), and setPopulation().

std::string Metapop::_source_name
private

The base filename of source population files.

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

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

unsigned int Metapop::_source_replicate_digits
private

Number of digits in the replicate counter filename extension.

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

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

std::string Metapop::_source_required_age
private

The age class to fill with the source population.

Referenced by setSourceParameters().

unsigned int Metapop::_source_start_at_replicate
private

The replicate number to start loading from.

Referenced by loadSourcePopulation(), and setSourceParameters().

MPStatHandler Metapop::_statHandler
private

The stat handler for the population stats.

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.0 by  doxygen 1.8.8 --
Catalogued on GSR