Stride Reference Manual  - generated for commit 9643b11
SecondaryCommunityPopulator.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/ContactPool.h"
19 #include "geopop/GeoGrid.h"
20 #include "geopop/Location.h"
21 #include "pop/Person.h"
22 
23 #include <set>
24 
25 using namespace std;
26 using namespace stride;
27 using namespace stride::ContactType;
28 
29 namespace geopop {
30 
31 template<>
33 {
34  m_logger->trace("Starting to populate Secondary Communities");
35 
36  for (const auto& loc : geoGrid) {
37  if (loc->GetPopCount() == 0) {
38  continue;
39  }
40  // 1. find all communities in an area of 10-k*10 km
41  const auto& nearbyPools = geoGrid.GetNearbyPools(Id::SecondaryCommunity, *loc);
42 
43  if (nearbyPools.empty()) { // apparently no commumity pools present, so nothing to populate
44  return;
45  }
46 
47  // 2. find all households in this location
48  const auto& households = loc->RefPools(Id::Household);
49 
50  auto hh_per_comm = households.size() / nearbyPools.size();
51  auto remainder = households.size() % nearbyPools.size();
52  auto current_comm = 0U;
53  auto current_hh_in_comm = 0U;
54 
55  for (const auto& housePool : households) {
56  if ((current_hh_in_comm == hh_per_comm && (!remainder || current_comm >= remainder)) ||
57  (current_hh_in_comm == hh_per_comm + 1 && (remainder && current_comm < remainder))) {
58  current_comm++;
59  current_hh_in_comm = 0;
60  }
61  current_hh_in_comm++;
62  auto pool = nearbyPools[current_comm];
63  for (auto p : *housePool) {
64  pool->AddMember(p);
65  p->SetPoolId(Id::SecondaryCommunity, pool->GetId());
66  }
67  }
68  }
69 
70  m_logger->trace("Done populating Secondary Communities");
71 }
72 } // 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.
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
Populator uses geo & pop data to populate ContactPools in the GeoGrid.
Definition: Populator.h:36
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28