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 ()
 
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...
 
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 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 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< 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 ( )
874  : LifeCycleEvent("breed_selection",""),
876 {
877  add_parameter("breed_selection_fecundity_fitness", BOOL, false, false, 0, 0, 0);
878 // get_parameter("mean_fecundity")->setIsRequired(true); //don't set here or it will be inherited by breed_selection_disperse
879 }
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 OFFSPRG;}
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50

References 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:874

References LCE_Breed_Selection().

◆ do_breed_selection_FecFitness()

void LCE_Breed_Selection::do_breed_selection_FecFitness ( Patch patch,
unsigned int  patchID,
unsigned int *  cntr 
)
1042 {
1043  unsigned int nbBaby;
1044  //double mean_fec;
1045  Individual* FatherPtr;
1046  Individual* MotherPtr;
1047  Individual* NewOffsprg;
1048  unsigned int cat;
1049 
1050  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1051  indexOfMother < size;
1052  indexOfMother++) {
1053 
1054  (this->*_setScalingFactor)(ADLTx, patchID); //from within LCE_selection_base
1055 
1056  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1057 
1058  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(getMeanFecundity(patchID)*
1059  getFitness(MotherPtr, patchID)) );
1060 
1061  (*cntr) += nbBaby;
1062  //-----------------------------------------------------------------------
1063  while(nbBaby != 0) {
1064 
1065 
1066  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1067 
1068  NewOffsprg = LCE_Breed_base::makeOffspring( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID) );
1069 
1070  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1071 
1072  nbBaby--;
1073 
1074  cat = NewOffsprg->getPedigreeClass();
1075 
1076  _fitness[cat] += getFitness(NewOffsprg, patchID);
1077  _ind_cntr[cat]++;
1078  _survival[cat]++;
1079 
1080  }//_END__WHILE;
1081  }//end_for indexOfMother
1082 
1083 }
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:341
Individual * do_breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Calls the breeding function unsing its pointer.
Definition: LCEbreed.h:164
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:106
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:142
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:213
double _ind_cntr[5]
Definition: LCEselection.h:106
double _survival[5]
Definition: LCEselection.h:106
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 
)
1006 {
1007  unsigned int nbBaby;
1008  //double mean_fec;
1009  Individual* FatherPtr;
1010  Individual* MotherPtr;
1011  Individual* NewOffsprg;
1012 
1013  for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
1014  indexOfMother < size;
1015  indexOfMother++) {
1016 
1017  MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
1018 
1019  nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(patchID) );
1020 
1021  (*cntr) += nbBaby;
1022  //-----------------------------------------------------------------------
1023  while(nbBaby != 0) {
1024 
1025  FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
1026 
1027  NewOffsprg = makeOffspringWithSelection( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID), patchID );
1028 
1029  if(NewOffsprg != NULL)
1030  patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
1031 
1032  nbBaby--;
1033 
1034  }//_END__WHILE;
1035  }//end_for indexOfMother
1036 
1037 }
Individual * makeOffspringWithSelection(Individual *ind, unsigned int natalpatch)
Performs viability selection and breeding at the same time.
Definition: LCEcomposite.cc:1213

References 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 
)
1138 {
1139  //WF pop with hermaphrodites
1140  Individual* FatherPtr = 0;
1141  Individual* MotherPtr = 0;
1142  Individual* NewOffsprg = 0;
1143  unsigned int size_parent = patch->size(FEM, ADLTx);
1144  unsigned int size_offspring;
1145 
1146  // FEMALE fitness
1147 
1148  gsl_ran_discrete_t* lookup_females = setReproScaledFitness_gsl(FEM, size_parent, patch);
1149 
1150  //filling female offspring container only
1151  //-----------------------------------------------------------------------
1152  size_offspring = patch->get_K(FEM);
1153 
1154  patch->resize(FEM, OFFSx, size_offspring);
1155 
1156  //make offspring by pairing mothers and fathers
1157  for(unsigned int i = 0; i < size_offspring; ++i)
1158  {
1159  MotherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1160 
1161  FatherPtr = patch->get(FEM, ADLTx, RAND::Discrete(lookup_females) ); // gsl_ran_discrete(RAND::r, lookup_females) );
1162 
1163  NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
1164 
1165  NewOffsprg->setSex(FEM);
1166 
1167  patch->set(FEM, OFFSx, i, NewOffsprg); // we use set() instead of add() for efficiency
1168 
1169  }//END FOR ind
1170 
1171  // we do the generation change here directly
1172  patch->flush(ADLTx, _popPtr);
1173  patch->move(FEM, OFFSx, ADLTx);
1174 
1175  gsl_ran_discrete_free(lookup_females);
1176 
1177 }
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:1196
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:685
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:813

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

References LifeCycleEvent::_popPtr, 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.

