95 bool isParallel()
const {
return m_parallel; }
108 bool run(
double &tMax, int64_t &maxEvents,
double startTime = 0) {
return State::evolve(tMax, maxEvents, startTime,
false); }
112 PersonBase **
getAllPeople() {
if (m_people.size() == m_numGlobalDummies)
return 0;
return &(m_people[m_numGlobalDummies]); }
125 int getNumberOfPeople()
const {
int num = (int)m_people.size() - m_numGlobalDummies; assert(num >= 0);
return num; }
165 bool initEventTimes()
const;
167 EventBase *getNextScheduledEvent(
double &dt);
168 void advanceEventTimes(
EventBase *pScheduledEvent,
double dt);
170 const std::vector<EventBase *> &getCurrentEvents()
const {
return m_allEvents; }
173 std::vector<EventBase *> m_allEvents;
176 #ifdef STATE_SHOW_EVENTS
178 #endif // STATE_SHOW_EVENTS
179 void onAlgorithmLoop();
181 PopulationEvent *getEarliestEvent(
const std::vector<PersonBase *> &people);
182 int64_t getNextEventID();
183 int64_t getNextPersonID();
186 std::vector<PersonBase *> m_people;
187 int m_numMen, m_numWomen;
188 int m_numGlobalDummies;
191 std::vector<PersonBase *> m_deceasedPersons;
193 #ifndef DISABLEOPENMP
194 Mutex m_eventsToRemoveMutex;
195 #endif // !DISABLEOPENMP
196 std::vector<EventBase *> m_eventsToRemove;
201 int64_t m_nextEventID, m_nextPersonID;
202 #ifndef DISABLEOPENMP
203 Mutex m_nextEventIDMutex, m_nextPersonIDMutex;
204 #endif // !DISABLEOPENMP
206 std::vector<PopulationEvent *> m_tmpEarliestEvents;
207 std::vector<double> m_tmpEarliestTimes;
209 mutable std::vector<PersonBase *> m_otherAffectedPeople;
211 #ifndef DISABLEOPENMP
212 mutable std::vector<Mutex> m_eventMutexes;
213 mutable std::vector<Mutex> m_personMutexes;
214 #endif // !DISABLEOPENMP
217 inline int64_t Population::getNextEventID()
219 #ifndef DISABLEOPENMP
221 m_nextEventIDMutex.lock();
222 #endif // !DISABLEOPENMP
224 int64_t
id = m_nextEventID++;
226 #ifndef DISABLEOPENMP
228 m_nextEventIDMutex.unlock();
229 #endif // !DISABLEOPENMP
234 inline int64_t Population::getNextPersonID()
236 #ifndef DISABLEOPENMP
238 m_nextPersonIDMutex.lock();
239 #endif // !DISABLEOPENMP
241 int64_t
id = m_nextPersonID++;
243 #ifndef DISABLEOPENMP
245 m_nextPersonIDMutex.unlock();
246 #endif // !DISABLEOPENMP
255 m_otherAffectedPeople.push_back(pPerson);
263 return &(m_people[m_numGlobalDummies]);
271 return &(m_people[m_numMen+m_numGlobalDummies]);
276 #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:108
int getNumberOfMen() const
Returns the number of people in the array returned by Population::getMen.
Definition: population.h:128
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:606
PersonBase ** getDeceasedPeople()
Returns the people who were part of the simulation but who are now deceased (intended for result anal...
Definition: population.h:122
This class provides functions for a population-based simulation using the modified Next Reaction Meth...
Definition: population.h:83
void setPersonDied(PersonBase *pPerson)
When a person has died, this function must be called to inform the simulation about this...
Definition: population.cpp:95
void markAffectedPerson(PersonBase *pPerson) const
This should only be called from within the PopulationEvent::markOtherAffectedPeople function...
Definition: population.cpp:498
This class allows you to generate random numbers, and uses the GNU Scientific Library for this...
Definition: gslrandomnumbergenerator.h:16
This is the base class for events in population-based simulations which use the Population class...
Definition: populationevent.h:61
int getNumberOfPeople() const
Returns the number of people in the array returned by Population::getAllPeople.
Definition: population.h:125
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:17
PersonBase ** getMen()
Same as Population::getAllPeople, but only the men are returned.
Definition: population.cpp:505
PersonBase ** getWomen()
Same as Population::getAllPeople, but only the women are returned.
Definition: population.cpp:518
This is the base class for events in the mNRM algorithm.
Definition: eventbase.h:62
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:23
PersonBase ** getAllPeople()
Returns a list to the current living members in the population, introduced into the simulation using ...
Definition: population.h:112
void onNewEvent(PopulationEvent *pEvt)
When a new event has been created, it must be injected into the simulation using this function...
Definition: population.cpp:535
int getNumberOfWomen() const
Returns the number of people in the array returned by Population::getWomen.
Definition: population.h:131
int getNumberOfDeceasedPeople() const
Returns the number of people in the array returned by Population::getDeceasedPeople.
Definition: population.h:134
A very naive implementation of the necessary functions from the State class.
Definition: simplestate.h:86