model.h Source File
|
CPP API
|
abm/model.h
Go to the documentation of this file.
4 * Authors: Daniel Abele, Majid Abedi, Elisabeth Kluth, David Kerkmann, Sascha Korf, Martin J. Kuehn, Khoa Nguyen
62 using MobilityRuleType = LocationType (*)(PersonalRandomNumberGenerator&, const Person&, TimePoint, TimeSpan,
135 obj.add_list("activeness_statuses", m_activeness_statuses.begin(), m_activeness_statuses.end());
163 [](auto&& params_, auto&& persons_, auto&& locations_, auto&& activeness_statuses_, auto&& location_types_,
176 params, persons, locations, activeness_statuses, location_types, trip_list, use_mobility_rules, cemetery_id,
277 size_t get_subpopulation_combined_per_location_type(TimePoint t, InfectionState s, LocationType type) const;
420 inline void change_location(PersonId person, LocationId destination, TransportMode mode = TransportMode::Unknown,
446 assert(id < LocationId((uint32_t)m_locations.size()) && "Given LocationId is not in this Model.");
465 assert(id < LocationId((uint32_t)m_locations.size()) && "Given LocationId is not in this Model.");
545 inline void change_location(Person& person, LocationId destination, TransportMode mode = TransportMode::Unknown,
550 const bool has_changed_location = mio::abm::change_location(person, get_location(destination), mode, cells);
551 // if the person has changed location, invalidate exposure caches but keep population caches valid
594 assert(location_id != LocationId::invalid_id() && "The person has no assigned location of that type.");
627 static std::conditional_t<std::is_const_v<M>, const Person&, Person&> get_person_impl(M& m, PersonId person_id)
635 mio::log_warning("get_person is accessed by PersonId which does not align with the index of the person due "
All Locations in the simulated Model where Persons gather.
Definition: location.h:92
LocationId get_id() const
Get the location's identifier in a Model.
Definition: location.h:143
TestingStrategy m_testing_strategy
List of TestingSchemes that are checked for testing.
Definition: abm/model.h:664
Range< ConstPersonIterator > get_persons() const
Get a range of all Persons in the Model.
Definition: abm/model.cpp:356
std::vector< Location >::iterator LocationIterator
Definition: abm/model.h:56
LocationId m_cemetery_id
Current number of Persons in a given location.
Definition: abm/model.h:668
Model(Model &&)=default
std::vector< bool >::const_iterator ConstActivenessIterator
Definition: abm/model.h:61
void interaction(TimePoint t, TimeSpan dt)
Persons interact at their Location and may become infected.
Definition: abm/model.cpp:91
static std::conditional_t< std::is_const_v< M >, const Person &, Person & > get_person_impl(M &m, PersonId person_id)
Implementation of Model::get_person.
Definition: abm/model.h:627
size_t get_number_persons_age(LocationId location, CellIndex cell_idx, AgeGroup age) const
Get the number of Persons of a specific AgeGroup in a specific Cell at the Location.
Definition: abm/model.h:402
TripList m_trip_list
List of all Trips the Persons do.
Definition: abm/model.h:665
const Location & get_location(Person &person) const
Current number of Persons in a given location.
Definition: abm/model.h:580
std::vector< bool > m_activeness_statuses
Vector with activeness status for every person. Is only used for abm graph model or hybrid model.
Definition: abm/model.h:661
void begin_step(TimePoint t, TimeSpan dt)
Prepare the Model for the next Simulation step.
Definition: abm/model.cpp:337
void build_compute_local_population_cache() const
Shape the cache and store how many Persons are at any Location. Use from single thread!
Definition: abm/model.cpp:224
bool m_use_mobility_rules
Whether mobility rules are considered.
Definition: abm/model.h:666
bool m_exposure_caches_need_rebuild
Current number of Persons in a given location.
Definition: abm/model.h:655
std::vector< bool >::iterator ActivenessIterator
Definition: abm/model.h:60
Range< ConstLocationIterator > get_locations() const
Get a range of all Locations in the Model.
Definition: abm/model.cpp:347
bool m_person_ids_equal_index
Current number of Persons in a given location.
Definition: abm/model.h:670
bool has_locations(const C &location_types) const
Check if at least one Location of every specified LocationType exists.
Definition: abm/model.h:312
Location & get_location(LocationId id)
Get a reference to a location in this Model.
Definition: abm/model.h:462
size_t get_subpopulation_combined(TimePoint t, InfectionState s) const
Get the number of Persons in one InfectionState at all Locations.
Definition: abm/model.cpp:381
size_t get_subpopulation(LocationId location, TimePoint t, InfectionState state) const
Get the number of Persons of a particular InfectionState for all Cells.
Definition: abm/model.h:373
uint32_t get_person_index(PersonId person_id) const
Get index of person in m_persons.
Definition: abm/model.h:494
std::vector< Location > m_locations
Vector of every Location.
Definition: abm/model.h:659
bool m_is_local_population_cache_valid
Current number of Persons in a given location.
Definition: abm/model.h:653
std::vector< Location >::const_iterator ConstLocationIterator
Definition: abm/model.h:57
void interact(PersonId person, TimePoint t, TimeSpan dt)
Let a person interact with the population at its current location.
Definition: abm/model.h:432
void assign_location(Person &person, LocationId location)
Assign a Location to a Person.
Definition: abm/model.h:457
TestingStrategy & get_testing_strategy()
Get the TestingStrategy.
Definition: abm/model.cpp:417
Location & get_location(PersonId id)
Get a reference to the location of a person.
Definition: abm/model.h:476
bool m_are_exposure_caches_valid
Current number of Persons in a given location.
Definition: abm/model.h:654
const Person & get_person(PersonId person_id) const
Get a reference to a Person from this Model.
Definition: abm/model.h:356
const Location & get_location(PersonId id) const
Get a reference to the location of a person.
Definition: abm/model.h:481
LocationId find_location(LocationType type, const PersonId person) const
Find an assigned Location of a Person.
Definition: abm/model.cpp:376
Model(size_t num_agegroups, int id=0)
Create a Model.
Definition: abm/model.h:70
Eigen::Matrix< ContactExposureRates, Eigen::Dynamic, 1 > m_contact_exposure_rates_cache
Cache for local exposure through contacts in #transmissions/day.
Definition: abm/model.h:652
bool has_location(LocationType type) const
Check if at least one Location with a specified LocationType exists.
Definition: abm/model.h:300
void perform_mobility(TimePoint t, TimeSpan dt)
Persons change location in the Model according to rules.
Definition: abm/model.cpp:104
std::vector< Person >::iterator PersonIterator
Definition: abm/model.h:58
size_t get_subpopulation_combined_per_location_type(TimePoint t, InfectionState s, LocationType type) const
Get the number of Persons in one InfectionState at all Locations of a type.
Definition: abm/model.cpp:389
Range< ConstActivenessIterator > get_activeness_statuses() const
Get a range of all Persons activeness statuses in the Model.
Definition: abm/model.cpp:366
void build_exposure_caches()
Shape the air and contact exposure cache according to the current Locations.
Definition: abm/model.cpp:260
LocationId add_location(LocationType type, uint32_t num_cells=1)
Add a Location to the Model.
Definition: abm/model.cpp:41
int m_id
Model id. Is only used for abm graph model or hybrid model.
Definition: abm/model.h:657
void evolve(TimePoint t, TimeSpan dt)
Evolve the Model one time step.
Definition: abm/model.cpp:82
Eigen::Matrix< std::atomic_int_fast32_t, Eigen::Dynamic, 1 > m_local_population_cache
Current number of Persons in a given location.
Definition: abm/model.h:646
std::vector< Person >::const_iterator ConstPersonIterator
Definition: abm/model.h:59
LocationType(*)(PersonalRandomNumberGenerator &, const Person &, TimePoint, TimeSpan, const Parameters &) MobilityRuleType
Definition: abm/model.h:63
std::vector< MobilityRuleType > m_mobility_rules
Rules that govern the mobility between Locations.
Definition: abm/model.h:667
static IOResult< Model > deserialize(IOContext &io)
deserialize an object of this class.
Definition: abm/model.h:149
RandomNumberGenerator m_rng
Global random number generator.
Definition: abm/model.h:669
Model & operator=(const Model &)=default
TripList & get_trip_list()
Get the mobility data.
Definition: abm/model.cpp:397
Location & get_location(Person &person)
Get a reference to the location of a person.
Definition: abm/model.h:575
const Location & get_location(LocationId id) const
Get a reference to a location in this Model.
Definition: abm/model.h:443
std::bitset< size_t(LocationType::Count)> m_has_locations
Flags for each LocationType, set if a Location of that type exists.
Definition: abm/model.h:663
void interact(Person &person, TimePoint t, TimeSpan dt)
Let a person interact with the population at its current location.
Definition: abm/model.h:604
void assign_location(PersonId person, LocationId location)
Assign a Location to a Person.
Definition: abm/model.h:259
Eigen::Matrix< PopulationByAge, Eigen::Dynamic, 1 > m_local_population_by_age_cache
Current number of Persons per AgeGroup in a given location.
Definition: abm/model.h:648
LocationId find_location(LocationType type, const Person &person) const
Find an assigned Location of a Person.
Definition: abm/model.h:591
RandomNumberGenerator & get_rng()
Get the RandomNumberGenerator used by this Model for random events.
Definition: abm/model.h:337
Eigen::Matrix< AirExposureRates, Eigen::Dynamic, 1 > m_air_exposure_rates_cache
Cache for local exposure through droplets in #transmissions/day.
Definition: abm/model.h:650
void compute_exposure_caches(TimePoint t, TimeSpan dt)
Store all air/contact exposures for the current simulation step.
Definition: abm/model.cpp:279
void change_location(Person &person, LocationId destination, TransportMode mode=TransportMode::Unknown, const std::vector< uint32_t > &cells={0})
Let a Person change to another Location.
Definition: abm/model.h:545
PersonId add_person(const LocationId id, AgeGroup age)
Add a Person to the Model.
Definition: abm/model.cpp:55
Parameters parameters
The simulation parameters of the Model.
Definition: abm/model.h:330
void change_location(PersonId person, LocationId destination, TransportMode mode=TransportMode::Unknown, const std::vector< uint32_t > &cells={0})
Let a Person change to another Location.
Definition: abm/model.h:420
Model & operator=(Model &&)=default
std::vector< Person > m_persons
Vector of every Person.
Definition: abm/model.h:658
void serialize(IOContext &io) const
serialize this.
Definition: abm/model.h:128
Model(const Parameters ¶ms, int id=0)
Create a Model.
Definition: abm/model.h:85
size_t get_number_persons(LocationId location) const
Get the total number of Persons at the Location.
Definition: abm/model.h:386
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
AgeGroup get_age() const
Get the AgeGroup of this Person.
Definition: person.h:121
LocationId get_location() const
Get the current Location of the Person.
Definition: person.cpp:96
void set_assigned_location(LocationType type, LocationId id, int model_id)
Set an assigned Location of the Person.
Definition: person.cpp:119
std::vector< uint32_t > & get_cells()
Get index of Cells of the Person.
Definition: person.cpp:207
LocationId get_assigned_location(LocationType type) const
Returns the index of an assigned Location of the Person.
Definition: person.cpp:125
Random number generator of individual persons.
Definition: personal_rng.h:50
Set of TestingSchemes that are checked for testing.
Definition: testing_strategy.h:168
static min_max_return_type< ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 >, ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > >::type max(const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &a, const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &b)
Definition: ad.hpp:2596
bool change_location(Person &person, const Location &destination, const TransportMode mode, const std::vector< uint32_t > &cells)
Change a persons location to another location.
Definition: model_functions.cpp:162
void interact(PersonalRandomNumberGenerator &personal_rng, Person &person, const Location &location, const PopulationByAge &local_population_by_age, const AirExposureRates &local_air_exposure, const ContactExposureRates &local_contact_exposure, const TimePoint t, const TimeSpan dt, const Parameters &global_parameters)
Let a Person interact with the population at its current Location, possibly getting infected.
Definition: model_functions.cpp:63
@ Unknown
@ Cemetery
constexpr const int MAX_NUM_AGE_GROUPS
Maximum number of age groups allowed in the model.
Definition: models/abm/config.h:31
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
requires details::IsElementReference< M > RowMajorIterator< M, false > end(M &m)
create a non-const end iterator for the matrix m.
Definition: eigen_util.h:449
boost::outcome_v2::in_place_type_t< T > Tag
Type that is used for overload resolution.
Definition: io.h:407
void log_warning(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:112
details::ApplyResultT< F, T... > apply(IOContext &io, F f, const IOResult< T > &... rs)
Evaluate a function with zero or more unpacked IOResults as arguments.
Definition: io.h:481
void log_error(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:100
void log_debug(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:118
requires details::IsElementReference< M > RowMajorIterator< M, false > begin(M &m)
create a non-const iterator to first element of the matrix m.
Definition: eigen_util.h:421
boost::outcome_v2::unchecked< T, IOStatus > IOResult
Value-or-error type for operations that return a value but can fail.
Definition: io.h:353
The AgeGroup struct is used as a dynamically sized tag for all age dependent categories.
Definition: age_group.h:32
Definition: location.h:37
static const LocationId invalid_id()
Value for invalid IDs.
Definition: location_id.h:48
Generated by