Stride Reference Manual  - generated for commit 9643b11
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GeoGridConfig.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 "GeoGridConfig.h"
17 
18 #include "contact/AgeBrackets.h"
19 #include "contact/ContactType.h"
22 #include "util/StringUtils.h"
23 
24 #include <boost/property_tree/ptree.hpp>
25 #include <cmath>
26 #include <iomanip>
27 
28 namespace geopop {
29 
30 using namespace std;
31 using namespace boost::property_tree;
32 using namespace stride::AgeBrackets;
33 using namespace stride::ContactType;
35 
37 
38 GeoGridConfig::GeoGridConfig(const ptree& configPt) : GeoGridConfig()
39 {
40  const auto pt = configPt.get_child("run.geopop_gen");
41  param.pop_size = pt.get<unsigned int>("population_size");
42  param.participation_college = pt.get<double>("participation_college");
43  param.fraction_workplace_commuters = pt.get<double>("fraction_workplace_commuters");
44  param.fraction_college_commuters = pt.get<double>("fraction_college_commuters");
45  param.particpation_workplace = pt.get<double>("particpation_workplace");
46 
47  people[Id::K12School] = pt.get<unsigned int>("people_per_K12School", 500U);
48  people[Id::College] = pt.get<unsigned int>("people_per_College", 3000U);
49  people[Id::Workplace] = pt.get<unsigned int>("people_per_Workplace", 20U);
50  people[Id::PrimaryCommunity] = pt.get<unsigned int>("people_per_PrimaryCommunity", 2000U);
51  people[Id::SecondaryCommunity] = pt.get<unsigned int>("people_per_SecondaryCommunity", 2000U);
52 
53  pools[Id::K12School] = pt.get<unsigned int>("pools_per_K12School", 25U);
54  pools[Id::College] = pt.get<unsigned int>("pools_per_College", 20U);
55 }
56 
57 void GeoGridConfig::SetData(const string& householdsFileName)
58 {
59  auto householdsReader = ReaderFactory::CreateHouseholdReader(householdsFileName);
60  householdsReader->SetReferenceHouseholds(refHH.person_count, refHH.ages);
61  const auto popSize = param.pop_size;
62 
63  //----------------------------------------------------------------
64  // Determine age makeup of reference houshold population.
65  //----------------------------------------------------------------
66  const auto ref_p_count = refHH.person_count;
67  const auto averageHhSize = static_cast<double>(ref_p_count) / static_cast<double>(refHH.ages.size());
68 
69  auto ref_k12school = 0U;
70  auto ref_college = 0U;
71  auto ref_workplace = 0U;
72  for (const auto& hhAgeProfile : refHH.ages) {
73  for (const auto& age : hhAgeProfile) {
74  if (K12School::HasAge(age)) {
75  ref_k12school++;
76  }
77  if (College::HasAge(age)) {
78  ref_college++;
79  }
80  if (Workplace::HasAge(age)) {
81  ref_workplace++;
82  }
83  }
84  }
85  //----------------------------------------------------------------
86  // Scale up to the generated population size.
87  //----------------------------------------------------------------
88  const auto fraction_k12school_age = static_cast<double>(ref_k12school) / static_cast<double>(ref_p_count);
89  const auto fraction_college_age = static_cast<double>(ref_college) / static_cast<double>(ref_p_count);
90  const auto fraction_workplace_age = static_cast<double>(ref_workplace) / static_cast<double>(ref_p_count);
91 
92  const auto age_count_k12school = static_cast<unsigned int>(floor(popSize * fraction_k12school_age));
93  const auto age_count_college = static_cast<unsigned int>(floor(popSize * fraction_college_age));
94  const auto age_count_workplace = static_cast<unsigned int>(floor(popSize * fraction_workplace_age));
95 
96  info.popcount_k12school = age_count_k12school;
97 
98  info.popcount_college = static_cast<unsigned int>(floor(param.participation_college * age_count_college));
99 
100  info.popcount_workplace = static_cast<unsigned int>(
101  floor(param.particpation_workplace * (age_count_workplace - info.popcount_college)));
102 
103  info.count_households = static_cast<unsigned int>(floor(static_cast<double>(popSize) / averageHhSize));
104 }
105 
106 ostream& operator<<(ostream& out, const GeoGridConfig& config)
107 {
108  const int w = 53;
109  out.setf(std::ios_base::left, std::ios_base::adjustfield);
110  out << "Input:" << endl;
111  out << setw(w) << "Fraction college commuters:" << config.param.fraction_college_commuters << "\n";
112  out << setw(w) << "Fraction workplace commuters:" << config.param.fraction_workplace_commuters << "\n";
113  out << setw(w) << "Participation fraction of college:" << config.param.participation_college << "\n";
114  out << setw(w) << "Participation fraaction of workplace:" << config.param.particpation_workplace << "\n";
115  out << setw(w) << "Target population size" << intToDottedString(config.param.pop_size) << "\n"
116  << "\n";
117  out << "Calculated:"
118  << "\n";
119  out << setw(w) << "K12School student count:" << intToDottedString(config.info.popcount_k12school) << "\n";
120  out << setw(w) << "College student count:" << intToDottedString(config.info.popcount_college) << "\n";
121  out << setw(w) << "Workplace person count:" << intToDottedString(config.info.popcount_workplace) << "\n";
122  out << endl;
123  return out;
124 }
125 
126 } // 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
void SetData(const std::string &householdsFileName)
Read the househould data file, parse it and set data.
static bool HasAge(double age)
Definition: AgeBrackets.h:48
GeoGridConfig()
Default constructor needed in test code.
struct geopop::GeoGridConfig::@1 refHH
double particpation_workplace
Participation of workplace (fraction of people of work age and not going to college and having employ...
Definition: GeoGridConfig.h:64
unsigned int popcount_k12school
Numbers of individuals in K12School.
Definition: GeoGridConfig.h:98
std::string intToDottedString(const T &value)
Definition: StringUtils.h:173
static bool HasAge(double age)
Definition: AgeBrackets.h:57
STL namespace.
unsigned int popcount_workplace
Number of individuals in Workplace.
AgeBrackets that determine participation in type of ContactPool.
Definition: AgeBrackets.h:22
Definition of ContactPool Id Type.
unsigned int pop_size
Target population size for the generated population.
Definition: GeoGridConfig.h:73
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
double fraction_college_commuters
Fraction of college students that commute.
Definition: GeoGridConfig.h:67
static std::shared_ptr< HouseholdReader > CreateHouseholdReader(const std::string &filename)
Create a HouseholdReader based on the filename relative to the data directory.
struct geopop::GeoGridConfig::@0 param
ostream & operator<<(ostream &out, const GeoGridConfig &config)
unsigned int popcount_college
Number of individuals in College.
double fraction_workplace_commuters
Fraction of people in the workplace that commute.
Definition: GeoGridConfig.h:70
static bool HasAge(double age)
Definition: AgeBrackets.h:66
double participation_college
Participation of college (fraction of people of college age going to college).
Definition: GeoGridConfig.h:60
Miscellaneous string utilities.
stride::ContactType::IdSubscriptArray< unsigned int > pools
Pools per unit (= Household, K12School, College, etc.) for each of the ContactTypes.
Definition: GeoGridConfig.h:52
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28