Stride Reference Manual  - generated for commit 9643b11
DiseaseSeeder.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, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #include "DiseaseSeeder.h"
22 
23 #include <boost/optional.hpp>
24 #include "disease/Immunizer.h"
25 #include "pop/Population.h"
26 #include "util/FileSys.h"
27 #include "util/LogUtils.h"
28 #include "util/StringUtils.h"
29 
30 #include <boost/property_tree/ptree.hpp>
31 
32 namespace stride {
33 
34 using namespace boost::property_tree;
35 using namespace stride::ContactType;
36 using namespace stride::util;
37 using namespace std;
38 
39 DiseaseSeeder::DiseaseSeeder(const ptree& config, RnMan& rnMan) : m_config(config), m_rn_man(rnMan) {}
40 
41 void DiseaseSeeder::Seed(std::shared_ptr<Population> pop)
42 {
43  // --------------------------------------------------------------
44  // Population immunity (natural immunity & vaccination).
45  // --------------------------------------------------------------
46  const auto immunityProfile = m_config.get<std::string>("run.immunity_profile");
47  Vaccinate("immunity", immunityProfile, pop, Id::Household);
48 
49  const auto vaccinationProfile = m_config.get<std::string>("run.vaccine_profile");
50  Vaccinate("vaccine", vaccinationProfile, pop, Id::Household);
51 
52  // --------------------------------------------------------------
53  // Seed infected persons.
54  // --------------------------------------------------------------
55  const auto sAgeMin = m_config.get<double>("run.seeding_age_min", 1);
56  const auto sAgeMax = m_config.get<double>("run.seeding_age_max", 99);
57  const auto popSize = pop->size();
58  const auto maxPopIndex = static_cast<int>(popSize - 1);
59  auto generator = m_rn_man.GetUniformIntGenerator(0, maxPopIndex, 0U);
60  auto& logger = pop->RefContactLogger();
61  const string log_level = m_config.get<string>("run.contact_log_level", "None");
62 
63  unsigned int numInfected = 0;
64  boost::optional<float> sRate = m_config.get_optional<float>("run.seeding_rate");
65  if (sRate) {
66  numInfected = static_cast<unsigned int>(floor(static_cast<double>(popSize) * (*sRate)));
67  } else {
68  numInfected = m_config.get<int>("run.num_index_cases");
69  }
70 
71 
72  while (numInfected > 0) {
73  Person& p = pop->at(static_cast<size_t>(generator()));
74  if (p.GetHealth().IsSusceptible() && (p.GetAge() >= sAgeMin) && (p.GetAge() <= sAgeMax)) {
76  numInfected--;
77  if (log_level != "None") {
78  logger->info("[PRIM] {} {} {} {} {} {} {}", p.GetId(), -1, p.GetAge(), -1, -1, -1, p.GetPoolId(ContactType::Id::Household));
79  }
80  }
81  }
82 }
83 
84 void DiseaseSeeder::Vaccinate(const std::string& immunityType, const std::string& immunizationProfile,
85  std::shared_ptr<Population> pop, const ContactType::Id contactPoolType)
86 {
87  std::vector<double> immunityDistribution;
88  double linkProbability = 0;
89  Immunizer immunizer(m_rn_man);
90 
91  if (immunizationProfile == "Random") {
92  const auto immunityLevel = m_config.get<double>("run." + ToLower(immunityType) + "_rate");
93  for (unsigned int index_age = 0; index_age < 100; index_age++) {
94  immunityDistribution.push_back(immunityLevel);
95  }
96  immunizer.Random(pop->CRefPoolSys().CRefPools(contactPoolType), immunityDistribution, linkProbability);
97  } else if (immunizationProfile == "AgeDependent") {
98  const auto immunityFile = m_config.get<string>("run." + ToLower(immunityType) + "_distribution_file");
99  const ptree& immunity_pt = FileSys::ReadPtreeFile(immunityFile);
100 
101  linkProbability = m_config.get<double>("run." + ToLower(immunityType) + "_link_probability");
102  for (unsigned int index_age = 0; index_age < 100; index_age++) {
103  auto immunityLevel = immunity_pt.get<double>("immunity.age" + std::to_string(index_age));
104  immunityDistribution.push_back(immunityLevel);
105  }
106  //immunizer.Random(pop->CRefPoolSys().CRefPools(contactPoolType), immunityDistribution, linkProbability);
107  immunizer.Random(pop, immunityDistribution, contactPoolType, linkProbability);
108 
109  } else if (immunizationProfile == "Cocoon") {
110  immunizer.Cocoon(pop->CRefPoolSys().CRefPools(contactPoolType), immunityDistribution, linkProbability);
111  }
112 }
113 
114 } // namespace stride
Health & GetHealth()
Return person&#39;s health status.
Definition: Person.h:56
Id
Enumerates the ContactPool types.
Definition: ContactType.h:34
const boost::property_tree::ptree & m_config
Run config.
Definition: DiseaseSeeder.h:52
util::RnMan & m_rn_man
Random number manager.
Definition: DiseaseSeeder.h:53
unsigned int GetPoolId(const ContactType::Id &poolType) const
Get ID of contactpool_type.
Definition: Person.h:65
Utilities for the project.
Header for the DiseaseSeeder class.
unsigned int GetId() const
Get the id.
Definition: Person.h:62
static boost::property_tree::ptree ReadPtreeFile(const filesys::path &f_p)
Read ptree from file at path.
Definition: FileSys.cpp:208
STL namespace.
float GetAge() const
Get the age.
Definition: Person.h:53
void Vaccinate(const std::string &immunityType, const std::string &immunizationProfile, std::shared_ptr< Population > pop, const ContactType::Id contactPoolType)
Seed for vaccination/natural immunity.
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
Logging (spdlog) utilities.
void Cocoon(const util::SegmentedVector< ContactPool > &, std::vector< double > &, double)
Cocoon immunization.
Definition: Immunizer.cpp:34
DiseaseSeeder(const boost::property_tree::ptree &config, util::RnMan &rnMan)
Initializing DiseaseSeeder.
Header file for the core Population class.
Deals with immunization strategies.
Definition: Immunizer.h:33
void Random(const util::SegmentedVector< ContactPool > &pools, std::vector< double > &immunityDistribution, double immunityLinkProbability)
Random immunization.
Miscellaneous string utilities.
Interface for install directory queries.
Store and handle person data.
Definition: Person.h:34
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
bool IsSusceptible() const
Is this person susceptible?
Definition: Health.h:77
void Seed(std::shared_ptr< Population > pop)
Build the simulator.
void StartInfection()
Start the infection.
Definition: Health.cpp:35
std::string ToLower(const std::string &source)
Builds a string with lower case characters only.
Definition: StringUtils.h:135
Namespace to manage types of ContactPool.
Definition: ContactType.cpp:28
Header for the Immunizer class.