Stride Reference Manual  1.0
Simulator.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * any later version.
7  * The software is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License
12  * along with the software. If not, see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2017, Willem L, Kuylen E, Stijven S & Broeckhove J
15  */
16 
28 
29 #include "sim/SimulatorStatus.h"
30 #include "core/DiseaseProfile.h"
31 #include "core/LogMode.h"
32 #include "core/District.h"
33 #include "core/ClusterType.h"
34 #include "pop/Person.h"
35 #include "pop/Traveller.h"
36 #include "util/Subject.h"
37 #include "util/Random.h"
38 #include "util/unipar.h"
39 #include "util/SimplePlanner.h"
41 #include <boost/property_tree/ptree.hpp>
42 #include <spdlog/spdlog.h>
43 #include <memory>
44 #include <string>
45 #include <vector>
46 #include <utility>
47 
48 namespace stride {
49 
50 class Population;
51 
52 class Calendar;
53 
54 class Cluster;
55 
56 class AsyncSimulator;
57 
58 using uint = unsigned int;
59 namespace run { class Runner; }
60 
64 class Simulator : public Subject<Simulator> {
65 public:
68  //using BeliefPolicy = Threshold<true, false>;
70  //using BehaviourPolicy = Vaccination<BeliefPolicy>;
73  //using LocalInformationPolicy = LocalDiscussion<PersonType>;
75 
77  Simulator();
78 
80  const std::shared_ptr<const Population> getPopulation() const;
81 
83  void setTrackIndexCase(bool track_index_case);
84 
85  void setName(string name) { m_name = name; }
86 
87  string getName() const { return m_name; }
88 
89  void setCommunicationMap(const std::map<string, AsyncSimulator*>& comm_map) { m_communication_map = comm_map; }
90 
92  SimulatorStatus timeStep();
93 
95  const Calendar& getCalendar() const { return *m_calendar; }
96 
99  const std::vector<Cluster>& getClusters(ClusterType cluster_type) const;
100 
102  std::vector<std::string> getRngStates() const;
103 
105  void setRngStates(std::vector<std::string> states);
106 
110  uint chooseCluster(const GeoCoordinate& coordinate, const vector<Cluster>& clusters, double influence);
111 
118  bool
119  hostForeignTravellers(const vector<Simulator::TravellerType>& travellers, uint days, string destination_district,
120  string destination_facility);
121 
126  bool welcomeHomeTravellers(const vector<uint>& travellers_indices, const vector<Health>& health_status);
127 
129  void returnForeignTravellers();
130 
131  void sendNewTravellers(uint amount, uint days, const string& destination_sim_id, string destination_district,
132  string destination_facility);
133 
134  const SimplePlanner<Traveller<Simulator::PersonType>>& getPlanner() const { return m_planner; }
135 
136 public:
137  const std::vector<Cluster>& getHouseholds() const { return m_households; }
138 
139  const std::vector<Cluster>& getSchoolClusters() const { return m_school_clusters; }
140 
141  const std::vector<Cluster>& getWorkClusters() const { return m_work_clusters; }
142 
143  const std::vector<Cluster>& getPrimaryCommunities() const { return m_primary_community; }
144 
145  const std::vector<Cluster>& getSecondaryCommunities() const { return m_secondary_community; }
146 
147  const std::vector<District>& getDistricts() const { return m_districts; }
148 
149 private:
150  // Information about travellers
151  std::map<unsigned int, Simulator::TravellerType> m_trav_elsewhere;
152  std::map<unsigned int, Simulator::TravellerType> m_trav_hosting;
153 
154 private:
156  template<LogMode log_level, bool track_index_case = false>
157  void updateClusters();
158 
159 private:
160  unsigned int m_num_threads;
161 
162  #if UNIPAR_IMPL == UNIPAR_DUMMY
164  #else
165  using RandomRef = std::unique_ptr<util::Random>;
166  #endif
167 
168  decltype(Parallel().with<RandomRef>()) m_parallel;
169 
170  std::shared_ptr<util::Random> m_rng;
171  LogMode m_log_level;
172  std::shared_ptr<Calendar> m_calendar;
173 
174 private:
175  boost::property_tree::ptree m_config_pt;
176  boost::property_tree::ptree m_config_pop;
177  std::shared_ptr<spdlog::logger> m_logger;
178  std::shared_ptr<Population> m_population;
179 
180  std::vector<Cluster> m_households;
181  std::vector<Cluster> m_school_clusters;
182  std::vector<Cluster> m_work_clusters;
183  std::vector<Cluster> m_primary_community;
184  std::vector<Cluster> m_secondary_community;
185 
186  std::vector<District> m_districts;
187 
188  std::map<string, AsyncSimulator*> m_communication_map;
189 
190  DiseaseProfile m_disease_profile;
191 
192  bool m_track_index_case;
193 
194  uint m_next_id;
195  uint m_next_hh_id;
196  string m_name;
197 
199 
200 public:
201  friend class SimulatorBuilder;
202 
203  friend class LocalSimulatorAdapter;
204 
205  friend class Hdf5Saver;
206 
207  friend class Hdf5Loader;
208 
209  friend class run::Runner;
210 };
211 
212 }
void setName(string name)
Definition: Simulator.h:85
const std::vector< Cluster > & getPrimaryCommunities() const
Definition: Simulator.h:143
Interface/Implementation of Subject.
unsigned int uint
Definition: Influence.h:17
You can see this class as a kind of planner that stores events in the near future.
Definition: SimplePlanner.h:23
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
Main class that contains and direct the virtual world.
Class that keeps track of the &#39;state&#39; of simulated world.
Definition: Calendar.h:36
Header file for the Person class.
A district is either a city or a village (currently, there is no difference between city and village)...
Definition: District.h:26
Header for the Random Number Generator class.
std::map< unsigned int, Simulator::TravellerType > m_trav_hosting
Definition: Simulator.h:152
Container for persons in population.
Definition: Population.h:132
Forward declaration of class Person.
Definition: ThresholdData.h:15
unipar::Parallel Parallel
Definition: unipar.h:16
Header for the District class.
const std::vector< Cluster > & getSchoolClusters() const
Definition: Simulator.h:139
Definition of ClusterType.
STL namespace.
Main class that contains and direct the virtual world.
Definition: Simulator.h:64
const std::vector< Cluster > & getWorkClusters() const
Definition: Simulator.h:141
LogMode
Enum specifiying the level of logging required:
Definition: LogMode.h:32
const std::vector< Cluster > & getSecondaryCommunities() const
Definition: Simulator.h:145
Header for the LogMode class.
Disease profile.
std::map< unsigned int, Simulator::TravellerType > m_trav_elsewhere
Definition: Simulator.h:151
Represents a location for social contacts, an group of people.
Definition: Cluster.h:46
Template for Subject/Observer (or Publish/Subscribe).
Definition: Subject.h:35
void setCommunicationMap(const std::map< string, AsyncSimulator * > &comm_map)
Definition: Simulator.h:89
const SimplePlanner< Traveller< Simulator::PersonType > > & getPlanner() const
Definition: Simulator.h:134
const std::vector< Cluster > & getHouseholds() const
Definition: Simulator.h:137
ClusterType
Enumerates the cluster types.
Definition: ClusterType.h:28
string getName() const
Definition: Simulator.h:87
unsigned int m_num_threads
The number of threads(as a hint)
Definition: Simulator.h:160
const std::vector< District > & getDistricts() const
Definition: Simulator.h:147
The random number generator.
Definition: Random.h:39
const Calendar & getCalendar() const
Return the calendar of this simulator.
Definition: Simulator.h:95