Simpact Cyan
Population based event driven simulation using mNRM
simpactpopulation.h
1 #ifndef SIMPACTPOPULATION_H
2 
3 #define SIMPACTPOPULATION_H
4 
5 #include "population.h"
6 #include <assert.h>
7 
9 class Person;
10 class Man;
11 class Woman;
12 
13 class SimpactPopulationConfig : public errut::ErrorBase
14 {
15 public:
16  SimpactPopulationConfig();
17  ~SimpactPopulationConfig();
18 
19  void setInitialMen(int number) { m_initialMen = number; }
20  void setInitialWomen(int number) { m_initialWomen = number; }
21  void setEyeCapsFraction(double f) { m_eyeCapsFraction = f; }
22 
23  int getInitialMen() const { return m_initialMen; }
24  int getInitialWomen() const { return m_initialWomen; }
25  double getEyeCapsFraction() const { return m_eyeCapsFraction; }
26 private:
27  int m_initialMen, m_initialWomen;
28  double m_eyeCapsFraction;
29 };
30 
31 class SimpactPopulation : public Population
32 {
33 public:
34  SimpactPopulation(bool parallel, GslRandomNumberGenerator *pRng);
35  ~SimpactPopulation();
36 
37  bool init(const SimpactPopulationConfig &popConfig, const PopulationDistribution &popDist);
38 
39  Person **getAllPeople() { return reinterpret_cast<Person**>(Population::getAllPeople()); }
40  Man **getMen() { return reinterpret_cast<Man**>(Population::getMen()); }
41  Woman **getWomen() { return reinterpret_cast<Woman**>(Population::getWomen()); }
42  Person **getDeceasedPeople() { return reinterpret_cast<Person**>(Population::getDeceasedPeople()); }
43 
44  int getInitialPopulationSize() const { return m_initialPopulationSize; }
45  double getEyeCapsFraction() const { return m_eyeCapsFraction; }
46 
47  // Is called by debut event
48  void initializeFormationEvents(Person *pPerson);
49 protected:
50  bool createInitialPopulation(const SimpactPopulationConfig &config, const PopulationDistribution &popDist);
51  bool scheduleInitialEvents();
52 private:
53  void onAboutToFire(EventBase *pEvt);
54  void getInterestsForPerson(const Person *pPerson, std::vector<Person *> &interests);
55 
56  int m_initialPopulationSize;
57  double m_eyeCapsFraction;
58 
59  bool m_init;
60 };
61 
62 inline SimpactPopulation &SIMPACTPOPULATION(State *pState)
63 {
64  assert(pState != 0);
65  return static_cast<SimpactPopulation &>(*pState);
66 }
67 
68 inline const SimpactPopulation &SIMPACTPOPULATION(const State *pState)
69 {
70  assert(pState != 0);
71  return static_cast<const SimpactPopulation &>(*pState);
72 }
73 
74 #endif // SIMPACTPOPULATION_H
75 
This class both describes the simulation state and contains the core algorithm (as shown on the main ...
Definition: state.h:40
Base class which allows an error message to be set.
Definition: errorbase.h:49
virtual void onAboutToFire(EventBase *pEvt)
Called right before pEvt is fired.
Definition: state.h:132
PersonBase ** getDeceasedPeople()
Returns the people who were part of the simulation but who are now deceased (intended for result anal...
Definition: population.h:122
Base class for picking random numbers according to some kind of age distribution. ...
Definition: populationdistribution.h:15
This class provides functions for a population-based simulation using the modified Next Reaction Meth...
Definition: population.h:83
This class allows you to generate random numbers, and uses the GNU Scientific Library for this...
Definition: gslrandomnumbergenerator.h:16
PersonBase ** getMen()
Same as Population::getAllPeople, but only the men are returned.
Definition: population.cpp:514
PersonBase ** getWomen()
Same as Population::getAllPeople, but only the women are returned.
Definition: population.cpp:527
This is the base class for events in the mNRM algorithm.
Definition: eventbase.h:62
PersonBase ** getAllPeople()
Returns a list to the current living members in the population, introduced into the simulation using ...
Definition: population.h:112