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

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
void(LCE_Breed_base::* PopModelFuncPtr )(void)
 
TMatrix _mean_fecundity
 
- 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 _letheq
 
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 ( )
529 : LifeCycleEvent("breed_selection",""),
531{
532 add_parameter("breed_selection_fecundity_fitness", BOOL, false, false, 0, 0, 0);
533// get_parameter("mean_fecundity")->setIsRequired(true); //not set here or inherited by breed_selection_disperse
534}
void(LCE_Breed_Selection::* _breed_selection)(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.h:216
unsigned int _nb_trait
Definition: LCEcomposite.h:218
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
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().

+ Here is the caller graph for this function:

◆ ~LCE_Breed_Selection()

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Breed_Selection::addAgeClass ( )
inlinevirtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

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

249{ return new LCE_Breed_Selection(); }
LCE_Breed_Selection()
Definition: LCEcomposite.cc:529

References LCE_Breed_Selection().

◆ do_breed_selection_FecFitness()

void LCE_Breed_Selection::do_breed_selection_FecFitness ( Patch patch,
unsigned int  patchID,
unsigned int cntr 
)
694{
695 unsigned int nbBaby;
696 //double mean_fec;
697 Individual* FatherPtr;
698 Individual* MotherPtr;
699 Individual* NewOffsprg;
700 unsigned int cat;
701
702 for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
703 indexOfMother < size;
704 indexOfMother++) {
705
706 (this->*_setScalingFactor)(ADLTx, patchID); //from within LCE_selection_base
707
708 MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
709
710 nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(getMeanFecundity(patchID)*
711 getFitness(MotherPtr, patchID)) );
712
713 (*cntr) += nbBaby;
714 //-----------------------------------------------------------------------
715 while(nbBaby != 0) {
716
717
718 FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
719
720 NewOffsprg = LCE_Breed_base::makeOffspring( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID) );
721
722 patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
723
724 nbBaby--;
725
726 cat = NewOffsprg->getPedigreeClass();
727
728 _fitness[cat] += getFitness(NewOffsprg, patchID);
729 _ind_cntr[cat]++;
730 _survival[cat]++;
731
732 }//_END__WHILE;
733 }//end_for indexOfMother
734
735}
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
Individual * do_breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Calls the breeding function unsing its pointer.
Definition: LCEbreed.h:156
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:76
Individual * makeOffspring(Individual *ind)
Last step of the breeding process, does inheritance and mutation of the parents' genes.
Definition: LCEbreed.cc:407
double getMeanFecundity(unsigned int patch)
Definition: LCEbreed.h:95
double getFecundity(unsigned int patch)
Definition: LCEbreed.h:106
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:92
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:128
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:190
double _ind_cntr[5]
Definition: LCEselection.h:92
double _survival[5]
Definition: LCEselection.h:92
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:496
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:549
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:532
@ 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().

+ 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 
)
658{
659 unsigned int nbBaby;
660 //double mean_fec;
661 Individual* FatherPtr;
662 Individual* MotherPtr;
663 Individual* NewOffsprg;
664
665 for(unsigned int size = patch->size(FEM, ADLTx), indexOfMother = 0;
666 indexOfMother < size;
667 indexOfMother++) {
668
669 MotherPtr = patch->get(FEM, ADLTx, indexOfMother);
670
671 nbBaby = (unsigned int)MotherPtr->setFecundity( getFecundity(patchID) );
672
673 (*cntr) += nbBaby;
674 //-----------------------------------------------------------------------
675 while(nbBaby != 0) {
676
677 FatherPtr = this->getFatherPtr(patch, MotherPtr, indexOfMother);
678
679 NewOffsprg = makeOffspringWithSelection( LCE_Breed_base::do_breed(MotherPtr, FatherPtr, patchID), patchID );
680
681 if(NewOffsprg != NULL)
682 patch->add(NewOffsprg->getSex(), OFFSx, NewOffsprg);
683
684 nbBaby--;
685
686 }//_END__WHILE;
687 }//end_for indexOfMother
688
689}
Individual * makeOffspringWithSelection(Individual *ind, unsigned int natalpatch)
Performs viability selection and breeding at the same time.
Definition: LCEcomposite.cc:880

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

+ 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 
)
810{
811 //WF pop with hermaphrodites
812 Individual* FatherPtr = 0;
813 Individual* MotherPtr = 0;
814 Individual* NewOffsprg = 0;
815 unsigned int size_parent = patch->size(FEM, ADLTx);
816 unsigned int *offspring_count[2] = {NULL, NULL};
817 unsigned int size_offspring;
818
819 // FEMALE fitness
820 valarray< double > fitness_fem(0.0, size_parent);
821 setReproScaledFitness_sum(FEM, fitness_fem, size_parent, patch); //normalized probabilities = relative fitness
822
823 //filling female offspring container only
824 //-----------------------------------------------------------------------
825 size_offspring = patch->get_K(FEM);
826
827 //stores the index of mother for each offspring
828 offspring_count[FEM] = new unsigned int [ size_offspring ];
829
830 //stores the index of "father" for each offspring
831 offspring_count[MAL] = new unsigned int [ size_offspring ];
832
833 //randomly draw each mother and each father proportionally to their fitness:
834
835 RAND::MultinomialOnNormalizedValarray_scrambleOut(size_parent, size_offspring, fitness_fem,
836 offspring_count[FEM]);
837 // second draw for second gamete
838 RAND::MultinomialOnNormalizedValarray_scrambleOut(size_parent, size_offspring, fitness_fem,
839 offspring_count[MAL]);
840
841 //make offspring by paring mothers and fathers
842
843 for(unsigned int i = 0; i < size_offspring; ++i)
844 {
845 MotherPtr = patch->get(FEM, ADLTx, offspring_count[FEM][i] );
846
847 FatherPtr = patch->get(FEM, ADLTx, offspring_count[MAL][i] ); //this is a female too!
848
849 NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
850
851 NewOffsprg->setSex(FEM);
852
853 patch->add(FEM, OFFSx, NewOffsprg);
854 }//END FOR ind
855
856 if(offspring_count[FEM])
857 delete [] offspring_count[FEM];
858
859 if(offspring_count[MAL])
860 delete [] offspring_count[MAL];
861}
void setSex(sex_t sex)
Definition: individual.h:112
void setReproScaledFitness_sum(sex_t SEX, valarray< double > &survival, unsigned int numReproFem, Patch *patch)
Definition: LCEcomposite.cc:865
unsigned int get_K()
Definition: metapop.h:479
static void MultinomialOnNormalizedValarray_scrambleOut(size_t K, unsigned int N, const std::valarray< double > &p, unsigned int n[])
Multinomial draw assuming the probabilities sum to 1.0 and are all > 0, the output is an array of siz...
Definition: Uniform.h:628
@ MAL
Definition: types.h:37

References Patch::add(), ADLTx, LCE_Breed_base::do_breed(), FEM, Patch::get(), Patch::get_K(), LCE_Breed_base::makeOffspring(), MAL, RAND::MultinomialOnNormalizedValarray_scrambleOut(), OFFSx, setReproScaledFitness_sum(), 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 
)
741{
742 //double mean_fec;
743 Individual* FatherPtr = 0;
744 Individual* MotherPtr = 0;
745 Individual* NewOffsprg = 0;
746 unsigned int size_parent[2] = {patch->size(MAL, ADLTx), patch->size(FEM, ADLTx)};//[MAL=0,FEM=1]
747 unsigned int *offspring_count[2] = {NULL, NULL};
748 unsigned int size_offspring;
749
750 // FEMALE fitness; FEM = 1
751 valarray< double > fitness_fem(0.0, size_parent[FEM]);
752 setReproScaledFitness_sum(FEM, fitness_fem, size_parent[FEM], patch); //normalized probabilities = relative fitness
753
754 // MALES fitness; Mal = 0
755 valarray< double > fitness_mal(0.0, size_parent[MAL]);
756 setReproScaledFitness_sum(MAL, fitness_mal, size_parent[MAL], patch);
757
758
759 for(unsigned int s = 0; s < 2; ++s) {
760 //filling male and female offspring containers
761 //-----------------------------------------------------------------------
762 size_offspring = patch->get_K(sex_t(s));
763
764 if(offspring_count[FEM]) delete [] offspring_count[FEM];
765
766 if(offspring_count[MAL]) delete [] offspring_count[MAL];
767
768 //stores the index of mother for each offspring
769 offspring_count[FEM] = new unsigned int [ size_offspring ];
770
771 //stores the index of father for each offspring
772 offspring_count[MAL] = new unsigned int [ size_offspring ];
773
774 //randomly draw each mother and each father proportionally to their fitness:
775
776 RAND::MultinomialOnNormalizedValarray_scrambleOut(size_parent[FEM], size_offspring, fitness_fem,
777 offspring_count[FEM]);
778
779 RAND::MultinomialOnNormalizedValarray_scrambleOut(size_parent[MAL], size_offspring, fitness_mal,
780 offspring_count[MAL]);
781
782 //make offspring by paring mothers and fathers
783
784 for(unsigned int i = 0; i < size_offspring; ++i)
785 {
786 MotherPtr = patch->get(FEM, ADLTx, offspring_count[FEM][i] );
787
788 FatherPtr = patch->get(MAL, ADLTx, offspring_count[MAL][i] );
789
790 NewOffsprg = makeOffspring( do_breed(MotherPtr, FatherPtr, patchID) );
791
792 NewOffsprg->setSex(sex_t(s));
793
794 patch->add(sex_t(s), OFFSx, NewOffsprg);
795 }//END FOR ind
796 } //END FOR sex
797
798 if(offspring_count[FEM])
799 delete [] offspring_count[FEM];
800
801 if(offspring_count[MAL])
802 delete [] offspring_count[MAL];
803}
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36

References Patch::add(), ADLTx, LCE_Breed_base::do_breed(), FEM, Patch::get(), Patch::get_K(), LCE_Breed_base::makeOffspring(), MAL, RAND::MultinomialOnNormalizedValarray_scrambleOut(), OFFSx, setReproScaledFitness_sum(), 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.

617{
618 Patch* current_patch;
619 unsigned int ind_count;
620
621 if(_popPtr->size(OFFSPRG) != 0) {
622 warning("offspring containers not empty at time of breeding, flushing.\n");
624 }
625
626#ifdef _DEBUG_
627 message("LCE_Breed_Selection::execute\n");
628#endif
629
630 _scaling_factor = 1;
631 _mean_fitness = 0;
632 ind_count = 0;
633
635
636 for(unsigned int home = 0; home < _popPtr->getPatchNbr(); home++) {
637
638 current_patch = _popPtr->getPatch(home);
639
640 if( !checkMatingCondition(current_patch) ) continue;
641
642 (this->* _breed_selection) (current_patch, home, &ind_count);
643
644 }//end_for home
645
647
648#ifdef _DEBUG_
649 message(" (offsprg nb: %i adults nb: %i, mean fitness: %f)\n",_popPtr->size(OFFSPRG),
651#endif
652
653}
bool checkMatingCondition(Patch *thePatch)
Checks if any mating will take place in the patch passed as argument.
Definition: LCEbreed.h:165
double _scaling_factor
Definition: LCEselection.h:89
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.cc:983
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.cc:972
double _mean_fitness
Definition: LCEselection.h:89
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:310
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:805
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
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_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.

250{}

◆ loadStatServices()

void LCE_Breed_Selection::loadStatServices ( StatServices loader)
virtual

Reimplemented from LCE_Selection_base.

Reimplemented in LCE_Breed_Selection_Disperse.

610{
612}
virtual void loadStatServices(StatServices *loader)
Definition: LCEselection.cc:108

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
882{
883 if(!ind->getMother() || !ind->getFather())
884 fatal("found NULL parent ptr in offspring (LCE_Breed_Selection::makeOffspringWithSelection)\n");
885
886 //do inheritance of the traits under selection:
887 for(unsigned int i = 0; i < _TraitIndices.size(); ++i)
889
890 //check if the individual survives
891 register double fitness = getFitness(ind, natalpatch);
892 register unsigned int cat = ind->getPedigreeClass();
893
894 _fitness[cat] += fitness;
895 _ind_cntr[cat]++;
896
897 if( RAND::Uniform() > fitness ) {
898 //this one dies
899 _popPtr->recycle(ind);
900
901 ind->getMother()->addMating(cat);
902 if(cat!=4) ind->getFather()->addMating(cat);
903
904 return NULL;
905
906 } else {
907 //it survived, we'll return it
908
909 //update counters
910 _survival[cat]++;
911
912 ind->getMother()->DidHaveABaby(cat);
913 if(cat!=4) ind->getFather()->DidHaveABaby(cat);
914 }
915
916 //compute inheritance and mutation of the traits not under selection:
917 for(unsigned int i = 0; i < _nonSelectedTraitIndices.size(); i++)
919
920 return ind;
921}
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 * getFather()
Definition: individual.h:126
Individual * getMother()
Definition: individual.h:127
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:220
bool doInheritance()
Definition: LCEbreed.h:97
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:111
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:125
void fatal(const char *str,...)
Definition: output.cc:96

References LCE_Selection_base::_fitness, LCE_Selection_base::_ind_cntr, _nonSelectedTraitIndices, LifeCycleEvent::_popPtr, LCE_Selection_base::_survival, 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(), and RAND::Uniform().

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.

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

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

252{return false;}

◆ setNonSelectedTraitTable()

bool LCE_Breed_Selection::setNonSelectedTraitTable ( )

Builds the vector of traits not under selection.

Used in LCE_Breed_Selection_Disperse as well.

580 {
581
583
585
586#ifdef _DEBUG_
587 cout << "@@@@ " << _nb_trait - _TraitIndices.size()<< " trait(s) not under selection\n";
588#endif
589
590 if (_nb_trait > _TraitIndices.size()) { //means we have some traits not under selection
591
592 for (unsigned int i = 0; i < _nb_trait; ++i) {
593 //check which trait is not under selection and add its index into the vector
594 if (find(_TraitIndices.begin(), _TraitIndices.end(), i) == _TraitIndices.end()) {
595 _nonSelectedTraitIndices.push_back(i);
596 }
597 }
598
600 return error("LCE_Breed_Selection::setParameters:: trait not under selection was not found at initialization\n");
601
602 }
603
604 return true;
605}
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().

+ 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.

539{
541 return false;
542
543 unsigned int mating_system = get_parameter_value("mating_system");
544
545 if(get_parameter("mating_isWrightFisher")->isSet()) {
546
547 if(mating_system == 1)
548
550
551 else if (mating_system == 6)
552
554
555 else {
556 return error("the Wright-Fisher population model with selection (breed_selection) can only be set with\
557 a random mating system: models 1 (2 sex random mating) or 6 (1 sex random mating)\n");
558 }
559
560 } else {
561
562 // check mating system and mating options:
563 if(getMeanFecundity(0) <= 0)
564 return error("\"mean_fecundity\" is not set!\n");
565
566 if(get_parameter("breed_selection_fecundity_fitness")->isSet()){
567
569
570 } else {
572 }
573 }
574
576}
void do_breed_selection_WrightFisher_1sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:808
void do_breed_selection_FecFitness(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:693
void do_breed_selection_WrightFisher_2sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:739
void do_breed_selection_OffSurvival(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:657
bool setNonSelectedTraitTable()
Builds the vector of traits not under selection.
Definition: LCEcomposite.cc:580
virtual bool setParameters()
Definition: LCEbreed.cc:75
virtual bool setParameters()
Definition: LCEselection.cc:152
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_sum()

void LCE_Breed_Selection::setReproScaledFitness_sum ( sex_t  SEX,
valarray< double > &  survival,
unsigned int  numReproFem,
Patch patch 
)
866{
867 _scaling_factor = 1; //we want the raw fitness before re-scaling
868 for(unsigned int i = 0; i < numReproFem; ++i) {
869 survival[i] = getFitness(patch->get(SEX, ADLTx, i), patch->getID());
870 }
871
872 double sum = survival.sum();
873
874 survival /= sum;
875
876}
unsigned int getID()
Definition: metapop.h:478

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:

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

Locations of visitors to this page
Catalogued on GSR