Nemo  2.4.0b
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 *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
58 { };

◆ ~IndFactory()

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

Member Function Documentation

◆ clearPrototype()

void IndFactory::clearPrototype ( )

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

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

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

Referenced by SimRunner::run().

◆ getIndividualProtoype()

Individual* IndFactory::getIndividualProtoype ( )
inline

Individual prototype accessor.

109 {return &_protoIndividual;}

References _protoIndividual.

Referenced by LCE_Breed_Selection::setNonSelectedTraitTable().

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

85 {return makeNewIndividual(NULL,NULL,MAL,0);}
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
@ MAL
Definition: types.h:37

References makeNewIndividual(), and MAL.

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

◆ getPrototypeClone()

Individual* IndFactory::getPrototypeClone ( )
inline

Return an uninitialized copy of the individual prototype.

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

References _protoIndividual, and Individual::clone().

Referenced by LCE_Cross::generatePedigree().

◆ getTraitIndex()

int IndFactory::getTraitIndex ( trait_t  type)

Gives the index of trait with type.

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

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

◆ getTraitPrototype()

TraitPrototype * IndFactory::getTraitPrototype ( trait_t  type)

Accessor to a TraitPrototype.

Parameters
typethe trait name
141 {
142  map< trait_t, TraitPrototype* >::iterator trait = _protoTraits.find(type);
143 
144  if(trait == _protoTraits.end()) return NULL;
145 
146  return trait->second;
147 
148 }

Referenced by LCE_QuantiInit::execute(), LCE_Init_BDMI::execute(), LCE_Selection_base::set_sel_model(), LCE_PhenotypeExpression::setParameters(), LCE_QuantiInit::setParameters(), LCE_QuantiModifier::setParameters(), LCE_Breed_Quanti::setParameters(), LCE_Init_BDMI::setParameters(), LCE_NtrlInit::setParameters(), and LCE_Selection_base::setSelectionMatrix().

◆ getTraitPrototypes()

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

Accessor to the list of TraitPrototype's.

117 {return _protoTraits;}

References _protoTraits.

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

◆ makeNewIndividual()

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.
153 {
154  Individual* newind;
155 
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 
169  newind->setSex(sex);
170  newind->setHome(homepatch);
171  if(mother != NULL && father != NULL) {
172  newind->setFatherID(father->getID());
173  newind->setMotherID(mother->getID());
174  newind->setFather(father);
175  newind->setMother(mother);
176  newind->setPedigreeClass(mother, father);
177  }
178 
179  return newind;
180 }
std::deque< Individual * > RecyclingPOOL
Garbage collector for unused Individual's.
Definition: indfactory.h:54
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
void setFather(Individual *f)
Definition: individual.h:109
Individual * init()
Inits parameters and traits.
Definition: individual.cc:53
void setID(unsigned long value)
Definition: individual.h:104
static unsigned long currentID
The ID counter, reset at the beginning of each simulation.
Definition: individual.h:83
unsigned long getID()
Definition: individual.h:122
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:115
void setMother(Individual *m)
Definition: individual.h:110
void reset()
Resets parameters and traits values.
Definition: individual.cc:79
void setHome(unsigned short value)
Definition: individual.h:111
void setMotherID(unsigned long value)
Definition: individual.h:108
void setSex(sex_t sex)
Definition: individual.h:112
void setFatherID(unsigned long value)
Definition: individual.h:107

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

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

◆ 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
185 {
186  Individual* offspring = makeNewIndividual(mother,father,sex,homepatch);
187  unsigned int cat = offspring->getPedigreeClass();
188  mother->DidHaveABaby(cat);
189  if(cat!=4) father->DidHaveABaby(cat);
190  return offspring->create(mother, father);
191 }
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:362
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:225
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179

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

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

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

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

◆ purgeRecyclingPOOL()

void IndFactory::purgeRecyclingPOOL ( )
inline

Empty the recycling pool.

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

◆ 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.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR