1 #ifndef UTOPIA_MODELS_CONTDISEASE_PARAMS_HH
2 #define UTOPIA_MODELS_CONTDISEASE_PARAMS_HH
47 "num_additional_infections", cfg, 0)},
49 auto cont = get_as<std::vector<std::size_t>>(
"at_times", cfg, {});
51 std::sort(cont.begin(), cont.end());
55 for (
const auto& v : cont){
61 change_p_infect{[&](){
64 if(cfg[
"change_p_infect"].IsSequence() and cfg[
"change_p_infect"].size() == 0){
66 return TimesValuesQueue{};
69 else if(not cfg[
"change_p_infect"].IsSequence()){
71 throw std::invalid_argument(
"Parameter change_p_infect need be "
72 "a sequence of pairs, but was not a sequence! Given infection "
77 bool pairs_only =
true;
78 for(
const auto pair: cfg[
"change_p_infect"]){
79 pairs_only &= pair.size() == 2;
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"
89 std::vector<std::pair<std::size_t, double>> cont = [&cfg](){
90 std::vector<std::pair<int, double>> val =
91 get_as<std::vector<std::pair<int, double>>>
92 (
"change_p_infect", cfg);
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));
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));
109 return get_as<std::vector<std::pair<std::size_t, double>>>
110 (
"change_p_infect", cfg);
114 std::sort(cont.begin(), cont.end(),
115 [](
const auto& a,
const auto& b){
116 return a.first < b.first;
121 TimesValuesQueue q{};
122 for (
const auto& v : cont){
151 p_growth(
get_as<double>(
"p_growth", cfg)),
152 p_immunity(
get_as<double>(
"p_immunity", cfg)),
153 p_infect(
get_as<double>(
"p_infect", cfg)),
154 infection_control(
get_as<DataIO::
Config>(
"infection_control", cfg))
void for_each(const Utopia::ExecPolicy policy, InputIt first, InputIt last, UnaryFunction f)
Apply a function to a range.
Definition: parallel.hh:346
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition: cfg_utils.hh:158
std::string to_string(const Config &node)
Given a config node, returns a string representation of it.
Definition: cfg_utils.hh:110
Definition: ContDisease.hh:18
DataIO::Config Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:80
Definition: parallel.hh:235
Parameters specifying the infection control.
Definition: params.hh:14
std::queue< std::size_t > TimesQueue
Type of the times queue.
Definition: params.hh:17
InfectionContParams(const DataIO::Config &cfg)
Configuration constructor.
Definition: params.hh:43
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
Parameters of the ContDisease.
Definition: params.hh:133
const double p_growth
Probability per site and time step to go from state empty to tree.
Definition: params.hh:135
const double p_immunity
Definition: params.hh:139
double p_infect
Definition: params.hh:143
const InfectionContParams infection_control
Infection control parameters.
Definition: params.hh:146
Params(const DataIO::Config &cfg)
Construct the parameters from the given configuration node.
Definition: params.hh:149