Simpact Cyan
Population based event driven simulation using mNRM
populationalgorithmsimple.h
Go to the documentation of this file.
1 #ifndef POPULATIONALGORITHMSIMPLE_H
2 
3 #define POPULATIONALGORITHMSIMPLE_H
4 
9 #include "simplealgorithm.h"
10 #include "populationinterfaces.h"
11 #include "populationevent.h"
12 #include <assert.h>
13 
15 class PersonBase;
16 class PopulationEvent;
18 
40 {
41 public:
47 
48  bool_t init();
49  bool_t run(double &tMax, int64_t &maxEvents, double startTime = 0);
50  void onNewEvent(PopulationEvent *pEvt);
51 
52  // TODO: shield these from the user somehow? These functions should not be used
53  // directly by the user, they are used internally by the algorithm
54  void scheduleForRemoval(PopulationEvent *pEvt);
55 
56  double getTime() const { return SimpleAlgorithm::getTime(); }
57 
58  void setAboutToFireAction(PopulationAlgorithmAboutToFireInterface *pAction) { m_pOnAboutToFire = pAction; }
60 private:
61  bool_t initEventTimes() const;
62  const std::vector<EventBase *> &getCurrentEvents() const { return m_allEvents; }
63  void onFiredEvent(EventBase *pEvt, int position);
64  int64_t getNextEventID();
65  void onAboutToFire(EventBase *pEvt) { if (m_pOnAboutToFire) m_pOnAboutToFire->onAboutToFire(static_cast<PopulationEvent *>(pEvt)); }
66 
67  std::vector<EventBase *> m_allEvents;
68  PopulationStateSimple &m_popState;
69  bool m_init;
70 
71 #ifdef STATE_SHOW_EVENTS
72  void showEvents(); // FOR DEBUGGING
73 #endif // STATE_SHOW_EVENTS
74  void onAlgorithmLoop();
75 
76  std::vector<EventBase *> m_eventsToRemove;
77 
78  // For the parallel version
79  bool m_parallelRequested;
80  int64_t m_nextEventID;
81 
83 };
84 
85 inline int64_t PopulationAlgorithmSimple::getNextEventID()
86 {
87  int64_t id = m_nextEventID++;
88  return id;
89 }
90 
91 #endif // POPULATIONALGORITHMSIMPLE_H
Type to return true/false with error description.
Definition: booltype.h:25
virtual void onAboutToFire(PopulationEvent *pEvt)=0
If set using PopulationAlgorithmInterface::setAboutToFireAction, this function will be called right b...
void onNewEvent(PopulationEvent *pEvt)
When a new event has been created, it must be injected into the simulation using this function...
Definition: populationalgorithmsimple.cpp:89
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...
Definition: populationalgorithmsimple.cpp:57
Population state to be used when simulating with the straightforward algorithm in PopulationAlgorithm...
Definition: populationstatesimple.h:28
double getTime() const
Must return the simulation tilme of the algorithm.
Definition: populationalgorithmsimple.h:56
This class allows you to generate random numbers, and uses the GNU Scientific Library for this...
Definition: gslrandomnumbergenerator.h:16
bool_t init()
Abstract function to initialize the implementation used.
Definition: populationalgorithmsimple.cpp:29
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 is the base class for events in population-based simulations.
Definition: populationevent.h:61
An interface to allow a member function PopulationAlgorithmAboutToFireInterface::onAboutToFire to be ...
Definition: populationinterfaces.h:89
This is the base class for a person in a population-based simulation.
Definition: personbase.h:23
void setAboutToFireAction(PopulationAlgorithmAboutToFireInterface *pAction)
Allows you to set the action that needs to be performed before firing an event dynamically.
Definition: populationalgorithmsimple.h:58
This is the base class for events in the mNRM algorithm.
Definition: eventbase.h:55
GslRandomNumberGenerator * getRandomNumberGenerator() const
Must return the random number generator used by the algorithm.
Definition: populationalgorithmsimple.h:59
An interface for a population based mNRM algorithm.
Definition: populationinterfaces.h:101
A very naive implementation of the necessary functions from the Algorithm class.
Definition: simplealgorithm.h:86
This class provides functions for a population-based simulation using the modified Next Reaction Meth...
Definition: populationalgorithmsimple.h:39
PopulationAlgorithmSimple(PopulationStateSimple &state, GslRandomNumberGenerator &rng, bool parallel)
Constructor of the class, indicating if a parallel version should be used, which random number genera...
Definition: populationalgorithmsimple.cpp:16