Nemo  2.4.0
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 ( )
918  : LifeCycleEvent("breed_selection",""),
920 {
921  add_parameter("breed_selection_fecundity_fitness", BOOL, false, false, 0, 0, 0);
922 // get_parameter("mean_fecundity")->setIsRequired(true); //don't set here or it will be inherited by breed_selection_disperse
923 }
void(LCE_Breed_Selection::* _breed_selection)(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.h:244
unsigned int _nb_trait
Definition: LCEcomposite.h:246
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
@ BOOL
Definition: types.h:77

References SimComponent::add_parameter(), and BOOL.

Referenced by clone().

+ Here is the caller graph for this function:

◆ ~LCE_Breed_Selection()

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Breed_Selection::addAgeClass ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

284 {return (isWrightFisher() ? NONE : OFFSPRG);}
bool isWrightFisher()
Definition: LCEbreed.h:119
#define NONE
No age flag.
Definition: types.h:47
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49

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.

279 { return new LCE_Breed_Selection(); }
LCE_Breed_Selection()
Definition: LCEcomposite.cc:918

References LCE_Breed_Selection().

◆ do_breed_selection_FecFitness()

void LCE_Breed_Selection::do_breed_selection_FecFitness ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1089 {
1090  unsigned int nbBaby;
1091  //double mean_fec;
1092  Individual* FatherPtr;
1093  Individual* MotherPtr;
1094  Individual* NewOffsprg;
1095  unsigned int cat;
1096 
1097  (this->*_setScalingFactor)(ADLTx, patchID); // @TODO fitness cached when computing fitness scaling factor?
1098 
1099  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1100  indexOfMother < size;
1101  indexOfMother++) {
1102 
1103  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1104 
1105  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(getMeanFecundity(patchID)*
1106  getFitness(MotherPtr, patchID)) );
1107 
1108  (*cntr) += nbBaby;
1109  //-----------------------------------------------------------------------
1110  while(nbBaby != 0) {
1111 
1112 
1113  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1114 
1115  NewOffsprg = LCE_Breed_base::makeOffspring( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID) );
1116 
1117  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1118 
1119  nbBaby--;
1120 
1121  cat = NewOffsprg->getPedigreeClass();
1122 
1123  _fitness[cat] += getFitness(NewOffsprg, patchID);
1124  _ind_cntr[cat]++;
1125  _survival[cat]++;
1126 
1127  }//_END__WHILE;
1128  }//end_for indexOfMother
1129 
1130 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
double setFecundity(double value)
Sets the fecundity to the value given and returns it.
Definition: individual.h:206
sex_t getSex()
Definition: individual.h:128
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:178
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:81
Individual * makeOffspring(Individual *ind)
Last step of the breeding process, does inheritance and mutation of the parents' genes.
Definition: LCEbreed.cc:350
Individual * do_breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Calls the breeding function unsing its pointer.
Definition: LCEbreed.h:176
double getMeanFecundity(unsigned int patch)
Definition: LCEbreed.h:100
double getFecundity(unsigned int patch)
Definition: LCEbreed.h:111
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:117
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:156
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:229
double _ind_cntr[5]
Definition: LCEselection.h:117
double _survival[5]
Definition: LCEselection.h:117
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
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
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
@ FEM
Definition: types.h:36
@ OFFSx
Definition: types.h:41
@ ADLTx
Definition: types.h:41

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

+ Here is the caller graph for this function:

◆ do_breed_selection_OffSurvival()

void LCE_Breed_Selection::do_breed_selection_OffSurvival ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1050 {
1051  unsigned int nbBaby;
1052  //double mean_fec;
1053  Individual* FatherPtr;
1054  Individual* MotherPtr;
1055  Individual* NewOffsprg;
1056 
1057  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1058  (this->*_setScalingFactor)(ADLTx, patchID);
1059 
1060  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1061  indexOfMother < size;
1062  indexOfMother++) {
1063 
1064  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1065 
1066  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(patchID) );
1067 
1068  (*cntr) += nbBaby;
1069  //-----------------------------------------------------------------------
1070  while(nbBaby != 0) {
1071 
1072  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1073 
1074  NewOffsprg = makeOffspringWithSelection( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID), patchID );
1075 
1076  if(NewOffsprg != NULL)
1077  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1078 
1079  nbBaby--;
1080 
1081  }//_END__WHILE;
1082  }//end_for indexOfMother
1083 
1084 }
Individual * makeOffspringWithSelection(Individual *ind, unsigned int natalpatch)
Performs viability selection and breeding at the same time.
Definition: LCEcomposite.cc:1267

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

