Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
Patch Class Reference

Second class in the metapopulation design structure, between the Metapop and Individual classes. More...

#include <metapop.h>

+ Collaboration diagram for Patch:

Public Member Functions

 Patch ()
 
 ~Patch ()
 
Patchinit (unsigned int nbfem, unsigned int nbmal, unsigned int id)
 
void reset_counters ()
 
void reset_containers ()
 
void setNewGeneration (age_t AGE, Metapop *pop)
 Fills the patch containers corresponding to the age flags passed, for both sexes. More...
 
void setNewGeneration (age_idx AGE, Metapop *pop)
 Fills the patch container corresponding to the age class index passed, for both sexes. More...
 
void show_up ()
 
Setters
void setID (unsigned int i)
 
void set_K (unsigned int k)
 
void set_KFem (unsigned int k)
 
void set_KMal (unsigned int k)
 
void set_isExtinct (bool status)
 
void set_age (unsigned int a)
 
Getters
unsigned int getID ()
 
unsigned int get_K ()
 
unsigned int get_K (sex_t SEX)
 
unsigned int get_KFem ()
 
unsigned int get_KMal ()
 
bool get_isExtinct ()
 
unsigned int get_age ()
 
bool isEmpty ()
 
unsigned int getAdultsNumber ()
 
double getDensity (age_idx age)
 
State getter and modifier functions
unsigned int size (age_t AGE)
 Returns the size of the container of the appropriate age class(es) for both sexes. More...
 
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. More...
 
unsigned int size (sex_t SEX, age_idx AGE)
 Returns the size of the container for the appropriate sex and age class. More...
 
unsigned int size (age_idx AGE)
 Returns the size of the container for the appropriate age class for both sexes. More...
 
Individualget (sex_t SEX, age_idx AGE, unsigned int at)
 Returns a pointer to the individual sitting at the index passed. More...
 
void set (sex_t SEX, age_idx AGE, unsigned int at, Individual *ind)
 Modifies the appropriate container with value of the pointer given. More...
 
void add (sex_t SEX, age_idx AGE, Individual *ind)
 Adds an individual to the appropriate container, increments its size, eventually resizing it. More...
 
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. More...
 
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. More...
 
Individualremove (sex_t SEX, age_idx AGE, unsigned int at)
 Removes the individual sitting at the given index in the appropriate container. More...
 
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. More...
 
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. More...
 
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 the same sex. More...
 
void clear (sex_t SEX, age_idx AGE)
 Sets the size of the appropriate container to zero. More...
 
void clear ()
 
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 recycling pool. More...
 
void flush (age_idx AGE, Metapop *pop)
 
void flush (age_t AGE, Metapop *pop)
 Removes all individual pointers of the appropriate sex and age class and flush them into the recycling pool. More...
 
void flush (Metapop *pop)
 Removes all individual pointers of all sex and age classes and flush them into the recycling pool. More...
 
void getCopy (sex_t SEX, age_idx AGE, deque< Individual * > &to)
 
void copy2patch (sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
 
void copy2patch (sex_t SEX, age_idx AGE, Patch *patch)
 
void copy2patch (age_idx AGE, Patch *patch)
 
void copy2patch (Patch *patch)
 

Public Attributes

unsigned short nbEmigrant
 
unsigned short nbImigrant
 
unsigned short nbPhilopat
 
short nbKolonisers
 

Private Attributes

unsigned int _ID
 Patch ID is equal to its position in the metapop patch array. More...
 
unsigned int _K
 Carrying capacity for males and females. More...
 
unsigned int _KFem
 Sex specific carrying capacity. More...
 
unsigned int _KMal
 
bool _isExtinct
 Extinction flag. More...
 
unsigned int _age
 age since last extinction. More...
 
unsigned int _nb_age_class
 Number of age classes present. More...
 
unsigned int _sizes [2][3]
 Containers size counters, sex X age. More...
 
unsigned int _capacities [2][3]
 Total size of the containers, amount of allocated memory. More...
 
deque< Individual * > _containers [2][3]
 Individuals containers, sex X age. More...
 

Detailed Description

Second class in the metapopulation design structure, between the Metapop and Individual classes.

The Patch class is an abstraction of a sub-population or patch concept (also called a deme) in a metapopulation context. It contains the individual containers for the different age classes. Three main age classes are currently implemented, the offspring, post-dispersal and adult classes (see the age_t enum) which are all subdivided into male and female individuals. These containers are accessed using the interface defined here or through the Metapop class interface. The different LCEs will use these interfaces to handle the individuals. They are also responsible to change the age flag of the population (see Metapop).

The individuals are accessed using their age index value and not the age flag value (e.g., using the Patch::get() method). These indexes are defined in the age_idx enum (see type.h) and differ from the age class flag values. For instance the adults' containers have the index 2 (ADLTx = 2) whereas their age flag is 4 (ADULTS = 4). This might be confusing but it saves a lot of checks at runtime! It also allows to give a flag containing several class bits set instead of a unique index value when needed (see the Patch::size() and Metapop::size() suite of functions).

Constructor & Destructor Documentation

◆ Patch()

Patch::Patch ( )
inline
458  : _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  }
unsigned int _KMal
Definition: metapop.h:438
unsigned int _sizes[2][3]
Containers size counters, sex X age.
Definition: metapop.h:446
unsigned short nbEmigrant
Definition: metapop.h:454
unsigned int _age
age since last extinction.
Definition: metapop.h:442
unsigned int _capacities[2][3]
Total size of the containers, amount of allocated memory.
Definition: metapop.h:448
unsigned short nbPhilopat
Definition: metapop.h:454
unsigned int _KFem
Sex specific carrying capacity.
Definition: metapop.h:438
unsigned int _nb_age_class
Number of age classes present.
Definition: metapop.h:444
bool _isExtinct
Extinction flag.
Definition: metapop.h:440
unsigned short nbImigrant
Definition: metapop.h:454
unsigned int _ID
Patch ID is equal to its position in the metapop patch array.
Definition: metapop.h:434
short nbKolonisers
Definition: metapop.h:455
unsigned int _K
Carrying capacity for males and females.
Definition: metapop.h:436
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References _capacities, _nb_age_class, _sizes, FEM, and MAL.

◆ ~Patch()

Patch::~Patch ( )
121 {
122 //#ifdef _DEBUG_
123 // message("Patch::~Patch\n");
124 //#endif
125 
126  for (unsigned int i = 0; i < 2; ++i)
127  for(unsigned int j = 0; j < _nb_age_class; ++j)
128  for(unsigned int k = 0; k < _sizes[i][j] ; ++k)
129  delete _containers[i][j][k];
130 }
deque< Individual * > _containers[2][3]
Individuals containers, sex X age.
Definition: metapop.h:450

Member Function Documentation

◆ add()

◆ assign()

void Patch::assign ( sex_t  SEX,
age_idx  AGE,
size_t  n 
)
inline

Assigns a new container of given size for the sex and age class passed, sets all values to NULL.

562  { _containers[SEX][AGE].assign(n,0);
563  _sizes[SEX][AGE] = 0;
564  _capacities[SEX][AGE] = n;
565  }

References _capacities, _containers, and _sizes.

Referenced by TTNOhtaStats::FHwrite(), TTQFreqExtractor::FHwrite(), TTQOhtaStats::FHwrite(), and TTNeutralGenesSH::setHs().

◆ clear() [1/2]

void Patch::clear ( )
inline
675 { for(int i = 0; i < 3; i++) {_sizes[0][i] = 0;_sizes[1][i] = 0;}}

References _sizes.

Referenced by move().

◆ clear() [2/2]

void Patch::clear ( sex_t  SEX,
age_idx  AGE 
)
inline

Sets the size of the appropriate container to zero.

Note: no memory operation is performed, the capacity of the container is thus not affected. The individual pointers are not flushed to the recycling pool, they will be overwritten by subsequent operations. It is thus a good idea to consider using Patch::flush to be sure no pointers remained in the container.

See also
flush()
Parameters
SEXthe sex class
AGEthe index of the age class
674 { _sizes[SEX][AGE] = 0;}

References _sizes.

Referenced by LCE_Resize::buildNewPatchArrayWithBackup(), FileServices::empty_sampled_pop(), LCE_BreedAssortativeMating::execute(), LCE_Resize::execute(), and LCE_Resize::removeDesignatedPatch().

◆ copy2patch() [1/4]

void Patch::copy2patch ( age_idx  AGE,
Patch patch 
)
inline
744  {
745  copy2patch(FEM, AGE, patch);
746  copy2patch(MAL, AGE, patch);
747  }
void copy2patch(sex_t from_sex, sex_t to_sex, age_idx from_age, age_idx to_age, Patch *to_patch)
Definition: metapop.h:731

References copy2patch(), FEM, and MAL.

◆ copy2patch() [2/4]

void Patch::copy2patch ( Patch patch)
inline
750  {
751  for (unsigned int i = 0; i < _nb_age_class; ++i){
752  copy2patch(FEM, static_cast<age_idx> (i), patch);
753  copy2patch(MAL, static_cast<age_idx> (i), patch);
754  }
755  }
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41

References _nb_age_class, copy2patch(), FEM, and MAL.

◆ copy2patch() [3/4]

