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 
134  Individual* breed (Individual* mother, Individual* father, unsigned int LocalPatch);
135 
142  Individual* breed_cloning (Individual* mother, Individual* father, unsigned int LocalPatch);
143 
160 
164  Individual* do_breed (Individual* mother, Individual* father, unsigned int LocalPatch)
165  {
166  return (this->* DoBreedFuncPtr)(mother, father, LocalPatch);
167  }
168 
173  bool checkMatingCondition (Patch* thePatch)
174  {
175  return (this->* CheckMatingConditionFuncPtr) (thePatch);
176  }
181  bool checkNoSelfing (Patch* thePatch)
182  {
183  return (thePatch->size(FEM, ADLTx) != 0 && thePatch->size(MAL, ADLTx) != 0);
184  }
185 
190  bool checkPolygyny (Patch* thePatch)
191  {
192  if(thePatch->size(FEM, ADLTx) == 0 || thePatch->size(MAL, ADLTx) == 0) return false;
193 
194 // if(thePatch->size(MAL, ADLTx) < _mating_males) _mating_males = thePatch->size(MAL, ADLTx);
195 
196  _alpha_male = (unsigned int)RAND::Uniform(thePatch->size(MAL, ADLTx));
197 
198  return true;
199  }
200 
205  bool checkSelfing (Patch* thePatch)
206  {
207  if(thePatch->size(MAL, ADLTx) != 0) thePatch->flush(MAL, ADLTx, this->_popPtr);
208  return (thePatch->size(FEM, ADLTx) != 0);
209  }
210 
215  bool checkCloning (Patch* thePatch)
216  {
217  if(thePatch->size(MAL, ADLTx) != 0) thePatch->flush(MAL, ADLTx, this->_popPtr);
218 
219  return (thePatch->size(FEM, ADLTx) != 0);
220  }
221 
222 
225 
230  Individual* RandomMating (Patch* thePatch, Individual* mother, unsigned int motherIndex)
231  { return thePatch->get(MAL, ADLTx, RAND::Uniform(thePatch->size(MAL, ADLTx)) ); }
232 
239  Individual* fullPolyginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
240  { return thePatch->get(MAL, ADLTx, _alpha_male); }
241 
247  Individual* fullPolyginy_manyMales (Patch* thePatch, Individual* mother, unsigned int motherIndex)
248  {
249  if(thePatch->size(MAL,ADLTx) < _mating_males)
250  return thePatch->get(MAL, ADLTx, RAND::Uniform( thePatch->size(MAL, ADLTx) ) );
251  else
252  return thePatch->get(MAL, ADLTx, RAND::Uniform( _mating_males ) );
253  }
254 
260  Individual* partialPolyginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
261  {
263  return RandomMating(thePatch, mother, 0);
264  else
265  return fullPolyginy(thePatch, 0, 0);
266  }
267 
274  Individual* partialPolyginy_manyMales (Patch* thePatch, Individual* mother, unsigned int motherIndex)
275  {
277  return RandomMating(thePatch, mother, 0);
278  else
279  return fullPolyginy_manyMales(thePatch, mother, 0);
280  }
281 
288  Individual* fullMonoginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
289  {
290  if(thePatch->size(MAL, ADLTx) < motherIndex+1)
291  return RandomMating(thePatch, mother, motherIndex);
292  else
293  return thePatch->get(MAL, ADLTx, motherIndex);
294  }
295 
302  Individual* partialMonoginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
303  {
304  if(RAND::Uniform() > _mating_proportion || thePatch->size(MAL, ADLTx) < motherIndex+1)
305  return RandomMating(thePatch, mother, motherIndex);
306  else
307  return thePatch->get(MAL, ADLTx, motherIndex);
308  }
309 
315  Individual* fullSelfing (Patch* thePatch, Individual* mother, unsigned int motherIndex)
316  {
317  return mother;
318  }
319 
325  Individual* partialSelfing (Patch* thePatch, Individual* mother, unsigned int motherIndex)
326  {
327  unsigned int fem;
329  do {
330  fem = RAND::Uniform(thePatch->size(FEM, ADLTx));
331  } while(fem == motherIndex && thePatch->size(FEM, ADLTx) != 1);
332  return thePatch->get(FEM, ADLTx, fem);
333  }else
334  return mother;
335  }
336 
342  Individual* random_hermaphrodite (Patch* thePatch, Individual* mother, unsigned int motherIndex)
343  {
344  return thePatch->get(FEM, ADLTx, RAND::Uniform(thePatch->size(FEM, ADLTx)) );
345  }
347 
348 };
349 
350 // Class LCE_Breed
351 //
362 class LCE_Breed : public virtual LCE_Breed_base
363 {
364 
365 public:
366 
367  LCE_Breed ( ) : LifeCycleEvent("breed","") { }
368 
369  virtual ~LCE_Breed ( ) { }
370 
373  virtual bool setParameters ();
374  virtual void execute ();
375 
376  virtual LifeCycleEvent* clone ( ) {return new LCE_Breed();}
377 
378  virtual void loadFileServices ( FileServices* loader ) {}
379  virtual void loadStatServices ( StatServices* loader ) {}
380  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
381  virtual age_t removeAgeClass ( ) {return 0;}
382  virtual age_t addAgeClass ( );
383  virtual age_t requiredAgeClass ( ) {return ADULTS;}
385 };
386 
387 // Class LCE_BreedAssortativeMating
388 //
400 {
401  // the phenotypic difference indicative of a match. Is zero by default
403 
404  // assortative tolerance around the difference in phenotype:
406 
408 
409  // the functor used to test for a match, following option by the user
410  std::function<bool(double,double)> _assortative_predicate;
411 
413 
415 
417 
418 
419 public:
420 
422 
424 
427 
428  bool testAssortativeMatingCouple (const double female_trait_value, const double male_trait_value);
430  Individual* non_assortative_mating (Patch* patch, Individual* mother, unsigned int motherIndex);
432  Individual* assortative_mating (deque<Individual*>& males, Individual* mother, unsigned int motherIndex);
434 
435  // to randomize males position when mating
436  void ScrambleContainer (const int length, deque<Individual*>& array);
437 
438  // LAMPREY specific function:
439  Individual* breed_lamprey(Individual* mother, Individual* father, unsigned int LocalPatch);
442 
445  virtual bool setParameters ();
446  virtual void execute ();
447 
448  virtual LifeCycleEvent* clone ( ) {return new LCE_BreedAssortativeMating();}
449 
450  virtual void loadFileServices ( FileServices* loader ) {}
451  virtual void loadStatServices ( StatServices* loader ) {}
452  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
453  virtual age_t removeAgeClass ( ) {return 0;}
454  virtual age_t addAgeClass ( ) {return OFFSPRG;}
455  virtual age_t requiredAgeClass () {return ADULTS;}
457 };
458 
459 #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:400
virtual void loadStatServices(StatServices *loader)
Definition: LCEbreed.h:451
Individual *(LCE_Breed_base::* AssortativeMatingFuncPtr)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:416
double _assortative_value
Definition: LCEbreed.h:402
double _prop_non_assortative
Definition: LCEbreed.h:412
void setPhenotypeAncestryBased(Individual *ind)
virtual age_t requiredAgeClass()
Definition: LCEbreed.h:455
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:720
virtual ~LCE_BreedAssortativeMating()
Definition: LCEbreed.h:423
virtual age_t addAgeClass()
Definition: LCEbreed.h:454
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEbreed.h:452
double _assortative_tolerance
Definition: LCEbreed.h:405
bool testAssortativeMatingCouple(const double female_trait_value, const double male_trait_value)
Test whether male and female match for mating.
Definition: LCEbreed.cc:771
Individual *(LCE_Breed_base::* MatingFuncPtr_base)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:414
std::function< bool(double, double)> _assortative_predicate
Definition: LCEbreed.h:410
virtual age_t removeAgeClass()
Definition: LCEbreed.h:453
double assortative_value_with_tolerance
Definition: LCEbreed.h:407
Individual * breed_lamprey(Individual *mother, Individual *father, unsigned int LocalPatch)
virtual void execute()
Definition: LCEbreed.cc:643
virtual void loadFileServices(FileServices *loader)
Definition: LCEbreed.h:450
virtual LifeCycleEvent * clone()
Definition: LCEbreed.h:448
LCE_BreedAssortativeMating()
Definition: LCEbreed.cc:539
virtual bool setParameters()
Definition: LCEbreed.cc:556
void setPhenotypeMotherInherited(Individual *ind)
void ScrambleContainer(const int length, deque< Individual * > &array)
Definition: LCEbreed.cc:789
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:702
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:190
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:274
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:302
sex_t getOffsprgSex()
Definition: LCEbreed.h:114
void NonWrightFisherPopulation()
Definition: LCEbreed.cc:388
unsigned int _alpha_male
Definition: LCEbreed.h:51
Individual * fullSelfing(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns the mother pointer.
Definition: LCEbreed.h:315
bool isWrightFisher()
Definition: LCEbreed.h:120
void WrightFisherPopulation()
Definition: LCEbreed.cc:439
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:260
Individual * breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Makes a new individual with the right parents.
Definition: LCEbreed.cc:353
Individual * RandomMating(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male drawn randomly from a patch.
Definition: LCEbreed.h:230
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:288
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:341
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:342
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:164
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:360
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:215
bool checkNoSelfing(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is not selfing or cloning.
Definition: LCEbreed.h:181
bool setFecundity()
Definition: LCEbreed.cc:253
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:173
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:331
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:325
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:247
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:205
Individual * fullPolyginy(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to the alpha male of the patch.
Definition: LCEbreed.h:239
int _mating_system
Definition: LCEbreed.h:49
bool setSexRatio()
Definition: LCEbreed.cc:213
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:363
virtual age_t requiredAgeClass()
Definition: LCEbreed.h:383
virtual bool setParameters()
Definition: LCEbreed.cc:499
virtual void loadFileServices(FileServices *loader)
Definition: LCEbreed.h:378
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEbreed.h:380
virtual void execute()
Definition: LCEbreed.cc:506
virtual LifeCycleEvent * clone()
Definition: LCEbreed.h:376
virtual void loadStatServices(StatServices *loader)
Definition: LCEbreed.h:379
virtual ~LCE_Breed()
Definition: LCEbreed.h:369
LCE_Breed()
Definition: LCEbreed.h:367
virtual age_t removeAgeClass()
Definition: LCEbreed.h:381
virtual age_t addAgeClass()
Definition: LCEbreed.cc:524
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:685
static double Poisson(double mean)
From the Numerical Recieps.
Definition: Uniform.h:219
static double Gaussian(double sigma)
Definition: Uniform.h:261
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:124
static bool RandBool()
Returns a random boolean.
Definition: Uniform.h:162
static double LogNormal(double zeta, double sigma)
Definition: Uniform.h:357
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