Stride Reference Manual  - generated for commit 9643b11
ContactHandler.h
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 #pragma once
22 
23 #include <cmath>
24 #include <functional>
25 
26 namespace stride {
27 
32 {
33 public:
35  explicit ContactHandler(std::function<double()> gen) : m_uniform01_generator(std::move(gen)) {}
36 
38  double operator()() { return m_uniform01_generator(); }
39 
41  bool HasContactAndTransmission(double contact_rate, double transmission_probability)
42  {
43  return m_uniform01_generator() < transmission_probability * RateToProbability(contact_rate);
44  }
45 
47  bool HasContact(double contact_rate) { return m_uniform01_generator() < RateToProbability(contact_rate); }
48 
50  bool HasTransmission(double transmission_probability)
51  {
52  return m_uniform01_generator() < transmission_probability;
53  }
54 
55 private:
57  double RateToProbability(double rate) { return 1.0 - std::exp(-rate); }
58 
59 private:
60  std::function<double()> m_uniform01_generator;
61 };
62 
63 } // namespace stride
bool HasContactAndTransmission(double contact_rate, double transmission_probability)
Check if two individuals have contact and transmission.
bool HasTransmission(double transmission_probability)
Check whether transmission occurs.
Processes the contacts between persons and determines whether transmission occurs.
STL namespace.
double RateToProbability(double rate)
Convert rate into probability.
std::function< double()> m_uniform01_generator
Random number generator: double in [0.0, 1.0)
double operator()()
Make a draw on the uniform generator.
ContactHandler(std::function< double()> gen)
Constructor sets the transmission rate and random number generator.
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
bool HasContact(double contact_rate)
Check if two individuals have contact.