Simpact Cyan
Population based event driven simulation using mNRM
algorithm.h
Go to the documentation of this file.
1 #ifndef ALGORITHM_H
2 
3 #define ALGORITHM_H
4 
9 #include "booltype.h"
10 #include <stdint.h>
11 #include <vector>
12 
13 //#define STATE_SHOW_EVENTS
14 
16 class EventBase;
17 class Algorithm;
18 
20 class State
21 {
22 public:
23  State() { m_time = 0; }
24  virtual ~State() { }
25 
32  double getTime() const { return m_time; }
33 
39  void setTime(double t) { m_time = t; }
40 private:
41  double m_time;
42 };
43 
66 class Algorithm
67 {
68 public:
72  virtual ~Algorithm();
73 
137  bool_t evolve(double &tMax, int64_t &maxEvents, double startTime = 0, bool initEvents = true);
138 
140  double getTime() const { return m_time; }
141 
143  GslRandomNumberGenerator *getRandomNumberGenerator() const { return m_pRndGen; }
144 protected:
146  State *getState() const { return m_pState; }
147 
150  virtual bool_t initEventTimes() const;
151 
154  virtual bool_t getNextScheduledEvent(double &dt, EventBase **ppEvt);
155 
158  virtual void advanceEventTimes(EventBase *pScheduledEvent, double dt);
159 
161  virtual void onAboutToFire(EventBase *pEvt) { }
162 
164  virtual void onFiredEvent(EventBase *pEvt) { }
165 
168  virtual void onAlgorithmLoop(bool finished) { }
169 private:
170  mutable GslRandomNumberGenerator *m_pRndGen;
171  State *m_pState;
172  double m_time;
173 };
174 
175 #endif // ALGORITHM_H
176 
Type to return true/false with error description.
Definition: booltype.h:25
This is a base class describing the simulation state of an mNRM algorithm.
Definition: algorithm.h:20
bool_t evolve(double &tMax, int64_t &maxEvents, double startTime=0, bool initEvents=true)
This advances the simulation state specified in the constructor using the core mNRM.
Definition: algorithm.cpp:26
virtual void onAboutToFire(EventBase *pEvt)
Called right before pEvt is fired.
Definition: algorithm.h:161
virtual void onFiredEvent(EventBase *pEvt)
Called after pEvt is fired.
Definition: algorithm.h:164
void setTime(double t)
Set the simulation time, which is normally only done by the Algorithm in use (but may be necessary wh...
Definition: algorithm.h:39
virtual void advanceEventTimes(EventBase *pScheduledEvent, double dt)
Advance the times of the necessary events to the time when dt has passed, ignoring pScheduledEvent si...
Definition: algorithm.cpp:100
virtual void onAlgorithmLoop(bool finished)
Called at the end of each algorithm loop, with finished set to true if the loop will be exited...
Definition: algorithm.h:168
Algorithm(State &state, GslRandomNumberGenerator &rng)
Constructor of the class, to which the simulation state must be specified as well as the random numbe...
Definition: algorithm.cpp:11
double getTime() const
Retrieve the current simulation time, which is stored by the Algorithm instance in use (note that unt...
Definition: algorithm.h:32
virtual bool_t getNextScheduledEvent(double &dt, EventBase **ppEvt)
Store the next event to be fired in ppEvt and store the real world time that will have passed until i...
Definition: algorithm.cpp:95
This class allows you to generate random numbers, and uses the GNU Scientific Library for this...
Definition: gslrandomnumbergenerator.h:16
double getTime() const
This function returns the current time of the simulation.
Definition: algorithm.h:140
GslRandomNumberGenerator * getRandomNumberGenerator() const
Returns the random number generator that was specified in the constructor.
Definition: algorithm.h:143
This class contains the core algorithm (as shown on the main page of the documentation) to execute th...
Definition: algorithm.h:66
State * getState() const
Returns the simulation state instance that was specified in the constructor.
Definition: algorithm.h:146
This is the base class for events in the mNRM algorithm.
Definition: eventbase.h:55
virtual bool_t initEventTimes() const
Generate the internal times for the events present in the algorithm (called by State::evolve dependin...
Definition: algorithm.cpp:90