Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
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 bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
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...
 
virtual bool has_parameter (std::string name)
 Param getter. 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::LCE_Resize ( )
792  : LifeCycleEvent("resize",""), _atGeneration(0),
794 {
796  add_parameter("resize_at_generation", INT, 1, 0, 0, 0, updater);
798  add_parameter("resize_patch_number", INT, 0, 0, 0, 0, updater);
799  add_parameter("resize_patch_capacity", INT, 0, 0, 0, 0, updater);
800  add_parameter("resize_female_capacity", INT, 0, 0, 0, 0, updater);
801  add_parameter("resize_male_capacity", INT, 0, 0, 0, 0, updater);
802  add_parameter("resize_age_class", STR, 0, 0, 0, 0, updater);
803  add_parameter("resize_do_flush", BOOL, 0, 0, 0, 0, updater);
804  add_parameter("resize_do_regulate", BOOL, 0, 0, 0, 0, updater);
805  add_parameter("resize_do_fill", BOOL, 0, 0, 0, 0, updater);
806  add_parameter("resize_keep_patch", MAT, 0, 0, 0, 0, updater);
807 }
age_t _setAge
Definition: LCEmisc.h:227
Patch * _patchBackup
Definition: LCEmisc.h:228
int _atGeneration
Definition: LCEmisc.h:223
bool _do_fill
Definition: LCEmisc.h:225
bool _do_regulate
Definition: LCEmisc.h:225
bool updateParameters()
Definition: LCEmisc.cc:836
virtual bool setParameters()
Definition: LCEmisc.cc:811
bool _do_flush
Definition: LCEmisc.h:225
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97
Implementation of the ParamUpdaterBase interface.
Definition: param.h:362
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
@ MAT
Definition: types.h:77
@ BOOL
Definition: types.h:77
@ STR
Definition: types.h:77
@ INT
Definition: types.h:77

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

Referenced by clone().

+ Here is the caller graph for this function:

◆ ~LCE_Resize()

virtual LCE_Resize::~LCE_Resize ( )
inlinevirtual
232 { if(_patchBackup) delete _patchBackup;}

References _patchBackup.

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Resize::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

256 {return 0;}

◆ buildNewPatchArrayNoBackup()

void LCE_Resize::buildNewPatchArrayNoBackup ( )
1000 {
1001  if(_patch2keep.getNbCols() != 0) removeDesignatedPatch(false);
1002 
1003  //
1004  //add or remove patches until the array size matches Metapop::_patchNbr
1005  //up to this point, the number of patches to keep could not be != from that nbre
1007 
1008 }
TMatrix _patch2keep
Definition: LCEmisc.h:226
void removeDesignatedPatch(bool do_backup)
Definition: LCEmisc.cc:1035
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:80
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:333
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:214

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ buildNewPatchArrayWithBackup()

void LCE_Resize::buildNewPatchArrayWithBackup ( )
1013 {
1014  unsigned int patchNbr = _popPtr->getPatchNbr();
1015 
1016  if(_patch2keep.getNbCols() != 0) removeDesignatedPatch(true);
1017 
1018  //reset the right number of patches to match new parameters
1019  if(_popPtr->getPatchArraySize() > patchNbr) {
1020 
1021  while(_popPtr->getPatchArraySize() > patchNbr) {
1023  _popPtr->getPatchPtr(0)->clear();
1024  _popPtr->removePatch(0);
1025  }
1026  } else while(_popPtr->getPatchArraySize() < patchNbr) _popPtr->addPatch(new Patch());
1027  //set the patch ID and Ks:
1029  //regulate the patches, backup the supernumerary individuals, will be used in empty patches
1031 }
void regulate(void(LCE_Resize::*regFuncPtr)(Patch *patch, age_idx age))
Definition: LCEmisc.cc:1118
void regulateAgeClassWithBackup(Patch *patch, age_idx age)
Definition: LCEmisc.cc:1130
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:343
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:259
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:885
Patch * removePatch(unsigned int i)
Removes a patch from the patch array and returns it pointer.
Definition: metapop.h:868
unsigned int getPatchArraySize()
Definition: metapop.h:269
unsigned int getPatchNbr()
Definition: metapop.h:275
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:732
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:675

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

+ Here is the caller graph for this function:

◆ clone()

virtual LifeCycleEvent* LCE_Resize::clone ( )
inlinevirtual

Implements LifeCycleEvent.

