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,
278 size_t get_subpopulation_combined_per_location_type(TimePoint t, InfectionState s, LocationType type) const;
449 inline void change_location(PersonId person, LocationId destination, TransportMode mode = TransportMode::Unknown,
475 assert(id < LocationId((uint32_t)m_locations.size()) && "Given LocationId is not in this Model.");
494 assert(id < LocationId((uint32_t)m_locations.size()) && "Given LocationId is not in this Model.");
574 inline void change_location(Person& person, LocationId destination, TransportMode mode = TransportMode::Unknown,
579 const bool has_changed_location = mio::abm::change_location(person, get_location(destination), mode, cells);
580 // if the person has changed location, invalidate exposure caches but keep population caches valid
623 assert(location_id != LocationId::invalid_id() && "The person has no assigned location of that type.");
656 static std::conditional_t<std::is_const_v<M>, const Person&, Person&> get_person_impl(M& m, PersonId person_id)
664 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:695
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:699
Model(Model &&)=default
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:656
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:431
TripList m_trip_list
List of all Trips the Persons do.
Definition: abm/model.h:696
const Location & get_location(Person &person) const
Current number of Persons in a given location.
Definition: abm/model.h:609
std::vector< char >::iterator ActivenessIterator
Definition: abm/model.h:60
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:697
bool m_exposure_caches_need_rebuild
Current number of Persons in a given location.
Definition: abm/model.h:684
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:701
bool has_locations(const C &location_types) const
Check if at least one Location of every specified LocationType exists.
Definition: abm/model.h:313
Location & get_location(LocationId id)
Get a reference to a location in this Model.
Definition: abm/model.h:491
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:402
uint32_t get_person_index(PersonId person_id) const
Get index of person in m_persons.
Definition: abm/model.h:523
std::vector< Location > m_locations
Vector of every Location.
Definition: abm/model.h:688
bool m_is_local_population_cache_valid
Current number of Persons in a given location.
Definition: abm/model.h:682
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:461
void assign_location(Person &person, LocationId location)
Assign a Location to a Person.
Definition: abm/model.h:486
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:505
bool m_are_exposure_caches_valid
Current number of Persons in a given location.
Definition: abm/model.h:683
const Person & get_person(PersonId person_id) const
Get a reference to a Person from this Model.
Definition: abm/model.h:385
const Location & get_location(PersonId id) const
Get a reference to the location of a person.
Definition: abm/model.h:510
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:681
bool has_location(LocationType type) const
Check if at least one Location with a specified LocationType exists.
Definition: abm/model.h:301
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:686
void evolve(TimePoint t, TimeSpan dt)
Evolve the Model one time step.
Definition: abm/model.cpp:82
void reset_rng(Counter< uint32_t > counter={})
Sets the RNG counters of the model and all persons to 0 (or to the optional counter argument).
Definition: abm/model.h:357
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:675
std::vector< Person >::const_iterator ConstPersonIterator
Definition: abm/model.h:59
std::vector< char >::const_iterator ConstActivenessIterator
Definition: abm/model.h:61
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:698
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:700
Model & operator=(const Model &)=default
std::vector< char > m_activeness_statuses
Vector with activeness status for every person.
Definition: abm/model.h:689
TripList & get_trip_list()
Get the mobility data.
Definition: abm/model.cpp:397
const RandomNumberGenerator & get_rng() const
Get the RandomNumberGenerator used by this Model for random events.
Definition: abm/model.h:343
Location & get_location(Person &person)
Get a reference to the location of a person.
Definition: abm/model.h:604
const Location & get_location(LocationId id) const
Get a reference to a location in this Model.
Definition: abm/model.h:472
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:694
void interact(Person &person, TimePoint t, TimeSpan dt)
Let a person interact with the population at its current location.
Definition: abm/model.h:633
void assign_location(PersonId person, LocationId location)
Assign a Location to a Person.
Definition: abm/model.h:260
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:677
LocationId find_location(LocationType type, const Person &person) const
Find an assigned Location of a Person.
Definition: abm/model.h:620
RandomNumberGenerator & get_rng()
Get the RandomNumberGenerator used by this Model for random events.
Definition: abm/model.h:339
Eigen::Matrix< AirExposureRates, Eigen::Dynamic, 1 > m_air_exposure_rates_cache
Cache for local exposure through droplets in #transmissions/day.
Definition: abm/model.h:679
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:574
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:331
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:449
Model & operator=(Model &&)=default
std::vector< Person > m_persons
Vector of every Person.
Definition: abm/model.h:687
void serialize(IOContext &io) const
serialize this.
Definition: abm/model.h:128
void reset_rng(const std::vector< uint32_t > &seeds, Counter< uint32_t > counter={})
Sets the RNG counters of the model and all persons to 0 (or to the optional counter argument).
Definition: abm/model.h:364
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:415
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
AgeGroup get_age() const
Get the AgeGroup of this Person.
Definition: person.h:120
LocationId get_location() const
Get the current Location of the Person.
Definition: person.cpp:93
void set_assigned_location(LocationType type, LocationId id, int model_id)
Set an assigned Location of the Person.
Definition: person.cpp:116
std::vector< uint32_t > & get_cells()
Get index of Cells of the Person.
Definition: person.cpp:204
LocationId get_assigned_location(LocationType type) const
Returns the index of an assigned Location of the Person.
Definition: person.cpp:122
Random number generator of individual persons.
Definition: personal_rng.h:49
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:408
void log_warning(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:126
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:482
void log_error(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:114
void log_debug(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:132
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:354
Definition: location.h:37
static const LocationId invalid_id()
Value for invalid IDs.
Definition: location_id.h:48
Generated by