person.h Source File

CPP API: person.h Source File
person.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Daniel Abele, Elisabeth Kluth, David Kerkmann, 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_PERSON_H
21 #define MIO_ABM_PERSON_H
22 
23 #include "abm/infection.h"
24 #include "abm/infection_state.h"
25 #include "abm/location_id.h"
26 #include "abm/location_type.h"
27 #include "abm/parameters.h"
28 #include "abm/person_id.h"
29 #include "abm/personal_rng.h"
31 #include "abm/time.h"
32 #include "abm/test_type.h"
33 #include "abm/protection_event.h"
34 #include "abm/intervention_type.h"
35 #include "abm/mask.h"
36 #include "abm/mobility_data.h"
39 #include <cstdint>
40 
41 namespace mio
42 {
43 namespace abm
44 {
45 
49 class Person
50 {
51 public:
60  explicit Person(mio::RandomNumberGenerator& rng, LocationType location_type, LocationId location_id,
61  int location_model_id, AgeGroup age, PersonId person_id = PersonId::invalid_ID());
62 
63  explicit Person(const Person& other, PersonId person_id);
64 
68  bool operator==(const Person& other) const
69  {
70  return (m_person_id == other.m_person_id);
71  }
72 
78  const Infection& get_infection() const;
79 
85  std::vector<ProtectionEvent>& get_vaccinations()
86  {
87  return m_vaccinations;
88  }
89 
90  const std::vector<ProtectionEvent>& get_vaccinations() const
91  {
92  return m_vaccinations;
93  }
101  bool is_infected(TimePoint t) const;
102 
109 
114  void add_new_infection(Infection&& inf);
115 
121  {
122  return m_age;
123  }
124 
129  LocationId get_location() const;
130 
132  {
133  return m_location_type;
134  }
135 
137  {
138  return m_location_model_id;
139  }
140 
147  void set_location(LocationType type, LocationId id, int model_id);
148 
154  {
155  return m_time_at_location;
156  }
157 
163  {
164  m_time_at_location += dt;
165  }
166 
179  void set_assigned_location(LocationType type, LocationId id, int model_id);
180 
188 
193  const std::vector<LocationId>& get_assigned_locations() const
194  {
195  return m_assigned_locations;
196  }
197 
205 
210  const std::vector<int>& get_assigned_location_model_ids() const
211  {
213  }
214 
223  bool goes_to_work(TimePoint t, const Parameters& params) const;
224 
232  TimeSpan get_go_to_work_time(const Parameters& params) const;
233 
241  bool goes_to_school(TimePoint t, const Parameters& params) const;
242 
250  TimeSpan get_go_to_school_time(const Parameters& params) const;
251 
259  bool is_in_quarantine(TimePoint t, const Parameters& params) const
260  {
262  }
263 
267  void remove_quarantine();
268 
279 
284  PersonId get_id() const;
285 
290  std::vector<uint32_t>& get_cells();
291 
292  const std::vector<uint32_t>& get_cells() const;
293 
299  {
300  return m_mask;
301  }
302 
303  const Mask& get_mask() const
304  {
305  return m_mask;
306  }
307 
315  ScalarType get_mask_protective_factor(const Parameters& params) const;
316 
325  {
326  m_compliance[static_cast<uint32_t>(intervention_type)] = value;
327  }
328 
334  ScalarType get_compliance(InterventionType intervention_type) const
335  {
336  return m_compliance[static_cast<uint32_t>(intervention_type)];
337  }
338 
345  bool is_compliant(PersonalRandomNumberGenerator& rng, InterventionType intervention) const;
346 
352  void set_mask(MaskType type, TimePoint t);
353 
361  ScalarType get_protection_factor(TimePoint t, VirusVariant virus, const Parameters& params) const;
362 
369  {
370  m_vaccinations.push_back(ProtectionEvent(v, t));
371  }
372 
378  {
379  return m_last_transport_mode;
380  }
381 
387  {
388  m_last_transport_mode = mode;
389  }
390 
395  Counter<uint32_t>& get_rng_counter()
396  {
397  return m_rng_counter;
398  }
399 
405 
408  {
409  return Members("Person")
410  .add("location", m_location)
411  .add("location_type", m_location_type)
412  .add("assigned_locations", m_assigned_locations)
413  .add("vaccinations", m_vaccinations)
414  .add("infections", m_infections)
415  .add("home_isolation_start", m_home_isolation_start)
416  .add("age_group", m_age)
417  .add("time_at_location", m_time_at_location)
418  .add("rnd_workgroup", m_random_workgroup)
419  .add("rnd_schoolgroup", m_random_schoolgroup)
420  .add("rnd_go_to_work_hour", m_random_goto_work_hour)
421  .add("rnd_go_to_school_hour", m_random_goto_school_hour)
422  .add("mask", m_mask)
423  .add("compliance", m_compliance)
424  .add("cells", m_cells)
425  .add("last_transport_mode", m_last_transport_mode)
426  .add("rng_counter", m_rng_counter)
427  .add("test_results", m_test_results)
428  .add("id", m_person_id);
429  }
430 
437  void add_test_result(TimePoint t, TestType type, bool result);
438 
445  TestResult get_test_result(TestType type) const;
446 
447 private:
451  std::vector<LocationId> m_assigned_locations;
453  std::vector<ProtectionEvent> m_vaccinations;
454  std::vector<Infection> m_infections;
458  ScalarType
460  ScalarType
465  std::vector<ScalarType>
467  std::vector<uint32_t> m_cells;
470  std::vector<int>
473  Counter<uint32_t> m_rng_counter{0};
474 };
475 
476 } // namespace abm
477 
479 template <>
480 struct DefaultFactory<abm::Person> {
482  {
484  abm::PersonId());
485  }
486 };
487 
488 } // namespace mio
489 
490 #endif
A class template for an array with custom indices.
Definition: custom_index_array.h:136
const ParameterTagTraits< Tag >::Type & get() const
get value of a parameter
Definition: parameter_set.h:262
Definition: infection.h:78
Reduces the probability that a Person becomes infected.
Definition: mask.h:37
Parameters of the simulation that are the same everywhere within the Model.
Definition: abm/parameters.h:764
Agents in the simulated Model that can carry and spread the Infection.
Definition: person.h:50
bool goes_to_school(TimePoint t, const Parameters &params) const
Draw if the Person goes to school or stays at home during lockdown.
Definition: person.cpp:155
Counter< uint32_t > & get_rng_counter()
Get this persons RandomNumberGenerator counter.
Definition: person.h:395
LocationType m_location_type
Type of the current Location.
Definition: person.h:449
void set_location(LocationType type, LocationId id, int model_id)
Change the location of the person.
Definition: person.cpp:98
int m_location_model_id
Model id of the current Location. Only used for Graph ABM.
Definition: person.h:450
void remove_quarantine()
Removes the quarantine status of the Person.
Definition: person.cpp:160
Infection & get_infection()
Get the latest #Infection of the Person.
Definition: person.cpp:111
ScalarType m_random_schoolgroup
Value to determine if the Person goes to school or stays at home during lockdown.
Definition: person.h:461
const std::vector< LocationId > & get_assigned_locations() const
Get the assigned Locations of the Person.
Definition: person.h:193
Counter< uint32_t > m_rng_counter
counter for RandomNumberGenerator.
Definition: person.h:473
Mask & get_mask()
Get the current Mask of the Person.
Definition: person.h:298
std::vector< ProtectionEvent > m_vaccinations
! Vector with the indices of the assigned Locations so that the Person always visits the same Home or...
Definition: person.h:453
const std::vector< ProtectionEvent > & get_vaccinations() const
Get all vaccinations of the Person.
Definition: person.h:90
int get_assigned_location_model_id(LocationType type) const
Returns the model id of an assigned location of the Person.
Definition: person.cpp:127
std::vector< LocationId > m_assigned_locations
Definition: person.h:451
bool is_infected(TimePoint t) const
Returns if the Person is infected at the TimePoint.
Definition: person.cpp:65
std::vector< uint32_t > m_cells
Vector with all Cells the Person visits at its current Location.
Definition: person.h:467
TimeSpan get_time_at_location() const
Get the time the Person has been at its current Location.
Definition: person.h:153
mio::abm::TransportMode get_last_transport_mode() const
Get the transport mode the Person used to get to its current Location.
Definition: person.h:377
bool get_tested(PersonalRandomNumberGenerator &rng, TimePoint t, const TestParameters &params)
Simulates a viral test and returns the test result of the Person.
Definition: person.cpp:165
std::vector< ProtectionEvent > & get_vaccinations()
Get all vaccinations of the Person.
Definition: person.h:85
std::vector< Infection > m_infections
Vector with all Infections the Person had.
Definition: person.h:454
TimePoint m_home_isolation_start
TimePoint when the Person started isolation at home.
Definition: person.h:455
ProtectionEvent get_latest_protection(TimePoint t) const
Get the latest ProtectionType and its initial TimePoint of the Person.
Definition: person.cpp:225
const Mask & get_mask() const
Definition: person.h:303
bool is_in_quarantine(TimePoint t, const Parameters &params) const
Answers the question if a Person is currently in quarantine.
Definition: person.h:259
TestResult get_test_result(TestType type) const
Get the most recent TestResult performed from the Person based on the TestType.
Definition: person.cpp:275
bool goes_to_work(TimePoint t, const Parameters &params) const
Draw if the Person goes to work or is in home office during lockdown at a specific TimePoint.
Definition: person.cpp:132
bool operator==(const Person &other) const
Compare two Persons.
Definition: person.h:68
PersonId m_person_id
Unique identifier of a person.
Definition: person.h:472
void add_new_infection(Infection &&inf)
Adds a new Infection to the list of Infections.
Definition: person.cpp:88
AgeGroup get_age() const
Get the AgeGroup of this Person.
Definition: person.h:120
void set_compliance(InterventionType intervention_type, ScalarType value)
For every InterventionType a Person has a compliance value between 0 and 1.
Definition: person.h:324
TimeSpan get_go_to_school_time(const Parameters &params) const
Draw at what time the Person goes to work.
Definition: person.cpp:146
ScalarType get_mask_protective_factor(const Parameters &params) const
Get the protection of the Mask.
Definition: person.cpp:214
ScalarType m_random_goto_work_hour
Value to determine at what time the Person goes to work.
Definition: person.h:462
CustomIndexArray< TestResult, TestType > m_test_results
CustomIndexArray for TestResults.
Definition: person.h:469
bool is_compliant(PersonalRandomNumberGenerator &rng, InterventionType intervention) const
Checks whether the Person complies an Intervention.
Definition: person.cpp:219
ScalarType m_random_workgroup
Value to determine if the Person goes to work or works from home during lockdown.
Definition: person.h:459
InfectionState get_infection_state(TimePoint t) const
Get the InfectionState of the Person at a specific TimePoint.
Definition: person.cpp:78
Mask m_mask
The Mask of the Person.
Definition: person.h:464
AgeGroup m_age
AgeGroup the Person belongs to.
Definition: person.h:456
PersonId get_id() const
Get the PersonId of the Person.
Definition: person.cpp:199
LocationType get_location_type() const
Definition: person.h:131
LocationId get_location() const
Get the current Location of the Person.
Definition: person.cpp:93
void set_last_transport_mode(const mio::abm::TransportMode mode)
Set the transport mode the Person used to get to its current Location.
Definition: person.h:386
void set_assigned_location(LocationType type, LocationId id, int model_id)
Set an assigned Location of the Person.
Definition: person.cpp:116
int get_location_model_id() const
Definition: person.h:136
Person(mio::RandomNumberGenerator &rng, LocationType location_type, LocationId location_id, int location_model_id, AgeGroup age, PersonId person_id=PersonId::invalid_ID())
Create a Person.
Definition: person.cpp:36
ScalarType get_compliance(InterventionType intervention_type) const
Get the compliance of the Person for an Intervention.
Definition: person.h:334
void add_time_at_location(const TimeSpan dt)
Add to the time the Person has been at its current Location.
Definition: person.h:162
ScalarType m_random_goto_school_hour
Value to determine at what time the Person goes to school.
Definition: person.h:463
mio::abm::TransportMode m_last_transport_mode
TransportMode the Person used to get to its current Location.
Definition: person.h:468
std::vector< int > m_assigned_location_model_ids
Vector with model ids of the assigned locations. Only used in graph abm.
Definition: person.h:471
void add_new_vaccination(ProtectionType v, TimePoint t)
Add a new vaccination.
Definition: person.h:368
TimeSpan m_time_at_location
Time the Person has spent at its current Location so far.
Definition: person.h:457
std::vector< uint32_t > & get_cells()
Get index of Cells of the Person.
Definition: person.cpp:204
const std::vector< int > & get_assigned_location_model_ids() const
Get the assigned locations' model ids of the Person.
Definition: person.h:210
void set_mask(MaskType type, TimePoint t)
Change the mask to new type.
Definition: person.cpp:264
LocationId get_assigned_location(LocationType type) const
Returns the index of an assigned Location of the Person.
Definition: person.cpp:122
LocationId m_location
Current Location of the Person.
Definition: person.h:448
ScalarType get_protection_factor(TimePoint t, VirusVariant virus, const Parameters &params) const
Get the multiplicative factor on how likely an #Infection is due to the immune system.
Definition: person.cpp:253
void add_test_result(TimePoint t, TestType type, bool result)
Add TestResult to the Person.
Definition: person.cpp:269
auto default_serialize()
This method is used by the default serialization feature.
Definition: person.h:407
TimeSpan get_go_to_work_time(const Parameters &params) const
Draw at what time the Person goes to work.
Definition: person.cpp:137
std::vector< ScalarType > m_compliance
Vector of compliance values for all InterventionTypes. Values from 0 to 1.
Definition: person.h:466
Random number generator of individual persons.
Definition: personal_rng.h:49
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
trait_value< T >::RETURN_TYPE & value(T &x)
Definition: ad.hpp:3308
ProtectionType
ProtectionType in ABM.
Definition: protection_event.h:38
InterventionType
Type of an Intervention.
Definition: intervention_type.h:35
TransportMode
Mode of Transport.
Definition: mobility_data.h:35
LocationType
Type of a Location.
Definition: location_type.h:34
VirusVariant
Virus variants in ABM.
Definition: virus_variant.h:38
TestType
Type of a Test.
Definition: test_type.h:37
InfectionState
InfectionState in ABM.
Definition: abm/infection_state.h:35
MaskType
Type of a Mask.
Definition: mask_type.h:35
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
RandomNumberGenerator & thread_local_rng()
Definition: random_number_generator.cpp:25
Typesafe index representing an age group.
Definition: age_group.h:40
static abm::Person create()
Definition: person.h:481
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
Unique ID for a Person within a Model.
Definition: person_id.h:33
static const PersonId invalid_ID()
Value for invalid IDs.
Definition: person_id.h:47
A tuple of ProtectionType and #TimePoint.
Definition: protection_event.h:49
Duration of quarantine.
Definition: abm/parameters.h:519
Parameters that describe the reliability of a test.
Definition: abm/parameters.h:465
The TestResult of a Person.
Definition: test_type.h:48