Nemo  2.3.46
simulation.h
Go to the documentation of this file.
1 
31 #ifndef SIMULATION_H
32 #define SIMULATION_H
33 
34 #include <list>
35 #include <map>
36 #include <vector>
37 #include <string>
38 #include <time.h>
39 #include "basicsimulation.h"
40 #include "fileservices.h"
41 #include "statservices.h"
42 #include "updaterservices.h"
43 #include "metapop.h"
44 
45 
53 class SimRunner: public SimBuilder {
54 private:
55 
57 
59 
60  std::string _logfile;
61 
62  char _startTime[20], _endTime[20];
63 
64  std::string _simElapsedTime;
68  unsigned int _meanGenLength;
69 
70  //parameters:
72  unsigned int _generations;
74  unsigned int _replicates;
76  unsigned int _currentReplicate;
78  unsigned int _currentGeneration;
82  unsigned long _random_seed;
84  std::string _modeArg;
86  unsigned int _mode;
88  bool _doRun;
90  std::string _postexec_script;
92  std::string _postexec_args;
95 
96 public:
97 
99 
101 
103 
104 public:
105 
106  SimRunner (Metapop* pop) : _my_mpi_manager(0)
107  {
108  attach_pop(pop);
109  }
111  ~SimRunner ( );
113  bool init ( );
120  bool init_components (map< string,string >& simparams);
121 
123  void setLifeCycle ( );
124 
126  void setForFirstGeneration ( );
127 
129  void init_random_seed ( );
130 
132  void reset ( );
133 
136  std::string setElapsedTime (clock_t time);
137 
140  void register_component (SimComponent* cmpt);
144  void reset_services ( );
150  list<StatRecBase*> get_allRegisteredStats ( ) {return _StatServices.getAllStats();}
151 
153  bool run ( int ARGC, char **ARGV );
155  bool run ( );
158  bool run_event (string& name);
161  void step (unsigned int nb_gen);
162 
166  void attach_pop (Metapop* pop) {_thePop = pop;this->_components.push_back(_thePop);}
170  Metapop* get_pop ( ) {return _thePop;}
174  bool build_pop ( );
175 
178 
179  void Replicate_LOOP();
180 
184  void Cycle(char* startTime);
186 
187  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen; _thePop->setCurrentGeneration(gen);}
188  unsigned int getCurrentGeneration () {return _currentGeneration;}
189  void setGenerations (unsigned int gen) {_generations = gen; _thePop->setGenerations(gen);}
190  unsigned int getGenerations () {return _generations;}
191  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl; _thePop->setCurrentReplicate(repl);}
192  unsigned int getCurrentReplicate () {return _currentReplicate;}
193  void setReplicates (unsigned int repl) {_replicates = repl; _thePop->setReplicates(repl);}
194  unsigned int getReplicates () {return _replicates;}
196 
197  void printLogHeader ();
198  void printLog ();
199  void runPostExec();
200 };
201 
202 
203 #endif
204 
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:162
Class to update the simulation components' state during a simulation.
Definition: updaterservices.h:64
unsigned int getGenerations()
Definition: simulation.h:190
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
char _startTime[20]
Definition: simulation.h:62
void register_component_handlers()
Register all the Handlers of the currently active simulation components.
Definition: simulation.cc:198
int _currentRankInLifeCycle
The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes...
Definition: simulation.h:80
void printLogHeader()
Definition: simulation.cc:662
StatServices _StatServices
Definition: simulation.h:100
UpdaterServices _ParamUpdaterManager
Definition: simulation.h:102
Metapop * _thePop
Definition: simulation.h:58
unsigned int _mode
The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init) ...
Definition: simulation.h:86
bool _doRun
Boolean set when not in dryrun mode.
Definition: simulation.h:88
~SimRunner()
Dstror.
Definition: simulation.cc:148
list< StatRecBase * > get_allRegisteredStats()
Returns the complete list of the stat recorders loaded after parameters initialization.
Definition: simulation.h:150
SimRunner(Metapop *pop)
Definition: simulation.h:106
void register_component(SimComponent *cmpt)
Register the different Handler's attached to a SimComponent.
Definition: simulation.cc:189
void reset_services()
Resets the FileServices and StatServices.
Definition: simulation.cc:177
unsigned int getCurrentReplicate()
Definition: simulation.h:192
void setReplicates(unsigned int repl)
Definition: metapop.h:268
void setGenerations(unsigned int gen)
Definition: metapop.h:266
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
void setCurrentGeneration(unsigned int gen)
Definition: simulation.h:187
void Cycle(char *startTime)
Life cycle loop, executes the list of LCEs _generations times.
Definition: simulation.cc:560
unsigned int _replicates
Number of replicates to iterate.
Definition: simulation.h:74
bool run()
First loop of the simulation, performs the simulations stored in the ParamManager base class...
Definition: simulation.cc:343
Metapop * get_pop()
Accessor to the pop ptr.
Definition: simulation.h:170
bool init()
Checks simulation parameters and init the FileServices with the base filename.
Definition: simulation.cc:61
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: simulation.h:76
FileServices _FileServices
Definition: simulation.h:98
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: simulation.h:78
void reset()
Resets all the parameters to the unset state, resets the services.
Definition: simulation.cc:160
unsigned int getReplicates()
Definition: simulation.h:194
list< StatRecBase * > getAllStats()
Definition: statservices.cc:389
std::string setElapsedTime(clock_t time)
Compute and print the simulation's elapsed time to stdout.
Definition: simulation.cc:637
Performs the setup of the Metapop and SimComponents and runs the simulation.
Definition: simulation.h:53
std::string _postexec_script
The path to the script to be executed after last simulation.
Definition: simulation.h:90
void setForFirstGeneration()
Sets the population and the services ready for the first generation of a new replicate.
Definition: simulation.cc:544
void Replicate_LOOP()
Replicate loop, iterates the life cycle _replicates times.
Definition: simulation.cc:442
bool init_components(map< string, string > &simparams)
Performs the initialization of the different components of the simulation.
Definition: simulation.cc:221
StatServices * get_StatServices()
Returns the StatServices.
Definition: simulation.h:148
clock_t _meanReplElapsedTime
Clock counter, for logging.
Definition: simulation.h:66
void runPostExec()
Definition: simulation.cc:745
Interface to all basic components of a simulation (traits, life cycle events, pop, etc. ).
Definition: simcomponent.h:45
void setReplicates(unsigned int repl)
Definition: simulation.h:193
std::string _modeArg
The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init').
Definition: simulation.h:84
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:288
void printLog()
Definition: simulation.cc:690
bool run_event(string &name)
Execute one specific life cycle event, if present in the list of current events.
Definition: simulation.cc:603
char _endTime[20]
Definition: simulation.h:62
void step(unsigned int nb_gen)
Iterates the life cycle.
Definition: simulation.cc:623
bool _do_postexec
Boolean set when a post-exec script must be executed.
Definition: simulation.h:94
std::string _logfile
Definition: simulation.h:60
bool build_pop()
Calls the Metapop init procedure with current traits and LCEs.
void init_random_seed()
Initialize the seed of the random generator.
Definition: simulation.cc:283
void attach_pop(Metapop *pop)
Attach a pop to the simulation.
Definition: simulation.h:166
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:71
MPImanager * _my_mpi_manager
Definition: simulation.h:56
unsigned int getCurrentGeneration()
Definition: simulation.h:188
std::string _simElapsedTime
Definition: simulation.h:64
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:287
Definition: MPImanager.h:48
unsigned int _meanGenLength
Generation counter, for logging.
Definition: simulation.h:68
void setLifeCycle()
Sets the list of LifeCyckeEvent's currently active.
Definition: simulation.cc:211
unsigned int _generations
Number of generations to iterate.
Definition: simulation.h:72
void setGenerations(unsigned int gen)
Definition: simulation.h:189
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
std::string _postexec_args
Arguments to pass to the post-exec script.
Definition: simulation.h:92
int getCurrentRankInLifeCycle()
Definition: simulation.h:195
unsigned long _random_seed
The startup random seed of the random generator.
Definition: simulation.h:82
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:146
void setCurrentReplicate(unsigned int repl)
Definition: simulation.h:191

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR