Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
intervention_scenario.h
Go to the documentation of this file.
1 #pragma once
2 #include "scenario.h"
3 
4 #include <optional>
5 #include <vector>
6 
7 namespace hgps {
8 
9 struct PolicyImpact;
10 struct PolicyInterval;
11 struct PolicyDynamic;
12 
20  public:
23  virtual const PolicyInterval &active_period() const noexcept = 0;
24 
27  virtual const std::vector<PolicyImpact> &impacts() const noexcept = 0;
28 
29  ScenarioType type() const noexcept override { return ScenarioType::intervention; }
30 
31  const std::string &name() const noexcept override { return name_; }
32 
33  private:
34  std::string name_{"Intervention"};
35 };
36 
42  public:
45  virtual const PolicyDynamic &dynamic() const noexcept = 0;
46 };
47 
49 struct PolicyImpact {
50  PolicyImpact() = delete;
51 
58  PolicyImpact(core::Identifier risk_factor_key, double policy_impact, unsigned int start_age,
59  std::optional<unsigned int> end_age = std::nullopt)
60  : risk_factor{std::move(risk_factor_key)}, value{policy_impact}, from_age{start_age},
61  to_age{end_age} {
62 
63  if (end_age.has_value() && start_age > end_age.value()) {
64  throw std::out_of_range("Impact end age must be equal or greater than the start age.");
65  }
66  }
67 
69  core::Identifier risk_factor{};
70 
72  double value{};
73 
75  unsigned int from_age{};
76 
78  std::optional<unsigned int> to_age{};
79 
83  bool contains(const unsigned int &age) const noexcept {
84  if (age < from_age) {
85  return false;
86  }
87 
88  if (to_age.has_value()) {
89  return age <= to_age.value();
90  }
91 
92  return true;
93  }
94 };
95 
98 
103  PolicyInterval(int start_at_time, std::optional<int> finish_at_time = std::nullopt)
104  : start_time{start_at_time}, finish_time{finish_at_time} {
105  if (start_at_time < 0) {
106  throw std::out_of_range("Policy start time must not be negative.");
107  }
108 
109  if (finish_at_time.has_value() && start_at_time > finish_at_time.value()) {
110  throw std::out_of_range(
111  "Policy finish time must be equal or greater than the start time.");
112  }
113  }
114 
116  int start_time{};
118  std::optional<int> finish_time{};
119 
123  bool contains(const int &time) const noexcept {
124  if (time < start_time) {
125  return false;
126  }
127 
128  if (finish_time.has_value()) {
129  return time <= finish_time.value();
130  }
131 
132  return true;
133  }
134 };
135 
142  PolicyDynamic(const std::vector<double> &parameters) {
143  if (parameters.size() != size_t{3}) {
144  throw std::invalid_argument(
145  "The vector of dynamic arguments must have size = 3 [alpha, beta, gamma]");
146  }
147 
148  for (const auto &p : parameters) {
149  if (0.0 > p || p > 1.0) {
150  throw std::out_of_range("Dynamic argument: " + std::to_string(p) +
151  ", outside range [0.0, 1.0]");
152  }
153  }
154 
155  alpha = parameters.at(0);
156  beta = parameters.at(1);
157  gamma = parameters.at(2);
158  }
159 
161  double alpha{1.0};
162 
164  double beta{0.0};
165 
167  double gamma{0.0};
168 };
169 } // namespace hgps
Health-GPS dynamic intervention policy scenario interface.
Definition: intervention_scenario.h:41
virtual const PolicyDynamic & dynamic() const noexcept=0
Gets the System Dynamic model parameters.
Health-GPS scripted intervention policy scenario interface.
Definition: intervention_scenario.h:19
ScenarioType type() const noexcept override
Gets the scenario type identifier.
Definition: intervention_scenario.h:29
const std::string & name() const noexcept override
Gets the scenario type name.
Definition: intervention_scenario.h:31
virtual const PolicyInterval & active_period() const noexcept=0
Gets the intervention active period.
virtual const std::vector< PolicyImpact > & impacts() const noexcept=0
Gets the intervention impacts by risk factor and age range.
Health-GPS simulation scenario interface.
Definition: scenario.h:30
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
ScenarioType
Health GPS policy scenario types enumeration.
Definition: scenario.h:17
@ intervention
Intervention scenario.
Global namespace.
Definition: jsonparser.h:88
Defines the policy dynamic parameters.
Definition: intervention_scenario.h:137
PolicyDynamic(const std::vector< double > &parameters)
Initialises a new instance of the PolicyDynamic structure.
Definition: intervention_scenario.h:142
Defines the policy impact on risk factors data structure.
Definition: intervention_scenario.h:49
bool contains(const unsigned int &age) const noexcept
Determine whether this impact should be applied to a given age.
Definition: intervention_scenario.h:83
PolicyImpact(core::Identifier risk_factor_key, double policy_impact, unsigned int start_age, std::optional< unsigned int > end_age=std::nullopt)
Initialise a new instance of the PolicyImpact structure.
Definition: intervention_scenario.h:58
Defines the policy active interval.
Definition: intervention_scenario.h:97
PolicyInterval(int start_at_time, std::optional< int > finish_at_time=std::nullopt)
Initialise a new instance of the PolicyInterval structure.
Definition: intervention_scenario.h:103
bool contains(const int &time) const noexcept
Determine whether this interval contains a given time.
Definition: intervention_scenario.h:123
Entity unique identifier data type.
Definition: identifier.h:17