void Patch::copy2patch ( sex_t  from_sex,
sex_t  to_sex,
age_idx  from_age,
age_idx  to_age,
Patch to_patch 
)
inline
732  {
733  for (unsigned int i = 0; i < _sizes[from_sex][from_age]; ++i)
734  to_patch->add(to_sex, to_age, _containers[from_sex][from_age][i] );
735  }
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

References _containers, _sizes, and add().

Referenced by LCE_Resize::buildNewPatchArrayWithBackup(), copy2patch(), and LCE_Resize::removeDesignatedPatch().

◆ copy2patch() [4/4]

void Patch::copy2patch ( sex_t  SEX,
age_idx  AGE,
Patch patch 
)
inline
738  {
739  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i)
740  patch->add(SEX, AGE, get(SEX, AGE, i) );
741  }
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

References _sizes, add(), and get().

◆ flush() [1/4]

void Patch::flush ( age_idx  AGE,
Metapop pop 
)
inline
695  { flush(FEM, AGE, pop); flush(MAL, AGE, pop); }
void flush(sex_t SEX, age_idx AGE, Metapop *pop)
Removes all individual pointers of the appropriate sex and age class and flush them into the recyclin...
Definition: metapop.h:685

References FEM, flush(), and MAL.

◆ flush() [2/4]

void Patch::flush ( age_t  AGE,
Metapop pop 
)
inline

Removes all individual pointers of the appropriate sex and age class and flush them into the recycling pool.

Parameters
AGEan unsigned int containing the flags of the age classes to flush
popthe pointer to the metapop for access to the recycling pool
See also
flush()
703  {
704  unsigned int mask = 1;
705 
706  for(unsigned int i = 0; i < _nb_age_class; i++) {
707  if( (mask & AGE) != 0) {
708  flush(MAL, age_idx(i), pop);
709  flush(FEM, age_idx(i), pop);
710  }
711  mask <<= 1;
712  }
713  }

References _nb_age_class, FEM, flush(), and MAL.

◆ flush() [3/4]

void Patch::flush ( Metapop pop)
inline

Removes all individual pointers of all sex and age classes and flush them into the recycling pool.

717  {
718  for(unsigned int i = 0; i < _nb_age_class; i++) {
719  flush(MAL, age_idx(i), pop);
720  flush(FEM, age_idx(i), pop);
721  }
722  }

References _nb_age_class, FEM, flush(), and MAL.

◆ flush() [4/4]

void Patch::flush ( sex_t  SEX,
age_idx  AGE,
Metapop pop 
)
inline

Removes all individual pointers of the appropriate sex and age class and flush them into the recycling pool.

Container sizes are reset to null values. Note: not memory operation is performed, the total amount of memory allocated is left untouched.

Parameters
SEXthe sex class of the individual
AGEthe index of the age class
popthe pointer to the metapop for access to the recycling pool
686  {
687  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
688  pop->recycle(_containers[SEX][AGE][i]);
689  _containers[SEX][AGE][i] = 0;
690  }
691  _sizes[SEX][AGE] = 0;
692  }
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:62

References _containers, _sizes, and IndFactory::recycle().

Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Breed_base::checkCloning(), LCE_Breed_base::checkSelfing(), LCE_Breed_Disperse::do_breed_disperse(), LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex(), LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex(), LCE_Patch_Extinction::do_flush(), LCE_Aging::execute(), flush(), LCE_Disperse_base::reset_counters(), and LCE_Breed_base::WrightFisherPopulation().

◆ get()

Individual* Patch::get ( sex_t  SEX,
age_idx  AGE,
unsigned int  at 
)
inline

Returns a pointer to the individual sitting at the index passed.

Note: the get operations are unchecked! It's up to the user to check for overflows.

Parameters
SEXthe sex class of the individual
AGEthe index of the age class
atthe index of the individual in the container
535  { return _containers[SEX][AGE][at]; }

References _containers.

