Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
metapop.h
Go to the documentation of this file.
1 
28 #ifndef __METAPOP_H
29 #define __METAPOP_H
30 
31 #include <list>
32 #include <deque>
33 #include <map>
34 #include <time.h>
35 #include "types.h"
36 #include "indfactory.h"
37 #include "MPStatHandler.h"
38 #include "binarydataloader.h"
39 #include "MPImanager.h"
40 #include "tmatrix.h"
41 #include "output.h"
42 #include "filehandler.h"
43 
44 class Patch;
45 
46 class LifeCycleEvent;
47 
48 class MPFileHandler;
49 
50 //CLASS METAPOP
51 
77 class Metapop : public StorableComponent, public SimComponent, public IndFactory
78 {
79 
80  friend Metapop *BinaryDataLoader::extractPop(std::string&, unsigned int, SimBuilder*, Metapop*);
81 
82 private:
84 
87 
90 
92  deque< Patch* > _vPatch;
93 
96 
106  unsigned int _source_replicates;
112  unsigned int _source_generation;
114  std::string _source_name;
116  std::string _source_filetype;
118  std::string _source_required_age;
122  vector< string > _source_param_override;
124 
125 
128 
129  //parameters:
131  unsigned int _patchNbr;
133  unsigned int _patchK;
135  unsigned int _patchKfem, _patchKmal;
138 
140  unsigned int _generations;
142  unsigned int _replicates;
143  //counters:
145  unsigned int _currentGeneration;
147  unsigned int _currentReplicate;
148 // unsigned int Current_LC_Rank;
151 
152 public:
153 
154  Metapop();
155  virtual ~Metapop();
158  bool init();
159 
160  virtual bool setParameters ();
164  bool setSourceParameters();
168  void reset();
170  void clear();
171 
172  void setMPImanager(MPImanager *mgr) {_mpimgr = mgr;}
173 
176 
178  void resizePatchArray ();
180  void buildPatchArray();
183  void updatePatchArray();
185  void updatePatchState();
187  void setPatchCapacities();
192  void setPatchCapacities(string param);
198  void setPatchCapacities(sex_t SEX, string param);
203  void setPatchCapacities(string paramfem, string parammal);
205  void loadSourcePopulation ( );
207  void loadPopFromBinarySource ( string &filename );
209  void loadPopFromTraitFile ( string &filename );
211  void setPopulation (unsigned int currentReplicate, unsigned int replicates);
213  void setPopulationFromSource () ;
219  void fillPopulationFromSource(age_idx AGE, sex_t SEX, deque<Individual*>& src_pool);
226  void fillPatchFromSource(sex_t SEX, Patch* src, Patch* patch, age_t AGE);
228 
231  //SimComponent implementation:
232  virtual void loadFileServices ( FileServices* loader );
233 
234  virtual void loadStatServices ( StatServices* loader ) {loader->attach(&_statHandler);}
235 
236  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
237 
238  //StoprableComponent implementation:
239  virtual void store_data ( BinaryStorageBuffer* saver );
240 
241  virtual bool retrieve_data ( BinaryStorageBuffer* reader );
243 
245  void store_trait (int trait_idx, BinaryStorageBuffer* saver);
246 
248  void read_trait (int trait_idx, BinaryStorageBuffer* loader);
249 
250 
253 
255  Patch* getPatch (unsigned int i) {return (i > _vPatch.size() -1 ? 0 : _vPatch[i]);}
256 
258  Patch* getPatchPtr (unsigned int patch){
259  if(!(patch < _vPatch.size()))
260  fatal("Metapop::getPatchPtr()::_vPatch overflow (id=%i nb=%i)\n", patch, _vPatch.size());
261 
262  if (_vPatch[patch] == NULL) fatal("Metapop::getPatchPtr()::NULL ptr\n");
263 
264  return _vPatch[patch];
265  }
266 
267  deque< Patch* >* getPatchArray ( ) {return &_vPatch;}
268  unsigned int getPatchArraySize ( ) {return _vPatch.size();}
269  void getAllIndividuals(age_idx AGE, deque<Individual*>& fem_pool, deque<Individual*>& mal_pool);
270  void setGenerations (unsigned int gen) {_generations = gen;}
271  unsigned int getGenerations ( ) {return _generations;}
272  void setReplicates (unsigned int repl) {_replicates = repl;}
273  unsigned int getReplicates ( ) {return _replicates;}
274  unsigned int getPatchNbr ( ) {return _patchNbr;}
275  unsigned int getPatchKFem ( ) {return _patchKfem;}
276  unsigned int getPatchKMal ( ) {return _patchKmal;}
277  unsigned int getPatchCapacity ( ) {return _patchK;}
278  unsigned int getPatchCapacity (sex_t SEX, unsigned int patch) {return (unsigned int)_patchSizes.get(SEX, patch);}
280  bool isSourceLoad ( ) {return _source_load;}
281  string getSourceName ( ) {return _source_name;}
282  string getSourceFileType ( ) {return _source_filetype;}
284 
285  void setPatchNbr (unsigned int val) {_patchNbr = val;}
286  void setPatchSizes (TMatrix& mat) {_patchSizes.copy(mat);}
287 
288  unsigned int getNumAgeClasses ( ) {return 2;}
290 
293  unsigned int getCurrentReplicate ( ) {return _currentReplicate;}
294  unsigned int getCurrentGeneration ( ) {return _currentGeneration;}
295  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl;}
296  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen;}
298 
301  void setCurrentAge (age_t age) {_currentAge = age;}
304  void setCurrentAge (LifeCycleEvent* LCE) ;
305 
307  bool isAlive ( ) {return size() != 0;}
308 
310  unsigned int size ( ) {return size(ALL);}
311 
316  unsigned int size ( sex_t SEX, age_t AGE );
317 
322  unsigned int size ( sex_t SEX, age_idx IDX );
323 
327  unsigned int size (age_idx IDX);
328  unsigned int size (age_idx IDX, unsigned int deme);
329  unsigned int size (sex_t SEX, age_idx IDX, unsigned int deme);
330 
336  unsigned int size (sex_t SEX, age_t AGE, unsigned int deme);
337 
341  unsigned int size ( age_t AGE )
342  { return size( FEM, AGE ) + size( MAL, AGE );}
343 
348  unsigned int size ( age_t AGE, unsigned int deme )
349  { return size( FEM, AGE, deme ) + size( MAL, AGE, deme );}
350 
356  Individual* get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme);
357 
366  void move (sex_t SEX, age_idx from_age, unsigned int from_deme,
367  age_idx to_age, unsigned int to_deme, unsigned int at);
368 
373  void flush ();
380  void flush (sex_t SEX, age_idx AGE);
386  void flush (age_idx AGE);
392  void flush (age_t AGE);
396  Patch* removePatch (unsigned int i);
400  void deletePatch (unsigned int i);
403  void addPatch (Patch* patch);
405  void addPatch (unsigned int num);
407 
408  void show_up();
409 };
410 //------------------------------------------------------------------------------------------
411 //
412 // CLASS PATCH
413 //
414 //------------------------------------------------------------------------------------------
415 
429 class Patch
430 {
432  unsigned int _ID;
434  unsigned int _K;
436  unsigned int _KFem, _KMal;
440  unsigned int _age;
442  unsigned int _nb_age_class;
444  unsigned int _sizes[2][3];
446  unsigned int _capacities[2][3];
448  deque <Individual*> _containers[2][3];
449 
450  public:
451 //counters:
452  unsigned short nbEmigrant, nbImigrant, nbPhilopat;
454 
455 //at construction, the capacities should be at least 1 to allow a patch to be filled (see add)
456  Patch() : _ID(0), _K(1), _KFem(1), _KMal(1), _isExtinct(0), _age(0), _nb_age_class(3),
458  { for(unsigned int i = 0; i < _nb_age_class; i++) {
459  _sizes[MAL][i] = 0;
460  _sizes[FEM][i] = 0;
461  _capacities[MAL][i] = 0;
462  _capacities[FEM][i] = 0;}
463  }
464 
465  ~Patch();
466 
467  Patch* init (unsigned int nbfem, unsigned int nbmal, unsigned int id);
470  void setID (unsigned int i) {_ID = i;}
471  void set_K (unsigned int k) {_K = k;}
472  void set_KFem (unsigned int k) {_KFem = k;}
473  void set_KMal (unsigned int k) {_KMal = k;}
474  void set_isExtinct (bool status) {_isExtinct = status;}
475  void set_age (unsigned int a) {_age = a;}
479  unsigned int getID () {return _ID;}
480  unsigned int get_K () {return _K;}
481  unsigned int get_K (sex_t SEX) {return (SEX ? _KFem : _KMal);}
482  unsigned int get_KFem () {return _KFem;}
483  unsigned int get_KMal () {return _KMal;}
484  bool get_isExtinct () {return _isExtinct;}
485  unsigned int get_age () {return _age;}
486  bool isEmpty () {return (size(ALL) == 0);}
487  unsigned int getAdultsNumber () {return size(ADLTx);}
488  double getDensity (age_idx age) {return (double)size(age)/_K;}
490 
493 
496  unsigned int size (age_t AGE)
497  { return size(MAL,AGE) + size(FEM,AGE); }
498 
503  unsigned int size (sex_t SEX, age_t AGE)
504  {
505  unsigned int mask = 1, s = 0;
506  for(unsigned int i = 0; i < _nb_age_class; i++) {
507  if( (mask & AGE) != 0) s += _sizes[SEX][i];
508  mask <<= 1;
509  }
510  return s;
511  }
512 
517  unsigned int size (sex_t SEX, age_idx AGE)
518  { return _sizes[SEX][AGE]; }
519 
523  unsigned int size (age_idx AGE)
524  { return _sizes[0][AGE] + _sizes[1][AGE]; }
525 
532  Individual* get (sex_t SEX, age_idx AGE, unsigned int at)
533  { return _containers[SEX][AGE][at]; }
534 
541  void set (sex_t SEX, age_idx AGE, unsigned int at, Individual* ind)
542  { _containers[SEX][AGE][at] = ind; }
543 
549  void add (sex_t SEX, age_idx AGE, Individual* ind)
550  {
551  if( _sizes[SEX][AGE] + 1 > _capacities[SEX][AGE] ) {
552  _containers[SEX][AGE].resize( _capacities[SEX][AGE] + (_K + 1) );
553  _capacities[SEX][AGE] += (_K + 1); //the +1 is here to avoid seg faults when K=0
554  }
555  _containers[SEX][AGE][ _sizes[SEX][AGE]++ ] = ind;
556  }
557 
559  void assign (sex_t SEX, age_idx AGE, size_t n)
560  { _containers[SEX][AGE].assign(n,0);
561  _sizes[SEX][AGE] = 0;
562  _capacities[SEX][AGE] = n;
563  }
564 
572  void resize (sex_t SEX, age_idx AGE, size_t new_size)
573  {
574  if( new_size > _capacities[SEX][AGE] ) {
575  _containers[SEX][AGE].resize( new_size );
576  _capacities[SEX][AGE] = new_size;
577  }
578  _sizes[SEX][AGE] = new_size;
579  }
586  Individual* remove (sex_t SEX, age_idx AGE, unsigned int at)
587  {
588  if(_sizes[SEX][AGE] == 0) {
589  error("Patch::remove:: container already empty!!");
590  return NULL;
591  }
592  unsigned int last = _sizes[SEX][AGE] - 1;
593  Individual* ind = _containers[SEX][AGE][at];
594  _containers[SEX][AGE][at] = _containers[SEX][AGE][ last ];
595  _containers[SEX][AGE][ last ] = 0;
596  _sizes[SEX][AGE]--;
597  return ind;
598  }
599 
609  void move (sex_t SEX, age_idx from, age_idx to, unsigned int at)
610  {
611  add( SEX, to, _containers[SEX][from][at] );
612  remove( SEX, from, at );
613  }
614 
622  void move (sex_t SEX, age_idx from, age_idx to)
623  {
624  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
625  _containers[SEX][to].resize( _sizes[SEX][from] );
626  _capacities[SEX][to] = _sizes[SEX][from];
627  }
628 
629  for(unsigned int i = 0; i < _sizes[SEX][from]; ++i)
630  _containers[SEX][to][i] = _containers[SEX][from][i];
631 // _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].end());
632 
633  _sizes[SEX][to] = _sizes[SEX][from];
634  clear(SEX, from);
635  }
636 
643  void swap_new (sex_t SEX, age_idx from, age_idx to)
644  {
645  deque<Individual*> temp(_containers[SEX][to].begin(), _containers[SEX][to].end());
646  unsigned int to_size = _sizes[SEX][to];
647 
648  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
649  _containers[SEX][to].resize( _sizes[SEX][from] );
650  _capacities[SEX][to] = _sizes[SEX][from];
651  }
652 
653  // copy content of 'from' into 'to', but restrict to the 'size' of 'from' to not copy over the actual number of individuals
654  _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].begin() + _sizes[SEX][from]);
655  _sizes[SEX][to] = _containers[SEX][to].size(); // this should be equal to _sizes[SEX][from]
656 
657  if( _sizes[SEX][to] > _capacities[SEX][from] ) {
658  _capacities[SEX][from] = _sizes[SEX][to];
659  }
660 
661  _containers[SEX][from].assign(temp.begin(), temp.begin()+to_size);
662  _sizes[SEX][from] = _containers[SEX][from].size();
663  }
664 
674  void clear (sex_t SEX, age_idx AGE) { _sizes[SEX][AGE] = 0;}
675  void clear () { for(int i = 0; i < 3; i++) {_sizes[0][i] = 0;_sizes[1][i] = 0;}}
676 
685  void flush (sex_t SEX, age_idx AGE, Metapop* pop)
686  {
687  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
688  pop->recycle(_containers[SEX][AGE][i]);
689  _containers[SEX][AGE][i] = 0;
690  }
691  _sizes[SEX][AGE] = 0;
692  }
693 
694  void flush (age_idx AGE, Metapop* pop)
695  { flush(FEM, AGE, pop); flush(MAL, AGE, pop); }
696 
702  void flush (age_t AGE, Metapop* pop)
703  {
704  unsigned int mask = 1;
705 
706  for(unsigned int i = 0; i < _nb_age_class; i++) {
707  if( (mask & AGE) != 0) {
708  flush(MAL, age_idx(i), pop);
709  flush(FEM, age_idx(i), pop);
710  }
711  mask <<= 1;
712  }
713  }
714 
716  void flush (Metapop* pop)
717  {
718  for(unsigned int i = 0; i < _nb_age_class; i++) {
719  flush(MAL, age_idx(i), pop);
720  flush(FEM, age_idx(i), pop);
721  }
722  }
723 
724  void getCopy (sex_t SEX, age_idx AGE, deque< Individual* >& to)
725  {
726  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
727  to.push_back(_containers[SEX][AGE][i]);
728  }
729  }
730 
731  void copy2patch (sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch* to_patch)
732  {
733  for (unsigned int i = 0; i < _sizes[from_sex][from_age]; ++i)
734  to_patch->add(to_sex, to_age, _containers[from_sex][from_age][i] );
735  }
736 
737  void copy2patch (sex_t SEX, age_idx AGE, Patch* patch)
738  {
739  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i)
740  patch->add(SEX, AGE, get(SEX, AGE, i) );
741  }
742 
743  void copy2patch (age_idx AGE, Patch* patch)
744  {
745  copy2patch(FEM, AGE, patch);
746  copy2patch(MAL, AGE, patch);
747  }
748 
749  void copy2patch (Patch* patch)
750  {
751  for (unsigned int i = 0; i < _nb_age_class; ++i){
752  copy2patch(FEM, static_cast<age_idx> (i), patch);
753  copy2patch(MAL, static_cast<age_idx> (i), patch);
754  }
755  }
757 
758  void reset_counters();
759  void reset_containers();
761  void setNewGeneration(age_t AGE, Metapop* pop);
763  void setNewGeneration(age_idx AGE, Metapop* pop);
764 
765  void show_up();
766 
767 };
768 
769 //------------------------------------------------------------------------------------------
770 //
771 // MPFileHandler
772 //
773 //------------------------------------------------------------------------------------------
774 class MPFileHandler : public FileHandler {
775 
777 
778 public:
780 
781  virtual ~MPFileHandler() {}
782 
783  void setOption(int size){_patch_sample_size = size;}
784 
785  virtual void FHwrite();
786  virtual void FHread (string& filename){}
787 
788  void createAndPrintSample (age_idx AGE, Patch* patch, ofstream& FH);
789  void printNoSample (sex_t SEX, age_idx AGE, Patch* patch, ofstream& FH);
790 };
791 
792 //------------------------------------------------------------------------------------------
793 //
794 // Metapop inline functions
795 //
796 //------------------------------------------------------------------------------------------
797 inline unsigned int Metapop::size (age_idx IDX)
798 {
799  return size(FEM, IDX) + size(MAL, IDX);
800 }
801 
802 inline unsigned int Metapop::size (age_idx IDX, unsigned int deme)
803 {
804  return size(FEM, IDX, deme) + size(MAL, IDX, deme);
805 }
806 
807 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX )
808 {
809  unsigned int s = 0;
810  for(unsigned int i = 0; i < _patchNbr; i++)
811  s += _vPatch[i]->size(SEX, IDX);
812  return s;
813 }
814 
815 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX, unsigned int deme)
816 {
817  return _vPatch[deme]->size(SEX, IDX);
818 }
819 
820 inline unsigned int Metapop::size ( sex_t SEX, age_t AGE )
821 {
822  unsigned int s = 0;
823  for(unsigned int i = 0; i < _vPatch.size(); i++)
824  s += _vPatch[i]->size(SEX, AGE);
825  return s;
826 }
827 
828 inline unsigned int Metapop::size (sex_t SEX, age_t AGE, unsigned int deme)
829 {
830  Patch* patch = getPatch(deme);
831  return (patch!=0? patch->size(SEX, AGE) : 0);
832 }
833 
834 inline Individual* Metapop::get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
835 { return getPatchPtr(deme)->get(SEX, AGE, at); }
836 
837 inline void Metapop::move (sex_t SEX, age_idx from_age, unsigned int from_deme,
838  age_idx to_age, unsigned int to_deme, unsigned int at)
839 {//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
840  _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
841  //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
842  _vPatch[from_deme]->remove(SEX, from_age, at);
843  //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
844  // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
845 }
846 
847 inline void Metapop::flush()
848 {
849  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(this);
850 }
851 
852 inline void Metapop::flush(sex_t SEX, age_idx AGE)
853 {
854  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
855 }
856 
857 inline void Metapop::flush(age_idx AGE)
858 {
859  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
860 }
861 
862 inline void Metapop::flush(age_t AGE)
863 {
864  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
865 }
866 
867 inline Patch* Metapop::removePatch (unsigned int i)
868 {
869  Patch* patch = getPatchPtr(i);
870  _vPatch.erase(_vPatch.begin() + i);
871  return patch;
872 }
873 
874 inline void Metapop::deletePatch (unsigned int i)
875 {
876  delete _vPatch[i];
877  for (unsigned int k = i; k < _vPatch.size() -1; k++) {
878  _vPatch[k] = _vPatch[k + 1];
879  _vPatch[k]->setID(k);
880  }
881  _vPatch.pop_back();
882 }
883 
884 inline void Metapop::addPatch (Patch* patch)
885 {
886  _vPatch.push_back(patch);
887 }
888 
889 inline void Metapop::addPatch (unsigned int num)
890 {
891  for (unsigned int i = 0; i < num; i++)
892  _vPatch.push_back(new Patch());
893 }
894 
895 
896 
897 
898 #endif
A class to load a whole population from a binary data file.
Definition: binarydataloader.h:39
Metapop * extractPop(string &filename, unsigned int generation, SimBuilder *sim, Metapop *popPtr)
Definition: binarydataloader.cc:161
A class to store any kind of data in a char buffer before unloading it in a binary data file.
Definition: binarystoragebuffer.h:42
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:51
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:50
Factory of Individual, stores the individual prototype and the trait prototypes, manages the individu...
Definition: indfactory.h:41
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:60
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:71
Definition: metapop.h:774
virtual ~MPFileHandler()
Definition: metapop.h:781
virtual void FHwrite()
Definition: metapop.cc:1258
void setOption(int size)
Definition: metapop.h:783
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1323
MPFileHandler()
Definition: metapop.h:779
virtual void FHread(string &filename)
Definition: metapop.h:786
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1307
int _patch_sample_size
Definition: metapop.h:776
Definition: MPImanager.h:46
A StatHandler for the Metapop SimComponent.
Definition: MPStatHandler.h:38
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:78
unsigned int getSourceReplDigits()
Definition: metapop.h:283
unsigned int getPatchCapacity()
Definition: metapop.h:277
MPStatHandler _statHandler
The stat handler for the population stats.
Definition: metapop.h:86
void loadPopFromBinarySource(string &filename)
Loads the population from a binary data file when setting the first generation of a replicate.
Definition: metapop.cc:1021
void setReplicates(unsigned int repl)
Definition: metapop.h:272
unsigned int getPatchCapacity(sex_t SEX, unsigned int patch)
Definition: metapop.h:278
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:101
MPFileHandler * _writer
The file handler used to save pedigree info.
Definition: metapop.h:89
unsigned int _patchKmal
Definition: metapop.h:135
bool isSourceLoad()
Definition: metapop.h:280
void buildPatchArray()
Builds the new population from parameter values.
Definition: metapop.cc:306
void setPatchCapacities()
Sets the deme capacity matrix from parameter values.
Definition: metapop.cc:355
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:106
void store_trait(int trait_idx, BinaryStorageBuffer *saver)
Iterates through the individuals containers to store the trait data to a binary file.
Definition: metapop.cc:531
void setPopulationFromSource()
Definition: metapop.cc:887
void loadPopFromTraitFile(string &filename)
Loads a population from a trait's data file (text file).
Definition: metapop.cc:1136
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:135
unsigned int size(age_t AGE)
Simplified interface to get the size of both sexes of the appropriate age class(es) in the whole popu...
Definition: metapop.h:341
unsigned int getPatchKMal()
Definition: metapop.h:276
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:194
unsigned int getPatchKFem()
Definition: metapop.h:275
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:296
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:342
void setPopulationFromSourceInPreserveMode()
Definition: metapop.cc:811
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:120
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:131
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:258
void read_trait(int trait_idx, BinaryStorageBuffer *loader)
Iterates through the individuals containers to retrieve the trait data from a binary file.
Definition: metapop.cc:682
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:884
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:295
unsigned int getNumAgeClasses()
Definition: metapop.h:288
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: metapop.h:236
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches),...
Definition: metapop.cc:95
virtual void loadFileServices(FileServices *loader)
Definition: metapop.cc:266
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:133
bool _source_load
Flage to specify that the population should be built from the binary loaded source population.
Definition: metapop.h:103
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:310
void setGenerations(unsigned int gen)
Definition: metapop.h:270
unsigned int getGenerations()
Definition: metapop.h:271
Patch * removePatch(unsigned int i)
Removes a patch from the patch array and returns it pointer.
Definition: metapop.h:867
unsigned int getPatchArraySize()
Definition: metapop.h:268
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:116
void deletePatch(unsigned int i)
Removes a patch from the patch array and deletes it and its content.
Definition: metapop.h:874
unsigned int getCurrentReplicate()
Definition: metapop.h:293
void setMPImanager(MPImanager *mgr)
Definition: metapop.h:172
unsigned int getPatchNbr()
Definition: metapop.h:274
virtual void loadStatServices(StatServices *loader)
Definition: metapop.h:234
string getSourceFileType()
Definition: metapop.h:282
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:307
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:137
Metapop()
Definition: metapop.cc:53
string getSourceName()
Definition: metapop.h:281
std::string _source_required_age
The age class to fill with the source population.
Definition: metapop.h:118
TMatrix * getPatchCapacities()
Definition: metapop.h:279
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:127
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:92
void setPatchNbr(unsigned int val)
Definition: metapop.h:285
deque< Patch * > * getPatchArray()
Definition: metapop.h:267
void loadSourcePopulation()
Loads a population from a soure population.
Definition: metapop.cc:967
virtual ~Metapop()
Definition: metapop.cc:85
vector< string > _source_param_override
List of parameters whose values in the source should override local values in the loading pop.
Definition: metapop.h:122
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1190
bool updatePopulationParameters()
Called during simulation to change the population's parameters (temporal argument).
Definition: metapop.cc:254
age_t getCurrentAge()
Definition: metapop.h:297
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc:319
MPImanager * _mpimgr
Definition: metapop.h:83
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:142
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:108
void setPopulation(unsigned int currentReplicate, unsigned int replicates)
Sets the population for the first generation of each replicates.
Definition: metapop.cc:706
void reset()
Called to empty the patches, individuals are move to the garbage collector.
Definition: metapop.cc:1178
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:147
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:255
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:150
unsigned int getCurrentGeneration()
Definition: metapop.h:294
virtual void store_data(BinaryStorageBuffer *saver)
Definition: metapop.cc:451
BinaryDataLoader _loader
A BinaryDataLoader to load a population from a binary data file.
Definition: metapop.h:97
void fillPatchFromSource(sex_t SEX, Patch *src, Patch *patch, age_t AGE)
Fills a patch from a source patch loaded from a binary file, used when setting the population in pres...
Definition: metapop.cc:868
void setPatchSizes(TMatrix &mat)
Definition: metapop.h:286
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:112
unsigned int getReplicates()
Definition: metapop.h:273
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:110
virtual bool setParameters()
Definition: metapop.cc:113
void show_up()
Definition: metapop.cc:1240
unsigned int size(age_t AGE, unsigned int deme)
Simplified interface to get the size of both sexes of the appropriate age class(es) in one patch.
Definition: metapop.h:348
bool setSourceParameters()
Setter for source population parameters.
Definition: metapop.cc:122
unsigned int _generations
Number of generations to iterate.
Definition: metapop.h:140
std::string _source_name
The base filename of source population files.
Definition: metapop.h:114
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:301
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:332
void move(sex_t SEX, age_idx from_age, unsigned int from_deme, age_idx to_age, unsigned int to_deme, unsigned int at)
Moves an individual from a deme to an other one, both demes sizes are modified.
Definition: metapop.h:837
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: metapop.h:145
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:834
void fillPopulationFromSource(age_idx AGE, sex_t SEX, deque< Individual * > &src_pool)
Fills the population of the first generation of each replicates with individuals from a population so...
Definition: metapop.cc:934
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:847
void getAllIndividuals(age_idx AGE, deque< Individual * > &fem_pool, deque< Individual * > &mal_pool)
Definition: metapop.cc:1222
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: metapop.cc:553
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
Patch * init(unsigned int nbfem, unsigned int nbmal, unsigned int id)
Definition: patch.cc:36
void setID(unsigned int i)
Definition: metapop.h:470
double getDensity(age_idx age)
Definition: metapop.h:488
unsigned int get_K()
Definition: metapop.h:480
Individual * remove(sex_t SEX, age_idx AGE, unsigned int at)
Removes the individual sitting at the given index in the appropriate container.
Definition: metapop.h:586
void getCopy(sex_t SEX, age_idx AGE, deque< Individual * > &to)
Definition: metapop.h:724
unsigned int _KMal
Definition: metapop.h:436
void show_up()
Definition: patch.cc:132
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 _sizes[2][3]
Containers size counters, sex X age.
Definition: metapop.h:444
void set_isExtinct(bool status)
Definition: metapop.h:474
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 add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it.
Definition: metapop.h:549
unsigned short nbEmigrant
Definition: metapop.h:452
void assign(sex_t SEX, age_idx AGE, size_t n)
Assigns a new container of given size for the sex and age class passed, sets all values to NULL.
Definition: metapop.h:559
unsigned int _age
age since last extinction.
Definition: metapop.h:440
void clear()
Definition: metapop.h:675
unsigned int _capacities[2][3]
Total size of the containers, amount of allocated memory.
Definition: metapop.h:446
void setNewGeneration(age_t AGE, Metapop *pop)
Fills the patch containers corresponding to the age flags passed, for both sexes.
Definition: patch.cc:78
Patch()
Definition: metapop.h:456
void flush(age_t AGE, Metapop *pop)
Removes all individual pointers of the appropriate sex and age class and flush them into the recyclin...
Definition: metapop.h:702
unsigned int size(sex_t SEX, age_idx AGE)
Returns the size of the container for the appropriate sex and age class.
Definition: metapop.h:517
void move(sex_t SEX, age_idx from, age_idx to, unsigned int at)
Moves an individual from an age class to an other one.
Definition: metapop.h:609
void set_KMal(unsigned int k)
Definition: metapop.h:473
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
void flush(age_idx AGE, Metapop *pop)
Definition: metapop.h:694
unsigned int size(sex_t SEX, age_t AGE)
Returns the size of the container for the appropriate sex and age classes present in the age flag.
Definition: metapop.h:503
unsigned int getID()
Definition: metapop.h:479
void set_age(unsigned int a)
Definition: metapop.h:475
void reset_containers()
Definition: patch.cc:64
unsigned short nbPhilopat
Definition: metapop.h:452
void set(sex_t SEX, age_idx AGE, unsigned int at, Individual *ind)
Modifies the appropriate container with value of the pointer given.
Definition: metapop.h:541
deque< Individual * > _containers[2][3]
Individuals containers, sex X age.
Definition: metapop.h:448
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:731
~Patch()
Definition: patch.cc:118
void move(sex_t SEX, age_idx from, age_idx to)
Copies all elements in the 'from' age-class container to the 'to' age-class container of the same sex...
Definition: metapop.h:622
void set_KFem(unsigned int k)
Definition: metapop.h:472
unsigned int _KFem
Sex specific carrying capacity.
Definition: metapop.h:436
void resize(sex_t SEX, age_idx AGE, size_t new_size)
Reserves a certain range of values that are assigned to 0 in a given container.
Definition: metapop.h:572
void copy2patch(Patch *patch)
Definition: metapop.h:749
void set_K(unsigned int k)
Definition: metapop.h:471
void copy2patch(age_idx AGE, Patch *patch)
Definition: metapop.h:743
unsigned int get_K(sex_t SEX)
Definition: metapop.h:481
unsigned int _nb_age_class
Number of age classes present.
Definition: metapop.h:442
bool _isExtinct
Extinction flag.
Definition: metapop.h:438
unsigned int get_KFem()
Definition: metapop.h:482
unsigned int get_KMal()
Definition: metapop.h:483
void reset_counters()
Definition: patch.cc:54
unsigned short nbImigrant
Definition: metapop.h:452
void copy2patch(sex_t SEX, age_idx AGE, Patch *patch)
Definition: metapop.h:737
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:674
void swap_new(sex_t SEX, age_idx from, age_idx to)
Swaps elements between two containers, 'from' age-class container and the 'to' age-class container of...
Definition: metapop.h:643
unsigned int _ID
Patch ID is equal to its position in the metapop patch array.
Definition: metapop.h:432
unsigned int size(age_idx AGE)
Returns the size of the container for the appropriate age class for both sexes.
Definition: metapop.h:523
short nbKolonisers
Definition: metapop.h:453
unsigned int get_age()
Definition: metapop.h:485
bool get_isExtinct()
Definition: metapop.h:484
bool isEmpty()
Definition: metapop.h:486
unsigned int _K
Carrying capacity for males and females.
Definition: metapop.h:434
unsigned int getAdultsNumber()
Definition: metapop.h:487
void flush(Metapop *pop)
Removes all individual pointers of all sex and age classes and flush them into the recycling pool.
Definition: metapop.h:716
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:166
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
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:175
Provides an interface to binary data saving and uploading.
Definition: simcomponent.h:160
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:48
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:76
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:191
void fatal(const char *str,...)
Definition: output.cc:98
int error(const char *str,...)
Definition: output.cc:77
Nemo2.
Nemo2.
Nemo2.
#define ALL
All ages age class flag.
Definition: types.h:54
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
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:39
@ ADLTx
Definition: types.h:40

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR