Stride Reference Manual  - generated for commit 9643b11
Location.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2018, 2019, Jan Broeckhove and Bistromatics group.
14  */
15 
16 #include "Location.h"
17 #include "contact/ContactPool.h"
18 #include "contact/ContactType.h"
19 #include "disease/Health.h"
20 #include "pop/Person.h"
21 #include "util/Exception.h"
22 
23 #include <cmath>
24 
25 namespace geopop {
26 
27 using namespace std;
28 using namespace stride::ContactType;
29 
30 Location::Location(unsigned int id, unsigned int province, Coordinate coordinate, string name, unsigned int popCount)
31  : m_coordinate(coordinate), m_id(id), m_name(move(name)), m_pop_count(popCount), m_pop_fraction(0.0),
32  m_province(province), m_inCommutes(), m_outCommutes(),/* m_cc(),*/ m_pool_index()
33 {
34 }
35 
36 bool Location::operator==(const Location& other) const
37 {
38  using boost::geometry::get;
39 
40  auto temp = true;
41  for (Id typ : IdList) {
42  temp = temp && (CRefPools(typ) == other.CRefPools(typ));
43  }
44  return temp && GetID() == other.GetID() && get<0>(GetCoordinate()) == get<0>(other.GetCoordinate()) &&
45  get<1>(GetCoordinate()) == get<1>(other.GetCoordinate()) && GetName() == other.GetName() &&
46  GetProvince() == other.GetProvince() && GetPopCount() == other.GetPopCount() &&
49 }
50 
51 void Location::AddIncomingCommute(shared_ptr<Location> otherLocation, double fraction)
52 {
53  m_inCommutes.emplace_back(otherLocation.get(), fraction);
54 }
55 
56 void Location::AddOutgoingCommute(shared_ptr<Location> otherLocation, double fraction)
57 {
58  m_outCommutes.emplace_back(otherLocation.get(), fraction);
59 }
60 
61 int Location::GetIncomingCommuteCount(double fractionCommuters) const
62 {
63  double value = 0;
64  for (const auto& locProportion : m_inCommutes) {
65  // locProportion.second of the people in locProportion.first are commuting to this
66  value += locProportion.second * (fractionCommuters * (double)locProportion.first->GetPopCount());
67  }
68  return static_cast<int>(floor(value));
69 }
70 
71 unsigned int Location::GetInfectedCount() const
72 {
73  unsigned int total{0U};
74  for (const auto& pool : CRefPools<Id::Household>()) {
75  for (const auto& person : *pool) {
76  const auto& h = person->GetHealth();
77  total += h.IsInfected() || h.IsRecovered();
78  }
79  }
80  return total;
81 }
82 
83 unsigned int Location::GetOutgoingCommuteCount(double fractionCommuters) const
84 {
85  double totalProportion = 0;
86  for (const auto& locProportion : m_outCommutes) {
87  // locProportion.second of the people in this are commuting to locProportion.first
88  totalProportion += locProportion.second;
89  }
90  return static_cast<unsigned int>(floor(totalProportion * (fractionCommuters * m_pop_count)));
91 }
92 
93 double Location::GetPopFraction() const { return m_pop_fraction; }
94 
95 void Location::SetPopCount(unsigned int totalPopCount)
96 {
97  m_pop_count = static_cast<unsigned int>(floor(m_pop_fraction * totalPopCount));
98 }
99 void Location::SetPopFraction(double relativePopulation) { m_pop_fraction = relativePopulation; }
100 
101 } // namespace geopop
unsigned int GetID() const
Gets ID of this Location.
Definition: Location.h:63
void AddIncomingCommute(std::shared_ptr< Location > otherLocation, double fraction)
Adds a Location and a proportion to the incoming commute vector.
Definition: Location.cpp:51
std::string GetName() const
Gets the name.
Definition: Location.h:72
Header file for the Person class.
Header for the core ContactPool class.
double GetPopFraction() const
Get Location&#39;s population fraction (of the total populaion count).
Definition: Location.cpp:93
constexpr std::initializer_list< Id > IdList
To allow iteration over the type ids.
Definition: ContactType.h:75
int GetIncomingCommuteCount(double fractionCommuters) const
Calculates number of incomming commuters, given the fraction of the population that commutes...
Definition: Location.cpp:61
unsigned int GetProvince() const
Gets the province.
Definition: Location.h:81
unsigned int m_pop_count
Population count (number of individuals) at this Location.
Definition: Location.h:155
std::vector< std::pair< Location *, double > > m_outCommutes
The system holding pointers to the contactpools (for each type id) at this Location.
Definition: Location.h:163
double m_pop_fraction
Fraction of whole population at this Location.
Definition: Location.h:156
STL namespace.
Header for the Health class.
std::vector< std::pair< Location *, double > > m_inCommutes
Incomming commutes stored as pair of Location and fraction of population at that Location.
Definition: Location.h:160
void SetPopCount(unsigned int totalPopCount)
Set Location&#39;s population count using its population fraction and the total population count...
Definition: Location.cpp:95
Definition of ContactPool Id Type.
unsigned int GetInfectedCount() const
Gets the number of people infected in the contactpools at this location.
Definition: Location.cpp:71
Namespace for the geographic and demograhic classes.
Definition: Coordinate.h:21
const Coordinate GetCoordinate() const
Gets the Coordinate of this Location.
Definition: Location.h:60
void AddOutgoingCommute(std::shared_ptr< Location > otherLocation, double fraction)
Adds a Location and a fraction to the outgoing commute vector.
Definition: Location.cpp:56
Location(unsigned int id, unsigned int province, Coordinate coordinate=Coordinate(0.0, 0.0), std::string name="", unsigned int popCount=0U)
Parametrized constructor with population count.
Definition: Location.cpp:30
void SetPopFraction(double relativePopulation)
Set Location&#39;s population fraction (of the total populaion count).
Definition: Location.cpp:99
boost::geometry::model::point< double, 2, boost::geometry::cs::geographic< boost::geometry::degree >> Coordinate
Definition: Coordinate.h:23
const std::vector< std::pair< Location *, double > > & CRefIncomingCommutes() const
References incoming commute Locations + fraction of commutes to that Location.
Definition: Location.h:146
unsigned int GetPopCount() const
Gets the absolute population.
Definition: Location.h:78
bool operator==(const Location &other) const
Perform a full comparison with the other location.
Definition: Location.cpp:36
const stride::util::SegmentedVector< stride::ContactPool * > & CRefPools(stride::ContactType::Id id) const
Access through const reference to ContactPools of type &#39;id&#39;.
Definition: Location.h:99
const stride::util::SegmentedVector< stride::ContactPool * > & CRefPools() const
Templated version of for use when the type id is fixed.
Definition: Location.h:108
Location for use within the GeoGrid, contains Coordinate and index to ContactPools.
Definition: Location.h:41
unsigned int GetOutgoingCommuteCount(double fractionCommuters) const
Calculates number of outgoing commuters, given the fraction of the population that commutes...
Definition: Location.cpp:83
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28
const std::vector< std::pair< Location *, double > > & CRefOutgoingCommutes() const
References outgoing commute Locations + fraction of commutes to that Location.
Definition: Location.h:149