Referenced by LCE_Selection_base::addPhenotypicSD(), copy2patch(), TTBDMI_SH::countAllele_diplo(), TTBDMI_SH::countAllele_haplo(), MPFileHandler::createAndPrintSample(), LCE_Breed_Selection::do_breed_selection_FecFitness(), LCE_Breed_Selection::do_breed_selection_OffSurvival(), LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex(), LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex(), LCE_Selection_base::doViabilitySelection(), LCE_Disperse_EvolDisp::evoldisp(), LCE_BreedAssortativeMating::execute(), TTDeletMutBitstrFH::FHwrite(), TTNOhtaStats::FHwrite(), TTQFreqExtractor::FHwrite(), TTQOhtaStats::FHwrite(), Metapop::fillPatchFromSource(), LCE_Resize::fillPatchWithBackup(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Breed_base::fullMonoginy(), LCE_Breed_base::fullPolyginy(), LCE_Breed_base::fullPolyginy_manyMales(), Metapop::get(), LCE_Breed_Disperse::get_parent(), TTNeutralGenesSH::getDxyPerPatch(), LCE_Selection_base::getMaxPatchFitness(), MPStatHandler::getMeanAssignedFecundity(), TTDispersalSH::getMeanDispRate(), TTDispersalSH::getMeanDispRateInPatch(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTWolbachiaSH::getMeanFemaleInfection_perPatch(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanMaleInfection_perPatch(), MPStatHandler::getMeanMatings(), TTWolbachiaSH::getMeanOffsprgFemaleInfection_perPatch(), TTWolbachiaSH::getMeanOffsprgInfection(), TTWolbachiaSH::getMeanOffsprgMaleInfection_perPatch(), LCE_Selection_base::getMeanPatchFitness(), TTDispersalSH::getOffsprgMeanDispRate(), TTDeletMutBitstrSH::getPatchLoad(), TTQuantiSH::getSNPalleleFreqInPatch(), TTQuantiSH::getVaNoDominance(), TTQuantiSH::getVaWithDominance(), LCE_Breed_Wolbachia::hasInfectedFemale(), LCE_Breed_Wolbachia::inoculate_wolbachia(), LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), LCE_Breed_base::partialMonoginy(), LCE_Breed_base::partialSelfing(), TTQuantiFH::print(), LCE_SelectionFH::print(), TTQuantiFH::print_PLINK_FAM(), TTNeutralGenesFH::print_PLINK_PED(), TTQuantiFH::print_PLINK_PED(), MPFileHandler::printNoSample(), LCE_Breed_base::random_hermaphrodite(), LCE_Breed_base::RandomMating(), LCE_Resize::regulateAgeClassNoBackup(), LCE_Resize::regulateAgeClassWithBackup(), LCE_Cross::sampleAmongPop(), TTNeutralGenesSH::setAdults_Theta(), TTNeutralGenesSH::setAlleleTables(), TTNeutralGenesSH::setCoaMatrix(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTDeletMutBitstrSH::setDeletStats(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), LCE_PhenotypeExpression::setIndPhenotype(), LCE_QuantiModifier::setIndPhenotype(), LCE_Breed_Quanti::setIndPhenotype(), TTWolbachiaSH::setInfectionStats(), MPStatHandler::setKinship(), TTDeletMutBitstrSH::setMeanViability(), MPStatHandler::setPedegreeCount(), MPStatHandler::setReproductiveStats(), LCE_Breed_Selection::setReproScaledFitness_gsl(), LCE_Breed_Selection::setReproScaledFitness_sum(), TTNeutralGenesSH::setSibStats(), TTDeletMutBitstrSH::setViability(), store_quanti_trait_values(), FileServices::subSamplePatch(), LCE_Breed_Wolbachia::wolbachia_model_1(), LCE_Breed_Wolbachia::wolbachia_model_2(), LCE_Breed_base::WrightFisherPopulation(), LCE_Breed_Quanti::WrightFisherPopulation(), TTBDMI_FH::write_diplo(), TTBDMI_FH::write_haplo(), TTNeutralGenesFH::write_patch_FSTAT(), TTNeutralGenesFH::write_patch_GENEPOP(), and TTNeutralGenesFH::write_patch_TAB().

◆ get_age()

unsigned int Patch::get_age ( )
inline
487 {return _age;}

References _age.

Referenced by LCE_Aging::execute(), and MPStatHandler::getPatchAge().

◆ get_isExtinct()

◆ get_K() [1/2]

◆ get_K() [2/2]

unsigned int Patch::get_K ( sex_t  SEX)
inline
483 {return (SEX ? _KFem : _KMal);}

References _KFem, and _KMal.

◆ get_KFem()

◆ get_KMal()

◆ getAdultsNumber()

unsigned int Patch::getAdultsNumber ( )
inline
489 {return size(ADLTx);}
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
@ ADLTx
Definition: types.h:42

References ADLTx, and size().

◆ getCopy()

void Patch::getCopy ( sex_t  SEX,
age_idx  AGE,
deque< Individual * > &  to 
)
inline
725  {
726  for (unsigned int i = 0; i < _sizes[SEX][AGE]; ++i) {
727  to.push_back(_containers[SEX][AGE][i]);
728  }
729  }

References _containers, and _sizes.

Referenced by LCE_BreedAssortativeMating::execute(), and LCE_Cross::execute().

◆ getDensity()

double Patch::getDensity ( age_idx  age)
inline
490 {return (double)size(age)/_K;}

References _K, and size().

◆ getID()

◆ init()

Patch * Patch::init ( unsigned int  nbfem,
unsigned int  nbmal,
unsigned int  id 
)
39 {
40  _ID = id;
41  _KFem = nbfem;
42  _KMal = nbmal;
43  _K = _KFem + _KMal;
44  _isExtinct = false;
45  _age = 0;
46 
48 
50 
51  return this;
52 }
void reset_containers()
Definition: patch.cc:66
void reset_counters()
Definition: patch.cc:56

Referenced by LCE_Resize::execute().

◆ isEmpty()

bool Patch::isEmpty ( )
inline
488 {return (size(ALL) == 0);}
#define ALL
All ages age class flag.
Definition: types.h:56

References ALL, and size().

◆ move() [1/2]

void Patch::move ( sex_t  SEX,
age_idx  from,
age_idx  to 
)
inline

Copies all elements in the 'from' age-class container to the 'to' age-class container of the same sex.

The previous elements of the 'to' container are overwritten, it is thus worth considering using flush() before moving to avoid memory leaks! After the call to move(), the size of the 'from' container is set to 0.

Parameters
SEXthe sex class of the individual
fromthe original age class of the individual
tothe destination age class of the individual
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  }
void clear()
Definition: metapop.h:675

References _capacities, _containers, _sizes, and clear().

◆ move() [2/2]

void Patch::move ( sex_t  SEX,
age_idx  from,
age_idx  to,
unsigned int  at 
)
inline

Moves an individual from an age class to an other one.

Note: both containers are transformed by this operation. The 'from' container size is reduced by one while the 'to' container size is increased by one.

Parameters
SEXthe sex class of the individual
fromthe original age class of the individual
tothe destination age class of the individual
atthe index of the individual in the container
612  {
613  add( SEX, to, _containers[SEX][from][at] );
614  remove( SEX, from, at );
615  }
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

References _containers, add(), and remove().

Referenced by LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex(), LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex(), LCE_Disperse_EvolDisp::evoldisp(), LCE_Aging::execute(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Disperse_base::swapPostDisp(), and LCE_Breed_base::WrightFisherPopulation().

◆ remove()

Individual* Patch::remove ( sex_t  SEX,
age_idx  AGE,
unsigned int  at 
)
inline

Removes the individual sitting at the given index in the appropriate container.

Parameters
SEXthe sex class of the individual
AGEthe index of the age class
atthe index of the individual in the container
Returns
pointer to the individual that has been removed
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  }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
int error(const char *str,...)
Definition: output.cc:77

References _containers, _sizes, and error().

Referenced by LCE_Patch_Extinction::do_remove(), LCE_Selection_base::doViabilitySelection(), LCE_Disperse_EvolDisp::evoldisp(), LCE_Resize::fillPatchWithBackup(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder(), move(), LCE_Resize::regulateAgeClassNoBackup(), LCE_Resize::regulateAgeClassWithBackup(), and LCE_Regulation::regulatePatch().

◆ reset_containers()

void Patch::reset_containers ( )
67 {
68  for(unsigned int i=0; i < _nb_age_class; i++) {
69  _containers[MAL][i].assign( _KMal, 0 );
70  _containers[FEM][i].assign( _KFem, 0 );
71  _sizes[MAL][i] = 0;
72  _sizes[FEM][i] = 0;
73  _capacities[MAL][i] = _KMal;
74  _capacities[FEM][i] = _KFem;
75  }
76 }

References FEM, and MAL.

◆ reset_counters()

void Patch::reset_counters ( )
57 {
58  nbEmigrant = 0;
59  nbImigrant = 0;
60  nbPhilopat = 0;
61  nbKolonisers = 0;
62 }

Referenced by LCE_Disperse_base::reset_counters().

◆ resize()

void Patch::resize ( sex_t  SEX,
age_idx  AGE,
size_t  new_size 
)
inline

Reserves a certain range of values that are assigned to 0 in a given container.

Container's size is set to the new size, thus add() will not fill from [0] but from [size]. the new_size first elements of the container ARE NOT reset to NULL. It is best to use set() to then fill the patch from [0] -> [new_size-1]

Parameters
SEXthe sex class of the individual
AGEthe index of the age class
new_sizethe new size of the container
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  }

References _capacities, _containers, and _sizes.

Referenced by LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex(), LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex(), and LCE_Breed_base::WrightFisherPopulation().

◆ set()

void Patch::set ( sex_t  SEX,
age_idx  AGE,
unsigned int  at,
Individual ind 
)
inline

Modifies the appropriate container with value of the pointer given.

Parameters
SEXthe sex class of the individual
AGEthe index of the age class
atthe index of the individual in the container
indthe pointer to the individual
544  { _containers[SEX][AGE][at] = ind; }

References _containers.

Referenced by LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex(), LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex(), and LCE_Breed_base::WrightFisherPopulation().

◆ set_age()

void Patch::set_age ( unsigned int  a)
inline
477 {_age = a;}

References _age.

Referenced by LCE_Patch_Extinction::do_flush(), and LCE_Aging::execute().

◆ set_isExtinct()

void Patch::set_isExtinct ( bool  status)
inline
476 {_isExtinct = status;}

References _isExtinct.

Referenced by LCE_Patch_Extinction::do_flush(), and LCE_Aging::execute().

◆ set_K()

void Patch::set_K ( unsigned int  k)
inline
473 {_K = k;}

References _K.

Referenced by FileServices::getSampledPop().

◆ set_KFem()

void Patch::set_KFem ( unsigned int  k)
inline

◆ set_KMal()

void Patch::set_KMal ( unsigned int  k)
inline

◆ setID()

void Patch::setID ( unsigned int  i)
inline
472 {_ID = i;}

References _ID.

Referenced by FileServices::getSampledPop().

◆ setNewGeneration() [1/2]

void Patch::setNewGeneration ( age_idx  AGE,
Metapop pop 
)

Fills the patch container corresponding to the age class index passed, for both sexes.

93 {
94  Individual *new_ind;
95 
96  //--------------------------------------------------------------------
97  //if too much females in the Patch, flush them into the RecyclingPOOL
98  if(size(FEM, AGE) > 0) flush(FEM, AGE, pop);
99 
100  for(unsigned int i = 0; i < _KFem; i++) {
101  new_ind = pop->makeNewIndividual(0,0,FEM,_ID);
102  new_ind->create_first_gen();
103  add(FEM, AGE, new_ind);
104  }
105 
106  //--------------------------------------------------------------------
107  //males: same as for the females....
108  if(size(MAL, AGE) > 0) flush(MAL, AGE, pop);
109 
110  for(unsigned int i = 0; i < _KMal; i++) {
111  new_ind = pop->makeNewIndividual(0,0,MAL,_ID);
112  new_ind->create_first_gen();
113  add(MAL, AGE, new_ind);
114  }
115 
116 }
Individual * makeNewIndividual(Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Creates an individual with pointers to parents, sex and home ID set but no genetic data.
Definition: indfactory.cc:152
Individual * create_first_gen()
Creates an individual's genotypes and phenotypes for first generation.
Definition: individual.h:348

References Individual::create_first_gen(), FEM, IndFactory::makeNewIndividual(), and MAL.

◆ setNewGeneration() [2/2]

void Patch::setNewGeneration ( age_t  AGE,
Metapop pop 
)

Fills the patch containers corresponding to the age flags passed, for both sexes.

81 {
82  unsigned int mask = 1;
83 
84  for(unsigned int i = 0; i < _nb_age_class; i++) {
85  if( (mask & AGE) != 0) setNewGeneration(static_cast<age_idx>(i), pop);
86  mask<<=1;
87  }
88 }
void setNewGeneration(age_t AGE, Metapop *pop)
Fills the patch containers corresponding to the age flags passed, for both sexes.
Definition: patch.cc:80

◆ show_up()

void Patch::show_up ( )
135 {
136  message("Patch %i:\n age: %i; K: %i, K_fem: %i; K_mal: %i\n",_ID, _age, _K, _KFem, _KMal);
137  for(unsigned int j = 0; j < _nb_age_class; ++j)
138  message(" age class %i: females: %i; males: %i\n", j, _sizes[FEM][j], _sizes[MAL][j]);
139 }
void message(const char *message,...)
Definition: output.cc:40

References FEM, MAL, and message().

◆ size() [1/4]

unsigned int Patch::size ( age_idx  AGE)
inline

Returns the size of the container for the appropriate age class for both sexes.

Parameters
AGEthe index of the age class
526  { return _sizes[0][AGE] + _sizes[1][AGE]; }

References _sizes.

◆ size() [2/4]

unsigned int Patch::size ( age_t  AGE)
inline

Returns the size of the container of the appropriate age class(es) for both sexes.

Parameters
AGEthe flag value of the age class
499  { return size(MAL,AGE) + size(FEM,AGE); }

References FEM, and MAL.

Referenced by LCE_Selection_base::addPhenotypicSD(), LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Breed_base::checkCloning(), LCE_Breed_base::checkNoSelfing(), LCE_Breed_base::checkPolygyny(), LCE_Breed_base::checkSelfing(), LCE_Breed_Disperse::conditionalLogisticGrowth(), LCE_Breed_Disperse::conditionalStochasticLogisticGrowth(), TTBDMI_SH::countAllele_diplo(), TTBDMI_SH::countAllele_haplo(), MPFileHandler::createAndPrintSample(), LCE_Breed_Selection_Disperse::do_breed(), LCE_Breed_Disperse::do_breed_disperse(), LCE_Breed_Selection::do_breed_selection_FecFitness(), LCE_Breed_Selection::do_breed_selection_OffSurvival(), LCE_Breed_Selection::do_breed_selection_WrightFisher_1sex(), LCE_Breed_Selection::do_breed_selection_WrightFisher_2sex(), LCE_Patch_Extinction::do_remove(), LCE_Selection_base::doViabilitySelection(), LCE_Disperse_EvolDisp::evoldisp(), LCE_BreedAssortativeMating::execute(), LCE_Disperse_EvolDisp::execute(), LCE_Aging::execute(), LCE_Patch_Extinction::execute(), LCE_Cross::execute(), LCE_Breed_Disperse::exponentialGrowth(), LCE_SelectionFH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTNOhtaStats::FHwrite(), TTQFreqExtractor::FHwrite(), TTQOhtaStats::FHwrite(), Metapop::fillPatchFromSource(), LCE_Resize::fillPatchNoBackup(), LCE_Resize::fillPatchWithBackup(), LCE_Disperse_EvolDisp::fixdisp(), LCE_Breed_Disperse::fixedFecundityGrowth(), LCE_Breed_base::fullMonoginy(), LCE_Breed_base::fullPolyginy_manyMales(), LCE_Patch_Extinction::get_harvest_size(), LCE_Breed_Disperse::get_parent(), getAdultsNumber(), getDensity(), TTNeutralGenesSH::getDxyPerPatch(), TTDeletMutBitstrSH::getLoad(), LCE_Selection_base::getMaxPatchFitness(), MPStatHandler::getMeanAssignedFecundity(), TTDispersalSH::getMeanDispRate(), TTDispersalSH::getMeanDispRateInPatch(), TTDeletMutBitstrSH::getMeanFecWithPatchMate(), TTWolbachiaSH::getMeanFemaleInfection_perPatch(), TTDispersalSH::getMeanFemDispRate(), LCE_Selection_base::getMeanFitness(), TTDispersalSH::getMeanMalDispRate(), TTWolbachiaSH::getMeanMaleInfection_perPatch(), MPStatHandler::getMeanMatings(), TTWolbachiaSH::getMeanOffsprgFemaleInfection_perPatch(), TTWolbachiaSH::getMeanOffsprgInfection(), TTWolbachiaSH::getMeanOffsprgMaleInfection_perPatch(), LCE_Selection_base::getMeanPatchFitness(), LCE_SelectionSH::getMeanPatchFitness(), TTDispersalSH::getOffsprgMeanDispRate(), TTDeletMutBitstrSH::getPatchLoad(), TTQuantiSH::getSNPalleleFreqInPatch(), TTQuantiSH::getVaNoDominance(), LCE_SelectionSH::getVarPatchFitness(), TTQuantiSH::getVaWithDominance(), LCE_Breed_Wolbachia::hasInfectedFemale(), isEmpty(), LCE_Breed_Disperse::logisticGrowth(), LCE_Breed_Disperse::mate_selfing(), LCE_Disperse_ConstDisp::Migrate(), LCE_Disperse_ConstDisp::MigratePatch(), LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder(), LCE_Disperse_ConstDisp::MigratePatchByNumber(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), LCE_Breed_Disperse::numFemOffspring(), LCE_Breed_Disperse::numMalOffspring_random(), LCE_Breed_base::partialMonoginy(), LCE_Breed_base::partialSelfing(), TTQuantiFH::print(), LCE_SelectionFH::print(), TTQuantiFH::print_PLINK_FAM(), TTNeutralGenesFH::print_PLINK_PED(), TTQuantiFH::print_PLINK_PED(), MPFileHandler::printNoSample(), LCE_Breed_base::random_hermaphrodite(), LCE_Breed_base::RandomMating(), LCE_Resize::regulateAgeClassNoBackup(), LCE_Resize::regulateAgeClassWithBackup(), LCE_Regulation::regulatePatch(), LCE_Cross::sampleAmongPop(), LCE_Cross::sampleWithinPop(), LCE_Selection_base::set_std_rate_of_change(), TTNeutralGenesSH::setAdults_Theta(), TTNeutralGenesSH::setAlleleTables(), TTNeutralGenesSH::setCoaMatrix(), LCE_SelectionSH::setDataTable(), TTQuantiSH::setDataTables(), TTDeletMutBitstrSH::setDeletStats(), TTDeletMutBitstrSH::setFst(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), LCE_PhenotypeExpression::setIndPhenotype(), LCE_QuantiModifier::setIndPhenotype(), LCE_Breed_Quanti::setIndPhenotype(), TTWolbachiaSH::setInfectionStats(), MPStatHandler::setKinship(), TTDeletMutBitstrSH::setMeanViability(), MPStatHandler::setPedegreeCount(), MPStatHandler::setReproductiveStats(), TTNeutralGenesSH::setSibStats(), TTBDMI_SH::setStats(), TTDeletMutBitstrSH::setViability(), Metapop::size(), LCE_Breed_Disperse::stochasticFecundityGrowth(), FileServices::subSamplePatch(), LCE_Breed_Wolbachia::wolbachia_model_1(), LCE_Breed_Wolbachia::wolbachia_model_2(), LCE_Breed_base::WrightFisherPopulation(), LCE_Breed_Quanti::WrightFisherPopulation(), TTBDMI_FH::write_diplo(), TTBDMI_FH::write_haplo(), TTNeutralGenesFH::write_patch_FSTAT(), TTNeutralGenesFH::write_patch_GENEPOP(), TTNeutralGenesFH::write_patch_TAB(), and TTQuantiFH::write_TABLE().

◆ size() [3/4]

unsigned int Patch::size ( sex_t  SEX,
age_idx  AGE 
)
inline

Returns the size of the container for the appropriate sex and age class.

Parameters
SEXthe sex class
AGEthe index of the age class
520  { return _sizes[SEX][AGE]; }

References _sizes.

◆ size() [4/4]

unsigned int Patch::size ( sex_t  SEX,
age_t  AGE 
)
inline

Returns the size of the container for the appropriate sex and age classes present in the age flag.

Parameters
SEXthe sex class
AGEthe flag value of the age class
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  }

References _nb_age_class, and _sizes.

◆ swap_new()

void Patch::swap_new ( sex_t  SEX,
age_idx  from,
age_idx  to 
)
inline

Swaps elements between two containers, 'from' age-class container and the 'to' age-class container of the same sex.

No elements are overwritten.

Parameters
SEXthe sex class of the individual
fromthe original age class of the individual
tothe destination age class of the individual
646  {
647  deque<Individual*> temp(_containers[SEX][to].begin(), _containers[SEX][to].end());
648 
649  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
650  _containers[SEX][to].resize( _sizes[SEX][from] );
651  _capacities[SEX][to] = _sizes[SEX][from];
652  }
653 
654  _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].end());
655  _sizes[SEX][to] = _containers[SEX][to].size();
656 
657  if( _sizes[SEX][to] > _capacities[SEX][from] ) {
658  _capacities[SEX][from] = _sizes[SEX][to];
659  }
660 
661  _containers[SEX][from].assign(temp.begin(), temp.end());
662  _sizes[SEX][from] = _containers[SEX][from].size();
663  }

References _capacities, _containers, and _sizes.

Member Data Documentation

◆ _age

unsigned int Patch::_age
private

age since last extinction.

Referenced by get_age(), and set_age().

◆ _capacities

unsigned int Patch::_capacities[2][3]
private

Total size of the containers, amount of allocated memory.

Referenced by add(), assign(), move(), Patch(), resize(), and swap_new().

◆ _containers

deque<Individual*> Patch::_containers[2][3]
private

Individuals containers, sex X age.

Referenced by add(), assign(), copy2patch(), flush(), get(), getCopy(), move(), remove(), resize(), set(), and swap_new().

◆ _ID

unsigned int Patch::_ID
private

Patch ID is equal to its position in the metapop patch array.

Referenced by getID(), and setID().

◆ _isExtinct

bool Patch::_isExtinct
private

Extinction flag.

Referenced by get_isExtinct(), and set_isExtinct().

◆ _K

unsigned int Patch::_K
private

Carrying capacity for males and females.

Referenced by add(), get_K(), getDensity(), and set_K().

◆ _KFem

unsigned int Patch::_KFem
private

Sex specific carrying capacity.

Referenced by get_K(), get_KFem(), and set_KFem().

◆ _KMal

unsigned int Patch::_KMal
private

Referenced by get_K(), get_KMal(), and set_KMal().

◆ _nb_age_class

unsigned int Patch::_nb_age_class
private

Number of age classes present.

Referenced by copy2patch(), flush(), Patch(), and size().

◆ _sizes

unsigned int Patch::_sizes[2][3]
private

Containers size counters, sex X age.

Referenced by add(), assign(), clear(), copy2patch(), flush(), getCopy(), move(), Patch(), remove(), resize(), size(), and swap_new().

◆ nbEmigrant

◆ nbImigrant

◆ nbKolonisers

◆ nbPhilopat


The documentation for this class was generated from the following files:

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