Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCE_Breed_Selection Class Reference

Composite LCE implementing breeding and viability selection on a given trait type. More...

#include <LCEcomposite.h>

+ Inheritance diagram for LCE_Breed_Selection:
+ Collaboration diagram for LCE_Breed_Selection:

Public Member Functions

 LCE_Breed_Selection ()
 
virtual ~LCE_Breed_Selection ()
 
bool setNonSelectedTraitTable ()
 Builds the vector of traits not under selection. More...
 
IndividualmakeOffspringWithSelection (Individual *ind, unsigned int natalpatch)
 Performs viability selection and breeding at the same time. More...
 
void do_breed_selection_FecFitness (Patch *patch, unsigned int patchID, unsigned int *cntr)
 
void do_breed_selection_OffSurvival (Patch *patch, unsigned int patchID, unsigned int *cntr)
 
void do_breed_selection_WrightFisher_2sex (Patch *patch, unsigned int patchID, unsigned int *cntr)
 
void do_breed_selection_WrightFisher_1sex (Patch *patch, unsigned int patchID, unsigned int *cntr)
 
void setReproScaledFitness_sum (sex_t SEX, valarray< double > &survival, unsigned int numReproFem, Patch *patch)
 
gsl_ran_discrete_t * setReproScaledFitness_gsl (sex_t SEX, unsigned int numReproInd, Patch *patch)
 
Implementations
virtual bool setParameters ()
 
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 LCE_Breed_base
 LCE_Breed_base ()
 
virtual ~LCE_Breed_base ()
 
virtual IndividualgetFatherPtr (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Calls the mating function according to the model chosen using the function pointer, used to get the father from the mother in a patch. More...
 
void NonWrightFisherPopulation ()
 
void WrightFisherPopulation ()
 
void doAgingInWFpop ()
 
Individualbreed (Individual *mother, Individual *father, unsigned int LocalPatch)
 Makes a new individual with the right parents. More...
 
Individualbreed_cloning (Individual *mother, Individual *father, unsigned int LocalPatch)
 Makes a new individual by doing a deep copy of the mother (copies the mother's genes into the offspring). More...
 
IndividualmakeOffspring (Individual *ind)
 Last step of the breeding process, does inheritance and mutation of the parents' genes. More...
 
IndividualmakeOffspring (Individual *newind, Individual *mother, Individual *father, unsigned int natalPatch)
 Overloads previous function when a new offspring is created "in-place", that is from existing pointer in a patch. More...
 
Individualdo_breed (Individual *mother, Individual *father, unsigned int LocalPatch)
 Calls the breeding function unsing its pointer. More...
 
bool checkMatingCondition (Patch *thePatch)
 Checks if any mating will take place in the patch passed as argument. More...
 
bool checkNoSelfing (Patch *thePatch)
 Checks whether mating will take place in the current patch when mating is not selfing or cloning. More...
 
bool checkPolygyny (Patch *thePatch)
 Checks whether mating will take place in the current patch when mating is polygynous. More...
 
bool checkSelfing (Patch *thePatch)
 Checks whether mating will take place in the current patch when mating is selfing. More...
 
bool checkCloning (Patch *thePatch)
 Checks whether mating will take place in the current patch when mating is cloning. More...
 
bool setMatingSystem ()
 
bool setFecundity ()
 
bool setSexRatio ()
 
double getMatingProportion ()
 
double getMeanFecundity (unsigned int patch)
 
int getMatingSystem ()
 
bool doInheritance ()
 
double getPoissonFecundity (double mean)
 
double getFixedFecundity (double mean)
 
double getGaussianFecundity (double mean)
 
double getLogNormalFecundity (double mean)
 
double getFecundity (unsigned int patch)
 
double getFecundity (double mean)
 
sex_t getOffsprgSex ()
 
sex_t getOffsprgSexRandom ()
 
sex_t getOffsprgSexFixed ()
 
sex_t getOffsprgSexSelfing ()
 
sex_t getOffsprgSexCloning ()
 
bool isWrightFisher ()
 
IndividualRandomMating (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a pointer to a male drawn randomly from a patch. More...
 
IndividualfullPolyginy (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a pointer to the alpha male of the patch. More...
 
IndividualfullPolyginy_manyMales (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a pointer to one of the first _mating_males males of the patch. More...
 
IndividualpartialPolyginy (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a pointer to a male from a patch chosen at random if _mating_proportion != 1, or the first male otherwise. More...
 
IndividualpartialPolyginy_manyMales (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a pointer to a male from a patch chosen at random if _mating_proportion != 1, or one of the _mating_males first males otherwise. More...
 
IndividualfullMonoginy (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a pointer to a male with same index as mother (if available) from the focal patch. More...
 
IndividualpartialMonoginy (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a pointer to a male with same index as mother (if available) from the focal patch. More...
 
IndividualfullSelfing (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns the mother pointer. More...
 
IndividualpartialSelfing (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns the mother pointer or a random female if _mating_proportion != 1. More...
 
Individualrandom_hermaphrodite (Patch *thePatch, Individual *mother, unsigned int motherIndex)
 Returns a random female from the patch, will be the same mother with probability 1/N (Wright-Fisher model). More...
 
- 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...
 
- Public Member Functions inherited from LCE_Selection_base
 LCE_Selection_base ()
 
virtual ~LCE_Selection_base ()
 
bool setSelectionMatrix ()
 
bool setSelectTraitMapping (unsigned int num_quanti_traits)
 
bool setSelectionOffset (double default_val, double min_val)
 
bool setLocalOptima ()
 
const TMatrixgetLocalOptima () const
 
bool set_sel_model ()
 
bool set_fit_model ()
 
bool set_local_optima ()
 
bool set_param_rate_of_change ()
 
void set_std_rate_of_change ()
 
void addPhenotypicSD (unsigned int deme, double *stDev)
 
void changeLocalOptima ()
 
void resetCounters ()
 Resets the fitness counters. More...
 
void setMeans (unsigned int tot_ind)
 Computes the average fitness of each pedigree class. More...
 
void updateFitnessCounters (double fitness, unsigned int ped_class, bool survived)
 Updates the fitness and survival mean counters. More...
 
double getMeanFitness (age_idx age)
 Computes the mean fitness of the whole population for a given age class. More...
 
double getMeanPatchFitness (age_idx age, unsigned int p)
 Computes the mean fitness in a given patch for a given age class. More...
 
double getMaxFitness (age_idx age)
 Computes the maximum fitness value of the whole population for a given age class. More...
 
double getMaxPatchFitness (age_idx age, unsigned int p)
 Computes the maximum fitness value in a given patch for a given age class. More...
 
double setMeanFitness (age_idx age)
 Sets the _mean_fitness variable to the value of the mean population fitness. More...
 
double getFitness (Individual *ind, unsigned int patch)
 Calls the fitness function according to the fitness model. More...
 
double getFitnessFixedEffect (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual in the fixed selection model. More...
 
double getFitnessDirect (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following the direct selection model. More...
 
double getFitnessUnivariateQuadratic (Individual *ind, unsigned int patch, unsigned int trait)
 Quadratic fitness surface, approximates the Gaussian model for weak selection and/or small deviation from the optimum. More...
 
double getFitnessUnivariateLinear (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Linear selection model with a single trait under selection. More...
 
double getFitnessUnivariateDisruptive (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with one trait under selection. More...
 
double getFitnessMultivariateDisruptive (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with several traits under selection. More...
 
double getFitnessTruncation (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Truncation selection model. More...
 
double getFitnessMultivariateGaussian (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following the Gaussian selection model with one trait under selection. More...
 
double getFitnessUnivariateGaussian (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following the Gaussian selection model with several traits under selection. More...
 
double getFitnessMultivariateGaussian_VE (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following the Gaussian selection model with one trait under selection and environmental variance. More...
 
double getFitnessUnivariateGaussian_VE (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following the Gaussian selection model with several traits under selection and environmental variance. More...
 
double getFitnessAbsolute (Individual *ind, unsigned int patch)
 Returns the raw fitness of the individual, without adjustment (absolute fitness). More...
 
double getFitnessRelative (Individual *ind, unsigned int patch)
 Returns the relative fitness of the individual, adjusted by a scaling factor. More...
 
void setScalingFactorLocal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the mean local patch fitness. More...
 
void setScalingFactorGlobal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the mean population fitness. More...
 
void setScalingFactorMaxLocal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the maximum local patch fitness value. More...
 
void setScalingFactorMaxGlobal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the maximum population fitness value. More...
 
void setScalingFactorForLinearSelection (age_idx age, unsigned int p)
 Sets the fitness scaling factor as the mean trait value in the patch to compute the fitness value in the linear selection model. More...
 
void setScalingFactorAbsolute (age_idx age, unsigned int p)
 Resets the fitness scaling factor equal to one. More...
 
void doViabilitySelection (sex_t SEX, age_idx AGE, Patch *patch, unsigned int p)
 Selectively removes individuals in the population depending on their fitness. More...
 
void checkChangeLocalOptima ()
 Check is rate of change in local optima has been set and must be applied. More...
 

Private Attributes

void(LCE_Breed_Selection::* _breed_selection )(Patch *patch, unsigned int patchID, unsigned int *cntr)
 
unsigned int _nb_trait
 
vector< unsigned int > _nonSelectedTraitIndices
 

Additional Inherited Members

- Protected Attributes inherited from LCE_Breed_base
TMatrix _mean_fecundity
 
Individual *(LCE_Breed_base::* MatingFuncPtr )(Patch *, Individual *, unsigned int)
 
Individual *(LCE_Breed_base::* DoBreedFuncPtr )(Individual *mother, Individual *father, unsigned int LocalPatch)
 
double(LCE_Breed_base::* FecundityFuncPtr )(double mean)
 
bool(LCE_Breed_base::* CheckMatingConditionFuncPtr )(Patch *thePatch)
 
sex_t(LCE_Breed_base::* GetOffsprgSex )()
 
void(LCE_Breed_base::* PopModelFuncPtr )(void)
 
- 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...
 
- Protected Attributes inherited from LCE_Selection_base
double _base_fitness
 
double _mean_fitness
 
double _max_fitness
 
double _scaling_factor
 
bool _is_local
 
bool _is_absolute
 
double _fitness [5]
 Fitness counters, one for each pedigree class. More...
 
double _survival [5]
 
double _ind_cntr [5]
 
vector< string > _Traits
 The list of trait types under selection. More...
 
vector< unsigned int > _TraitIndices
 The indices of the traits under selection. More...
 
vector< string > _SelectionModels
 The selection models associated with each trait under selection. More...
 
LCE_SelectionSH_stater
 
LCE_SelectionFH_writer
 
int _selectTraitDimension
 Number of quantitative traits under selection. More...
 
vector< unsigned int > _selectTraitMapping
 Mapping from selection dimension index to quanti trait index (0-based). More...
 
vector< double > _selection_variance
 Patch-specific selection variance. More...
 
double _eVariance
 Evironmental variance. More...
 
vector< double(LCE_Selection_base::*)(Individual *, unsigned int, unsigned int) > _getRawFitness
 A vector containing pointers to fitness function related to each trait under selection. More...
 
double(LCE_Selection_base::* _getFitness )(Individual *, unsigned int)
 Pointer to the function returning the individual fitness. More...
 
void(LCE_Selection_base::* _setScalingFactor )(age_idx, unsigned int)
 Pointer to the function used to set the fitness scaling factor when fitness is relative. More...
 
void(LCE_Selection_base::* _setNewLocalOptima )(void)
 Pointer to the function used to change the local phenotypic optima or its rate of change. More...
 

Detailed Description

Composite LCE implementing breeding and viability selection on a given trait type.

Inherits from LCE_Breed_base and LCE_Selection_base.

Constructor & Destructor Documentation

◆ LCE_Breed_Selection()

LCE_Breed_Selection::LCE_Breed_Selection ( )
870  : LifeCycleEvent("breed_selection",""),
872 {
873  add_parameter("breed_selection_fecundity_fitness", BOOL, false, false, 0, 0, 0);
874 // get_parameter("mean_fecundity")->setIsRequired(true); //don't set here or it will be inherited by breed_selection_disperse
875 }
void(LCE_Breed_Selection::* _breed_selection)(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.h:240
unsigned int _nb_trait
Definition: LCEcomposite.h:242
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
@ BOOL
Definition: types.h:78

References SimComponent::add_parameter(), and BOOL.

Referenced by clone().

◆ ~LCE_Breed_Selection()

virtual LCE_Breed_Selection::~LCE_Breed_Selection ( )
inlinevirtual
249 {}

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Breed_Selection::addAgeClass ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

280 {return (isWrightFisher() ? NONE : OFFSPRG);}
bool isWrightFisher()
Definition: LCEbreed.h:120
#define NONE
No age flag.
Definition: types.h:48
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50

References LCE_Breed_base::isWrightFisher(), NONE, and OFFSPRG.

◆ clone()

virtual LifeCycleEvent* LCE_Breed_Selection::clone ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

275 { return new LCE_Breed_Selection(); }
LCE_Breed_Selection()
Definition: LCEcomposite.cc:870

References LCE_Breed_Selection().

◆ do_breed_selection_FecFitness()

void LCE_Breed_Selection::do_breed_selection_FecFitness ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1041 {
1042  unsigned int nbBaby;
1043  //double mean_fec;
1044  Individual* FatherPtr;
1045  Individual* MotherPtr;
1046  Individual* NewOffsprg;
1047  unsigned int cat;
1048 
1049  (this->*_setScalingFactor)(ADLTx, patchID); // @TODO fitness cached when computing fitness scaling factor?
1050 
1051  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1052  indexOfMother < size;
1053  indexOfMother++) {
1054 
1055  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1056 
1057  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(getMeanFecundity(patchID)*
1058  getFitness(MotherPtr, patchID)) );
1059 
1060  (*cntr) += nbBaby;
1061  //-----------------------------------------------------------------------
1062  while(nbBaby != 0) {
1063 
1064 
1065  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1066 
1067  NewOffsprg = LCE_Breed_base::makeOffspring( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID) );
1068 
1069  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1070 
1071  nbBaby--;
1072 
1073  cat = NewOffsprg->getPedigreeClass();
1074 
1075  _fitness[cat] += getFitness(NewOffsprg, patchID);
1076  _ind_cntr[cat]++;
1077  _survival[cat]++;
1078 
1079  }//_END__WHILE;
1080  }//end_for indexOfMother
1081 
1082 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
double setFecundity(double value)
Sets the fecundity to the value given and returns it.
Definition: individual.h:207
sex_t getSex()
Definition: individual.h:129
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
virtual Individual * getFatherPtr(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Calls the mating function according to the model chosen using the function pointer,...
Definition: LCEbreed.h:82
Individual * makeOffspring(Individual *ind)
Last step of the breeding process, does inheritance and mutation of the parents' genes.
Definition: LCEbreed.cc:351
Individual * do_breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Calls the breeding function unsing its pointer.
Definition: LCEbreed.h:177
double getMeanFecundity(unsigned int patch)
Definition: LCEbreed.h:101
double getFecundity(unsigned int patch)
Definition: LCEbreed.h:112
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:118
void(LCE_Selection_base::* _setScalingFactor)(age_idx, unsigned int)
Pointer to the function used to set the fitness scaling factor when fitness is relative.
Definition: LCEselection.h:157
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:230
double _ind_cntr[5]
Definition: LCEselection.h:118
double _survival[5]
Definition: LCEselection.h:118
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
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
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
@ FEM
Definition: types.h:37
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References LCE_Selection_base::_fitness, LCE_Selection_base::_ind_cntr, LCE_Selection_base::_setScalingFactor, LCE_Selection_base::_survival, Patch::add(), ADLTx, LCE_Breed_base::do_breed(), FEM, Patch::get(), LCE_Breed_base::getFatherPtr(), LCE_Breed_base::getFecundity(), LCE_Selection_base::getFitness(), LCE_Breed_base::getMeanFecundity(), Individual::getPedigreeClass(), Individual::getSex(), LCE_Breed_base::makeOffspring(), OFFSx, Individual::setFecundity(), and Patch::size().

Referenced by setParameters().

◆ do_breed_selection_OffSurvival()

void LCE_Breed_Selection::do_breed_selection_OffSurvival ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1002 {
1003  unsigned int nbBaby;
1004  //double mean_fec;
1005  Individual* FatherPtr;
1006  Individual* MotherPtr;
1007  Individual* NewOffsprg;
1008 
1009  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1010  (this->*_setScalingFactor)(ADLTx, patchID);
1011 
1012  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1013  indexOfMother < size;
1014  indexOfMother++) {
1015 
1016  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1017 
1018  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(patchID) );
1019 
1020  (*cntr) += nbBaby;
1021  //-----------------------------------------------------------------------
1022  while(nbBaby != 0) {
1023 
1024  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1025 
1026  NewOffsprg = makeOffspringWithSelection( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID), patchID );
1027 
1028  if(NewOffsprg != NULL)
1029  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1030 
1031  nbBaby--;
1032 
1033  }//_END__WHILE;
1034  }//end_for indexOfMother
1035 
1036 }
Individual * makeOffspringWithSelection(Individual *ind, unsigned int natalpatch)
Performs viability selection and breeding at the same time.
Definition: LCEcomposite.cc:1219

References LCE_Selection_base::_setScalingFactor, Patch::add(), ADLTx, LCE_Breed_base::do_breed(), FEM, Patch::get(), LCE_Breed_base::getFatherPtr(), LCE_Breed_base::getFecundity(), Individual::getSex(), makeOffspringWithSelection(), OFFSx, Individual::setFecundity(), and Patch::size().

Referenced by setParameters().

◆ do_breed_selection_WrightFisher_1sex()

void LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1140 {
1141  //WF pop with hermaphrodites
1142  Individual* FatherPtr = 0;
1143  Individual* MotherPtr = 0;
1144  Individual* NewOffsprg = 0;
1145  unsigned int size_parent = patch->size(FEM, ADLTx);
1146  unsigned int size_offspring;
1147 
1148  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1149  (this->*_setScalingFactor)(ADLTx, patchID);
1150 
1151  // FEMALE fitness
1152 
1153  gsl_ran_discrete_t* lookup_females = setReproScaledFitness_gsl(FEM, size_parent, patch);
1154 
1155  //filling female offspring container only
1156  //-----------------------------------------------------------------------
1157  size_offspring = patch->get_K(FEM);
1158 
1159  patch->resize(FEM, OFFSx, size_offspring);
1160 
1161  //make offspring by pairing mothers and fathers
1162  for(unsigned int i = 0; i < size_offspring; ++i)
1163  {
1164  MotherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1165 
1166  FatherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1167 
1168  NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
1169 
1170  NewOffsprg->setSex(FEM);
1171 
1172  patch->set(FEM, OFFSx, i, NewOffsprg); // we use set() instead of add() for efficiency
1173 
1174  }//END FOR ind
1175 
1176  // we do the generation change here directly
1177  patch->flush(ADLTx, _popPtr);
1178  patch->move(FEM, OFFSx, ADLTx);
1179 
1180  gsl_ran_discrete_free(lookup_females);
1181 
1182 }
void setSex(sex_t sex)
Definition: individual.h:112
gsl_ran_discrete_t * setReproScaledFitness_gsl(sex_t SEX, unsigned int numReproInd, Patch *patch)
Definition: LCEcomposite.cc:1201
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
unsigned int get_K()
Definition: metapop.h:482
void move(sex_t SEX, age_idx from, age_idx to, unsigned int at)
Moves an individual from an age class to an other one.
Definition: metapop.h:611
void flush(sex_t SEX, age_idx AGE, Metapop *pop)
Removes all individual pointers of the appropriate sex and age class and flush them into the recyclin...
Definition: metapop.h:687
void set(sex_t SEX, age_idx AGE, unsigned int at, Individual *ind)
Modifies the appropriate container with value of the pointer given.
Definition: metapop.h:543
void resize(sex_t SEX, age_idx AGE, size_t new_size)
Reserves a certain range of values that are assigned to 0 in a given container.
Definition: metapop.h:574
static size_t Discrete(const gsl_ran_discrete_t *g)
Calling the GSL ran_discrete function.
Definition: Uniform.h:816

References LifeCycleEvent::_popPtr, LCE_Selection_base::_setScalingFactor, ADLTx, RAND::Discrete(), LCE_Breed_base::do_breed(), FEM, Patch::flush(), Patch::get(), Patch::get_K(), LCE_Breed_base::makeOffspring(), Patch::move(), OFFSx, Patch::resize(), Patch::set(), setReproScaledFitness_gsl(), Individual::setSex(), and Patch::size().

Referenced by setParameters().

◆ do_breed_selection_WrightFisher_2sex()

void LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1088 {
1089  //double mean_fec;
1090  Individual* FatherPtr = 0;
1091  Individual* MotherPtr = 0;
1092  Individual* NewOffsprg = 0;
1093  unsigned int size_parent[2] = {patch->size(MAL, ADLTx), patch->size(FEM, ADLTx)};//[MAL=0,FEM=1]
1094  unsigned int size_offspring;
1095 
1096  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1097  (this->*_setScalingFactor)(ADLTx, patchID);
1098 
1099  gsl_ran_discrete_t* lookup_females = setReproScaledFitness_gsl(FEM, size_parent[FEM], patch);
1100  gsl_ran_discrete_t* lookup_males = setReproScaledFitness_gsl(MAL, size_parent[MAL], patch);
1101 
1102  for(unsigned int s = 0; s < 2; ++s) {
1103 
1104  size_offspring = patch->get_K(sex_t(s));
1105 
1106  patch->resize(sex_t(s), OFFSx, size_offspring);
1107 
1108  //make offspring by pairing mothers and fathers
1109 
1110  for(unsigned int i = 0; i < size_offspring; ++i)
1111  {
1112  MotherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1113 
1114  FatherPtr = patch->get(MAL, ADLTx, RAND::Discrete(lookup_males) ); // gsl_ran_discrete(RAND::r, lookup_males) );
1115 
1116  NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
1117 
1118  NewOffsprg->setSex(sex_t(s));
1119 
1120  patch->set(sex_t(s), OFFSx, i, NewOffsprg);
1121  }//END FOR ind
1122 
1123  } //END FOR sex
1124 
1125  // we do the generation change here directly
1126  patch->flush(ADLTx, _popPtr); //first move adults to recycling pool
1127  patch->move(FEM, OFFSx, ADLTx); //moves offspring to adult containers, resets offsprg size to 0
1128  patch->move(MAL, OFFSx, ADLTx);
1129 
1130  gsl_ran_discrete_free(lookup_males);
1131  gsl_ran_discrete_free(lookup_females);
1132 
1133 }
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
@ MAL
Definition: types.h:37

References LifeCycleEvent::_popPtr, LCE_Selection_base::_setScalingFactor, ADLTx, RAND::Discrete(), LCE_Breed_base::do_breed(), FEM, Patch::flush(), Patch::get(), Patch::get_K(), LCE_Breed_base::makeOffspring(), MAL, Patch::move(), OFFSx, Patch::resize(), Patch::set(), setReproScaledFitness_gsl(), Individual::setSex(), and Patch::size().

Referenced by setParameters().

◆ execute()

void LCE_Breed_Selection::execute ( )
virtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

958 {
959  Patch* current_patch;
960  unsigned int ind_count;
961 
962  if(_popPtr->size(OFFSPRG) != 0) {
963  warning("offspring containers not empty at time of breeding, flushing.\n");
964  _popPtr->flush(OFFSx);
965  }
966 
967 #ifdef _DEBUG_
968  message("LCE_Breed_Selection::execute\n");
969 #endif
970 
971  _scaling_factor = 1;
972  _mean_fitness = 0;
973  ind_count = 0;
974 
976 
977  // check if change in local optima for quantitative traits
979 
980  for(unsigned int home = 0; home < _popPtr->getPatchNbr(); home++) {
981 
982  current_patch = _popPtr->getPatch(home);
983 
984  if( !checkMatingCondition(current_patch) ) continue;
985 
986  (this->* _breed_selection) (current_patch, home, &ind_count);
987 
988  }//end_for home
989 
990  LCE_Selection_base::setMeans(ind_count);
991 
992 #ifdef _DEBUG_
993  message(" (offsprg nb: %i adults nb: %i, mean fitness: %f)\n",_popPtr->size(OFFSPRG),
995 #endif
996 
997 }
bool checkMatingCondition(Patch *thePatch)
Checks if any mating will take place in the patch passed as argument.
Definition: LCEbreed.h:186
double _scaling_factor
Definition: LCEselection.h:113
void checkChangeLocalOptima()
Check is rate of change in local optima has been set and must be applied.
Definition: LCEselection.cc:1305
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.cc:1400
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.cc:1389
double _mean_fitness
Definition: LCEselection.h:113
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:312
unsigned int getPatchNbr()
Definition: metapop.h:276
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:849
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
void warning(const char *str,...)
Definition: output.cc:58
void message(const char *message,...)
Definition: output.cc:40
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54

References _breed_selection, LCE_Selection_base::_mean_fitness, LifeCycleEvent::_popPtr, LCE_Selection_base::_scaling_factor, ADULTS, LCE_Selection_base::checkChangeLocalOptima(), LCE_Breed_base::checkMatingCondition(), Metapop::flush(), Metapop::getPatch(), Metapop::getPatchNbr(), message(), OFFSPRG, OFFSx, LCE_Selection_base::resetCounters(), LCE_Selection_base::setMeans(), Metapop::size(), and warning().

◆ loadFileServices()

virtual void LCE_Breed_Selection::loadFileServices ( FileServices loader)
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

276 {}

◆ loadStatServices()

void LCE_Breed_Selection::loadStatServices ( StatServices loader)
virtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

951 {
953 }
virtual void loadStatServices(StatServices *loader)
Definition: LCEselection.cc:139

References LCE_Selection_base::loadStatServices().

◆ makeOffspringWithSelection()

Individual * LCE_Breed_Selection::makeOffspringWithSelection ( Individual ind,
unsigned int  natalpatch 
)

Performs viability selection and breeding at the same time.

The selected trait is first inherited (with recombination and mutations) and survival checked before the remaining traits are inherited. This helps save some computing time. The function returns a null pointer in case of selective death.

Parameters
indthe newborn, its new traits have not been computed yet
natalpatchthe index of the natal patch of the offfspring where selectin takes palce
1221 {
1222  if(!ind->getMother() || !ind->getFather())
1223  fatal("found NULL parent ptr in offspring (LCE_Breed_Selection::makeOffspringWithSelection)\n");
1224 
1225  //do inheritance of the traits under selection:
1226  for(unsigned int i = 0; i < _TraitIndices.size(); ++i)
1228 
1229  //check if the individual survives
1230  double fitness = getFitness(ind, natalpatch);
1231  unsigned int cat = ind->getPedigreeClass();
1232  bool not_survived = (RAND::Uniform() > fitness);
1233 
1234  if( not_survived ) {
1235 
1236  //this one dies
1237  _popPtr->recycle(ind);
1238 
1239  // update realized fecundity counters
1240  ind->getMother()->addMating(cat);
1241  if(cat!=4) ind->getFather()->addMating(cat);
1242 
1243  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1244 
1245  return NULL;
1246 
1247  } else {
1248  //it survived, we'll return it
1249 
1250  ind->getMother()->DidHaveABaby(cat);
1251  if(cat!=4) ind->getFather()->DidHaveABaby(cat);
1252  }
1253 
1254  //compute inheritance and mutation of the traits not under selection:
1255  for(unsigned int i = 0; i < _nonSelectedTraitIndices.size(); i++)
1257 
1258  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1259 
1260  return ind;
1261 }
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:62
void createTrait(IDX i, Individual *mother, Individual *father)
Sets a particular trait's genotype and phenotype values from the two parents.
Definition: individual.h:325
Individual * getMother()
Definition: individual.h:127
Individual * getFather()
Definition: individual.h:126
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:225
void addMating(unsigned int category)
Increments the mating counter according to the pedigree class of the offspring.
Definition: individual.h:219
vector< unsigned int > _nonSelectedTraitIndices
Definition: LCEcomposite.h:244
bool doInheritance()
Definition: LCEbreed.h:103
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:140
void updateFitnessCounters(double fitness, unsigned int ped_class, bool survived)
Updates the fitness and survival mean counters.
Definition: LCEselection.cc:1416
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:127
void fatal(const char *str,...)
Definition: output.cc:100

References _nonSelectedTraitIndices, LifeCycleEvent::_popPtr, LCE_Selection_base::_TraitIndices, Individual::addMating(), Individual::createTrait(), Individual::DidHaveABaby(), LCE_Breed_base::doInheritance(), fatal(), Individual::getFather(), LCE_Selection_base::getFitness(), Individual::getMother(), Individual::getPedigreeClass(), IndFactory::recycle(), RAND::Uniform(), and LCE_Selection_base::updateFitnessCounters().

Referenced by LCE_Breed_Selection_Disperse::do_breed(), and do_breed_selection_OffSurvival().

◆ removeAgeClass()

virtual age_t LCE_Breed_Selection::removeAgeClass ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

279 {return NONE;}

References NONE.

◆ requiredAgeClass()

virtual age_t LCE_Breed_Selection::requiredAgeClass ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

281 {return ADULTS;}

References ADULTS.

◆ resetParameterFromSource()

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

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

278 {return false;}

◆ setNonSelectedTraitTable()

bool LCE_Breed_Selection::setNonSelectedTraitTable ( )

Builds the vector of traits not under selection.

Used in LCE_Breed_Selection_Disperse as well.

921  {
922 
924 
925  _nonSelectedTraitIndices.clear();
926 
927 #ifdef _DEBUG_
928  cout << "@@@@ " << _nb_trait - _TraitIndices.size()<< " trait(s) not under selection\n";
929 #endif
930 
931  if (_nb_trait > _TraitIndices.size()) { //means we have some traits not under selection
932 
933  for (unsigned int i = 0; i < _nb_trait; ++i) {
934  //check which trait is not under selection and add its index into the vector
935  if (find(_TraitIndices.begin(), _TraitIndices.end(), i) == _TraitIndices.end()) {
936  _nonSelectedTraitIndices.push_back(i);
937  }
938  }
939 
940  if(_nonSelectedTraitIndices.size() != _nb_trait - _TraitIndices.size())
941  return error("LCE_Breed_Selection::setParameters:: trait not under selection was not found at initialization\n");
942 
943  }
944 
945  return true;
946 }
Individual * getIndividualProtoype()
Individual prototype accessor.
Definition: indfactory.h:132
unsigned int getTraitNumber()
Accessor to the size of the traits table.
Definition: individual.h:247
int error(const char *str,...)
Definition: output.cc:79

References _nb_trait, _nonSelectedTraitIndices, LifeCycleEvent::_popPtr, LCE_Selection_base::_TraitIndices, error(), IndFactory::getIndividualProtoype(), and Individual::getTraitNumber().

Referenced by setParameters(), and LCE_Breed_Selection_Disperse::setParameters().

◆ setParameters()

bool LCE_Breed_Selection::setParameters ( )
virtual

Reimplemented from LCE_Breed_base.

Reimplemented in LCE_Breed_Selection_Disperse.

880 {
882  return false;
883 
884  unsigned int mating_system = get_parameter_value("mating_system");
885 
886  if(get_parameter("mating_isWrightFisher")->isSet()) {
887 
888  if(mating_system == 1)
889 
891 
892  else if (mating_system == 6)
893 
895 
896  else {
897  return error("breed_selection::the Wright-Fisher population model with selection can only be set with\
898  a random mating system: models 1 (2-sex random mating) or 6 (1-sex random mating)\n");
899  }
900 
901  } else {
902 
903  // check mating system and mating options:
904  if(getMeanFecundity(0) <= 0)
905  return error("breed_selection::parameter \"mean_fecundity\" is not set!\n");
906 
907  if(get_parameter("breed_selection_fecundity_fitness")->isSet()){
908 
910 
911  } else {
913  }
914  }
915 
916  return setNonSelectedTraitTable();
917 }
void do_breed_selection_WrightFisher_1sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1138
void do_breed_selection_FecFitness(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1040
void do_breed_selection_WrightFisher_2sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1086
void do_breed_selection_OffSurvival(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1001
bool setNonSelectedTraitTable()
Builds the vector of traits not under selection.
Definition: LCEcomposite.cc:921
virtual bool setParameters()
Definition: LCEbreed.cc:77
virtual bool setParameters()
Definition: LCEselection.cc:186
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139

References _breed_selection, do_breed_selection_FecFitness(), do_breed_selection_OffSurvival(), do_breed_selection_WrightFisher_1sex(), do_breed_selection_WrightFisher_2sex(), error(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), LCE_Breed_base::getMeanFecundity(), setNonSelectedTraitTable(), LCE_Breed_base::setParameters(), and LCE_Selection_base::setParameters().

◆ setReproScaledFitness_gsl()

gsl_ran_discrete_t * LCE_Breed_Selection::setReproScaledFitness_gsl ( sex_t  SEX,
unsigned int  numReproInd,
Patch patch 
)
1202 {
1203  _scaling_factor = 1; //we want the raw fitness before re-scaling
1204 
1205  double fitnessCache[numReproInd];
1206 
1207  for(unsigned int i = 0; i < numReproInd; ++i) {
1208  fitnessCache[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1209  if(fitnessCache[i] < 0) fitnessCache[i] = 0; // clamp for gsl_ran_discrete
1210  }
1211 
1212  gsl_ran_discrete_t* table = gsl_ran_discrete_preproc(numReproInd, fitnessCache);
1213 
1214  return table;
1215 }
unsigned int getID()
Definition: metapop.h:481

References LCE_Selection_base::_scaling_factor, ADLTx, Patch::get(), LCE_Selection_base::getFitness(), and Patch::getID().

Referenced by do_breed_selection_WrightFisher_1sex(), and do_breed_selection_WrightFisher_2sex().

◆ setReproScaledFitness_sum()

void LCE_Breed_Selection::setReproScaledFitness_sum ( sex_t  SEX,
valarray< double > &  survival,
unsigned int  numReproFem,
Patch patch 
)
1187 {
1188  _scaling_factor = 1; //we want the raw fitness before re-scaling
1189  for(unsigned int i = 0; i < numReproInd; ++i) {
1190  survival[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1191  }
1192 
1193  double sum = survival.sum();
1194 
1195  survival /= sum;
1196 
1197 }

References LCE_Selection_base::_scaling_factor, ADLTx, Patch::get(), LCE_Selection_base::getFitness(), and Patch::getID().

Member Data Documentation

◆ _breed_selection

void(LCE_Breed_Selection::* LCE_Breed_Selection::_breed_selection) (Patch *patch, unsigned int patchID, unsigned int *cntr)
private

Referenced by execute(), and setParameters().

◆ _nb_trait

unsigned int LCE_Breed_Selection::_nb_trait
private

◆ _nonSelectedTraitIndices

vector< unsigned int > LCE_Breed_Selection::_nonSelectedTraitIndices
private

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