962 {
963  Patch* current_patch;
964  unsigned int ind_count;
965 
966  if(_popPtr->size(OFFSPRG) != 0) {
967  warning("offspring containers not empty at time of breeding, flushing.\n");
968  _popPtr->flush(OFFSx);
969  }
970 
971 #ifdef _DEBUG_
972  message("LCE_Breed_Selection::execute\n");
973 #endif
974 
975  _scaling_factor = 1;
976  _mean_fitness = 0;
977  ind_count = 0;
978 
980 
981  // check if change in local optima for quantitative traits
983 
984  for(unsigned int home = 0; home < _popPtr->getPatchNbr(); home++) {
985 
986  current_patch = _popPtr->getPatch(home);
987 
988  if( !checkMatingCondition(current_patch) ) continue;
989 
990  (this->* _breed_selection) (current_patch, home, &ind_count);
991 
992  }//end_for home
993 
994  LCE_Selection_base::setMeans(ind_count);
995 
996 #ifdef _DEBUG_
997  message(" (offsprg nb: %i adults nb: %i, mean fitness: %f)\n",_popPtr->size(OFFSPRG),
999 #endif
1000 
1001 }
bool checkMatingCondition(Patch *thePatch)
Checks if any mating will take place in the patch passed as argument.
Definition: LCEbreed.h:173
double _scaling_factor
Definition: LCEselection.h:101
void checkChangeLocalOptima()
Check is rate of change in local optima has been set and must be applied.
Definition: LCEselection.cc:1105
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.cc:1200
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.cc:1189
double _mean_fitness
Definition: LCEselection.h:101
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:847
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.

955 {
957 }
virtual void loadStatServices(StatServices *loader)
Definition: LCEselection.cc:131

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
1215 {
1216  if(!ind->getMother() || !ind->getFather())
1217  fatal("found NULL parent ptr in offspring (LCE_Breed_Selection::makeOffspringWithSelection)\n");
1218 
1219  //do inheritance of the traits under selection:
1220  for(unsigned int i = 0; i < _TraitIndices.size(); ++i)
1222 
1223  //check if the individual survives
1224  double fitness = getFitness(ind, natalpatch);
1225  unsigned int cat = ind->getPedigreeClass();
1226  bool not_survived = (RAND::Uniform() > fitness);
1227 
1228  if( not_survived ) {
1229 
1230  //this one dies
1231  _popPtr->recycle(ind);
1232 
1233  // update realized fecundity counters
1234  ind->getMother()->addMating(cat);
1235  if(cat!=4) ind->getFather()->addMating(cat);
1236 
1237  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1238 
1239  return NULL;
1240 
1241  } else {
1242  //it survived, we'll return it
1243 
1244  ind->getMother()->DidHaveABaby(cat);
1245  if(cat!=4) ind->getFather()->DidHaveABaby(cat);
1246  }
1247 
1248  //compute inheritance and mutation of the traits not under selection:
1249  for(unsigned int i = 0; i < _nonSelectedTraitIndices.size(); i++)
1251 
1252  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1253 
1254  return ind;
1255 }
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:125
void updateFitnessCounters(double fitness, unsigned int ped_class, bool survived)
Updates the fitness and survival mean counters.
Definition: LCEselection.cc:1216
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:124
void fatal(const char *str,...)
Definition: output.cc:96

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;}
#define NONE
No age flag.
Definition: types.h:48

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.

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

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.

884 {
886  return false;
887 
888  unsigned int mating_system = get_parameter_value("mating_system");
889 
890  if(get_parameter("mating_isWrightFisher")->isSet()) {
891 
892  if(mating_system == 1)
893 
895 
896  else if (mating_system == 6)
897 
899 
900  else {
901  return error("breed_selection::the Wright-Fisher population model with selection can only be set with\
902  a random mating system: models 1 (2-sex random mating) or 6 (1-sex random mating)\n");
903  }
904 
905  } else {
906 
907  // check mating system and mating options:
908  if(getMeanFecundity(0) <= 0)
909  return error("breed_selection::parameter \"mean_fecundity\" is not set!\n");
910 
911  if(get_parameter("breed_selection_fecundity_fitness")->isSet()){
912 
914 
915  } else {
917  }
918  }
919 
920  return setNonSelectedTraitTable();
921 }
void do_breed_selection_WrightFisher_1sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1136
void do_breed_selection_FecFitness(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1041
void do_breed_selection_WrightFisher_2sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1087
void do_breed_selection_OffSurvival(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1005
bool setNonSelectedTraitTable()
Builds the vector of traits not under selection.
Definition: LCEcomposite.cc:925
virtual bool setParameters()
Definition: LCEbreed.cc:77
virtual bool setParameters()
Definition: LCEselection.cc:178
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 
)
1197 {
1198  _scaling_factor = 1; //we want the raw fitness before re-scaling
1199 
1200  double fitnessCache[numReproInd];
1201 
1202  for(unsigned int i = 0; i < numReproInd; ++i) {
1203  fitnessCache[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1204  }
1205 
1206  gsl_ran_discrete_t* table = gsl_ran_discrete_preproc(numReproInd, fitnessCache);
1207 
1208  return table;
1209 }
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 
)
1182 {
1183  _scaling_factor = 1; //we want the raw fitness before re-scaling
1184  for(unsigned int i = 0; i < numReproInd; ++i) {
1185  survival[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
1186  }
1187 
1188  double sum = survival.sum();
1189 
1190  survival /= sum;
1191 
1192 }

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