+ Here is the caller graph for this function:

◆ do_breed_selection_WrightFisher_1sex()

void LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1188 {
1189  //WF pop with hermaphrodites
1190  Individual* FatherPtr = 0;
1191  Individual* MotherPtr = 0;
1192  Individual* NewOffsprg = 0;
1193  unsigned int size_parent = patch->size(FEM, ADLTx);
1194  unsigned int size_offspring;
1195 
1196  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1197  (this->*_setScalingFactor)(ADLTx, patchID);
1198 
1199  // FEMALE fitness
1200 
1201  gsl_ran_discrete_t* lookup_females = setReproScaledFitness_gsl(FEM, size_parent, patch);
1202 
1203  //filling female offspring container only
1204  //-----------------------------------------------------------------------
1205  size_offspring = patch->get_K(FEM);
1206 
1207  patch->resize(FEM, OFFSx, size_offspring);
1208 
1209  //make offspring by pairing mothers and fathers
1210  for(unsigned int i = 0; i < size_offspring; ++i)
1211  {
1212  MotherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1213 
1214  FatherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1215 
1216  NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
1217 
1218  NewOffsprg->setSex(FEM);
1219 
1220  patch->set(FEM, OFFSx, i, NewOffsprg); // we use set() instead of add() for efficiency
1221 
1222  }//END FOR ind
1223 
1224  // we do the generation change here directly
1225  patch->flush(ADLTx, _popPtr);
1226  patch->move(FEM, OFFSx, ADLTx);
1227 
1228  gsl_ran_discrete_free(lookup_females);
1229 
1230 }
void setSex(sex_t sex)
Definition: individual.h:111
gsl_ran_discrete_t * setReproScaledFitness_gsl(sex_t SEX, unsigned int numReproInd, Patch *patch)
Definition: LCEcomposite.cc:1249
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:80
unsigned int get_K()
Definition: metapop.h:481
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:610
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:686
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:542
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:573
static size_t Discrete(const gsl_ran_discrete_t *g)
Calling the GSL ran_discrete function.
Definition: Uniform.h:813

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

+ Here is the caller graph for this function:

◆ do_breed_selection_WrightFisher_2sex()

void LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1136 {
1137  //double mean_fec;
1138  Individual* FatherPtr = 0;
1139  Individual* MotherPtr = 0;
1140  Individual* NewOffsprg = 0;
1141  unsigned int size_parent[2] = {patch->size(MAL, ADLTx), patch->size(FEM, ADLTx)};//[MAL=0,FEM=1]
1142  unsigned int size_offspring;
1143 
1144  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1145  (this->*_setScalingFactor)(ADLTx, patchID);
1146 
1147  gsl_ran_discrete_t* lookup_females = setReproScaledFitness_gsl(FEM, size_parent[FEM], patch);
1148  gsl_ran_discrete_t* lookup_males = setReproScaledFitness_gsl(MAL, size_parent[MAL], patch);
1149 
1150  for(unsigned int s = 0; s < 2; ++s) {
1151 
1152  size_offspring = patch->get_K(sex_t(s));
1153 
1154  patch->resize(sex_t(s), OFFSx, size_offspring);
1155 
1156  //make offspring by pairing mothers and fathers
1157 
1158  for(unsigned int i = 0; i < size_offspring; ++i)
1159  {
1160  MotherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1161 
1162  FatherPtr = patch->get(MAL, ADLTx, RAND::Discrete(lookup_males) ); // gsl_ran_discrete(RAND::r, lookup_males) );
1163 
1164  NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
1165 
1166  NewOffsprg->setSex(sex_t(s));
1167 
1168  patch->set(sex_t(s), OFFSx, i, NewOffsprg);
1169  }//END FOR ind
1170 
1171  } //END FOR sex
1172 
1173  // we do the generation change here directly
1174  patch->flush(ADLTx, _popPtr); //first move adults to recycling pool
1175  patch->move(FEM, OFFSx, ADLTx); //moves offspring to adult containers, resets offsprg size to 0
1176  patch->move(MAL, OFFSx, ADLTx);
1177 
1178  gsl_ran_discrete_free(lookup_males);
1179  gsl_ran_discrete_free(lookup_females);
1180 
1181 }
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:35
@ MAL
Definition: types.h:36

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

+ Here is the caller graph for this function:

