Stride Reference Manual  - generated for commit 9643b11
K12SchoolGenerator.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 namespace geopop {
19 
20 using namespace std;
21 using namespace stride;
22 using namespace stride::ContactType;
23 
24 template<>
26 {
27  // 1. given the number of persons of school age, calculate number of schools
28  // 2. assign schools to a location by using a discrete distribution which reflects the
29  // relative number of pupils for that location; the relative number of pupils is set
30  // to the relative population w.r.t the total population.
31 
32  const auto pupilCount = ggConfig.info.popcount_k12school;
33  const auto schoolCount =
34  static_cast<unsigned int>(ceil(pupilCount / static_cast<double>(ggConfig.people[Id::K12School])));
35 
36  vector<double> weights;
37  for (const auto& loc : geoGrid) {
38  weights.push_back(loc->GetPopFraction());
39  }
40 
41  if (weights.empty()) {
42  // trng can't handle empty vectors
43  return;
44  }
45 
46  const auto dist = m_rn_man.GetDiscreteGenerator(weights, 0U);
47  auto pop = geoGrid.GetPopulation();
48 
49  for (auto i = 0U; i < schoolCount; i++) {
50  const auto loc = geoGrid[dist()];
51  AddPools(*loc, pop, ggConfig);
52  }
53 }
54 
55 } // namespace geopop
struct geopop::GeoGridConfig::@2 info
Configuration data mostly for generating a population, but also for computing the required number of ...
Definition: GeoGridConfig.h:35
unsigned int popcount_k12school
Numbers of individuals in K12School.
Definition: GeoGridConfig.h:98
STL namespace.
A Geographic grid of simulation region contains Locations that in turn contain an index to the Contac...
Definition: GeoGrid.h:41
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
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28