Nemo  2.4.0
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
169 { }

◆ SimBuilder() [2/2]

SimBuilder::SimBuilder ( const SimBuilder SB)

copy cstor.

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

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

◆ ~SimBuilder()

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

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
890 {
891  if(! this->set_parameters(simparams, false) ) return false;
892 
893  //empty the current parameters container:
894  _currentParams.clear();
895 
896  list<ParamSet*>::iterator current_paramset = this->_allParams.begin();
897 
898  //add all set parameters to the list of the current params:
899  while(current_paramset != this->_allParams.end()){
900  if((*current_paramset)->isSet()) {
901 #ifdef _DEBUG_
902  message("SimBuilder::build_currentParams:adding paramset %s\n",
903  (*current_paramset)->getName().c_str());
904 #endif
905  _currentParams.push_back(*current_paramset);
906  }
907  current_paramset++;
908  }
909 
910  return true;
911 }
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:152
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:142
list< ParamSet * > _currentParams
List of the selected simulation components from the user defined input parameters.
Definition: basicsimulation.h:219

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

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.

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

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
858 {
859  LCE_ITER LCE = _LifeCycle.begin();
860 
861  while(LCE != _LifeCycle.end()) {
862  if( LCE->second->get_event_name().compare(name) == 0)
863  return LCE->second;
864  LCE++;
865  }
866 
867  return NULL;
868 }
map< int, LifeCycleEvent * >::const_iterator LCE_ITER
Definition: basicsimulation.h:225

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
873 {
874  LifeCycleEvent* event = NULL;
875 
876  for(LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++)
877  {
878  if( LCE->second->has_parameter(param)) {
879  event = LCE->second;
880  break; //this assumes that parameters are unique, the first component found with that parameter is returned
881  }
882  }
883 
884  return event;
885 }
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72

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
829 {
830  TRAIT_ITER trait = _currentTraits.find(type);
831 
832  if(trait != _currentTraits.end())
833  return trait->second;
834  else
835  return NULL;
836 }
map< trait_t, TraitPrototype * >::const_iterator TRAIT_ITER
Definition: basicsimulation.h:226

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
841 {
842  TraitPrototype* TP = NULL;
843 
844  for(TRAIT_ITER trait = _currentTraits.begin(); trait != _currentTraits.end(); trait++)
845  {
846  if( trait->second->has_parameter(param)) {
847  TP = trait->second;
848  break; //this assumes that parameters are unique, the first component found with that parameter is returned
849  }
850  }
851 
852  return TP;
853 }
TTrait setter.
Definition: ttrait.h:130

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
213 {return _currentParams;}

◆ getFirstRequiredAgeInLifeCycle()

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

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

Locations of visitors to this page
Catalogued on GSR