Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
simulation.h
Go to the documentation of this file.
1 
29 #ifndef SIMULATION_H
30 #define SIMULATION_H
31 
32 #include <list>
33 #include <map>
34 #include <vector>
35 #include <string>
36 #include <time.h>
37 #include "basicsimulation.h"
38 #include "fileservices.h"
39 #include "statservices.h"
40 #include "updaterservices.h"
41 #include "metapop.h"
42 
43 
51 class SimRunner: public SimBuilder {
52 private:
53 
55 
57 
58  std::string _logfile;
59 
60  char _startTime[20], _endTime[20];
61 
62  std::string _simElapsedTime;
66  unsigned int _meanGenLength;
67 
68  //parameters:
70  unsigned int _generations;
72  unsigned int _replicates;
74  unsigned int _currentReplicate;
76  unsigned int _currentGeneration;
80  unsigned long _random_seed;
82  std::string _modeArg;
84  unsigned int _mode;
86  bool _doRun;
88  std::string _postexec_script;
90  std::string _postexec_args;
95 
96 public:
97 
99 
101 
103 
104 public:
105 
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 
135  void expandPreservedMacros ( );
136 
138  void reset ( );
139 
142  std::string setElapsedTime (clock_t time);
143 
146  void register_component (SimComponent* cmpt);
150  void reset_services ( );
156  list<StatRecBase*> get_allRegisteredStats ( ) {return _StatServices.getAllStats();}
157 
159  bool run ( int ARGC, char **ARGV );
161  bool run ( );
164  bool run_event (string& name);
167  void step (unsigned int nb_gen);
168 
172  void attach_pop (Metapop* pop) {_thePop = pop;this->_components.push_back(_thePop);}
176  Metapop* get_pop ( ) {return _thePop;}
180  bool build_pop ( );
181 
184 
185  void Replicate_LOOP();
186 
190  void Cycle(char* startTime);
192 
193  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen; _thePop->setCurrentGeneration(gen);}
194  unsigned int getCurrentGeneration () {return _currentGeneration;}
195  void setGenerations (unsigned int gen) {_generations = gen; _thePop->setGenerations(gen);}
196  unsigned int getGenerations () {return _generations;}
197  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl; _thePop->setCurrentReplicate(repl);}
198  unsigned int getCurrentReplicate () {return _currentReplicate;}
199  void setReplicates (unsigned int repl) {_replicates = repl; _thePop->setReplicates(repl);}
200  unsigned int getReplicates () {return _replicates;}
202 
203  void printLogHeader ();
204  void printLog ();
206  void runPostExec();
208  void runPostExecReplicateWise ( );
209 };
210 
211 
212 #endif
213 
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:69
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:50
Definition: MPImanager.h:46
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:78
void setReplicates(unsigned int repl)
Definition: metapop.h:272
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:296
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:295
void setGenerations(unsigned int gen)
Definition: metapop.h:270
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:166
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:43
Performs the setup of the Metapop and SimComponents and runs the simulation.
Definition: simulation.h:51
std::string _postexec_args
Arguments to pass to the post-exec script.
Definition: simulation.h:90
UpdaterServices _ParamUpdaterManager
Definition: simulation.h:102
unsigned int _replicates
Number of replicates to iterate.
Definition: simulation.h:72
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:655
void expandPreservedMacros()
Expands the macros that were preserved by the P() macro in the input file.
Definition: simulation.cc:351
unsigned int getReplicates()
Definition: simulation.h:200
clock_t _meanReplElapsedTime
Clock counter, for logging.
Definition: simulation.h:64
char _startTime[20]
Definition: simulation.h:60
unsigned int getGenerations()
Definition: simulation.h:196
bool run()
First loop of the simulation, performs the simulations stored in the ParamManager base class.
Definition: simulation.cc:432
bool init()
Checks simulation parameters and init the FileServices with the base filename.
Definition: simulation.cc:67
unsigned int getCurrentGeneration()
Definition: simulation.h:194
std::string setElapsedTime(clock_t time)
Compute and print the simulation's elapsed time to stdout.
Definition: simulation.cc:759
void step(unsigned int nb_gen)
Iterates the life cycle.
Definition: simulation.cc:742
unsigned int _generations
Number of generations to iterate.
Definition: simulation.h:70
void setGenerations(unsigned int gen)
Definition: simulation.h:195
list< StatRecBase * > get_allRegisteredStats()
Returns the complete list of the stat recorders loaded after parameters initialization.
Definition: simulation.h:156
unsigned int _meanGenLength
Generation counter, for logging.
Definition: simulation.h:66
SimRunner(Metapop *pop)
Definition: simulation.h:106
void Cycle(char *startTime)
Life cycle loop, executes the list of LCEs _generations times.
Definition: simulation.cc:672
void runPostExecReplicateWise()
Run the post-exec script after each replicate, adds filename and replicate number as args.
Definition: simulation.cc:892
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:80
void attach_pop(Metapop *pop)
Attach a pop to the simulation.
Definition: simulation.h:172
char _endTime[20]
Definition: simulation.h:60
bool build_pop()
Calls the Metapop init procedure with current traits and LCEs.
StatServices * get_StatServices()
Returns the StatServices.
Definition: simulation.h:154
unsigned int _mode
The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init)
Definition: simulation.h:84
std::string _logfile
Definition: simulation.h:58
MPImanager * _my_mpi_manager
Definition: simulation.h:54
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:152
void setCurrentGeneration(unsigned int gen)
Definition: simulation.h:193
bool _doRun
Boolean set when not in dryrun mode.
Definition: simulation.h:86
~SimRunner()
Dstror.
Definition: simulation.cc:178
FileServices _FileServices
Definition: simulation.h:98
void runPostExec()
Run the post-exec script after all simulations have finished.
Definition: simulation.cc:867
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:78
std::string _postexec_script
The path to the script to be executed after last simulation.
Definition: simulation.h:88
Metapop * get_pop()
Accessor to the pop ptr.
Definition: simulation.h:176
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: simulation.h:74
int getCurrentRankInLifeCycle()
Definition: simulation.h:201
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:92
Metapop * _thePop
Definition: simulation.h:56
void init_random_seed()
Initialize the seed of the random generator.
Definition: simulation.cc:318
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: simulation.h:76
void printLog()
Definition: simulation.cc:812
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:552
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:197
StatServices _StatServices
Definition: simulation.h:100
void setReplicates(unsigned int repl)
Definition: simulation.h:199
std::string _modeArg
The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init').
Definition: simulation.h:82
std::string _simElapsedTime
Definition: simulation.h:62
bool _do_postexec
Boolean set when a post-exec script must be executed.
Definition: simulation.h:94
void printLogHeader()
Definition: simulation.cc:784
bool run_event(string &name)
Execute one specific life cycle event, if present in the list of current events.
Definition: simulation.cc:722
unsigned int getCurrentReplicate()
Definition: simulation.h:198
The Service class used to manage the StatHandler objects.
Definition: statservices.h:48
list< StatRecBase * > getAllStats()
Definition: statservices.cc:403
Class to update the simulation components' state during a simulation.
Definition: updaterservices.h:62
Nemo2.

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR