Stride Reference Manual  - generated for commit 9643b11
WorkplaceGenerator.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  // 1. active people count and the commuting people count are given
30  // 2. count the workplaces
31  // 3. count the working people at each location = #residents + #incoming commuters - #outgoing commuters
32  // 4. use that information for the distribution
33  // 5. assign each workplaces to a location
34 
35  const auto EmployeeCount = ggConfig.info.popcount_workplace;
36  const auto WorkplacesCount =
37  static_cast<unsigned int>(ceil(EmployeeCount / static_cast<double>(ggConfig.people[Id::Workplace])));
38 
39  // = for each location #residents + #incoming commuting people - #outgoing commuting people
40  vector<double> weights;
41  for (const auto& loc : geoGrid) {
42  const double ActivePeopleCount =
43  (loc->GetPopCount() +
44  loc->GetIncomingCommuteCount(ggConfig.param.fraction_workplace_commuters) -
45  loc->GetOutgoingCommuteCount(ggConfig.param.fraction_workplace_commuters) *
46  ggConfig.param.particpation_workplace);
47 
48  const double weight = ActivePeopleCount / EmployeeCount;
49  AssertThrow(weight >= 0 && weight <= 1 && !std::isnan(weight), "Invalid weight: " + to_string(weight),
50  m_logger);
51  weights.push_back(weight);
52  }
53 
54  if (weights.empty()) {
55  // trng can't handle empty vectors
56  return;
57  }
58 
59  const auto dist = m_rn_man.GetDiscreteGenerator(weights, 0U);
60  auto pop = geoGrid.GetPopulation();
61 
62  for (auto i = 0U; i < WorkplacesCount; i++) {
63  const auto loc = geoGrid[dist()];
64  AddPools(*loc, pop, ggConfig);
65  }
66 }
67 
68 } // 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
double particpation_workplace
Participation of workplace (fraction of people of work age and not going to college and having employ...
Definition: GeoGridConfig.h:64
#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
unsigned int popcount_workplace
Number of individuals in Workplace.
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
struct geopop::GeoGridConfig::@0 param
void Apply(GeoGrid &, const GeoGridConfig &)
Generate ContactPools for ContactType::Id as sepcified by data in GeoGridConfig.
Definition: Generator.h:52
Definition of .
double fraction_workplace_commuters
Fraction of people in the workplace that commute.
Definition: GeoGridConfig.h:70
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28