Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
Utopia::Models::ContDisease::InfectionContParams Struct Reference

Parameters specifying the infection control. More...

#include <params.hh>

Public Types

using TimesQueue = std::queue< std::size_t >
 Type of the times queue.
 
using TimesValuesQueue = std::queue< std::pair< std::size_t, double > >
 The type of the change p_infection pairs.
 

Public Member Functions

 InfectionContParams (const DataIO::Config &cfg)
 Configuration constructor.
 

Public Attributes

const bool enabled
 Whether infection control is enabled.
 
const std::size_t num_additional_infections
 The number of infections added to the default p_infect.
 
TimesQueue at_times
 Add additional infections at these time steps.
 
TimesValuesQueue change_p_infect
 Change p_infect to new value at given times.
 

Detailed Description

Parameters specifying the infection control.

Member Typedef Documentation

◆ TimesQueue

Type of the times queue.

◆ TimesValuesQueue

The type of the change p_infection pairs.

Constructor & Destructor Documentation

◆ InfectionContParams()

Utopia::Models::ContDisease::InfectionContParams::InfectionContParams ( const DataIO::Config cfg)
inline

Configuration constructor.

Construct an InfectionContParams object with required parameters being extracted from a configuration node with the same parameter names.

44 :
45 enabled(get_as<bool>("enabled", cfg)),
47 "num_additional_infections", cfg, 0)},
48 at_times{[&](){
49 auto cont = get_as<std::vector<std::size_t>>("at_times", cfg, {});
50
51 std::sort(cont.begin(), cont.end());
52
53 // Copy elements into the queue
54 TimesQueue q{};
55 for (const auto& v : cont){
56 q.push(v);
57 }
58
59 return q;
60 }()},
61 change_p_infect{[&](){
62 // Check the parameter
63 // For the default case, an empty list, a empty queue is returned.
64 if(cfg["change_p_infect"].IsSequence() and cfg["change_p_infect"].size() == 0){
65 // Key was empty; return empty queue.
66 return TimesValuesQueue{};
67 }
68 // Check if given Parameter is a Sequence
69 else if(not cfg["change_p_infect"].IsSequence()){
70 // Inform about bad type of the given configuration entry
71 throw std::invalid_argument("Parameter change_p_infect need be "
72 "a sequence of pairs, but was not a sequence! Given infection "
73 "control parameters:\n" + DataIO::to_string(cfg));
74 }
75 // Check if it is a sequence that it contains only pairs.
76 else{
77 bool pairs_only = true;
78 for(const auto pair: cfg["change_p_infect"]){
79 pairs_only &= pair.size() == 2;
80 }
81 if(not pairs_only){
82 throw std::invalid_argument("Parameter change_p_infect need be "
83 "a sequence of pairs, but contained something which was not "
84 "a pair! Given infection control parameters:\n"
85 + DataIO::to_string(cfg));
86 }
87 }
88 // Getting the parameters
89 std::vector<std::pair<std::size_t, double>> cont = [&cfg](){
90 std::vector<std::pair<int, double>> val =
92 ("change_p_infect", cfg);
93
94 for_each(val.begin(), val.end(),
95 [&cfg](auto& pair){
96 // Check for negative timesteps
97 if(pair.first < 0){
98 throw std::invalid_argument("Timesteps from parameter "
99 "change_p_infect needs to be larger zero. Given infection "
100 "control parameters:\n" + DataIO::to_string(cfg));
101 }
102 // Check for probabilites outside [0, 1]
103 if(pair.second < 0 or pair.second > 1){
104 throw std::invalid_argument("Infection chance from parameter "
105 "change_p_infect needs to be withhin [0, 1]. Given infection "
106 "control parameters:\n" + DataIO::to_string(cfg));
107 }
108 });
110 ("change_p_infect", cfg);
111 }();
112
113 // Sort such that times low times are in the beginning of the queue
114 std::sort(cont.begin(), cont.end(),
115 [](const auto& a, const auto& b){
116 return a.first < b.first;
117 }
118 );
119
120 // Copy elements into the queue
122 for (const auto& v : cont){
123 q.push(v);
124 }
125
126 return q;
127 }()}
128 {};
void for_each(const Utopia::ExecPolicy policy, InputIt first, InputIt last, UnaryFunction f)
Apply a function to a range.
Definition parallel.hh:346
std::string to_string(const Config &node)
Given a config node, returns a string representation of it.
Definition cfg_utils.hh:110
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
std::queue< std::size_t > TimesQueue
Type of the times queue.
Definition params.hh:17
TimesValuesQueue change_p_infect
Change p_infect to new value at given times.
Definition params.hh:37
std::queue< std::pair< std::size_t, double > > TimesValuesQueue
The type of the change p_infection pairs.
Definition params.hh:20
const std::size_t num_additional_infections
The number of infections added to the default p_infect.
Definition params.hh:27
TimesQueue at_times
Add additional infections at these time steps.
Definition params.hh:30
const bool enabled
Whether infection control is enabled.
Definition params.hh:24

Member Data Documentation

◆ at_times

TimesQueue Utopia::Models::ContDisease::InfectionContParams::at_times
mutable

Add additional infections at these time steps.

◆ change_p_infect

TimesValuesQueue Utopia::Models::ContDisease::InfectionContParams::change_p_infect
mutable

Change p_infect to new value at given times.

Each element of this container provides a pair of [time, new_value]. If the iteration step (time) of the simulation is reached p_infect is set to new_value

◆ enabled

const bool Utopia::Models::ContDisease::InfectionContParams::enabled

Whether infection control is enabled.

◆ num_additional_infections

const std::size_t Utopia::Models::ContDisease::InfectionContParams::num_additional_infections

The number of infections added to the default p_infect.


The documentation for this struct was generated from the following file: