Stride Reference Manual  - generated for commit 9643b11
CollegePopulator.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 "Populator.h"
17 
18 #include "contact/AgeBrackets.h"
19 #include "contact/ContactPool.h"
20 #include "geopop/GeoGrid.h"
21 #include "geopop/GeoGridConfig.h"
22 #include "geopop/Location.h"
23 #include "pop/Person.h"
24 #include "util/Assert.h"
25 
26 namespace geopop {
27 
28 using namespace std;
29 using namespace stride;
30 using namespace stride::ContactType;
31 
32 template<>
34 {
35  m_logger->trace("Starting to populate Colleges");
36 
37  // for every location
38  for (const auto& loc : geoGrid) {
39  if (loc->GetPopCount() == 0) {
40  continue;
41  }
42  // 1. find all highschools in an area of 10-k*10 km
43  const auto& nearByCollegePools = geoGrid.GetNearbyPools(Id::College, *loc);
44 
45  AssertThrow(!nearByCollegePools.empty(), "No College found!", m_logger);
46 
47  const auto distNonCommuting =
48  m_rn_man.GetUniformIntGenerator(0, static_cast<int>(nearByCollegePools.size()), 0U);
49 
50  // 2. find all colleges where students from this location commute to
51  vector<Location*> commutingCollege;
52  vector<double> commutingWeights;
53  for (const auto& commute : loc->CRefOutgoingCommutes()) {
54  const auto& cpools = commute.first->CRefPools(Id::College);
55  if (!cpools.empty()) {
56  commutingCollege.push_back(commute.first);
57  commutingWeights.push_back(commute.second);
58  }
59  }
60 
61  function<int()> disCommuting;
62 
63  if (!commutingWeights.empty()) {
64  disCommuting = m_rn_man.GetDiscreteGenerator(commutingWeights, 0U);
65  }
66 
67  // 2. for every student assign a class
68  for (const auto& hhPool : loc->RefPools(Id::Household)) {
69  for (Person* p : *hhPool) {
70  if (AgeBrackets::College::HasAge(p->GetAge()) &&
71  m_rn_man.MakeWeightedCoinFlip(geoGridConfig.param.participation_college)) {
72  // this person is a student
73  if (!commutingCollege.empty() &&
74  m_rn_man.MakeWeightedCoinFlip(geoGridConfig.param.fraction_college_commuters)) {
75  // this person is commuting
76 
77  // pools to commute to
78  const auto& collegePools =
79  commutingCollege[disCommuting()]->CRefPools(Id::College);
80 
81  auto disPools = m_rn_man.GetUniformIntGenerator(
82  0, static_cast<int>(collegePools.size()), 0U);
83  auto idraw = disPools();
84  collegePools[idraw]->AddMember(p);
85  p->SetPoolId(Id::College, collegePools[idraw]->GetId());
86  } else {
87  auto idraw = distNonCommuting();
88  nearByCollegePools[idraw]->AddMember(p);
89  p->SetPoolId(Id::College, nearByCollegePools[idraw]->GetId());
90  }
91  }
92  }
93  }
94  }
95 
96  m_logger->trace("Done populating Colleges");
97 }
98 
99 } // namespace geopop
Header file for the Person class.
Configuration data mostly for generating a population, but also for computing the required number of ...
Definition: GeoGridConfig.h:35
Header for the core ContactPool class.
#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
Namespace for the geographic and demograhic classes.
Definition: Coordinate.h:21
void Apply(GeoGrid &, const GeoGridConfig &)
Populate the ContactPools type ID. This is a placeholder for the specializations. ...
Definition: Populator.h:51
double fraction_college_commuters
Fraction of college students that commute.
Definition: GeoGridConfig.h:67
struct geopop::GeoGridConfig::@0 param
Definition of .
double participation_college
Participation of college (fraction of people of college age going to college).
Definition: GeoGridConfig.h:60
Store and handle person data.
Definition: Person.h:34
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28