Nemo  2.4.1
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 ( )
898  : LifeCycleEvent("breed_selection",""),
900 {
901  add_parameter("breed_selection_fecundity_fitness", BOOL, false, false, 0, 0, 0);
902 // get_parameter("mean_fecundity")->setIsRequired(true); //don't set here or it will be inherited by breed_selection_disperse
903 }
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:898

References LCE_Breed_Selection().

◆ do_breed_selection_FecFitness()

void LCE_Breed_Selection::do_breed_selection_FecFitness ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1069 {
1070  unsigned int nbBaby;
1071  //double mean_fec;
1072  Individual* FatherPtr;
1073  Individual* MotherPtr;
1074  Individual* NewOffsprg;
1075  unsigned int cat;
1076 
1077  (this->*_setScalingFactor)(ADLTx, patchID); // @TODO fitness cached when computing fitness scaling factor?
1078 
1079  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1080  indexOfMother < size;
1081  indexOfMother++) {
1082 
1083  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1084 
1085  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(getMeanFecundity(patchID)*
1086  getFitness(MotherPtr, patchID)) );
1087 
1088  (*cntr) += nbBaby;
1089  //-----------------------------------------------------------------------
1090  while(nbBaby != 0) {
1091 
1092 
1093  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1094 
1095  NewOffsprg = LCE_Breed_base::makeOffspring( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID) );
1096 
1097  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1098 
1099  nbBaby--;
1100 
1101  cat = NewOffsprg->getPedigreeClass();
1102 
1103  _fitness[cat] += getFitness(NewOffsprg, patchID);
1104  _ind_cntr[cat]++;
1105  _survival[cat]++;
1106 
1107  }//_END__WHILE;
1108  }//end_for indexOfMother
1109 
1110 }
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 
)
1030 {
1031  unsigned int nbBaby;
1032  //double mean_fec;
1033  Individual* FatherPtr;
1034  Individual* MotherPtr;
1035  Individual* NewOffsprg;
1036 
1037  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1038  (this->*_setScalingFactor)(ADLTx, patchID);
1039 
1040  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1041  indexOfMother < size;
1042  indexOfMother++) {
1043 
1044  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1045 
1046  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(patchID) );
1047 
1048  (*cntr) += nbBaby;
1049  //-----------------------------------------------------------------------
1050  while(nbBaby != 0) {
1051 
1052  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1053 
1054  NewOffsprg = makeOffspringWithSelection( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID), patchID );
1055 
1056  if(NewOffsprg != NULL)
1057  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1058 
1059  nbBaby--;
1060 
1061  }//_END__WHILE;
1062  }//end_for indexOfMother
1063 
1064 }
Individual * makeOffspringWithSelection(Individual *ind, unsigned int natalpatch)
Performs viability selection and breeding at the same time.
Definition: LCEcomposite.cc:1247

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 
)
1168 {
1169  //WF pop with hermaphrodites
1170  Individual* FatherPtr = 0;
1171  Individual* MotherPtr = 0;
1172  Individual* NewOffsprg = 0;
1173  unsigned int size_parent = patch->size(FEM, ADLTx);
1174  unsigned int size_offspring;
1175 
1176  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1177  (this->*_setScalingFactor)(ADLTx, patchID);
1178 
1179  // FEMALE fitness
1180 
1181  gsl_ran_discrete_t* lookup_females = setReproScaledFitness_gsl(FEM, size_parent, patch);
1182 
1183  //filling female offspring container only
1184  //-----------------------------------------------------------------------
1185  size_offspring = patch->get_K(FEM);
1186 
1187  patch->resize(FEM, OFFSx, size_offspring);
1188 
1189  //make offspring by pairing mothers and fathers
1190  for(unsigned int i = 0; i < size_offspring; ++i)
1191  {
1192  MotherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1193 
1194  FatherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1195 
1196  NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
1197 
1198  NewOffsprg->setSex(FEM);
1199 
1200  patch->set(FEM, OFFSx, i, NewOffsprg); // we use set() instead of add() for efficiency
1201 
1202  }//END FOR ind
1203 
1204  // we do the generation change here directly
1205  patch->flush(ADLTx, _popPtr);
1206  patch->move(FEM, OFFSx, ADLTx);
1207 
1208  gsl_ran_discrete_free(lookup_females);
1209 
1210 }
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:1229
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 
)
1116 {
1117  //double mean_fec;
1118  Individual* FatherPtr = 0;
1119  Individual* MotherPtr = 0;
1120  Individual* NewOffsprg = 0;
1121  unsigned int size_parent[2] = {patch->size(MAL, ADLTx), patch->size(FEM, ADLTx)};//[MAL=0,FEM=1]
1122  unsigned int size_offspring;
1123 
1124  // compute per-patch scaling factor (needed by linear selection to set mean trait values)
1125  (this->*_setScalingFactor)(ADLTx, patchID);
1126 
1127  gsl_ran_discrete_t* lookup_females = setReproScaledFitness_gsl(FEM, size_parent[FEM], patch);
1128  gsl_ran_discrete_t* lookup_males = setReproScaledFitness_gsl(MAL, size_parent[MAL], patch);
1129 
1130  for(unsigned int s = 0; s < 2; ++s) {
1131 
1132  size_offspring = patch->get_K(sex_t(s));
1133 
1134  patch->resize(sex_t(s), OFFSx, size_offspring);
1135 
1136  //make offspring by pairing mothers and fathers
1137 
1138  for(unsigned int i = 0; i < size_offspring; ++i)
1139  {
1140  MotherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1141 
1142  FatherPtr = patch->get(MAL, ADLTx, RAND::Discrete(lookup_males) ); // gsl_ran_discrete(RAND::r, lookup_males) );
1143 
1144  NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
1145 
1146  NewOffsprg->setSex(sex_t(s));
1147 
1148  patch->set(sex_t(s), OFFSx, i, NewOffsprg);
1149  }//END FOR ind
1150 
1151  } //END FOR sex
1152 
1153  // we do the generation change here directly
1154  patch->flush(ADLTx, _popPtr); //first move adults to recycling pool
1155  patch->move(FEM, OFFSx, ADLTx); //moves offspring to adult containers, resets offsprg size to 0
1156  patch->move(MAL, OFFSx, ADLTx);
1157 
1158  gsl_ran_discrete_free(lookup_males);
1159  gsl_ran_discrete_free(lookup_females);
1160 
1161 }
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.

