Simpact Cyan
Population based event driven simulation using mNRM
|
A very naive implementation of the necessary functions from the State class. More...
#include <simplestate.h>
Public Member Functions | |
SimpleState (bool parallel, GslRandomNumberGenerator *pRng) | |
Constructor of this class, specifying whether a parallel version should be used to speed things up a bit, and specifying the random number generator. More... | |
Public Member Functions inherited from State | |
State (GslRandomNumberGenerator *pRng) | |
Constructor of the class, to which the random number generator to be used internally must be specified. More... | |
bool | evolve (double &tMax, int64_t &maxEvents, double startTime=0, bool initEvents=true) |
This advances the simulation state 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... | |
Public Member Functions inherited from errut::ErrorBase | |
ErrorBase () | |
Creates an instance without an explicit object name. More... | |
ErrorBase (const std::string &objName) | |
Creates an instance with the object name set to objName . More... | |
std::string | getObjectName () const |
Returns the stored object name. More... | |
std::string | getErrorString () const |
Returns the currently stored error message. More... | |
Protected Member Functions | |
virtual const std::vector < EventBase * > & | getCurrentEvents () const |
This function should return the list of events that are currently scheduled. More... | |
virtual void | onFiredEvent (EventBase *pEvt, int position) |
This function is called after firing the event pEvt , stored at position position in the list that was returned by SimpleState::getCurrentEvents, and this function should remove at least that event from the list. More... | |
Protected Member Functions inherited from State | |
virtual void | onAboutToFire (EventBase *pEvt) |
Called right before 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... | |
Protected Member Functions inherited from errut::ErrorBase | |
void | setErrorString (const std::string &str) const |
Derived classes can use this member function to store an error message. More... | |
A very naive implementation of the necessary functions from the State class.
In this implementation, all event times are recalculated each time an event has fired. This is slow, but a good reference implemenation to check an optimized version against. To create a simulation with this version of the algorithm, you need to provide implementations for the SimpleState::getCurrentEvents and SimpleState::onFiredEvent functions. The first function must return a list of all events in the system, the second one can modify the list, for example removing the fired event if no longer necessary.
The code that implements State::initEventTimes looks as follow:
The code for the State::getNextScheduledEvent implementation looks as follows:
Here, the key calculation is the solveForRealTimeInterval
one, which solves for in the integral
where is the current (remaining) internal time interval for an event.
Finally, the State::advanceEventTimes implementation is the following:
Here, the internal time for an event is replaced by
where and is the time at which the mapping between internal time interval and real world fire time was last calculated (see main page).
Note that if you still need to implement the State::onFiredEvent function yourself, you must call the corresponding implementation of SimpleState as well. Otherwise the algorithm will not work properly anymore.
SimpleState::SimpleState | ( | bool | parallel, |
GslRandomNumberGenerator * | pRng | ||
) |
Constructor of this class, specifying whether a parallel version should be used to speed things up a bit, and specifying the random number generator.
|
inlineprotectedvirtual |
This function should return the list of events that are currently scheduled.
|
inlineprotectedvirtual |
This function is called after firing the event pEvt
, stored at position position
in the list that was returned by SimpleState::getCurrentEvents, and this function should remove at least that event from the list.