Nemo  2.3.46
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...
 
LifeCycleEventget_current_event (string &name)
 Accessor to the list of current LCEs. 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

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

Constructor & Destructor Documentation

SimBuilder::SimBuilder ( )
inline
164 { }
SimBuilder::SimBuilder ( const SimBuilder SB)

copy cstor.

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

551 {
552  list< TraitPrototype* >::const_iterator TT = SB._TTrait_Templates.begin();
553 
554  for(;TT != SB._TTrait_Templates.end(); TT++) add_trait( (*TT)->clone() );
555 
556  list< LifeCycleEvent* >::const_iterator LCE = SB._LCE_Templates.begin();
557 
558  for(;LCE != SB._LCE_Templates.end(); LCE++) add_LCE( (*LCE)->clone() );
559 
560 
561  _paramSet = SB._paramSet;
562 
563  build_allParams();
564 }
ParamSet _paramSet
The ParamSet param set of the simulation.
Definition: basicsimulation.h:145
list< LifeCycleEvent * > _LCE_Templates
List of all the life-cycle events of the simulation, a subset of _components list.
Definition: basicsimulation.h:75
void add_LCE(LifeCycleEvent *event)
Add a life cycle event to the template and component lists.
Definition: basicsimulation.h:58
void build_allParams()
Clears and fills the _allParams list with the ParamSet's of the simulation components.
Definition: basicsimulation.cc:115
void add_trait(TraitPrototype *trait)
Add a trait prototype to the template and component lists.
Definition: basicsimulation.h:56
list< TraitPrototype * > _TTrait_Templates
List of all trait prototypes of the simulation, a subset of _components list.
Definition: basicsimulation.h:73
SimBuilder::~SimBuilder ( )

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

569 {
570 #ifdef _DEBUG_
571  message("SimBuilder::~SimBuilder\n");
572 #endif
573 
574  _components.clear();
575 
576  list< TraitPrototype* >::iterator TT_it = _TTrait_Templates.begin();
577 
578  while(TT_it != _TTrait_Templates.end()) {
579  delete (*TT_it);
580  TT_it++;
581  }
582 
583  list< LifeCycleEvent* >::iterator LCE_it = _LCE_Templates.begin();
584 
585  while(LCE_it != _LCE_Templates.end()) {
586  delete (*LCE_it);
587  LCE_it++;
588  }
589 
590 }
void message(const char *message,...)
Definition: output.cc:40
list< LifeCycleEvent * > _LCE_Templates
List of all the life-cycle events of the simulation, a subset of _components list.
Definition: basicsimulation.h:75
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:71
list< TraitPrototype * > _TTrait_Templates
List of all trait prototypes of the simulation, a subset of _components list.
Definition: basicsimulation.h:73

Member Function Documentation

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

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

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

622 {
623  if(! this->set_parameters(simparams, false) ) return false;
624 
625  //empty the current parameters container:
626  _currentParams.clear();
627 
628  list<ParamSet*>::iterator current_paramset = this->_allParams.begin();
629 
630  //add all set parameters to the list of the current params:
631  while(current_paramset != this->_allParams.end()){
632  if((*current_paramset)->isSet()) {
633 #ifdef _DEBUG_
634  message("SimBuilder::build_currentParams:adding paramset %s\n",
635  (*current_paramset)->getName().c_str());
636 #endif
637  _currentParams.push_back(*current_paramset);
638  }
639  current_paramset++;
640  }
641 
642  return true;
643 }
void message(const char *message,...)
Definition: output.cc:40
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:137
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 * > _currentParams
List of the selected simulation components from the user defined input parameters.
Definition: basicsimulation.h:200
map< trait_t, TraitPrototype * > & SimBuilder::build_currentTraits ( )

Selects the trait prototypes that have their parameters set.

Returns
Hashtable of the trait prototypes

References _currentTraits, and ComponentManager::_TTrait_Templates.

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

648 {
649  //build the list of Traits for this simulation:
650  list< TraitPrototype* >::iterator trait = this->_TTrait_Templates.begin();
651 
652  _currentTraits.clear();
653 
654  while(trait != this->_TTrait_Templates.end()) {
655 
656  if( (*trait)->get_paramset()->isSet() ){
657  _currentTraits[(*trait)->get_type()] = (*trait);
658  }
659 
660  trait++;
661  }
662 
663  return _currentTraits;
664 }
map< trait_t, TraitPrototype * > _currentTraits
List of the selected trait prototypes from the user defined input parameters.
Definition: basicsimulation.h:202
list< TraitPrototype * > _TTrait_Templates
List of all trait prototypes of the simulation, a subset of _components list.
Definition: basicsimulation.h:73
void SimBuilder::build_LifeCycle ( )

Selects the life cycle events that have their parameters set.

References ComponentManager::_LCE_Templates, and _LifeCycle.

Referenced by SimRunner::setLifeCycle().

669 {
670  //build the list of the life cycle events for this simulation:
671  list< LifeCycleEvent* >::iterator LCE = this->_LCE_Templates.begin();
672 
673  _LifeCycle.clear();
674 
675 
676  while(LCE != this->_LCE_Templates.end()) {
677  if( (*LCE)->get_paramset()->isSet() ){
678 #ifdef _DEBUG_
679  cout <<"adding LCE "<< (*LCE)->get_event_name() <<" : "<< (*LCE)->get_rank() << endl;
680 #endif
681  _LifeCycle[(int)(*LCE)->get_rank()] = (*LCE);
682  }
683  LCE++;
684  }
685 
686 }
list< LifeCycleEvent * > _LCE_Templates
List of all the life-cycle events of the simulation, a subset of _components list.
Definition: basicsimulation.h:75
map< int, LifeCycleEvent * > _LifeCycle
List of the selected life cycle events from the user defined input parameters.
Definition: basicsimulation.h:204
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

References _LifeCycle.

Referenced by SimRunner::run_event().

607 {
608  LCE_ITER LCE = _LifeCycle.begin();
609 
610  while(LCE != _LifeCycle.end()) {
611  if( LCE->second->get_event_name().compare(name) == 0)
612  return LCE->second;
613  LCE++;
614  }
615 
616  return NULL;
617 }
map< int, LifeCycleEvent * >::const_iterator LCE_ITER
Definition: basicsimulation.h:206
map< int, LifeCycleEvent * > _LifeCycle
List of the selected life cycle events from the user defined input parameters.
Definition: basicsimulation.h:204
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

References _currentTraits.

595 {
596  TRAIT_ITER trait = _currentTraits.find(type);
597 
598  if(trait != _currentTraits.end())
599  return trait->second;
600  else
601  return NULL;
602 }
map< trait_t, TraitPrototype * > _currentTraits
List of the selected trait prototypes from the user defined input parameters.
Definition: basicsimulation.h:202
map< trait_t, TraitPrototype * >::const_iterator TRAIT_ITER
Definition: basicsimulation.h:207
list<ParamSet*>& SimBuilder::get_currentParams ( )
inline

Accessor to the list of the selected parameter sets.

Returns
list of ParamSet
194 {return _currentParams;}
list< ParamSet * > _currentParams
List of the selected simulation components from the user defined input parameters.
Definition: basicsimulation.h:200
age_t SimBuilder::getFirstRequiredAgeInLifeCycle ( )

References _LifeCycle, and NONE.

Referenced by Metapop::setPopulation().

691 {
692  age_t requiredAgeClass = NONE;
693 
694  for(LCE_ITER IT = _LifeCycle.begin();
695  IT != _LifeCycle.end() && requiredAgeClass == NONE;
696  IT++)
697  requiredAgeClass = IT->second->requiredAgeClass();
698 
699  return requiredAgeClass;
700 }
unsigned int age_t
Age class flags.
Definition: types.h:46
#define NONE
No age flag.
Definition: types.h:48
map< int, LifeCycleEvent * >::const_iterator LCE_ITER
Definition: basicsimulation.h:206
map< int, LifeCycleEvent * > _LifeCycle
List of the selected life cycle events from the user defined input parameters.
Definition: basicsimulation.h:204

Member Data Documentation

list< ParamSet* > SimBuilder::_currentParams
protected

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

Referenced by build_currentParams().

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(), SimRunner::register_component_handlers(), and SimRunner::run().

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

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