249 {return new LCE_Resize();}
LCE_Resize()
Definition: LCEmisc.cc:792

References LCE_Resize().

◆ execute()

void LCE_Resize::execute ( )
virtual

Implements LifeCycleEvent.

882 {
883 
884  if(_atGeneration > 0)
885  if(_popPtr->getCurrentGeneration() != (unsigned)_atGeneration) return;
886 
887  if(++_genITER != _generations.end())
888  _atGeneration = (*_genITER);
889  else {
890  _genITER = _generations.begin();
891  _atGeneration = (*_genITER);
892  }
893 
894  // if(_everyGeneration > 0)
895  // if(_atGeneration > 0) {
896  // //in this case, the _atGeneration value is taken as the starting point
897  // if( _popPtr->getCurrentGeneration() < (unsigned)_atGeneration ||
898  // (_popPtr->getCurrentGeneration() - _atGeneration) % _everyGeneration ) return;
899  // } else if(_popPtr->getCurrentGeneration() % _everyGeneration) return;
900 
901 #ifdef _DEBUG_
902  message("\nLCE_Resize::execute at %i (Patch nb: %i offsprg nb: %i adlt nb: %i)"
904 #endif
905 
906  if( !(_popPtr->getCurrentAge() & _setAge) || _popPtr->getCurrentAge() == NONE ) {
907  warning("LCE_Resize::execute:: required aged class not present in population, exiting.\n");
908  return;
909  }
910  //first reset the metapop size parameters:
911  ParamSet *originalPSet = _popPtr->get_paramset();
912  //make a backup copy of the initial parameters state to restore them later:
913  ParamSet *pSet = new ParamSet(*originalPSet);
914 
915  if( get_parameter("resize_patch_number")->isSet() )
916  pSet->set_param("patch_number", _paramSet->getArg("resize_patch_number"));
917 
918  if( get_parameter("resize_keep_patch")->isSet() ) {
920  pSet->set_param("patch_number", tstring::int2str(_patch2keep.getNbCols()));
921  } else if(_patch2keep.getNbCols() > _popPtr->getPatchNbr() &&
923  //this is a problem if one want to resize AND reorder... unless temporal arg used in pop params
924  fatal("LCE_Resize::execute:: more patches to keep than present in the population!\n");
925  }
926 
927  if( get_parameter("resize_patch_capacity")->isSet() )
928  pSet->set_param("patch_capacity", _paramSet->getArg("resize_patch_capacity"));
929 
930  if( get_parameter("resize_female_capacity")->isSet() )
931  pSet->set_param("patch_nbfem", _paramSet->getArg("resize_female_capacity"));
932 
933  if( get_parameter("resize_male_capacity")->isSet() )
934  pSet->set_param("patch_nbmal", _paramSet->getArg("resize_male_capacity"));
935 
936  _popPtr->set_paramset(pSet);
937  //just reset the patch number and patch capacities, doesn't touch the patch structure yet
939 
940  //now restore the original param set from the backup, will be needed to start the next replicate:
941  _popPtr->set_paramset(originalPSet);
942 
943  delete pSet;
944 
945  if(_do_flush) {
946 
947  //new populations will be empty and supernumerary patches are flushed and deleted
949 
950  } else {
951 
952  if(_patchBackup) {
953  _patchBackup->clear();
954  delete _patchBackup;
955  }
956  _patchBackup = new Patch();
957 
959 
960  //should be used when existing patches are merged together (fusion) or split (fission)
962 
963  }
964 
965  // updatePatchCapacities();
966 
967  if(_do_regulate) {
970  }
971 
972  if(_do_fill){
975  }
976 #ifdef _DEBUG_
977  message(" ---> (Patch nb: %i offsprg nb: %i adlt nb: %i, do_fill %i, do_flush %i)\n"
979 #endif
980 }
void fillPatchWithBackup(unsigned int p, age_idx age)
Definition: LCEmisc.cc:1103
void fillPatchNoBackup(unsigned int p, age_idx age)
Definition: LCEmisc.cc:1090
void fillPop(void(LCE_Resize::*fillFuncPtr)(unsigned int p, age_idx age))
Definition: LCEmisc.cc:1073
void regulateAgeClassNoBackup(Patch *patch, age_idx age)
Definition: LCEmisc.cc:1150
void buildNewPatchArrayNoBackup()
Definition: LCEmisc.cc:999
list< int > _generations
Definition: LCEmisc.h:224
void buildNewPatchArrayWithBackup()
Definition: LCEmisc.cc:1012
list< int >::const_iterator _genITER
Definition: LCEmisc.h:222
unsigned int getPatchKMal()
Definition: metapop.h:277
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:195
unsigned int getPatchKFem()
Definition: metapop.h:276
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
age_t getCurrentAge()
Definition: metapop.h:298
unsigned int getCurrentGeneration()
Definition: metapop.h:295
Parameters container, implemented in each SimComponent.
Definition: param.h:205
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:299
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:634
Patch * init(unsigned int nbfem, unsigned int nbmal, unsigned int id)
Definition: patch.cc:37
virtual void set_paramset(ParamSet *paramset)
Sets the ParamSet member.
Definition: simcomponent.h:85
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:107
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:94
void fatal(const char *str,...)
Definition: output.cc:99
void warning(const char *str,...)
Definition: output.cc:57
void message(const char *message,...)
Definition: output.cc:39
#define NONE
No age flag.
Definition: types.h:47
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:53
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49

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(), message(), NONE, OFFSPRG, regulate(), regulateAgeClassNoBackup(), regulateAgeClassWithBackup(), ParamSet::set_param(), SimComponent::set_paramset(), Metapop::setPopulationParameters(), Metapop::size(), and warning().

◆ fillPatchNoBackup()

void LCE_Resize::fillPatchNoBackup ( unsigned int  p,
age_idx  age 
)
1091 {
1092  Patch *patch = _popPtr->getPatchPtr(p);
1093  while (patch->size(FEM, age) != patch->get_KFem()) {
1094  patch->add(FEM, age, _popPtr->makeNewIndividual(NULL, NULL, FEM, patch->getID()));
1095  }
1096  while (patch->size(MAL, age) != patch->get_KMal()) {
1097  patch->add(MAL, age, _popPtr->makeNewIndividual(NULL, NULL, MAL, patch->getID()));
1098  }
1099 }
Individual * makeNewIndividual(Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Creates an individual from existing pointer with new ID.
Definition: indfactory.cc:151
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:497
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it.
Definition: metapop.h:550
unsigned int getID()
Definition: metapop.h:480
unsigned int get_KFem()
Definition: metapop.h:483
unsigned int get_KMal()
Definition: metapop.h:484
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36

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

+ Here is the caller graph for this function:

◆ fillPatchWithBackup()

void LCE_Resize::fillPatchWithBackup ( unsigned int  p,
age_idx  age 
)
1104 {
1105  Patch *patch = _popPtr->getPatchPtr(p);
1106  while (patch->size(FEM, age) != patch->get_KFem() && _patchBackup->size(FEM, age) != 0) {
1107  patch->add(FEM, age, _patchBackup->get(FEM, age, 0));
1108  _patchBackup->remove(FEM, age, 0);
1109  }
1110  while (patch->size(MAL, age) != patch->get_KMal() && _patchBackup->size(MAL, age) != 0) {
1111  patch->add(MAL, age, _patchBackup->get(MAL, age, 0));
1112  _patchBackup->remove(MAL, age, 0);
1113  }
1114 }
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:587
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:533

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

+ Here is the caller graph for this function:

◆ fillPop()

void LCE_Resize::fillPop ( void(LCE_Resize::*)(unsigned int p, age_idx age)  fillFuncPtr)
1074 {
1075  age_t active_age = (_popPtr->getCurrentAge() & _setAge);
1076 
1077  if(active_age & OFFSPRG) {
1078  for(unsigned int i=0; i < _popPtr->getPatchNbr(); ++i)
1079  (this->*fillFuncPtr)(i, OFFSx);
1080  }
1081 
1082  if(active_age & ADULTS) {
1083  for(unsigned int i=0; i < _popPtr->getPatchNbr(); ++i)
1084  (this->*fillFuncPtr)(i, ADLTx);
1085  }
1086 }
unsigned int age_t
Age class flags.
Definition: types.h:45
@ OFFSx
Definition: types.h:41
@ ADLTx
Definition: types.h:41

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ loadFileServices()

virtual void LCE_Resize::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

252 {}

◆ loadStatServices()

virtual void LCE_Resize::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

253 {}

◆ regulate()

void LCE_Resize::regulate ( void(LCE_Resize::*)(Patch *patch, age_idx age)  regFuncPtr)
1119 {
1120  Patch *patch;
1121  for(unsigned int i = 0; i < _popPtr->getPatchNbr(); i++) {
1122  patch = _popPtr->getPatchPtr(i);
1123  (this->*regFuncPtr)(patch, OFFSx);
1124  (this->*regFuncPtr)(patch, ADLTx);
1125  }
1126 }

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

Referenced by buildNewPatchArrayWithBackup(), and execute().

+ Here is the caller graph for this function:

◆ regulateAgeClassNoBackup()

void LCE_Resize::regulateAgeClassNoBackup ( Patch patch,
age_idx  age 
)
1151 {
1152  unsigned int ind;
1153 
1154  while(patch->size(FEM, age) > patch->get_KFem()) {
1155  ind = RAND::Uniform( patch->size(FEM, age) ) ;
1156  _popPtr->recycle( patch->get(FEM, age, ind) );
1157  patch->remove(FEM, age, ind);
1158  }
1159 
1160  while(patch->size(MAL, age) > patch->get_KMal()) {
1161  ind = RAND::Uniform( patch->size(MAL, age) ) ;
1162  _popPtr->recycle( patch->get(MAL, age, ind) );
1163  patch->remove(MAL, age, ind);
1164  }
1165 
1166 }
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:61
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:126

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

+ Here is the caller graph for this function:

◆ regulateAgeClassWithBackup()

void LCE_Resize::regulateAgeClassWithBackup ( Patch patch,
age_idx  age 
)
1131 {
1132  unsigned int ind;
1133 
1134  while(patch->size(FEM, age) > patch->get_KFem()) {
1135  ind = RAND::Uniform( patch->size(FEM, age) ) ;
1136  _patchBackup->add(FEM, age, patch->get(FEM, age, ind));
1137  patch->remove(FEM, age, ind);
1138  }
1139 
1140  while(patch->size(MAL, age) > patch->get_KMal()) {
1141  ind = RAND::Uniform( patch->size(MAL, age) ) ;
1142  _patchBackup->add(MAL, age, patch->get(MAL, age, ind));
1143  patch->remove(MAL, age, ind);
1144  }
1145 
1146 }

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

+ Here is the caller graph for this function:

◆ removeAgeClass()

virtual age_t LCE_Resize::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

255 {return 0;}

◆ removeDesignatedPatch()

void LCE_Resize::removeDesignatedPatch ( bool  do_backup)
1036 {
1037  deque< Patch* > to_keep;
1038  Patch* patch;
1039  unsigned int patchNbr = _popPtr->getPatchArraySize() ;
1040  unsigned int i, nKeep = _patch2keep.getNbCols();
1041  unsigned int id;
1042 
1043  if(patchNbr < nKeep) fatal("LCE_Resize::more patches to keep than available in the population\n");
1044 
1045  for(i = 0; i < nKeep; i++)
1046  to_keep.push_back( _popPtr->getPatchPtr((unsigned int)_patch2keep.get(0, i)-1 ) );
1047 
1048  //remove the patches we want to keep from the patch array, without touching the contents
1049  for(i = 0; i < nKeep; i++) {
1050  id = to_keep[i]->getID();
1051  for(unsigned int j = 0; j < _popPtr->getPatchArraySize(); ++j)
1052  if(_popPtr->getPatchPtr(j)->getID() == id){ _popPtr->removePatch(j); break;}
1053  }
1054  //delete the patches we don't want to keep, remove the individuals and backup them if needed
1055  for(i = 0; i < _popPtr->getPatchArraySize(); i++) {
1056 
1057  patch = _popPtr->getPatchPtr(i);
1058 
1059  if(do_backup) { patch->copy2patch(_patchBackup); patch->clear(); }
1060 
1061  _popPtr->deletePatch(i); //this deletes the patch and the individuals it contains
1062 
1063  }
1064  //rebuild the patch array with the patches we want, in the right order
1065  for(i = 0; i < nKeep; i++)
1066  _popPtr->addPatch(to_keep[i]);
1067 
1068 
1069 }
void deletePatch(unsigned int i)
Removes a patch from the patch array and deletes it and its content.
Definition: metapop.h:875
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:192

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

+ Here is the caller graph for this function:

◆ requiredAgeClass()

virtual age_t LCE_Resize::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

257 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

254 {return false;}

◆ setParameters()

bool LCE_Resize::setParameters ( )
virtual

Implements SimComponent.

812 {
813 
814  _generations.clear();
815 
816  if(_paramSet->isMatrix("resize_at_generation") ) {
817 
818  TMatrix tmp;
819 
820  _paramSet->getMatrix("resize_at_generation", &tmp);
821 
822  for(unsigned int i = 0; i < tmp.getNbCols(); i++)
823  _generations.push_back((int)tmp.get(0, i));
824 
825  } else
826  _generations.push_back((int)get_parameter_value("resize_at_generation"));
827 
828  _genITER = _generations.begin();
829  _atGeneration = (*_genITER);
830 
831  return updateParameters();
832 }
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:303
bool isMatrix(string name)
Check if the parameter "name" is of matrix type.
Definition: param.h:295
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49

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

Referenced by LCE_Resize().

+ Here is the caller graph for this function:

◆ updateParameters()

bool LCE_Resize::updateParameters ( )
837 {
838  string option = _paramSet->getArg("resize_age_class");
839 
840  if(option.length() == 0) _setAge = ALL;
841  else if(option.compare("OFFSPRG") == 0 || option.compare("offspring") == 0 ||
842  option.compare("0") == 0){
843  _setAge = OFFSPRG;
844  } else if(option.compare("ADULTS") == 0 || option.compare("adults") == 0 ||
845  option.compare("1") == 0) {
846  _setAge = ADULTS;
847  } else if(option.compare("ALL") == 0 || option.compare("all") == 0) {
848  _setAge = ALL;
849  } else {
850  warning("\"%s\" is not a valid option for parameter \"resize_age_class\".\n",option.c_str());
851  _setAge = ALL;
852  }
853 
854  if( !get_parameter("resize_patch_number")->isSet() &&
855  !get_parameter("resize_patch_capacity")->isSet() &&
856  !get_parameter("resize_female_capacity")->isSet() &&
857  !get_parameter("resize_male_capacity")->isSet() &&
858  !get_parameter("resize_keep_patch")->isSet()) {
859  error("LCE_Resize:: at least one of the population size parameters must be specified.\n");
860  return false;
861  }
862 
863  _do_regulate = get_parameter("resize_do_regulate")->isSet();
864  _do_flush = get_parameter("resize_do_flush")->isSet();
865  _do_fill = get_parameter("resize_do_fill")->isSet();
866 
867  if(get_parameter("resize_keep_patch")->isSet()) {
868  _paramSet->getMatrix("resize_keep_patch", &_patch2keep);
870  _popPtr->getCurrentGeneration() == (unsigned)_atGeneration) {
871  error("LCE_Resize:: more patches to keep than existing patches in the population!\n");
872  return false;
873  }
874  } else
875  _patch2keep.reset();
876  return true;
877 }
bool isSet()
Definition: param.h:139
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:160
int error(const char *str,...)
Definition: output.cc:78
#define ALL
All ages age class flag.
Definition: types.h:55

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

+ Here is the caller graph for this function:

◆ updatePatchCapacities()

void LCE_Resize::updatePatchCapacities ( )
985 {
987 
988  if(cap->getNbCols() != _popPtr->getPatchNbr())
989  fatal("LCE_Resize:: more patch capacities than patches in the population!\n");
990 
991  for (unsigned int i = 0; i < _popPtr->getPatchNbr(); i++) {
992  _popPtr->getPatchPtr(i)->set_KFem((unsigned int)cap->get(FEM, i));
993  _popPtr->getPatchPtr(i)->set_KMal((unsigned int)cap->get(MAL, i));
994  }
995 }
TMatrix * getPatchCapacities()
Definition: metapop.h:280
void set_KMal(unsigned int k)
Definition: metapop.h:474
void set_KFem(unsigned int k)
Definition: metapop.h:473

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

Member Data Documentation

◆ _atGeneration

int LCE_Resize::_atGeneration
private

◆ _do_fill

bool LCE_Resize::_do_fill
private

◆ _do_flush

bool LCE_Resize::_do_flush
private

Referenced by execute(), and updateParameters().

◆ _do_regulate

bool LCE_Resize::_do_regulate
private

Referenced by execute(), and updateParameters().

◆ _generations

list< int > LCE_Resize::_generations
private

Referenced by execute(), and setParameters().

◆ _genITER

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

Referenced by execute(), and setParameters().

◆ _patch2keep

◆ _patchBackup

◆ _setAge

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.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR