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

◆ SimBuilder() [2/2]

SimBuilder::SimBuilder ( const SimBuilder SB)

copy cstor.

616 {
617  list< TraitPrototype* >::const_iterator TT = SB._TTrait_Templates.begin();
618 
619  for(;TT != SB._TTrait_Templates.end(); TT++) add_trait( (*TT)->clone() );
620 
621  list< LifeCycleEvent* >::const_iterator LCE = SB._LCE_Templates.begin();
622 
623  for(;LCE != SB._LCE_Templates.end(); LCE++) add_LCE( (*LCE)->clone() );
624 
625 
626  _paramSet = SB._paramSet;
627 
628  build_allParams();
629 }
list< LifeCycleEvent * > _LCE_Templates
List of all the life-cycle events of the simulation, a subset of _components list.
Definition: basicsimulation.h:75
list< TraitPrototype * > _TTrait_Templates
List of all trait prototypes of the simulation, a subset of _components list.
Definition: basicsimulation.h:73
void add_LCE(LifeCycleEvent *event)
Add a life cycle event to the template and component lists.
Definition: basicsimulation.h:58
void add_trait(TraitPrototype *trait)
Add a trait prototype to the template and component lists.
Definition: basicsimulation.h:56
void build_allParams()
Clears and fills the _allParams list with the ParamSet's of the simulation components.
Definition: basicsimulation.cc:115
ParamSet _paramSet
The ParamSet param set of the simulation.
Definition: basicsimulation.h:151

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

◆ ~SimBuilder()

SimBuilder::~SimBuilder ( )
634 {
635 #ifdef _DEBUG_
636  message("SimBuilder::~SimBuilder\n");
637 #endif
638 
639  _components.clear();
640 
641  list< TraitPrototype* >::iterator TT_it = _TTrait_Templates.begin();
642 
643  while(TT_it != _TTrait_Templates.end()) {
644  delete (*TT_it);
645  TT_it++;
646  }
647 
648  list< LifeCycleEvent* >::iterator LCE_it = _LCE_Templates.begin();
649 
650  while(LCE_it != _LCE_Templates.end()) {
651  delete (*LCE_it);
652  LCE_it++;
653  }
654 
655 }
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:71
void message(const char *message,...)
Definition: output.cc:40

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
721 {
722  if(! this->set_parameters(simparams, false) ) return false;
723 
724  //empty the current parameters container:
725  _currentParams.clear();
726 
727  list<ParamSet*>::iterator current_paramset = this->_allParams.begin();
728 
729  //add all set parameters to the list of the current params:
730  while(current_paramset != this->_allParams.end()){
731  if((*current_paramset)->isSet()) {
732 #ifdef _DEBUG_
733  message("SimBuilder::build_currentParams:adding paramset %s\n",
734  (*current_paramset)->getName().c_str());
735 #endif
736  _currentParams.push_back(*current_paramset);
737  }
738  current_paramset++;
739  }
740 
741  return true;
742 }
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:150
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:143
list< ParamSet * > _currentParams
List of the selected simulation components from the user defined input parameters.
Definition: basicsimulation.h:220

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

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

◆ build_currentTraits()

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

Selects the trait prototypes that have their parameters set.

Returns
Hashtable of the trait prototypes
747 {
748  //build the list of Traits for this simulation:
749  list< TraitPrototype* >::iterator trait = this->_TTrait_Templates.begin();
750 
751  _currentTraits.clear();
752 
753  while(trait != this->_TTrait_Templates.end()) {
754 
755  if( (*trait)->get_paramset()->isSet() ){
756  _currentTraits[(*trait)->get_type()] = (*trait);
757  }
758 
759  trait++;
760  }
761 
762  return _currentTraits;
763 }
map< trait_t, TraitPrototype * > _currentTraits
List of the selected trait prototypes from the user defined input parameters.
Definition: basicsimulation.h:222

References _currentTraits, and ComponentManager::_TTrait_Templates.

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

◆ build_LifeCycle()

void SimBuilder::build_LifeCycle ( )

Selects the life cycle events that have their parameters set.

768 {
769  //build the list of the life cycle events for this simulation:
770  list< LifeCycleEvent* >::iterator LCE = this->_LCE_Templates.begin();
771 
772  _LifeCycle.clear();
773 
774  int rank;
775 
776 
777  while(LCE != this->_LCE_Templates.end()) {
778 
779  if( (*LCE)->get_paramset()->isSet() ){
780 
781 #ifdef _DEBUG_
782  cout <<"adding LCE "<< (*LCE)->get_event_name() <<" : "<< (*LCE)->get_rank() << endl;
783 #endif
784 
785  rank = (int)(*LCE)->get_rank();
786 
787  if(rank < 0)
788  fatal("rank %i for LCE \"%s\" cannot be negative, please provide a positive rank number.\n", rank, (*LCE)->get_name().c_str());
789 
790  if(_LifeCycle[rank]){
791  fatal("rank %i for LCE \"%s\" is already assigned to \"%s\", please choose a different rank number.\n",
792  rank, (*LCE)->get_name().c_str(), _LifeCycle[rank]->get_name().c_str());
793  }
794  else
795  _LifeCycle[rank] = (*LCE);
796  }
797  LCE++;
798  }
799 
800 }
map< int, LifeCycleEvent * > _LifeCycle
List of the selected life cycle events from the user defined input parameters.
Definition: basicsimulation.h:224
void fatal(const char *str,...)
Definition: output.cc:96

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

Referenced by SimRunner::setLifeCycle().

◆ 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
689 {
690  LCE_ITER LCE = _LifeCycle.begin();
691 
692  while(LCE != _LifeCycle.end()) {
693  if( LCE->second->get_event_name().compare(name) == 0)
694  return LCE->second;
695  LCE++;
696  }
697 
698  return NULL;
699 }
map< int, LifeCycleEvent * >::const_iterator LCE_ITER
Definition: basicsimulation.h:226

References _LifeCycle.

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

◆ 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
704 {
705  LifeCycleEvent* event = NULL;
706 
707  for(LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++)
708  {
709  if( LCE->second->has_parameter(param)) {
710  event = LCE->second;
711  break; //this assumes that parameters are unique, the first component found with that parameter is returned
712  }
713  }
714 
715  return event;
716 }
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73

References _LifeCycle.

Referenced by Metapop::loadPopFromBinarySource().

◆ 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
660 {
661  TRAIT_ITER trait = _currentTraits.find(type);
662 
663  if(trait != _currentTraits.end())
664  return trait->second;
665  else
666  return NULL;
667 }
map< trait_t, TraitPrototype * >::const_iterator TRAIT_ITER
Definition: basicsimulation.h:227

References _currentTraits.

Referenced by Metapop::loadPopFromBinarySource().

◆ 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
672 {
673  TraitPrototype* TP = NULL;
674 
675  for(TRAIT_ITER trait = _currentTraits.begin(); trait != _currentTraits.end(); trait++)
676  {
677  if( trait->second->has_parameter(param)) {
678  TP = trait->second;
679  break; //this assumes that parameters are unique, the first component found with that parameter is returned
680  }
681  }
682 
683  return TP;
684 }
TTrait setter.
Definition: ttrait.h:125

References _currentTraits.

Referenced by Metapop::loadPopFromBinarySource().

◆ get_currentParams()

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

Accessor to the list of the selected parameter sets.

Returns
list of ParamSet
214 {return _currentParams;}

◆ getFirstRequiredAgeInLifeCycle()

age_t SimBuilder::getFirstRequiredAgeInLifeCycle ( )
805 {
806  age_t requiredAgeClass = NONE;
807 
808  for(LCE_ITER IT = _LifeCycle.begin();
809  IT != _LifeCycle.end() && requiredAgeClass == NONE;
810  IT++)
811  requiredAgeClass = IT->second->requiredAgeClass();
812 
813  return requiredAgeClass;
814 }
#define NONE
No age flag.
Definition: types.h:48
unsigned int age_t
Age class flags.
Definition: types.h:46

References _LifeCycle, and NONE.

Referenced by Metapop::setPopulation().

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

Locations of visitors to this page
Catalogued on GSR