Nemo  2.3.46
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 ( )
inline
58 { };
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, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:46
void clearTraits()
Clears the traits container.
Definition: individual.h:300
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
std::map< trait_t, int > _TraitsIndex
Table containing the index of each trait.
Definition: indfactory.h:48

Member Function Documentation

void IndFactory::clearPrototype ( )

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

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

Referenced by SimRunner::run().

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 message(const char *message,...)
Definition: output.cc:40
std::map< trait_t, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:46
static GeneticMap _map
Definition: ttrait_with_map.h:190
void clearTraits()
Clears the traits container.
Definition: individual.h:300
void clear()
Definition: ttrait_with_map.cc:538
Individual _protoIndividual
The individuals prototype used to create any new individual in a simulation.
Definition: indfactory.h:51
std::map< trait_t, int > _TraitsIndex
Table containing the index of each trait.
Definition: indfactory.h:48
Individual* IndFactory::getIndividualProtoype ( )
inline

Individual prototype accessor.

References _protoIndividual.

Referenced by SimRunner::run(), and LCE_Breed_Selection::setNonSelectedTraitTable().

109 {return &_protoIndividual;}
Individual _protoIndividual
The individuals prototype used to create any new individual in a simulation.
Definition: indfactory.h:51
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.

References makeNewIndividual(), and MAL.

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

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
Definition: types.h:37
Individual* IndFactory::getPrototypeClone ( )
inline

Return an uninitialized copy of the individual prototype.

References Individual::clone().

Referenced by LCE_Cross::generatePedigree().

79 {return _protoIndividual.clone();}
Individual _protoIndividual
The individuals prototype used to create any new individual in a simulation.
Definition: indfactory.h:51
Individual * clone()
Cloning procedure, clones all the traits present in the individual.
Definition: individual.cc:149
int IndFactory::getTraitIndex ( trait_t  type)

Gives the index of trait with type.

Parameters
typethe type of the trait (i.e. its "name")

Referenced by LifeCycleEvent::attach_trait(), TTDispersalSH::init(), LCE_Disperse_EvolDisp::setParameters(), and LCE_Selection_base::setParameters().

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 }
std::map< trait_t, int > _TraitsIndex
Table containing the index of each trait.
Definition: indfactory.h:48
TraitPrototype * IndFactory::getTraitPrototype ( trait_t  type)

Accessor to a TraitPrototype.

Parameters
typethe trait name

Referenced by LCE_QuantiInit::execute(), LCE_Init_BDMI::execute(), LCE_QuantiInit::setParameters(), LCE_NtrlInit::setParameters(), and LCE_Init_BDMI::setParameters().

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 }
std::map< trait_t, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:46
std::map< trait_t,TraitPrototype* >& IndFactory::getTraitPrototypes ( )
inline

Accessor to the list of TraitPrototype's.

References _protoTraits.

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

117 {return _protoTraits;}
std::map< trait_t, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:46
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.

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(), TTNeutralGenesFH::FHread(), TTDeletMutBitstrFH::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().

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 }
unsigned long getID()
Definition: individual.h:122
void setFather(Individual *f)
Definition: individual.h:109
void setFatherID(unsigned long value)
Definition: individual.h:107
void setMotherID(unsigned long value)
Definition: individual.h:108
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:115
void reset()
Resets parameters and traits values.
Definition: individual.cc:79
void setID(unsigned long value)
Definition: individual.h:104
void setMother(Individual *m)
Definition: individual.h:110
static unsigned long currentID
The ID counter, reset at the beginning of each simulation.
Definition: individual.h:83
void setSex(sex_t sex)
Definition: individual.h:112
std::deque< Individual * > RecyclingPOOL
Garbage collector for unused Individual's.
Definition: indfactory.h:54
void setHome(unsigned short value)
Definition: individual.h:111
Individual * init()
Inits parameters and traits.
Definition: individual.cc:53
Individual _protoIndividual
The individuals prototype used to create any new individual in a simulation.
Definition: indfactory.h:51
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
Individual * clone()
Cloning procedure, clones all the traits present in the individual.
Definition: individual.cc:149
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

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

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 * 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
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:225
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:362
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
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.

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

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

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 message(const char *message,...)
Definition: output.cc:40
std::map< trait_t, TraitPrototype * > _protoTraits
Map of the trait prototypes.
Definition: indfactory.h:46
void fatal(const char *str,...)
Definition: output.cc:90
int error(const char *str,...)
Definition: output.cc:73
Individual _protoIndividual
The individuals prototype used to create any new individual in a simulation.
Definition: indfactory.h:51
void addTrait(TTrait *theTrait, IDX pos)
Adds a trait to the table.
Definition: individual.h:288
void setCurrentID(unsigned long value)
Definition: individual.h:113
std::map< trait_t, int > _TraitsIndex
Table containing the index of each trait.
Definition: indfactory.h:48
void IndFactory::purgeRecyclingPOOL ( )
inline

Empty the recycling pool.

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

67  { for(unsigned int i=0; i < RecyclingPOOL.size(); ++i) delete RecyclingPOOL[i]; RecyclingPOOL.clear(); }
std::deque< Individual * > RecyclingPOOL
Garbage collector for unused Individual's.
Definition: indfactory.h:54
void IndFactory::recycle ( Individual ind)
inline

Put an individual in the recycling pool.

References error().

Referenced by LCE_Patch_Extinction::do_remove(), LCE_Selection_base::doViabilitySelection(), LCE_Disperse_EvolDisp::evoldisp(), LCE_Disperse_EvolDisp::fixdisp(), Patch::flush(), LCE_Breed_Selection::makeOffspringWithSelection(), LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder(), LCE_Resize::regulateAgeClassNoBackup(), LCE_Regulation::regulatePatch(), and LCE_Breed_Wolbachia::wolbachia_model_1().

63  { if(ind == NULL) error("IndFactory::recycle:ind is NULL!!\n"); else RecyclingPOOL.push_back(ind); }
int error(const char *str,...)
Definition: output.cc:73
std::deque< Individual * > RecyclingPOOL
Garbage collector for unused Individual's.
Definition: indfactory.h:54

Member Data Documentation

Individual IndFactory::_protoIndividual
protected

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

Referenced by getIndividualProtoype().

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

Map of the trait prototypes.

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

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

Table containing the index of each trait.

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

Garbage collector for unused Individual's.


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

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR