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.h"
27 #include "abm/location_type.h"
28 #include "abm/parameters.h"
29 #include "abm/person_id.h"
30 #include "abm/personal_rng.h"
32 #include "abm/time.h"
33 #include "abm/test_type.h"
34 #include "abm/protection_event.h"
35 #include "abm/intervention_type.h"
36 #include "abm/mask.h"
37 #include "abm/mobility_data.h"
40 #include <cstdint>
41 
42 namespace mio
43 {
44 namespace abm
45 {
46 
50 class Person
51 {
52 public:
61  explicit Person(mio::RandomNumberGenerator& rng, LocationType location_type, LocationId location_id,
62  int location_model_id, AgeGroup age, PersonId person_id = PersonId::invalid_ID());
63 
64  explicit Person(const Person& other, PersonId person_id);
65 
69  bool operator==(const Person& other) const
70  {
71  return (m_person_id == other.m_person_id);
72  }
73 
79  const Infection& get_infection() const;
80 
86  std::vector<ProtectionEvent>& get_vaccinations()
87  {
88  return m_vaccinations;
89  }
90 
91  const std::vector<ProtectionEvent>& get_vaccinations() const
92  {
93  return m_vaccinations;
94  }
102  bool is_infected(TimePoint t) const;
103 
110 
115  void add_new_infection(Infection&& inf);
116 
122  {
123  return m_age;
124  }
125 
130  LocationId get_location() const;
131 
133  {
134  return m_location_type;
135  }
136 
138  {
139  return m_location_model_id;
140  }
141 
148  void set_location(LocationType type, LocationId id, int model_id);
149 
155  {
156  return m_time_at_location;
157  }
158 
164  {
165  m_time_at_location += dt;
166  }
167 
180  void set_assigned_location(LocationType type, LocationId id, int model_id);
181 
189 
194  const std::vector<LocationId>& get_assigned_locations() const
195  {
196  return m_assigned_locations;
197  }
198 
206 
211  const std::vector<int>& get_assigned_location_model_ids() const
212  {
214  }
215 
224  bool goes_to_work(TimePoint t, const Parameters& params) const;
225 
233  TimeSpan get_go_to_work_time(const Parameters& params) const;
234 
242  bool goes_to_school(TimePoint t, const Parameters& params) const;
243 
251  TimeSpan get_go_to_school_time(const Parameters& params) const;
252 
260  bool is_in_quarantine(TimePoint t, const Parameters& params) const
261  {
263  }
264 
268  void remove_quarantine();
269 
280 
285  PersonId get_id() const;
286 
291  std::vector<uint32_t>& get_cells();
292 
293  const std::vector<uint32_t>& get_cells() const;
294 
300  {
301  return m_mask;
302  }
303 
304  const Mask& get_mask() const
305  {
306  return m_mask;
307  }
308 
316  ScalarType get_mask_protective_factor(const Parameters& params) const;
317 
326  {
327  m_compliance[static_cast<uint32_t>(intervention_type)] = value;
328  }
329 
335  ScalarType get_compliance(InterventionType intervention_type) const
336  {
337  return m_compliance[static_cast<uint32_t>(intervention_type)];
338  }
339 
346  bool is_compliant(PersonalRandomNumberGenerator& rng, InterventionType intervention) const;
347 
353  void set_mask(MaskType type, TimePoint t);
354 
362  ScalarType get_protection_factor(TimePoint t, VirusVariant virus, const Parameters& params) const;
363 
370  {
371  m_vaccinations.push_back(ProtectionEvent(v, t));
372  }
373 
379  {
380  return m_last_transport_mode;
381  }
382 
388  {
389  m_last_transport_mode = mode;
390  }
391 
396  Counter<uint32_t>& get_rng_counter()
397  {
398  return m_rng_counter;
399  }
400 
405  uint32_t get_rng_index()
406  {
407  return m_rng_index;
408  }
409 
414  mio::Key<uint64_t> get_rng_key()
415  {
416  return m_rng_key;
417  }
418 
424 
427  {
428  return Members("Person")
429  .add("location", m_location)
430  .add("location_type", m_location_type)
431  .add("assigned_locations", m_assigned_locations)
432  .add("vaccinations", m_vaccinations)
433  .add("infections", m_infections)
434  .add("home_isolation_start", m_home_isolation_start)
435  .add("age_group", m_age)
436  .add("time_at_location", m_time_at_location)
437  .add("rnd_workgroup", m_random_workgroup)
438  .add("rnd_schoolgroup", m_random_schoolgroup)
439  .add("rnd_go_to_work_hour", m_random_goto_work_hour)
440  .add("rnd_go_to_school_hour", m_random_goto_school_hour)
441  .add("mask", m_mask)
442  .add("compliance", m_compliance)
443  .add("cells", m_cells)
444  .add("last_transport_mode", m_last_transport_mode)
445  .add("rng_counter", m_rng_counter)
446  .add("test_results", m_test_results)
447  .add("id", m_person_id)
448  .add("rng_index", m_rng_index);
449  }
450 
457  void add_test_result(TimePoint t, TestType type, bool result);
458 
465  TestResult get_test_result(TestType type) const;
466 
467 private:
471  std::vector<LocationId> m_assigned_locations;
473  std::vector<ProtectionEvent> m_vaccinations;
474  std::vector<Infection> m_infections;
478  ScalarType
480  ScalarType
485  std::vector<ScalarType>
487  std::vector<uint32_t> m_cells;
490  std::vector<int>
493  mio::Key<uint64_t> m_rng_key;
494  uint32_t m_rng_index;
495  Counter<uint32_t> m_rng_counter{0};
496 };
497 
498 } // namespace abm
499 
501 template <>
502 struct DefaultFactory<abm::Person> {
504  {
506  abm::PersonId());
507  }
508 };
509 
510 } // namespace mio
511 
512 #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:51
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:158
Counter< uint32_t > & get_rng_counter()
Get this persons RandomNumberGenerator counter.
Definition: person.h:396
mio::Key< uint64_t > get_rng_key()
Get this Person's key that is used for the RandomNumberGenerator.
Definition: person.h:414
LocationType m_location_type
Type of the current Location.
Definition: person.h:469
void set_location(LocationType type, LocationId id, int model_id)
Change the location of the person.
Definition: person.cpp:101
int m_location_model_id
Model id of the current Location. Only used for Graph ABM.
Definition: person.h:470
void remove_quarantine()
Removes the quarantine status of the Person.
Definition: person.cpp:163
Infection & get_infection()
Get the latest #Infection of the Person.
Definition: person.cpp:114
uint32_t get_rng_index()
Get this Person's index that is used for the RandomNumberGenerator.
Definition: person.h:405
ScalarType m_random_schoolgroup
Value to determine if the Person goes to school or stays at home during lockdown.
Definition: person.h:481
const std::vector< LocationId > & get_assigned_locations() const
Get the assigned Locations of the Person.
Definition: person.h:194
uint32_t m_rng_index
Index for PersonalRandomNumberGenerator.
Definition: person.h:494
Counter< uint32_t > m_rng_counter
counter for RandomNumberGenerator.
Definition: person.h:495
Mask & get_mask()
Get the current Mask of the Person.
Definition: person.h:299
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:473
const std::vector< ProtectionEvent > & get_vaccinations() const
Get all vaccinations of the Person.
Definition: person.h:91
int get_assigned_location_model_id(LocationType type) const
Returns the model id of an assigned location of the Person.
Definition: person.cpp:130
std::vector< LocationId > m_assigned_locations
Definition: person.h:471
bool is_infected(TimePoint t) const
Returns if the Person is infected at the TimePoint.
Definition: person.cpp:68
std::vector< uint32_t > m_cells
Vector with all Cells the Person visits at its current Location.
Definition: person.h:487
TimeSpan get_time_at_location() const
Get the time the Person has been at its current Location.
Definition: person.h:154
mio::abm::TransportMode get_last_transport_mode() const
Get the transport mode the Person used to get to its current Location.
Definition: person.h:378
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:168
std::vector< ProtectionEvent > & get_vaccinations()
Get all vaccinations of the Person.
Definition: person.h:86
std::vector< Infection > m_infections
Vector with all Infections the Person had.
Definition: person.h:474
TimePoint m_home_isolation_start
TimePoint when the Person started isolation at home.
Definition: person.h:475
ProtectionEvent get_latest_protection(TimePoint t) const
Get the latest ProtectionType and its initial TimePoint of the Person.
Definition: person.cpp:228
const Mask & get_mask() const
Definition: person.h:304
bool is_in_quarantine(TimePoint t, const Parameters &params) const
Answers the question if a Person is currently in quarantine.
Definition: person.h:260
TestResult get_test_result(TestType type) const
Get the most recent TestResult performed from the Person based on the TestType.
Definition: person.cpp:278
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:135
bool operator==(const Person &other) const
Compare two Persons.
Definition: person.h:69
PersonId m_person_id
Unique identifier of a person.
Definition: person.h:492
mio::Key< uint64_t > m_rng_key
Key for PersonalRandomNumberGenerator.
Definition: person.h:493
void add_new_infection(Infection &&inf)
Adds a new Infection to the list of Infections.
Definition: person.cpp:91
AgeGroup get_age() const
Get the AgeGroup of this Person.
Definition: person.h:121
void set_compliance(InterventionType intervention_type, ScalarType value)
For every InterventionType a Person has a compliance value between 0 and 1.
Definition: person.h:325
TimeSpan get_go_to_school_time(const Parameters &params) const
Draw at what time the Person goes to work.
Definition: person.cpp:149
ScalarType get_mask_protective_factor(const Parameters &params) const
Get the protection of the Mask.
Definition: person.cpp:217
ScalarType m_random_goto_work_hour
Value to determine at what time the Person goes to work.
Definition: person.h:482
CustomIndexArray< TestResult, TestType > m_test_results
CustomIndexArray for TestResults.
Definition: person.h:489
bool is_compliant(PersonalRandomNumberGenerator &rng, InterventionType intervention) const
Checks whether the Person complies an Intervention.
Definition: person.cpp:222
ScalarType m_random_workgroup
Value to determine if the Person goes to work or works from home during lockdown.
Definition: person.h:479
InfectionState get_infection_state(TimePoint t) const
Get the InfectionState of the Person at a specific TimePoint.
Definition: person.cpp:81
Mask m_mask
The Mask of the Person.
Definition: person.h:484
AgeGroup m_age
AgeGroup the Person belongs to.
Definition: person.h:476
PersonId get_id() const
Get the PersonId of the Person.
Definition: person.cpp:202
LocationType get_location_type() const
Definition: person.h:132
LocationId get_location() const
Get the current Location of the Person.
Definition: person.cpp:96
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:387
void set_assigned_location(LocationType type, LocationId id, int model_id)
Set an assigned Location of the Person.
Definition: person.cpp:119
int get_location_model_id() const
Definition: person.h:137
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:335
void add_time_at_location(const TimeSpan dt)
Add to the time the Person has been at its current Location.
Definition: person.h:163
ScalarType m_random_goto_school_hour
Value to determine at what time the Person goes to school.
Definition: person.h:483
mio::abm::TransportMode m_last_transport_mode
TransportMode the Person used to get to its current Location.
Definition: person.h:488
std::vector< int > m_assigned_location_model_ids
Vector with model ids of the assigned locations. Only used in graph abm.
Definition: person.h:491
void add_new_vaccination(ProtectionType v, TimePoint t)
Add a new vaccination.
Definition: person.h:369
TimeSpan m_time_at_location
Time the Person has spent at its current Location so far.
Definition: person.h:477
std::vector< uint32_t > & get_cells()
Get index of Cells of the Person.
Definition: person.cpp:207
const std::vector< int > & get_assigned_location_model_ids() const
Get the assigned locations' model ids of the Person.
Definition: person.h:211
void set_mask(MaskType type, TimePoint t)
Change the mask to new type.
Definition: person.cpp:267
LocationId get_assigned_location(LocationType type) const
Returns the index of an assigned Location of the Person.
Definition: person.cpp:125
LocationId m_location
Current Location of the Person.
Definition: person.h:468
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:256
void add_test_result(TimePoint t, TestType type, bool result)
Add TestResult to the Person.
Definition: person.cpp:272
auto default_serialize()
This method is used by the default serialization feature.
Definition: person.h:426
TimeSpan get_go_to_work_time(const Parameters &params) const
Draw at what time the Person goes to work.
Definition: person.cpp:140
std::vector< ScalarType > m_compliance
Vector of compliance values for all InterventionTypes. Values from 0 to 1.
Definition: person.h:486
Random number generator of individual persons.
Definition: personal_rng.h:50
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
The AgeGroup struct is used as a dynamically sized tag for all age dependent categories.
Definition: age_group.h:32
static abm::Person create()
Definition: person.h:503
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