Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCEcomposite.h
Go to the documentation of this file.
1 
30 #ifndef LCE_COMPOSITE_H
31 #define LCE_COMPOSITE_H
32 
33 #include <cmath>
34 #include "LCEbreed.h"
35 #include "LCEdisperse.h"
36 #include "LCEselection.h"
37 #include "lifecycleevent.h"
38 
39 #ifdef HAS_GSL
40  #include <gsl/gsl_rng.h>
41  #include <gsl/gsl_randist.h>
42 #endif
43 //CLASS LCE_Breed_Disperse
44 //
49 class LCE_Breed_Disperse : public virtual LCE_Breed_base, public virtual LCE_Disperse_base
50 {
52 
53 
55  double *_growthRates;
56 
59 
60 protected: //so that the derived class can use these function pointers
61 
64 
67 
68  Individual* (LCE_Breed_Disperse::* _make_offspring)(sex_t SEX, Patch* patch, unsigned int LocalPatch,
69  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
70  unsigned int (LCE_Breed_Disperse::* _get_numFemOffspring)(Patch* patch);
71  unsigned int (LCE_Breed_Disperse::* _get_numMalOffspring)(Patch* patch);
72  unsigned int (LCE_Breed_Disperse::* _get_patchFecundity )(Patch* patch, sex_t SEX);
73 
74 public:
75 
77 
78  virtual ~LCE_Breed_Disperse (){if(_growthRates) delete [] _growthRates;}
79 
80  void do_breed_disperse ();
82  void do_breed_disperse_in_patch (sex_t SEX, Patch* patch, unsigned int ID, unsigned int num_offsprg);
83  void do_breed_disperse_in_empty_patch (sex_t SEX, Patch* patch, unsigned int ID, unsigned int num_offsprg);
84 
85 
86  unsigned int numFemOffspring (Patch *patch)
87  {
88  if (patch->size(FEM, ADLTx) == 0 && _dispersing_sex != FEM)//to avoid choosing a local female when there is none
89  return 0;
90  else
91  return (this->*_get_patchFecundity)(patch, FEM);
92  }
93 
95  unsigned int numFemOffspring_colonizers (Patch *patch)
96  {
97  if(patch->get_isExtinct()) {
98 // //check if only one sex sends gametes around, capturing the case of pollen dispersal
99 // if(_dispersing_sex != FEM)
100 // return 0;
101 // else
102  return _num_colonizers;
103  } else
104  return (this->*_get_patchFecundity)(patch, FEM);
105  }
106 
108  unsigned int numMalOffspring_notrandom (Patch *patch)
109  {
110  return 0;
111  }
112 
113  unsigned int numMalOffspring_random (Patch *patch)
114  { //return 0 if only males gametes migrate and there is no females in the patch
115  //to avoid choosing a local female when there is none
116  //(we assume it doesn't make sense to have only female gametes migrating)
117  if (patch->size(FEM, ADLTx) == 0 && _dispersing_sex != FEM)
118  return 0;
119  else
120  return (this->*_get_patchFecundity)(patch, MAL);
121  }
122 
124  {
125  if(patch->get_isExtinct()) {
126 // //check if only one sex sends gametes around, capturing the case of pollen dispersal
127 // if(_dispersing_sex != FEM)
128 // return 0;
129 // else
130  return _num_colonizers;
131  } else
132  return (this->*_get_patchFecundity)(patch, MAL);
133  }
134 
137 
138  unsigned int instantGrowth (Patch* patch, sex_t SEX)
139  {
140  return patch->get_K(SEX);
141  }
143  unsigned int logisticGrowth (Patch* patch, sex_t SEX)
144  {
145  double K = (double)patch->get_K(SEX);
146  double r = _growthRates[ patch->getID() ];
147  double N = (double)patch->size(ADLTx);
148  if( K <= N )
149  return K;
150  else
151  return (unsigned int)ceil(N + r*N*((K-N)/K));
152  }
154  unsigned int stochasticLogisticGrowth (Patch* patch, sex_t SEX)
155  {
156  return (unsigned int)RAND::Poisson((double)logisticGrowth(patch, SEX));
157  }
160  unsigned int conditionalLogisticGrowth (Patch* patch, sex_t SEX)
161  {
162  if (patch->size(SEX, ADLTx) < patch->get_K(SEX)/2) {
163  return fixedFecundityGrowth(patch, SEX);
164  } else {
165  return logisticGrowth(patch, SEX);
166  }
167  }
171  {
172  if (patch->size(SEX, ADLTx) < patch->get_K(SEX)/2) {
173  return stochasticFecundityGrowth(patch, SEX);
174  } else {
175  return stochasticLogisticGrowth(patch, SEX);
176  }
177  }
180  unsigned int fixedFecundityGrowth (Patch* patch, sex_t SEX)
181  {
182  return patch->size(SEX,ADULTS)*LCE_Breed_base::getMeanFecundity(patch->getID());
183  }
186  unsigned int stochasticFecundityGrowth (Patch* patch, sex_t SEX)
187  {
188  return RAND::Uniform(patch->size(SEX,ADULTS)*LCE_Breed_base::getMeanFecundity(patch->getID()));
189  }
191  unsigned int exponentialGrowth (Patch* patch, sex_t SEX);
193 
196  Individual* mate_random (sex_t SEX, Patch *patch, unsigned int LocalPatch,
197  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
198 
199  Individual* mate_random_hermaphrodite (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_selfing (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_full_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_cloning (sex_t SEX, Patch *patch, unsigned int LocalPatch,
209  gsl_ran_discrete_t* rate_fem, gsl_ran_discrete_t* rate_mal);
210 
212 
213  Individual* get_parent (sex_t SEX, sex_t DispSex, Patch* LocalPatch, unsigned int patchID,
214  gsl_ran_discrete_t* rates);
216 
219 // virtual void init(Metapop* popPtr);
220  virtual bool setParameters ();
221  virtual void execute ();
222  virtual LifeCycleEvent* clone () {return new LCE_Breed_Disperse();}
223  virtual void loadFileServices ( FileServices* loader ) {}
224  virtual void loadStatServices ( StatServices* loader ) {}
225  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
226  virtual age_t removeAgeClass ( ) {return NONE;}
227  virtual age_t addAgeClass ( ) {return OFFSPRG;}
228  virtual age_t requiredAgeClass () {return ADULTS;}
230 
231 };
232 
233 // Class LCE_Breed_Selection
234 //
237 class LCE_Breed_Selection : public virtual LCE_Breed_base, public virtual LCE_Selection_base
238 {
239 
240  void (LCE_Breed_Selection::* _breed_selection) (Patch* patch, unsigned int patchID, unsigned int *cntr);
241 
242  unsigned int _nb_trait;
243 
244  vector< unsigned int > _nonSelectedTraitIndices;
245 
246 public:
247 
248  LCE_Breed_Selection ( ); // : LifeCycleEvent("breed_selection","") {}
249  virtual ~LCE_Breed_Selection ( ) {}
250 
252  bool setNonSelectedTraitTable ();
253 
260  Individual* makeOffspringWithSelection (Individual* ind, unsigned int natalpatch);
261 
262  void do_breed_selection_FecFitness (Patch* patch, unsigned int patchID, unsigned int *cntr);
263  void do_breed_selection_OffSurvival (Patch* patch, unsigned int patchID, unsigned int *cntr);
264  void do_breed_selection_WrightFisher_2sex (Patch* patch, unsigned int patchID, unsigned int *cntr);
265  void do_breed_selection_WrightFisher_1sex (Patch* patch, unsigned int patchID, unsigned int *cntr);
266 
267  void setReproScaledFitness_sum (sex_t SEX, valarray< double > &survival, unsigned int numReproFem, Patch* patch);
268  gsl_ran_discrete_t* setReproScaledFitness_gsl (sex_t SEX, unsigned int numReproInd, Patch* patch);
269 
272 // virtual void init (Metapop* popPtr);
273  virtual bool setParameters ();
274  virtual void execute ();
275  virtual LifeCycleEvent* clone ( ){ return new LCE_Breed_Selection(); }
276  virtual void loadFileServices ( FileServices* loader ) {}
277  virtual void loadStatServices ( StatServices* loader );
278  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
279  virtual age_t removeAgeClass ( ) {return NONE;}
280  virtual age_t addAgeClass ( ) {return OFFSPRG;}
281  virtual age_t requiredAgeClass () {return ADULTS;}
283 };
284 
285 //CLASS LCE_Breed_Selection_Disperse
286 //
294 {
295 // int _max_try;
296 
298 
299 public:
300 
302 
304 
305  void breed_selection_disperse(int* counter);
306  void breed_selection_disperse_propagule(int* counter);
307 
308  void do_breed (sex_t SEX, unsigned int size, int* counter, Patch* patch, unsigned int patchID);
309 
312 // virtual void init(Metapop* popPtr);
313  virtual bool setParameters ();
314  virtual void execute ();
316  virtual void loadFileServices ( FileServices* loader ) {}
317  virtual void loadStatServices ( StatServices* loader );
318  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
319  virtual age_t removeAgeClass ( ) {return NONE;}
320  virtual age_t addAgeClass ( ) {return OFFSPRG;}
321  virtual age_t requiredAgeClass () {return ADULTS;}
323 };
324 #endif
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
Performs breeding and migration in one, migration rates are backward rates.
Definition: LCEcomposite.h:50
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:186
unsigned int(LCE_Breed_Disperse::* _get_numMalOffspring)(Patch *patch)
Definition: LCEcomposite.h:71
void do_breed_disperse()
Definition: LCEcomposite.cc:251
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:525
unsigned int conditionalLogisticGrowth(Patch *patch, sex_t SEX)
The number of offspring produced depends on the adult density.
Definition: LCEcomposite.h:160
unsigned int numMalOffspring_random_colonizers(Patch *patch)
Definition: LCEcomposite.h:123
void do_breed_disperse_in_empty_patch(sex_t SEX, Patch *patch, unsigned int ID, unsigned int num_offsprg)
Definition: LCEcomposite.cc:326
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEcomposite.h:225
virtual age_t removeAgeClass()
Definition: LCEcomposite.h:226
Individual * get_parent(sex_t SEX, sex_t DispSex, Patch *LocalPatch, unsigned int patchID, gsl_ran_discrete_t *rates)
Definition: LCEcomposite.cc:537
virtual void loadStatServices(StatServices *loader)
Definition: LCEcomposite.h:224
LCE_Breed_Disperse()
Definition: LCEcomposite.cc:45
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:513
TMatrix _NatT0
Recorder of original patch sizes used to compute future sizes depending on growth rate model.
Definition: LCEcomposite.h:58
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:428
sex_t _dispersing_sex
Which part of the population is dispersing its gametes.
Definition: LCEcomposite.h:66
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:108
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:486
unsigned int(LCE_Breed_Disperse::* _get_patchFecundity)(Patch *patch, sex_t SEX)
Definition: LCEcomposite.h:72
unsigned int conditionalStochasticLogisticGrowth(Patch *patch, sex_t SEX)
The number of offspring produced depends on the adult density, similar to 'conditionalLogisticGrowth'...
Definition: LCEcomposite.h:170
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:472
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:154
virtual age_t addAgeClass()
Definition: LCEcomposite.h:227
double * _growthRates
Patch-specific growth rates.
Definition: LCEcomposite.h:55
unsigned int numFemOffspring(Patch *patch)
Definition: LCEcomposite.h:86
void(LCE_Breed_Disperse::* _breed_disperse)()
Definition: LCEcomposite.h:51
virtual ~LCE_Breed_Disperse()
Definition: LCEcomposite.h:78
virtual age_t requiredAgeClass()
Definition: LCEcomposite.h:228
unsigned int numFemOffspring_colonizers(Patch *patch)
The number of females produced in case a max number of colonizers was specified.
Definition: LCEcomposite.h:95
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:180
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:68
void do_breed_disperse_in_patch(sex_t SEX, Patch *patch, unsigned int ID, unsigned int num_offsprg)
Definition: LCEcomposite.cc:287
unsigned int numMalOffspring_random(Patch *patch)
Definition: LCEcomposite.h:113
int _num_colonizers
Maximum size of a patch after colonisation.
Definition: LCEcomposite.h:63
unsigned int logisticGrowth(Patch *patch, sex_t SEX)
The number of offspring produced is given by the logistic growth function.
Definition: LCEcomposite.h:143
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:459
virtual bool setParameters()
Definition: LCEcomposite.cc:61
virtual void loadFileServices(FileServices *loader)
Definition: LCEcomposite.h:223
unsigned int(LCE_Breed_Disperse::* _get_numFemOffspring)(Patch *patch)
Definition: LCEcomposite.h:70
virtual void execute()
Definition: LCEcomposite.cc:222
unsigned int instantGrowth(Patch *patch, sex_t SEX)
The number of offspring produced corresponds to the carrying capacity of the patch.
Definition: LCEcomposite.h:138
virtual LifeCycleEvent * clone()
Definition: LCEcomposite.h:222
void do_breed_disperse_propagule()
Definition: LCEcomposite.cc:420
Composite LCE performing breeding, migration and viability selection all in one.
Definition: LCEcomposite.h:294
virtual void execute()
Definition: LCEcomposite.cc:641
virtual void loadStatServices(StatServices *loader)
Definition: LCEcomposite.cc:634
virtual LifeCycleEvent * clone()
Definition: LCEcomposite.h:315
void breed_selection_disperse_propagule(int *counter)
Definition: LCEcomposite.cc:743
LCE_Breed_Selection_Disperse()
Definition: LCEcomposite.cc:588
virtual void loadFileServices(FileServices *loader)
Definition: LCEcomposite.h:316
void do_breed(sex_t SEX, unsigned int size, int *counter, Patch *patch, unsigned int patchID)
Definition: LCEcomposite.cc:751
virtual ~LCE_Breed_Selection_Disperse()
Definition: LCEcomposite.h:303
virtual age_t removeAgeClass()
Definition: LCEcomposite.h:319
virtual bool setParameters()
Definition: LCEcomposite.cc:597
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEcomposite.h:318
void(LCE_Breed_Selection_Disperse::* _breed_selection_disperse)(int *counter)
Definition: LCEcomposite.h:297
virtual age_t addAgeClass()
Definition: LCEcomposite.h:320
virtual age_t requiredAgeClass()
Definition: LCEcomposite.h:321
void breed_selection_disperse(int *counter)
Definition: LCEcomposite.cc:681
Composite LCE implementing breeding and viability selection on a given trait type.
Definition: LCEcomposite.h:238
void do_breed_selection_WrightFisher_1sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1136
virtual bool setParameters()
Definition: LCEcomposite.cc:883
void do_breed_selection_FecFitness(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1041
void do_breed_selection_WrightFisher_2sex(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1087
virtual age_t addAgeClass()
Definition: LCEcomposite.h:280
Individual * makeOffspringWithSelection(Individual *ind, unsigned int natalpatch)
Performs viability selection and breeding at the same time.
Definition: LCEcomposite.cc:1213
vector< unsigned int > _nonSelectedTraitIndices
Definition: LCEcomposite.h:244
virtual void loadStatServices(StatServices *loader)
Definition: LCEcomposite.cc:954
void do_breed_selection_OffSurvival(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.cc:1005
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEcomposite.h:278
virtual LifeCycleEvent * clone()
Definition: LCEcomposite.h:275
virtual age_t requiredAgeClass()
Definition: LCEcomposite.h:281
void setReproScaledFitness_sum(sex_t SEX, valarray< double > &survival, unsigned int numReproFem, Patch *patch)
Definition: LCEcomposite.cc:1181
virtual ~LCE_Breed_Selection()
Definition: LCEcomposite.h:249
LCE_Breed_Selection()
Definition: LCEcomposite.cc:874
virtual age_t removeAgeClass()
Definition: LCEcomposite.h:279
virtual void loadFileServices(FileServices *loader)
Definition: LCEcomposite.h:276
void(LCE_Breed_Selection::* _breed_selection)(Patch *patch, unsigned int patchID, unsigned int *cntr)
Definition: LCEcomposite.h:240
bool setNonSelectedTraitTable()
Builds the vector of traits not under selection.
Definition: LCEcomposite.cc:925
gsl_ran_discrete_t * setReproScaledFitness_gsl(sex_t SEX, unsigned int numReproInd, Patch *patch)
Definition: LCEcomposite.cc:1196
unsigned int _nb_trait
Definition: LCEcomposite.h:242
virtual void execute()
Definition: LCEcomposite.cc:961
Base class for the breeding (and mating) life cycle events.
Definition: LCEbreed.h:46
double getMeanFecundity(unsigned int patch)
Definition: LCEbreed.h:101
The base class of the dispersal LCEs, all events move offspring to the post-dispersal patch container...
Definition: LCEdisperse.h:44
Base class performing (viability) selection on an arbitrary trait.
Definition: LCEselection.h:51
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
unsigned int get_K()
Definition: metapop.h:482
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
unsigned int getID()
Definition: metapop.h:481
bool get_isExtinct()
Definition: metapop.h:486
static double Poisson(double mean)
From the Numerical Recieps.
Definition: Uniform.h:219
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:124
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:45
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
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
#define NONE
No age flag.
Definition: types.h:48
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