Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
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;
97 
98 public:
99 
101 
103 
105 
106 public:
107 
109  {
110  attach_pop(pop);
111  }
113  ~SimRunner ( );
115  bool init ( );
122  bool init_components (map< string,string >& simparams);
123 
125  void setLifeCycle ( );
126 
128  void setForFirstGeneration ( );
129 
131  void init_random_seed ( );
132 
134  void reset ( );
135 
138  std::string setElapsedTime (clock_t time);
139 
142  void register_component (SimComponent* cmpt);
146  void reset_services ( );
152  list<StatRecBase*> get_allRegisteredStats ( ) {return _StatServices.getAllStats();}
153 
155  bool run ( int ARGC, char **ARGV );
157  bool run ( );
160  bool run_event (string& name);
163  void step (unsigned int nb_gen);
164 
168  void attach_pop (Metapop* pop) {_thePop = pop;this->_components.push_back(_thePop);}
172  Metapop* get_pop ( ) {return _thePop;}
176  bool build_pop ( );
177 
180 
181  void Replicate_LOOP();
182 
186  void Cycle(char* startTime);
188 
189  void setCurrentGeneration (unsigned int gen) {_currentGeneration = gen; _thePop->setCurrentGeneration(gen);}
190  unsigned int getCurrentGeneration () {return _currentGeneration;}
191  void setGenerations (unsigned int gen) {_generations = gen; _thePop->setGenerations(gen);}
192  unsigned int getGenerations () {return _generations;}
193  void setCurrentReplicate (unsigned int repl) {_currentReplicate = repl; _thePop->setCurrentReplicate(repl);}
194  unsigned int getCurrentReplicate () {return _currentReplicate;}
195  void setReplicates (unsigned int repl) {_replicates = repl; _thePop->setReplicates(repl);}
196  unsigned int getReplicates () {return _replicates;}
198 
199  void printLogHeader ();
200  void printLog ();
202  void runPostExec();
204  void runPostExecReplicateWise ( );
205 };
206 
207 
208 #endif
209 
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:71
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:52
Definition: MPImanager.h:48
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:80
void setReplicates(unsigned int repl)
Definition: metapop.h:274
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:298
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:297
void setGenerations(unsigned int gen)
Definition: metapop.h:272
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:168
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:45
Performs the setup of the Metapop and SimComponents and runs the simulation.
Definition: simulation.h:53
std::string _postexec_args
Arguments to pass to the post-exec script.
Definition: simulation.h:92
UpdaterServices _ParamUpdaterManager
Definition: simulation.h:104
unsigned int _replicates
Number of replicates to iterate.
Definition: simulation.h:74
void reset_services()
Resets the FileServices and StatServices.
Definition: simulation.cc:208
void setForFirstGeneration()
Sets the population and the services ready for the first generation of a new replicate.
Definition: simulation.cc:622
unsigned int getReplicates()
Definition: simulation.h:196
clock_t _meanReplElapsedTime
Clock counter, for logging.
Definition: simulation.h:66
char _startTime[20]
Definition: simulation.h:62
unsigned int getGenerations()
Definition: simulation.h:192
bool run()
First loop of the simulation, performs the simulations stored in the ParamManager base class.
Definition: simulation.cc:399
bool init()
Checks simulation parameters and init the FileServices with the base filename.
Definition: simulation.cc:68
unsigned int getCurrentGeneration()
Definition: simulation.h:190
std::string setElapsedTime(clock_t time)
Compute and print the simulation's elapsed time to stdout.
Definition: simulation.cc:726
void step(unsigned int nb_gen)
Iterates the life cycle.
Definition: simulation.cc:709
unsigned int _generations
Number of generations to iterate.
Definition: simulation.h:72
void setGenerations(unsigned int gen)
Definition: simulation.h:191
list< StatRecBase * > get_allRegisteredStats()
Returns the complete list of the stat recorders loaded after parameters initialization.
Definition: simulation.h:152
unsigned int _meanGenLength
Generation counter, for logging.
Definition: simulation.h:68
SimRunner(Metapop *pop)
Definition: simulation.h:108
void Cycle(char *startTime)
Life cycle loop, executes the list of LCEs _generations times.
Definition: simulation.cc:639
void runPostExecReplicateWise()
Run the post-exec script after each replicate, adds filename and replicate number as args.
Definition: simulation.cc:859
void setLifeCycle()
Sets the list of LifeCyckeEvent's currently active.
Definition: simulation.cc:242
unsigned long _random_seed
The startup random seed of the random generator.
Definition: simulation.h:82
void attach_pop(Metapop *pop)
Attach a pop to the simulation.
Definition: simulation.h:168
char _endTime[20]
Definition: simulation.h:62
bool build_pop()
Calls the Metapop init procedure with current traits and LCEs.
StatServices * get_StatServices()
Returns the StatServices.
Definition: simulation.h:150
unsigned int _mode
The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init)
Definition: simulation.h:86
std::string _logfile
Definition: simulation.h:60
MPImanager * _my_mpi_manager
Definition: simulation.h:56
FileServices * get_FileServices()
Returns the FileServices.
Definition: simulation.h:148
void setCurrentGeneration(unsigned int gen)
Definition: simulation.h:189
bool _doRun
Boolean set when not in dryrun mode.
Definition: simulation.h:88
~SimRunner()
Dstror.
Definition: simulation.cc:179
FileServices _FileServices
Definition: simulation.h:100
void runPostExec()
Run the post-exec script after all simulations have finished.
Definition: simulation.cc:834
void reset()
Resets all the parameters to the unset state, resets the services.
Definition: simulation.cc:191
int _currentRankInLifeCycle
The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes.
Definition: simulation.h:80
std::string _postexec_script
The path to the script to be executed after last simulation.
Definition: simulation.h:90
Metapop * get_pop()
Accessor to the pop ptr.
Definition: simulation.h:172
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: simulation.h:76
int getCurrentRankInLifeCycle()
Definition: simulation.h:197
bool init_components(map< string, string > &simparams)
Performs the initialization of the different components of the simulation.
Definition: simulation.cc:252
bool _do_postexec_replicatewise
Boolean to trigger replicate-wise execution of post script.
Definition: simulation.h:94
Metapop * _thePop
Definition: simulation.h:58
void init_random_seed()
Initialize the seed of the random generator.
Definition: simulation.cc:315
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: simulation.h:78
void printLog()
Definition: simulation.cc:779
void register_component(SimComponent *cmpt)
Register the different Handler's attached to a SimComponent.
Definition: simulation.cc:220
void Replicate_LOOP()
Replicate loop, iterates the life cycle _replicates times.
Definition: simulation.cc:519
void register_component_handlers()
Register all the Handlers of the currently active simulation components.
Definition: simulation.cc:229
void setCurrentReplicate(unsigned int repl)
Definition: simulation.h:193
StatServices _StatServices
Definition: simulation.h:102
void setReplicates(unsigned int repl)
Definition: simulation.h:195
std::string _modeArg
The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init').
Definition: simulation.h:84
std::string _simElapsedTime
Definition: simulation.h:64
bool _do_postexec
Boolean set when a post-exec script must be executed.
Definition: simulation.h:96
void printLogHeader()
Definition: simulation.cc:751
bool run_event(string &name)
Execute one specific life cycle event, if present in the list of current events.
Definition: simulation.cc:689
unsigned int getCurrentReplicate()
Definition: simulation.h:194
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
list< StatRecBase * > getAllStats()
Definition: statservices.cc:405
Class to update the simulation components' state during a simulation.
Definition: updaterservices.h:64

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR