Nemo  2.3.46
LCEmisc.h
Go to the documentation of this file.
1 
30 #ifndef LCEMISC_H
31 #define LCEMISC_H
32 
33 #include <iostream>
34 #include <string>
35 #include <map>
36 #include "types.h"
37 #include "lifecycleevent.h"
38 #include "fileservices.h"
39 #include "statservices.h"
40 #include "filehandler.h"
41 #include "stathandler.h"
42 #include "Uniform.h"
43 
44 // LCE_Regulation
45 //
51 {
52 public:
53 
54  LCE_Regulation( ) : LifeCycleEvent("regulation","") {}
55 
56  virtual ~LCE_Regulation( ) { }
57 
58  void regulatePatch (Patch* patch, age_idx age, sex_t sex);
59 
60  //implementations:
61  virtual bool setParameters () {return true;}
62  virtual void execute ();
63  virtual LCE_Regulation* clone ( ) {return new LCE_Regulation();}
64  virtual void loadFileServices ( FileServices* loader ) {}
65  virtual void loadStatServices ( StatServices* loader ) {}
66  virtual age_t removeAgeClass ( ) {return NONE;}
67  virtual age_t addAgeClass ( ) {return NONE;}
68  virtual age_t requiredAgeClass () {return NONE;}
69 };
70 
71 // LCE_Aging
72 //
79 {
80 public:
81 
82  LCE_Aging( ) : LifeCycleEvent("aging","") {}
83 
84  virtual ~LCE_Aging( ) { }
85 
86  //implementations:
87  virtual bool setParameters () {return true;}
88  virtual void execute ();
89  virtual LCE_Aging* clone ( ) {return new LCE_Aging();}
90  virtual void loadFileServices ( FileServices* loader ) {}
91  virtual void loadStatServices ( StatServices* loader ) {}
92  virtual age_t removeAgeClass ( ) {return OFFSPRG;}
93  virtual age_t addAgeClass ( ) {return ADULTS;}
94  virtual age_t requiredAgeClass () {return OFFSPRG;}
95 };
96 
97 // LCE_Patch_Extinction
98 //
102 {
119 
120  unsigned int (LCE_Patch_Extinction:: *_rand_size_fct) (double);
121 
122  unsigned int rand_uniform (double max) {return RAND::Uniform((unsigned int)max);}
123  unsigned int rand_poisson (double mean){return (unsigned int)RAND::Poisson(mean);}
124  unsigned int rand_gaussian (double mean){return (unsigned int)abs(mean + RAND::Gaussian(_harvest_dist_stdev));}
125  unsigned int rand_exp (double mean){return (unsigned int)(-1.0 * mean * log(1.0-RAND::Uniform()));}
126  unsigned int rand_lognormal (double mean){return (unsigned int)RAND::LogNormal(mean, _harvest_dist_stdev);}
127 
128 public:
129 
132  {
133  if(_Xtion_rate) delete _Xtion_rate;
134  if(_harvest_size) delete _harvest_size;
135  if(_harvest_proportion) delete _harvest_proportion;
136  }
137 
138  bool set_matrix_param (TMatrix* mat, string name);
139  void do_flush (Patch *patch);
140  void do_remove (age_idx AGE, Patch *patch);
141  unsigned int get_harvest_size (age_idx AGE, Patch *patch);
142 
143  //LifeCycleEvent interface:
144  virtual bool setParameters ();
145  virtual void execute ();
146  virtual LifeCycleEvent* clone ( ) {return new LCE_Patch_Extinction();}
147 
148  //SimComponent interface:
149  virtual void loadFileServices ( FileServices* loader ) {}
150  virtual void loadStatServices ( StatServices* loader ) {}
151  virtual age_t removeAgeClass ( ) {return 0;}
152  virtual age_t addAgeClass ( ) {return 0;}
153  virtual age_t requiredAgeClass () {return 0;}
154 };
155 
156 class FHPedigreeReader;
157 
158 //CROSSING
159 //
161 class LCE_Cross : public LifeCycleEvent
162 {
163  unsigned int _nSire, _nDam;
164  unsigned int _nOffspring;
165  unsigned int _atGeneration;
167 
170  map<unsigned long, Individual* > _pedigree_pop;
171 
172 public:
173 
174  LCE_Cross( );
175  virtual ~LCE_Cross( ) { }
176 
177  void sampleAmongPop(Patch* patch, deque<Individual*>& males, unsigned int nsire);
178  void sampleWithinPop(Patch* patch, deque<Individual*>& males, deque<Individual*>& females, unsigned int nsire);
179  void generatePedigree ();
181 
182  //LifeCycleEvent interface:
183  virtual bool setParameters ();
184  virtual void execute ();
185  virtual LifeCycleEvent* clone ( ) {return new LCE_Cross();}
186 
187  //SimComponent interface:
188  virtual void loadFileServices ( FileServices* loader );
189  virtual void loadStatServices ( StatServices* loader ) {}
190  virtual age_t removeAgeClass ( ) {return 0;}
191  virtual age_t addAgeClass ( ) {return OFFSPRG;}
192  virtual age_t requiredAgeClass () {return ADULTS;}
193 
194 };
195 
196 //CROSSING FILE READER
197 //
199 class FHPedigreeReader : public EventFileHandler<LCE_Cross> {
200 public:
201  FHPedigreeReader(LCE_Cross* event); // : EventFileHandler< LCE_Cross > (event, ".ped");
202  virtual ~FHPedigreeReader(){}
203 
204  virtual void FHwrite () {}
205  virtual void FHread (string& filename);
206 
207  vector< unsigned long * >& getPedigree() {return _pedigree;}
208 
209 private:
210  vector< unsigned long * > _pedigree;
211 };
212 
213 
214 //RESIZE POP
215 //
218  {
219  list< int >::const_iterator _genITER;
221  list< int > _generations;
226  public:
227 
228  LCE_Resize( );
229  virtual ~LCE_Resize( ) { if(_patchBackup) delete _patchBackup;}
230 
233  void removeDesignatedPatch(bool do_backup);
234  void updatePatchCapacities();
235  void fillPop ( void (LCE_Resize:: *fillFuncPtr) (unsigned int p, age_idx age));
236  void fillPatchNoBackup(unsigned int p, age_idx age);
237  void fillPatchWithBackup(unsigned int p, age_idx age);
238  void regulate( void (LCE_Resize::* regFuncPtr) (Patch *patch, age_idx age));
239  void regulateAgeClassWithBackup(Patch *patch, age_idx age);
240  void regulateAgeClassNoBackup(Patch *patch, age_idx age);
241 
242  //LifeCycleEvent interface:
243  virtual bool setParameters ();
244  bool updateParameters ();
245  virtual void execute ();
246  virtual LifeCycleEvent* clone ( ) {return new LCE_Resize();}
247 
248  //SimComponent interface:
249  virtual void loadFileServices ( FileServices* loader ) {}
250  virtual void loadStatServices ( StatServices* loader ) {}
251  virtual age_t removeAgeClass ( ) {return 0;}
252  virtual age_t addAgeClass ( ) {return 0;}
253  virtual age_t requiredAgeClass () {return 0;}
254 
255  };
256 
257 
258 #endif //LCEMISC_H
Template class for the LCEs StatHandler classes.
Definition: filehandler.h:247
virtual void FHwrite()
Definition: LCEmisc.h:204
virtual bool setParameters()
Definition: LCEmisc.cc:397
bool _by_proportion
Definition: LCEmisc.h:112
virtual age_t addAgeClass()
Definition: LCEmisc.h:67
virtual void loadStatServices(StatServices *loader)
Definition: LCEmisc.h:250
virtual age_t addAgeClass()
Definition: LCEmisc.h:152
TMatrix * _harvest_size
Number of individual to remove per patch.
Definition: LCEmisc.h:106
Randomly removes individuals from the patches according to the extinction rate parameter.
Definition: LCEmisc.h:101
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
void regulateAgeClassWithBackup(Patch *patch, age_idx age)
Definition: LCEmisc.cc:1138
virtual ~LCE_Cross()
Definition: LCEmisc.h:175
void do_flush(Patch *patch)
Definition: LCEmisc.cc:316
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
void generatePedigree()
Definition: LCEmisc.cc:509
bool set_matrix_param(TMatrix *mat, string name)
Definition: LCEmisc.cc:252
virtual age_t requiredAgeClass()
Definition: LCEmisc.h:153
virtual LifeCycleEvent * clone()
Definition: LCEmisc.h:185
virtual void execute()
Definition: LCEmisc.cc:45
unsigned int get_harvest_size(age_idx AGE, Patch *patch)
Definition: LCEmisc.cc:354
LCE_Patch_Extinction()
Definition: LCEmisc.cc:132
unsigned int(LCE_Patch_Extinction::* _rand_size_fct)(double)
Definition: LCEmisc.h:120
virtual ~FHPedigreeReader()
Definition: LCEmisc.h:202
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
LCE_Aging()
Definition: LCEmisc.h:82
age_t _setAge
Definition: LCEmisc.h:224
virtual void loadStatServices(StatServices *loader)
Definition: LCEmisc.h:189
void buildNewPatchArrayWithBackup()
Definition: LCEmisc.cc:1020
void regulatePatch(Patch *patch, age_idx age, sex_t sex)
Definition: LCEmisc.cc:118
virtual LCE_Regulation * clone()
Definition: LCEmisc.h:63
virtual age_t addAgeClass()
Definition: LCEmisc.h:93
unsigned int age_t
Age class flags.
Definition: types.h:46
bool _doAmongPop
Definition: LCEmisc.h:166
static double LogNormal(double zeta, double sigma)
Definition: Uniform.h:334
virtual LifeCycleEvent * clone()
Definition: LCEmisc.h:146
TMatrix * _Xtion_rate
Patch extinction probability.
Definition: LCEmisc.h:104
bool create_individual_ancestors(Individual *ind)
Definition: LCEmisc.cc:579
void updatePatchCapacities()
Definition: LCEmisc.cc:992
void fillPatchNoBackup(unsigned int p, age_idx age)
Definition: LCEmisc.cc:1098
virtual ~LCE_Regulation()
Definition: LCEmisc.h:56
virtual void loadFileServices(FileServices *loader)
Definition: LCEmisc.h:90
A class to change the size of the population/patches during a simulation.
Definition: LCEmisc.h:217
virtual bool setParameters()
Definition: LCEmisc.cc:150
LCE_Regulation()
Definition: LCEmisc.h:54
virtual void loadFileServices(FileServices *loader)
Definition: LCEmisc.h:64
vector< unsigned long * > & getPedigree()
Definition: LCEmisc.h:207
FHPedigreeReader(LCE_Cross *event)
Definition: LCEmisc.cc:731
void sampleWithinPop(Patch *patch, deque< Individual * > &males, deque< Individual * > &females, unsigned int nsire)
Definition: LCEmisc.cc:688
virtual age_t removeAgeClass()
Definition: LCEmisc.h:151
Removes all adults from the patches and randomly moves the offspring to the adults age class...
Definition: LCEmisc.h:78
virtual age_t removeAgeClass()
Definition: LCEmisc.h:92
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * _patchBackup
Definition: LCEmisc.h:225
virtual void execute()
Definition: LCEmisc.cc:281
void do_remove(age_idx AGE, Patch *patch)
Definition: LCEmisc.cc:325
#define NONE
No age flag.
Definition: types.h:48
void removeDesignatedPatch(bool do_backup)
Definition: LCEmisc.cc:1043
static double Poisson(double mean)
From the Numerical Recieps.
Definition: Uniform.h:196
bool _doWithinPop
Definition: LCEmisc.h:166
unsigned int _nOffspring
Definition: LCEmisc.h:164
list< int > _generations
Definition: LCEmisc.h:221
void fillPop(void(LCE_Resize::*fillFuncPtr)(unsigned int p, age_idx age))
Definition: LCEmisc.cc:1081
bool _do_flush
Definition: LCEmisc.h:222
virtual void loadStatServices(StatServices *loader)
Definition: LCEmisc.h:150
void fillPatchWithBackup(unsigned int p, age_idx age)
Definition: LCEmisc.cc:1111
list< int >::const_iterator _genITER
Definition: LCEmisc.h:219
bool _do_regulate
Definition: LCEmisc.h:222
virtual void execute()
Definition: LCEmisc.cc:452
A class to perform crosses within patches, implements the NC1 mating design.
Definition: LCEmisc.h:161
void sampleAmongPop(Patch *patch, deque< Individual * > &males, unsigned int nsire)
Definition: LCEmisc.cc:649
bool _harvest_size_varies
Flags.
Definition: LCEmisc.h:112
virtual age_t requiredAgeClass()
Definition: LCEmisc.h:68
int _atGeneration
Definition: LCEmisc.h:220
virtual age_t addAgeClass()
Definition: LCEmisc.h:191
TMatrix _patch2keep
Definition: LCEmisc.h:223
LCE_Cross()
Definition: LCEmisc.cc:379
map< unsigned long, Individual * > _pedigree_pop
Definition: LCEmisc.h:170
virtual ~LCE_Resize()
Definition: LCEmisc.h:229
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
double _extinction_threshold
Patch extinction threshold in % of total size of the patch.
Definition: LCEmisc.h:118
virtual void execute()
Definition: LCEmisc.cc:890
virtual bool setParameters()
Definition: LCEmisc.h:87
virtual age_t removeAgeClass()
Definition: LCEmisc.h:190
string _pedigree_file
Definition: LCEmisc.h:169
unsigned int _nDam
Definition: LCEmisc.h:163
unsigned int rand_lognormal(double mean)
Definition: LCEmisc.h:126
double _harvest_dist_stdev
Standard deviate to use with the Gaussian dist.
Definition: LCEmisc.h:114
unsigned int rand_exp(double mean)
Definition: LCEmisc.h:125
virtual ~LCE_Aging()
Definition: LCEmisc.h:84
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void buildNewPatchArrayNoBackup()
Definition: LCEmisc.cc:1007
static double Gaussian(double sigma)
Definition: Uniform.h:238
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
virtual void loadFileServices(FileServices *loader)
Definition: LCEmisc.h:149
virtual void FHread(string &filename)
Definition: LCEmisc.cc:736
virtual void loadStatServices(StatServices *loader)
Definition: LCEmisc.h:91
TMatrix * _harvest_proportion
Proportion of the patch size to remove.
Definition: LCEmisc.h:108
virtual age_t removeAgeClass()
Definition: LCEmisc.h:251
unsigned int rand_gaussian(double mean)
Definition: LCEmisc.h:124
bool _by_size
Definition: LCEmisc.h:112
virtual LCE_Aging * clone()
Definition: LCEmisc.h:89
virtual void loadStatServices(StatServices *loader)
Definition: LCEmisc.h:65
unsigned int _nSire
Definition: LCEmisc.h:163
virtual bool setParameters()
Definition: LCEmisc.h:61
void regulateAgeClassNoBackup(Patch *patch, age_idx age)
Definition: LCEmisc.cc:1158
virtual age_t addAgeClass()
Definition: LCEmisc.h:252
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
virtual void execute()
Definition: LCEmisc.cc:91
virtual void loadFileServices(FileServices *loader)
Definition: LCEmisc.cc:433
string _harvest_distribution
Name of the distribution to use.
Definition: LCEmisc.h:110
Regulates the patches to their carrying capacity, acts on each age class separately.
Definition: LCEmisc.h:50
vector< unsigned long * > _pedigree
Definition: LCEmisc.h:210
virtual age_t requiredAgeClass()
Definition: LCEmisc.h:94
virtual age_t removeAgeClass()
Definition: LCEmisc.h:66
virtual LifeCycleEvent * clone()
Definition: LCEmisc.h:246
double _harvest_dist_shape
shape variable to use with the gamma dist.
Definition: LCEmisc.h:116
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
A class to read a pedigree from a file.
Definition: LCEmisc.h:199
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
unsigned int rand_uniform(double max)
Definition: LCEmisc.h:122
virtual void loadFileServices(FileServices *loader)
Definition: LCEmisc.h:249
bool _doReplace
Definition: LCEmisc.h:166
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
FHPedigreeReader * _reader
Definition: LCEmisc.h:168
virtual age_t requiredAgeClass()
Definition: LCEmisc.h:253
LCE_Resize()
Definition: LCEmisc.cc:801
virtual bool setParameters()
Definition: LCEmisc.cc:820
virtual ~LCE_Patch_Extinction()
Definition: LCEmisc.h:131
virtual age_t requiredAgeClass()
Definition: LCEmisc.h:192
bool updateParameters()
Definition: LCEmisc.cc:845
void regulate(void(LCE_Resize::*regFuncPtr)(Patch *patch, age_idx age))
Definition: LCEmisc.cc:1126
unsigned int _atGeneration
Definition: LCEmisc.h:165
unsigned int rand_poisson(double mean)
Definition: LCEmisc.h:123
bool _do_fill
Definition: LCEmisc.h:222

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR