38 m_logger->trace(
"Starting to populate Workplaces");
40 auto genCommute{function<int()>()};
41 auto genNonCommute{function<int()>()};
42 vector<ContactPool*> nearbyWp{};
43 vector<Location*> commuteLocations{};
53 double fracCommuteStudents = 0.0;
54 if (static_cast<bool>(fracWorkplaceCommute) && popWorkplace) {
55 fracCommuteStudents = (popCollege * fracCollegeCommute) /(popWorkplace * fracWorkplaceCommute);
61 for (
const auto& loc : geoGrid) {
62 if (loc->GetPopCount() == 0) {
69 commuteLocations.clear();
70 genCommute = function<int()>();
72 vector<double> commutingWeights;
73 for (
const pair<Location*, double>& commute : loc->CRefOutgoingCommutes()) {
74 const auto& workplaces = commute.first->RefPools(Id::Workplace);
75 if (!workplaces.empty()) {
76 commuteLocations.push_back(commute.first);
77 const auto weight = commute.second - (commute.second * fracCommuteStudents);
78 commutingWeights.push_back(weight);
79 AssertThrow(weight >= 0.0 && weight <= 1.0 && !isnan(weight),
80 "Invalid weight: " + to_string(weight), m_logger);
84 if (!commutingWeights.empty()) {
85 genCommute = m_rn_man.GetDiscreteGenerator(commutingWeights, 0U);
91 nearbyWp = geoGrid.GetNearbyPools(Id::Workplace, *loc);
92 genNonCommute = m_rn_man.GetUniformIntGenerator(0, static_cast<int>(nearbyWp.size()), 0U);
97 for (
auto& hhPool : loc->RefPools(Id::Household)) {
98 for (
auto person : *hhPool) {
104 if (!
Workplace::HasAge(person->GetAge()) || (person->GetPoolId(Id::College) != 0)) {
110 bool isActiveWorker = m_rn_man.MakeWeightedCoinFlip(participWorkplace);
111 if (isActiveWorker) {
115 const auto isCommuter = m_rn_man.MakeWeightedCoinFlip(fracWorkplaceCommute);
116 if (!commuteLocations.empty() && isCommuter) {
120 auto& pools = commuteLocations[genCommute()]->RefPools(Id::Workplace);
121 auto s =
static_cast<int>(pools.size());
122 auto gen = m_rn_man.GetUniformIntGenerator(0, s);
123 auto pool = pools[gen()];
125 pool->AddMember(person);
126 person->SetPoolId(Id::Workplace, pool->GetId());
131 const auto idraw = genNonCommute();
132 nearbyWp[idraw]->AddMember(person);
133 person->SetPoolId(Id::Workplace, nearbyWp[idraw]->GetId());
140 m_logger->trace(
"Done populating Workplaces");
struct geopop::GeoGridConfig::@2 info
Configuration data mostly for generating a population, but also for computing the required number of ...
Header for the core ContactPool class.
double particpation_workplace
Participation of workplace (fraction of people of work age and not going to college and having employ...
#define AssertThrow(CONDITION, MESSAGE, LOGGER)
A Geographic grid of simulation region contains Locations that in turn contain an index to the Contac...
unsigned int popcount_workplace
Number of individuals in Workplace.
AgeBrackets that determine participation in type of ContactPool.
Namespace for the geographic and demograhic classes.
void Apply(GeoGrid &, const GeoGridConfig &)
Populate the ContactPools type ID. This is a placeholder for the specializations. ...
double fraction_college_commuters
Fraction of college students that commute.
struct geopop::GeoGridConfig::@0 param
unsigned int popcount_college
Number of individuals in College.
double fraction_workplace_commuters
Fraction of people in the workplace that commute.
static bool HasAge(double age)
Namespace for the simulator and related classes.
Namespace to manage types of ContactPool.