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

Provides methods to build the user's selected set of life cycle events and traits from the parameters. More...

#include <basicsimulation.h>

+ Inheritance diagram for SimBuilder:
+ Collaboration diagram for SimBuilder:

Public Member Functions

 SimBuilder ()
 
 SimBuilder (const SimBuilder &SB)
 copy cstor. More...
 
 ~SimBuilder ()
 
bool build_currentParams (map< string, string > &simparams)
 Builds the list of parameters from user's defined input parameters. More...
 
map< trait_t, TraitPrototype * > & build_currentTraits ()
 Selects the trait prototypes that have their parameters set. More...
 
void build_LifeCycle ()
 Selects the life cycle events that have their parameters set. More...
 
TraitPrototypeget_current_trait (trait_t type)
 Accessor to the list of current trait prototypes. More...
 
TraitPrototypeget_current_traitWithParameter (string &param)
 Accessor to the current trait prototypes conditioned on ownership of a specified parameter. More...
 
LifeCycleEventget_current_event (string &name)
 Accessor to the list of current LCEs. More...
 
LifeCycleEventget_current_eventWithParameter (string &param)
 Accessor to the current LCEs conditioned on ownership of a specified parameter. More...
 
list< ParamSet * > & get_currentParams ()
 Accessor to the list of the selected parameter sets. More...
 
age_t getFirstRequiredAgeInLifeCycle ()
 
- Public Member Functions inherited from ParamManager
 ParamManager ()
 Cstor. More...
 
 ~ParamManager ()
 
void add_paramset (ParamSet *paramset)
 Adds a ParamSet to the list of the parameter sets of the simulation. More...
 
ParamSetget_paramset (string &name)
 Looks for paramset with "name" in the list of parameter sets. More...
 
void build_allParams ()
 Clears and fills the _allParams list with the ParamSet's of the simulation components. More...
 
list< ParamSet * > & get_allParams ()
 Accessor of the whole list of the parameter sets. More...
 
bool set_parameters (map< string, string > &simparams, bool silent)
 Sets the parameters of the simulation with the argument strings given in input. More...
 
bool param_consistency_check ()
 Checks if all the mandatory parameters are set so that the simulation can be launched. More...
 
void build_records (map< string, vector< string > > &initParams)
 Builds the list of simulation parameters from the parsed input file(s). More...
 
list< map< string, string > > & get_simRecords ()
 Accessor to the simulations parameter list. More...
 
map< string, string > & get_firstRecord ()
 Accessor to the first element in the simulations parameter list. More...
 
int get_nbSims ()
 Accessor to the size of the simulations parameter list, i.e. More...
 
- Public Member Functions inherited from ComponentManager
 ComponentManager ()
 
 ~ComponentManager ()
 
void build_component_list ()
 Clears and builds the list of all components from the lists of trait prototype templates and life cycle event templates. More...
 
void add_component (SimComponent *cmpt)
 Push a component at the back of the component list. More...
 
void add_trait (TraitPrototype *trait)
 Add a trait prototype to the template and component lists. More...
 
void add_LCE (LifeCycleEvent *event)
 Add a life cycle event to the template and component lists. More...
 
TraitPrototypeget_trait (string name)
 Search for component with "name" in the trait prototype list. More...
 
LifeCycleEventget_LCE (string name)
 Search for component with "name" in the life cycle events list. More...
 

Protected Types

typedef map< int, LifeCycleEvent * >::const_iterator LCE_ITER
 
typedef map< trait_t, TraitPrototype * >::const_iterator TRAIT_ITER
 

Protected Attributes

list< ParamSet * > _currentParams
 List of the selected simulation components from the user defined input parameters. More...
 
map< trait_t, TraitPrototype * > _currentTraits
 List of the selected trait prototypes from the user defined input parameters. More...
 
map< int, LifeCycleEvent * > _LifeCycle
 List of the selected life cycle events from the user defined input parameters. More...
 
- Protected Attributes inherited from ParamManager
list< ParamSet * > _allParams
 A list of all the parameter sets of all the simulation components loaded in the _component list of the ComponentManager. More...
 
map< string, string > _inputParams
 A map of the parameters and their arguments of the current (running) simulation. More...
 
map< unsigned int, list< pair< string, string > > > _temporalParams
 Lists of parameters to be updated during a simulation indexed by generation update time. More...
 
list< map< string, string > > _simRecords
 Sets of parameters of all the simulations to perform. More...
 
ParamSet _paramSet
 The ParamSet param set of the simulation. More...
 
- Protected Attributes inherited from ComponentManager
list< SimComponent * > _components
 List of all the simulation components. More...
 
list< TraitPrototype * > _TTrait_Templates
 List of all trait prototypes of the simulation, a subset of _components list. More...
 
list< LifeCycleEvent * > _LCE_Templates
 List of all the life-cycle events of the simulation, a subset of _components list. More...
 

Detailed Description

Provides methods to build the user's selected set of life cycle events and traits from the parameters.

This class implements methods to build the lists of selected traits and life cycle events from the user's defined parameters. Each simulation component that has its ParamSet in the "set" state is elligible to be part of the current simulation. Accessors to these components are provided. This class does however not provide a runnable simulation object.

Member Typedef Documentation

◆ LCE_ITER

typedef map< int, LifeCycleEvent* >::const_iterator SimBuilder::LCE_ITER
protected

◆ TRAIT_ITER

typedef map< trait_t, TraitPrototype* >::const_iterator SimBuilder::TRAIT_ITER
protected

Constructor & Destructor Documentation

◆ SimBuilder() [1/2]

SimBuilder::SimBuilder ( )
inline
168 { }

◆ SimBuilder() [2/2]

SimBuilder::SimBuilder ( const SimBuilder SB)

copy cstor.

784 {
785  list< TraitPrototype* >::const_iterator TT = SB._TTrait_Templates.begin();
786 
787  for(;TT != SB._TTrait_Templates.end(); TT++) add_trait( (*TT)->clone() );
788 
789  list< LifeCycleEvent* >::const_iterator LCE = SB._LCE_Templates.begin();
790 
791  for(;LCE != SB._LCE_Templates.end(); LCE++) add_LCE( (*LCE)->clone() );
792 
793 
794  _paramSet = SB._paramSet;
795 
796  build_allParams();
797 }
list< LifeCycleEvent * > _LCE_Templates
List of all the life-cycle events of the simulation, a subset of _components list.
Definition: basicsimulation.h:73
list< TraitPrototype * > _TTrait_Templates
List of all trait prototypes of the simulation, a subset of _components list.
Definition: basicsimulation.h:71
void add_LCE(LifeCycleEvent *event)
Add a life cycle event to the template and component lists.
Definition: basicsimulation.h:56
void add_trait(TraitPrototype *trait)
Add a trait prototype to the template and component lists.
Definition: basicsimulation.h:54
void build_allParams()
Clears and fills the _allParams list with the ParamSet's of the simulation components.
Definition: basicsimulation.cc:116
ParamSet _paramSet
The ParamSet param set of the simulation.
Definition: basicsimulation.h:149

References ComponentManager::_LCE_Templates, ParamManager::_paramSet, ComponentManager::_TTrait_Templates, ComponentManager::add_LCE(), ComponentManager::add_trait(), and ParamManager::build_allParams().

◆ ~SimBuilder()

SimBuilder::~SimBuilder ( )
802 {
803 #ifdef _DEBUG_
804  message("SimBuilder::~SimBuilder\n");
805 #endif
806 
807  _components.clear();
808 
809  list< TraitPrototype* >::iterator TT_it = _TTrait_Templates.begin();
810 
811  while(TT_it != _TTrait_Templates.end()) {
812  delete (*TT_it);
813  TT_it++;
814  }
815 
816  list< LifeCycleEvent* >::iterator LCE_it = _LCE_Templates.begin();
817 
818  while(LCE_it != _LCE_Templates.end()) {
819  delete (*LCE_it);
820  LCE_it++;
821  }
822 
823 }
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:69
void message(const char *message,...)
Definition: output.cc:38

References ComponentManager::_components, ComponentManager::_LCE_Templates, ComponentManager::_TTrait_Templates, and message().

Member Function Documentation

◆ build_currentParams()

bool SimBuilder::build_currentParams ( map< string, string > &  simparams)

Builds the list of parameters from user's defined input parameters.

Parameters
simparamsHashtable of the parsed input parameters
Returns
TRUE if parameters are consitently set
889 {
890  if(! this->set_parameters(simparams, false) ) return false;
891 
892  //empty the current parameters container:
893  _currentParams.clear();
894 
895  list<ParamSet*>::iterator current_paramset = this->_allParams.begin();
896 
897  //add all set parameters to the list of the current params:
898  while(current_paramset != this->_allParams.end()){
899  if((*current_paramset)->isSet()) {
900 #ifdef _DEBUG_
901  message("SimBuilder::build_currentParams:adding paramset %s\n",
902  (*current_paramset)->getName().c_str());
903 #endif
904  _currentParams.push_back(*current_paramset);
905  }
906  current_paramset++;
907  }
908 
909  return true;
910 }
bool set_parameters(map< string, string > &simparams, bool silent)
Sets the parameters of the simulation with the argument strings given in input.
Definition: basicsimulation.cc:151
list< ParamSet * > _allParams
A list of all the parameter sets of all the simulation components loaded in the _component list of th...
Definition: basicsimulation.h:141
list< ParamSet * > _currentParams
List of the selected simulation components from the user defined input parameters.
Definition: basicsimulation.h:218

References ParamManager::_allParams, _currentParams, message(), and ParamManager::set_parameters().

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

+ Here is the caller graph for this function:

◆ build_currentTraits()

map< trait_t, TraitPrototype * > & SimBuilder::build_currentTraits ( )

Selects the trait prototypes that have their parameters set.

Returns
Hashtable of the trait prototypes
915 {
916  //build the list of Traits for this simulation:
917  list< TraitPrototype* >::iterator trait = this->_TTrait_Templates.begin();
918 
919  _currentTraits.clear();
920 
921  while(trait != this->_TTrait_Templates.end()) {
922 
923  if( (*trait)->get_paramset()->isSet() ){
924  _currentTraits[(*trait)->get_type()] = (*trait);
925  }
926 
927  trait++;
928  }
929 
930  return _currentTraits;
931 }
map< trait_t, TraitPrototype * > _currentTraits
List of the selected trait prototypes from the user defined input parameters.
Definition: basicsimulation.h:220

References _currentTraits, and ComponentManager::_TTrait_Templates.

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

+ Here is the caller graph for this function:

◆ build_LifeCycle()

void SimBuilder::build_LifeCycle ( )

Selects the life cycle events that have their parameters set.

936 {
937  //build the list of the life cycle events for this simulation:
938  list< LifeCycleEvent* >::iterator LCE = this->_LCE_Templates.begin();
939 
940  _LifeCycle.clear();
941 
942  int rank;
943 
944 
945  while(LCE != this->_LCE_Templates.end()) {
946 
947  if( (*LCE)->get_paramset()->isSet() ){
948 
949 #ifdef _DEBUG_
950  cout <<"adding LCE "<< (*LCE)->get_event_name() <<" : "<< (*LCE)->get_rank() << endl;
951 #endif
952 
953  rank = (int)(*LCE)->get_rank();
954 
955  if(rank < 0)
956  fatal("rank %i for LCE \"%s\" cannot be negative, please provide a positive rank number.\n", rank, (*LCE)->get_name().c_str());
957 
958  if(_LifeCycle[rank]){
959  fatal("rank %i for LCE \"%s\" is already assigned to \"%s\", please choose a different rank number.\n",
960  rank, (*LCE)->get_name().c_str(), _LifeCycle[rank]->get_name().c_str());
961  }
962  else
963  _LifeCycle[rank] = (*LCE);
964  }
965  LCE++;
966  }
967 
968 }
map< int, LifeCycleEvent * > _LifeCycle
List of the selected life cycle events from the user defined input parameters.
Definition: basicsimulation.h:222
void fatal(const char *str,...)
Definition: output.cc:98

References ComponentManager::_LCE_Templates, _LifeCycle, and fatal().

Referenced by SimRunner::setLifeCycle().

+ Here is the caller graph for this function:

◆ get_current_event()

LifeCycleEvent * SimBuilder::get_current_event ( string &  name)

Accessor to the list of current LCEs.

Parameters
namethe name of the LCE
Returns
ptr to the LCE
857 {
858  LCE_ITER LCE = _LifeCycle.begin();
859 
860  while(LCE != _LifeCycle.end()) {
861  if( LCE->second->get_event_name().compare(name) == 0)
862  return LCE->second;
863  LCE++;
864  }
865 
866  return NULL;
867 }
map< int, LifeCycleEvent * >::const_iterator LCE_ITER
Definition: basicsimulation.h:224

References _LifeCycle.

Referenced by Metapop::loadPopFromBinarySource(), and SimRunner::run_event().

+ Here is the caller graph for this function:

◆ get_current_eventWithParameter()

LifeCycleEvent * SimBuilder::get_current_eventWithParameter ( string &  param)

Accessor to the current LCEs conditioned on ownership of a specified parameter.

Parameters
thename of the parameter of interest
Returns
a pointer to the LCE, is NULL if no trait found
872 {
873  LifeCycleEvent* event = NULL;
874 
875  for(LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++)
876  {
877  if( LCE->second->has_parameter(param)) {
878  event = LCE->second;
879  break; //this assumes that parameters are unique, the first component found with that parameter is returned
880  }
881  }
882 
883  return event;
884 }
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:71

References _LifeCycle.

Referenced by Metapop::loadPopFromBinarySource().

+ Here is the caller graph for this function:

◆ get_current_trait()

TraitPrototype * SimBuilder::get_current_trait ( trait_t  type)

Accessor to the list of current trait prototypes.

Parameters
typethe trait type
Returns
ptr to the prototype
828 {
829  TRAIT_ITER trait = _currentTraits.find(type);
830 
831  if(trait != _currentTraits.end())
832  return trait->second;
833  else
834  return NULL;
835 }
map< trait_t, TraitPrototype * >::const_iterator TRAIT_ITER
Definition: basicsimulation.h:225

References _currentTraits.

Referenced by Metapop::loadPopFromBinarySource().

+ Here is the caller graph for this function:

◆ get_current_traitWithParameter()

TraitPrototype * SimBuilder::get_current_traitWithParameter ( string &  param)

Accessor to the current trait prototypes conditioned on ownership of a specified parameter.

Parameters
thename of the parameter of interest
Returns
a pointer to the trait prototype, is NULL if no trait found
840 {
841  TraitPrototype* TP = NULL;
842 
843  for(TRAIT_ITER trait = _currentTraits.begin(); trait != _currentTraits.end(); trait++)
844  {
845  if( trait->second->has_parameter(param)) {
846  TP = trait->second;
847  break; //this assumes that parameters are unique, the first component found with that parameter is returned
848  }
849  }
850 
851  return TP;
852 }
TTrait setter.
Definition: ttrait.h:129

References _currentTraits.

Referenced by Metapop::loadPopFromBinarySource().

+ Here is the caller graph for this function:

◆ get_currentParams()

list<ParamSet*>& SimBuilder::get_currentParams ( )
inline

Accessor to the list of the selected parameter sets.

Returns
list of ParamSet
212 {return _currentParams;}

Referenced by SimRunner::expandPreservedMacros().

+ Here is the caller graph for this function:

◆ getFirstRequiredAgeInLifeCycle()

age_t SimBuilder::getFirstRequiredAgeInLifeCycle ( )
973 {
974  age_t requiredAgeClass = NONE;
975 
976  for(LCE_ITER IT = _LifeCycle.begin();
977  IT != _LifeCycle.end() && requiredAgeClass == NONE;
978  IT++)
979  requiredAgeClass = IT->second->requiredAgeClass();
980 
981  return requiredAgeClass;
982 }
#define NONE
No age flag.
Definition: types.h:46
unsigned int age_t
Age class flags.
Definition: types.h:44

References _LifeCycle, and NONE.

Referenced by Metapop::setPopulation().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _currentParams

list< ParamSet* > SimBuilder::_currentParams
protected

List of the selected simulation components from the user defined input parameters.

Referenced by build_currentParams().

◆ _currentTraits

map< trait_t, TraitPrototype* > SimBuilder::_currentTraits
protected

List of the selected trait prototypes from the user defined input parameters.

Referenced by build_currentTraits(), get_current_trait(), get_current_traitWithParameter(), SimRunner::register_component_handlers(), and SimRunner::run().

◆ _LifeCycle

map< int, LifeCycleEvent* > SimBuilder::_LifeCycle
protected

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