Stride Reference Manual  - generated for commit 9643b11
Location.h
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 #pragma once
17 
18 #include "contact/ContactType.h"
20 #include "geopop/Coordinate.h"
21 #include "util/SegmentedVector.h"
22 
23 #include <iostream>
24 #include <memory>
25 #include <set>
26 #include <string>
27 #include <typeindex>
28 #include <typeinfo>
29 #include <unordered_map>
30 #include <vector>
31 
32 namespace stride {
33 class ContactPool;
34 }
35 
36 namespace geopop {
37 
41 class Location
42 {
43 public:
45  Location(unsigned int id, unsigned int province, Coordinate coordinate = Coordinate(0.0, 0.0),
46  std::string name = "", unsigned int popCount = 0U);
47 
49  bool operator==(const Location& other) const;
50 
53  void AddIncomingCommute(std::shared_ptr<Location> otherLocation, double fraction);
54 
57  void AddOutgoingCommute(std::shared_ptr<Location> otherLocation, double fraction);
58 
60  const Coordinate GetCoordinate() const { return m_coordinate; }
61 
63  unsigned int GetID() const { return m_id; }
64 
66  int GetIncomingCommuteCount(double fractionCommuters) const;
67 
69  unsigned int GetInfectedCount() const;
70 
72  std::string GetName() const { return m_name; }
73 
75  unsigned int GetOutgoingCommuteCount(double fractionCommuters) const;
76 
78  unsigned int GetPopCount() const { return m_pop_count; }
79 
81  unsigned int GetProvince() const { return m_province; }
82 
84  double GetPopFraction() const;
85 
87  void SetCoordinate(const Coordinate& coordinate) { m_coordinate = coordinate; }
88 
90  void SetPopCount(unsigned int totalPopCount);
91 
93  void SetPopFraction(double relativePopulation);
94 
95 public:
100  {
101  return m_pool_index[id];
102  }
103 
107  template <stride::ContactType::Id T>
109  {
110  return m_pool_index[T];
111  }
112 
117  {
118  return m_pool_index[id];
119  }
120 
124  template <stride::ContactType::Id T>
126  {
127  return m_pool_index[T];
128  }
129 
133  {
134  m_pool_index[typeId].emplace_back(p);
135  }
136 
138  template <stride::ContactType::Id T>
140  {
141  m_pool_index[T].emplace_back(p);
142  }
143 
144 public:
146  const std::vector<std::pair<Location*, double>>& CRefIncomingCommutes() const { return m_inCommutes; }
147 
149  const std::vector<std::pair<Location*, double>>& CRefOutgoingCommutes() const { return m_outCommutes; }
150 
151 private:
153  unsigned int m_id = 0U;
154  std::string m_name;
155  unsigned int m_pop_count;
156  double m_pop_fraction;
157  unsigned int m_province;
158 
160  std::vector<std::pair<Location*, double>> m_inCommutes;
161 
163  std::vector<std::pair<Location*, double>> m_outCommutes;
164 
167 };
168 
169 } // namespace geopop
unsigned int GetID() const
Gets ID of this Location.
Definition: Location.h:63
Id
Enumerates the ContactPool types.
Definition: ContactType.h:34
void AddIncomingCommute(std::shared_ptr< Location > otherLocation, double fraction)
Adds a Location and a proportion to the incoming commute vector.
Definition: Location.cpp:51
void RegisterPool(stride::ContactPool *p)
Templated version of .
Definition: Location.h:139
std::string GetName() const
Gets the name.
Definition: Location.h:72
A group of Persons that potentially have contacts with one another.
Definition: ContactPool.h:38
stride::ContactType::IdSubscriptArray< stride::util::SegmentedVector< stride::ContactPool * > > m_pool_index
Definition: Location.h:166
stride::util::SegmentedVector< stride::ContactPool * > & RefPools(stride::ContactType::Id id)
Access through reference to ContactPools of type &#39;id&#39;.
Definition: Location.h:116
double GetPopFraction() const
Get Location&#39;s population fraction (of the total populaion count).
Definition: Location.cpp:93
unsigned int m_id
Id.
Definition: Location.h:153
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
Coordinate m_coordinate
Coordinate of the Location.
Definition: Location.h:152
Interface and implementation for SegmentedVector class.
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
void RegisterPool(stride::ContactPool *p, stride::ContactType::Id typeId)
Register a ContactPool pointer in this Location&#39;s pool system.
Definition: Location.h:132
double m_pop_fraction
Fraction of whole population at this Location.
Definition: Location.h:156
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
Container that stores objects "almost contiguously" (in a chain of blocks) and guarantees that pointe...
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
Container for the contact pools of various type (household, work, ...).
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
An std::array modified to enable subscripting with the constact pool type indentifiers.
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
stride::util::SegmentedVector< stride::ContactPool * > & RefPools()
Templated version of for use when the type id is fixed.
Definition: Location.h:125
void SetPopFraction(double relativePopulation)
Set Location&#39;s population fraction (of the total populaion count).
Definition: Location.cpp:99
std::string m_name
Name.
Definition: Location.h:154
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
void SetCoordinate(const Coordinate &coordinate)
Sets the Coordinate of this Location.
Definition: Location.h:87
Location for use within the GeoGrid, contains Coordinate and index to ContactPools.
Definition: Location.h:41
unsigned int m_province
Province id.
Definition: Location.h:157
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
unsigned int GetOutgoingCommuteCount(double fractionCommuters) const
Calculates number of outgoing commuters, given the fraction of the population that commutes...
Definition: Location.cpp:83
const std::vector< std::pair< Location *, double > > & CRefOutgoingCommutes() const
References outgoing commute Locations + fraction of commutes to that Location.
Definition: Location.h:149