Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
simulation.h
Go to the documentation of this file.
1 
30 #ifndef SIMULATION_H
31 #define SIMULATION_H
32 
33 #include <list>
34 #include <map>
35 #include <vector>
36 #include <string>
37 #include <time.h>
38 #include "basicsimulation.h"
39 #include "fileservices.h"
40 #include "statservices.h"
41 #include "updaterservices.h"
42 #include "metapop.h"
43 
44 
52 class SimRunner: public SimBuilder {
53 private:
54 
56 
58 
59  std::string _logfile;
60 
61  char _startTime[20], _endTime[20];
62 
63  std::string _simElapsedTime;
67  unsigned int _meanGenLength;
68 
69  //parameters:
71  unsigned int _generations;
73  unsigned int _replicates;
75  unsigned int _currentReplicate;
77  unsigned int _currentGeneration;
81  unsigned long _random_seed;
83  std::string _modeArg;
85  unsigned int _mode;
87  bool _doRun;
89  std::string _postexec_script;
91  std::string _postexec_args;
96 
97 public:
98 
100 
102 
104 
105 public:
106 
108  {
109  attach_pop(pop);
110  }
112  ~SimRunner ( );
114  bool init ( );
121  bool init_components (map< string,string >& simparams);
122 
124  void setLifeCycle ( );
125 
127  void setForFirstGeneration ( );
128 
130  void init_random_seed ( );
131 
133  void reset ( );
134 
137  std::string setElapsedTime (clock_t time);
138 
141  void register_component (SimComponent* cmpt);
145  void reset_services ( );
151  list<StatRecBase*> get_allRegisteredStats ( ) {return _StatServices.getAllStats();}
152 
154  bool run ( int ARGC, char **ARGV );
156  bool run ( );
159  bool run_event (string& name);
162  void step (unsigned int nb_gen);
163 
167  void attach_pop (Metapop* pop) {_thePop = pop;this->_components.push_back(_thePop);}
171  Metapop* get_pop ( ) {return _thePop;}
175  bool build_pop ( );
176 
179 
180  void Replicate_LOOP();
181 
185  void Cycle(char* startTime);
187 
188  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen; _thePop->setCurrentGeneration(gen);}
189  unsigned int getCurrentGeneration () {return _currentGeneration;}
190  void setGenerations (unsigned int gen) {_generations = gen; _thePop->setGenerations(gen);}
191  unsigned int getGenerations () {return _generations;}
192  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl; _thePop->setCurrentReplicate(repl);}
193  unsigned int getCurrentReplicate () {return _currentReplicate;}
194  void setReplicates (unsigned int repl) {_replicates = repl; _thePop->setReplicates(repl);}
195  unsigned int getReplicates () {return _replicates;}
197 
198  void printLogHeader ();
199  void printLog ();
201  void runPostExec();
203  void runPostExecReplicateWise ( );
204 };
205 
206 
207 #endif
208 
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:70
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
Definition: MPImanager.h:47
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
void setReplicates(unsigned int repl)
Definition: metapop.h:273
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:297
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:296
void setGenerations(unsigned int gen)
Definition: metapop.h:271
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:167
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:44
Performs the setup of the Metapop and SimComponents and runs the simulation.
Definition: simulation.h:52
std::string _postexec_args
Arguments to pass to the post-exec script.
Definition: simulation.h:91
UpdaterServices _ParamUpdaterManager
Definition: simulation.h:103
unsigned int _replicates
Number of replicates to iterate.
Definition: simulation.h:73
void reset_services()
Resets the FileServices and StatServices.
Definition: simulation.cc:207
void setForFirstGeneration()
Sets the population and the services ready for the first generation of a new replicate.
Definition: simulation.cc:621
unsigned int getReplicates()
Definition: simulation.h:195
clock_t _meanReplElapsedTime
Clock counter, for logging.
Definition: simulation.h:65
char _startTime[20]
Definition: simulation.h:61
unsigned int getGenerations()
Definition: simulation.h:191
bool run()
First loop of the simulation, performs the simulations stored in the ParamManager base class.
Definition: simulation.cc:398
bool init()
Checks simulation parameters and init the FileServices with the base filename.
Definition: simulation.cc:67
unsigned int getCurrentGeneration()
Definition: simulation.h:189
std::string setElapsedTime(clock_t time)
Compute and print the simulation's elapsed time to stdout.
Definition: simulation.cc:725
void step(unsigned int nb_gen)
Iterates the life cycle.
Definition: simulation.cc:708
unsigned int _generations
Number of generations to iterate.
Definition: simulation.h:71
void setGenerations(unsigned int gen)
Definition: simulation.h:190
list< StatRecBase * > get_allRegisteredStats()
Returns the complete list of the stat recorders loaded after parameters initialization.
Definition: simulation.h:151
unsigned int _meanGenLength
Generation counter, for logging.
Definition: simulation.h:67
SimRunner(Metapop *pop)
Definition: simulation.h:107
void Cycle(char *startTime)
Life cycle loop, executes the list of LCEs _generations times.
Definition: simulation.cc:638
void runPostExecReplicateWise()
Run the post-exec script after each replicate, adds filename and replicate number as args.
Definition: simulation.cc:858
void setLifeCycle()
Sets the list of LifeCyckeEvent's currently active.
Definition: simulation.cc:241
unsigned long _random_seed
The startup random seed of the random generator.
Definition: simulation.h:81
void attach_pop(Metapop *pop)
Attach a pop to the simulation.
Definition: simulation.h:167
char _endTime[20]
Definition: simulation.h:61
bool build_pop()
Calls the Metapop init procedure with current traits and LCEs.
StatServices * get_StatServices()
Returns the StatServices.
Definition: simulation.h:149
unsigned int _mode
The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init)
Definition: simulation.h:85
std::string _logfile
Definition: simulation.h:59
MPImanager * _my_mpi_manager
Definition: simulation.h:55
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:147
void setCurrentGeneration(unsigned int gen)
Definition: simulation.h:188
bool _doRun
Boolean set when not in dryrun mode.
Definition: simulation.h:87
~SimRunner()
Dstror.
Definition: simulation.cc:178
FileServices _FileServices
Definition: simulation.h:99
void runPostExec()
Run the post-exec script after all simulations have finished.
Definition: simulation.cc:833
void reset()
Resets all the parameters to the unset state, resets the services.
Definition: simulation.cc:190
int _currentRankInLifeCycle
The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes.
Definition: simulation.h:79
std::string _postexec_script
The path to the script to be executed after last simulation.
Definition: simulation.h:89
Metapop * get_pop()
Accessor to the pop ptr.
Definition: simulation.h:171
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: simulation.h:75
int getCurrentRankInLifeCycle()
Definition: simulation.h:196
bool init_components(map< string, string > &simparams)
Performs the initialization of the different components of the simulation.
Definition: simulation.cc:251
bool _do_postexec_replicatewise
Boolean to trigger replicate-wise execution of post script.
Definition: simulation.h:93
Metapop * _thePop
Definition: simulation.h:57
void init_random_seed()
Initialize the seed of the random generator.
Definition: simulation.cc:314
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: simulation.h:77
void printLog()
Definition: simulation.cc:778
void register_component(SimComponent *cmpt)
Register the different Handler's attached to a SimComponent.
Definition: simulation.cc:219
void Replicate_LOOP()
Replicate loop, iterates the life cycle _replicates times.
Definition: simulation.cc:518
void register_component_handlers()
Register all the Handlers of the currently active simulation components.
Definition: simulation.cc:228
void setCurrentReplicate(unsigned int repl)
Definition: simulation.h:192
StatServices _StatServices
Definition: simulation.h:101
void setReplicates(unsigned int repl)
Definition: simulation.h:194
std::string _modeArg
The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init').
Definition: simulation.h:83
std::string _simElapsedTime
Definition: simulation.h:63
bool _do_postexec
Boolean set when a post-exec script must be executed.
Definition: simulation.h:95
void printLogHeader()
Definition: simulation.cc:750
bool run_event(string &name)
Execute one specific life cycle event, if present in the list of current events.
Definition: simulation.cc:688
unsigned int getCurrentReplicate()
Definition: simulation.h:193
The Service class used to manage the StatHandler objects.
Definition: statservices.h:49
list< StatRecBase * > getAllStats()
Definition: statservices.cc:404
Class to update the simulation components' state during a simulation.
Definition: updaterservices.h:63
Nemo2.

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