Nemo  2.4.2
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
56 { };

◆ ~IndFactory()

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

Member Function Documentation

◆ clearPrototype()

void IndFactory::clearPrototype ( )

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

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

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.
180 {
181  if(!newind) return makeNewIndividual(newind, mother, father, sex, homepatch);
182 
183  newind->setAge(0);
184  newind->setSex(sex);
185  newind->setHome(homepatch);
186 
187  if(mother != NULL && father != NULL) {
188  newind->setFatherID(father->getID());
189  newind->setMotherID(mother->getID());
190  newind->setFather(father);
191  newind->setMother(mother);
192  newind->setPedigreeClass(mother, father);
193  }
194 
195  return newind;
196 }
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
void setFather(Individual *f)
Definition: individual.h:107
unsigned long getID()
Definition: individual.h:120
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:113
void setMother(Individual *m)
Definition: individual.h:108
void setHome(unsigned short value)
Definition: individual.h:109
void setMotherID(unsigned long value)
Definition: individual.h:106
void setSex(sex_t sex)
Definition: individual.h:110
void setFatherID(unsigned long value)
Definition: individual.h:105
void setAge(unsigned short value)
Definition: individual.h:103

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.

130 {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.

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

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.

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

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")
127 {
128  map< trait_t, int >::iterator trait = _TraitsIndex.find(type);
129 
130  if(trait == _TraitsIndex.end())
131  return -1;
132 
133  return trait->second;
134 }

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.

138 {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.
201 {
202  Individual* newind;
203 
204  if(RecyclingPOOL.empty()) {
205  //create new Individual by cloning the proto-individual
206  newind = _protoIndividual.clone();
207  //allocate memory for the traits' sequences:
208  newind->init();
209  } else {
210  //recycle an Individual from the POOL
211  newind = RecyclingPOOL[0];
212  RecyclingPOOL.pop_front();
213  newind->reset();
214  newind->setID(Individual::currentID++);
215  }
216 
217  newind->setSex(sex);
218  newind->setHome(homepatch);
219  if(mother != NULL && father != NULL) {
220  newind->setFatherID(father->getID());
221  newind->setMotherID(mother->getID());
222  newind->setFather(father);
223  newind->setMother(mother);
224  newind->setPedigreeClass(mother, father);
225  }
226 
227  return newind;
228 }
std::deque< Individual * > RecyclingPOOL
Garbage collector for unused Individual's.
Definition: indfactory.h:52
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
Individual * init()
Inits parameters and traits.
Definition: individual.cc:51
void setID(unsigned long value)
Definition: individual.h:102
static unsigned long currentID
The ID counter, reset at the beginning of each simulation.
Definition: individual.h:81
void reset()
Resets parameters and traits values.
Definition: individual.cc:77

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.
152 {
153 
154  if(!newind) {
155  if(RecyclingPOOL.empty()) {
156  //create new Individual by cloning the proto-individual
157  newind = _protoIndividual.clone();
158  //allocate memory for the traits' sequences:
159  newind->init();
160  } else {
161  //recycle an Individual from the POOL
162  newind = RecyclingPOOL[0];
163  RecyclingPOOL.pop_front();
164  newind->reset();
165  newind->setID(Individual::currentID++);
166  }
167  } else {
168  //new individual exists and is passed as argument (in-place creation from existing pointer in patch container)
169  newind->reset();
170  newind->setID(Individual::currentID++);
171  }
172 
173  return decorateNewIndividual(newind, mother, father, sex, homepatch);
174 }
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:178

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
233 {
234  Individual* offspring = makeNewIndividual(mother,father,sex,homepatch);
235  unsigned int cat = offspring->getPedigreeClass();
236  mother->DidHaveABaby(cat);
237  if(cat!=4) father->DidHaveABaby(cat);
238  return offspring->create(mother, father);
239 }
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:360
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:223
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:177

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

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.

65  { 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.2 by  doxygen 1.9.1

Catalogued on GSR