-
Notifications
You must be signed in to change notification settings - Fork 1
/
Location.cpp
90 lines (76 loc) · 2.82 KB
/
Location.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Location.cpp
#include <cstdlib>
#include <cstring>
#include <climits>
#include <assert.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include "Person.h"
#include "Location.h"
#include "Parameters.h"
using namespace covid::standard;
size_t Location::NEXT_ID = 0;
Location::Location()
: _person(0) {
_ID = NEXT_ID++;
_coord = make_pair(0.0, 0.0);
_type = NUM_OF_LOCATION_TYPES; // compileable, but not sensible value, because it must be set elsewhere
_essential = true;
_riskiness= 0.0;
_hospital = nullptr;
}
Location::~Location() {
_person.clear();
_neighbors.clear();
}
void Location::dumper() const {
cerr << "Location ID: " << _ID << endl;
cerr << "\ttype: " << _type << endl;
cerr << "\tcoords: " << _coord.first << ", " << _coord.second << endl;
cerr << "\tessential: " << _essential << endl;
cerr << "\triskiness: " << _riskiness << endl;
cerr << "\tpeople: "; /*for (auto p: _person) { cerr << p->getID() << " "; }*/ cerr << _person.size(); cerr << endl;
cerr << "\tvisitors: "; /*for (auto p: _visitors) { cerr << p->getID() << " "; }*/ cerr << _visitors.size(); cerr << endl;
cerr << "\tneighbors: "; for (auto l: _neighbors) { cerr << l->getID() << " "; } cerr << endl;
}
void Location::revertState() {
// _visitors should be empty before tick() is called because it is cleared after each day
// _person is only dynamic for hospitals
if (_type == HOSPITAL) {
for (Person* p : _person) {
// remove all patients from this hospital (HCWs will not be removed since that is a static property)
// those patients that should be in a hospital will be added back by Person::revertState()
if (not (p->getDayLoc() == this)) { removePerson(p); }
}
}
}
bool Location::removePerson(Person* p) { // TODO -- consider implications of using set for container, to make removing faster
for (unsigned int i=0; i<_person.size(); i++) {
if (_person[i] == p) {
_person[i] = _person.back();
_person.pop_back();
return true;
}
}
return false;
}
/*
// Calling scope must verify that returned person is not nullptr
Person* Location::findMom() {
vector<Person*> residents = getResidents();
vector<Person*> potential_moms;
int minage = 15;
int maxage = 45;
for (auto p: residents) {
if (p->getSex() == FEMALE and p->getAge() >= minage and p->getAge() <= maxage) potential_moms.push_back(p);
}
if (potential_moms.size() == 0) return nullptr;
int r = gsl_rng_uniform_int(RNG, potential_moms.size());
Person* mom = potential_moms[r];
return mom;
}*/
// addNeighbor - adds location p to the location's neighbor list.
// Note that this relationship is one-way.
void Location::addNeighbor(Location* loc) {
_neighbors.insert(loc);
}