◆ execute()

void LCE_Breed_Selection::execute ( )
virtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

1006 {
1007  Patch* current_patch;
1008  unsigned int ind_count;
1009 
1010  if(_popPtr->size(OFFSPRG) != 0) {
1011  warning("offspring containers not empty at time of breeding, flushing.\n");
1012  _popPtr->flush(OFFSx);
1013  }
1014 
1015 #ifdef _DEBUG_
1016  message("LCE_Breed_Selection::execute\n");
1017 #endif
1018 
1019  _scaling_factor = 1;
1020  _mean_fitness = 0;
1021  ind_count = 0;
1022 
1024 
1025  // check if change in local optima for quantitative traits
1027 
1028  for(unsigned int home = 0; home < _popPtr->getPatchNbr(); home++) {
1029 
1030  current_patch = _popPtr->getPatch(home);
1031 
1032  if( !checkMatingCondition(current_patch) ) continue;
1033 
1034  (this->* _breed_selection) (current_patch, home, &ind_count);
1035 
1036  }//end_for home
1037 
1038  LCE_Selection_base::setMeans(ind_count);
1039 
1040 #ifdef _DEBUG_
1041  message(" (offsprg nb: %i adults nb: %i, mean fitness: %f)\n",_popPtr->size(OFFSPRG),
1043 #endif
1044 
1045 }
bool checkMatingCondition(Patch *thePatch)
Checks if any mating will take place in the patch passed as argument.
Definition: LCEbreed.h:185
double _scaling_factor
Definition: LCEselection.h:112
void checkChangeLocalOptima()
Check is rate of change in local optima has been set and must be applied.
Definition: LCEselection.cc:1322
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.cc:1417
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.cc:1406
double _mean_fitness
Definition: LCEselection.h:112
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
unsigned int getPatchNbr()
Definition: metapop.h:275
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:256
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:848
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
void warning(const char *str,...)
Definition: output.cc:57
void message(const char *message,...)
Definition: output.cc:39
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:53

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.

280 {}

◆ loadStatServices()

void LCE_Breed_Selection::loadStatServices ( StatServices loader)
virtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

999 {
1001 }
virtual void loadStatServices(StatServices *loader)
Definition: LCEselection.cc:144

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
1269 {
1270  if(!ind->getMother() || !ind->getFather())
1271  fatal("found NULL parent ptr in offspring (LCE_Breed_Selection::makeOffspringWithSelection)\n");
1272 
1273  //do inheritance of the traits under selection:
1274  for(unsigned int i = 0; i < _TraitIndices.size(); ++i)
1276 
1277  //check if the individual survives
1278  double fitness = getFitness(ind, natalpatch);
1279  unsigned int cat = ind->getPedigreeClass();
1280  bool not_survived = (RAND::Uniform() > fitness);
1281 
1282  if( not_survived ) {
1283 
1284  //this one dies
1285  _popPtr->recycle(ind);
1286 
1287  // update realized fecundity counters
1288  ind->getMother()->addMating(cat);
1289  if(cat!=4) ind->getFather()->addMating(cat);
1290 
1291  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1292 
1293  return NULL;
1294 
1295  } else {
1296  //it survived, we'll return it
1297 
1298  ind->getMother()->DidHaveABaby(cat);
1299  if(cat!=4) ind->getFather()->DidHaveABaby(cat);
1300  }
1301 
1302  //compute inheritance and mutation of the traits not under selection:
1303  for(unsigned int i = 0; i < _nonSelectedTraitIndices.size(); i++)
1305 
1306  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1307 
1308  return ind;
1309 }
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:61
void createTrait(IDX i, Individual *mother, Individual *father)
Sets a particular trait's genotype and phenotype values from the two parents.
Definition: individual.h:324
Individual * getMother()
Definition: individual.h:126
Individual * getFather()
Definition: individual.h:125
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:224
void addMating(unsigned int category)
Increments the mating counter according to the pedigree class of the offspring.
Definition: individual.h:218
vector< unsigned int > _nonSelectedTraitIndices
Definition: LCEcomposite.h:248
bool doInheritance()
Definition: LCEbreed.h:102
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:139
void updateFitnessCounters(double fitness, unsigned int ped_class, bool survived)
Updates the fitness and survival mean counters.
Definition: LCEselection.cc:1433
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:126
void fatal(const char *str,...)
Definition: output.cc:99

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

+ Here is the caller graph for this function:

◆ removeAgeClass()

virtual age_t LCE_Breed_Selection::removeAgeClass ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

283 {return NONE;}

References NONE.

◆ requiredAgeClass()

virtual age_t LCE_Breed_Selection::requiredAgeClass ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

285 {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.

282 {return false;}

◆ setNonSelectedTraitTable()

bool LCE_Breed_Selection::setNonSelectedTraitTable ( )

Builds the vector of traits not under selection.

Used in LCE_Breed_Selection_Disperse as well.

969  {
970 
972 
973  _nonSelectedTraitIndices.clear();
974 
975 #ifdef _DEBUG_
976  cout << "@@@@ " << _nb_trait - _TraitIndices.size()<< " trait(s) not under selection\n";
977 #endif
978 
979  if (_nb_trait > _TraitIndices.size()) { //means we have some traits not under selection
980 
981  for (unsigned int i = 0; i < _nb_trait; ++i) {
982  //check which trait is not under selection and add its index into the vector
983  if (find(_TraitIndices.begin(), _TraitIndices.end(), i) == _TraitIndices.end()) {
984  _nonSelectedTraitIndices.push_back(i);
985  }
986  }
987 
988  if(_nonSelectedTraitIndices.size() != _nb_trait - _TraitIndices.size())
989  return error("LCE_Breed_Selection::setParameters:: trait not under selection was not found at initialization\n");
990 
991  }
992 
993  return true;
994 }
Individual * getIndividualProtoype()
Individual prototype accessor.
Definition: indfactory.h:131
unsigned int getTraitNumber()
Accessor to the size of the traits table.
Definition: individual.h:246
int error(const char *str,...)
Definition: output.cc:78

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

+ Here is the caller graph for this function:

◆ setParameters()

bool LCE_Breed_Selection::setParameters ( )
virtual

Reimplemented from LCE_Breed_base.

Reimplemented in LCE_Breed_Selection_Disperse.

928 {
930  return false;
931 
932  unsigned int mating_system = get_parameter_value("mating_system");
933 
934  if(get_parameter("mating_isWrightFisher")->isSet()) {
935 
936  if(mating_system == 1)
937 
939 
940  else if (mating_system == 6)
941 
943 
944  else {
945  return error("breed_selection::the Wright-Fisher population model with selection can only be set with\
946  a random mating system: models 1 (2-sex random mating) or 6 (1-sex random mating)\n");
947  }
948 
949  } else {
950 
951  // check mating system and mating options:
952  if(getMeanFecundity(0) <= 0)
953  return error("breed_selection::parameter \"mean_fecundity\" is not set!\n");
954 
955  if(get_parameter("breed_selection_fecundity_fitness")->isSet()){
956 
958 
959  } else {
961  }
962  }
963 
964  return setNonSelectedTraitTable();
965 }
void do_breed_selection_WrightFisher_1sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1186
void do_breed_selection_FecFitness(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1088
void do_breed_selection_WrightFisher_2sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1134
void do_breed_selection_OffSurvival(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1049
bool setNonSelectedTraitTable()
Builds the vector of traits not under selection.
Definition: LCEcomposite.cc:969
virtual bool setParameters()
Definition: LCEbreed.cc:76
virtual bool setParameters()
Definition: LCEselection.cc:191
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138

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 
)
1250 {
1251  _scaling_factor = 1; //we want the raw fitness before re-scaling
1252 
1253  double fitnessCache[numReproInd];
1254 
1255  for(unsigned int i = 0; i < numReproInd; ++i) {
1256  fitnessCache[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1257  if(fitnessCache[i] < 0) fitnessCache[i] = 0; // clamp for gsl_ran_discrete
1258  }
1259 
1260  gsl_ran_discrete_t* table = gsl_ran_discrete_preproc(numReproInd, fitnessCache);
1261 
1262  return table;
1263 }
unsigned int getID()
Definition: metapop.h:480

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

+ Here is the caller graph for this function:

◆ setReproScaledFitness_sum()

void LCE_Breed_Selection::setReproScaledFitness_sum ( sex_t  SEX,
valarray< double > &  survival,
unsigned int  numReproFem,
Patch patch 
)
1235 {
1236  _scaling_factor = 1; //we want the raw fitness before re-scaling
1237  for(unsigned int i = 0; i < numReproInd; ++i) {
1238  survival[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1239  }
1240 
1241  double sum = survival.sum();
1242 
1243  survival /= sum;
1244 
1245 }

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

Locations of visitors to this page
Catalogued on GSR