986 {
987  Patch* current_patch;
988  unsigned int ind_count;
989 
990  if(_popPtr->size(OFFSPRG) != 0) {
991  warning("offspring containers not empty at time of breeding, flushing.\n");
992  _popPtr->flush(OFFSx);
993  }
994 
995 #ifdef _DEBUG_
996  message("LCE_Breed_Selection::execute\n");
997 #endif
998 
999  _scaling_factor = 1;
1000  _mean_fitness = 0;
1001  ind_count = 0;
1002 
1004 
1005  // check if change in local optima for quantitative traits
1007 
1008  for(unsigned int home = 0; home < _popPtr->getPatchNbr(); home++) {
1009 
1010  current_patch = _popPtr->getPatch(home);
1011 
1012  if( !checkMatingCondition(current_patch) ) continue;
1013 
1014  (this->* _breed_selection) (current_patch, home, &ind_count);
1015 
1016  }//end_for home
1017 
1018  LCE_Selection_base::setMeans(ind_count);
1019 
1020 #ifdef _DEBUG_
1021  message(" (offsprg nb: %i adults nb: %i, mean fitness: %f)\n",_popPtr->size(OFFSPRG),
1023 #endif
1024 
1025 }
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.

979 {
981 }
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
1249 {
1250  if(!ind->getMother() || !ind->getFather())
1251  fatal("found NULL parent ptr in offspring (LCE_Breed_Selection::makeOffspringWithSelection)\n");
1252 
1253  //do inheritance of the traits under selection:
1254  for(unsigned int i = 0; i < _TraitIndices.size(); ++i)
1256 
1257  //check if the individual survives
1258  double fitness = getFitness(ind, natalpatch);
1259  unsigned int cat = ind->getPedigreeClass();
1260  bool not_survived = (RAND::Uniform() > fitness);
1261 
1262  if( not_survived ) {
1263 
1264  //this one dies
1265  _popPtr->recycle(ind);
1266 
1267  // update realized fecundity counters
1268  ind->getMother()->addMating(cat);
1269  if(cat!=4) ind->getFather()->addMating(cat);
1270 
1271  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1272 
1273  return NULL;
1274 
1275  } else {
1276  //it survived, we'll return it
1277 
1278  ind->getMother()->DidHaveABaby(cat);
1279  if(cat!=4) ind->getFather()->DidHaveABaby(cat);
1280  }
1281 
1282  //compute inheritance and mutation of the traits not under selection:
1283  for(unsigned int i = 0; i < _nonSelectedTraitIndices.size(); i++)
1285 
1286  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1287 
1288  return ind;
1289 }
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.

949  {
950 
952 
953  _nonSelectedTraitIndices.clear();
954 
955 #ifdef _DEBUG_
956  cout << "@@@@ " << _nb_trait - _TraitIndices.size()<< " trait(s) not under selection\n";
957 #endif
958 
959  if (_nb_trait > _TraitIndices.size()) { //means we have some traits not under selection
960 
961  for (unsigned int i = 0; i < _nb_trait; ++i) {
962  //check which trait is not under selection and add its index into the vector
963  if (find(_TraitIndices.begin(), _TraitIndices.end(), i) == _TraitIndices.end()) {
964  _nonSelectedTraitIndices.push_back(i);
965  }
966  }
967 
968  if(_nonSelectedTraitIndices.size() != _nb_trait - _TraitIndices.size())
969  return error("LCE_Breed_Selection::setParameters:: trait not under selection was not found at initialization\n");
970 
971  }
972 
973  return true;
974 }
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.

908 {
910  return false;
911 
912  unsigned int mating_system = get_parameter_value("mating_system");
913 
914  if(get_parameter("mating_isWrightFisher")->isSet()) {
915 
916  if(mating_system == 1)
917 
919 
920  else if (mating_system == 6)
921 
923 
924  else {
925  return error("breed_selection::the Wright-Fisher population model with selection can only be set with\
926  a random mating system: models 1 (2-sex random mating) or 6 (1-sex random mating)\n");
927  }
928 
929  } else {
930 
931  // check mating system and mating options:
932  if(getMeanFecundity(0) <= 0)
933  return error("breed_selection::parameter \"mean_fecundity\" is not set!\n");
934 
935  if(get_parameter("breed_selection_fecundity_fitness")->isSet()){
936 
938 
939  } else {
941  }
942  }
943 
944  return setNonSelectedTraitTable();
945 }
void do_breed_selection_WrightFisher_1sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1166
void do_breed_selection_FecFitness(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1068
void do_breed_selection_WrightFisher_2sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1114
void do_breed_selection_OffSurvival(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1029
bool setNonSelectedTraitTable()
Builds the vector of traits not under selection.
Definition: LCEcomposite.cc:949
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 
)
1230 {
1231  _scaling_factor = 1; //we want the raw fitness before re-scaling
1232 
1233  double fitnessCache[numReproInd];
1234 
1235  for(unsigned int i = 0; i < numReproInd; ++i) {
1236  fitnessCache[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1237  if(fitnessCache[i] < 0) fitnessCache[i] = 0; // clamp for gsl_ran_discrete
1238  }
1239 
1240  gsl_ran_discrete_t* table = gsl_ran_discrete_preproc(numReproInd, fitnessCache);
1241 
1242  return table;
1243 }
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 
)
1215 {
1216  _scaling_factor = 1; //we want the raw fitness before re-scaling
1217  for(unsigned int i = 0; i < numReproInd; ++i) {
1218  survival[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1219  }
1220 
1221  double sum = survival.sum();
1222 
1223  survival /= sum;
1224 
1225 }

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.1 by  doxygen 1.9.1

Catalogued on GSR