1 #ifndef POPULATIONALGORITHMADVANCED_H
3 #define POPULATIONALGORITHMADVANCED_H
14 #include "personaleventlist.h"
17 #ifdef STATE_SHOW_EVENTS
19 #endif // STATE_SHOW_EVENTS
97 bool isParallel()
const {
return m_parallel; }
98 bool_t run(
double &tMax, int64_t &maxEvents,
double startTime = 0);
112 bool_t initEventTimes()
const;
114 void advanceEventTimes(
EventBase *pScheduledEvent,
double dt);
116 PopulationEvent *getEarliestEvent(
const std::vector<PersonBase *> &people);
117 PersonalEventList *personalEventList(
PersonBase *pPerson);
122 #ifdef ALGORITHM_SHOW_EVENTS
124 #endif // ALGORITHM_SHOW_EVENTS
125 void onAlgorithmLoop(
bool finished);
127 int64_t getNextEventID();
129 #ifndef DISABLEOPENMP
130 Mutex m_eventsToRemoveMutex;
131 #endif // !DISABLEOPENMP
132 std::vector<EventBase *> m_eventsToRemove;
137 int64_t m_nextEventID;
138 #ifndef DISABLEOPENMP
139 Mutex m_nextEventIDMutex;
140 #endif // !DISABLEOPENMP
142 std::vector<PopulationEvent *> m_tmpEarliestEvents;
143 std::vector<double> m_tmpEarliestTimes;
145 #ifndef DISABLEOPENMP
146 mutable std::vector<Mutex> m_eventMutexes;
147 #endif // !DISABLEOPENMP
152 inline int64_t PopulationAlgorithmAdvanced::getNextEventID()
154 #ifndef DISABLEOPENMP
156 m_nextEventIDMutex.lock();
157 #endif // !DISABLEOPENMP
159 int64_t
id = m_nextEventID++;
161 #ifndef DISABLEOPENMP
163 m_nextEventIDMutex.unlock();
164 #endif // !DISABLEOPENMP
169 inline PersonalEventList *PopulationAlgorithmAdvanced::personalEventList(
PersonBase *pPerson)
172 PersonalEventList *pEvtList =
static_cast<PersonalEventList *
>(pPerson->
getAlgorithmInfo());
177 inline void PopulationAlgorithmAdvanced::onAboutToFire(
EventBase *pEvt)
179 #ifdef STATE_SHOW_EVENTS
181 #endif // STATE_SHOW_EVENTS
183 if (m_pOnAboutToFire)
184 m_pOnAboutToFire->
onAboutToFire(static_cast<PopulationEvent *>(pEvt));
187 #endif // POPULATIONALGORITHMADVANCED_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...
This class provides functions for a population-based simulation using the modified Next Reaction Meth...
Definition: populationalgorithmadvanced.h:86
void setAboutToFireAction(PopulationAlgorithmAboutToFireInterface *pAction)
Allows you to set the action that needs to be performed before firing an event dynamically.
Definition: populationalgorithmadvanced.h:110
PopulationAlgorithmAdvanced(PopulationStateAdvanced &state, GslRandomNumberGenerator &rng, bool parallel)
Constructor of the class, indicating if a parallel version should be used, which random number genera...
Definition: populationalgorithmadvanced.cpp:28
double getTime() const
Must return the simulation tilme of the algorithm.
Definition: populationalgorithmadvanced.h:107
bool_t init()
Abstract function to initialize the implementation used.
Definition: populationalgorithmadvanced.cpp:41
GslRandomNumberGenerator * getRandomNumberGenerator() const
Must return the random number generator used by the algorithm.
Definition: populationalgorithmadvanced.h:108
This class allows you to generate random numbers, and uses the GNU Scientific Library for this...
Definition: gslrandomnumbergenerator.h:16
double getTime() const
This function returns the current time of the simulation.
Definition: algorithm.h:155
GslRandomNumberGenerator * getRandomNumberGenerator() const
Returns the random number generator that was specified in the constructor.
Definition: algorithm.h:158
This class contains the core algorithm (as shown on the main page of the documentation) to execute th...
Definition: algorithm.h:81
This is the base class for events in population-based simulations.
Definition: populationevent.h:63
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
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: populationalgorithmadvanced.cpp:83
Population state to be used when simulating with the population based algorithm in PopulationAlgorith...
Definition: populationstateadvanced.h:22
void onNewEvent(PopulationEvent *pEvt)
When a new event has been created, it must be injected into the simulation using this function...
Definition: populationalgorithmadvanced.cpp:415
This is the base class for events in the mNRM algorithm.
Definition: eventbase.h:55
PersonAlgorithmInfo * getAlgorithmInfo() const
Returns what was stored using PersonBase::PersonAlgorithmInfo.
Definition: personbase.h:77
An interface for a population based mNRM algorithm.
Definition: populationinterfaces.h:101