Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
metapop.h
Go to the documentation of this file.
1 
29 #ifndef __METAPOP_H
30 #define __METAPOP_H
31 
32 #include <list>
33 #include <deque>
34 #include <map>
35 #include <time.h>
36 #include "types.h"
37 #include "indfactory.h"
38 #include "MPStatHandler.h"
39 #include "binarydataloader.h"
40 #include "MPImanager.h"
41 #include "tmatrix.h"
42 #include "output.h"
43 #include "filehandler.h"
44 
45 class Patch;
46 
47 class LifeCycleEvent;
48 
49 class MPFileHandler;
50 
51 //CLASS METAPOP
52 
78 class Metapop : public StorableComponent, public SimComponent, public IndFactory
79 {
80 
81  friend Metapop *BinaryDataLoader::extractPop(std::string&, unsigned int, SimBuilder*, Metapop*);
82 
83 private:
85 
88 
91 
93  deque< Patch* > _vPatch;
94 
97 
107  unsigned int _source_replicates;
113  unsigned int _source_generation;
115  std::string _source_name;
117  std::string _source_filetype;
119  std::string _source_required_age;
123  vector< string > _source_param_override;
125 
126 
129 
130  //parameters:
132  unsigned int _patchNbr;
134  unsigned int _patchK;
136  unsigned int _patchKfem, _patchKmal;
139 
141  unsigned int _generations;
143  unsigned int _replicates;
144  //counters:
146  unsigned int _currentGeneration;
148  unsigned int _currentReplicate;
149 // unsigned int Current_LC_Rank;
152 
153 public:
154 
155  Metapop();
156  virtual ~Metapop();
159  bool init();
160 
161  virtual bool setParameters ();
165  bool setSourceParameters();
169  void reset();
171  void clear();
172 
173  void setMPImanager(MPImanager *mgr) {_mpimgr = mgr;}
174 
177 
179  void resizePatchArray ();
181  void buildPatchArray();
184  void updatePatchArray();
186  void updatePatchState();
188  void setPatchCapacities();
193  void setPatchCapacities(string param);
199  void setPatchCapacities(sex_t SEX, string param);
204  void setPatchCapacities(string paramfem, string parammal);
206  void loadSourcePopulation ( );
208  void loadPopFromBinarySource ( string &filename );
210  void loadPopFromTraitFile ( string &filename );
212  void setPopulation (unsigned int currentReplicate, unsigned int replicates);
214  void setPopulationFromSource () ;
220  void fillPopulationFromSource(age_idx AGE, sex_t SEX, deque<Individual*>& src_pool);
227  void fillPatchFromSource(sex_t SEX, Patch* src, Patch* patch, age_t AGE);
229 
232  //SimComponent implementation:
233  virtual void loadFileServices ( FileServices* loader );
234 
235  virtual void loadStatServices ( StatServices* loader ) {loader->attach(&_statHandler);}
236 
237  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
238 
239  //StoprableComponent implementation:
240  virtual void store_data ( BinaryStorageBuffer* saver );
241 
242  virtual bool retrieve_data ( BinaryStorageBuffer* reader );
244 
246  void store_trait (int trait_idx, BinaryStorageBuffer* saver);
247 
249  void read_trait (int trait_idx, BinaryStorageBuffer* loader);
250 
251 
254 
256  Patch* getPatch (unsigned int i) {return (i > _vPatch.size() -1 ? 0 : _vPatch[i]);}
257 
259  Patch* getPatchPtr (unsigned int patch){
260  if(!(patch < _vPatch.size()))
261  fatal("Metapop::getPatchPtr()::_vPatch overflow (id=%i nb=%i)\n", patch, _vPatch.size());
262 
263  if (_vPatch[patch] == NULL) fatal("Metapop::getPatchPtr()::NULL ptr\n");
264 
265  return _vPatch[patch];
266  }
267 
268  deque< Patch* >* getPatchArray ( ) {return &_vPatch;}
269  unsigned int getPatchArraySize ( ) {return _vPatch.size();}
270  void getAllIndividuals(age_idx AGE, deque<Individual*>& fem_pool, deque<Individual*>& mal_pool);
271  void setGenerations (unsigned int gen) {_generations = gen;}
272  unsigned int getGenerations ( ) {return _generations;}
273  void setReplicates (unsigned int repl) {_replicates = repl;}
274  unsigned int getReplicates ( ) {return _replicates;}
275  unsigned int getPatchNbr ( ) {return _patchNbr;}
276  unsigned int getPatchKFem ( ) {return _patchKfem;}
277  unsigned int getPatchKMal ( ) {return _patchKmal;}
278  unsigned int getPatchCapacity ( ) {return _patchK;}
279  unsigned int getPatchCapacity (sex_t SEX, unsigned int patch) {return (unsigned int)_patchSizes.get(SEX, patch);}
281  bool isSourceLoad ( ) {return _source_load;}
282  string getSourceName ( ) {return _source_name;}
283  string getSourceFileType ( ) {return _source_filetype;}
285 
286  void setPatchNbr (unsigned int val) {_patchNbr = val;}
287  void setPatchSizes (TMatrix& mat) {_patchSizes.copy(mat);}
288 
289  unsigned int getNumAgeClasses ( ) {return 2;}
291 
294  unsigned int getCurrentReplicate ( ) {return _currentReplicate;}
295  unsigned int getCurrentGeneration ( ) {return _currentGeneration;}
296  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl;}
297  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen;}
299 
302  void setCurrentAge (age_t age) {_currentAge = age;}
305  void setCurrentAge (LifeCycleEvent* LCE) ;
306 
308  bool isAlive ( ) {return size() != 0;}
309 
311  unsigned int size ( ) {return size(ALL);}
312 
317  unsigned int size ( sex_t SEX, age_t AGE );
318 
323  unsigned int size ( sex_t SEX, age_idx IDX );
324 
328  unsigned int size (age_idx IDX);
329  unsigned int size (age_idx IDX, unsigned int deme);
330  unsigned int size (sex_t SEX, age_idx IDX, unsigned int deme);
331 
337  unsigned int size (sex_t SEX, age_t AGE, unsigned int deme);
338 
342  unsigned int size ( age_t AGE )
343  { return size( FEM, AGE ) + size( MAL, AGE );}
344 
349  unsigned int size ( age_t AGE, unsigned int deme )
350  { return size( FEM, AGE, deme ) + size( MAL, AGE, deme );}
351 
357  Individual* get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme);
358 
367  void move (sex_t SEX, age_idx from_age, unsigned int from_deme,
368  age_idx to_age, unsigned int to_deme, unsigned int at);
369 
374  void flush ();
381  void flush (sex_t SEX, age_idx AGE);
387  void flush (age_idx AGE);
393  void flush (age_t AGE);
397  Patch* removePatch (unsigned int i);
401  void deletePatch (unsigned int i);
404  void addPatch (Patch* patch);
406  void addPatch (unsigned int num);
408 
409  void show_up();
410 };
411 //------------------------------------------------------------------------------------------
412 //
413 // CLASS PATCH
414 //
415 //------------------------------------------------------------------------------------------
416 
430 class Patch
431 {
433  unsigned int _ID;
435  unsigned int _K;
437  unsigned int _KFem, _KMal;
441  unsigned int _age;
443  unsigned int _nb_age_class;
445  unsigned int _sizes[2][3];
447  unsigned int _capacities[2][3];
449  deque <Individual*> _containers[2][3];
450 
451  public:
452 //counters:
453  unsigned short nbEmigrant, nbImigrant, nbPhilopat;
455 
456 //at construction, the capacities should be at least 1 to allow a patch to be filled (see add)
457  Patch() : _ID(0), _K(1), _KFem(1), _KMal(1), _isExtinct(0), _age(0), _nb_age_class(3),
459  { for(unsigned int i = 0; i < _nb_age_class; i++) {
460  _sizes[MAL][i] = 0;
461  _sizes[FEM][i] = 0;
462  _capacities[MAL][i] = 0;
463  _capacities[FEM][i] = 0;}
464  }
465 
466  ~Patch();
467 
468  Patch* init (unsigned int nbfem, unsigned int nbmal, unsigned int id);
471  void setID (unsigned int i) {_ID = i;}
472  void set_K (unsigned int k) {_K = k;}
473  void set_KFem (unsigned int k) {_KFem = k;}
474  void set_KMal (unsigned int k) {_KMal = k;}
475  void set_isExtinct (bool status) {_isExtinct = status;}
476  void set_age (unsigned int a) {_age = a;}
480  unsigned int getID () {return _ID;}
481  unsigned int get_K () {return _K;}
482  unsigned int get_K (sex_t SEX) {return (SEX ? _KFem : _KMal);}
483  unsigned int get_KFem () {return _KFem;}
484  unsigned int get_KMal () {return _KMal;}
485  bool get_isExtinct () {return _isExtinct;}
486  unsigned int get_age () {return _age;}
487  bool isEmpty () {return (size(ALL) == 0);}
488  unsigned int getAdultsNumber () {return size(ADLTx);}
489  double getDensity (age_idx age) {return (double)size(age)/_K;}
491 
494 
497  unsigned int size (age_t AGE)
498  { return size(MAL,AGE) + size(FEM,AGE); }
499 
504  unsigned int size (sex_t SEX, age_t AGE)
505  {
506  unsigned int mask = 1, s = 0;
507  for(unsigned int i = 0; i < _nb_age_class; i++) {
508  if( (mask & AGE) != 0) s += _sizes[SEX][i];
509  mask <<= 1;
510  }
511  return s;
512  }
513 
518  unsigned int size (sex_t SEX, age_idx AGE)
519  { return _sizes[SEX][AGE]; }
520 
524  unsigned int size (age_idx AGE)
525  { return _sizes[0][AGE] + _sizes[1][AGE]; }
526 
533  Individual* get (sex_t SEX, age_idx AGE, unsigned int at)
534  { return _containers[SEX][AGE][at]; }
535 
542  void set (sex_t SEX, age_idx AGE, unsigned int at, Individual* ind)
543  { _containers[SEX][AGE][at] = ind; }
544 
550  void add (sex_t SEX, age_idx AGE, Individual* ind)
551  {
552  if( _sizes[SEX][AGE] + 1 > _capacities[SEX][AGE] ) {
553  _containers[SEX][AGE].resize( _capacities[SEX][AGE] + (_K + 1) );
554  _capacities[SEX][AGE] += (_K + 1); //the +1 is here to avoid seg faults when K=0
555  }
556  _containers[SEX][AGE][ _sizes[SEX][AGE]++ ] = ind;
557  }
558 
560  void assign (sex_t SEX, age_idx AGE, size_t n)
561  { _containers[SEX][AGE].assign(n,0);
562  _sizes[SEX][AGE] = 0;
563  _capacities[SEX][AGE] = n;
564  }
565 
573  void resize (sex_t SEX, age_idx AGE, size_t new_size)
574  {
575  if( new_size > _capacities[SEX][AGE] ) {
576  _containers[SEX][AGE].resize( new_size );
577  _capacities[SEX][AGE] = new_size;
578  }
579  _sizes[SEX][AGE] = new_size;
580  }
587  Individual* remove (sex_t SEX, age_idx AGE, unsigned int at)
588  {
589  if(_sizes[SEX][AGE] == 0) {
590  error("Patch::remove:: container already empty!!");
591  return NULL;
592  }
593  unsigned int last = _sizes[SEX][AGE] - 1;
594  Individual* ind = _containers[SEX][AGE][at];
595  _containers[SEX][AGE][at] = _containers[SEX][AGE][ last ];
596  _containers[SEX][AGE][ last ] = 0;
597  _sizes[SEX][AGE]--;
598  return ind;
599  }
600 
610  void move (sex_t SEX, age_idx from, age_idx to, unsigned int at)
611  {
612  add( SEX, to, _containers[SEX][from][at] );
613  remove( SEX, from, at );
614  }
615 
623  void move (sex_t SEX, age_idx from, age_idx to)
624  {
625  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
626  _containers[SEX][to].resize( _sizes[SEX][from] );
627  _capacities[SEX][to] = _sizes[SEX][from];
628  }
629 
630  for(unsigned int i = 0; i < _sizes[SEX][from]; ++i)
631  _containers[SEX][to][i] = _containers[SEX][from][i];
632 // _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].end());
633 
634  _sizes[SEX][to] = _sizes[SEX][from];
635  clear(SEX, from);
636  }
637 
644  void swap_new (sex_t SEX, age_idx from, age_idx to)
645  {
646  deque<Individual*> temp(_containers[SEX][to].begin(), _containers[SEX][to].end());
647  unsigned int to_size = _sizes[SEX][to];
648 
649  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
650  _containers[SEX][to].resize( _sizes[SEX][from] );
651  _capacities[SEX][to] = _sizes[SEX][from];
652  }
653 
654  // copy content of 'from' into 'to', but restrict to the 'size' of 'from' to not copy over the actual number of individuals
655  _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].begin() + _sizes[SEX][from]);
656  _sizes[SEX][to] = _containers[SEX][to].size(); // this should be equal to _sizes[SEX][from]
657 
658  if( _sizes[SEX][to] > _capacities[SEX][from] ) {
659  _capacities[SEX][from] = _sizes[SEX][to];
660  }
661 
662  _containers[SEX][from].assign(temp.begin(), temp.begin()+to_size);
663  _sizes[SEX][from] = _containers[SEX][from].size();
664  }
665 
675  void clear (sex_t SEX, age_idx AGE) { _sizes[SEX][AGE] = 0;}
676  void clear () { for(int i = 0; i < 3; i++) {_sizes[0][i] = 0;_sizes[1][i] = 0;}}
677 
686  void flush (sex_t SEX, age_idx AGE, Metapop* pop)
687  {
688  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
689  pop->recycle(_containers[SEX][AGE][i]);
690  _containers[SEX][AGE][i] = 0;
691  }
692  _sizes[SEX][AGE] = 0;
693  }
694 
695  void flush (age_idx AGE, Metapop* pop)
696  { flush(FEM, AGE, pop); flush(MAL, AGE, pop); }
697 
703  void flush (age_t AGE, Metapop* pop)
704  {
705  unsigned int mask = 1;
706 
707  for(unsigned int i = 0; i < _nb_age_class; i++) {
708  if( (mask & AGE) != 0) {
709  flush(MAL, age_idx(i), pop);
710  flush(FEM, age_idx(i), pop);
711  }
712  mask <<= 1;
713  }
714  }
715 
717  void flush (Metapop* pop)
718  {
719  for(unsigned int i = 0; i < _nb_age_class; i++) {
720  flush(MAL, age_idx(i), pop);
721  flush(FEM, age_idx(i), pop);
722  }
723  }
724 
725  void getCopy (sex_t SEX, age_idx AGE, deque< Individual* >& to)
726  {
727  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
728  to.push_back(_containers[SEX][AGE][i]);
729  }
730  }
731 
732  void copy2patch (sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch* to_patch)
733  {
734  for (unsigned int i = 0; i < _sizes[from_sex][from_age]; ++i)
735  to_patch->add(to_sex, to_age, _containers[from_sex][from_age][i] );
736  }
737 
738  void copy2patch (sex_t SEX, age_idx AGE, Patch* patch)
739  {
740  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i)
741  patch->add(SEX, AGE, get(SEX, AGE, i) );
742  }
743 
744  void copy2patch (age_idx AGE, Patch* patch)
745  {
746  copy2patch(FEM, AGE, patch);
747  copy2patch(MAL, AGE, patch);
748  }
749 
750  void copy2patch (Patch* patch)
751  {
752  for (unsigned int i = 0; i < _nb_age_class; ++i){
753  copy2patch(FEM, static_cast<age_idx> (i), patch);
754  copy2patch(MAL, static_cast<age_idx> (i), patch);
755  }
756  }
758 
759  void reset_counters();
760  void reset_containers();
762  void setNewGeneration(age_t AGE, Metapop* pop);
764  void setNewGeneration(age_idx AGE, Metapop* pop);
765 
766  void show_up();
767 
768 };
769 
770 //------------------------------------------------------------------------------------------
771 //
772 // MPFileHandler
773 //
774 //------------------------------------------------------------------------------------------
775 class MPFileHandler : public FileHandler {
776 
778 
779 public:
781 
782  virtual ~MPFileHandler() {}
783 
784  void setOption(int size){_patch_sample_size = size;}
785 
786  virtual void FHwrite();
787  virtual void FHread (string& filename){}
788 
789  void createAndPrintSample (age_idx AGE, Patch* patch, ofstream& FH);
790  void printNoSample (sex_t SEX, age_idx AGE, Patch* patch, ofstream& FH);
791 };
792 
793 //------------------------------------------------------------------------------------------
794 //
795 // Metapop inline functions
796 //
797 //------------------------------------------------------------------------------------------
798 inline unsigned int Metapop::size (age_idx IDX)
799 {
800  return size(FEM, IDX) + size(MAL, IDX);
801 }
802 
803 inline unsigned int Metapop::size (age_idx IDX, unsigned int deme)
804 {
805  return size(FEM, IDX, deme) + size(MAL, IDX, deme);
806 }
807 
808 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX )
809 {
810  unsigned int s = 0;
811  for(unsigned int i = 0; i < _patchNbr; i++)
812  s += _vPatch[i]->size(SEX, IDX);
813  return s;
814 }
815 
816 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX, unsigned int deme)
817 {
818  return _vPatch[deme]->size(SEX, IDX);
819 }
820 
821 inline unsigned int Metapop::size ( sex_t SEX, age_t AGE )
822 {
823  unsigned int s = 0;
824  for(unsigned int i = 0; i < _vPatch.size(); i++)
825  s += _vPatch[i]->size(SEX, AGE);
826  return s;
827 }
828 
829 inline unsigned int Metapop::size (sex_t SEX, age_t AGE, unsigned int deme)
830 {
831  Patch* patch = getPatch(deme);
832  return (patch!=0? patch->size(SEX, AGE) : 0);
833 }
834 
835 inline Individual* Metapop::get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
836 { return getPatchPtr(deme)->get(SEX, AGE, at); }
837 
838 inline void Metapop::move (sex_t SEX, age_idx from_age, unsigned int from_deme,
839  age_idx to_age, unsigned int to_deme, unsigned int at)
840 {//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
841  _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
842  //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
843  _vPatch[from_deme]->remove(SEX, from_age, at);
844  //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
845  // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
846 }
847 
848 inline void Metapop::flush()
849 {
850  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(this);
851 }
852 
853 inline void Metapop::flush(sex_t SEX, age_idx AGE)
854 {
855  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
856 }
857 
858 inline void Metapop::flush(age_idx AGE)
859 {
860  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
861 }
862 
863 inline void Metapop::flush(age_t AGE)
864 {
865  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
866 }
867 
868 inline Patch* Metapop::removePatch (unsigned int i)
869 {
870  Patch* patch = getPatchPtr(i);
871  _vPatch.erase(_vPatch.begin() + i);
872  return patch;
873 }
874 
875 inline void Metapop::deletePatch (unsigned int i)
876 {
877  delete _vPatch[i];
878  for (unsigned int k = i; k < _vPatch.size() -1; k++) {
879  _vPatch[k] = _vPatch[k + 1];
880  _vPatch[k]->setID(k);
881  }
882  _vPatch.pop_back();
883 }
884 
885 inline void Metapop::addPatch (Patch* patch)
886 {
887  _vPatch.push_back(patch);
888 }
889 
890 inline void Metapop::addPatch (unsigned int num)
891 {
892  for (unsigned int i = 0; i < num; i++)
893  _vPatch.push_back(new Patch());
894 }
895 
896 
897 
898 
899 #endif
A class to load a whole population from a binary data file.
Definition: binarydataloader.h:40
Metapop * extractPop(string &filename, unsigned int generation, SimBuilder *sim, Metapop *popPtr)
Definition: binarydataloader.cc:162
A class to store any kind of data in a char buffer before unloading it in a binary data file.
Definition: binarystoragebuffer.h:43
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:52
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
Factory of Individual, stores the individual prototype and the trait prototypes, manages the individu...
Definition: indfactory.h:42
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:61
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
Definition: metapop.h:775
virtual ~MPFileHandler()
Definition: metapop.h:782
virtual void FHwrite()
Definition: metapop.cc:1259
void setOption(int size)
Definition: metapop.h:784
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1324
MPFileHandler()
Definition: metapop.h:780
virtual void FHread(string &filename)
Definition: metapop.h:787
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1308
int _patch_sample_size
Definition: metapop.h:777
Definition: MPImanager.h:47
A StatHandler for the Metapop SimComponent.
Definition: MPStatHandler.h:39
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
unsigned int getSourceReplDigits()
Definition: metapop.h:284
unsigned int getPatchCapacity()
Definition: metapop.h:278
MPStatHandler _statHandler
The stat handler for the population stats.
Definition: metapop.h:87
void loadPopFromBinarySource(string &filename)
Loads the population from a binary data file when setting the first generation of a replicate.
Definition: metapop.cc:1022
void setReplicates(unsigned int repl)
Definition: metapop.h:273
unsigned int getPatchCapacity(sex_t SEX, unsigned int patch)
Definition: metapop.h:279
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:102
MPFileHandler * _writer
The file handler used to save pedigree info.
Definition: metapop.h:90
unsigned int _patchKmal
Definition: metapop.h:136
bool isSourceLoad()
Definition: metapop.h:281
void buildPatchArray()
Builds the new population from parameter values.
Definition: metapop.cc:307
void setPatchCapacities()
Sets the deme capacity matrix from parameter values.
Definition: metapop.cc:356
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:107
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:532
void setPopulationFromSource()
Definition: metapop.cc:888
void loadPopFromTraitFile(string &filename)
Loads a population from a trait's data file (text file).
Definition: metapop.cc:1137
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:136
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:342
unsigned int getPatchKMal()
Definition: metapop.h:277
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:195
unsigned int getPatchKFem()
Definition: metapop.h:276
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:297
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:343
void setPopulationFromSourceInPreserveMode()
Definition: metapop.cc:812
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:121
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:132
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:259
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:683
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:885
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:296
unsigned int getNumAgeClasses()
Definition: metapop.h:289
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: metapop.h:237
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches),...
Definition: metapop.cc:96
virtual void loadFileServices(FileServices *loader)
Definition: metapop.cc:267
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:100
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:134
bool _source_load
Flage to specify that the population should be built from the binary loaded source population.
Definition: metapop.h:104
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
void setGenerations(unsigned int gen)
Definition: metapop.h:271
unsigned int getGenerations()
Definition: metapop.h:272
Patch * removePatch(unsigned int i)
Removes a patch from the patch array and returns it pointer.
Definition: metapop.h:868
unsigned int getPatchArraySize()
Definition: metapop.h:269
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:117
void deletePatch(unsigned int i)
Removes a patch from the patch array and deletes it and its content.
Definition: metapop.h:875
unsigned int getCurrentReplicate()
Definition: metapop.h:294
void setMPImanager(MPImanager *mgr)
Definition: metapop.h:173
unsigned int getPatchNbr()
Definition: metapop.h:275
virtual void loadStatServices(StatServices *loader)
Definition: metapop.h:235
string getSourceFileType()
Definition: metapop.h:283
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:308
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:138
Metapop()
Definition: metapop.cc:54
string getSourceName()
Definition: metapop.h:282
std::string _source_required_age
The age class to fill with the source population.
Definition: metapop.h:119
TMatrix * getPatchCapacities()
Definition: metapop.h:280
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:128
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
void setPatchNbr(unsigned int val)
Definition: metapop.h:286
deque< Patch * > * getPatchArray()
Definition: metapop.h:268
void loadSourcePopulation()
Loads a population from a soure population.
Definition: metapop.cc:968
virtual ~Metapop()
Definition: metapop.cc:86
vector< string > _source_param_override
List of parameters whose values in the source should override local values in the loading pop.
Definition: metapop.h:123
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1191
bool updatePopulationParameters()
Called during simulation to change the population's parameters (temporal argument).
Definition: metapop.cc:255
age_t getCurrentAge()
Definition: metapop.h:298
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc:320
MPImanager * _mpimgr
Definition: metapop.h:84
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:143
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:109
void setPopulation(unsigned int currentReplicate, unsigned int replicates)
Sets the population for the first generation of each replicates.
Definition: metapop.cc:707
void reset()
Called to empty the patches, individuals are move to the garbage collector.
Definition: metapop.cc:1179
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:148
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:256
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:151
unsigned int getCurrentGeneration()
Definition: metapop.h:295
virtual void store_data(BinaryStorageBuffer *saver)
Definition: metapop.cc:452
BinaryDataLoader _loader
A BinaryDataLoader to load a population from a binary data file.
Definition: metapop.h:98
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:869
void setPatchSizes(TMatrix &mat)
Definition: metapop.h:287
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:113
unsigned int getReplicates()
Definition: metapop.h:274
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:111
virtual bool setParameters()
Definition: metapop.cc:114
void show_up()
Definition: metapop.cc:1241
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:349
bool setSourceParameters()
Setter for source population parameters.
Definition: metapop.cc:123
unsigned int _generations
Number of generations to iterate.
Definition: metapop.h:141
std::string _source_name
The base filename of source population files.
Definition: metapop.h:115
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:302
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:333
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:838
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: metapop.h:146
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:835
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:935
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:848
void getAllIndividuals(age_idx AGE, deque< Individual * > &fem_pool, deque< Individual * > &mal_pool)
Definition: metapop.cc:1223
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: metapop.cc:554
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
Patch * init(unsigned int nbfem, unsigned int nbmal, unsigned int id)
Definition: patch.cc:37
void setID(unsigned int i)
Definition: metapop.h:471
double getDensity(age_idx age)
Definition: metapop.h:489
unsigned int get_K()
Definition: metapop.h:481
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:587
void getCopy(sex_t SEX, age_idx AGE, deque< Individual * > &to)
Definition: metapop.h:725
unsigned int _KMal
Definition: metapop.h:437
void show_up()
Definition: patch.cc:133
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:497
unsigned int _sizes[2][3]
Containers size counters, sex X age.
Definition: metapop.h:445
void set_isExtinct(bool status)
Definition: metapop.h:475
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:533
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:550
unsigned short nbEmigrant
Definition: metapop.h:453
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:560
unsigned int _age
age since last extinction.
Definition: metapop.h:441
void clear()
Definition: metapop.h:676
unsigned int _capacities[2][3]
Total size of the containers, amount of allocated memory.
Definition: metapop.h:447
void setNewGeneration(age_t AGE, Metapop *pop)
Fills the patch containers corresponding to the age flags passed, for both sexes.
Definition: patch.cc:79
Patch()
Definition: metapop.h:457
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:703
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:518
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:610
void set_KMal(unsigned int k)
Definition: metapop.h:474
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:686
void flush(age_idx AGE, Metapop *pop)
Definition: metapop.h:695
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:504
unsigned int getID()
Definition: metapop.h:480
void set_age(unsigned int a)
Definition: metapop.h:476
void reset_containers()
Definition: patch.cc:65
unsigned short nbPhilopat
Definition: metapop.h:453
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:542
deque< Individual * > _containers[2][3]
Individuals containers, sex X age.
Definition: metapop.h:449
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:732
~Patch()
Definition: patch.cc:119
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:623
void set_KFem(unsigned int k)
Definition: metapop.h:473
unsigned int _KFem
Sex specific carrying capacity.
Definition: metapop.h:437
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:573
void copy2patch(Patch *patch)
Definition: metapop.h:750
void set_K(unsigned int k)
Definition: metapop.h:472
void copy2patch(age_idx AGE, Patch *patch)
Definition: metapop.h:744
unsigned int get_K(sex_t SEX)
Definition: metapop.h:482
unsigned int _nb_age_class
Number of age classes present.
Definition: metapop.h:443
bool _isExtinct
Extinction flag.
Definition: metapop.h:439
unsigned int get_KFem()
Definition: metapop.h:483
unsigned int get_KMal()
Definition: metapop.h:484
void reset_counters()
Definition: patch.cc:55
unsigned short nbImigrant
Definition: metapop.h:453
void copy2patch(sex_t SEX, age_idx AGE, Patch *patch)
Definition: metapop.h:738
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:675
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:644
unsigned int _ID
Patch ID is equal to its position in the metapop patch array.
Definition: metapop.h:433
unsigned int size(age_idx AGE)
Returns the size of the container for the appropriate age class for both sexes.
Definition: metapop.h:524
short nbKolonisers
Definition: metapop.h:454
unsigned int get_age()
Definition: metapop.h:486
bool get_isExtinct()
Definition: metapop.h:485
bool isEmpty()
Definition: metapop.h:487
unsigned int _K
Carrying capacity for males and females.
Definition: metapop.h:435
unsigned int getAdultsNumber()
Definition: metapop.h:488
void flush(Metapop *pop)
Removes all individual pointers of all sex and age classes and flush them into the recycling pool.
Definition: metapop.h:717
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:167
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:44
The Service class used to manage the StatHandler objects.
Definition: statservices.h:49
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:176
Provides an interface to binary data saving and uploading.
Definition: simcomponent.h:161
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:77
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:192
void fatal(const char *str,...)
Definition: output.cc:99
int error(const char *str,...)
Definition: output.cc:78
Nemo2.
Nemo2.
Nemo2.
#define ALL
All ages age class flag.
Definition: types.h:55
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:35
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36
unsigned int age_t
Age class flags.
Definition: types.h:45
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:40
@ ADLTx
Definition: types.h:41

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR