Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCEbreed.h
Go to the documentation of this file.
1 
30 #ifndef LCEBREED_H
31 #define LCEBREED_H
32 
33 #include <functional>
34 #include "lifecycleevent.h"
35 #include "Uniform.h"
36 
37 
38 // Class LCE_Breed_base
39 //
45 class LCE_Breed_base : public virtual LifeCycleEvent
46 {
50  unsigned int _mating_males;
51  unsigned int _alpha_male;
55 
56 protected:
57 
61  Individual* (LCE_Breed_base::* DoBreedFuncPtr) (Individual* mother, Individual* father, unsigned int LocalPatch);
62  double (LCE_Breed_base::* FecundityFuncPtr) (double mean);
65  void (LCE_Breed_base::* PopModelFuncPtr) (void);
67 
69 
70 public:
71 
72  LCE_Breed_base ();
73 
74  virtual ~LCE_Breed_base ( ) {}
75 
82  virtual Individual* getFatherPtr (Patch* thePatch, Individual* mother, unsigned int motherIndex)
83  {
84  return (this->*MatingFuncPtr)(thePatch, mother, motherIndex);
85  }
89  virtual bool setParameters();
91 
94  bool setMatingSystem ();
95  bool setFecundity ();
96  bool setSexRatio ();
101  double getMeanFecundity (unsigned int patch) {return _mean_fecundity.get(0, patch);}
103  bool doInheritance () {return _do_inherit;}
104  double getPoissonFecundity (double mean) {return RAND::Poisson(mean);}
105  double getFixedFecundity (double mean) {return (mean < 0) ? 0 : mean;}
106  double getGaussianFecundity(double mean) {
107  double fec; do{fec = mean + RAND::Gaussian(_sd_fecundity);}while(fec < 0);
108  return fec;}
109  double getLogNormalFecundity(double mean) {
110  double fec; do{fec = mean + RAND::LogNormal(mean, _sd_fecundity);}while(fec < 0);
111  return fec;}
112  double getFecundity (unsigned int patch) {return (this->* FecundityFuncPtr)(_mean_fecundity.get(0, patch));}
113  double getFecundity (double mean) {return (this->* FecundityFuncPtr)(mean);}
114  sex_t getOffsprgSex () {return (this->* GetOffsprgSex) ();}
119 
120  bool isWrightFisher () {return get_parameter("mating_isWrightFisher")->isSet();}
121 
124 
125  void WrightFisherPopulation ();
126 
127  void doAgingInWFpop ();
128 
136  Individual* breed (Individual* mother, Individual* father, unsigned int LocalPatch);
137 
144  Individual* breed_cloning (Individual* mother, Individual* father, unsigned int LocalPatch);
145 
162 
171  Individual* makeOffspring(Individual* newind, Individual* mother, Individual* father,
172  unsigned int natalPatch);
173 
177  Individual* do_breed (Individual* mother, Individual* father, unsigned int LocalPatch)
178  {
179  return (this->* DoBreedFuncPtr)(mother, father, LocalPatch);
180  }
181 
186  bool checkMatingCondition (Patch* thePatch)
187  {
188  return (this->* CheckMatingConditionFuncPtr) (thePatch);
189  }
194  bool checkNoSelfing (Patch* thePatch)
195  {
196  return (thePatch->size(FEM, ADLTx) != 0 && thePatch->size(MAL, ADLTx) != 0);
197  }
198 
203  bool checkPolygyny (Patch* thePatch)
204  {
205  if(thePatch->size(FEM, ADLTx) == 0 || thePatch->size(MAL, ADLTx) == 0) return false;
206 
207 // if(thePatch->size(MAL, ADLTx) < _mating_males) _mating_males = thePatch->size(MAL, ADLTx);
208 
209  _alpha_male = (unsigned int)RAND::Uniform(thePatch->size(MAL, ADLTx));
210 
211  return true;
212  }
213 
218  bool checkSelfing (Patch* thePatch)
219  {
220  if(thePatch->size(MAL, ADLTx) != 0) thePatch->flush(MAL, ADLTx, this->_popPtr);
221  return (thePatch->size(FEM, ADLTx) != 0);
222  }
223 
228  bool checkCloning (Patch* thePatch)
229  {
230  if(thePatch->size(MAL, ADLTx) != 0) thePatch->flush(MAL, ADLTx, this->_popPtr);
231 
232  return (thePatch->size(FEM, ADLTx) != 0);
233  }
234 
235 
238 
243  Individual* RandomMating (Patch* thePatch, Individual* mother, unsigned int motherIndex)
244  { return thePatch->get(MAL, ADLTx, RAND::Uniform(thePatch->size(MAL, ADLTx)) ); }
245 
252  Individual* fullPolyginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
253  { return thePatch->get(MAL, ADLTx, _alpha_male); }
254 
260  Individual* fullPolyginy_manyMales (Patch* thePatch, Individual* mother, unsigned int motherIndex)
261  {
262  if(thePatch->size(MAL,ADLTx) < _mating_males)
263  return thePatch->get(MAL, ADLTx, RAND::Uniform( thePatch->size(MAL, ADLTx) ) );
264  else
265  return thePatch->get(MAL, ADLTx, RAND::Uniform( _mating_males ) );
266  }
267 
273  Individual* partialPolyginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
274  {
276  return RandomMating(thePatch, mother, 0);
277  else
278  return fullPolyginy(thePatch, 0, 0);
279  }
280 
287  Individual* partialPolyginy_manyMales (Patch* thePatch, Individual* mother, unsigned int motherIndex)
288  {
290  return RandomMating(thePatch, mother, 0);
291  else
292  return fullPolyginy_manyMales(thePatch, mother, 0);
293  }
294 
301  Individual* fullMonoginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
302  {
303  if(thePatch->size(MAL, ADLTx) < motherIndex+1)
304  return RandomMating(thePatch, mother, motherIndex);
305  else
306  return thePatch->get(MAL, ADLTx, motherIndex);
307  }
308 
315  Individual* partialMonoginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
316  {
317  if(RAND::Uniform() > _mating_proportion || thePatch->size(MAL, ADLTx) < motherIndex+1)
318  return RandomMating(thePatch, mother, motherIndex);
319  else
320  return thePatch->get(MAL, ADLTx, motherIndex);
321  }
322 
328  Individual* fullSelfing (Patch* thePatch, Individual* mother, unsigned int motherIndex)
329  {
330  return mother;
331  }
332 
338  Individual* partialSelfing (Patch* thePatch, Individual* mother, unsigned int motherIndex)
339  {
340  unsigned int fem;
342  do {
343  fem = RAND::Uniform(thePatch->size(FEM, ADLTx));
344  } while(fem == motherIndex && thePatch->size(FEM, ADLTx) != 1);
345  return thePatch->get(FEM, ADLTx, fem);
346  }else
347  return mother;
348  }
349 
355  Individual* random_hermaphrodite (Patch* thePatch, Individual* mother, unsigned int motherIndex)
356  {
357  return thePatch->get(FEM, ADLTx, RAND::Uniform(thePatch->size(FEM, ADLTx)) );
358  }
360 
361 };
362 
363 // Class LCE_Breed
364 //
375 class LCE_Breed : public virtual LCE_Breed_base
376 {
377 
378 public:
379 
380  LCE_Breed ( ) : LifeCycleEvent("breed","") { }
381 
382  virtual ~LCE_Breed ( ) { }
383 
386  virtual bool setParameters ();
387  virtual void execute ();
388 
389  virtual LifeCycleEvent* clone ( ) {return new LCE_Breed();}
390 
391  virtual void loadFileServices ( FileServices* loader ) {}
392  virtual void loadStatServices ( StatServices* loader ) {}
393  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
394  virtual age_t removeAgeClass ( ) {return 0;}
395  virtual age_t addAgeClass ( );
396  virtual age_t requiredAgeClass ( ) {return ADULTS;}
398 };
399 
400 // Class LCE_BreedAssortativeMating
401 //
413 {
414  // the phenotypic difference indicative of a match. Is zero by default
416 
417  // assortative tolerance around the difference in phenotype:
419 
421 
422  // the functor used to test for a match, following option by the user
423  std::function<bool(double,double)> _assortative_predicate;
424 
426 
428 
430 
431 
432 public:
433 
435 
437 
440 
441  bool testAssortativeMatingCouple (const double female_trait_value, const double male_trait_value);
443  Individual* non_assortative_mating (Patch* patch, Individual* mother, unsigned int motherIndex);
445  Individual* assortative_mating (deque<Individual*>& males, Individual* mother, unsigned int motherIndex);
447 
448  // to randomize males position when mating
449  void ScrambleContainer (const int length, deque<Individual*>& array);
450 
451  // LAMPREY specific function:
452  Individual* breed_lamprey(Individual* mother, Individual* father, unsigned int LocalPatch);
455 
458  virtual bool setParameters ();
459  virtual void execute ();
460 
461  virtual LifeCycleEvent* clone ( ) {return new LCE_BreedAssortativeMating();}
462 
463  virtual void loadFileServices ( FileServices* loader ) {}
464  virtual void loadStatServices ( StatServices* loader ) {}
465  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
466  virtual age_t removeAgeClass ( ) {return 0;}
467  virtual age_t addAgeClass ( ) {return OFFSPRG;}
468  virtual age_t requiredAgeClass () {return ADULTS;}
470 };
471 
472 #endif //LCEBREED_H
Nemo2.
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:52
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
Implementation of the basic breeding and mating procedures, does not link to any trait.
Definition: LCEbreed.h:413
virtual void loadStatServices(StatServices *loader)
Definition: LCEbreed.h:464
Individual *(LCE_Breed_base::* AssortativeMatingFuncPtr)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:429
double _assortative_value
Definition: LCEbreed.h:415
double _prop_non_assortative
Definition: LCEbreed.h:425
void setPhenotypeAncestryBased(Individual *ind)
virtual age_t requiredAgeClass()
Definition: LCEbreed.h:468
Individual * assortative_mating(deque< Individual * > &males, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male chosen relative to its phenotypic resemblance with the mother.
Definition: LCEbreed.cc:792
virtual ~LCE_BreedAssortativeMating()
Definition: LCEbreed.h:436
virtual age_t addAgeClass()
Definition: LCEbreed.h:467
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEbreed.h:465
double _assortative_tolerance
Definition: LCEbreed.h:418
bool testAssortativeMatingCouple(const double female_trait_value, const double male_trait_value)
Test whether male and female match for mating.
Definition: LCEbreed.cc:843
Individual *(LCE_Breed_base::* MatingFuncPtr_base)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:427
std::function< bool(double, double)> _assortative_predicate
Definition: LCEbreed.h:423
virtual age_t removeAgeClass()
Definition: LCEbreed.h:466
double assortative_value_with_tolerance
Definition: LCEbreed.h:420
Individual * breed_lamprey(Individual *mother, Individual *father, unsigned int LocalPatch)
virtual void execute()
Definition: LCEbreed.cc:715
virtual void loadFileServices(FileServices *loader)
Definition: LCEbreed.h:463
virtual LifeCycleEvent * clone()
Definition: LCEbreed.h:461
LCE_BreedAssortativeMating()
Definition: LCEbreed.cc:611
virtual bool setParameters()
Definition: LCEbreed.cc:628
void setPhenotypeMotherInherited(Individual *ind)
void ScrambleContainer(const int length, deque< Individual * > &array)
Definition: LCEbreed.cc:861
Individual * non_assortative_mating(Patch *patch, Individual *mother, unsigned int motherIndex)
Proceed with non-assortative mating, choosing a male at random in the patch, conditioned on him being...
Definition: LCEbreed.cc:774
Base class for the breeding (and mating) life cycle events.
Definition: LCEbreed.h:46
bool checkPolygyny(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is polygynous.
Definition: LCEbreed.h:203
Individual * partialPolyginy_manyMales(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male from a patch chosen at random if _mating_proportion != 1,...
Definition: LCEbreed.h:287
Individual * partialMonoginy(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male with same index as mother (if available) from the focal patch.
Definition: LCEbreed.h:315
sex_t getOffsprgSex()
Definition: LCEbreed.h:114
void NonWrightFisherPopulation()
Definition: LCEbreed.cc:408
unsigned int _alpha_male
Definition: LCEbreed.h:51
Individual * fullSelfing(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns the mother pointer.
Definition: LCEbreed.h:328
bool isWrightFisher()
Definition: LCEbreed.h:120
void WrightFisherPopulation()
Definition: LCEbreed.cc:459
virtual ~LCE_Breed_base()
Definition: LCEbreed.h:74
double getFixedFecundity(double mean)
Definition: LCEbreed.h:105
sex_t getOffsprgSexSelfing()
Definition: LCEbreed.h:117
Individual * partialPolyginy(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male from a patch chosen at random if _mating_proportion != 1,...
Definition: LCEbreed.h:273
Individual * breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Makes a new individual with the right parents.
Definition: LCEbreed.cc:373
Individual * RandomMating(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male drawn randomly from a patch.
Definition: LCEbreed.h:243
int getMatingSystem()
Definition: LCEbreed.h:102
Individual * fullMonoginy(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male with same index as mother (if available) from the focal patch.
Definition: LCEbreed.h:301
double getFecundity(double mean)
Definition: LCEbreed.h:113
bool _do_inherit
Definition: LCEbreed.h:53
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
double getGaussianFecundity(double mean)
Definition: LCEbreed.h:106
Individual * makeOffspring(Individual *ind)
Last step of the breeding process, does inheritance and mutation of the parents' genes.
Definition: LCEbreed.cc:351
double _sd_fecundity
Definition: LCEbreed.h:52
sex_t(LCE_Breed_base::* GetOffsprgSex)()
Definition: LCEbreed.h:64
Individual * random_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 m...
Definition: LCEbreed.h:355
double(LCE_Breed_base::* FecundityFuncPtr)(double mean)
Definition: LCEbreed.h:62
Individual * do_breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Calls the breeding function unsing its pointer.
Definition: LCEbreed.h:177
double getMatingProportion()
Definition: LCEbreed.h:100
void(LCE_Breed_base::* PopModelFuncPtr)(void)
Definition: LCEbreed.h:65
double getLogNormalFecundity(double mean)
Definition: LCEbreed.h:109
Individual * breed_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 offspri...
Definition: LCEbreed.cc:380
Individual *(LCE_Breed_base::* DoBreedFuncPtr)(Individual *mother, Individual *father, unsigned int LocalPatch)
Definition: LCEbreed.h:61
double _mating_proportion
Definition: LCEbreed.h:52
bool setMatingSystem()
Definition: LCEbreed.cc:84
bool checkCloning(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is cloning.
Definition: LCEbreed.h:228
void doAgingInWFpop()
Definition: LCEbreed.cc:548
bool checkNoSelfing(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is not selfing or cloning.
Definition: LCEbreed.h:194
bool setFecundity()
Definition: LCEbreed.cc:264
sex_t getOffsprgSexRandom()
Definition: LCEbreed.h:115
bool doInheritance()
Definition: LCEbreed.h:103
bool checkMatingCondition(Patch *thePatch)
Checks if any mating will take place in the patch passed as argument.
Definition: LCEbreed.h:186
bool(LCE_Breed_base::* CheckMatingConditionFuncPtr)(Patch *thePatch)
Definition: LCEbreed.h:63
double getPoissonFecundity(double mean)
Definition: LCEbreed.h:104
sex_t getOffsprgSexFixed()
Definition: LCEbreed.cc:342
unsigned int _mating_males
Definition: LCEbreed.h:50
LCE_Breed_base()
Definition: LCEbreed.cc:46
Individual * partialSelfing(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns the mother pointer or a random female if _mating_proportion != 1.
Definition: LCEbreed.h:338
Individual * fullPolyginy_manyMales(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to one of the first _mating_males males of the patch.
Definition: LCEbreed.h:260
sex_t getOffsprgSexCloning()
Definition: LCEbreed.h:118
TMatrix _mean_fecundity
Definition: LCEbreed.h:68
bool checkSelfing(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is selfing.
Definition: LCEbreed.h:218
Individual * fullPolyginy(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to the alpha male of the patch.
Definition: LCEbreed.h:252
int _mating_system
Definition: LCEbreed.h:49
bool setSexRatio()
Definition: LCEbreed.cc:224
Individual *(LCE_Breed_base::* MatingFuncPtr)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:60
double getMeanFecundity(unsigned int patch)
Definition: LCEbreed.h:101
double getFecundity(unsigned int patch)
Definition: LCEbreed.h:112
virtual bool setParameters()
Definition: LCEbreed.cc:77
Implementation of the basic breeding and mating procedures, does not link to any trait.
Definition: LCEbreed.h:376
virtual age_t requiredAgeClass()
Definition: LCEbreed.h:396
virtual bool setParameters()
Definition: LCEbreed.cc:571
virtual void loadFileServices(FileServices *loader)
Definition: LCEbreed.h:391
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEbreed.h:393
virtual void execute()
Definition: LCEbreed.cc:578
virtual LifeCycleEvent * clone()
Definition: LCEbreed.h:389
virtual void loadStatServices(StatServices *loader)
Definition: LCEbreed.h:392
virtual ~LCE_Breed()
Definition: LCEbreed.h:382
LCE_Breed()
Definition: LCEbreed.h:380
virtual age_t removeAgeClass()
Definition: LCEbreed.h:394
virtual age_t addAgeClass()
Definition: LCEbreed.cc:596
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
bool isSet()
Definition: param.h:140
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
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 flush(sex_t SEX, age_idx AGE, Metapop *pop)
Removes all individual pointers of the appropriate sex and age class and flush them into the recyclin...
Definition: metapop.h:687
static double Poisson(double mean)
From the Numerical Recieps.
Definition: Uniform.h:222
static double Gaussian(double sigma)
Definition: Uniform.h:264
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:127
static bool RandBool()
Returns a random boolean.
Definition: Uniform.h:165
static double LogNormal(double zeta, double sigma)
Definition: Uniform.h:360
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:45
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:193
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37
unsigned int age_t
Age class flags.
Definition: types.h:46
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
@ ADLTx
Definition: types.h:42

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