Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCEcomposite.h
Go to the documentation of this file.
1 
28 #ifndef LCE_COMPOSITE_H
29 #define LCE_COMPOSITE_H
30 
31 #include <cmath>
32 #include "LCEbreed.h"
33 #include "LCEdisperse.h"
34 #include "LCEselection.h"
35 #include "lifecycleevent.h"
36 
37 #ifdef HAS_GSL
38  #include <gsl/gsl_rng.h>
39  #include <gsl/gsl_randist.h>
40 #endif
41 //CLASS LCE_Breed_Disperse
42 //
47 class LCE_Breed_Disperse : public virtual LCE_Breed_base, public virtual LCE_Disperse_base
48 {
50 
51 
54 
55  // EXPONENTIAL GROWTH PARAMETERS:
59  unsigned int _T0_exp_growth;
60 
61 protected: //so that the derived class can use these function pointers
62 
65 
68 
69  Individual* (LCE_Breed_Disperse::* _make_offspring)(sex_t SEX, Patch* patch, unsigned int LocalPatch,
70  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
71  unsigned int (LCE_Breed_Disperse::* _get_numFemOffspring)(Patch* patch);
72  unsigned int (LCE_Breed_Disperse::* _get_numMalOffspring)(Patch* patch);
73  unsigned int (LCE_Breed_Disperse::* _get_patchFecundity )(Patch* patch, sex_t SEX);
74 
75 public:
76 
78 
79  virtual ~LCE_Breed_Disperse (){}
80 
81  void do_breed_disperse ();
83  void do_breed_disperse_in_patch (sex_t SEX, Patch* patch, unsigned int ID, unsigned int num_offsprg);
84  void do_breed_disperse_in_empty_patch (sex_t SEX, Patch* patch, unsigned int ID, unsigned int num_offsprg);
85 
86 
87  unsigned int numFemOffspring (Patch *patch)
88  {
89 // if (patch->size(FEM, ADLTx) == 0 && _dispersing_sex != FEM)//to avoid choosing a local female when there is none
90 // return 0;
91 // else
92  return (this->*_get_patchFecundity)(patch, FEM);
93  }
94 
96  unsigned int numFemOffspring_colonizers (Patch *patch)
97  {
98  if(patch->isEmpty()) {
99 // //check if only one sex sends gametes around, capturing the case of pollen dispersal
100 // if(_dispersing_sex != FEM)
101 // return 0;
102 // else
103 
104  return _num_colonizers.get(1, patch->getID()); // Females on second row
105 
106  } else
107  return (this->*_get_patchFecundity)(patch, FEM);
108  }
109 
111  unsigned int numMalOffspring_notrandom (Patch *patch)
112  {
113  return 0;
114  }
115 
116  unsigned int numMalOffspring_random (Patch *patch)
117  { //return 0 if only males gametes migrate and there is no females in the patch
118  //to avoid choosing a local female when there is none
119  //(we assume it doesn't make sense to have only female gametes migrating)
120 // if (patch->size(FEM, ADLTx) == 0 && _dispersing_sex != FEM)
121 // return 0;
122 // else
123  return (this->*_get_patchFecundity)(patch, MAL);
124  }
125 
127  {
128  if(patch->isEmpty()) {
129 // //check if only one sex sends gametes around, capturing the case of pollen dispersal
130 // if(_dispersing_sex != FEM)
131 // return 0;
132 // else
133  return _num_colonizers.get(0, patch->getID()); // Males on first row
134  } else
135  return (this->*_get_patchFecundity)(patch, MAL);
136  }
137 
140 
141  unsigned int instantGrowth (Patch* patch, sex_t SEX)
142  {
143  return patch->get_K(SEX);
144  }
146  unsigned int logisticGrowth (Patch* patch, sex_t SEX)
147  {
148  double K = (double)patch->get_K(SEX);
149  double r = _growthRates.get(0, patch->getID());
150  double N = (double)patch->size(ADLTx);
151  if( K <= N )
152  return K;
153  else
154  return (unsigned int)ceil(N + r*N*((K-N)/K));
155  }
157  unsigned int stochasticLogisticGrowth (Patch* patch, sex_t SEX)
158  {
159  return (unsigned int)RAND::Poisson((double)logisticGrowth(patch, SEX));
160  }
163  unsigned int conditionalLogisticGrowth (Patch* patch, sex_t SEX)
164  {
165  if (patch->size(SEX, ADLTx) < patch->get_K(SEX)/2) {
166  return fixedFecundityGrowth(patch, SEX);
167  } else {
168  return logisticGrowth(patch, SEX);
169  }
170  }
174  {
175  if (patch->size(SEX, ADLTx) < patch->get_K(SEX)/2) {
176  return stochasticFecundityGrowth(patch, SEX);
177  } else {
178  return stochasticLogisticGrowth(patch, SEX);
179  }
180  }
183  unsigned int fixedFecundityGrowth (Patch* patch, sex_t SEX)
184  {
185  return patch->size(SEX,ADULTS)*LCE_Breed_base::getMeanFecundity(patch->getID());
186  }
189  unsigned int stochasticFecundityGrowth (Patch* patch, sex_t SEX)
190  {
191  return RAND::Uniform(patch->size(SEX,ADULTS)*LCE_Breed_base::getMeanFecundity(patch->getID()));
192  }
194  unsigned int exponentialGrowth (Patch* patch, sex_t SEX);
196 
199  Individual* mate_random (sex_t SEX, Patch *patch, unsigned int LocalPatch,
200  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
201 
202  Individual* mate_random_hermaphrodite (sex_t SEX, Patch *patch, unsigned int LocalPatch,
203  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
204 
205  Individual* mate_selfing (sex_t SEX, Patch *patch, unsigned int LocalPatch,
206  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
207 
208  Individual* mate_full_selfing (sex_t SEX, Patch *patch, unsigned int LocalPatch,
209  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
210 
211  Individual* mate_cloning (sex_t SEX, Patch *patch, unsigned int LocalPatch,
212  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
213 
215 
216  Individual* get_parent (sex_t SEX, sex_t DispSex, Patch* LocalPatch, unsigned int patchID,
217  gsl_ran_discrete_t* rates);
219 
222 // virtual void init(Metapop* popPtr);
223  virtual bool setParameters ();
224  virtual void execute ();
225  virtual LifeCycleEvent* clone () {return new LCE_Breed_Disperse();}
226  virtual void loadFileServices ( FileServices* loader ) {}
227  virtual void loadStatServices ( StatServices* loader ) {}
228  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
229  virtual age_t removeAgeClass ( ) {return NONE;}
230  virtual age_t addAgeClass ( ) {return (isWrightFisher() ? NONE : OFFSPRG);}
231  virtual age_t requiredAgeClass () {return ADULTS;}
233 
234 };
235 
236 // Class LCE_Breed_Selection
237 //
240 class LCE_Breed_Selection : public virtual LCE_Breed_base, public virtual LCE_Selection_base
241 {
242 
243  void (LCE_Breed_Selection::* _breed_selection) (Patch* patch, unsigned int patchID, unsigned int *cntr);
244 
245  unsigned int _nb_trait;
246 
247  vector< unsigned int > _nonSelectedTraitIndices;
248 
249 public:
250 
251  LCE_Breed_Selection ( ); // : LifeCycleEvent("breed_selection","") {}
252  virtual ~LCE_Breed_Selection ( ) {}
253 
255  bool setNonSelectedTraitTable ();
256 
263  Individual* makeOffspringWithSelection (Individual* ind, unsigned int natalpatch);
264 
265  void do_breed_selection_FecFitness (Patch* patch, unsigned int patchID, unsigned int *cntr);
266  void do_breed_selection_OffSurvival (Patch* patch, unsigned int patchID, unsigned int *cntr);
267  void do_breed_selection_WrightFisher_2sex (Patch* patch, unsigned int patchID, unsigned int *cntr);
268  void do_breed_selection_WrightFisher_1sex (Patch* patch, unsigned int patchID, unsigned int *cntr);
269 
270  void setReproScaledFitness_sum (sex_t SEX, valarray< double > &survival, unsigned int numReproFem, Patch* patch);
271  gsl_ran_discrete_t* setReproScaledFitness_gsl (sex_t SEX, unsigned int numReproInd, Patch* patch);
272 
275 // virtual void init (Metapop* popPtr);
276  virtual bool setParameters ( );
277  virtual void execute ( );
278  virtual LifeCycleEvent* clone ( ){ return new LCE_Breed_Selection(); }
279  virtual void loadFileServices ( FileServices* loader ) {}
280  virtual void loadStatServices ( StatServices* loader );
281  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
282  virtual age_t removeAgeClass ( ) {return NONE;}
283  virtual age_t addAgeClass ( ) {return (isWrightFisher() ? NONE : OFFSPRG);}
284  virtual age_t requiredAgeClass( ) {return ADULTS;}
286 };
287 
288 //CLASS LCE_Breed_Selection_Disperse
289 //
297 {
298 // int _max_try;
299 
301 
302 public:
303 
305 
307 
308  void breed_selection_disperse(int* counter);
309  void breed_selection_disperse_propagule(int* counter);
310 
311  void do_breed (sex_t SEX, unsigned int size, int* counter, Patch* patch, unsigned int patchID);
312 
315 // virtual void init(Metapop* popPtr);
316  virtual bool setParameters ();
317  virtual void execute ();
319  virtual void loadFileServices ( FileServices* loader ) {}
320  virtual void loadStatServices ( StatServices* loader );
321  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
322  virtual age_t removeAgeClass ( ) {return NONE;}
323  virtual age_t addAgeClass ( ) {return (isWrightFisher() ? NONE : OFFSPRG);}
324  virtual age_t requiredAgeClass () {return ADULTS;}
326 };
327 #endif
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
Performs breeding and migration in one, migration rates are backward rates.
Definition: LCEcomposite.h:48
unsigned int stochasticFecundityGrowth(Patch *patch, sex_t SEX)
The number of offspring produced is a random number drawn from a Poisson distribution with mean equal...
Definition: LCEcomposite.h:189
unsigned int(LCE_Breed_Disperse::* _get_numMalOffspring)(Patch *patch)
Definition: LCEcomposite.h:72
void do_breed_disperse()
Definition: LCEcomposite.cc:275
Individual * mate_cloning(sex_t SEX, Patch *patch, unsigned int LocalPatch, gsl_ran_discrete_t *rate_fem, gsl_ran_discrete_t *rate_mal)
Definition: LCEcomposite.cc:556
unsigned int conditionalLogisticGrowth(Patch *patch, sex_t SEX)
The number of offspring produced depends on the adult density.
Definition: LCEcomposite.h:163
unsigned int numMalOffspring_random_colonizers(Patch *patch)
Definition: LCEcomposite.h:126
void do_breed_disperse_in_empty_patch(sex_t SEX, Patch *patch, unsigned int ID, unsigned int num_offsprg)
Definition: LCEcomposite.cc:355
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEcomposite.h:228
virtual age_t removeAgeClass()
Definition: LCEcomposite.h:229
Individual * get_parent(sex_t SEX, sex_t DispSex, Patch *LocalPatch, unsigned int patchID, gsl_ran_discrete_t *rates)
Definition: LCEcomposite.cc:568
virtual void loadStatServices(StatServices *loader)
Definition: LCEcomposite.h:227
LCE_Breed_Disperse()
Definition: LCEcomposite.cc:43
Individual * mate_full_selfing(sex_t SEX, Patch *patch, unsigned int LocalPatch, gsl_ran_discrete_t *rate_fem, gsl_ran_discrete_t *rate_mal)
Definition: LCEcomposite.cc:544
unsigned int exponentialGrowth(Patch *patch, sex_t SEX)
Exponential growth using current patch size as basis to calculate future sizes, set once the function...
Definition: LCEcomposite.cc:458
sex_t _dispersing_sex
Which part of the population is dispersing its gametes.
Definition: LCEcomposite.h:67
unsigned int numMalOffspring_notrandom(Patch *patch)
The number of males produced is always zero when the mating system is not random mating.
Definition: LCEcomposite.h:111
Individual * mate_selfing(sex_t SEX, Patch *patch, unsigned int LocalPatch, gsl_ran_discrete_t *rate_fem, gsl_ran_discrete_t *rate_mal)
Definition: LCEcomposite.cc:517
unsigned int(LCE_Breed_Disperse::* _get_patchFecundity)(Patch *patch, sex_t SEX)
Definition: LCEcomposite.h:73
unsigned int conditionalStochasticLogisticGrowth(Patch *patch, sex_t SEX)
The number of offspring produced depends on the adult density, similar to 'conditionalLogisticGrowth'...
Definition: LCEcomposite.h:173
Individual * makeOffspring(Individual *ind)
Individual * mate_random_hermaphrodite(sex_t SEX, Patch *patch, unsigned int LocalPatch, gsl_ran_discrete_t *rate_fem, gsl_ran_discrete_t *rate_mal)
Definition: LCEcomposite.cc:503
TMatrix _growthRates
Patch-specific growth rates.
Definition: LCEcomposite.h:53
unsigned int stochasticLogisticGrowth(Patch *patch, sex_t SEX)
The number of offspring produced is drawn from a Poisson with mean equal to the logistic growth predi...
Definition: LCEcomposite.h:157
virtual age_t addAgeClass()
Definition: LCEcomposite.h:230
unsigned int numFemOffspring(Patch *patch)
Definition: LCEcomposite.h:87
void(LCE_Breed_Disperse::* _breed_disperse)()
Definition: LCEcomposite.h:49
virtual ~LCE_Breed_Disperse()
Definition: LCEcomposite.h:79
virtual age_t requiredAgeClass()
Definition: LCEcomposite.h:231
unsigned int numFemOffspring_colonizers(Patch *patch)
The number of females produced in case a max number of colonizers was specified.
Definition: LCEcomposite.h:96
unsigned int fixedFecundityGrowth(Patch *patch, sex_t SEX)
The number of offspring produced is equal to the current number of breeders multiplied by the mean fe...
Definition: LCEcomposite.h:183
Individual *(LCE_Breed_Disperse::* _make_offspring)(sex_t SEX, Patch *patch, unsigned int LocalPatch, gsl_ran_discrete_t *rate_fem, gsl_ran_discrete_t *rate_mal)
Definition: LCEcomposite.h:69
void do_breed_disperse_in_patch(sex_t SEX, Patch *patch, unsigned int ID, unsigned int num_offsprg)
Definition: LCEcomposite.cc:316
unsigned int numMalOffspring_random(Patch *patch)
Definition: LCEcomposite.h:116
unsigned int logisticGrowth(Patch *patch, sex_t SEX)
The number of offspring produced is given by the logistic growth function.
Definition: LCEcomposite.h:146
Individual * mate_random(sex_t SEX, Patch *patch, unsigned int LocalPatch, gsl_ran_discrete_t *rate_fem, gsl_ran_discrete_t *rate_mal)
Definition: LCEcomposite.cc:490
virtual bool setParameters()
Definition: LCEcomposite.cc:58
unsigned int _T0_exp_growth
Starting time of the growing phase, can be reset by a parameter update.
Definition: LCEcomposite.h:59
virtual void loadFileServices(FileServices *loader)
Definition: LCEcomposite.h:226
unsigned int(LCE_Breed_Disperse::* _get_numFemOffspring)(Patch *patch)
Definition: LCEcomposite.h:71
virtual void execute()
Definition: LCEcomposite.cc:243
TMatrix _num_colonizers
Maximum size of a patch after colonisation.
Definition: LCEcomposite.h:64
unsigned int instantGrowth(Patch *patch, sex_t SEX)
The number of offspring produced corresponds to the carrying capacity of the patch.
Definition: LCEcomposite.h:141
virtual LifeCycleEvent * clone()
Definition: LCEcomposite.h:225
void do_breed_disperse_propagule()
Definition: LCEcomposite.cc:450
TMatrix _N_at_T0
Recorder of original patch sizes used to compute future sizes depending on growth rate model.
Definition: LCEcomposite.h:57
Composite LCE performing breeding, migration and viability selection all in one.
Definition: LCEcomposite.h:297
virtual void execute()
Definition: LCEcomposite.cc:658
virtual void loadStatServices(StatServices *loader)
Definition: LCEcomposite.cc:651
virtual LifeCycleEvent * clone()
Definition: LCEcomposite.h:318
void breed_selection_disperse_propagule(int *counter)
Definition: LCEcomposite.cc:766
LCE_Breed_Selection_Disperse()
Definition: LCEcomposite.cc:619
virtual void loadFileServices(FileServices *loader)
Definition: LCEcomposite.h:319
void do_breed(sex_t SEX, unsigned int size, int *counter, Patch *patch, unsigned int patchID)
Definition: LCEcomposite.cc:774
virtual ~LCE_Breed_Selection_Disperse()
Definition: LCEcomposite.h:306
virtual age_t removeAgeClass()
Definition: LCEcomposite.h:322
virtual bool setParameters()
Definition: LCEcomposite.cc:628
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEcomposite.h:321
void(LCE_Breed_Selection_Disperse::* _breed_selection_disperse)(int *counter)
Definition: LCEcomposite.h:300
virtual age_t addAgeClass()
Definition: LCEcomposite.h:323
virtual age_t requiredAgeClass()
Definition: LCEcomposite.h:324
void breed_selection_disperse(int *counter)
Definition: LCEcomposite.cc:701
Composite LCE implementing breeding and viability selection on a given trait type.
Definition: LCEcomposite.h:241
void do_breed_selection_WrightFisher_1sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1165
virtual bool setParameters()
Definition: LCEcomposite.cc:906
void do_breed_selection_FecFitness(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1067
void do_breed_selection_WrightFisher_2sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1113
virtual age_t addAgeClass()
Definition: LCEcomposite.h:283
Individual * makeOffspringWithSelection(Individual *ind, unsigned int natalpatch)
Performs viability selection and breeding at the same time.
Definition: LCEcomposite.cc:1246
vector< unsigned int > _nonSelectedTraitIndices
Definition: LCEcomposite.h:247
virtual void loadStatServices(StatServices *loader)
Definition: LCEcomposite.cc:977
void do_breed_selection_OffSurvival(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1028
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEcomposite.h:281
virtual LifeCycleEvent * clone()
Definition: LCEcomposite.h:278
virtual age_t requiredAgeClass()
Definition: LCEcomposite.h:284
void setReproScaledFitness_sum(sex_t SEX, valarray< double > &survival, unsigned int numReproFem, Patch *patch)
Definition: LCEcomposite.cc:1213
virtual ~LCE_Breed_Selection()
Definition: LCEcomposite.h:252
LCE_Breed_Selection()
Definition: LCEcomposite.cc:897
virtual age_t removeAgeClass()
Definition: LCEcomposite.h:282
virtual void loadFileServices(FileServices *loader)
Definition: LCEcomposite.h:279
void(LCE_Breed_Selection::* _breed_selection)(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.h:243
bool setNonSelectedTraitTable()
Builds the vector of traits not under selection.
Definition: LCEcomposite.cc:948
gsl_ran_discrete_t * setReproScaledFitness_gsl(sex_t SEX, unsigned int numReproInd, Patch *patch)
Definition: LCEcomposite.cc:1228
unsigned int _nb_trait
Definition: LCEcomposite.h:245
virtual void execute()
Definition: LCEcomposite.cc:984
Base class for the breeding (and mating) life cycle events.
Definition: LCEbreed.h:44
bool isWrightFisher()
Definition: LCEbreed.h:118
double getMeanFecundity(unsigned int patch)
Definition: LCEbreed.h:99
The base class of the dispersal LCEs, all events move offspring to the post-dispersal patch container...
Definition: LCEdisperse.h:42
Base class performing (viability) selection on an arbitrary trait.
Definition: LCEselection.h:49
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:71
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
unsigned int get_K()
Definition: metapop.h:480
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
unsigned int getID()
Definition: metapop.h:479
bool isEmpty()
Definition: metapop.h:486
static double Poisson(double mean)
From the Numerical Recieps.
Definition: Uniform.h:229
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:125
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:43
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
#define NONE
No age flag.
Definition: types.h:46
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