testing_strategy.h Source File

CPP API: testing_strategy.h Source File
testing_strategy.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Elisabeth Kluth, David Kerkmann, Sascha Korf, Martin J. Kuehn, Khoa Nguyen
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef MIO_ABM_TESTING_SCHEME_H
21 #define MIO_ABM_TESTING_SCHEME_H
22 
23 #include "abm/config.h"
24 #include "abm/location_id.h"
25 #include "abm/location_type.h"
26 #include "abm/parameters.h"
27 #include "abm/person.h"
28 #include "abm/location.h"
29 #include "abm/time.h"
31 
32 #include <bitset>
33 #include <vector>
34 
35 namespace mio
36 {
37 namespace abm
38 {
39 
44 {
45 public:
49  TestingCriteria() = default;
50 
58  TestingCriteria(const std::vector<AgeGroup>& ages, const std::vector<InfectionState>& infection_states);
59 
63  bool operator==(const TestingCriteria& other) const;
64 
70  bool evaluate(const Person& p, TimePoint t) const;
71 
73  {
74  return Members("TestingCriteria").add("ages", m_ages).add("infection_states", m_infection_states);
75  }
76 
77 private:
78  std::bitset<MAX_NUM_AGE_GROUPS> m_ages;
79  std::bitset<(size_t)InfectionState::Count>
82 };
83 
88 {
89 public:
99  TestingScheme(const TestingCriteria& testing_criteria, TimeSpan validity_period, TimePoint start_date,
100  TimePoint end_date, TestParameters test_parameters, ScalarType probability);
101 
105  bool operator==(const TestingScheme& other) const;
106 
111  bool is_active(TimePoint t) const;
112 
120  bool run_and_test(PersonalRandomNumberGenerator& rng, Person& person, TimePoint t) const;
121 
124  {
125  return Members("TestingScheme")
126  .add("criteria", m_testing_criteria)
127  .add("validity_period", m_validity_period)
128  .add("start_date", m_start_date)
129  .add("end_date", m_end_date)
130  .add("test_params", m_test_parameters)
131  .add("probability", m_probability);
132  }
133 
134 private:
136  TestingScheme() = default;
137 
143  {
144  return m_start_date;
145  }
146 
152  {
153  return m_end_date;
154  }
155 
162 };
163 
168 {
169 public:
174  struct LocalStrategy {
175  std::vector<TestingScheme> schemes;
176 
179  {
180  return Members("LocalStrategy").add("schemes", schemes);
181  }
182  };
183 
190  TestingStrategy() = default;
191  explicit TestingStrategy(const std::vector<LocalStrategy>& location_to_schemes_id,
192  const std::vector<LocalStrategy>& location_to_schemes_type);
193 
199  void add_scheme(const LocationId& loc_id, const TestingScheme& scheme);
205  void add_scheme(const LocationType& loc_type, const TestingScheme& scheme);
206 
212  void add_scheme(const std::vector<LocationType>& loc_type, const TestingScheme& scheme)
213  {
214  for (auto& type : loc_type) {
215  add_scheme(type, scheme);
216  }
217  }
218 
228  bool run_and_check(PersonalRandomNumberGenerator& rng, Person& person, const Location& location, TimePoint t);
229 
232  {
233  return Members("TestingStrategy")
234  .add("schemes_id", m_testing_schemes_at_location_id)
235  .add("schemes_type", m_testing_schemes_at_location_type);
236  }
237 
238 private:
239  std::vector<LocalStrategy>
241  std::vector<LocalStrategy>
243 };
244 
245 } // namespace abm
246 } // namespace mio
247 
248 #endif
All Locations in the simulated Model where Persons gather.
Definition: location.h:92
Agents in the simulated Model that can carry and spread the Infection.
Definition: person.h:51
Random number generator of individual persons.
Definition: personal_rng.h:50
TestingCriteria for TestingScheme.
Definition: testing_strategy.h:44
bool evaluate(const Person &p, TimePoint t) const
Check if a Person and a Location meet all the required properties to get tested.
Definition: testing_strategy.cpp:46
TestingCriteria()=default
Create a TestingCriteria where everyone is tested.
std::bitset< MAX_NUM_AGE_GROUPS > m_ages
Set of #AgeGroups that are either allowed or required to be tested.
Definition: testing_strategy.h:78
auto default_serialize()
Definition: testing_strategy.h:72
std::bitset<(size_t) InfectionState::Count > m_infection_states
BitSet of InfectionStates that are either allowed or required to be tested.
Definition: testing_strategy.h:80
bool operator==(const TestingCriteria &other) const
Compares two TestingCriteria for functional equality.
Definition: testing_strategy.cpp:41
TestingScheme to regular test Persons.
Definition: testing_strategy.h:88
TestParameters m_test_parameters
Parameters of the test.
Definition: testing_strategy.h:160
bool run_and_test(PersonalRandomNumberGenerator &rng, Person &person, TimePoint t) const
Runs the TestingScheme and potentially tests a Person.
Definition: testing_strategy.cpp:80
TimeSpan m_validity_period
The valid TimeSpan of the test.
Definition: testing_strategy.h:157
TimePoint m_start_date
Starting date of the scheme.
Definition: testing_strategy.h:158
TestingCriteria m_testing_criteria
TestingCriteria of the scheme.
Definition: testing_strategy.h:156
mio::abm::TimePoint get_end_date() const
Gets the end date of the scheme.
Definition: testing_strategy.h:151
bool operator==(const TestingScheme &other) const
Compares two TestingSchemes for functional equality.
Definition: testing_strategy.cpp:65
TimePoint m_end_date
Ending date of the scheme.
Definition: testing_strategy.h:159
ScalarType m_probability
Probability of performing the test.
Definition: testing_strategy.h:161
auto default_serialize()
This method is used by the default serialization feature.
Definition: testing_strategy.h:123
bool is_active(TimePoint t) const
Gets the activity status of the scheme.
Definition: testing_strategy.cpp:75
mio::abm::TimePoint get_start_date() const
Gets the start date of the scheme.
Definition: testing_strategy.h:142
Set of TestingSchemes that are checked for testing.
Definition: testing_strategy.h:168
bool run_and_check(PersonalRandomNumberGenerator &rng, Person &person, const Location &location, TimePoint t)
Runs the TestingStrategy and potentially tests a Person when entering.
Definition: testing_strategy.cpp:134
std::vector< LocalStrategy > m_testing_schemes_at_location_id
Set of schemes that are checked for testing in specific locations.
Definition: testing_strategy.h:240
TestingStrategy()=default
Create a TestingStrategy.
std::vector< LocalStrategy > m_testing_schemes_at_location_type
Set of schemes that are checked for testing in overall locations types.
Definition: testing_strategy.h:242
void add_scheme(const LocationId &loc_id, const TestingScheme &scheme)
Add a TestingScheme to the set of schemes that are checked for testing at a certain Location for a sp...
Definition: testing_strategy.cpp:118
auto default_serialize()
This method is used by the default serialization feature.
Definition: testing_strategy.h:231
void add_scheme(const std::vector< LocationType > &loc_type, const TestingScheme &scheme)
Add a TestingScheme to the set of schemes that are checked for testing at a certain Location.
Definition: testing_strategy.h:212
Represents a point in time.
Definition: time.h:175
A duration of time.
Definition: time.h:36
double ScalarType
Configuration of memilio library.
Definition: memilio/config.h:30
LocationType
Type of a Location.
Definition: location_type.h:34
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
Creates an instance of T for later initialization.
Definition: default_serialize.h:173
List of a class's members.
Definition: default_serialize.h:113
Members< ValueTypes..., T > add(const char *member_name, T &member)
Add a class member.
Definition: default_serialize.h:139
Unique identifier for a Location within a Model.
Definition: location_id.h:34
Parameters that describe the reliability of a test.
Definition: abm/parameters.h:465
Vector of testing schemes used as an entry for either LocationId or LocationType in TestingStrategy.
Definition: testing_strategy.h:174
std::vector< TestingScheme > schemes
Definition: testing_strategy.h:175
auto default_serialize()
This method is used by the default serialization feature.
Definition: testing_strategy.h:178