Model Class Reference
|
CPP API
|
The Model of the Simulation. More...
#include <model.h>
Public Types | |
| using | ActivenessIterator = std::vector< bool >::iterator |
| using | Compartments = mio::abm::InfectionState |
| using | ConstActivenessIterator = std::vector< bool >::const_iterator |
| using | ConstLocationIterator = std::vector< Location >::const_iterator |
| using | ConstPersonIterator = std::vector< Person >::const_iterator |
| using | LocationIterator = std::vector< Location >::iterator |
| using | MobilityRuleType = LocationType(*)(PersonalRandomNumberGenerator &, const Person &, TimePoint, TimeSpan, const Parameters &) |
| using | PersonIterator = std::vector< Person >::iterator |
Public Member Functions | |
| LocationId | add_location (LocationType type, uint32_t num_cells=1) |
| Add a Location to the Model. More... | |
| PersonId | add_person (const LocationId id, AgeGroup age) |
| Add a Person to the Model. More... | |
| PersonId | add_person (Person &&person) |
| Adds a copy of a given Person to the Model. More... | |
| void | assign_location (PersonId person, LocationId location) |
| Assign a Location to a Person. More... | |
| void | begin_step (TimePoint t, TimeSpan dt) |
| Prepare the Model for the next Simulation step. More... | |
| 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. More... | |
| void | evolve (TimePoint t, TimeSpan dt) |
| Evolve the Model one time step. More... | |
| LocationId | find_location (LocationType type, const PersonId person) const |
| Find an assigned Location of a Person. More... | |
| int | get_id () const |
| Get the model id. More... | |
| size_t | get_number_persons (LocationId location) const |
| Get the total number of Persons at the Location. More... | |
| 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. More... | |
| Person & | get_person (PersonId person_id) |
| const Person & | get_person (PersonId person_id) const |
| Get a reference to a Person from this Model. More... | |
| RandomNumberGenerator & | get_rng () |
| Get the RandomNumberGenerator used by this Model for random events. More... | |
| size_t | get_subpopulation (LocationId location, TimePoint t, InfectionState state) const |
| Get the number of Persons of a particular InfectionState for all Cells. More... | |
| size_t | get_subpopulation_combined (TimePoint t, InfectionState s) const |
| Get the number of Persons in one InfectionState at all Locations. More... | |
| 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. More... | |
| TestingStrategy & | get_testing_strategy () |
| Get the TestingStrategy. More... | |
| const TestingStrategy & | get_testing_strategy () const |
| TripList & | get_trip_list () |
| Get the mobility data. More... | |
| const TripList & | get_trip_list () const |
| bool | has_location (LocationType type) const |
| Check if at least one Location with a specified LocationType exists. More... | |
| template<class C = std::initializer_list<LocationType>> | |
| bool | has_locations (const C &location_types) const |
| Check if at least one Location of every specified LocationType exists. More... | |
| void | interact (PersonId person, TimePoint t, TimeSpan dt) |
| Let a person interact with the population at its current location. More... | |
| Model (const Model &other, int id=0) | |
| Model (const Parameters ¶ms, int id=0) | |
| Create a Model. More... | |
| Model (Model &&)=default | |
| Model (size_t num_agegroups, int id=0) | |
| Create a Model. More... | |
| Model & | operator= (const Model &)=default |
| Model & | operator= (Model &&)=default |
| template<class IOContext > | |
| void | serialize (IOContext &io) const |
| serialize this. More... | |
| bool | use_mobility_rules () const |
| void | use_mobility_rules (bool param) |
| Decide if mobility rules (like go to school/work) are used or not; The mobility rules regarding hospitalization/ICU/quarantine are always used. More... | |
| Range< ConstLocationIterator > | get_locations () const |
| Get a range of all Locations in the Model. More... | |
| Range< LocationIterator > | get_locations () |
| Get a range of all Locations in the Model. More... | |
| Range< ConstPersonIterator > | get_persons () const |
| Get a range of all Persons in the Model. More... | |
| Range< PersonIterator > | get_persons () |
| Get a range of all Persons in the Model. More... | |
| Range< ConstActivenessIterator > | get_activeness_statuses () const |
| Get a range of all Persons activeness statuses in the Model. More... | |
| Range< ActivenessIterator > | get_activeness_statuses () |
| Get a range of all Persons activeness statuses in the Model. More... | |
| const Location & | get_location (LocationId id) const |
| Get a reference to a location in this Model. More... | |
| void | assign_location (Person &person, LocationId location) |
| Assign a Location to a Person. More... | |
| Location & | get_location (LocationId id) |
| Get a reference to a location in this Model. More... | |
| Location & | get_location (PersonId id) |
| Get a reference to the location of a person. More... | |
| const Location & | get_location (PersonId id) const |
| Get a reference to the location of a person. More... | |
Static Public Member Functions | |
| template<class IOContext > | |
| static IOResult< Model > | deserialize (IOContext &io) |
| deserialize an object of this class. More... | |
Public Attributes | |
| Parameters | parameters |
| The simulation parameters of the Model. More... | |
| Eigen::Matrix< std::atomic_int_fast32_t, Eigen::Dynamic, 1 > | m_local_population_cache |
| Current number of Persons in a given location. More... | |
| Eigen::Matrix< PopulationByAge, Eigen::Dynamic, 1 > | m_local_population_by_age_cache |
| Current number of Persons per AgeGroup in a given location. More... | |
| Eigen::Matrix< AirExposureRates, Eigen::Dynamic, 1 > | m_air_exposure_rates_cache |
| Cache for local exposure through droplets in #transmissions/day. More... | |
| Eigen::Matrix< ContactExposureRates, Eigen::Dynamic, 1 > | m_contact_exposure_rates_cache |
| Cache for local exposure through contacts in #transmissions/day. More... | |
| bool | m_is_local_population_cache_valid = false |
| Current number of Persons in a given location. More... | |
| bool | m_are_exposure_caches_valid = false |
| Current number of Persons in a given location. More... | |
| bool | m_exposure_caches_need_rebuild = true |
| Current number of Persons in a given location. More... | |
| int | m_id |
| Model id. Is only used for abm graph model or hybrid model. More... | |
| std::vector< Person > | m_persons |
| Vector of every Person. More... | |
| std::vector< Location > | m_locations |
| Vector of every Location. More... | |
| std::vector< bool > | m_activeness_statuses |
| Vector with activeness status for every person. Is only used for abm graph model or hybrid model. More... | |
| std::bitset< size_t(LocationType::Count)> | m_has_locations |
| Flags for each LocationType, set if a Location of that type exists. More... | |
| TestingStrategy | m_testing_strategy |
| List of TestingSchemes that are checked for testing. More... | |
| TripList | m_trip_list |
| List of all Trips the Persons do. More... | |
| bool | m_use_mobility_rules |
| Whether mobility rules are considered. More... | |
| std::vector< MobilityRuleType > | m_mobility_rules |
| Rules that govern the mobility between Locations. More... | |
| LocationId | m_cemetery_id |
| Current number of Persons in a given location. More... | |
| RandomNumberGenerator | m_rng |
| Global random number generator. More... | |
| bool | m_person_ids_equal_index |
| Current number of Persons in a given location. More... | |
| uint32_t | get_person_index (PersonId person_id) const |
| Get index of person in m_persons. More... | |
| void | interaction (TimePoint t, TimeSpan dt) |
| Persons interact at their Location and may become infected. More... | |
| void | perform_mobility (TimePoint t, TimeSpan dt) |
| Persons change location in the Model according to rules. More... | |
| void | build_compute_local_population_cache () const |
| Shape the cache and store how many Persons are at any Location. Use from single thread! More... | |
| void | build_exposure_caches () |
| Shape the air and contact exposure cache according to the current Locations. More... | |
| void | compute_exposure_caches (TimePoint t, TimeSpan dt) |
| Store all air/contact exposures for the current simulation step. More... | |
| 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. More... | |
| Location & | get_location (Person &person) |
| Get a reference to the location of a person. More... | |
| const Location & | get_location (Person &person) const |
| Current number of Persons in a given location. More... | |
| LocationId | find_location (LocationType type, const Person &person) const |
| Find an assigned Location of a Person. More... | |
| void | interact (Person &person, TimePoint t, TimeSpan dt) |
| Let a person interact with the population at its current location. More... | |
| template<class M > | |
| 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. More... | |
Detailed Description
The Model of the Simulation.
Member Typedef Documentation
◆ ActivenessIterator
| using mio::abm::Model::ActivenessIterator = std::vector<bool>::iterator |
◆ Compartments
◆ ConstActivenessIterator
| using mio::abm::Model::ConstActivenessIterator = std::vector<bool>::const_iterator |
◆ ConstLocationIterator
| using mio::abm::Model::ConstLocationIterator = std::vector<Location>::const_iterator |
◆ ConstPersonIterator
| using mio::abm::Model::ConstPersonIterator = std::vector<Person>::const_iterator |
◆ LocationIterator
| using mio::abm::Model::LocationIterator = std::vector<Location>::iterator |
◆ MobilityRuleType
| using mio::abm::Model::MobilityRuleType = LocationType (*)(PersonalRandomNumberGenerator&, const Person&, TimePoint, TimeSpan, const Parameters&) |
◆ PersonIterator
| using mio::abm::Model::PersonIterator = std::vector<Person>::iterator |
Constructor & Destructor Documentation
◆ Model() [1/4]
|
inline |
◆ Model() [2/4]
|
inline |
Create a Model.
- Parameters
-
[in] params Initial simulation parameters.
◆ Model() [3/4]
|
inline |
◆ Model() [4/4]
|
default |
Member Function Documentation
◆ add_location()
| LocationId mio::abm::Model::add_location | ( | LocationType | type, |
| uint32_t | num_cells = 1 |
||
| ) |
◆ add_person() [1/2]
| PersonId mio::abm::Model::add_person | ( | const LocationId | id, |
| AgeGroup | age | ||
| ) |
◆ add_person() [2/2]
◆ assign_location() [1/2]
|
inline |
Assign a Location to a Person.
A Person can have at most one assigned Location of a certain LocationType. Assigning another Location of an already assigned LocationType will replace the prior assignment.
- Parameters
-
[in] person reference to the Person the location will be assigned to. [in] location The LocationId of the Location.
◆ assign_location() [2/2]
|
inline |
Assign a Location to a Person.
A Person can have at most one assigned Location of a certain LocationType. Assigning another Location of an already assigned LocationType will replace the prior assignment.
- Parameters
-
[in] person The Id of the person this location will be assigned to. [in] location The LocationId of the Location.
◆ begin_step()
Prepare the Model for the next Simulation step.
- Parameters
-
[in] t Current time. [in] dt Length of the time step.
◆ build_compute_local_population_cache()
|
protected |
◆ build_exposure_caches()
|
protected |
Shape the air and contact exposure cache according to the current Locations.
◆ change_location() [1/2]
|
inlineprotected |
◆ change_location() [2/2]
|
inline |
◆ compute_exposure_caches()
Store all air/contact exposures for the current simulation step.
This will also compute the local population cache if it is not valid, as it is required for the computation of the exposure rates.
- Parameters
-
[in] t Current TimePoint of the simulation. [in] dt The duration of the simulation step.
◆ deserialize()
|
inlinestatic |
deserialize an object of this class.
- See also
- mio::deserialize
◆ evolve()
Evolve the Model one time step.
- Parameters
-
[in] t Current time. [in] dt Length of the time step.
◆ find_location() [1/2]
|
inlineprotected |
◆ find_location() [2/2]
| LocationId mio::abm::Model::find_location | ( | LocationType | type, |
| const PersonId | person | ||
| ) | const |
◆ get_activeness_statuses() [1/2]
| auto mio::abm::Model::get_activeness_statuses | ( | ) |
◆ get_activeness_statuses() [2/2]
| auto mio::abm::Model::get_activeness_statuses | ( | ) | const |
◆ get_id()
|
inline |
Get the model id.
Is only relevant for graph abm or hybrid model.
- Returns
- The model id
◆ get_location() [1/6]
|
inline |
Get a reference to a location in this Model.
- Parameters
-
[in] id LocationId of the Location.
- Returns
- Reference to the Location.
◆ get_location() [2/6]
|
inline |
Get a reference to a location in this Model.
- Parameters
-
[in] id LocationId of the Location.
- Returns
- Reference to the Location.
◆ get_location() [3/6]
◆ get_location() [4/6]
Current number of Persons in a given location.
◆ get_location() [5/6]
Get a reference to the location of a person.
- Parameters
-
[in] id Id of a person.
- Returns
- Reference to the Location.
◆ get_location() [6/6]
Get a reference to the location of a person.
- Parameters
-
[in] id Id of a person.
- Returns
- Reference to the Location.
◆ get_locations() [1/2]
| auto mio::abm::Model::get_locations | ( | ) |
◆ get_locations() [2/2]
| auto mio::abm::Model::get_locations | ( | ) | const |
◆ get_number_persons()
|
inline |
Get the total number of Persons at the Location.
- Parameters
-
[in] location A LocationId from the Model.
- Returns
- Number of Persons at the location.
◆ get_number_persons_age()
|
inline |
◆ get_person() [1/2]
◆ get_person() [2/2]
◆ get_person_impl()
|
inlinestaticprotected |
Implementation of Model::get_person.
This function needs to use a template to deduce whether the model and returned person should be const.
- Returns
- A reference to the Person with matching ID.
◆ get_person_index()
|
inline |
◆ get_persons() [1/2]
| auto mio::abm::Model::get_persons | ( | ) |
◆ get_persons() [2/2]
| auto mio::abm::Model::get_persons | ( | ) | const |
◆ get_rng()
|
inline |
Get the RandomNumberGenerator used by this Model for random events.
Persons use their own generators with the same key as the global one.
- Returns
- The random number generator.
◆ get_subpopulation()
|
inline |
Get the number of Persons of a particular InfectionState for all Cells.
- Parameters
-
[in] location A LocationId from the Model. [in] t TimePoint of querry. [in] state InfectionState of interest.
- Returns
- Amount of Persons of the InfectionState in all Cells of the Location.
◆ get_subpopulation_combined()
| size_t mio::abm::Model::get_subpopulation_combined | ( | TimePoint | t, |
| InfectionState | s | ||
| ) | const |
Get the number of Persons in one InfectionState at all Locations.
- Parameters
-
[in] t Specified #TimePoint. [in] s Specified InfectionState.
◆ get_subpopulation_combined_per_location_type()
| size_t mio::abm::Model::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.
- Parameters
-
[in] t Specified #TimePoint. [in] s Specified InfectionState. [in] type Specified LocationType.
◆ get_testing_strategy() [1/2]
| TestingStrategy & mio::abm::Model::get_testing_strategy | ( | ) |
Get the TestingStrategy.
- Returns
- Reference to the list of TestingSchemes that are checked for testing.
◆ get_testing_strategy() [2/2]
| const TestingStrategy & mio::abm::Model::get_testing_strategy | ( | ) | const |
◆ get_trip_list() [1/2]
| TripList & mio::abm::Model::get_trip_list | ( | ) |
◆ get_trip_list() [2/2]
| const TripList & mio::abm::Model::get_trip_list | ( | ) | const |
◆ has_location()
|
inline |
◆ has_locations()
|
inline |
◆ interact() [1/2]
Let a person interact with the population at its current location.
- Parameters
-
[in] person Reference to Person. [in] t Time step of the simulation. [in] dt Step size of the simulation.
◆ interact() [2/2]
Let a person interact with the population at its current location.
- Parameters
-
[in] person Id of a person from this Model. [in] t Time step of the simulation. [in] dt Step size of the simulation.
◆ interaction()
Persons interact at their Location and may become infected.
- Parameters
-
[in] t The current TimePoint. [in] dt The length of the time step of the Simulation.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ perform_mobility()
Persons change location in the Model according to rules.
- Parameters
-
[in] t The current TimePoint. [in] dt The length of the time step of the Simulation.
◆ serialize()
|
inline |
serialize this.
- See also
- mio::serialize
◆ use_mobility_rules() [1/2]
| bool mio::abm::Model::use_mobility_rules | ( | ) | const |
◆ use_mobility_rules() [2/2]
| void mio::abm::Model::use_mobility_rules | ( | bool | param | ) |
Decide if mobility rules (like go to school/work) are used or not; The mobility rules regarding hospitalization/ICU/quarantine are always used.
- Parameters
-
[in] param If true uses the mobility rules for changing location to school/work etc., else only the rules regarding hospitalization/ICU/quarantine.
Member Data Documentation
◆ m_activeness_statuses
|
protected |
Vector with activeness status for every person. Is only used for abm graph model or hybrid model.
◆ m_air_exposure_rates_cache
|
protected |
Cache for local exposure through droplets in #transmissions/day.
◆ m_are_exposure_caches_valid
|
protected |
Current number of Persons in a given location.
◆ m_cemetery_id
|
protected |
Current number of Persons in a given location.
◆ m_contact_exposure_rates_cache
|
protected |
Cache for local exposure through contacts in #transmissions/day.
◆ m_exposure_caches_need_rebuild
|
protected |
Current number of Persons in a given location.
◆ m_has_locations
|
protected |
Flags for each LocationType, set if a Location of that type exists.
◆ m_id
|
protected |
Model id. Is only used for abm graph model or hybrid model.
◆ m_is_local_population_cache_valid
|
mutableprotected |
Current number of Persons in a given location.
◆ m_local_population_by_age_cache
|
mutableprotected |
Current number of Persons per AgeGroup in a given location.
◆ m_local_population_cache
|
mutableprotected |
Current number of Persons in a given location.
◆ m_locations
◆ m_mobility_rules
|
protected |
Rules that govern the mobility between Locations.
◆ m_person_ids_equal_index
|
protected |
Current number of Persons in a given location.
◆ m_persons
◆ m_rng
|
protected |
Global random number generator.
◆ m_testing_strategy
|
protected |
List of TestingSchemes that are checked for testing.
◆ m_trip_list
◆ m_use_mobility_rules
|
protected |
Whether mobility rules are considered.
◆ parameters
| Parameters mio::abm::Model::parameters |
The simulation parameters of the Model.
Generated by