Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCEbreed.h
Go to the documentation of this file.
1 
28 #ifndef LCEBREED_H
29 #define LCEBREED_H
30 
31 #include <functional>
32 #include "lifecycleevent.h"
33 #include "Uniform.h"
34 
35 
36 // Class LCE_Breed_base
37 //
43 class LCE_Breed_base : public virtual LifeCycleEvent
44 {
48  unsigned int _mating_males;
49  unsigned int _alpha_male;
53 
54 protected:
55 
59  Individual* (LCE_Breed_base::* DoBreedFuncPtr) (Individual* mother, Individual* father, unsigned int LocalPatch);
60  double (LCE_Breed_base::* FecundityFuncPtr) (double mean);
63  void (LCE_Breed_base::* PopModelFuncPtr) (void);
65 
67 
68 public:
69 
70  LCE_Breed_base ();
71 
72  virtual ~LCE_Breed_base ( ) {}
73 
80  virtual Individual* getFatherPtr (Patch* thePatch, Individual* mother, unsigned int motherIndex)
81  {
82  return (this->*MatingFuncPtr)(thePatch, mother, motherIndex);
83  }
87  virtual bool setParameters();
89 
92  bool setMatingSystem ();
93  bool setFecundity ();
94  bool setSexRatio ();
99  double getMeanFecundity (unsigned int patch) {return _mean_fecundity.get(0, patch);}
101  bool doInheritance () {return _do_inherit;}
102  double getPoissonFecundity (double mean) {return RAND::Poisson(mean);}
103  double getFixedFecundity (double mean) {return (mean < 0) ? 0 : mean;}
104  double getGaussianFecundity(double mean) {
105  double fec; do{fec = mean + RAND::Gaussian(_sd_fecundity);}while(fec < 0);
106  return fec;}
107  double getLogNormalFecundity(double mean) {
108  double fec; do{fec = mean + RAND::LogNormal(mean, _sd_fecundity);}while(fec < 0);
109  return fec;}
110  double getFecundity (unsigned int patch) {return (this->* FecundityFuncPtr)(_mean_fecundity.get(0, patch));}
111  double getFecundity (double mean) {return (this->* FecundityFuncPtr)(mean);}
112  sex_t getOffsprgSex () {return (this->* GetOffsprgSex) ();}
117 
118  bool isWrightFisher () {return get_parameter("mating_isWrightFisher")->isSet();}
119 
122 
123  void WrightFisherPopulation ();
124 
125  void doAgingInWFpop ();
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 
169  Individual* makeOffspring(Individual* newind, Individual* mother, Individual* father,
170  unsigned int natalPatch);
171 
175  Individual* do_breed (Individual* mother, Individual* father, unsigned int LocalPatch)
176  {
177  return (this->* DoBreedFuncPtr)(mother, father, LocalPatch);
178  }
179 
184  bool checkMatingCondition (Patch* thePatch)
185  {
186  return (this->* CheckMatingConditionFuncPtr) (thePatch);
187  }
192  bool checkNoSelfing (Patch* thePatch)
193  {
194  return (thePatch->size(FEM, ADLTx) != 0 && thePatch->size(MAL, ADLTx) != 0);
195  }
196 
201  bool checkPolygyny (Patch* thePatch)
202  {
203  if(thePatch->size(FEM, ADLTx) == 0 || thePatch->size(MAL, ADLTx) == 0) return false;
204 
205 // if(thePatch->size(MAL, ADLTx) < _mating_males) _mating_males = thePatch->size(MAL, ADLTx);
206 
207  _alpha_male = (unsigned int)RAND::Uniform(thePatch->size(MAL, ADLTx));
208 
209  return true;
210  }
211 
216  bool checkSelfing (Patch* thePatch)
217  {
218  if(thePatch->size(MAL, ADLTx) != 0) thePatch->flush(MAL, ADLTx, this->_popPtr);
219  return (thePatch->size(FEM, ADLTx) != 0);
220  }
221 
226  bool checkCloning (Patch* thePatch)
227  {
228  if(thePatch->size(MAL, ADLTx) != 0) thePatch->flush(MAL, ADLTx, this->_popPtr);
229 
230  return (thePatch->size(FEM, ADLTx) != 0);
231  }
232 
233 
236 
241  Individual* RandomMating (Patch* thePatch, Individual* mother, unsigned int motherIndex)
242  { return thePatch->get(MAL, ADLTx, RAND::Uniform(thePatch->size(MAL, ADLTx)) ); }
243 
250  Individual* fullPolyginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
251  { return thePatch->get(MAL, ADLTx, _alpha_male); }
252 
258  Individual* fullPolyginy_manyMales (Patch* thePatch, Individual* mother, unsigned int motherIndex)
259  {
260  if(thePatch->size(MAL,ADLTx) < _mating_males)
261  return thePatch->get(MAL, ADLTx, RAND::Uniform( thePatch->size(MAL, ADLTx) ) );
262  else
263  return thePatch->get(MAL, ADLTx, RAND::Uniform( _mating_males ) );
264  }
265 
271  Individual* partialPolyginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
272  {
274  return RandomMating(thePatch, mother, 0);
275  else
276  return fullPolyginy(thePatch, 0, 0);
277  }
278 
285  Individual* partialPolyginy_manyMales (Patch* thePatch, Individual* mother, unsigned int motherIndex)
286  {
288  return RandomMating(thePatch, mother, 0);
289  else
290  return fullPolyginy_manyMales(thePatch, mother, 0);
291  }
292 
299  Individual* fullMonoginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
300  {
301  if(thePatch->size(MAL, ADLTx) < motherIndex+1)
302  return RandomMating(thePatch, mother, motherIndex);
303  else
304  return thePatch->get(MAL, ADLTx, motherIndex);
305  }
306 
313  Individual* partialMonoginy (Patch* thePatch, Individual* mother, unsigned int motherIndex)
314  {
315  if(RAND::Uniform() > _mating_proportion || thePatch->size(MAL, ADLTx) < motherIndex+1)
316  return RandomMating(thePatch, mother, motherIndex);
317  else
318  return thePatch->get(MAL, ADLTx, motherIndex);
319  }
320 
326  Individual* fullSelfing (Patch* thePatch, Individual* mother, unsigned int motherIndex)
327  {
328  return mother;
329  }
330 
336  Individual* partialSelfing (Patch* thePatch, Individual* mother, unsigned int motherIndex)
337  {
338  unsigned int fem;
340  do {
341  fem = RAND::Uniform(thePatch->size(FEM, ADLTx));
342  } while(fem == motherIndex && thePatch->size(FEM, ADLTx) != 1);
343  return thePatch->get(FEM, ADLTx, fem);
344  }else
345  return mother;
346  }
347 
353  Individual* random_hermaphrodite (Patch* thePatch, Individual* mother, unsigned int motherIndex)
354  {
355  return thePatch->get(FEM, ADLTx, RAND::Uniform(thePatch->size(FEM, ADLTx)) );
356  }
358 
359 };
360 
361 // Class LCE_Breed
362 //
373 class LCE_Breed : public virtual LCE_Breed_base
374 {
375 
376 public:
377 
378  LCE_Breed ( ) : LifeCycleEvent("breed","") { }
379 
380  virtual ~LCE_Breed ( ) { }
381 
384  virtual bool setParameters ();
385  virtual void execute ();
386 
387  virtual LifeCycleEvent* clone ( ) {return new LCE_Breed();}
388 
389  virtual void loadFileServices ( FileServices* loader ) {}
390  virtual void loadStatServices ( StatServices* loader ) {}
391  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
392  virtual age_t removeAgeClass ( ) {return 0;}
393  virtual age_t addAgeClass ( );
394  virtual age_t requiredAgeClass ( ) {return ADULTS;}
396 };
397 
398 // Class LCE_BreedAssortativeMating
399 //
411 {
412  // the phenotypic difference indicative of a match. Is zero by default
414 
415  // assortative tolerance around the difference in phenotype:
417 
419 
420  // the functor used to test for a match, following option by the user
421  std::function<bool(double,double)> _assortative_predicate;
422 
424 
426 
428 
429 
430 public:
431 
433 
435 
438 
439  bool testAssortativeMatingCouple (const double female_trait_value, const double male_trait_value);
441  Individual* non_assortative_mating (Patch* patch, Individual* mother, unsigned int motherIndex);
443  Individual* assortative_mating (deque<Individual*>& males, Individual* mother, unsigned int motherIndex);
445 
446  // to randomize males position when mating
447  void ScrambleContainer (const int length, deque<Individual*>& array);
448 
449  // LAMPREY specific function:
450  Individual* breed_lamprey(Individual* mother, Individual* father, unsigned int LocalPatch);
453 
456  virtual bool setParameters ();
457  virtual void execute ();
458 
459  virtual LifeCycleEvent* clone ( ) {return new LCE_BreedAssortativeMating();}
460 
461  virtual void loadFileServices ( FileServices* loader ) {}
462  virtual void loadStatServices ( StatServices* loader ) {}
463  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
464  virtual age_t removeAgeClass ( ) {return 0;}
465  virtual age_t addAgeClass ( ) {return OFFSPRG;}
466  virtual age_t requiredAgeClass () {return ADULTS;}
468 };
469 
470 #endif //LCEBREED_H
Nemo2.
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:50
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
Implementation of the basic breeding and mating procedures, does not link to any trait.
Definition: LCEbreed.h:411
virtual void loadStatServices(StatServices *loader)
Definition: LCEbreed.h:462
Individual *(LCE_Breed_base::* AssortativeMatingFuncPtr)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:427
double _assortative_value
Definition: LCEbreed.h:413
double _prop_non_assortative
Definition: LCEbreed.h:423
void setPhenotypeAncestryBased(Individual *ind)
virtual age_t requiredAgeClass()
Definition: LCEbreed.h:466
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:790
virtual ~LCE_BreedAssortativeMating()
Definition: LCEbreed.h:434
virtual age_t addAgeClass()
Definition: LCEbreed.h:465
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEbreed.h:463
double _assortative_tolerance
Definition: LCEbreed.h:416
bool testAssortativeMatingCouple(const double female_trait_value, const double male_trait_value)
Test whether male and female match for mating.
Definition: LCEbreed.cc:841
Individual *(LCE_Breed_base::* MatingFuncPtr_base)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:425
std::function< bool(double, double)> _assortative_predicate
Definition: LCEbreed.h:421
virtual age_t removeAgeClass()
Definition: LCEbreed.h:464
double assortative_value_with_tolerance
Definition: LCEbreed.h:418
Individual * breed_lamprey(Individual *mother, Individual *father, unsigned int LocalPatch)
virtual void execute()
Definition: LCEbreed.cc:713
virtual void loadFileServices(FileServices *loader)
Definition: LCEbreed.h:461
virtual LifeCycleEvent * clone()
Definition: LCEbreed.h:459
LCE_BreedAssortativeMating()
Definition: LCEbreed.cc:609
virtual bool setParameters()
Definition: LCEbreed.cc:626
void setPhenotypeMotherInherited(Individual *ind)
void ScrambleContainer(const int length, deque< Individual * > &array)
Definition: LCEbreed.cc:859
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:772
Base class for the breeding (and mating) life cycle events.
Definition: LCEbreed.h:44
bool checkPolygyny(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is polygynous.
Definition: LCEbreed.h:201
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:285
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:313
sex_t getOffsprgSex()
Definition: LCEbreed.h:112
void NonWrightFisherPopulation()
Definition: LCEbreed.cc:406
unsigned int _alpha_male
Definition: LCEbreed.h:49
Individual * fullSelfing(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns the mother pointer.
Definition: LCEbreed.h:326
bool isWrightFisher()
Definition: LCEbreed.h:118
void WrightFisherPopulation()
Definition: LCEbreed.cc:457
virtual ~LCE_Breed_base()
Definition: LCEbreed.h:72
double getFixedFecundity(double mean)
Definition: LCEbreed.h:103
sex_t getOffsprgSexSelfing()
Definition: LCEbreed.h:115
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:271
Individual * breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Makes a new individual with the right parents.
Definition: LCEbreed.cc:371
Individual * RandomMating(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to a male drawn randomly from a patch.
Definition: LCEbreed.h:241
int getMatingSystem()
Definition: LCEbreed.h:100
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:299
double getFecundity(double mean)
Definition: LCEbreed.h:111
bool _do_inherit
Definition: LCEbreed.h:51
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:80
double getGaussianFecundity(double mean)
Definition: LCEbreed.h:104
Individual * makeOffspring(Individual *ind)
Last step of the breeding process, does inheritance and mutation of the parents' genes.
Definition: LCEbreed.cc:349
double _sd_fecundity
Definition: LCEbreed.h:50
sex_t(LCE_Breed_base::* GetOffsprgSex)()
Definition: LCEbreed.h:62
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:353
double(LCE_Breed_base::* FecundityFuncPtr)(double mean)
Definition: LCEbreed.h:60
Individual * do_breed(Individual *mother, Individual *father, unsigned int LocalPatch)
Calls the breeding function unsing its pointer.
Definition: LCEbreed.h:175
double getMatingProportion()
Definition: LCEbreed.h:98
void(LCE_Breed_base::* PopModelFuncPtr)(void)
Definition: LCEbreed.h:63
double getLogNormalFecundity(double mean)
Definition: LCEbreed.h:107
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:378
Individual *(LCE_Breed_base::* DoBreedFuncPtr)(Individual *mother, Individual *father, unsigned int LocalPatch)
Definition: LCEbreed.h:59
double _mating_proportion
Definition: LCEbreed.h:50
bool setMatingSystem()
Definition: LCEbreed.cc:82
bool checkCloning(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is cloning.
Definition: LCEbreed.h:226
void doAgingInWFpop()
Definition: LCEbreed.cc:546
bool checkNoSelfing(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is not selfing or cloning.
Definition: LCEbreed.h:192
bool setFecundity()
Definition: LCEbreed.cc:262
sex_t getOffsprgSexRandom()
Definition: LCEbreed.h:113
bool doInheritance()
Definition: LCEbreed.h:101
bool checkMatingCondition(Patch *thePatch)
Checks if any mating will take place in the patch passed as argument.
Definition: LCEbreed.h:184
bool(LCE_Breed_base::* CheckMatingConditionFuncPtr)(Patch *thePatch)
Definition: LCEbreed.h:61
double getPoissonFecundity(double mean)
Definition: LCEbreed.h:102
sex_t getOffsprgSexFixed()
Definition: LCEbreed.cc:340
unsigned int _mating_males
Definition: LCEbreed.h:48
LCE_Breed_base()
Definition: LCEbreed.cc:44
Individual * partialSelfing(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns the mother pointer or a random female if _mating_proportion != 1.
Definition: LCEbreed.h:336
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:258
sex_t getOffsprgSexCloning()
Definition: LCEbreed.h:116
TMatrix _mean_fecundity
Definition: LCEbreed.h:66
bool checkSelfing(Patch *thePatch)
Checks whether mating will take place in the current patch when mating is selfing.
Definition: LCEbreed.h:216
Individual * fullPolyginy(Patch *thePatch, Individual *mother, unsigned int motherIndex)
Returns a pointer to the alpha male of the patch.
Definition: LCEbreed.h:250
int _mating_system
Definition: LCEbreed.h:47
bool setSexRatio()
Definition: LCEbreed.cc:222
Individual *(LCE_Breed_base::* MatingFuncPtr)(Patch *, Individual *, unsigned int)
Definition: LCEbreed.h:58
double getMeanFecundity(unsigned int patch)
Definition: LCEbreed.h:99
double getFecundity(unsigned int patch)
Definition: LCEbreed.h:110
virtual bool setParameters()
Definition: LCEbreed.cc:75
Implementation of the basic breeding and mating procedures, does not link to any trait.
Definition: LCEbreed.h:374
virtual age_t requiredAgeClass()
Definition: LCEbreed.h:394
virtual bool setParameters()
Definition: LCEbreed.cc:569
virtual void loadFileServices(FileServices *loader)
Definition: LCEbreed.h:389
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEbreed.h:391
virtual void execute()
Definition: LCEbreed.cc:576
virtual LifeCycleEvent * clone()
Definition: LCEbreed.h:387
virtual void loadStatServices(StatServices *loader)
Definition: LCEbreed.h:390
virtual ~LCE_Breed()
Definition: LCEbreed.h:380
LCE_Breed()
Definition: LCEbreed.h:378
virtual age_t removeAgeClass()
Definition: LCEbreed.h:392
virtual age_t addAgeClass()
Definition: LCEbreed.cc:594
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:71
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:79
bool isSet()
Definition: param.h:146
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
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
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
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:229
static double Gaussian(double sigma)
Definition: Uniform.h:271
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:125
static bool RandBool()
Returns a random boolean.
Definition: Uniform.h:170
static double LogNormal(double zeta, double sigma)
Definition: Uniform.h:367
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:43
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:137
The Service class used to manage the StatHandler objects.
Definition: statservices.h:48
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:48
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:191
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
@ FEM
Definition: types.h:35
@ MAL
Definition: types.h:35
unsigned int age_t
Age class flags.
Definition: types.h:44
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:52
#define OFFSPRG
Offspring age class flag.
Definition: types.h:48
@ ADLTx
Definition: types.h:40

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR