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

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

◆ ~Patch()

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

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.

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

References _capacities, _containers, and _sizes.

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

+ Here is the caller graph for this function:

◆ 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().

+ Here is the caller graph for this function:

◆ 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().

+ Here is the caller graph for this function:

◆ 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:39

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:549

References _containers, _sizes, and add().

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

+ Here is the caller graph for this function:

◆ 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:532

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:60

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_Breed_base::doAgingInWFpop(), LCE_Aging::execute(), flush(), LCE_Disperse_ConstDisp::MigratePatchByNumber(), LCE_Disperse_base::reset_counters(), and LCE_Breed_base::WrightFisherPopulation().

+ Here is the caller graph for this function:

◆ 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
533  { 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(), GenotyperFH::prepare_data_table(), TTQuantiFH::print(), LCE_SelectionFH::print(), GenotyperFH::print_genotypes(), GenotyperFH::print_PLINK(), TTQuantiFH::print_PLINK_FAM(), TTNeutralGenesFH::print_PLINK_PED(), TTQuantiFH::print_PLINK_PED(), GenotyperFH::print_snp_genotypes(), GenotyperFH::print_snp_id(), 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(), TTDeletMutBitstrSH::setDeletStats(), TTNeutralGenesSH::setFstat_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham_bitstring(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), LCE_PhenotypeExpression::setIndLiability(), LCE_PhenotypeExpression::setIndLiability_evolving(), LCE_PhenotypeExpression::setIndLiability_evolving_sigmoid(), LCE_PhenotypeExpression::setIndLiability_sigmoid(), LCE_PhenotypeExpression::setIndPhenotype(), LCE_QuantiModifier::setIndPhenotype(), LCE_Breed_Quanti::setIndPhenotype(), LCE_PhenotypeExpression::setIndPhenotype_labile(), TTWolbachiaSH::setInfectionStats(), MPStatHandler::setKinship(), TTDeletMutBitstrSH::setMeanViability(), MPStatHandler::setPedegreeCount(), MPStatHandler::setReproductiveStats(), LCE_Breed_Selection::setReproScaledFitness_gsl(), LCE_Breed_Selection::setReproScaledFitness_sum(), LCE_Selection_base::setScalingFactorForLinearSelection(), 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
485 {return _age;}

References _age.

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

+ Here is the caller graph for this function:

◆ get_isExtinct()

◆ get_K() [1/2]

◆ get_K() [2/2]

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

References _KFem, and _KMal.

◆ get_KFem()

unsigned int Patch::get_KFem ( )
inline

◆ get_KMal()

unsigned int Patch::get_KMal ( )
inline

◆ getAdultsNumber()

unsigned int Patch::getAdultsNumber ( )
inline
487 {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:496
@ ADLTx
Definition: types.h:40

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().

+ Here is the caller graph for this function:

◆ getDensity()

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

References _K, and size().

◆ getID()

◆ init()

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

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ isEmpty()

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

References ALL, and size().

Referenced by LCE_Breed_base::doAgingInWFpop(), LCE_Breed_Disperse::numFemOffspring_colonizers(), and LCE_Breed_Disperse::numMalOffspring_random_colonizers().

+ Here is the caller graph for this function:

◆ 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
623  {
624  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
625  _containers[SEX][to].resize( _sizes[SEX][from] );
626  _capacities[SEX][to] = _sizes[SEX][from];
627  }
628 
629  for(unsigned int i = 0; i < _sizes[SEX][from]; ++i)
630  _containers[SEX][to][i] = _containers[SEX][from][i];
631 // _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].end());
632 
633  _sizes[SEX][to] = _sizes[SEX][from];
634  clear(SEX, from);
635  }
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
610  {
611  add( SEX, to, _containers[SEX][from][at] );
612  remove( SEX, from, at );
613  }
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:586

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

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

+ Here is the caller graph for this function:

◆ 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
587  {
588  if(_sizes[SEX][AGE] == 0) {
589  error("Patch::remove:: container already empty!!");
590  return NULL;
591  }
592  unsigned int last = _sizes[SEX][AGE] - 1;
593  Individual* ind = _containers[SEX][AGE][at];
594  _containers[SEX][AGE][at] = _containers[SEX][AGE][ last ];
595  _containers[SEX][AGE][ last ] = 0;
596  _sizes[SEX][AGE]--;
597  return ind;
598  }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
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().

+ Here is the caller graph for this function:

◆ reset_containers()

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

References FEM, and MAL.

◆ reset_counters()

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

Referenced by LCE_Disperse_base::reset_counters().

+ Here is the caller graph for this function:

◆ 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
573  {
574  if( new_size > _capacities[SEX][AGE] ) {
575  _containers[SEX][AGE].resize( new_size );
576  _capacities[SEX][AGE] = new_size;
577  }
578  _sizes[SEX][AGE] = new_size;
579  }

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().

+ Here is the caller graph for this function:

◆ 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
542  { _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().

+ Here is the caller graph for this function:

◆ set_age()

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

References _age.

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

+ Here is the caller graph for this function:

◆ set_isExtinct()

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

References _isExtinct.

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

+ Here is the caller graph for this function:

◆ set_K()

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

References _K.

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ set_KFem()

void Patch::set_KFem ( unsigned int  k)
inline
472 {_KFem = k;}

References _KFem.

Referenced by FileServices::getSampledPop(), and LCE_Resize::updatePatchCapacities().

+ Here is the caller graph for this function:

◆ set_KMal()

void Patch::set_KMal ( unsigned int  k)
inline
473 {_KMal = k;}

References _KMal.

Referenced by FileServices::getSampledPop(), and LCE_Resize::updatePatchCapacities().

+ Here is the caller graph for this function:

◆ setID()

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

References _ID.

Referenced by FileServices::getSampledPop().

+ Here is the caller graph for this function:

◆ 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.

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

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.

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

◆ show_up()

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

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
524  { 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
497  { 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_base::partialMonoginy(), LCE_Breed_base::partialSelfing(), GenotyperFH::prepare_data_table(), TTQuantiFH::print(), LCE_SelectionFH::print(), GenotyperFH::print_genotypes(), GenotyperFH::print_PLINK(), TTQuantiFH::print_PLINK_FAM(), TTNeutralGenesFH::print_PLINK_PED(), TTQuantiFH::print_PLINK_PED(), GenotyperFH::print_snp_genotypes(), GenotyperFH::print_snp_id(), 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::setFstat_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham_bitstring(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), LCE_PhenotypeExpression::setIndLiability(), LCE_PhenotypeExpression::setIndLiability_evolving(), LCE_PhenotypeExpression::setIndLiability_evolving_sigmoid(), LCE_PhenotypeExpression::setIndLiability_sigmoid(), LCE_PhenotypeExpression::setIndPhenotype(), LCE_QuantiModifier::setIndPhenotype(), LCE_Breed_Quanti::setIndPhenotype(), LCE_PhenotypeExpression::setIndPhenotype_labile(), TTWolbachiaSH::setInfectionStats(), MPStatHandler::setKinship(), TTDeletMutBitstrSH::setMeanViability(), MPStatHandler::setPedegreeCount(), MPStatHandler::setReproductiveStats(), LCE_Selection_base::setScalingFactorForLinearSelection(), 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
518  { 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
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  }

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
644  {
645  deque<Individual*> temp(_containers[SEX][to].begin(), _containers[SEX][to].end());
646  unsigned int to_size = _sizes[SEX][to];
647 
648  if( _sizes[SEX][from] > _capacities[SEX][to] ) {
649  _containers[SEX][to].resize( _sizes[SEX][from] );
650  _capacities[SEX][to] = _sizes[SEX][from];
651  }
652 
653  // copy content of 'from' into 'to', but restrict to the 'size' of 'from' to not copy over the actual number of individuals
654  _containers[SEX][to].assign(_containers[SEX][from].begin(), _containers[SEX][from].begin() + _sizes[SEX][from]);
655  _sizes[SEX][to] = _containers[SEX][to].size(); // this should be equal to _sizes[SEX][from]
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.begin()+to_size);
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.2 by  doxygen 1.9.1

Catalogued on GSR