Simpact Cyan
Population based event driven simulation using mNRM
|
This class contains the core algorithm (as shown on the main page of the documentation) to execute the modified next reaction method (mNRM). More...
#include <algorithm.h>
Public Member Functions | |
Algorithm (State &state, GslRandomNumberGenerator &rng) | |
Constructor of the class, to which the simulation state must be specified as well as the random number generator to be used internally. More... | |
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. More... | |
double | getTime () const |
This function returns the current time of the simulation. More... | |
GslRandomNumberGenerator * | getRandomNumberGenerator () const |
Returns the random number generator that was specified in the constructor. More... | |
Protected Member Functions | |
State * | getState () const |
Returns the simulation state instance that was specified in the constructor. More... | |
virtual bool_t | initEventTimes () const |
Generate the internal times for the events present in the algorithm (called by State::evolve depending on the value of the initEvents parameter). More... | |
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 it fires in dt . More... | |
virtual void | advanceEventTimes (EventBase *pScheduledEvent, double dt) |
Advance the times of the necessary events to the time when dt has passed, ignoring pScheduledEvent since this is the one we will be firing. More... | |
virtual void | onAboutToFire (EventBase *pEvt) |
Called right before pEvt is fired. More... | |
virtual void | onFiredEvent (EventBase *pEvt) |
Called after pEvt is fired. More... | |
virtual void | onAlgorithmLoop (bool finished) |
Called at the end of each algorithm loop, with finished set to true if the loop will be exited. More... | |
This class contains the core algorithm (as shown on the main page of the documentation) to execute the modified next reaction method (mNRM).
Using this class alone will not work however, since it does not contain an implementation of several necessary functions. At leest three functions must be implemented in a subclass:
A very straightforward implementation is available in the SimpleAlgorithm class, where no attempt is made to avoid unnecessary recalculations.
Algorithm::Algorithm | ( | State & | state, |
GslRandomNumberGenerator & | rng | ||
) |
Constructor of the class, to which the simulation state must be specified as well as the random number generator to be used internally.
|
protectedvirtual |
Advance the times of the necessary events to the time when dt
has passed, ignoring pScheduledEvent since this is the one we will be firing.
bool_t Algorithm::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.
tMax | Stop the simulation if the simulation time exceeds the specified time. Upon completion of the function, this variable will contain the actual simulation time stopped. |
maxEvents | If positive, the simulation will stop if this many events have been executed. Set to a negative value to disable this limit. At the end of the simulation, this variable will contain the number of events executed. |
startTime | The start time of the simulation, can be used to continue where a previous call to this function left off. |
initEvents | If set to true, the Algorithm::initEvents function will be called before entering the algorithm loop. |
The algorithm executed is the following:
Apart from the core functions Algorithm::initEventTimes, Algorithm::getNextScheduledEvent and Algorithm::advanceEventTimes which need to be provided by an implementation to get a working algorithm, a few extra functions can come in handy as well:
Store the next event to be fired in ppEvt
and store the real world time that will have passed until it fires in dt
.
|
inline |
Returns the random number generator that was specified in the constructor.
|
inlineprotected |
Returns the simulation state instance that was specified in the constructor.
|
inline |
This function returns the current time of the simulation.
|
protectedvirtual |
Generate the internal times for the events present in the algorithm (called by State::evolve depending on the value of the initEvents parameter).
|
inlineprotectedvirtual |
Called right before pEvt is fired.
|
inlineprotectedvirtual |
Called at the end of each algorithm loop, with finished
set to true if the loop will be exited.
|
inlineprotectedvirtual |
Called after pEvt is fired.