Stride Reference Manual  - generated for commit 9643b11
SurveySeeder.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 2017, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #include "SurveySeeder.h"
22 
23 #include "pop/Population.h"
24 #include "util/Exception.h"
25 #include "util/RnMan.h"
26 
27 #include <boost/property_tree/ptree.hpp>
28 #include <cassert>
29 
30 using namespace boost::property_tree;
31 using namespace stride::util;
32 using namespace stride::ContactType;
33 using namespace std;
34 
35 namespace stride {
36 
37 SurveySeeder::SurveySeeder(const ptree& config, RnMan& rnMan) : m_config(config), m_rn_man(rnMan) {}
38 
39 shared_ptr<Population> SurveySeeder::Seed(shared_ptr<Population> pop)
40 {
41  const string logLevel = m_config.get<string>("run.contact_log_level", "None");
42  if (logLevel != "None") {
43  Population& population = *pop;
44  auto& poolSys = population.CRefPoolSys();
45  auto& logger = population.RefContactLogger();
46  const auto popCount = static_cast<unsigned int>(population.size() - 1);
47  const auto numSurveyed = m_config.get<unsigned int>("run.num_participants_survey");
48 
49  assert((popCount >= 1U) && "SurveySeeder> Population count zero unacceptable.");
50  assert((popCount >= numSurveyed) && "SurveySeeder> Pop count has to exceeed number of surveyed.");
51 
52  // Use while-loop to get 'participants' unique participants (default sampling is with replacement).
53  // A for loop will not do because we might draw the same person twice.
54  auto numSamples = 0U;
55  auto generator = m_rn_man.GetUniformIntGenerator(0, static_cast<int>(popCount), 0U);
56 
57  while (numSamples < numSurveyed) {
58  Person& p = population[generator()];
59  if (p.IsSurveyParticipant()) {
60  continue;
61  }
63 
64  const auto h = p.GetHealth();
65  const auto pHH = p.GetPoolId(Id::Household);
66  const auto pK12 = p.GetPoolId(Id::K12School);
67  const auto pC = p.GetPoolId(Id::College);
68  const auto pW = p.GetPoolId(Id::Workplace);
69  const auto pPC = p.GetPoolId(Id::PrimaryCommunity);
70  const auto pSC = p.GetPoolId(Id::SecondaryCommunity);
71  logger->info("[PART] {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}", p.GetId(),
72  p.GetAge(), pHH, pK12, pC, pW, h.IsSusceptible(), h.IsInfected(), h.IsInfectious(),
73  h.IsRecovered(), h.IsImmune(), h.GetStartInfectiousness(), h.GetStartSymptomatic(),
74  h.GetEndInfectiousness(), h.GetEndSymptomatic(),
75  poolSys.CRefPools<Id::Household>()[pHH].GetPool().size(),
76  poolSys.CRefPools<Id::K12School>()[pK12].GetPool().size(),
77  poolSys.CRefPools<Id::College>()[pC].GetPool().size(),
78  poolSys.CRefPools<Id::Workplace>()[pW].GetPool().size(),
79  poolSys.CRefPools<Id::PrimaryCommunity>()[pPC].GetPool().size(),
80  poolSys.CRefPools<Id::SecondaryCommunity>()[pSC].GetPool().size());
81 
82  numSamples++;
83  }
84  }
85  return pop;
86 }
87 
88 } // namespace stride
Health & GetHealth()
Return person&#39;s health status.
Definition: Person.h:56
bool IsSurveyParticipant() const
Does this person participates in the social contact study?
Definition: Person.h:71
unsigned int GetPoolId(const ContactType::Id &poolType) const
Get ID of contactpool_type.
Definition: Person.h:65
Utilities for the project.
unsigned int GetId() const
Get the id.
Definition: Person.h:62
const ContactPoolSys & CRefPoolSys() const
The ContactPoolSys of the simulator.
Definition: Population.h:71
STL namespace.
float GetAge() const
Get the age.
Definition: Person.h:53
std::function< int()> GetUniformIntGenerator(int a, int b, unsigned int i=0U)
Return a generator for uniform ints in [a, b[ (a < b) using i-th random stream.
Definition: RnMan.cpp:74
Interface of RnMan.
Key Data structure: container for (a) all individuals in the population (b) the ContactPoolSys wchich...
Definition: Population.h:47
util::RnMan & m_rn_man
Random number manager.
Definition: SurveySeeder.h:51
const boost::property_tree::ptree & m_config
Run config.
Definition: SurveySeeder.h:50
Header file for the SurveySeeder class.
Header file for the core Population class.
std::shared_ptr< spdlog::logger > & RefContactLogger()
Return the contactlogger.
Definition: Population.h:77
std::size_t size() const
Returns the number of elements.
std::shared_ptr< Population > Seed(std::shared_ptr< Population > pop)
Seeds the population with survey participants.
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
void ParticipateInSurvey()
Participate in social contact study and log person details.
Definition: Person.h:74