89 bool isParallel()
const {
return m_parallel; }
102 bool run(
double &tMax, int64_t &maxEvents,
double startTime = 0) {
return State::evolve(tMax, maxEvents, startTime,
false); }
147 bool initEventTimes()
const;
149 EventBase *getNextScheduledEvent(
double &dt);
150 void advanceEventTimes(
EventBase *pScheduledEvent,
double dt);
152 const std::vector<EventBase *> &getCurrentEvents()
const {
return m_allEvents; }
155 std::vector<EventBase *> m_allEvents;
158 #ifdef STATE_SHOW_EVENTS
160 #endif // STATE_SHOW_EVENTS
161 void onAlgorithmLoop();
163 PopulationEvent *getEarliestEvent(
const std::vector<PersonBase *> &people);
164 int64_t getNextEventID();
165 int64_t getNextPersonID();
168 std::vector<PersonBase *> m_people;
169 int m_numMen, m_numWomen;
172 std::vector<PersonBase *> m_deceasedPersons;
174 Mutex m_eventsToRemoveMutex;
175 std::vector<EventBase *> m_eventsToRemove;
180 int64_t m_nextEventID, m_nextPersonID;
181 Mutex m_nextEventIDMutex, m_nextPersonIDMutex;
183 std::vector<PopulationEvent *> m_tmpEarliestEvents;
184 std::vector<double> m_tmpEarliestTimes;
186 mutable std::vector<Mutex> m_eventMutexes;
187 mutable std::vector<Mutex> m_personMutexes;
190 inline int64_t Population::getNextEventID()
193 m_nextEventIDMutex.lock();
195 int64_t
id = m_nextEventID++;
198 m_nextEventIDMutex.unlock();
203 inline int64_t Population::getNextPersonID()
206 m_nextPersonIDMutex.lock();
208 int64_t
id = m_nextPersonID++;
211 m_nextPersonIDMutex.unlock();
223 return &(m_people[0]);
231 return &(m_people[m_numMen]);
236 #endif // POPULATION_H
bool run(double &tMax, int64_t &maxEvents, double startTime=0)
This should be called to actually start the simulation, do not call State::evolve for this...
Definition: population.h:102
int getNumberOfMen() const
Returns the number of people in the array returned by Population::getMen.
Definition: population.h:118
This class both describes the simulation state and contains the core algorithm (as shown on the main ...
Definition: state.h:40
virtual void onFiredEvent(EventBase *pEvt)
Called after pEvt is fired.
Definition: state.h:135
void addNewPerson(PersonBase *pPerson)
When a new person is introduced into the population, this function must be used to tell the simulatio...
Definition: population.cpp:513
This class provides functions for a population-based simulation using the modified Next Reaction Meth...
Definition: population.h:77
void setPersonDied(PersonBase *pPerson)
When a person has died, this function must be called to inform the simulation about this...
Definition: population.cpp:74
This class allows you to generate random numbers, and uses the GNU Scientific Library for this...
Definition: gslrandomnumbergenerator.h:15
This is the base class for events in population-based simulations which use the Population class...
Definition: populationevent.h:58
int getNumberOfPeople() const
Returns the number of people in the array returned by Population::getAllPeople.
Definition: population.h:115
This is the base class for a person in a population-based simulation that used the Population class...
Definition: personbase.h:23
Population(bool parallel, GslRandomNumberGenerator *pRng)
Constructor of the class, indicating if a parallel version should be used and which random number gen...
Definition: population.cpp:14
PersonBase ** getMen()
Same as Population::getAllPeople, but only the men are returned.
Definition: population.cpp:429
PersonBase ** getWomen()
Same as Population::getAllPeople, but only the women are returned.
Definition: population.cpp:442
This is the base class for events in the mNRM algorithm.
Definition: eventbase.h:60
bool evolve(double &tMax, int64_t &maxEvents, double startTime=0, bool initEvents=true)
This advances the simulation state using the core mNRM.
Definition: state.cpp:24
PersonBase ** getAllPeople()
Returns a list to the current living members in the population, introduced into the simulation using ...
Definition: population.h:106
void onNewEvent(PopulationEvent *pEvt)
When a new event has been created, it must be injected into the simulation using this function...
Definition: population.cpp:457
int getNumberOfWomen() const
Returns the number of people in the array returned by Population::getWomen.
Definition: population.h:121
A very naive implementation of the necessary functions from the State class.
Definition: simplestate.h:86