Nemo  2.3.46
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  friend Metapop *BinaryDataLoader::extractPop(std::string&, unsigned int, SimBuilder*, Metapop*);
82 
83 private:
85 
88 
91 
93  deque< Patch* > _vPatch;
94 
95  //binary source loader:
106  unsigned int _source_replicates;
112  unsigned int _source_generation;
114  std::string _source_name;
116  std::string _source_filetype;
118  std::string _source_required_age;
121 
124 
125  //parameters:
127  unsigned int _patchNbr;
129  unsigned int _patchK;
131  unsigned int _patchKfem, _patchKmal;
134 // /**Patch init sizes.*/
135 // unsigned int *_patch_init_size;
136 
138  unsigned int _generations;
140  unsigned int _replicates;
141  //counters:
143  unsigned int _currentGeneration;
145  unsigned int _currentReplicate;
146 // unsigned int Current_LC_Rank;
149 
150 public:
151 
152  Metapop();
153  virtual ~Metapop();
156  bool init();
157 
158  virtual bool setParameters ();
162  bool setSourceParameters();
166  void reset();
168  void clear();
169 
170  void setMPImanager(MPImanager *mgr) {_mpimgr = mgr;}
171 
174 
176  void resizePatchArray ();
178  void buildPatchArray();
181  void updatePatchArray();
183  void updatePatchState();
185  void setPatchCapacities();
190  void setPatchCapacities(string param);
196  void setPatchCapacities(sex_t SEX, string param);
201  void setPatchCapacities(string paramfem, string parammal);
203  void loadSourcePopulation ( );
205  void loadPopFromBinarySource ( string &filename );
207  void loadPopFromTraitFile ( string &filename );
209  void setPopulation (unsigned int currentReplicate, unsigned int replicates);
211  void setPopulationFromSource () ;
217  void fillPopulationFromSource(age_idx AGE, sex_t SEX, deque<Individual*>& src_pool);
224  void fillPatchFromSource(sex_t SEX, Patch* src, Patch* patch, age_t AGE);
226 
229  //SimComponent implementation:
230  virtual void loadFileServices ( FileServices* loader );
231 
232  virtual void loadStatServices ( StatServices* loader ) {loader->attach(&_statHandler);}
233 
234  //StoprableComponent implementation:
235  virtual void store_data ( BinaryStorageBuffer* saver );
236 
237  virtual bool retrieve_data ( BinaryStorageBuffer* reader );
239 
241  void store_trait (int trait_idx, BinaryStorageBuffer* saver);
242 
244  void read_trait (int trait_idx, BinaryStorageBuffer* loader);
245 
246 
249 
251  Patch* getPatch (unsigned int i) {return (i > _vPatch.size() -1 ? 0 : _vPatch[i]);}
252 
254  Patch* getPatchPtr (unsigned int patch){
255  if(!(patch < _vPatch.size()))
256  fatal("Metapop::getPatchPtr()::_vPatch overflow (id=%i nb=%i)\n", patch, _vPatch.size());
257 
258  if (_vPatch[patch] == NULL) fatal("Metapop::getPatchPtr()::NULL ptr\n");
259 
260  return _vPatch[patch];
261  }
262 
263  deque< Patch* >* getPatchArray ( ) {return &_vPatch;}
264  unsigned int getPatchArraySize ( ) {return _vPatch.size();}
265  void getAllIndividuals(age_idx AGE, deque<Individual*>& fem_pool, deque<Individual*>& mal_pool);
266  void setGenerations (unsigned int gen) {_generations = gen;}
267  unsigned int getGenerations ( ) {return _generations;}
268  void setReplicates (unsigned int repl) {_replicates = repl;}
269  unsigned int getReplicates ( ) {return _replicates;}
270  unsigned int getPatchNbr ( ) {return _patchNbr;}
271  unsigned int getPatchKFem ( ) {return _patchKfem;}
272  unsigned int getPatchKMal ( ) {return _patchKmal;}
273  unsigned int getPatchCapacity ( ) {return _patchK;}
274  unsigned int getPatchCapacity (sex_t SEX, unsigned int patch) {return (unsigned int)_patchSizes.get(SEX, patch);}
276  bool isSourceLoad ( ) {return _source_load;}
277  string getSourceName ( ) {return _source_name;}
278  string getSourceFileType ( ) {return _source_filetype;}
280 
282 
285  unsigned int getCurrentReplicate ( ) {return _currentReplicate;}
286  unsigned int getCurrentGeneration ( ) {return _currentGeneration;}
287  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl;}
288  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen;}
290 
293  void setCurrentAge (age_t age) {_currentAge = age;}
296  void setCurrentAge (LifeCycleEvent* LCE) ;
297 
299  bool isAlive ( ) {return size() != 0;}
300 
302  unsigned int size ( ) {return size(ALL);}
303 
308  unsigned int size ( sex_t SEX, age_t AGE );
309 
314  unsigned int size ( sex_t SEX, age_idx IDX );
315 
319  unsigned int size (age_idx IDX);
320  unsigned int size (age_idx IDX, unsigned int deme);
321  unsigned int size (sex_t SEX, age_idx IDX, unsigned int deme);
322 
328  unsigned int size (sex_t SEX, age_t AGE, unsigned int deme);
329 
333  unsigned int size ( age_t AGE )
334  { return size( FEM, AGE ) + size( MAL, AGE );}
335 
340  unsigned int size ( age_t AGE, unsigned int deme )
341  { return size( FEM, AGE, deme ) + size( MAL, AGE, deme );}
342 
348  Individual* get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme);
349 
358  void move (sex_t SEX, age_idx from_age, unsigned int from_deme,
359  age_idx to_age, unsigned int to_deme, unsigned int at);
360 
365  void flush ();
372  void flush (sex_t SEX, age_idx AGE);
378  void flush (age_idx AGE);
384  void flush (age_t AGE);
388  Patch* removePatch (unsigned int i);
392  void deletePatch (unsigned int i);
395  void addPatch (Patch* patch);
397  void addPatch (unsigned int num);
399 
400  void show_up();
401 };
402 //------------------------------------------------------------------------------------------
403 //
404 // CLASS PATCH
405 //
406 //------------------------------------------------------------------------------------------
407 
421 class Patch
422 {
424  unsigned int _ID;
426  unsigned int _K;
428  unsigned int _KFem, _KMal;
432  unsigned int _age;
434  unsigned int _nb_age_class;
436  unsigned int _sizes[2][3];
438  unsigned int _capacities[2][3];
440  deque <Individual*> _containers[2][3];
441 
442  public:
443 //counters:
444  unsigned short nbEmigrant, nbImigrant, nbPhilopat;
446 
447 //at construction, the capacities should be at least 1 to allow a patch to be filled (see add)
448  Patch() : _ID(0), _K(1), _KFem(1), _KMal(1), _isExtinct(0), _age(0), _nb_age_class(3)
449  { for(unsigned int i = 0; i < _nb_age_class; i++) {
450  _sizes[MAL][i] = 0;
451  _sizes[FEM][i] = 0;
452  _capacities[MAL][i] = 0;
453  _capacities[FEM][i] = 0;}
454  }
455  ~Patch();
456  Patch* init (unsigned int nbfem, unsigned int nbmal, unsigned int id);
459  void setID (unsigned int i) {_ID = i;}
460  void set_K (unsigned int k) {_K = k;}
461  void set_KFem (unsigned int k) {_KFem = k;}
462  void set_KMal (unsigned int k) {_KMal = k;}
463  void set_isExtinct (bool status) {_isExtinct = status;}
464  void set_age (unsigned int a) {_age = a;}
465 // void set_growth_rate (double r) {_r = r;}
469  unsigned int getID () {return _ID;}
470  unsigned int get_K () {return _K;}
471  unsigned int get_K (sex_t SEX) {return (SEX ? _KFem : _KMal);}
472  unsigned int get_KFem () {return _KFem;}
473  unsigned int get_KMal () {return _KMal;}
474 // double get_growth_rate () {return _r;}
475  bool get_isExtinct () {return _isExtinct;}
476  unsigned int get_age () {return _age;}
477  bool isEmpty () {return (size(ALL) == 0);}
478  unsigned int getAdultsNumber () {return size(ADLTx);}
479  double getDensity (age_idx age) {return (double)size(age)/_K;}
481 
484 
487  unsigned int size (age_t AGE)
488  { return size(MAL,AGE) + size(FEM,AGE); }
489 
494  unsigned int size (sex_t SEX, age_t AGE)
495  {
496  unsigned int mask = 1, s = 0;
497  for(unsigned int i = 0; i < _nb_age_class; i++) {
498  if( (mask & AGE) != 0) s += _sizes[SEX][i];
499  mask <<= 1;
500  }
501  return s;
502  }
503 
508  unsigned int size (sex_t SEX, age_idx AGE)
509  { return _sizes[SEX][AGE]; }
510 
514  unsigned int size (age_idx AGE)
515  { return _sizes[0][AGE] + _sizes[1][AGE]; }
516 
523  Individual* get (sex_t SEX, age_idx AGE, unsigned int at)
524  { return _containers[SEX][AGE][at]; }
525 
532  void set (sex_t SEX, age_idx AGE, unsigned int at, Individual* ind)
533  { _containers[SEX][AGE][at] = ind; }
534 
540  void add (sex_t SEX, age_idx AGE, Individual* ind)
541  {
542 
543  if( _sizes[SEX][AGE] + 1 > _capacities[SEX][AGE] ) {
544  _containers[SEX][AGE].resize( _capacities[SEX][AGE] + (_K + 1) );
545  _capacities[SEX][AGE] += (_K + 1); //the +1 is here to avoid seg faults when K=0
546  }
547 
548  _containers[SEX][AGE][ _sizes[SEX][AGE]++ ] = ind;
549  }
550 
552  void assign (sex_t SEX, age_idx AGE, unsigned int n)
553  { _containers[SEX][AGE].assign(n,0);
554  _sizes[SEX][AGE] = 0;
555  _capacities[SEX][AGE] = n;
556  }
557 
564  Individual* remove (sex_t SEX, age_idx AGE, unsigned int at)
565  {
566  if(_sizes[SEX][AGE] == 0) {
567  error("Patch::remove:: container already empty!!");
568  return NULL;
569  }
570  unsigned int last = _sizes[SEX][AGE] - 1;
571  Individual* ind = _containers[SEX][AGE][at];
572  _containers[SEX][AGE][at] = _containers[SEX][AGE][ last ];
573  _containers[SEX][AGE][ last ] = 0;
574  _sizes[SEX][AGE]--;
575  return ind;
576  }
577 
587  void move (sex_t SEX, age_idx from, age_idx to, unsigned int at)
588  {
589  add( SEX, to, _containers[SEX][from][at] );
590  remove( SEX, from, at );
591  }
592 
600  void swap (sex_t SEX, age_idx from, age_idx to)
601  {
602  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
603  _containers[SEX][to].resize( _sizes[SEX][from] );
604  _capacities[SEX][to] = _sizes[SEX][from];
605  }
606 
607  for(unsigned int i = 0; i < _sizes[SEX][from]; ++i)
608  _containers[SEX][to][i] = _containers[SEX][from][i];
609 
610  _sizes[SEX][to] = _sizes[SEX][from];
611  clear(SEX, from);
612  }
613 
623  void clear (sex_t SEX, age_idx AGE) { _sizes[SEX][AGE] = 0;}
624  void clear () { for(int i = 0; i < 3; i++) {_sizes[0][i] = 0;_sizes[1][i] = 0;}}
625 
634  void flush (sex_t SEX, age_idx AGE, Metapop* pop)
635  {
636  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
637  pop->recycle(_containers[SEX][AGE][i]);
638  _containers[SEX][AGE][i] = 0;
639  }
640  _sizes[SEX][AGE] = 0;
641  }
642 
643  void flush (age_idx AGE, Metapop* pop)
644  { flush(FEM, AGE, pop); flush(MAL, AGE, pop); }
645 
651  void flush (age_t AGE, Metapop* pop)
652  {
653  unsigned int mask = 1;
654 
655  for(unsigned int i = 0; i < _nb_age_class; i++) {
656  if( (mask & AGE) != 0) {
657  flush(MAL, static_cast<age_idx>(i), pop);
658  flush(FEM, static_cast<age_idx>(i), pop);
659  }
660  mask <<= 1;
661  }
662  }
663 
665  void flush (Metapop* pop)
666  {
667  for(unsigned int i = 0; i < _nb_age_class; i++) {
668  flush(MAL, static_cast<age_idx>(i), pop);
669  flush(FEM, static_cast<age_idx>(i), pop);
670  }
671  }
672 
673  void getCopy (sex_t SEX, age_idx AGE, deque< Individual* >& to)
674  {
675  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
676  to.push_back(_containers[SEX][AGE][i]);
677  }
678  }
679 
680  void copy2patch (sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch* to_patch)
681  {
682  for (unsigned int i = 0; i < _sizes[from_sex][from_age]; ++i)
683  to_patch->add(to_sex, to_age, _containers[from_sex][from_age][i] );
684  }
685 
686  void copy2patch (sex_t SEX, age_idx AGE, Patch* patch)
687  {
688  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i)
689  patch->add(SEX, AGE, get(SEX, AGE, i) );
690  }
691 
692  void copy2patch (age_idx AGE, Patch* patch)
693  {
694  copy2patch(FEM, AGE, patch);
695  copy2patch(MAL, AGE, patch);
696  }
697 
698  void copy2patch (Patch* patch)
699  {
700  for (unsigned int i = 0; i < _nb_age_class; ++i){
701  copy2patch(FEM, static_cast<age_idx> (i), patch);
702  copy2patch(MAL, static_cast<age_idx> (i), patch);
703  }
704  }
706 
707  void reset_counters();
708  void reset_containers();
710  void setNewGeneration(age_t AGE, Metapop* pop);
712  void setNewGeneration(age_idx AGE, Metapop* pop);
713 
714  void show_up();
715 
716 };
717 
718 //------------------------------------------------------------------------------------------
719 //
720 // MPFileHandler
721 //
722 //------------------------------------------------------------------------------------------
723 class MPFileHandler : public FileHandler {
724 
726 
727 public:
728  MPFileHandler () : FileHandler(".ped"), _patch_sample_size(0) {}
729 
730  virtual ~MPFileHandler() {}
731 
732  void setOption(int size){_patch_sample_size = size;}
733 
734  virtual void FHwrite();
735  virtual void FHread (string& filename){}
736 
737  void createAndPrintSample (age_idx AGE, Patch* patch, ofstream& FH);
738  void printNoSample (sex_t SEX, age_idx AGE, Patch* patch, ofstream& FH);
739 };
740 
741 //------------------------------------------------------------------------------------------
742 //
743 // Metapop inline functions
744 //
745 //------------------------------------------------------------------------------------------
746 inline unsigned int Metapop::size (age_idx IDX)
747 {
748  return size(FEM, IDX) + size(MAL, IDX);
749 }
750 
751 inline unsigned int Metapop::size (age_idx IDX, unsigned int deme)
752 {
753  return size(FEM, IDX, deme) + size(MAL, IDX, deme);
754 }
755 
756 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX )
757 {
758  unsigned int s = 0;
759  for(unsigned int i = 0; i < _patchNbr; i++)
760  s += _vPatch[i]->size(SEX, IDX);
761  return s;
762 }
763 
764 inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX, unsigned int deme)
765 {
766  return _vPatch[deme]->size(SEX, IDX);
767 }
768 
769 inline unsigned int Metapop::size ( sex_t SEX, age_t AGE )
770 {
771  unsigned int s = 0;
772  for(unsigned int i = 0; i < _vPatch.size(); i++)
773  s += _vPatch[i]->size(SEX, AGE);
774  return s;
775 }
776 
777 inline unsigned int Metapop::size (sex_t SEX, age_t AGE, unsigned int deme)
778 {
779  Patch* patch = getPatch(deme);
780  return (patch!=0? patch->size(SEX, AGE) : 0);
781 }
782 
783 inline Individual* Metapop::get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
784 { return getPatchPtr(deme)->get(SEX, AGE, at); }
785 
786 inline void Metapop::move (sex_t SEX, age_idx from_age, unsigned int from_deme,
787  age_idx to_age, unsigned int to_deme, unsigned int at)
788 {//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
789  _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
790  //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
791  _vPatch[from_deme]->remove(SEX, from_age, at);
792  //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
793  // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
794 }
795 
796 inline void Metapop::flush()
797 {
798  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(this);
799 }
800 
801 inline void Metapop::flush(sex_t SEX, age_idx AGE)
802 {
803  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
804 }
805 
806 inline void Metapop::flush(age_idx AGE)
807 {
808  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
809 }
810 
811 inline void Metapop::flush(age_t AGE)
812 {
813  for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
814 }
815 
816 inline Patch* Metapop::removePatch (unsigned int i)
817 {
818  Patch* patch = getPatchPtr(i);
819  _vPatch.erase(_vPatch.begin() + i);
820  return patch;
821 }
822 
823 inline void Metapop::deletePatch (unsigned int i)
824 {
825  delete _vPatch[i];
826  for (unsigned int k = i; k < _vPatch.size() -1; k++) {
827  _vPatch[k] = _vPatch[k + 1];
828  _vPatch[k]->setID(k);
829  }
830  _vPatch.pop_back();
831 }
832 
833 inline void Metapop::addPatch (Patch* patch)
834 {
835  _vPatch.push_back(patch);
836 }
837 
838 inline void Metapop::addPatch (unsigned int num)
839 {
840  for (unsigned int i = 0; i < num; i++)
841  _vPatch.push_back(new Patch());
842 }
843 
844 
845 
846 
847 #endif
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:162
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:623
std::string _source_required_age
The age class to fill with the source population.
Definition: metapop.h:118
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:62
void show_up()
Definition: patch.cc:134
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:532
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:680
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:340
std::string _source_filetype
The trait type to load from.
Definition: metapop.h:116
MPImanager * _mpimgr
Definition: metapop.h:84
unsigned int _ID
Patch ID is equal to its position in the metapop patch array.
Definition: metapop.h:424
BinaryDataLoader _loader
A BinaryDataLoader to load a population from a binary data file.
Definition: metapop.h:97
unsigned int _patchKfem
Sex specific carrying capacities.
Definition: metapop.h:131
unsigned int _patchK
Patch carrying capacity.
Definition: metapop.h:129
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
virtual ~Metapop()
Definition: metapop.cc:85
void set_KMal(unsigned int k)
Definition: metapop.h:462
unsigned int get_KMal()
Definition: metapop.h:473
void clear()
Definition: metapop.h:624
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:587
unsigned int _nb_age_class
Number of age classes present.
Definition: metapop.h:434
string getSourceFileType()
Definition: metapop.h:278
unsigned int _generations
Patch init sizes.
Definition: metapop.h:138
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:634
unsigned int get_KFem()
Definition: metapop.h:472
void setPopulation(unsigned int currentReplicate, unsigned int replicates)
Sets the population for the first generation of each replicates.
Definition: metapop.cc:682
virtual void FHread(string &filename)
Definition: metapop.h:735
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
virtual bool setParameters()
Definition: metapop.cc:114
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:148
unsigned int _age
age since last extinction.
Definition: metapop.h:432
MPFileHandler * _writer
The file handler used to save pedigree info.
Definition: metapop.h:90
void setOption(int size)
Definition: metapop.h:732
Patch()
Definition: metapop.h:448
double getDensity(age_idx age)
Definition: metapop.h:479
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
void assign(sex_t SEX, age_idx AGE, unsigned int n)
Assigns a new container of given size for the sex and age class passed, sets all values to NULL...
Definition: metapop.h:552
bool setPopulationParameters()
Population's size parameters initializing procedure.
Definition: metapop.cc:172
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:833
void setReplicates(unsigned int repl)
Definition: metapop.h:268
void setGenerations(unsigned int gen)
Definition: metapop.h:266
unsigned int _source_load_periodicity
The number of replicates to source from a single source replicate.
Definition: metapop.h:120
void getCopy(sex_t SEX, age_idx AGE, deque< Individual * > &to)
Definition: metapop.h:673
unsigned int age_t
Age class flags.
Definition: types.h:46
void deletePatch(unsigned int i)
Removes a patch from the patch array and deletes it and its content.
Definition: metapop.h:823
unsigned int _source_replicates
The number of source files, each file being a different replicate of the source population.
Definition: metapop.h:106
unsigned int _source_start_at_replicate
The replicate number to start loading from.
Definition: metapop.h:110
void setPopulationFromSource()
Definition: metapop.cc:815
void show_up()
Definition: metapop.cc:1057
string getSourceName()
Definition: metapop.h:277
unsigned int _source_generation
The generation to load from the binary file source file.
Definition: metapop.h:112
unsigned int getID()
Definition: metapop.h:469
void copy2patch(age_idx AGE, Patch *patch)
Definition: metapop.h:692
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
unsigned int getCurrentGeneration()
Definition: metapop.h:286
unsigned int _sizes[2][3]
Containers size counters, sex X age.
Definition: metapop.h:436
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc:295
bool setSourceParameters()
Setter for source population parameters.
Definition: metapop.cc:123
void copy2patch(sex_t SEX, age_idx AGE, Patch *patch)
Definition: metapop.h:686
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
virtual void store_data(BinaryStorageBuffer *saver)
Definition: metapop.cc:427
void set_KFem(unsigned int k)
Definition: metapop.h:461
void fatal(const char *str,...)
Definition: output.cc:90
deque< Individual * > _containers[2][3]
Individuals containers, sex X age.
Definition: metapop.h:440
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:145
void flush(Metapop *pop)
Removes all individual pointers of all sex and age classes and flush them into the recycling pool...
Definition: metapop.h:665
std::string _source_name
The base filename of source population files.
Definition: metapop.h:114
unsigned short nbImigrant
Definition: metapop.h:444
unsigned int getPatchKMal()
Definition: metapop.h:272
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:293
void buildPatchArray()
Builds the new population from parameter values.
Definition: metapop.cc:282
virtual ~MPFileHandler()
Definition: metapop.h:730
bool get_isExtinct()
Definition: metapop.h:475
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class...
Definition: metapop.h:299
virtual void FHwrite()
Definition: metapop.cc:1075
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
Definition: output.cc:73
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: metapop.h:143
bool _source_preserve
Flag to specify the loading mode, true means the source pop is the actual population.
Definition: metapop.h:101
unsigned int _patchNbr
Number of patches in the population.
Definition: metapop.h:127
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:494
unsigned int getCurrentReplicate()
Definition: metapop.h:285
void set_K(unsigned int k)
Definition: metapop.h:460
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:318
Metapop()
Definition: metapop.cc:54
A StatHandler for the Metapop SimComponent.
Definition: MPStatHandler.h:40
bool isSourceLoad()
Definition: metapop.h:276
unsigned int get_age()
Definition: metapop.h:476
unsigned int getSourceReplDigits()
Definition: metapop.h:279
void loadSourcePopulation()
Loads a population from a soure population.
Definition: metapop.cc:895
unsigned int _KFem
Sex specific carrying capacity.
Definition: metapop.h:428
TMatrix _patchSizes
Matrix of the deme sizes, row 0 for the males, row 1 for the females.
Definition: metapop.h:133
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
Definition: types.h:42
unsigned int size(age_idx AGE)
Returns the size of the container for the appropriate age class for both sexes.
Definition: metapop.h:514
virtual void loadStatServices(StatServices *loader)
Definition: metapop.h:232
Interface to all basic components of a simulation (traits, life cycle events, pop, etc. ).
Definition: simcomponent.h:45
void setPopulationFromSourceInPreserveMode()
Definition: metapop.cc:753
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1016
unsigned int getAdultsNumber()
Definition: metapop.h:478
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:507
unsigned int get_K()
Definition: metapop.h:470
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:786
unsigned int _patchKmal
Definition: metapop.h:131
A class to store any kind of data in a char buffer before unloading it in a binary data file...
Definition: binarystoragebuffer.h:40
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:288
void setNewGeneration(age_t AGE, Metapop *pop)
Fills the patch containers corresponding to the age flags passed, for both sexes. ...
Definition: patch.cc:80
void reset_containers()
Definition: patch.cc:66
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:783
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:796
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
unsigned int get_K(sex_t SEX)
Definition: metapop.h:471
virtual void loadFileServices(FileServices *loader)
Definition: metapop.cc:246
unsigned int _KMal
Definition: metapop.h:428
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1134
bool updatePopulationParameters()
Called during simulation to change the population's parameters (temporal argument).
Definition: metapop.cc:234
Definition: metapop.h:723
unsigned int _K
Carrying capacity for males and females.
Definition: metapop.h:426
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
age_t _requiredAge
The age class flag that is required to fill the population at the beginning of a replicate.
Definition: metapop.h:123
A class to load a whole population from a binary data file.
Definition: binarydataloader.h:41
unsigned int _capacities[2][3]
Total size of the containers, amount of allocated memory.
Definition: metapop.h:438
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:658
bool isEmpty()
Definition: metapop.h:477
#define ALL
All ages age class flag.
Definition: types.h:56
Definition: types.h:37
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: metapop.cc:529
bool _isExtinct
Extinction flag.
Definition: metapop.h:430
unsigned int getPatchArraySize()
Definition: metapop.h:264
void reset_counters()
Definition: patch.cc:56
void set_age(unsigned int a)
Definition: metapop.h:464
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:523
void setMPImanager(MPImanager *mgr)
Definition: metapop.h:170
deque< Patch * > * getPatchArray()
Definition: metapop.h:263
Patch * init(unsigned int nbfem, unsigned int nbmal, unsigned int id)
Definition: patch.cc:38
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:508
void getAllIndividuals(age_idx AGE, deque< Individual * > &fem_pool, deque< Individual * > &mal_pool)
Definition: metapop.cc:1042
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:862
void loadPopFromTraitFile(string &filename)
Loads a population from a trait's data file (text file).
Definition: metapop.cc:973
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches), the prototypes and the life cycle.
Definition: metapop.cc:95
MPStatHandler _statHandler
The stat handler for the population stats.
Definition: metapop.h:87
TMatrix * getPatchCapacities()
Definition: metapop.h:275
void set_isExtinct(bool status)
Definition: metapop.h:463
void swap(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:600
Factory of Individual, stores the individual prototype and the trait prototypes, manages the individu...
Definition: indfactory.h:43
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:287
Definition: MPImanager.h:48
unsigned int _replicates
Number of replicates to iterate.
Definition: metapop.h:140
void loadPopFromBinarySource(string &filename)
Loads the population from a binary data file when setting the first generation of a replicate...
Definition: metapop.cc:940
unsigned int getPatchCapacity()
Definition: metapop.h:273
unsigned int getReplicates()
Definition: metapop.h:269
void reset()
Called to empty the patches, individuals are move to the garbage collector.
Definition: metapop.cc:1004
void setPatchCapacities()
Sets the deme capacity matrix from parameter values.
Definition: metapop.cc:331
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:177
deque< Patch * > _vPatch
The Patch container.
Definition: metapop.h:93
MPFileHandler()
Definition: metapop.h:728
age_t getCurrentAge()
Definition: metapop.h:289
unsigned short nbPhilopat
Definition: metapop.h:444
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
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:540
Definition: types.h:37
unsigned int getGenerations()
Definition: metapop.h:267
int _patch_sample_size
Definition: metapop.h:725
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
void flush(age_idx AGE, Metapop *pop)
Definition: metapop.h:643
Metapop * _source
A source population as loaded from a binary data file, used to build a population.
Definition: metapop.h:99
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1121
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc:308
short nbKolonisers
Definition: metapop.h:445
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:333
unsigned int getPatchCapacity(sex_t SEX, unsigned int patch)
Definition: metapop.h:274
unsigned short nbEmigrant
Definition: metapop.h:444
unsigned int _source_replicate_digits
Number of digits in the replicate counter filename extension.
Definition: metapop.h:108
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:799
Metapop * extractPop(string &filename, unsigned int generation, SimBuilder *sim, Metapop *popPtr)
Definition: binarydataloader.cc:130
~Patch()
Definition: patch.cc:120
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:651
void copy2patch(Patch *patch)
Definition: metapop.h:698
Patch * removePatch(unsigned int i)
Removes a patch from the patch array and returns it pointer.
Definition: metapop.h:816
bool _source_load
Flage to specify that the population should be built from the binary loaded source population...
Definition: metapop.h:103
unsigned int getPatchKFem()
Definition: metapop.h:271
Provides an interface to binary data saving and uploading.
Definition: simcomponent.h:155
void setID(unsigned int i)
Definition: metapop.h:459

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