Nemo  2.3.56
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
46class Patch;
47
48class LifeCycleEvent;
49
50class MPFileHandler;
51
52//CLASS METAPOP
53
79class Metapop : public StorableComponent, public SimComponent, public IndFactory
80{
81
82 friend Metapop *BinaryDataLoader::extractPop(std::string&, unsigned int, SimBuilder*, Metapop*);
83
84private:
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;
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
154public:
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);
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;}
286
287 void setPatchNbr (unsigned int val) {_patchNbr = val;}
290
293 unsigned int getCurrentReplicate ( ) {return _currentReplicate;}
294 unsigned int getCurrentGeneration ( ) {return _currentGeneration;}
295 void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl;}
296 void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen;}
298
301 void setCurrentAge (age_t age) {_currentAge = age;}
304 void setCurrentAge (LifeCycleEvent* LCE) ;
305
307 bool isAlive ( ) {return size() != 0;}
308
310 unsigned int size ( ) {return size(ALL);}
311
316 unsigned int size ( sex_t SEX, age_t AGE );
317
322 unsigned int size ( sex_t SEX, age_idx IDX );
323
327 unsigned int size (age_idx IDX);
328 unsigned int size (age_idx IDX, unsigned int deme);
329 unsigned int size (sex_t SEX, age_idx IDX, unsigned int deme);
330
336 unsigned int size (sex_t SEX, age_t AGE, unsigned int deme);
337
341 unsigned int size ( age_t AGE )
342 { return size( FEM, AGE ) + size( MAL, AGE );}
343
348 unsigned int size ( age_t AGE, unsigned int deme )
349 { return size( FEM, AGE, deme ) + size( MAL, AGE, deme );}
350
356 Individual* get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme);
357
366 void move (sex_t SEX, age_idx from_age, unsigned int from_deme,
367 age_idx to_age, unsigned int to_deme, unsigned int at);
368
373 void flush ();
380 void flush (sex_t SEX, age_idx AGE);
386 void flush (age_idx AGE);
392 void flush (age_t AGE);
396 Patch* removePatch (unsigned int i);
400 void deletePatch (unsigned int i);
403 void addPatch (Patch* patch);
405 void addPatch (unsigned int num);
407
408 void show_up();
409};
410//------------------------------------------------------------------------------------------
411//
412// CLASS PATCH
413//
414//------------------------------------------------------------------------------------------
415
429class Patch
430{
432 unsigned int _ID;
434 unsigned int _K;
436 unsigned int _KFem, _KMal;
440 unsigned int _age;
442 unsigned int _nb_age_class;
444 unsigned int _sizes[2][3];
446 unsigned int _capacities[2][3];
448 deque <Individual*> _containers[2][3];
449
450 public:
451//counters:
454
455//at construction, the capacities should be at least 1 to allow a patch to be filled (see add)
456 Patch() : _ID(0), _K(1), _KFem(1), _KMal(1), _isExtinct(0), _age(0), _nb_age_class(3),
458 { for(unsigned int i = 0; i < _nb_age_class; i++) {
459 _sizes[MAL][i] = 0;
460 _sizes[FEM][i] = 0;
461 _capacities[MAL][i] = 0;
462 _capacities[FEM][i] = 0;}
463 }
464 ~Patch();
465 Patch* init (unsigned int nbfem, unsigned int nbmal, unsigned int id);
468 void setID (unsigned int i) {_ID = i;}
469 void set_K (unsigned int k) {_K = k;}
470 void set_KFem (unsigned int k) {_KFem = k;}
471 void set_KMal (unsigned int k) {_KMal = k;}
472 void set_isExtinct (bool status) {_isExtinct = status;}
473 void set_age (unsigned int a) {_age = a;}
474// void set_growth_rate (double r) {_r = r;}
478 unsigned int getID () {return _ID;}
479 unsigned int get_K () {return _K;}
480 unsigned int get_K (sex_t SEX) {return (SEX ? _KFem : _KMal);}
481 unsigned int get_KFem () {return _KFem;}
482 unsigned int get_KMal () {return _KMal;}
483// double get_growth_rate () {return _r;}
484 bool get_isExtinct () {return _isExtinct;}
485 unsigned int get_age () {return _age;}
486 bool isEmpty () {return (size(ALL) == 0);}
487 unsigned int getAdultsNumber () {return size(ADLTx);}
488 double getDensity (age_idx age) {return (double)size(age)/_K;}
490
493
496 unsigned int size (age_t AGE)
497 { return size(MAL,AGE) + size(FEM,AGE); }
498
503 unsigned int size (sex_t SEX, age_t AGE)
504 {
505 unsigned int mask = 1, s = 0;
506 for(unsigned int i = 0; i < _nb_age_class; i++) {
507 if( (mask & AGE) != 0) s += _sizes[SEX][i];
508 mask <<= 1;
509 }
510 return s;
511 }
512
517 unsigned int size (sex_t SEX, age_idx AGE)
518 { return _sizes[SEX][AGE]; }
519
523 unsigned int size (age_idx AGE)
524 { return _sizes[0][AGE] + _sizes[1][AGE]; }
525
532 Individual* get (sex_t SEX, age_idx AGE, unsigned int at)
533 { return _containers[SEX][AGE][at]; }
534
541 void set (sex_t SEX, age_idx AGE, unsigned int at, Individual* ind)
542 { _containers[SEX][AGE][at] = ind; }
543
549 void add (sex_t SEX, age_idx AGE, Individual* ind)
550 {
551
552 if( _sizes[SEX][AGE] + 1 > _capacities[SEX][AGE] ) {
553 _containers[SEX][AGE].resize( _capacities[SEX][AGE] + (_K + 1) );
554 _capacities[SEX][AGE] += (_K + 1); //the +1 is here to avoid seg faults when K=0
555 }
556
557 _containers[SEX][AGE][ _sizes[SEX][AGE]++ ] = ind;
558 }
559
561 void assign (sex_t SEX, age_idx AGE, unsigned int n)
562 { _containers[SEX][AGE].assign(n,0);
563 _sizes[SEX][AGE] = 0;
564 _capacities[SEX][AGE] = n;
565 }
566
573 Individual* remove (sex_t SEX, age_idx AGE, unsigned int at)
574 {
575 if(_sizes[SEX][AGE] == 0) {
576 error("Patch::remove:: container already empty!!");
577 return NULL;
578 }
579 unsigned int last = _sizes[SEX][AGE] - 1;
580 Individual* ind = _containers[SEX][AGE][at];
581 _containers[SEX][AGE][at] = _containers[SEX][AGE][ last ];
582 _containers[SEX][AGE][ last ] = 0;
583 _sizes[SEX][AGE]--;
584 return ind;
585 }
586
596 void move (sex_t SEX, age_idx from, age_idx to, unsigned int at)
597 {
598 add( SEX, to, _containers[SEX][from][at] );
599 remove( SEX, from, at );
600 }
601
609 void swap (sex_t SEX, age_idx from, age_idx to)
610 {
611 if( _sizes[SEX][from] > _capacities[SEX][to] ) {
612 _containers[SEX][to].resize( _sizes[SEX][from] );
613 _capacities[SEX][to] = _sizes[SEX][from];
614 }
615
616 for(unsigned int i = 0; i < _sizes[SEX][from]; ++i)
617 _containers[SEX][to][i] = _containers[SEX][from][i];
618
619 _sizes[SEX][to] = _sizes[SEX][from];
620 clear(SEX, from);
621 }
622
632 void clear (sex_t SEX, age_idx AGE) { _sizes[SEX][AGE] = 0;}
633 void clear () { for(int i = 0; i < 3; i++) {_sizes[0][i] = 0;_sizes[1][i] = 0;}}
634
643 void flush (sex_t SEX, age_idx AGE, Metapop* pop)
644 {
645 for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
646 pop->recycle(_containers[SEX][AGE][i]);
647 _containers[SEX][AGE][i] = 0;
648 }
649 _sizes[SEX][AGE] = 0;
650 }
651
652 void flush (age_idx AGE, Metapop* pop)
653 { flush(FEM, AGE, pop); flush(MAL, AGE, pop); }
654
660 void flush (age_t AGE, Metapop* pop)
661 {
662 unsigned int mask = 1;
663
664 for(unsigned int i = 0; i < _nb_age_class; i++) {
665 if( (mask & AGE) != 0) {
666 flush(MAL, static_cast<age_idx>(i), pop);
667 flush(FEM, static_cast<age_idx>(i), pop);
668 }
669 mask <<= 1;
670 }
671 }
672
674 void flush (Metapop* pop)
675 {
676 for(unsigned int i = 0; i < _nb_age_class; i++) {
677 flush(MAL, static_cast<age_idx>(i), pop);
678 flush(FEM, static_cast<age_idx>(i), pop);
679 }
680 }
681
682 void getCopy (sex_t SEX, age_idx AGE, deque< Individual* >& to)
683 {
684 for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
685 to.push_back(_containers[SEX][AGE][i]);
686 }
687 }
688
689 void copy2patch (sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch* to_patch)
690 {
691 for (unsigned int i = 0; i < _sizes[from_sex][from_age]; ++i)
692 to_patch->add(to_sex, to_age, _containers[from_sex][from_age][i] );
693 }
694
695 void copy2patch (sex_t SEX, age_idx AGE, Patch* patch)
696 {
697 for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i)
698 patch->add(SEX, AGE, get(SEX, AGE, i) );
699 }
700
701 void copy2patch (age_idx AGE, Patch* patch)
702 {
703 copy2patch(FEM, AGE, patch);
704 copy2patch(MAL, AGE, patch);
705 }
706
707 void copy2patch (Patch* patch)
708 {
709 for (unsigned int i = 0; i < _nb_age_class; ++i){
710 copy2patch(FEM, static_cast<age_idx> (i), patch);
711 copy2patch(MAL, static_cast<age_idx> (i), patch);
712 }
713 }
715
716 void reset_counters();
717 void reset_containers();
719 void setNewGeneration(age_t AGE, Metapop* pop);
721 void setNewGeneration(age_idx AGE, Metapop* pop);
722
723 void show_up();
724
725};
726
727//------------------------------------------------------------------------------------------
728//
729// MPFileHandler
730//
731//------------------------------------------------------------------------------------------
733
735
736public:
738
739 virtual ~MPFileHandler() {}
740
741 void setOption(int size){_patch_sample_size = size;}
742
743 virtual void FHwrite();
744 virtual void FHread (string& filename){}
745
746 void createAndPrintSample (age_idx AGE, Patch* patch, ofstream& FH);
747 void printNoSample (sex_t SEX, age_idx AGE, Patch* patch, ofstream& FH);
748};
749
750//------------------------------------------------------------------------------------------
751//
752// Metapop inline functions
753//
754//------------------------------------------------------------------------------------------
755inline unsigned int Metapop::size (age_idx IDX)
756{
757 return size(FEM, IDX) + size(MAL, IDX);
758}
759
760inline unsigned int Metapop::size (age_idx IDX, unsigned int deme)
761{
762 return size(FEM, IDX, deme) + size(MAL, IDX, deme);
763}
764
765inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX )
766{
767 unsigned int s = 0;
768 for(unsigned int i = 0; i < _patchNbr; i++)
769 s += _vPatch[i]->size(SEX, IDX);
770 return s;
771}
772
773inline unsigned int Metapop::size ( sex_t SEX, age_idx IDX, unsigned int deme)
774{
775 return _vPatch[deme]->size(SEX, IDX);
776}
777
778inline unsigned int Metapop::size ( sex_t SEX, age_t AGE )
779{
780 unsigned int s = 0;
781 for(unsigned int i = 0; i < _vPatch.size(); i++)
782 s += _vPatch[i]->size(SEX, AGE);
783 return s;
784}
785
786inline unsigned int Metapop::size (sex_t SEX, age_t AGE, unsigned int deme)
787{
788 Patch* patch = getPatch(deme);
789 return (patch!=0? patch->size(SEX, AGE) : 0);
790}
791
792inline Individual* Metapop::get (sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
793{ return getPatchPtr(deme)->get(SEX, AGE, at); }
794
795inline void Metapop::move (sex_t SEX, age_idx from_age, unsigned int from_deme,
796 age_idx to_age, unsigned int to_deme, unsigned int at)
797{//cout << " add "<<get(SEX, from_age, at, from_deme)->getID()<<" to "<<to_deme<<endl;
798 _vPatch[to_deme]->add( SEX, to_age, get(SEX, from_age, at, from_deme));
799 //cout << " remove "<<get(SEX, from_age, at, from_deme)->getID()<<" from "<<from_deme<<endl;
800 _vPatch[from_deme]->remove(SEX, from_age, at);
801 //cout << " sizes: "<<from_deme<<": "<<_vPatch[from_deme]->size(SEX, from_age)<<", "
802 // << to_deme << ": " <<_vPatch[to_deme]->size( SEX, to_age)<<endl;
803}
804
805inline void Metapop::flush()
806{
807 for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(this);
808}
809
810inline void Metapop::flush(sex_t SEX, age_idx AGE)
811{
812 for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(SEX, AGE, this);
813}
814
815inline void Metapop::flush(age_idx AGE)
816{
817 for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
818}
819
820inline void Metapop::flush(age_t AGE)
821{
822 for(unsigned int i = 0; i < _patchNbr; i++) _vPatch[i]->flush(AGE, this);
823}
824
825inline Patch* Metapop::removePatch (unsigned int i)
826{
827 Patch* patch = getPatchPtr(i);
828 _vPatch.erase(_vPatch.begin() + i);
829 return patch;
830}
831
832inline void Metapop::deletePatch (unsigned int i)
833{
834 delete _vPatch[i];
835 for (unsigned int k = i; k < _vPatch.size() -1; k++) {
836 _vPatch[k] = _vPatch[k + 1];
837 _vPatch[k]->setID(k);
838 }
839 _vPatch.pop_back();
840}
841
842inline void Metapop::addPatch (Patch* patch)
843{
844 _vPatch.push_back(patch);
845}
846
847inline void Metapop::addPatch (unsigned int num)
848{
849 for (unsigned int i = 0; i < num; i++)
850 _vPatch.push_back(new Patch());
851}
852
853
854
855
856#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:732
virtual ~MPFileHandler()
Definition: metapop.h:739
virtual void FHwrite()
Definition: metapop.cc:1260
void setOption(int size)
Definition: metapop.h:741
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1325
MPFileHandler()
Definition: metapop.h:737
virtual void FHread(string &filename)
Definition: metapop.h:744
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1309
int _patch_sample_size
Definition: metapop.h:734
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:1016
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:882
void loadPopFromTraitFile(string &filename)
Loads a population from a trait's data file (text file).
Definition: metapop.cc:1131
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:341
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:296
void updatePatchState()
Update the patch capacities and patch ID (reset to array position).
Definition: metapop.cc:344
void setPopulationFromSourceInPreserveMode()
Definition: metapop.cc:806
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
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:842
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:295
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
deque< Patch * > * getPatchArray()
Definition: metapop.h:269
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:310
void setGenerations(unsigned int gen)
Definition: metapop.h: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:825
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:832
unsigned int getCurrentReplicate()
Definition: metapop.h:293
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:307
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
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
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:260
void loadSourcePopulation()
Loads a population from a soure population.
Definition: metapop.cc:962
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:1193
bool updatePopulationParameters()
Called during simulation to change the population's parameters (temporal argument).
Definition: metapop.cc:256
age_t getCurrentAge()
Definition: metapop.h:297
void resizePatchArray()
Resets the patch container to the right number of patches as set by _patchNbr.
Definition: metapop.cc: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:1181
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: metapop.h:149
age_t _currentAge
The current age class, might be changed by the LCEs.
Definition: metapop.h:152
unsigned int getCurrentGeneration()
Definition: metapop.h:294
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:863
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:348
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
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
TMatrix * getPatchCapacities()
Definition: metapop.h:281
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:301
void updatePatchArray()
Called during simulation to modify the meta-population size.
Definition: metapop.cc: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:795
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:792
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:929
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:805
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:430
Patch * init(unsigned int nbfem, unsigned int nbmal, unsigned int id)
Definition: patch.cc:38
void setID(unsigned int i)
Definition: metapop.h:468
double getDensity(age_idx age)
Definition: metapop.h:488
unsigned int get_K()
Definition: metapop.h:479
void getCopy(sex_t SEX, age_idx AGE, deque< Individual * > &to)
Definition: metapop.h:682
unsigned int _KMal
Definition: metapop.h:436
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:496
unsigned int _sizes[2][3]
Containers size counters, sex X age.
Definition: metapop.h:444
void set_isExtinct(bool status)
Definition: metapop.h:472
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:561
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it.
Definition: metapop.h:549
unsigned short nbEmigrant
Definition: metapop.h:452
unsigned int _age
age since last extinction.
Definition: metapop.h:440
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:573
void clear()
Definition: metapop.h:633
unsigned int _capacities[2][3]
Total size of the containers, amount of allocated memory.
Definition: metapop.h:446
void setNewGeneration(age_t AGE, Metapop *pop)
Fills the patch containers corresponding to the age flags passed, for both sexes.
Definition: patch.cc:80
Patch()
Definition: metapop.h:456
void flush(age_t AGE, Metapop *pop)
Removes all individual pointers of the appropriate sex and age class and flush them into the recyclin...
Definition: metapop.h:660
unsigned int size(sex_t SEX, age_idx AGE)
Returns the size of the container for the appropriate sex and age class.
Definition: metapop.h:517
void move(sex_t SEX, age_idx from, age_idx to, unsigned int at)
Moves an individual from an age class to an other one.
Definition: metapop.h:596
void set_KMal(unsigned int k)
Definition: metapop.h:471
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:643
void flush(age_idx AGE, Metapop *pop)
Definition: metapop.h:652
unsigned int size(sex_t SEX, age_t AGE)
Returns the size of the container for the appropriate sex and age classes present in the age flag.
Definition: metapop.h:503
unsigned int getID()
Definition: metapop.h:478
void set_age(unsigned int a)
Definition: metapop.h:473
void reset_containers()
Definition: patch.cc:66
unsigned short nbPhilopat
Definition: metapop.h:452
void set(sex_t SEX, age_idx AGE, unsigned int at, Individual *ind)
Modifies the appropriate container with value of the pointer given.
Definition: metapop.h:541
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:532
deque< Individual * > _containers[2][3]
Individuals containers, sex X age.
Definition: metapop.h:448
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:689
~Patch()
Definition: patch.cc:120
void set_KFem(unsigned int k)
Definition: metapop.h:470
unsigned int _KFem
Sex specific carrying capacity.
Definition: metapop.h:436
void copy2patch(Patch *patch)
Definition: metapop.h:707
void set_K(unsigned int k)
Definition: metapop.h:469
void copy2patch(age_idx AGE, Patch *patch)
Definition: metapop.h:701
unsigned int get_K(sex_t SEX)
Definition: metapop.h:480
unsigned int _nb_age_class
Number of age classes present.
Definition: metapop.h:442
bool _isExtinct
Extinction flag.
Definition: metapop.h:438
unsigned int get_KFem()
Definition: metapop.h:481
unsigned int get_KMal()
Definition: metapop.h:482
void reset_counters()
Definition: patch.cc:56
unsigned short nbImigrant
Definition: metapop.h:452
void copy2patch(sex_t SEX, age_idx AGE, Patch *patch)
Definition: metapop.h:695
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:632
unsigned int _ID
Patch ID is equal to its position in the metapop patch array.
Definition: metapop.h:432
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:609
unsigned int size(age_idx AGE)
Returns the size of the container for the appropriate age class for both sexes.
Definition: metapop.h:523
short nbKolonisers
Definition: metapop.h:453
unsigned int get_age()
Definition: metapop.h:485
bool get_isExtinct()
Definition: metapop.h:484
bool isEmpty()
Definition: metapop.h:486
unsigned int _K
Carrying capacity for males and females.
Definition: metapop.h:434
unsigned int getAdultsNumber()
Definition: metapop.h:487
void flush(Metapop *pop)
Removes all individual pointers of all sex and age classes and flush them into the recycling pool.
Definition: metapop.h:674
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:49
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:77
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:147
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.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR