44 : m_num_threads(1U), m_log_level(
LogMode::
Null), m_config_pt(), m_population(nullptr),
45 m_disease_profile(), m_track_index_case(false), m_next_id(0), m_next_hh_id(0) {
47 #if UNIPAR_IMPL == UNIPAR_DUMMY 50 std::random_device rd;
51 return make_unique<Random>(rd());
64 template<LogMode log_level,
bool track_index_case>
80 district.advanceInfluencesRecords();
83 shared_ptr<DaysOffInterface> days_off {
nullptr};
89 days_off = make_shared<DaysOffStandard>(
m_calendar);
90 const bool is_work_off {days_off->isWorkOff()};
91 const bool is_school_off {days_off->isSchoolOff()};
93 double fraction_infected =
m_population->getFractionInfected();
96 p.update(is_work_off, is_school_off, fraction_infected);
102 updateClusters<LogMode::Contacts, true>();
105 updateClusters<LogMode::Transmissions, true>();
108 updateClusters<LogMode::None, true>();
111 throw runtime_error(std::string(__func__) +
"Log mode screwed up!");
116 updateClusters<LogMode::Contacts, false>();
119 updateClusters<LogMode::Transmissions, false>();
122 updateClusters<LogMode::None, false>();
125 throw runtime_error(std::string(__func__) +
"Log mode screwed up!");
136 switch (cluster_type) {
148 throw runtime_error(
string(__func__) +
"> Should not reach default.");
153 vector<string> states;
156 states.push_back(ss.str());
161 m_rng->setState(states.at(0));
165 double current_influence = influence;
167 if (clusters.size() == 0) {
168 throw runtime_error(
string(__func__) +
string(
"> Empty cluster vector."));
172 vector<uint> available_clusters;
175 for (
uint i = 1; i < clusters.size(); ++i) {
177 const auto& cluster = clusters.at(i);
179 if (calc.getDistance(coordinate, cluster.getLocation()) <= current_influence) {
180 available_clusters.push_back(i);
184 if (available_clusters.size() != 0) {
185 uint chosen_index =
m_rng->operator()(available_clusters.size());
186 return available_clusters[chosen_index];
190 current_influence *= 2.0;
196 string destination_district,
string destination_facility) {
198 double influence = 0.0;
199 bool found_airport =
false;
202 if (district.getName() == destination_district && district.hasFacility(destination_facility)) {
203 found_airport =
true;
204 facility_location = district.getLocation();
205 influence = district.getFacilityInfluence(destination_facility);
206 district.visitFacility(destination_facility, travellers.size());
211 if (!found_airport) {
212 cerr <<
"\nWarning: facility " << destination_facility <<
" not found in district " << destination_district
219 this->
m_population.get()->m_visitors.getModifiableDay(days)->reserve(travellers.size());
231 throw runtime_error(
"Failed to find cluster for traveller");
235 uint start_infectiousness = traveller.getHomePerson().getHealth().getStartInfectiousness();
236 uint start_symptomatic = traveller.getHomePerson().getHealth().getStartSymptomatic();
241 work_index, prim_comm_index, sec_comm_index,
242 start_infectiousness, start_symptomatic,
243 traveller.getHomePerson().getHealth().getEndInfectiousness() -
244 start_infectiousness,
245 traveller.getHomePerson().getHealth().getEndSymptomatic() -
247 new_person.
getHealth() = traveller.getHomePerson().getHealth();
256 traveller.getHomeSimulatorId(),
257 traveller.getDestinationSimulatorId(),
258 traveller.getHomePerson().getId());
280 for (
uint i = 0; i < travellers_indices.size(); ++i) {
281 original_population.at(travellers_indices.at(i)).setOnVacation(
false);
282 original_population.at(travellers_indices.at(i)).getHealth() = health_status.at(i);
293 map<string, pair<vector<uint>, vector<Health>>> result;
295 for (
auto it = returning_people->begin(); it != returning_people->end(); ++it) {
296 auto& traveller = **it;
310 string destination_sim = traveller.getHomeSimulatorId();
313 result[destination_sim].first.push_back(traveller.getHomePerson().getId());
314 result.at(destination_sim).second.push_back(traveller.getNewPerson()->getHealth());
321 for (
auto it = result.begin(); it != result.end(); ++it) {
322 if (it->second.second.size() != 0) {
329 string destination_facility) {
330 list < Simulator::PersonType * > working_people;
337 working_people.push_back(&person);
341 if (amount > working_people.size()) {
342 cout <<
"Warning, more people to send than actual people in region. Sending all people.\n";
343 amount = working_people.size();
346 vector<Simulator::TravellerType> chosen_people;
349 while (chosen_people.size() != amount) {
351 unsigned int index =
m_rng->operator()(working_people.size());
360 chosen_people.push_back(new_traveller);
361 working_people.erase(next(working_people.begin(), index));
365 m_communication_map[destination_sim]->hostForeignTravellers(chosen_people, days, destination_district,
366 destination_facility);
Person< BehaviourPolicy, BeliefPolicy > PersonType
std::shared_ptr< Calendar > m_calendar
Management of calendar.
SimulatorStatus timeStep()
Run one time step, computing full simulation (default) or only index case.
std::shared_ptr< spdlog::logger > m_logger
Traveller< PersonType > TravellerType
PersonType * getNewPerson() const
Header for the Infector class.
std::vector< Cluster > m_school_clusters
Container with school Clusters.
Header file for the Calendar class.
const std::vector< Cluster > & getClusters(ClusterType cluster_type) const
Get the clusters of this simulator based on the cluster type This is rather for testing purposes...
Simulator()
Default constructor for empty Simulator.
void sendNewTravellers(uint amount, uint days, const string &destination_sim_id, string destination_district, string destination_facility)
bool hostForeignTravellers(const vector< Simulator::TravellerType > &travellers, uint days, string destination_district, string destination_facility)
Receive travellers travellers: the travellers this simulator has to host.
Time Dependent Person DataType.
DiseaseProfile m_disease_profile
Profile of disease.
Utilities for the project.
std::vector< std::string > getRngStates() const
Retrieve the states of the rng's.
static void execute(Cluster &cluster, DiseaseProfile disease_profile, util::Random &contact_handler, std::shared_ptr< const Calendar > calendar, spdlog::logger &logger)
std::shared_ptr< Population > m_population
Pointer to the Population.
std::map< string, AsyncSimulator * > m_communication_map
Communication between the simulator and the senders.
void setOnVacation(bool is_on_vacation)
void setRngStates(std::vector< std::string > states)
Set the states of the rng's.
string m_name
Name of the simulator (the region it simulates)
bool m_track_index_case
General simulation or tracking index case.
bool isOnVacation() const
Header for the Simulator class.
vector< unique_ptr< T >> Block
Header file for the core Population class.
LogMode m_log_level
Specifies logging mode.
Container for persons in population.
Forward declaration of class Person.
std::vector< Cluster > m_primary_community
Container with primary community Clusters.
uint chooseCluster(const GeoCoordinate &coordinate, const vector< Cluster > &clusters, double influence)
Return an index to a cluster in the given vector Current policy: search for the first cluster with eq...
void notify(const EventType &e)
Health & getHealth()
Return person's health status.
const std::shared_ptr< const Population > getPopulation() const
Get the population.
void returnForeignTravellers()
Return people that are here FROM abroad.
uint m_next_hh_id
The household ID of the next traveller that arrives.
decltype(Parallel().with< RandomRef >()) m_parallel
bool welcomeHomeTravellers(const vector< uint > &travellers_indices, const vector< Health > &health_status)
Return people that were abroad travellers_indices: contains the indices (in the m_population->m_orig...
LogMode
Enum specifiying the level of logging required:
uint m_next_id
The ID of the next traveller that arrives.
std::vector< District > m_districts
Container with districts (villages and cities).
std::vector< Cluster > m_work_clusters
Container with work Clusters.
unsigned int getId() const
Get the id.
unsigned int getClusterId(ClusterType cluster_type) const
Get cluster ID of cluster_type.
ClusterType
Enumerates the cluster types.
static const GeoCoordCalculator & getInstance()
Singleton pattern.
SimplePlanner< Traveller< Simulator::PersonType > > m_planner
The Planner, responsible for the timing of travellers (when do they return home?).
std::vector< Cluster > m_households
Container with household Clusters.
Header for the core Cluster class.
void updateClusters()
Update the contacts in the given clusters.
std::shared_ptr< util::Random > m_rng
void setTrackIndexCase(bool track_index_case)
Change track_index_case setting.
std::vector< Cluster > m_secondary_community
Container with secondary community Clusters.
The random number generator.