Nemo  2.4.0b
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 ( )
793  : LifeCycleEvent("resize",""), _atGeneration(0),
795 {
797  add_parameter("resize_at_generation", INT, 1, 0, 0, 0, updater);
799  add_parameter("resize_patch_number", INT, 0, 0, 0, 0, updater);
800  add_parameter("resize_patch_capacity", INT, 0, 0, 0, 0, updater);
801  add_parameter("resize_female_capacity", INT, 0, 0, 0, 0, updater);
802  add_parameter("resize_male_capacity", INT, 0, 0, 0, 0, updater);
803  add_parameter("resize_age_class", STR, 0, 0, 0, 0, updater);
804  add_parameter("resize_do_flush", BOOL, 0, 0, 0, 0, updater);
805  add_parameter("resize_do_regulate", BOOL, 0, 0, 0, 0, updater);
806  add_parameter("resize_do_fill", BOOL, 0, 0, 0, 0, updater);
807  add_parameter("resize_keep_patch", MAT, 0, 0, 0, 0, updater);
808 }
age_t _setAge
Definition: LCEmisc.h:228
Patch * _patchBackup
Definition: LCEmisc.h:229
int _atGeneration
Definition: LCEmisc.h:224
bool _do_fill
Definition: LCEmisc.h:226
bool _do_regulate
Definition: LCEmisc.h:226
bool updateParameters()
Definition: LCEmisc.cc:837
virtual bool setParameters()
Definition: LCEmisc.cc:812
bool _do_flush
Definition: LCEmisc.h:226
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
Implementation of the ParamUpdaterBase interface.
Definition: param.h:363
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
@ MAT
Definition: types.h:78
@ BOOL
Definition: types.h:78
@ STR
Definition: types.h:78
@ INT
Definition: types.h:78

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

Referenced by clone().

◆ ~LCE_Resize()

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

References _patchBackup.

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Resize::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

257 {return 0;}

◆ buildNewPatchArrayNoBackup()

void LCE_Resize::buildNewPatchArrayNoBackup ( )
1001 {
1002  if(_patch2keep.getNbCols() != 0) removeDesignatedPatch(false);
1003 
1004  //
1005  //add or remove patches until the array size matches Metapop::_patchNbr
1006  //up to this point, the number of patches to keep could not be != from that nbre
1008 
1009 }
TMatrix _patch2keep
Definition: LCEmisc.h:227
void removeDesignatedPatch(bool do_backup)
Definition: LCEmisc.cc:1036
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:334
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:215

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

Referenced by execute().

◆ buildNewPatchArrayWithBackup()

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

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

◆ clone()

virtual LifeCycleEvent* LCE_Resize::clone ( )
inlinevirtual

Implements LifeCycleEvent.

250 {return new LCE_Resize();}
LCE_Resize()
Definition: LCEmisc.cc:793

References LCE_Resize().

◆ execute()

void LCE_Resize::execute ( )
virtual

Implements LifeCycleEvent.

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

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 
)
1092 {
1093  Patch *patch = _popPtr->getPatchPtr(p);
1094  while (patch->size(FEM, age) != patch->get_KFem()) {
1095  patch->add(FEM, age, _popPtr->makeNewIndividual(NULL, NULL, FEM, patch->getID()));
1096  }
1097  while (patch->size(MAL, age) != patch->get_KMal()) {
1098  patch->add(MAL, age, _popPtr->makeNewIndividual(NULL, NULL, MAL, patch->getID()));
1099  }
1100 }
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 size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:498
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:551
unsigned int getID()
Definition: metapop.h:481
unsigned int get_KFem()
Definition: metapop.h:484
unsigned int get_KMal()
Definition: metapop.h:485
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

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

◆ fillPatchWithBackup()

void LCE_Resize::fillPatchWithBackup ( unsigned int  p,
age_idx  age 
)
1105 {
1106  Patch *patch = _popPtr->getPatchPtr(p);
1107  while (patch->size(FEM, age) != patch->get_KFem() && _patchBackup->size(FEM, age) != 0) {
1108  patch->add(FEM, age, _patchBackup->get(FEM, age, 0));
1109  _patchBackup->remove(FEM, age, 0);
1110  }
1111  while (patch->size(MAL, age) != patch->get_KMal() && _patchBackup->size(MAL, age) != 0) {
1112  patch->add(MAL, age, _patchBackup->get(MAL, age, 0));
1113  _patchBackup->remove(MAL, age, 0);
1114  }
1115 }
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:588
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:534

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

◆ fillPop()

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

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

Referenced by execute().

◆ loadFileServices()

virtual void LCE_Resize::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

253 {}

◆ loadStatServices()

virtual void LCE_Resize::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

254 {}

◆ regulate()

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

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

Referenced by buildNewPatchArrayWithBackup(), and execute().

◆ regulateAgeClassNoBackup()

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

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

◆ regulateAgeClassWithBackup()

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

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

◆ removeAgeClass()

virtual age_t LCE_Resize::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

256 {return 0;}

◆ removeDesignatedPatch()

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

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

◆ requiredAgeClass()

virtual age_t LCE_Resize::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

258 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

255 {return false;}

◆ setParameters()

bool LCE_Resize::setParameters ( )
virtual

Implements SimComponent.

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

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

Referenced by LCE_Resize().

◆ updateParameters()

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

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

◆ updatePatchCapacities()

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

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

Locations of visitors to this page
Catalogued on GSR