Simpact Cyan
Population based event driven simulation using mNRM
Public Member Functions | Protected Member Functions | List of all members
EventBase Class Reference

This is the base class for events in the mNRM algorithm. More...

#include <eventbase.h>

Inheritance diagram for EventBase:
Inheritance graph
[legend]

Public Member Functions

virtual void fire (State *pState, double t)
 This function will be called when the event fires, so this should most likely be re-implemented in your own event. More...
 
bool willBeRemoved () const
 Check if the event has been marked for deletion, can avoid a call to the random number generator to create a new random number. More...
 
void setWillBeRemoved (bool f)
 When an event has fired, by default a new internal fire time will be calculated; setting this flag avoids this which can be useful if the event isn't going to be used again. More...
 

Protected Member Functions

virtual double getNewInternalTimeDifference (GslRandomNumberGenerator *pRndGen, const State *pState)
 This function will be called to generate a new internal time difference. More...
 
virtual double calculateInternalTimeInterval (const State *pState, double t0, double dt)
 This function should map the real world time interval onto an internal time interval and return it. More...
 
virtual double solveForRealTimeInterval (const State *pState, double Tdiff, double t0)
 This function should calculate the real world time interval that corresponds to the value of $ {\rm Tdiff} $. More...
 

Detailed Description

This is the base class for events in the mNRM algorithm.

To create an actual event implementation, these functions should be reimplemented:

As discussed on the main page, negative real-world times are used to signal that a recalculation is necessary, so in a simulation events can only fire at positive times.

Since this class by default uses an exponential distribution, the implementation of your own event will probably only need the calculateInternalTimeInterval and solveForRealTimeInterval to implement the specific hazard to use for the event. Of course, most likely the fire function will need to be implemented as well.

If you want to schedule events using a real world time directly, you can just implement the getNewInternalTimeDifference function to generate a real world time interval until the real world event fire time. Because the calculateInternalTimeInterval and solveForRealTimeInterval function by default use the trivial $ \Delta T = dt $ mapping onto real world times, you won't need to implement them to make the event fire at the correct time.

Member Function Documentation

double EventBase::calculateInternalTimeInterval ( const State pState,
double  t0,
double  dt 
)
protectedvirtual

This function should map the real world time interval onto an internal time interval and return it.

Basically the function should calculate the integral

\[ \Delta T = \int_{t_0}^{t_0+dt} h(X(t_0), s) ds \]

where $ t_0 $ and $ dt $ are specified as parameters and $ X(t_0) $ is the state of the simulation specified by pState.

If not re-implemented, this function just returns the value of $ dt $, corresponding to the trivial mapping $ \Delta T = dt $.

void EventBase::fire ( State pState,
double  t 
)
virtual

This function will be called when the event fires, so this should most likely be re-implemented in your own event.

Parameters
pStateThe current simulation state when the event fires. The firing of the event can change this state.
tThe time at which the event fires, so this is the current simulation time (a real world time).
double EventBase::getNewInternalTimeDifference ( GslRandomNumberGenerator pRndGen,
const State pState 
)
protectedvirtual

This function will be called to generate a new internal time difference.

By default, as is common in the mNRM, a random number from an exponential distribution $ \exp(-x) $ is used for this, but by re-implementing this function you can change this.

For example, if you just want to make an event fire at a specific real world time, this function should just return the interval until that time (the current simulation time can be obtained from the State::getTime function). In that case you don't even need to re-implement EventBase::calculateInternalTimeInterval and EventBase::solveForRealTimeInterval since their default implementation is the trivial $ \Delta T = dt $ mapping between internal time and real world time.

void EventBase::setWillBeRemoved ( bool  f)
inline

When an event has fired, by default a new internal fire time will be calculated; setting this flag avoids this which can be useful if the event isn't going to be used again.

double EventBase::solveForRealTimeInterval ( const State pState,
double  Tdiff,
double  t0 
)
protectedvirtual

This function should calculate the real world time interval that corresponds to the value of $ {\rm Tdiff} $.

The function should return $ dt $ that solves the equation

\[ {\rm Tdiff} = \int_{t_0}^{t_0+dt} h(X(t_0), s) \]

where $ t_0 $ and $ {\rm Tdiff} $ are specified as parameters and $ X(t_0) $ is the state of the simulation specified by pState.

If not re-implemented, this function just returns the value of $ {\rm Tdiff} $, corresponding to the trivial mapping $ \Delta T = dt $.

bool EventBase::willBeRemoved ( ) const
inline

Check if the event has been marked for deletion, can avoid a call to the random number generator to create a new random number.


The documentation for this class was generated from the following files: