Nemo
2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
|
Performs the setup of the Metapop and SimComponents and runs the simulation. More...
#include <simulation.h>
Public Member Functions | |
SimRunner (Metapop *pop) | |
~SimRunner () | |
Dstror. More... | |
bool | init () |
Checks simulation parameters and init the FileServices with the base filename. More... | |
bool | init_components (map< string, string > &simparams) |
Performs the initialization of the different components of the simulation. More... | |
void | setLifeCycle () |
Sets the list of LifeCyckeEvent's currently active. More... | |
void | setForFirstGeneration () |
Sets the population and the services ready for the first generation of a new replicate. More... | |
void | init_random_seed () |
Initialize the seed of the random generator. More... | |
void | reset () |
Resets all the parameters to the unset state, resets the services. More... | |
std::string | setElapsedTime (clock_t time) |
Compute and print the simulation's elapsed time to stdout. More... | |
void | register_component (SimComponent *cmpt) |
Register the different Handler's attached to a SimComponent. More... | |
void | register_component_handlers () |
Register all the Handlers of the currently active simulation components. More... | |
void | reset_services () |
Resets the FileServices and StatServices. More... | |
FileServices * | get_FileServices () |
Returns the FileServices. More... | |
StatServices * | get_StatServices () |
Returns the StatServices. More... | |
list< StatRecBase * > | get_allRegisteredStats () |
Returns the complete list of the stat recorders loaded after parameters initialization. More... | |
bool | run (int ARGC, char **ARGV) |
First loop of the simulation, performs the simulations stored in the ParamManager base class. More... | |
bool | run () |
First loop of the simulation, performs the simulations stored in the ParamManager base class. More... | |
bool | run_event (string &name) |
Execute one specific life cycle event, if present in the list of current events. More... | |
void | step (unsigned int nb_gen) |
Iterates the life cycle. More... | |
void | attach_pop (Metapop *pop) |
Attach a pop to the simulation. More... | |
Metapop * | get_pop () |
Accessor to the pop ptr. More... | |
bool | build_pop () |
Calls the Metapop init procedure with current traits and LCEs. More... | |
void | setCurrentGeneration (unsigned int gen) |
unsigned int | getCurrentGeneration () |
void | setGenerations (unsigned int gen) |
unsigned int | getGenerations () |
void | setCurrentReplicate (unsigned int repl) |
unsigned int | getCurrentReplicate () |
void | setReplicates (unsigned int repl) |
unsigned int | getReplicates () |
int | getCurrentRankInLifeCycle () |
void | printLogHeader () |
void | printLog () |
void | runPostExec () |
Run the post-exec script after all simulations have finished. More... | |
void | runPostExecReplicateWise () |
Run the post-exec script after each replicate, adds filename and replicate number as args. More... | |
Main loops | |
void | Replicate_LOOP () |
Replicate loop, iterates the life cycle _replicates times. More... | |
void | Cycle (char *startTime) |
Life cycle loop, executes the list of LCEs _generations times. More... | |
![]() | |
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... | |
TraitPrototype * | get_current_trait (trait_t type) |
Accessor to the list of current trait prototypes. More... | |
TraitPrototype * | get_current_traitWithParameter (string ¶m) |
Accessor to the current trait prototypes conditioned on ownership of a specified parameter. More... | |
LifeCycleEvent * | get_current_event (string &name) |
Accessor to the list of current LCEs. More... | |
LifeCycleEvent * | get_current_eventWithParameter (string ¶m) |
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 () |
![]() | |
ParamManager () | |
Cstor. More... | |
~ParamManager () | |
void | add_paramset (ParamSet *paramset) |
Adds a ParamSet to the list of the parameter sets of the simulation. More... | |
ParamSet * | get_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... | |
![]() | |
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... | |
TraitPrototype * | get_trait (string name) |
Search for component with "name" in the trait prototype list. More... | |
LifeCycleEvent * | get_LCE (string name) |
Search for component with "name" in the life cycle events list. More... | |
Public Attributes | |
FileServices | _FileServices |
StatServices | _StatServices |
UpdaterServices | _ParamUpdaterManager |
Private Attributes | |
MPImanager * | _my_mpi_manager |
Metapop * | _thePop |
std::string | _logfile |
char | _startTime [20] |
char | _endTime [20] |
std::string | _simElapsedTime |
clock_t | _meanReplElapsedTime |
Clock counter, for logging. More... | |
unsigned int | _meanGenLength |
Generation counter, for logging. More... | |
unsigned int | _generations |
Number of generations to iterate. More... | |
unsigned int | _replicates |
Number of replicates to iterate. More... | |
unsigned int | _currentReplicate |
The current replicate in the replicate loop, starts at 1. More... | |
unsigned int | _currentGeneration |
The current generation in the generation loop, starts at 1. More... | |
int | _currentRankInLifeCycle |
The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes. More... | |
unsigned long | _random_seed |
The startup random seed of the random generator. More... | |
std::string | _modeArg |
The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init'). More... | |
unsigned int | _mode |
The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init) More... | |
bool | _doRun |
Boolean set when not in dryrun mode. More... | |
std::string | _postexec_script |
The path to the script to be executed after last simulation. More... | |
std::string | _postexec_args |
Arguments to pass to the post-exec script. More... | |
bool | _do_postexec_replicatewise |
Boolean to trigger replicate-wise execution of post script. More... | |
bool | _do_postexec |
Boolean set when a post-exec script must be executed. More... | |
Additional Inherited Members | |
![]() | |
typedef map< int, LifeCycleEvent * >::const_iterator | LCE_ITER |
typedef map< trait_t, TraitPrototype * >::const_iterator | TRAIT_ITER |
![]() | |
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... | |
![]() | |
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... | |
![]() | |
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... | |
Performs the setup of the Metapop and SimComponents and runs the simulation.
This class implements the two main loops of a simulation, the replicate and the generation loops. The replicate loop iterates the generation loop which itself iterates the life cycle loop composed of the LCEs selected by the user. A SimRunner brings together the basic simulation components and a metapopulation on which they act. It perfoms the setups necessary to have a Metapop ready for the simulation and runs the different simulations stored in its ParamManager base class. Also hosts the file and stat services.
|
inline |
References attach_pop().
SimRunner::~SimRunner | ( | ) |
Dstror.
|
inline |
Attach a pop to the simulation.
Adds it to the components list.
pop | ptr to the pop object |
References ComponentManager::_components, and _thePop.
Referenced by SimRunner().
bool SimRunner::build_pop | ( | ) |
Calls the Metapop init procedure with current traits and LCEs.
void SimRunner::Cycle | ( | char * | startTime | ) |
Life cycle loop, executes the list of LCEs _generations times.
startTime | the starting time of the current replicate. |
References _currentGeneration, _currentReplicate, _generations, _replicates, _thePop, Metapop::isAlive(), message(), Metapop::setCurrentGeneration(), and step().
Referenced by Replicate_LOOP().
|
inline |
Returns the complete list of the stat recorders loaded after parameters initialization.
References _StatServices, and StatServices::getAllStats().
|
inline |
Returns the FileServices.
References _FileServices.
Referenced by Metapop::loadPopFromTraitFile().
|
inline |
|
inline |
Returns the StatServices.
References _StatServices.
Referenced by LCE_StatServiceNotifier::LCE_StatServiceNotifier().
|
inline |
References _currentGeneration.
Referenced by SIMenv::getCurrentGeneration().
|
inline |
References _currentRankInLifeCycle.
Referenced by SIMenv::getCurrentRankInLifeCycle().
|
inline |
References _currentReplicate.
Referenced by SIMenv::getCurrentReplicate().
|
inline |
References _generations.
Referenced by SIMenv::getGenerations().
|
inline |
References _replicates.
Referenced by SIMenv::getReplicates().
bool SimRunner::init | ( | ) |
Checks simulation parameters and init the FileServices with the base filename.
References _do_postexec, _do_postexec_replicatewise, _doRun, _FileServices, _generations, _logfile, _mode, _modeArg, ParamManager::_paramSet, _postexec_args, _postexec_script, _replicates, error(), ParamSet::getArg(), ParamSet::getValue(), ParamSet::isSet(), printLogHeader(), FileServices::setBasename(), FileServices::setMode(), FileServices::setRootDir(), and SILENT_RUN.
Referenced by init_components().
bool SimRunner::init_components | ( | map< string, string > & | simparams | ) |
Performs the initialization of the different components of the simulation.
Builds the list of the simulation parameters and load the components that have their ParamSet in the set state. Builds the population, the TraitPrototype, and life cycle, register the various services and init the StatServices and ParameterUpdaterManager.
simparams | the hashtable containing the parameters and their arguments parsed from the init file |
References _FileServices, _generations, SimBuilder::_LifeCycle, _ParamUpdaterManager, _replicates, _StatServices, _thePop, SimBuilder::build_currentParams(), SimBuilder::build_currentTraits(), error(), UpdaterServices::hasTemporals(), Metapop::init(), init(), StatServices::init(), UpdaterServices::init(), LifeCycleEvent::init(), init_random_seed(), IndFactory::makePrototype(), message(), register_component_handlers(), reset(), FileServices::set_pop_ptr(), StatServices::set_pop_ptr(), Metapop::setGenerations(), setLifeCycle(), LCE_ParamUpdaterNotifier::setManager(), and Metapop::setReplicates().
Referenced by run().
void SimRunner::init_random_seed | ( | ) |
Initialize the seed of the random generator.
References _myenv, ParamManager::_paramSet, _random_seed, ParamSet::getValue(), RAND::init(), MPIenv::isMaster(), ParamSet::isSet(), and message().
Referenced by init_components().
void SimRunner::printLog | ( | ) |
References _endTime, _FileServices, _logfile, _meanGenLength, _meanReplElapsedTime, _replicates, _simElapsedTime, _startTime, error(), FileServices::getBaseFileName(), FileServices::getFirstWriter(), FileServices::getLastWriter(), MAIN_VERSION, MINOR_VERSION, RELEASE, REVISION, setElapsedTime(), and VERSION_DATE.
Referenced by run().
void SimRunner::printLogHeader | ( | ) |
References _logfile, and error().
Referenced by init().
void SimRunner::register_component | ( | SimComponent * | cmpt | ) |
Register the different Handler's attached to a SimComponent.
cmpt | a SimComponent |
References _FileServices, _ParamUpdaterManager, _StatServices, FileServices::load(), StatServices::load(), and UpdaterServices::load().
Referenced by register_component_handlers().
void SimRunner::register_component_handlers | ( | ) |
Register all the Handlers of the currently active simulation components.
References SimBuilder::_currentTraits, SimBuilder::_LifeCycle, _thePop, and register_component().
Referenced by init_components().
void SimRunner::Replicate_LOOP | ( | ) |
Replicate loop, iterates the life cycle _replicates times.
References _currentGeneration, _currentReplicate, _do_postexec_replicatewise, _FileServices, _generations, _meanGenLength, _meanReplElapsedTime, _my_mpi_manager, _myenv, _replicates, _StatServices, _thePop, Metapop::clear(), Cycle(), FileHandler::FHwrite(), MPImanager::finish(), ComponentManager::get_LCE(), ParamManager::get_paramset(), MPImanager::init(), Metapop::isAlive(), MPIenv::isMaster(), MPImanager::iterate(), message(), FileServices::notify(), runPostExecReplicateWise(), Metapop::setCurrentGeneration(), Metapop::setCurrentReplicate(), and setForFirstGeneration().
Referenced by run().
void SimRunner::reset | ( | ) |
Resets all the parameters to the unset state, resets the services.
References ParamManager::_allParams, message(), and reset_services().
Referenced by init_components(), and ~SimRunner().
void SimRunner::reset_services | ( | ) |
Resets the FileServices and StatServices.
References _FileServices, _ParamUpdaterManager, _StatServices, message(), FileServices::reset(), StatServices::reset(), and UpdaterServices::reset().
Referenced by reset().
bool SimRunner::run | ( | ) |
First loop of the simulation, performs the simulations stored in the ParamManager base class.
References SimBuilder::_currentTraits, _do_postexec, _doRun, _endTime, _FileServices, SimBuilder::_LifeCycle, _mode, _modeArg, _myenv, _random_seed, _simElapsedTime, ParamManager::_simRecords, _startTime, _thePop, IndFactory::clearPrototype(), RAND::free(), FileServices::getBaseFileName(), IndFactory::getIndividualProtoype(), Metapop::getSourceFileType(), Metapop::getSourceName(), IndFactory::getTraitIndex(), Individual::getTraitNumber(), FileServices::init(), init_components(), MPIenv::isMaster(), Metapop::isSourceLoad(), FileServices::log(), FileServices::log_simparams(), message(), printLog(), Replicate_LOOP(), runPostExec(), setElapsedTime(), tstring::ulong2str(), and warning().
Referenced by run().
bool SimRunner::run | ( | int | ARGC, |
char ** | ARGV | ||
) |
First loop of the simulation, performs the simulations stored in the ParamManager base class.
References _my_mpi_manager, _myenv, _thePop, ParamManager::build_allParams(), ParamManager::build_records(), fatal(), MPIenv::finish(), ParamsParser::getParsedParameters(), MPIenv::isMaster(), run(), and START_MESSAGE().
Referenced by main().
bool SimRunner::run_event | ( | string & | name | ) |
Execute one specific life cycle event, if present in the list of current events.
name | the name of the (paramSet of the) LifeCycleEvent to execute. |
References error(), and SimBuilder::get_current_event().
void SimRunner::runPostExec | ( | ) |
Run the post-exec script after all simulations have finished.
References _postexec_args, _postexec_script, error(), and message().
Referenced by run().
void SimRunner::runPostExecReplicateWise | ( | ) |
Run the post-exec script after each replicate, adds filename and replicate number as args.
References _currentReplicate, _FileServices, _postexec_args, _postexec_script, error(), FileServices::getBaseFileName(), tstring::int2str(), and message().
Referenced by Replicate_LOOP().
|
inline |
References _currentGeneration, _thePop, and Metapop::setCurrentGeneration().
|
inline |
References _currentReplicate, _thePop, and Metapop::setCurrentReplicate().
std::string SimRunner::setElapsedTime | ( | clock_t | time | ) |
Compute and print the simulation's elapsed time to stdout.
time | elapsed time in ticks count |
Referenced by printLog(), and run().
void SimRunner::setForFirstGeneration | ( | ) |
Sets the population and the services ready for the first generation of a new replicate.
References _currentReplicate, _ParamUpdaterManager, _replicates, _StatServices, _thePop, UpdaterServices::notify(), StatServices::resetCurrentOccurrence(), Metapop::setCurrentGeneration(), and Metapop::setPopulation().
Referenced by Replicate_LOOP().
|
inline |
References _generations, _thePop, and Metapop::setGenerations().
void SimRunner::setLifeCycle | ( | ) |
Sets the list of LifeCyckeEvent's currently active.
References SimBuilder::_LifeCycle, _thePop, and SimBuilder::build_LifeCycle().
Referenced by init_components().
|
inline |
References _replicates, _thePop, and Metapop::setReplicates().
void SimRunner::step | ( | unsigned int | nb_gen | ) |
Iterates the life cycle.
nb_gen | number of iterations to perform. |
References _currentRankInLifeCycle, SimBuilder::_LifeCycle, _thePop, and Metapop::setCurrentAge().
Referenced by Cycle().
|
private |
The current generation in the generation loop, starts at 1.
Referenced by Cycle(), getCurrentGeneration(), Replicate_LOOP(), and setCurrentGeneration().
|
private |
The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes.
Referenced by getCurrentRankInLifeCycle(), and step().
|
private |
The current replicate in the replicate loop, starts at 1.
Referenced by Cycle(), getCurrentReplicate(), Replicate_LOOP(), runPostExecReplicateWise(), setCurrentReplicate(), and setForFirstGeneration().
|
private |
|
private |
Boolean to trigger replicate-wise execution of post script.
Referenced by init(), and Replicate_LOOP().
|
private |
|
private |
Referenced by printLog(), and run().
FileServices SimRunner::_FileServices |
|
private |
Number of generations to iterate.
Referenced by Cycle(), getGenerations(), init(), init_components(), Replicate_LOOP(), and setGenerations().
|
private |
Referenced by init(), printLog(), and printLogHeader().
|
private |
Generation counter, for logging.
Referenced by printLog(), and Replicate_LOOP().
|
private |
Clock counter, for logging.
Referenced by printLog(), and Replicate_LOOP().
|
private |
|
private |
|
private |
Referenced by Replicate_LOOP(), and run().
UpdaterServices SimRunner::_ParamUpdaterManager |
Referenced by init_components(), register_component(), reset_services(), and setForFirstGeneration().
|
private |
Arguments to pass to the post-exec script.
Referenced by init(), runPostExec(), and runPostExecReplicateWise().
|
private |
The path to the script to be executed after last simulation.
Referenced by init(), runPostExec(), and runPostExecReplicateWise().
|
private |
The startup random seed of the random generator.
Referenced by init_random_seed(), and run().
|
private |
Number of replicates to iterate.
Referenced by Cycle(), getReplicates(), init(), init_components(), printLog(), Replicate_LOOP(), setForFirstGeneration(), and setReplicates().
|
private |
Referenced by printLog(), and run().
|
private |
Referenced by printLog(), and run().
StatServices SimRunner::_StatServices |
|
private |