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

This class provides functions for a population-based simulation using the modified Next Reaction Method (mNRM). More...

#include <populationalgorithmsimple.h>

Inheritance diagram for PopulationAlgorithmSimple:
Inheritance graph
[legend]
Collaboration diagram for PopulationAlgorithmSimple:
Collaboration graph
[legend]

Public Member Functions

 PopulationAlgorithmSimple (PopulationStateSimple &state, GslRandomNumberGenerator &rng, bool parallel)
 Constructor of the class, indicating if a parallel version should be used, which random number generator should be used and which simulation state.
 
bool_t init ()
 Abstract function to initialize the implementation used.
 
bool_t run (double &tMax, int64_t &maxEvents, double startTime=0)
 This should be called to actually start the simulation, do not call Algorithm::evolve for this. More...
 
void onNewEvent (PopulationEvent *pEvt)
 When a new event has been created, it must be injected into the simulation using this function.
 
double getTime () const
 Must return the simulation tilme of the algorithm.
 
void setAboutToFireAction (PopulationAlgorithmAboutToFireInterface *pAction)
 Allows you to set the action that needs to be performed before firing an event dynamically. More...
 
GslRandomNumberGeneratorgetRandomNumberGenerator () const
 Must return the random number generator used by the algorithm.
 
- Public Member Functions inherited from SimpleAlgorithm
 SimpleAlgorithm (State &state, GslRandomNumberGenerator &rng, bool parallel)
 Constructor of this class, specifying whether a parallel version should be used to speed things up a bit, specifying the random number generator as well as the simulation state to use.
 
- Public Member Functions inherited from 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.
 
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.
 
GslRandomNumberGeneratorgetRandomNumberGenerator () const
 Returns the random number generator that was specified in the constructor.
 

Additional Inherited Members

- Protected Member Functions inherited from Algorithm
StategetState () const
 Returns the simulation state instance that was specified in the constructor.
 

Detailed Description

This class provides functions for a population-based simulation using the modified Next Reaction Method (mNRM).

Being population-based, the state of the simulation mostly consists of the (living) people.

In this implementation, the very straightforward algorithm provided by the SimpleState class is used, making sure that all event times are recalculated after an event got fired. While being a slow algorithm, it can be useful to compare the results from PopulationAlgorithmAdvanced to, to make sure the advanced implementation yields the correct results.

Before calling PopulationAlgorithmInterface::run, you'll need to introduce initial events (see PopulationAlgorithmInterface::onNewEvent) and most likely also an initial set of persons in the simulation state you're using (see PopulationStateInterface::addNewPerson). The actual state that needs to be used in this implementation, is defined in PopulationStateSimple.

Events for this type of simulation should derive from the PopulationEvent class instead of using the EventBase base class directly.

Member Function Documentation

◆ run()

bool_t PopulationAlgorithmSimple::run ( double &  tMax,
int64_t &  maxEvents,
double  startTime = 0 
)
virtual

This should be called to actually start the simulation, do not call Algorithm::evolve for this.

Parameters
tMaxStop the simulation if the simulation time exceeds the specified time. Upon completion of the function, this variable will contain the actual simulation time stopped.
maxEventsIf 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.
startTimeThe start time of the simulation, can be used to continue where a previous call to this function left off.

Implements PopulationAlgorithmInterface.

◆ setAboutToFireAction()

void PopulationAlgorithmSimple::setAboutToFireAction ( PopulationAlgorithmAboutToFireInterface pAction)
inlinevirtual

Allows you to set the action that needs to be performed before firing an event dynamically.

When implementing a new population based algorithm you must make sure that this way the action performed by Algorithm::onAboutToFire can be changed at run time.

Implements PopulationAlgorithmInterface.


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