Stride Reference Manual  - generated for commit 9643b11
CollegeGenerator.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 "Generator.h"
17 
18 #include "util/Assert.h"
19 
20 namespace geopop {
21 
22 using namespace std;
23 using namespace stride;
24 using namespace stride::ContactType;
25 
26 template<>
28 {
29  const auto studentCount = ggConfig.info.popcount_college;
30  const auto collegeCount =
31  static_cast<unsigned int>(ceil(studentCount / static_cast<double>(ggConfig.people[Id::College])));
32  const auto cities = geoGrid.TopK(10);
33 
34  if (cities.empty()) {
35  // trng can't handle empty vectors
36  return;
37  }
38 
39  // Aggregate population in TopK cities.
40  auto totalPop = 0U;
41  for (const auto& c : cities) {
42  totalPop += c->GetPopCount();
43  }
44 
45  // Weights determined by relative population in city.
46  vector<double> weights;
47  for (const auto& c : cities) {
48  const auto weight = static_cast<double>(c->GetPopCount()) / static_cast<double>(totalPop);
49  AssertThrow(weight >= 0 && weight <= 1 && !std::isnan(weight),
50  "CollegeGenerator> Invalid weight: " + to_string(weight), m_logger);
51  weights.push_back(weight);
52  }
53 
54  const auto dist = m_rn_man.GetDiscreteGenerator(weights, 0U);
55  auto pop = geoGrid.GetPopulation();
56 
57  for (auto i = 0U; i < collegeCount; i++) {
58  auto loc = cities[dist()];
59  AddPools(*loc, pop, ggConfig);
60  }
61 }
62 
63 
64 } // namespace geopop
stride::Population * GetPopulation() const
Get the Population associated with this GeoGrid.
Definition: GeoGrid.h:63
struct geopop::GeoGridConfig::@2 info
Configuration data mostly for generating a population, but also for computing the required number of ...
Definition: GeoGridConfig.h:35
#define AssertThrow(CONDITION, MESSAGE, LOGGER)
Definition: Assert.h:68
STL namespace.
A Geographic grid of simulation region contains Locations that in turn contain an index to the Contac...
Definition: GeoGrid.h:41
std::vector< Location * > TopK(size_t k) const
Gets the K biggest (in population count) locations of this GeoGrid.
Definition: GeoGrid.cpp:129
Namespace for the geographic and demograhic classes.
Definition: Coordinate.h:21
stride::ContactType::IdSubscriptArray< unsigned int > people
People per unit (= Household, K12School, College, etc.) for each of the ContactTypes.
Definition: GeoGridConfig.h:47
void Apply(GeoGrid &, const GeoGridConfig &)
Generate ContactPools for ContactType::Id as sepcified by data in GeoGridConfig.
Definition: Generator.h:52
Definition of .
unsigned int popcount_college
Number of individuals in College.
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28