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

Factory of Individual, stores the individual prototype and the trait prototypes, manages the individual garbage collector. More...

#include <indfactory.h>

+ Inheritance diagram for IndFactory:
+ Collaboration diagram for IndFactory:

Public Member Functions

 IndFactory ()
 
virtual ~IndFactory ()
 
void recycle (Individual *ind)
 Put an individual in the recycling pool. More...
 
void purgeRecyclingPOOL ()
 Empty the recycling pool. More...
 
void makePrototype (map< trait_t, TraitPrototype * > TTlist)
 Creates the individuals prototype from the selected trait prototypes. More...
 
void clearPrototype ()
 Reset the trait prototypes, mostly done to unregister the genetic maps. More...
 
IndividualgetPrototypeClone ()
 Return an uninitialized copy of the individual prototype. More...
 
IndividualgetNewIndividual ()
 Creates a blank individual which has to be "decorated" later. More...
 
IndividualmakeNewIndividual (Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
 Creates an individual from existing pointer with new ID. More...
 
IndividualdecorateNewIndividual (Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
 Sets the internals of a new individual with pointers to parents, sex and home ID set. More...
 
IndividualmakeNewIndividual (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. More...
 
IndividualmakeOffsprg (Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
 Completely creates an individual with inheritance and mutations on all traits. More...
 
IndividualgetIndividualProtoype ()
 Individual prototype accessor. More...
 
TraitPrototypegetTraitPrototype (trait_t type)
 Accessor to a TraitPrototype. More...
 
std::map< trait_t, TraitPrototype * > & getTraitPrototypes ()
 Accessor to the list of TraitPrototype's. More...
 
int getTraitIndex (trait_t type)
 Gives the index of trait with type. More...
 

Protected Attributes

std::map< trait_t, TraitPrototype * > _protoTraits
 Map of the trait prototypes. More...
 
std::map< trait_t, int > _TraitsIndex
 Table containing the index of each trait. More...
 
Individual _protoIndividual
 The individuals prototype used to create any new individual in a simulation. More...
 
std::deque< Individual * > RecyclingPOOL
 Garbage collector for unused Individual's. More...
 

Detailed Description

Factory of Individual, stores the individual prototype and the trait prototypes, manages the individual garbage collector.

Provides methods to generate new individuals within the Metapop. Each new individual is created by cloning a prototype itself created at the simulation setup. New individuals are decorated with the appropriate traits as set by the trait prototypes and receives a unique ID (unique within a simulation).

Constructor & Destructor Documentation

◆ IndFactory()

IndFactory::IndFactory ( )
inline
57 { };

◆ ~IndFactory()

IndFactory::~IndFactory ( )
virtual
36 {
38 
40 
41  _protoTraits.clear(); //the proto traits are deallocated within ~SimBuilder
42 
43  _TraitsIndex.clear();
44 
45 }
std::map< trait_t, int > _TraitsIndex
Table containing the index of each trait.
Definition: indfactory.h:47
std::map< trait_t, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:45
void purgeRecyclingPOOL()
Empty the recycling pool.
Definition: indfactory.h:65
Individual _protoIndividual
The individuals prototype used to create any new individual in a simulation.
Definition: indfactory.h:50
void clearTraits()
Clears the traits container.
Definition: individual.h:299

Member Function Documentation

◆ clearPrototype()

void IndFactory::clearPrototype ( )

Reset the trait prototypes, mostly done to unregister the genetic maps.

103 {
104 #ifdef _DEBUG_
105  message("IndFactory::clearPrototype\n");
106 #endif
107 
108  //clear the ttraits:
110 
111  map< trait_t, TraitPrototype* >::iterator trait = _protoTraits.begin();
112 
113  while(trait != _protoTraits.end()) {
114 
115  trait->second->reset();
116 
117  trait++;
118  }
119 
120  _protoTraits.clear();
121  _TraitsIndex.clear();
123 }
void clear()
Definition: ttrait_with_map.cc:682
static GeneticMap _map
Definition: ttrait_with_map.h:208
void message(const char *message,...)
Definition: output.cc:39

References TTProtoWithMap::_map, GeneticMap::clear(), and message().

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ decorateNewIndividual()

Individual * IndFactory::decorateNewIndividual ( Individual newind,
Individual mother,
Individual father,
sex_t  sex,
unsigned short  homepatch 
)

Sets the internals of a new individual with pointers to parents, sex and home ID set.

No inheritance or mutations on the trait sequences are done here (see makeOffsprg for that). If newing is NULL, then 'makeNewIndividual() is called to generate a new pointer.

Parameters
newindptr to the new individual
motherptr to the mother
fatherptr to the father
sexgender of the individual
homepatchID of the Patch where this individual is born, usually the current position in the Metapop::vPatch array.
181 {
182  if(!newind) return makeNewIndividual(newind, mother, father, sex, homepatch);
183 
184  newind->setAge(0);
185  newind->setSex(sex);
186  newind->setHome(homepatch);
187 
188  if(mother != NULL && father != NULL) {
189  newind->setFatherID(father->getID());
190  newind->setMotherID(mother->getID());
191  newind->setFather(father);
192  newind->setMother(mother);
193  newind->setPedigreeClass(mother, father);
194  }
195 
196  return newind;
197 }
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:151
void setFather(Individual *f)
Definition: individual.h:108
unsigned long getID()
Definition: individual.h:121
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:114
void setMother(Individual *m)
Definition: individual.h:109
void setHome(unsigned short value)
Definition: individual.h:110
void setMotherID(unsigned long value)
Definition: individual.h:107
void setSex(sex_t sex)
Definition: individual.h:111
void setFatherID(unsigned long value)
Definition: individual.h:106
void setAge(unsigned short value)
Definition: individual.h:104

References Individual::getID(), Individual::setAge(), Individual::setFather(), Individual::setFatherID(), Individual::setHome(), Individual::setMother(), Individual::setMotherID(), Individual::setPedigreeClass(), and Individual::setSex().

Referenced by LCE_Breed_base::makeOffspring().

+ Here is the caller graph for this function:

◆ getIndividualProtoype()

Individual* IndFactory::getIndividualProtoype ( )
inline

Individual prototype accessor.

131 {return &_protoIndividual;}

References _protoIndividual.

Referenced by LCE_Breed_Selection::setNonSelectedTraitTable().

+ Here is the caller graph for this function:

◆ getNewIndividual()

Individual* IndFactory::getNewIndividual ( )
inline

Creates a blank individual which has to be "decorated" later.

ID is set and new traits are allocated but no genetic data is created (i.e. TTrait::init_sequence() is not called). Sex has to be set later too.

84 {return makeNewIndividual(NULL,NULL,MAL,0);}
@ MAL
Definition: types.h:36

References makeNewIndividual(), and MAL.

Referenced by LCE_Breed_base::breed_cloning(), Metapop::fillPatchFromSource(), Metapop::fillPopulationFromSource(), Metapop::loadPopFromBinarySource(), and Metapop::retrieve_data().

+ Here is the caller graph for this function:

◆ getPrototypeClone()

Individual* IndFactory::getPrototypeClone ( )
inline

Return an uninitialized copy of the individual prototype.

78 {return _protoIndividual.clone();}
Individual * clone()
Cloning procedure, clones all the traits present in the individual.
Definition: individual.cc:149

References _protoIndividual, and Individual::clone().

Referenced by LCE_Cross::generatePedigree().

+ Here is the caller graph for this function:

◆ getTraitIndex()

int IndFactory::getTraitIndex ( trait_t  type)

Gives the index of trait with type.

Parameters
typethe type of the trait (i.e. its "name")
128 {
129  map< trait_t, int >::iterator trait = _TraitsIndex.find(type);
130 
131  if(trait == _TraitsIndex.end())
132  return -1;
133 
134  return trait->second;
135 }

Referenced by LifeCycleEvent::attach_trait(), TTDispersalSH::init(), TTQuantiSH::init(), SimRunner::run(), LCE_BreedAssortativeMating::setParameters(), LCE_Disperse_EvolDisp::setParameters(), and LCE_Selection_base::setParameters().

+ Here is the caller graph for this function:

◆ getTraitPrototype()

TraitPrototype * IndFactory::getTraitPrototype ( trait_t  type)

◆ getTraitPrototypes()

std::map< trait_t,TraitPrototype* >& IndFactory::getTraitPrototypes ( )
inline

Accessor to the list of TraitPrototype's.

139 {return _protoTraits;}

References _protoTraits.

Referenced by Metapop::loadPopFromTraitFile(), and Metapop::store_data().

+ Here is the caller graph for this function:

◆ makeNewIndividual() [1/2]

Individual * IndFactory::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.

No inheritance or mutations on the trait sequences are done. Sets the pedigree class of the individual. Calls Individual::init() to allocate traits' sequences memory if individual is cloned from the prototype. Otherwise, calls Individual::reset() if the new individual is coming from the recycling pool.

Parameters
motherptr to the mother
fatherptr to the father
sexgender of the individual
homepatchID of the Patch where this individual is born, usually the current position in the Metapop::vPatch array.
202 {
203  Individual* newind;
204 
205  if(RecyclingPOOL.empty()) {
206  //create new Individual by cloning the proto-individual
207  newind = _protoIndividual.clone();
208  //allocate memory for the traits' sequences:
209  newind->init();
210  } else {
211  //recycle an Individual from the POOL
212  newind = RecyclingPOOL[0];
213  RecyclingPOOL.pop_front();
214  newind->reset();
215  newind->setID(Individual::currentID++);
216  }
217 
218  newind->setSex(sex);
219  newind->setHome(homepatch);
220  if(mother != NULL && father != NULL) {
221  newind->setFatherID(father->getID());
222  newind->setMotherID(mother->getID());
223  newind->setFather(father);
224  newind->setMother(mother);
225  newind->setPedigreeClass(mother, father);
226  }
227 
228  return newind;
229 }
std::deque< Individual * > RecyclingPOOL
Garbage collector for unused Individual's.
Definition: indfactory.h:53
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
Individual * init()
Inits parameters and traits.
Definition: individual.cc:52
void setID(unsigned long value)
Definition: individual.h:103
static unsigned long currentID
The ID counter, reset at the beginning of each simulation.
Definition: individual.h:82
void reset()
Resets parameters and traits values.
Definition: individual.cc:78

References Individual::clone(), Individual::currentID, Individual::getID(), Individual::init(), Individual::reset(), Individual::setFather(), Individual::setFatherID(), Individual::setHome(), Individual::setID(), Individual::setMother(), Individual::setMotherID(), Individual::setPedigreeClass(), and Individual::setSex().

◆ makeNewIndividual() [2/2]

Individual * IndFactory::makeNewIndividual ( Individual newind,
Individual mother,
Individual father,
sex_t  sex,
unsigned short  homepatch 
)

Creates an individual from existing pointer with new ID.

A new pointer is generated if newind is NULL, by calling the other version of makeNewIndividual No inheritance or mutations on the trait sequences are done. Returns the individual after a call to decorateNewIndividual() which sets the internal state of the individual.

Parameters
newingptr to new individual
motherptr to the mother
fatherptr to the father
sexgender of the individual
homepatchID of the Patch where this individual is born, usually the current position in the Metapop::vPatch array.
153 {
154 
155  if(!newind) {
156  if(RecyclingPOOL.empty()) {
157  //create new Individual by cloning the proto-individual
158  newind = _protoIndividual.clone();
159  //allocate memory for the traits' sequences:
160  newind->init();
161  } else {
162  //recycle an Individual from the POOL
163  newind = RecyclingPOOL[0];
164  RecyclingPOOL.pop_front();
165  newind->reset();
166  newind->setID(Individual::currentID++);
167  }
168  } else {
169  //new individual exists and is passed as argument (in-place creation from existing pointer in patch container)
170  newind->reset();
171  newind->setID(Individual::currentID++);
172  }
173 
174  return decorateNewIndividual(newind, mother, father, sex, homepatch);
175 }
Individual * decorateNewIndividual(Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Sets the internals of a new individual with pointers to parents, sex and home ID set.
Definition: indfactory.cc:179

References Individual::clone(), Individual::currentID, Individual::init(), Individual::reset(), and Individual::setID().

Referenced by LCE_Breed_base::breed(), LCE_Breed_base::breed_cloning(), LCE_Cross::create_individual_ancestors(), TTDeletMutBitstrFH::FHread(), TTNeutralGenesFH::FHread(), TTQuantiFH::FHread(), LCE_Resize::fillPatchNoBackup(), getNewIndividual(), LCE_Breed_Disperse::mate_full_selfing(), LCE_Breed_Disperse::mate_random(), LCE_Breed_Disperse::mate_random_hermaphrodite(), LCE_Breed_Disperse::mate_selfing(), and Patch::setNewGeneration().

+ Here is the caller graph for this function:

◆ makeOffsprg()

Individual * IndFactory::makeOffsprg ( Individual mother,
Individual father,
sex_t  sex,
unsigned short  homepatch 
)

Completely creates an individual with inheritance and mutations on all traits.

Calls makeNewIndividual() to get the new offspring.

Parameters
motherptr to the mother
fatherptr to the father
sexgender of the individual
homepatchID of the Patch where this individual is born, usually the current position in the Patch array
234 {
235  Individual* offspring = makeNewIndividual(mother,father,sex,homepatch);
236  unsigned int cat = offspring->getPedigreeClass();
237  mother->DidHaveABaby(cat);
238  if(cat!=4) father->DidHaveABaby(cat);
239  return offspring->create(mother, father);
240 }
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:361
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:224
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:178

References Individual::create(), Individual::DidHaveABaby(), and Individual::getPedigreeClass().

Referenced by LCE_Cross::sampleAmongPop(), LCE_Cross::sampleWithinPop(), LCE_Breed_Wolbachia::wolbachia_model_1(), and LCE_Breed_Wolbachia::wolbachia_model_2().

+ Here is the caller graph for this function:

◆ makePrototype()

void IndFactory::makePrototype ( map< trait_t, TraitPrototype * >  TTlist)

Creates the individuals prototype from the selected trait prototypes.

Resets the individual's ID counter to 0 and sets the traits index table.

Parameters
TTlistthe list of the current trait prototype selected from the current simulation parameters.
50 {
51 #ifdef _DEBUG_
52  message("IndFactory::makePrototype\n");
53 #endif
54 
55  //first, reset the ID counter:
57 
58  //store the traits list for future use:
59  _protoTraits = TTlist;
60 
61  //then add the traits from the trait prototypes:
62  map< trait_t, TraitPrototype* >::iterator trait = TTlist.begin();
63 
64  _TraitsIndex.clear(); //kept here but also done in clearPrototype()
65 
66  int i = 0;
67 
68  while(trait != TTlist.end()) {
69 
70 #ifdef _DEBUG_
71  message("IndFactory::makePrototype::addTrait: %s\n",trait->first.c_str());
72  cout << "trait proto ptr:"<<trait->second <<endl;
73  cout << "trait proto type:"<<trait->second->get_type() <<endl;
74 // TTrait* tt=trait->second->hatch();
75 // tt->init();
76 // tt->init_sequence();
77 // tt->show_up();
78 // delete tt;
79 #endif
80 
81  //init the trait prototype, set attribute from input file parameters value
82  if(!trait->second->setParameters()) {
83  error("initialization of prototype for trait \"%s\" failed\n",trait->first.c_str());
84  fatal("bailing out from individual prototype initialization\n");
85  }
86  //set the prototype's index value
87  trait->second->set_index(i);
88 
89  //create the trait and add it to the proto-individual
90  _protoIndividual.addTrait(trait->second->hatch(),i);
91 
92  //store the trait's index into the index map
93  _TraitsIndex[trait->first] = i++;
94 
95  trait++;
96  }
97 
98 }
void setCurrentID(unsigned long value)
Definition: individual.h:112
void addTrait(TTrait *theTrait, IDX pos)
Adds a trait to the table.
Definition: individual.h:287
void fatal(const char *str,...)
Definition: output.cc:99
int error(const char *str,...)
Definition: output.cc:78

References error(), fatal(), and message().

Referenced by BinaryDataLoader::extractPop(), SimRunner::init_components(), and Metapop::loadPopFromTraitFile().

+ Here is the caller graph for this function:

◆ purgeRecyclingPOOL()

void IndFactory::purgeRecyclingPOOL ( )
inline

Empty the recycling pool.

66  { for(unsigned int i=0; i < RecyclingPOOL.size(); ++i) delete RecyclingPOOL[i]; RecyclingPOOL.clear(); }

References RecyclingPOOL.

Referenced by Metapop::clear(), Metapop::init(), and Metapop::setPopulation().

+ Here is the caller graph for this function:

◆ recycle()

Member Data Documentation

◆ _protoIndividual

Individual IndFactory::_protoIndividual
protected

The individuals prototype used to create any new individual in a simulation.

Referenced by getIndividualProtoype(), and getPrototypeClone().

◆ _protoTraits

std::map< trait_t, TraitPrototype* > IndFactory::_protoTraits
protected

Map of the trait prototypes.

Referenced by getTraitPrototypes(), and Metapop::retrieve_data().

◆ _TraitsIndex

std::map< trait_t, int > IndFactory::_TraitsIndex
protected

Table containing the index of each trait.

◆ RecyclingPOOL

std::deque<Individual*> IndFactory::RecyclingPOOL
protected

Garbage collector for unused Individual's.

Referenced by purgeRecyclingPOOL(), and recycle().


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

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR