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  unsigned int to_size = _sizes[SEX][to];
649 
650  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
651  _containers[SEX][to].resize( _sizes[SEX][from] );
652  _capacities[SEX][to] = _sizes[SEX][from];
653  }
654 
655  // copy content of 'from' into 'to', but restrict to the 'size' of 'from' to not copy over the actual number of individuals
656  _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].begin() + _sizes[SEX][from]);
657  _sizes[SEX][to] = _containers[SEX][to].size(); // this should be equal to _sizes[SEX][from]
658 
659  if( _sizes[SEX][to] > _capacities[SEX][from] ) {
660  _capacities[SEX][from] = _sizes[SEX][to];
661  }
662 
663  _containers[SEX][from].assign(temp.begin(), temp.begin()+to_size);
664  _sizes[SEX][from] = _containers[SEX][from].size();
665  }
666 
676  void clear (sex_t SEX, age_idx AGE) { _sizes[SEX][AGE] = 0;}
677  void clear () { for(int i = 0; i < 3; i++) {_sizes[0][i] = 0;_sizes[1][i] = 0;}}
678 
687  void flush (sex_t SEX, age_idx AGE, Metapop* pop)
688  {
689  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
690  pop->recycle(_containers[SEX][AGE][i]);
691  _containers[SEX][AGE][i] = 0;
692  }
693  _sizes[SEX][AGE] = 0;
694  }
695 
696  void flush (age_idx AGE, Metapop* pop)
697  { flush(FEM, AGE, pop); flush(MAL, AGE, pop); }
698 
704  void flush (age_t AGE, Metapop* pop)
705  {
706  unsigned int mask = 1;
707 
708  for(unsigned int i = 0; i < _nb_age_class; i++) {
709  if( (mask & AGE) != 0) {
710  flush(MAL, age_idx(i), pop);
711  flush(FEM, age_idx(i), pop);
712  }
713  mask <<= 1;
714  }
715  }
716 
718  void flush (Metapop* pop)
719  {
720  for(unsigned int i = 0; i < _nb_age_class; i++) {
721  flush(MAL, age_idx(i), pop);
722  flush(FEM, age_idx(i), pop);
723  }
724  }
725 
726  void getCopy (sex_t SEX, age_idx AGE, deque< Individual* >& to)
727  {
728  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
729  to.push_back(_containers[SEX][AGE][i]);
730  }
731  }
732 
733  void copy2patch (sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch* to_patch)
734  {
735  for (unsigned int i = 0; i < _sizes[from_sex][from_age]; ++i)
736  to_patch->add(to_sex, to_age, _containers[from_sex][from_age][i] );
737  }
738 
739  void copy2patch (sex_t SEX, age_idx AGE, Patch* patch)
740  {
741  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i)
742  patch->add(SEX, AGE, get(SEX, AGE, i) );
743  }
744 
745  void copy2patch (age_idx AGE, Patch* patch)
746  {
747  copy2patch(FEM, AGE, patch);
748  copy2patch(MAL, AGE, patch);
749  }
750 
751  void copy2patch (Patch* patch)
752  {
753  for (unsigned int i = 0; i < _nb_age_class; ++i){
754  copy2patch(FEM, static_cast<age_idx> (i), patch);
755  copy2patch(MAL, static_cast<age_idx> (i), patch);
756  }
757  }
759 
760  void reset_counters();
761  void reset_containers();
763  void setNewGeneration(age_t AGE, Metapop* pop);
765  void setNewGeneration(age_idx AGE, Metapop* pop);
766 
767  void show_up();
768 
769 };
770 
771 //------------------------------------------------------------------------------------------
772 //
773 // MPFileHandler
774 //
775 //------------------------------------------------------------------------------------------
776 class MPFileHandler : public FileHandler {
777 
779 
780 public:
782 
783  virtual ~MPFileHandler() {}
784 
785  void setOption(int size){_patch_sample_size = size;}
786 
787  virtual void FHwrite();
788  virtual void FHread (string& filename){}
789 
790  void createAndPrintSample (age_idx AGE, Patch* patch, ofstream& FH);
791  void printNoSample (sex_t SEX, age_idx AGE, Patch* patch, ofstream& FH);
792 };
793 
794 //------------------------------------------------------------------------------------------
795 //
796 // Metapop inline functions
797 //
798 //------------------------------------------------------------------------------------------
799 inline unsigned int Metapop::size (age_idx IDX)
800 {
801  return size(FEM, IDX) + size(MAL, IDX);
802 }
803 
804 inline unsigned int Metapop::size (age_idx IDX, unsigned int deme)
805 {
806  return size(FEM, IDX, deme) + size(MAL, IDX, deme);
807 }
808 
809 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX )
810 {
811  unsigned int s = 0;
812  for(unsigned int i = 0; i < _patchNbr; i++)
813  s += _vPatch[i]->size(SEX, IDX);
814  return s;
815 }
816 
817 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX, unsigned int deme)
818 {
819  return _vPatch[deme]->size(SEX, IDX);
820 }
821 
822 inline unsigned int Metapop::size ( sex_t SEX, age_t AGE )
823 {
824  unsigned int s = 0;
825  for(unsigned int i = 0; i < _vPatch.size(); i++)
826  s += _vPatch[i]->size(SEX, AGE);
827  return s;
828 }
829 
830 inline unsigned int Metapop::size (sex_t SEX, age_t AGE, unsigned int deme)
831 {
832  Patch* patch = getPatch(deme);
833  return (patch!=0? patch->size(SEX, AGE) : 0);
834 }
835 
836 inline Individual* Metapop::get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
837 { return getPatchPtr(deme)->get(SEX, AGE, at); }
838 
839 inline void Metapop::move (sex_t SEX, age_idx from_age, unsigned int from_deme,
840  age_idx to_age, unsigned int to_deme, unsigned int at)
841 {//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
842  _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
843  //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
844  _vPatch[from_deme]->remove(SEX, from_age, at);
845  //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
846  // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
847 }
848 
849 inline void Metapop::flush()
850 {
851  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(this);
852 }
853 
854 inline void Metapop::flush(sex_t SEX, age_idx AGE)
855 {
856  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
857 }
858 
859 inline void Metapop::flush(age_idx AGE)
860 {
861  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
862 }
863 
864 inline void Metapop::flush(age_t AGE)
865 {
866  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
867 }
868 
869 inline Patch* Metapop::removePatch (unsigned int i)
870 {
871  Patch* patch = getPatchPtr(i);
872  _vPatch.erase(_vPatch.begin() + i);
873  return patch;
874 }
875 
876 inline void Metapop::deletePatch (unsigned int i)
877 {
878  delete _vPatch[i];
879  for (unsigned int k = i; k < _vPatch.size() -1; k++) {
880  _vPatch[k] = _vPatch[k + 1];
881  _vPatch[k]->setID(k);
882  }
883  _vPatch.pop_back();
884 }
885 
886 inline void Metapop::addPatch (Patch* patch)
887 {
888  _vPatch.push_back(patch);
889 }
890 
891 inline void Metapop::addPatch (unsigned int num)
892 {
893  for (unsigned int i = 0; i < num; i++)
894  _vPatch.push_back(new Patch());
895 }
896 
897 
898 
899 
900 #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:776
virtual ~MPFileHandler()
Definition: metapop.h:783
virtual void FHwrite()
Definition: metapop.cc:1260
void setOption(int size)
Definition: metapop.h:785
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1325
MPFileHandler()
Definition: metapop.h:781
virtual void FHread(string &filename)
Definition: metapop.h:788
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1309
int _patch_sample_size
Definition: metapop.h:778
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:886
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:869
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:876
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:839
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:836
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:849
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:726
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:677
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:704
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:687
void flush(age_idx AGE, Metapop *pop)
Definition: metapop.h:696
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:733
~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:751
void set_K(unsigned int k)
Definition: metapop.h:473
void copy2patch(age_idx AGE, Patch *patch)
Definition: metapop.h:745
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:739
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:676
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:718
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:100
int error(const char *str,...)
Definition: output.cc:79
Nemo2.
#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