Nemo  2.3.46
LCE_Resize Class Reference

A class to change the size of the population/patches during a simulation. More...

#include <LCEmisc.h>

+ Inheritance diagram for LCE_Resize:
+ Collaboration diagram for LCE_Resize:

Public Member Functions

 LCE_Resize ()
 
virtual ~LCE_Resize ()
 
void buildNewPatchArrayNoBackup ()
 
void buildNewPatchArrayWithBackup ()
 
void removeDesignatedPatch (bool do_backup)
 
void updatePatchCapacities ()
 
void fillPop (void(LCE_Resize::*fillFuncPtr)(unsigned int p, age_idx age))
 
void fillPatchNoBackup (unsigned int p, age_idx age)
 
void fillPatchWithBackup (unsigned int p, age_idx age)
 
void regulate (void(LCE_Resize::*regFuncPtr)(Patch *patch, age_idx age))
 
void regulateAgeClassWithBackup (Patch *patch, age_idx age)
 
void regulateAgeClassNoBackup (Patch *patch, age_idx age)
 
virtual bool setParameters ()
 
bool updateParameters ()
 
virtual void execute ()
 
virtual LifeCycleEventclone ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual age_t removeAgeClass ()
 
virtual age_t addAgeClass ()
 
virtual age_t requiredAgeClass ()
 
- Public Member Functions inherited from LifeCycleEvent
 LifeCycleEvent (const char *name, const char *trait_link)
 Cstor. More...
 
virtual ~LifeCycleEvent ()
 
virtual void init (Metapop *popPtr)
 Sets the pointer to the current Metapop and the trait link if applicable. More...
 
virtual bool attach_trait (string trait)
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 
virtual void set_event_name (std::string &name)
 Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set. More...
 
virtual void set_event_name (const char *name)
 
virtual string & get_event_name ()
 Accessor to the LCE's name. More...
 
virtual int get_rank ()
 Accessor to the LCE rank in the life cycle. More...
 
virtual void set_pop_ptr (Metapop *popPtr)
 Accessors for the population pointer. More...
 
virtual Metapopget_pop_ptr ()
 
- 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_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...
 

Private Attributes

list< int >::const_iterator _genITER
 
int _atGeneration
 
list< int_generations
 
bool _do_flush
 
bool _do_fill
 
bool _do_regulate
 
TMatrix _patch2keep
 
age_t _setAge
 
Patch_patchBackup
 

Additional Inherited Members

- Protected Attributes inherited from LifeCycleEvent
std::string _event_name
 The param name to be read in the init file. More...
 
Metapop_popPtr
 The ptr to the current Metapop. More...
 
std::string _LCELinkedTraitType
 The name of the linked trait. More...
 
int _LCELinkedTraitIndex
 The index in the individual's trait table of the linked trait. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Detailed Description

A class to change the size of the population/patches during a simulation.

Constructor & Destructor Documentation

LCE_Resize::LCE_Resize ( )

References SimComponent::add_parameter(), BOOL, INT, MAT, setParameters(), STR, and updateParameters().

Referenced by clone().

801  : LifeCycleEvent("resize",""), _genITER(0), _atGeneration(0),
803 {
805  add_parameter("resize_at_generation", INT, 1, 0, 0, 0, updater);
807  add_parameter("resize_patch_number", INT, 0, 0, 0, 0, updater);
808  add_parameter("resize_patch_capacity", INT, 0, 0, 0, 0, updater);
809  add_parameter("resize_female_capacity", INT, 0, 0, 0, 0, updater);
810  add_parameter("resize_male_capacity", INT, 0, 0, 0, 0, updater);
811  add_parameter("resize_age_class", STR, 0, 0, 0, 0, updater);
812  add_parameter("resize_do_flush", BOOL, 0, 0, 0, 0, updater);
813  add_parameter("resize_do_regulate", BOOL, 0, 0, 0, 0, updater);
814  add_parameter("resize_do_fill", BOOL, 0, 0, 0, 0, updater);
815  add_parameter("resize_keep_patch", MAT, 0, 0, 0, 0, updater);
816 }
Implementation of the ParamUpdaterBase interface.
Definition: param.h:348
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
age_t _setAge
Definition: LCEmisc.h:224
Definition: types.h:78
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
Patch * _patchBackup
Definition: LCEmisc.h:225
bool _do_flush
Definition: LCEmisc.h:222
list< int >::const_iterator _genITER
Definition: LCEmisc.h:219
bool _do_regulate
Definition: LCEmisc.h:222
int _atGeneration
Definition: LCEmisc.h:220
Definition: types.h:78
Definition: types.h:78
virtual bool setParameters()
Definition: LCEmisc.cc:820
bool updateParameters()
Definition: LCEmisc.cc:845
bool _do_fill
Definition: LCEmisc.h:222
Definition: types.h:78
virtual LCE_Resize::~LCE_Resize ( )
inlinevirtual

References _patchBackup.

229 { if(_patchBackup) delete _patchBackup;}
Patch * _patchBackup
Definition: LCEmisc.h:225

Member Function Documentation

virtual age_t LCE_Resize::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

252 {return 0;}
void LCE_Resize::buildNewPatchArrayNoBackup ( )

References _patch2keep, LifeCycleEvent::_popPtr, TMatrix::getNbCols(), removeDesignatedPatch(), and Metapop::updatePatchArray().

Referenced by execute().

1008 {
1009  if(_patch2keep.getNbCols() != 0) removeDesignatedPatch(false);
1010 
1011  //
1012  //add or remove patches until the array size matches Metapop::_patchNbr
1013  //up to this point, the number of patches to keep could not be != from that nbre
1015 
1016 }
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
void removeDesignatedPatch(bool do_backup)
Definition: LCEmisc.cc:1043
TMatrix _patch2keep
Definition: LCEmisc.h:223
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:308
void LCE_Resize::buildNewPatchArrayWithBackup ( )

References _do_fill, _patch2keep, _patchBackup, LifeCycleEvent::_popPtr, Metapop::addPatch(), Patch::clear(), Patch::copy2patch(), TMatrix::getNbCols(), Metapop::getPatchArraySize(), Metapop::getPatchNbr(), Metapop::getPatchPtr(), regulate(), regulateAgeClassWithBackup(), removeDesignatedPatch(), Metapop::removePatch(), and Metapop::updatePatchState().

Referenced by execute().

1021 {
1022  unsigned int patchNbr = _popPtr->getPatchNbr();
1023 
1024  if(_patch2keep.getNbCols() != 0) removeDesignatedPatch(true);
1025 
1026  //reset the right number of patches to match new parameters
1027  if(_popPtr->getPatchArraySize() > patchNbr) {
1028 
1029  while(_popPtr->getPatchArraySize() > patchNbr) {
1031  _popPtr->getPatchPtr(0)->clear();
1032  _popPtr->removePatch(0);
1033  }
1034  } else while(_popPtr->getPatchArraySize() < patchNbr) _popPtr->addPatch(new Patch());
1035  //set the patch ID and Ks:
1037  //regulate the patches, backup the supernumerary individuals, will be used in empty patches
1039 }
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:623
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:680
void regulateAgeClassWithBackup(Patch *patch, age_idx age)
Definition: LCEmisc.cc:1138
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:833
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * _patchBackup
Definition: LCEmisc.h:225
void removeDesignatedPatch(bool do_backup)
Definition: LCEmisc.cc:1043
unsigned int getPatchNbr()
Definition: metapop.h:270
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:318
TMatrix _patch2keep
Definition: LCEmisc.h:223
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
unsigned int getPatchArraySize()
Definition: metapop.h:264
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Patch * removePatch(unsigned int i)
Removes a patch from the patch array and returns it pointer.
Definition: metapop.h:816
void regulate(void(LCE_Resize::*regFuncPtr)(Patch *patch, age_idx age))
Definition: LCEmisc.cc:1126
bool _do_fill
Definition: LCEmisc.h:222
virtual LifeCycleEvent* LCE_Resize::clone ( )
inlinevirtual

Implements LifeCycleEvent.

References LCE_Resize().

246 {return new LCE_Resize();}
LCE_Resize()
Definition: LCEmisc.cc:801
void LCE_Resize::execute ( )
virtual

Implements LifeCycleEvent.

References _atGeneration, _do_fill, _do_flush, _do_regulate, _generations, _genITER, SimComponent::_paramSet, _patch2keep, _patchBackup, LifeCycleEvent::_popPtr, _setAge, ADULTS, buildNewPatchArrayNoBackup(), buildNewPatchArrayWithBackup(), Patch::clear(), fatal(), fillPatchNoBackup(), fillPatchWithBackup(), fillPop(), SimComponent::get_parameter(), SimComponent::get_paramset(), ParamSet::getArg(), Metapop::getCurrentAge(), Metapop::getCurrentGeneration(), TMatrix::getNbCols(), Metapop::getPatchArraySize(), Metapop::getPatchKFem(), Metapop::getPatchKMal(), Metapop::getPatchNbr(), Patch::init(), tstring::int2str(), Param::isSet(), message(), NONE, OFFSPRG, regulate(), regulateAgeClassNoBackup(), regulateAgeClassWithBackup(), ParamSet::set_param(), SimComponent::set_paramset(), Metapop::setPopulationParameters(), Metapop::size(), and warning().

891 {
892 
893  if(_atGeneration > 0)
894  if(_popPtr->getCurrentGeneration() != (unsigned)_atGeneration) return;
895 
896  if(++_genITER != _generations.end())
897  _atGeneration = (*_genITER);
898  else {
899  _genITER = _generations.begin();
900  _atGeneration = (*_genITER);
901  }
902 
903  // if(_everyGeneration > 0)
904  // if(_atGeneration > 0) {
905  // //in this case, the _atGeneration value is taken as the starting point
906  // if( _popPtr->getCurrentGeneration() < (unsigned)_atGeneration ||
907  // (_popPtr->getCurrentGeneration() - _atGeneration) % _everyGeneration ) return;
908  // } else if(_popPtr->getCurrentGeneration() % _everyGeneration) return;
909 
910 #ifdef _DEBUG_
911  message("\nLCE_Resize::execute at %i (Patch nb: %i offsprg nb: %i adlt nb: %i)"
913 #endif
914 
915  if( !(_popPtr->getCurrentAge() & _setAge) || _popPtr->getCurrentAge() == NONE ) {
916  warning("LCE_Resize::execute:: required aged class not present in population, exiting.\n");
917  return;
918  }
919  //first reset the metapop size parameters:
920  ParamSet *originalPSet = _popPtr->get_paramset();
921  //make a backup copy of the initial parameters state to restore them later:
922  ParamSet *pSet = new ParamSet(*originalPSet);
923 
924  if( get_parameter("resize_patch_number")->isSet() )
925  pSet->set_param("patch_number", _paramSet->getArg("resize_patch_number"));
926 
927  if( get_parameter("resize_keep_patch")->isSet() ) {
929  pSet->set_param("patch_number", tstring::int2str(_patch2keep.getNbCols()));
930  } else if(_patch2keep.getNbCols() > _popPtr->getPatchNbr() &&
932  //this is a problem if one want to resize AND reorder... unless temporal arg used in pop params
933  fatal("LCE_Resize::execute:: more patches to keep than present in the population!\n");
934  }
935 
936  if( get_parameter("resize_patch_capacity")->isSet() )
937  pSet->set_param("patch_capacity", _paramSet->getArg("resize_patch_capacity"));
938 
939  if( get_parameter("resize_female_capacity")->isSet() )
940  pSet->set_param("patch_nbfem", _paramSet->getArg("resize_female_capacity"));
941 
942  if( get_parameter("resize_male_capacity")->isSet() )
943  pSet->set_param("patch_nbmal", _paramSet->getArg("resize_male_capacity"));
944 
945  _popPtr->set_paramset(pSet);
946  //just reset the patch number and patch capacities, doesn't touch the patch structure yet
948 
949  //now restore the original param set from the backup, will be needed to start the next replicate:
950  _popPtr->set_paramset(originalPSet);
951 
952  delete pSet;
953 
954  if(_do_flush) {
955 
956  //new populations will be empty and supernumerary patches are flushed and deleted
958 
959  } else {
960 
961  if(_patchBackup) {
962  _patchBackup->clear();
963  delete _patchBackup;
964  }
965  _patchBackup = new Patch();
966 
968 
969  //should be used when existing patches are merged together (fusion) or split (fission)
971 
972  }
973 
974  // updatePatchCapacities();
975 
976  if(_do_regulate)
979 
980  if(_do_fill)
983 
984 #ifdef _DEBUG_
985  message(" ---> (Patch nb: %i offsprg nb: %i adlt nb: %i, do_fill %i, do_flush %i)\n"
987 #endif
988 }
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:623
void message(const char *message,...)
Definition: output.cc:40
void regulateAgeClassWithBackup(Patch *patch, age_idx age)
Definition: LCEmisc.cc:1138
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
age_t _setAge
Definition: LCEmisc.h:224
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
void buildNewPatchArrayWithBackup()
Definition: LCEmisc.cc:1020
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:172
void fillPatchNoBackup(unsigned int p, age_idx age)
Definition: LCEmisc.cc:1098
unsigned int getCurrentGeneration()
Definition: metapop.h:286
virtual void set_paramset(ParamSet *paramset)
Sets the ParamSet member.
Definition: simcomponent.h:86
void fatal(const char *str,...)
Definition: output.cc:90
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * _patchBackup
Definition: LCEmisc.h:225
#define NONE
No age flag.
Definition: types.h:48
unsigned int getPatchKMal()
Definition: metapop.h:272
list< int > _generations
Definition: LCEmisc.h:221
void fillPop(void(LCE_Resize::*fillFuncPtr)(unsigned int p, age_idx age))
Definition: LCEmisc.cc:1081
bool _do_flush
Definition: LCEmisc.h:222
unsigned int getPatchNbr()
Definition: metapop.h:270
void fillPatchWithBackup(unsigned int p, age_idx age)
Definition: LCEmisc.cc:1111
list< int >::const_iterator _genITER
Definition: LCEmisc.h:219
bool _do_regulate
Definition: LCEmisc.h:222
int _atGeneration
Definition: LCEmisc.h:220
TMatrix _patch2keep
Definition: LCEmisc.h:223
void warning(const char *str,...)
Definition: output.cc:56
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:95
void buildNewPatchArrayNoBackup()
Definition: LCEmisc.cc:1007
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
bool set_param(string Name, string Arg)
Look for a param named "Name" and try to set it with the "Arg" argument string.
Definition: param.cc:577
unsigned int getPatchArraySize()
Definition: metapop.h:264
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
void regulateAgeClassNoBackup(Patch *patch, age_idx age)
Definition: LCEmisc.cc:1158
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
Patch * init(unsigned int nbfem, unsigned int nbmal, unsigned int id)
Definition: patch.cc:38
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:285
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:108
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
age_t getCurrentAge()
Definition: metapop.h:289
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Parameters container, implemented in each SimComponent.
Definition: param.h:203
void regulate(void(LCE_Resize::*regFuncPtr)(Patch *patch, age_idx age))
Definition: LCEmisc.cc:1126
unsigned int getPatchKFem()
Definition: metapop.h:271
bool _do_fill
Definition: LCEmisc.h:222
bool isSet()
Definition: param.h:138
void LCE_Resize::fillPatchNoBackup ( unsigned int  p,
age_idx  age 
)

References LifeCycleEvent::_popPtr, Patch::add(), FEM, Patch::get_KFem(), Patch::get_KMal(), Patch::getID(), Metapop::getPatchPtr(), IndFactory::makeNewIndividual(), MAL, and Patch::size().

Referenced by execute().

1099 {
1100  Patch *patch = _popPtr->getPatchPtr(p);
1101  while (patch->size(FEM, age) != patch->get_KFem()) {
1102  patch->add(FEM, age, _popPtr->makeNewIndividual(NULL, NULL, FEM, patch->getID()));
1103  }
1104  while (patch->size(MAL, age) != patch->get_KMal()) {
1105  patch->add(MAL, age, _popPtr->makeNewIndividual(NULL, NULL, MAL, patch->getID()));
1106  }
1107 }
unsigned int get_KMal()
Definition: metapop.h:473
unsigned int get_KFem()
Definition: metapop.h:472
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 * makeNewIndividual(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...
Definition: indfactory.cc:152
unsigned int getID()
Definition: metapop.h:469
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
Definition: types.h:37
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
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
Definition: types.h:37
void LCE_Resize::fillPatchWithBackup ( unsigned int  p,
age_idx  age 
)

References _patchBackup, LifeCycleEvent::_popPtr, Patch::add(), FEM, Patch::get(), Patch::get_KFem(), Patch::get_KMal(), Metapop::getPatchPtr(), MAL, Patch::remove(), and Patch::size().

Referenced by execute().

1112 {
1113  Patch *patch = _popPtr->getPatchPtr(p);
1114  while (patch->size(FEM, age) != patch->get_KFem() && _patchBackup->size(FEM, age) != 0) {
1115  patch->add(FEM, age, _patchBackup->get(FEM, age, 0));
1116  _patchBackup->remove(FEM, age, 0);
1117  }
1118  while (patch->size(MAL, age) != patch->get_KMal() && _patchBackup->size(MAL, age) != 0) {
1119  patch->add(MAL, age, _patchBackup->get(MAL, age, 0));
1120  _patchBackup->remove(MAL, age, 0);
1121  }
1122 }
unsigned int get_KMal()
Definition: metapop.h:473
unsigned int get_KFem()
Definition: metapop.h:472
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 * remove(sex_t SEX, age_idx AGE, unsigned int at)
Removes the individual sitting at the given index in the appropriate container.
Definition: metapop.h:564
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * _patchBackup
Definition: LCEmisc.h:225
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
Definition: types.h:37
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
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
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
Definition: types.h:37
void LCE_Resize::fillPop ( void(LCE_Resize::*)(unsigned int p, age_idx age)  fillFuncPtr)

References LifeCycleEvent::_popPtr, _setAge, ADLTx, ADULTS, Metapop::getCurrentAge(), Metapop::getPatchNbr(), OFFSPRG, and OFFSx.

Referenced by execute().

1082 {
1083  age_t active_age = (_popPtr->getCurrentAge() & _setAge);
1084 
1085  if(active_age & OFFSPRG) {
1086  for(unsigned int i=0; i < _popPtr->getPatchNbr(); ++i)
1087  (this->*fillFuncPtr)(i, OFFSx);
1088  }
1089 
1090  if(active_age & ADULTS) {
1091  for(unsigned int i=0; i < _popPtr->getPatchNbr(); ++i)
1092  (this->*fillFuncPtr)(i, ADLTx);
1093  }
1094 }
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
age_t _setAge
Definition: LCEmisc.h:224
unsigned int age_t
Age class flags.
Definition: types.h:46
unsigned int getPatchNbr()
Definition: metapop.h:270
Definition: types.h:42
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
age_t getCurrentAge()
Definition: metapop.h:289
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
virtual void LCE_Resize::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

249 {}
virtual void LCE_Resize::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

250 {}
void LCE_Resize::regulate ( void(LCE_Resize::*)(Patch *patch, age_idx age)  regFuncPtr)

References LifeCycleEvent::_popPtr, ADLTx, Metapop::getPatchNbr(), Metapop::getPatchPtr(), and OFFSx.

Referenced by buildNewPatchArrayWithBackup(), and execute().

1127 {
1128  Patch *patch;
1129  for(unsigned int i = 0; i < _popPtr->getPatchNbr(); i++) {
1130  patch = _popPtr->getPatchPtr(i);
1131  (this->*regFuncPtr)(patch, OFFSx);
1132  (this->*regFuncPtr)(patch, ADLTx);
1133  }
1134 }
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
unsigned int getPatchNbr()
Definition: metapop.h:270
Definition: types.h:42
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
Definition: types.h:42
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
void LCE_Resize::regulateAgeClassNoBackup ( Patch patch,
age_idx  age 
)

References LifeCycleEvent::_popPtr, FEM, Patch::get(), Patch::get_KFem(), Patch::get_KMal(), MAL, IndFactory::recycle(), Patch::remove(), Patch::size(), and RAND::Uniform().

Referenced by execute().

1159 {
1160  unsigned int ind;
1161 
1162  while(patch->size(FEM, age) > patch->get_KFem()) {
1163  ind = RAND::Uniform( patch->size(FEM, age) ) ;
1164  _popPtr->recycle( patch->get(FEM, age, ind) );
1165  patch->remove(FEM, age, ind);
1166  }
1167 
1168  while(patch->size(MAL, age) > patch->get_KMal()) {
1169  ind = RAND::Uniform( patch->size(MAL, age) ) ;
1170  _popPtr->recycle( patch->get(MAL, age, ind) );
1171  patch->remove(MAL, age, ind);
1172  }
1173 
1174 }
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:62
unsigned int get_KMal()
Definition: metapop.h:473
unsigned int get_KFem()
Definition: metapop.h:472
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 * remove(sex_t SEX, age_idx AGE, unsigned int at)
Removes the individual sitting at the given index in the appropriate container.
Definition: metapop.h:564
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
Definition: types.h:37
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
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
void LCE_Resize::regulateAgeClassWithBackup ( Patch patch,
age_idx  age 
)

References _patchBackup, Patch::add(), FEM, Patch::get(), Patch::get_KFem(), Patch::get_KMal(), MAL, Patch::remove(), Patch::size(), and RAND::Uniform().

Referenced by buildNewPatchArrayWithBackup(), and execute().

1139 {
1140  unsigned int ind;
1141 
1142  while(patch->size(FEM, age) > patch->get_KFem()) {
1143  ind = RAND::Uniform( patch->size(FEM, age) ) ;
1144  _patchBackup->add(FEM, age, patch->get(FEM, age, ind));
1145  patch->remove(FEM, age, ind);
1146  }
1147 
1148  while(patch->size(MAL, age) > patch->get_KMal()) {
1149  ind = RAND::Uniform( patch->size(MAL, age) ) ;
1150  _patchBackup->add(MAL, age, patch->get(MAL, age, ind));
1151  patch->remove(MAL, age, ind);
1152  }
1153 
1154 }
unsigned int get_KMal()
Definition: metapop.h:473
unsigned int get_KFem()
Definition: metapop.h:472
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 * remove(sex_t SEX, age_idx AGE, unsigned int at)
Removes the individual sitting at the given index in the appropriate container.
Definition: metapop.h:564
Patch * _patchBackup
Definition: LCEmisc.h:225
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
Definition: types.h:37
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 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
Definition: types.h:37
virtual age_t LCE_Resize::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

251 {return 0;}
void LCE_Resize::removeDesignatedPatch ( bool  do_backup)

References _patch2keep, _patchBackup, LifeCycleEvent::_popPtr, Metapop::addPatch(), Patch::clear(), Patch::copy2patch(), Metapop::deletePatch(), fatal(), TMatrix::get(), Patch::getID(), TMatrix::getNbCols(), Metapop::getPatchArraySize(), Metapop::getPatchPtr(), and Metapop::removePatch().

Referenced by buildNewPatchArrayNoBackup(), and buildNewPatchArrayWithBackup().

1044 {
1045  deque< Patch* > to_keep;
1046  Patch* patch;
1047  unsigned int patchNbr = _popPtr->getPatchArraySize() ;
1048  unsigned int i, nKeep = _patch2keep.getNbCols();
1049  unsigned int id;
1050 
1051  if(patchNbr < nKeep) fatal("LCE_Resize::more patches to keep than available in the population\n");
1052 
1053  for(i = 0; i < nKeep; i++)
1054  to_keep.push_back( _popPtr->getPatchPtr((unsigned int)_patch2keep.get(0, i)-1 ) );
1055 
1056  //remove the patches we want to keep from the patch array, without touching the contents
1057  for(i = 0; i < nKeep; i++) {
1058  id = to_keep[i]->getID();
1059  for(unsigned int j = 0; j < _popPtr->getPatchArraySize(); ++j)
1060  if(_popPtr->getPatchPtr(j)->getID() == id){ _popPtr->removePatch(j); break;}
1061  }
1062  //delete the patches we don't want to keep, remove the individuals and backup them if needed
1063  for(i = 0; i < _popPtr->getPatchArraySize(); i++) {
1064 
1065  patch = _popPtr->getPatchPtr(i);
1066 
1067  if(do_backup) { patch->copy2patch(_patchBackup); patch->clear(); }
1068 
1069  _popPtr->deletePatch(i); //this deletes the patch and the individuals it contains
1070 
1071  }
1072  //rebuild the patch array with the patches we want, in the right order
1073  for(i = 0; i < nKeep; i++)
1074  _popPtr->addPatch(to_keep[i]);
1075 
1076 
1077 }
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:623
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:680
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:833
void deletePatch(unsigned int i)
Removes a patch from the patch array and deletes it and its content.
Definition: metapop.h:823
unsigned int getID()
Definition: metapop.h:469
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void fatal(const char *str,...)
Definition: output.cc:90
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * _patchBackup
Definition: LCEmisc.h:225
TMatrix _patch2keep
Definition: LCEmisc.h:223
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
unsigned int getPatchArraySize()
Definition: metapop.h:264
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Patch * removePatch(unsigned int i)
Removes a patch from the patch array and returns it pointer.
Definition: metapop.h:816
virtual age_t LCE_Resize::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

253 {return 0;}
bool LCE_Resize::setParameters ( )
virtual

Implements SimComponent.

References _atGeneration, _generations, _genITER, SimComponent::_paramSet, TMatrix::get(), SimComponent::get_parameter_value(), ParamSet::getMatrix(), TMatrix::getNbCols(), ParamSet::isMatrix(), and updateParameters().

Referenced by LCE_Resize().

821 {
822 
823  _generations.clear();
824 
825  if(_paramSet->isMatrix("resize_at_generation") ) {
826 
827  TMatrix tmp;
828 
829  _paramSet->getMatrix("resize_at_generation", &tmp);
830 
831  for(unsigned int i = 0; i < tmp.getNbCols(); i++)
832  _generations.push_back((int)tmp.get(0, i));
833 
834  } else
835  _generations.push_back((int)get_parameter_value("resize_at_generation"));
836 
837  _genITER = _generations.begin();
838  _atGeneration = (*_genITER);
839 
840  return updateParameters();
841 }
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
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
list< int > _generations
Definition: LCEmisc.h:221
list< int >::const_iterator _genITER
Definition: LCEmisc.h:219
int _atGeneration
Definition: LCEmisc.h:220
bool isMatrix(string name)
Check if the parameter "name" is of matrix type.
Definition: param.h:281
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
bool updateParameters()
Definition: LCEmisc.cc:845
bool LCE_Resize::updateParameters ( )

References _atGeneration, _do_fill, _do_flush, _do_regulate, SimComponent::_paramSet, _patch2keep, LifeCycleEvent::_popPtr, _setAge, ADULTS, ALL, error(), SimComponent::get_parameter(), ParamSet::getArg(), Metapop::getCurrentGeneration(), ParamSet::getMatrix(), TMatrix::getNbCols(), Metapop::getPatchNbr(), Param::isSet(), OFFSPRG, TMatrix::reset(), and warning().

Referenced by LCE_Resize(), and setParameters().

846 {
847  string option = _paramSet->getArg("resize_age_class");
848 
849  if(option.length() == 0) _setAge = ALL;
850  else if(option.compare("OFFSPRG") == 0 || option.compare("offspring") == 0 ||
851  option.compare("0") == 0){
852  _setAge = OFFSPRG;
853  } else if(option.compare("ADULTS") == 0 || option.compare("adults") == 0 ||
854  option.compare("1") == 0) {
855  _setAge = ADULTS;
856  } else if(option.compare("ALL") == 0 || option.compare("all") == 0) {
857  _setAge = ALL;
858  } else {
859  warning("\"%s\" is not a valid option for parameter \"resize_age_class\".\n",option.c_str());
860  _setAge = ALL;
861  }
862 
863  if( !get_parameter("resize_patch_number")->isSet() &&
864  !get_parameter("resize_patch_capacity")->isSet() &&
865  !get_parameter("resize_female_capacity")->isSet() &&
866  !get_parameter("resize_male_capacity")->isSet() &&
867  !get_parameter("resize_keep_patch")->isSet()) {
868  error("LCE_Resize:: at least one of the population size parameters must be specified.\n");
869  return false;
870  }
871 
872  _do_regulate = get_parameter("resize_do_regulate")->isSet();
873  _do_flush = get_parameter("resize_do_flush")->isSet();
874  _do_fill = get_parameter("resize_do_fill")->isSet();
875 
876  if(get_parameter("resize_keep_patch")->isSet()) {
877  _paramSet->getMatrix("resize_keep_patch", &_patch2keep);
879  _popPtr->getCurrentGeneration() == (unsigned)_atGeneration) {
880  error("LCE_Resize:: more patches to keep than existing patches in the population!\n");
881  return false;
882  }
883  } else
884  _patch2keep.reset();
885  return true;
886 }
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
age_t _setAge
Definition: LCEmisc.h:224
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
unsigned int getCurrentGeneration()
Definition: metapop.h:286
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
bool _do_flush
Definition: LCEmisc.h:222
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
Definition: output.cc:73
bool _do_regulate
Definition: LCEmisc.h:222
int _atGeneration
Definition: LCEmisc.h:220
TMatrix _patch2keep
Definition: LCEmisc.h:223
void warning(const char *str,...)
Definition: output.cc:56
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
#define ALL
All ages age class flag.
Definition: types.h:56
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:285
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
bool _do_fill
Definition: LCEmisc.h:222
bool isSet()
Definition: param.h:138
void LCE_Resize::updatePatchCapacities ( )

References LifeCycleEvent::_popPtr, fatal(), FEM, TMatrix::get(), TMatrix::getNbCols(), Metapop::getPatchCapacities(), Metapop::getPatchNbr(), Metapop::getPatchPtr(), MAL, Patch::set_KFem(), and Patch::set_KMal().

993 {
995 
996  if(cap->getNbCols() != _popPtr->getPatchNbr())
997  fatal("LCE_Resize:: more patch capacities than patches in the population!\n");
998 
999  for (unsigned int i = 0; i < _popPtr->getPatchNbr(); i++) {
1000  _popPtr->getPatchPtr(i)->set_KFem((unsigned int)cap->get(FEM, i));
1001  _popPtr->getPatchPtr(i)->set_KMal((unsigned int)cap->get(MAL, i));
1002  }
1003 }
void set_KMal(unsigned int k)
Definition: metapop.h:462
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void set_KFem(unsigned int k)
Definition: metapop.h:461
void fatal(const char *str,...)
Definition: output.cc:90
unsigned int getPatchNbr()
Definition: metapop.h:270
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
Definition: types.h:37
TMatrix * getPatchCapacities()
Definition: metapop.h:275
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37

Member Data Documentation

int LCE_Resize::_atGeneration
private
bool LCE_Resize::_do_fill
private
bool LCE_Resize::_do_flush
private

Referenced by execute(), and updateParameters().

bool LCE_Resize::_do_regulate
private

Referenced by execute(), and updateParameters().

list< int > LCE_Resize::_generations
private

Referenced by execute(), and setParameters().

list< int >::const_iterator LCE_Resize::_genITER
private

Referenced by execute(), and setParameters().

age_t LCE_Resize::_setAge
private

Referenced by execute(), fillPop(), and updateParameters().


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