Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
metapop.h
Go to the documentation of this file.
1 
30 #ifndef __METAPOP_H
31 #define __METAPOP_H
32 
33 #include <list>
34 #include <deque>
35 #include <map>
36 #include <time.h>
37 #include "types.h"
38 #include "indfactory.h"
39 #include "MPStatHandler.h"
40 #include "binarydataloader.h"
41 #include "MPImanager.h"
42 #include "tmatrix.h"
43 #include "output.h"
44 #include "filehandler.h"
45 
46 class Patch;
47 
48 class LifeCycleEvent;
49 
50 class MPFileHandler;
51 
52 //CLASS METAPOP
53 
79 class Metapop : public StorableComponent, public SimComponent, public IndFactory
80 {
81 
82  friend Metapop *BinaryDataLoader::extractPop(std::string&, unsigned int, SimBuilder*, Metapop*);
83 
84 private:
86 
89 
92 
94  deque< Patch* > _vPatch;
95 
98 
108  unsigned int _source_replicates;
114  unsigned int _source_generation;
116  std::string _source_name;
118  std::string _source_filetype;
120  std::string _source_required_age;
124  vector< string > _source_param_override;
126 
127 
130 
131  //parameters:
133  unsigned int _patchNbr;
135  unsigned int _patchK;
137  unsigned int _patchKfem, _patchKmal;
140 
142  unsigned int _generations;
144  unsigned int _replicates;
145  //counters:
147  unsigned int _currentGeneration;
149  unsigned int _currentReplicate;
150 // unsigned int Current_LC_Rank;
153 
154 public:
155 
156  Metapop();
157  virtual ~Metapop();
160  bool init();
161 
162  virtual bool setParameters ();
166  bool setSourceParameters();
170  void reset();
172  void clear();
173 
174  void setMPImanager(MPImanager *mgr) {_mpimgr = mgr;}
175 
178 
180  void resizePatchArray ();
182  void buildPatchArray();
185  void updatePatchArray();
187  void updatePatchState();
189  void setPatchCapacities();
194  void setPatchCapacities(string param);
200  void setPatchCapacities(sex_t SEX, string param);
205  void setPatchCapacities(string paramfem, string parammal);
207  void loadSourcePopulation ( );
209  void loadPopFromBinarySource ( string &filename );
211  void loadPopFromTraitFile ( string &filename );
213  void setPopulation (unsigned int currentReplicate, unsigned int replicates);
215  void setPopulationFromSource () ;
221  void fillPopulationFromSource(age_idx AGE, sex_t SEX, deque<Individual*>& src_pool);
228  void fillPatchFromSource(sex_t SEX, Patch* src, Patch* patch, age_t AGE);
230 
233  //SimComponent implementation:
234  virtual void loadFileServices ( FileServices* loader );
235 
236  virtual void loadStatServices ( StatServices* loader ) {loader->attach(&_statHandler);}
237 
238  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
239 
240  //StoprableComponent implementation:
241  virtual void store_data ( BinaryStorageBuffer* saver );
242 
243  virtual bool retrieve_data ( BinaryStorageBuffer* reader );
245 
247  void store_trait (int trait_idx, BinaryStorageBuffer* saver);
248 
250  void read_trait (int trait_idx, BinaryStorageBuffer* loader);
251 
252 
255 
257  Patch* getPatch (unsigned int i) {return (i > _vPatch.size() -1 ? 0 : _vPatch[i]);}
258 
260  Patch* getPatchPtr (unsigned int patch){
261  if(!(patch < _vPatch.size()))
262  fatal("Metapop::getPatchPtr()::_vPatch overflow (id=%i nb=%i)\n", patch, _vPatch.size());
263 
264  if (_vPatch[patch] == NULL) fatal("Metapop::getPatchPtr()::NULL ptr\n");
265 
266  return _vPatch[patch];
267  }
268 
269  deque< Patch* >* getPatchArray ( ) {return &_vPatch;}
270  unsigned int getPatchArraySize ( ) {return _vPatch.size();}
271  void getAllIndividuals(age_idx AGE, deque<Individual*>& fem_pool, deque<Individual*>& mal_pool);
272  void setGenerations (unsigned int gen) {_generations = gen;}
273  unsigned int getGenerations ( ) {return _generations;}
274  void setReplicates (unsigned int repl) {_replicates = repl;}
275  unsigned int getReplicates ( ) {return _replicates;}
276  unsigned int getPatchNbr ( ) {return _patchNbr;}
277  unsigned int getPatchKFem ( ) {return _patchKfem;}
278  unsigned int getPatchKMal ( ) {return _patchKmal;}
279  unsigned int getPatchCapacity ( ) {return _patchK;}
280  unsigned int getPatchCapacity (sex_t SEX, unsigned int patch) {return (unsigned int)_patchSizes.get(SEX, patch);}
282  bool isSourceLoad ( ) {return _source_load;}
283  string getSourceName ( ) {return _source_name;}
284  string getSourceFileType ( ) {return _source_filetype;}
286 
287  void setPatchNbr (unsigned int val) {_patchNbr = val;}
288  void setPatchSizes (TMatrix& mat) {_patchSizes.copy(mat);}
289 
290  unsigned int getNumAgeClasses ( ) {return 2;}
292 
295  unsigned int getCurrentReplicate ( ) {return _currentReplicate;}
296  unsigned int getCurrentGeneration ( ) {return _currentGeneration;}
297  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl;}
298  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen;}
300 
303  void setCurrentAge (age_t age) {_currentAge = age;}
306  void setCurrentAge (LifeCycleEvent* LCE) ;
307 
309  bool isAlive ( ) {return size() != 0;}
310 
312  unsigned int size ( ) {return size(ALL);}
313 
318  unsigned int size ( sex_t SEX, age_t AGE );
319 
324  unsigned int size ( sex_t SEX, age_idx IDX );
325 
329  unsigned int size (age_idx IDX);
330  unsigned int size (age_idx IDX, unsigned int deme);
331  unsigned int size (sex_t SEX, age_idx IDX, unsigned int deme);
332 
338  unsigned int size (sex_t SEX, age_t AGE, unsigned int deme);
339 
343  unsigned int size ( age_t AGE )
344  { return size( FEM, AGE ) + size( MAL, AGE );}
345 
350  unsigned int size ( age_t AGE, unsigned int deme )
351  { return size( FEM, AGE, deme ) + size( MAL, AGE, deme );}
352 
358  Individual* get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme);
359 
368  void move (sex_t SEX, age_idx from_age, unsigned int from_deme,
369  age_idx to_age, unsigned int to_deme, unsigned int at);
370 
375  void flush ();
382  void flush (sex_t SEX, age_idx AGE);
388  void flush (age_idx AGE);
394  void flush (age_t AGE);
398  Patch* removePatch (unsigned int i);
402  void deletePatch (unsigned int i);
405  void addPatch (Patch* patch);
407  void addPatch (unsigned int num);
409 
410  void show_up();
411 };
412 //------------------------------------------------------------------------------------------
413 //
414 // CLASS PATCH
415 //
416 //------------------------------------------------------------------------------------------
417 
431 class Patch
432 {
434  unsigned int _ID;
436  unsigned int _K;
438  unsigned int _KFem, _KMal;
442  unsigned int _age;
444  unsigned int _nb_age_class;
446  unsigned int _sizes[2][3];
448  unsigned int _capacities[2][3];
450  deque <Individual*> _containers[2][3];
451 
452  public:
453 //counters:
454  unsigned short nbEmigrant, nbImigrant, nbPhilopat;
456 
457 //at construction, the capacities should be at least 1 to allow a patch to be filled (see add)
458  Patch() : _ID(0), _K(1), _KFem(1), _KMal(1), _isExtinct(0), _age(0), _nb_age_class(3),
460  { for(unsigned int i = 0; i < _nb_age_class; i++) {
461  _sizes[MAL][i] = 0;
462  _sizes[FEM][i] = 0;
463  _capacities[MAL][i] = 0;
464  _capacities[FEM][i] = 0;}
465  }
466 
467  ~Patch();
468 
469  Patch* init (unsigned int nbfem, unsigned int nbmal, unsigned int id);
472  void setID (unsigned int i) {_ID = i;}
473  void set_K (unsigned int k) {_K = k;}
474  void set_KFem (unsigned int k) {_KFem = k;}
475  void set_KMal (unsigned int k) {_KMal = k;}
476  void set_isExtinct (bool status) {_isExtinct = status;}
477  void set_age (unsigned int a) {_age = a;}
481  unsigned int getID () {return _ID;}
482  unsigned int get_K () {return _K;}
483  unsigned int get_K (sex_t SEX) {return (SEX ? _KFem : _KMal);}
484  unsigned int get_KFem () {return _KFem;}
485  unsigned int get_KMal () {return _KMal;}
486  bool get_isExtinct () {return _isExtinct;}
487  unsigned int get_age () {return _age;}
488  bool isEmpty () {return (size(ALL) == 0);}
489  unsigned int getAdultsNumber () {return size(ADLTx);}
490  double getDensity (age_idx age) {return (double)size(age)/_K;}
492 
495 
498  unsigned int size (age_t AGE)
499  { return size(MAL,AGE) + size(FEM,AGE); }
500 
505  unsigned int size (sex_t SEX, age_t AGE)
506  {
507  unsigned int mask = 1, s = 0;
508  for(unsigned int i = 0; i < _nb_age_class; i++) {
509  if( (mask & AGE) != 0) s += _sizes[SEX][i];
510  mask <<= 1;
511  }
512  return s;
513  }
514 
519  unsigned int size (sex_t SEX, age_idx AGE)
520  { return _sizes[SEX][AGE]; }
521 
525  unsigned int size (age_idx AGE)
526  { return _sizes[0][AGE] + _sizes[1][AGE]; }
527 
534  Individual* get (sex_t SEX, age_idx AGE, unsigned int at)
535  { return _containers[SEX][AGE][at]; }
536 
543  void set (sex_t SEX, age_idx AGE, unsigned int at, Individual* ind)
544  { _containers[SEX][AGE][at] = ind; }
545 
551  void add (sex_t SEX, age_idx AGE, Individual* ind)
552  {
553  if( _sizes[SEX][AGE] + 1 > _capacities[SEX][AGE] ) {
554  _containers[SEX][AGE].resize( _capacities[SEX][AGE] + (_K + 1) );
555  _capacities[SEX][AGE] += (_K + 1); //the +1 is here to avoid seg faults when K=0
556  }
557  _containers[SEX][AGE][ _sizes[SEX][AGE]++ ] = ind;
558  }
559 
561  void assign (sex_t SEX, age_idx AGE, size_t n)
562  { _containers[SEX][AGE].assign(n,0);
563  _sizes[SEX][AGE] = 0;
564  _capacities[SEX][AGE] = n;
565  }
566 
574  void resize (sex_t SEX, age_idx AGE, size_t new_size)
575  {
576  if( new_size > _capacities[SEX][AGE] ) {
577  _containers[SEX][AGE].resize( new_size );
578  _capacities[SEX][AGE] = new_size;
579  }
580  _sizes[SEX][AGE] = new_size;
581  }
588  Individual* remove (sex_t SEX, age_idx AGE, unsigned int at)
589  {
590  if(_sizes[SEX][AGE] == 0) {
591  error("Patch::remove:: container already empty!!");
592  return NULL;
593  }
594  unsigned int last = _sizes[SEX][AGE] - 1;
595  Individual* ind = _containers[SEX][AGE][at];
596  _containers[SEX][AGE][at] = _containers[SEX][AGE][ last ];
597  _containers[SEX][AGE][ last ] = 0;
598  _sizes[SEX][AGE]--;
599  return ind;
600  }
601 
611  void move (sex_t SEX, age_idx from, age_idx to, unsigned int at)
612  {
613  add( SEX, to, _containers[SEX][from][at] );
614  remove( SEX, from, at );
615  }
616 
624  void move (sex_t SEX, age_idx from, age_idx to)
625  {
626  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
627  _containers[SEX][to].resize( _sizes[SEX][from] );
628  _capacities[SEX][to] = _sizes[SEX][from];
629  }
630 
631  for(unsigned int i = 0; i < _sizes[SEX][from]; ++i)
632  _containers[SEX][to][i] = _containers[SEX][from][i];
633 // _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].end());
634 
635  _sizes[SEX][to] = _sizes[SEX][from];
636  clear(SEX, from);
637  }
638 
645  void swap_new (sex_t SEX, age_idx from, age_idx to)
646  {
647  deque<Individual*> temp(_containers[SEX][to].begin(), _containers[SEX][to].end());
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  _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].end());
655  _sizes[SEX][to] = _containers[SEX][to].size();
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.end());
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:41
Metapop * extractPop(string &filename, unsigned int generation, SimBuilder *sim, Metapop *popPtr)
Definition: binarydataloader.cc:163
A class to store any kind of data in a char buffer before unloading it in a binary data file.
Definition: binarystoragebuffer.h:44
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:52
Factory of Individual, stores the individual prototype and the trait prototypes, manages the individu...
Definition: indfactory.h:43
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:62
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
Definition: metapop.h:774
virtual ~MPFileHandler()
Definition: metapop.h:781
virtual void FHwrite()
Definition: metapop.cc:1260
void setOption(int size)
Definition: metapop.h:783
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1325
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:1309
int _patch_sample_size
Definition: metapop.h:776
Definition: MPImanager.h:48
A StatHandler for the Metapop SimComponent.
Definition: MPStatHandler.h:40
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:80
unsigned int getSourceReplDigits()
Definition: metapop.h:285
unsigned int getPatchCapacity()
Definition: metapop.h:279
MPStatHandler _statHandler
The stat handler for the population stats.
Definition: metapop.h:88
void loadPopFromBinarySource(string &filename)
Loads the population from a binary data file when setting the first generation of a replicate.
Definition: metapop.cc:1023
void setReplicates(unsigned int repl)
Definition: metapop.h:274
unsigned int getPatchCapacity(sex_t SEX, unsigned int patch)
Definition: metapop.h:280
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:103
MPFileHandler * _writer
The file handler used to save pedigree info.
Definition: metapop.h:91
unsigned int _patchKmal
Definition: metapop.h:137
bool isSourceLoad()
Definition: metapop.h:282
void buildPatchArray()
Builds the new population from parameter values.
Definition: metapop.cc:308
void setPatchCapacities()
Sets the deme capacity matrix from parameter values.
Definition: metapop.cc:357
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:108
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:533
void setPopulationFromSource()
Definition: metapop.cc:889
void loadPopFromTraitFile(string &filename)
Loads a population from a trait's data file (text file).
Definition: metapop.cc:1138
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:137
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:343
unsigned int getPatchKMal()
Definition: metapop.h:278
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:196
unsigned int getPatchKFem()
Definition: metapop.h:277
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:298
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:344
void setPopulationFromSourceInPreserveMode()
Definition: metapop.cc:813
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:122
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:133
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:260
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:684
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:884
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:297
unsigned int getNumAgeClasses()
Definition: metapop.h:290
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: metapop.h:238
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches),...
Definition: metapop.cc:97
virtual void loadFileServices(FileServices *loader)
Definition: metapop.cc:268
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:101
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:135
bool _source_load
Flage to specify that the population should be built from the binary loaded source population.
Definition: metapop.h:105
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:312
void setGenerations(unsigned int gen)
Definition: metapop.h:272
unsigned int getGenerations()
Definition: metapop.h:273
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:270
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:118
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:295
void setMPImanager(MPImanager *mgr)
Definition: metapop.h:174
unsigned int getPatchNbr()
Definition: metapop.h:276
virtual void loadStatServices(StatServices *loader)
Definition: metapop.h:236
string getSourceFileType()
Definition: metapop.h:284
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:309
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:139
Metapop()
Definition: metapop.cc:55
string getSourceName()
Definition: metapop.h:283
std::string _source_required_age
The age class to fill with the source population.
Definition: metapop.h:120
TMatrix * getPatchCapacities()
Definition: metapop.h:281
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:129
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:94
void setPatchNbr(unsigned int val)
Definition: metapop.h:287
deque< Patch * > * getPatchArray()
Definition: metapop.h:269
void loadSourcePopulation()
Loads a population from a soure population.
Definition: metapop.cc:969
virtual ~Metapop()
Definition: metapop.cc:87
vector< string > _source_param_override
List of parameters whose values in the source should override local values in the loading pop.
Definition: metapop.h:124
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1192
bool updatePopulationParameters()
Called during simulation to change the population's parameters (temporal argument).
Definition: metapop.cc:256
age_t getCurrentAge()
Definition: metapop.h:299
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc:321
MPImanager * _mpimgr
Definition: metapop.h:85
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:144
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:110
void setPopulation(unsigned int currentReplicate, unsigned int replicates)
Sets the population for the first generation of each replicates.
Definition: metapop.cc:708
void reset()
Called to empty the patches, individuals are move to the garbage collector.
Definition: metapop.cc:1180
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:149
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:152
unsigned int getCurrentGeneration()
Definition: metapop.h:296
virtual void store_data(BinaryStorageBuffer *saver)
Definition: metapop.cc:453
BinaryDataLoader _loader
A BinaryDataLoader to load a population from a binary data file.
Definition: metapop.h:99
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:870
void setPatchSizes(TMatrix &mat)
Definition: metapop.h:288
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:114
unsigned int getReplicates()
Definition: metapop.h:275
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:112
virtual bool setParameters()
Definition: metapop.cc:115
void show_up()
Definition: metapop.cc:1242
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:350
bool setSourceParameters()
Setter for source population parameters.
Definition: metapop.cc:124
unsigned int _generations
Number of generations to iterate.
Definition: metapop.h:142
std::string _source_name
The base filename of source population files.
Definition: metapop.h:116
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:303
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:334
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:147
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:936
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:1224
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: metapop.cc:555
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
Patch * init(unsigned int nbfem, unsigned int nbmal, unsigned int id)
Definition: patch.cc:38
void setID(unsigned int i)
Definition: metapop.h:472
double getDensity(age_idx age)
Definition: metapop.h:490
unsigned int get_K()
Definition: metapop.h:482
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:588
void getCopy(sex_t SEX, age_idx AGE, deque< Individual * > &to)
Definition: metapop.h:724
unsigned int _KMal
Definition: metapop.h:438
void show_up()
Definition: patch.cc:134
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 _sizes[2][3]
Containers size counters, sex X age.
Definition: metapop.h:446
void set_isExtinct(bool status)
Definition: metapop.h:476
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:534
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:551
unsigned short nbEmigrant
Definition: metapop.h:454
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:561
unsigned int _age
age since last extinction.
Definition: metapop.h:442
void clear()
Definition: metapop.h:675
unsigned int _capacities[2][3]
Total size of the containers, amount of allocated memory.
Definition: metapop.h:448
void setNewGeneration(age_t AGE, Metapop *pop)
Fills the patch containers corresponding to the age flags passed, for both sexes.
Definition: patch.cc:80
Patch()
Definition: metapop.h:458
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:519
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:611
void set_KMal(unsigned int k)
Definition: metapop.h:475
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:505
unsigned int getID()
Definition: metapop.h:481
void set_age(unsigned int a)
Definition: metapop.h:477
void reset_containers()
Definition: patch.cc:66
unsigned short nbPhilopat
Definition: metapop.h:454
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:543
deque< Individual * > _containers[2][3]
Individuals containers, sex X age.
Definition: metapop.h:450
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:120
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:624
void set_KFem(unsigned int k)
Definition: metapop.h:474
unsigned int _KFem
Sex specific carrying capacity.
Definition: metapop.h:438
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:574
void copy2patch(Patch *patch)
Definition: metapop.h:749
void set_K(unsigned int k)
Definition: metapop.h:473
void copy2patch(age_idx AGE, Patch *patch)
Definition: metapop.h:743
unsigned int get_K(sex_t SEX)
Definition: metapop.h:483
unsigned int _nb_age_class
Number of age classes present.
Definition: metapop.h:444
bool _isExtinct
Extinction flag.
Definition: metapop.h:440
unsigned int get_KFem()
Definition: metapop.h:484
unsigned int get_KMal()
Definition: metapop.h:485
void reset_counters()
Definition: patch.cc:56
unsigned short nbImigrant
Definition: metapop.h:454
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:645
unsigned int _ID
Patch ID is equal to its position in the metapop patch array.
Definition: metapop.h:434
unsigned int size(age_idx AGE)
Returns the size of the container for the appropriate age class for both sexes.
Definition: metapop.h:525
short nbKolonisers
Definition: metapop.h:455
unsigned int get_age()
Definition: metapop.h:487
bool get_isExtinct()
Definition: metapop.h:486
bool isEmpty()
Definition: metapop.h:488
unsigned int _K
Carrying capacity for males and females.
Definition: metapop.h:436
unsigned int getAdultsNumber()
Definition: metapop.h:489
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:168
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
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:177
Provides an interface to binary data saving and uploading.
Definition: simcomponent.h:162
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:78
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:193
void fatal(const char *str,...)
Definition: output.cc:96
int error(const char *str,...)
Definition: output.cc:77
#define ALL
All ages age class flag.
Definition: types.h:56
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
unsigned int age_t
Age class flags.
Definition: types.h:46
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
@ 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