Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1039 Add functions for the Person to choose whether to comply to mask,test and isolation #1040

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
943ae3e
Add functions for the Person to choose whether to comply to mask,test…
khoanguyen-dev May 24, 2024
770f9f9
Change apply_mask_intervention() so that the Person can enter the tar…
khoanguyen-dev May 27, 2024
7e687a7
Change positions of apply compliance for test and mask and name of as…
khoanguyen-dev May 30, 2024
a487487
Test if the NPI is applied and the Person cannot enter targeted location
khoanguyen-dev Jun 3, 2024
36ae54e
Add tests when the NPIs are applied, people cannot enter targeted loc…
khoanguyen-dev Jun 3, 2024
41e8e43
Remove not used variable in test_abm_world
khoanguyen-dev Jun 4, 2024
b4241b4
Remove not used variable in test_abm_world
khoanguyen-dev Jun 4, 2024
26e5c87
Correct the code as suggested by Rene's comments
khoanguyen-dev Jun 11, 2024
9798e7d
More correction in the code as suggested by Rene's comments, missing …
khoanguyen-dev Jun 14, 2024
652c983
Add TimePoint for mask initial use and improve tests
khoanguyen-dev Jun 14, 2024
51ec868
Add comments and correct tests
khoanguyen-dev Jun 14, 2024
2586963
Delete set_npi_active in benchmarks/abm.cpp
khoanguyen-dev Jun 19, 2024
b0c372f
Some fixes according to David's comments
khoanguyen-dev Jul 1, 2024
ac874ab
Fix some comment for mask compliance is world.cpp
khoanguyen-dev Jul 2, 2024
11b0f59
Remove voluntary mask wearing in World::migrate function
khoanguyen-dev Jul 3, 2024
3f8fa8b
Merge branch 'main' into 1039-implement-agents-compliance-to-mask-tes…
khoanguyen-dev Jul 22, 2024
f9bd301
Merge branch 'main' into 1039-implement-agents-compliance-to-mask-tes…
khoanguyen-dev Jul 22, 2024
6f8307d
Add test for migrateWithAppliedNPIs
khoanguyen-dev Jul 24, 2024
1b90418
Small updates according to Rene's comments
khoanguyen-dev Jul 25, 2024
0cc2218
Remove enum = 0 and optimise run_strategy()
khoanguyen-dev Jul 29, 2024
44eaf5a
Merge branch 'main' into 1039-implement-agents-compliance-to-mask-tes…
khoanguyen-dev Jul 31, 2024
f327c9b
Add TestModel, mobilityRulesWithAppliedNPIs
khoanguyen-dev Jul 31, 2024
58451d8
Modifications according to David comments
khoanguyen-dev Aug 1, 2024
e038809
Undo EXPECT_EQ is test_abm_model.cpp
khoanguyen-dev Aug 1, 2024
5c2f84f
Merge branch 'main' into 1039-implement-agents-compliance-to-mask-tes…
khoanguyen-dev Aug 5, 2024
2d4fada
Optimise perform_mobility and comments
khoanguyen-dev Aug 12, 2024
4305163
Adjust InfectionState to take into account required test time
khoanguyen-dev Aug 12, 2024
a6aa4c8
Remove test for trips of the Dead and quarantine Person
khoanguyen-dev Aug 12, 2024
27cca92
Add back test for the trips of the quarantine Person
khoanguyen-dev Aug 12, 2024
dca8915
Fix small error in trip's mobility
khoanguyen-dev Aug 13, 2024
990fe6b
Chang trip loop in perform_mobility() from while to for
khoanguyen-dev Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/benchmarks/abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mio::abm::Simulation make_simulation(size_t num_persons, std::initializer_list<u
//skip homes so persons always have a place to go, simulation might break otherwise
auto pct_require_mask = 0.2;
if (loc.get_type() != mio::abm::LocationType::Home &&
mio::UniformDistribution<double>::get_instance()(world.get_rng()) < pct_require_mask) {
mio::UniformDistribution<double>::get_instance()(model.get_rng()) < pct_require_mask) {
loc.set_required_mask(mio::abm::MaskType::Community);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/models/abm/intervention_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace abm
*/
enum class InterventionType : std::uint32_t
{
Mask = 0,
Mask,
Testing,
Isolation,

Expand Down
2 changes: 1 addition & 1 deletion cpp/models/abm/mask_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace abm
*/
enum class MaskType : std::uint32_t
{
None = 0,
None,
Community,
Surgical,
FFP2,
Expand Down
4 changes: 2 additions & 2 deletions cpp/models/abm/mobility_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace abm
*/
enum class TransportMode : uint32_t
{
Bike = 0,
Bike,
CarDriver,
CarPassenger,
PublicTransport,
Expand All @@ -47,7 +47,7 @@ enum class TransportMode : uint32_t
*/
enum class ActivityType : uint32_t
{
Workplace = 0,
Workplace,
Education,
Shopping,
Leisure,
Expand Down
48 changes: 23 additions & 25 deletions cpp/models/abm/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,20 @@ void Model::perform_mobility(TimePoint t, TimeSpan dt)
Person& person = m_persons[person_id];
auto personal_rng = PersonalRandomNumberGenerator(m_rng, person);

auto try_mobility_rule = [&](auto rule) -> bool {
//run mobility rule and check if change of location can actually happen
auto try_migration_rule = [&](auto rule) -> bool {
//run migration rule and check if migration can actually happen
khoanguyen-dev marked this conversation as resolved.
Show resolved Hide resolved
auto target_type = rule(personal_rng, person, t, dt, parameters);
const Location& target_location = get_location(find_location(target_type, person_id));
const LocationId current_location = person.get_location();

// Check if the Person wears mask if required at targeted location
if ((target_location.is_mask_required() && person.is_compliant(personal_rng, InterventionType::Mask)) ||
!target_location.is_mask_required()) {
if (!target_location.is_mask_required() || person.is_compliant(personal_rng, InterventionType::Mask)) {
// Check if the capacity of targeted Location is not reached
if (target_location.get_id() != current_location &&
get_number_persons(target_location.get_id()) < target_location.get_capacity().persons) {
// Perform TestingStrategy if required
if (m_testing_strategy.run_strategy(personal_rng, person, target_location, t)) {
migrate(person_id, target_location.get_id());
change_location(person_id, target_location.get_id());
if (target_location.is_mask_required()) {
// If the current MaskProtection level is lower than required, the Person changes mask
if (parameters.get<MaskProtection>()[person.get_mask().get_type()] <
Expand All @@ -130,26 +129,26 @@ void Model::perform_mobility(TimePoint t, TimeSpan dt)
return false;
};

//run mobility rules one after the other if the corresponding location type exists
//run migration rules one after the other if the corresponding location type exists
khoanguyen-dev marked this conversation as resolved.
Show resolved Hide resolved
//shortcutting of bool operators ensures the rules stop after the first rule is applied
if (m_use_mobility_rules) {
(has_locations({LocationType::Cemetery}) && try_mobility_rule(&get_buried)) ||
(has_locations({LocationType::Home}) && try_mobility_rule(&return_home_when_recovered)) ||
(has_locations({LocationType::Hospital}) && try_mobility_rule(&go_to_hospital)) ||
(has_locations({LocationType::ICU}) && try_mobility_rule(&go_to_icu)) ||
(has_locations({LocationType::School, LocationType::Home}) && try_mobility_rule(&go_to_school)) ||
(has_locations({LocationType::Work, LocationType::Home}) && try_mobility_rule(&go_to_work)) ||
(has_locations({LocationType::BasicsShop, LocationType::Home}) && try_mobility_rule(&go_to_shop)) ||
(has_locations({LocationType::SocialEvent, LocationType::Home}) && try_mobility_rule(&go_to_event)) ||
(has_locations({LocationType::Home}) && try_mobility_rule(&go_to_quarantine));
(has_locations({LocationType::Cemetery}) && try_migration_rule(&get_buried)) ||
(has_locations({LocationType::Home}) && try_migration_rule(&return_home_when_recovered)) ||
(has_locations({LocationType::Hospital}) && try_migration_rule(&go_to_hospital)) ||
(has_locations({LocationType::ICU}) && try_migration_rule(&go_to_icu)) ||
(has_locations({LocationType::School, LocationType::Home}) && try_migration_rule(&go_to_school)) ||
(has_locations({LocationType::Work, LocationType::Home}) && try_migration_rule(&go_to_work)) ||
(has_locations({LocationType::BasicsShop, LocationType::Home}) && try_migration_rule(&go_to_shop)) ||
(has_locations({LocationType::SocialEvent, LocationType::Home}) && try_migration_rule(&go_to_event)) ||
(has_locations({LocationType::Home}) && try_migration_rule(&go_to_quarantine));
DavidKerkmann marked this conversation as resolved.
Show resolved Hide resolved
}
else {
//no daily routine mobility, just infection related
(has_locations({LocationType::Cemetery}) && try_mobility_rule(&get_buried)) ||
(has_locations({LocationType::Home}) && try_mobility_rule(&return_home_when_recovered)) ||
(has_locations({LocationType::Hospital}) && try_mobility_rule(&go_to_hospital)) ||
(has_locations({LocationType::ICU}) && try_mobility_rule(&go_to_icu)) ||
(has_locations({LocationType::Home}) && try_mobility_rule(&go_to_quarantine));
//no daily routine migration, just infection related
(has_locations({LocationType::Cemetery}) && try_migration_rule(&get_buried)) ||
(has_locations({LocationType::Home}) && try_migration_rule(&return_home_when_recovered)) ||
(has_locations({LocationType::Hospital}) && try_migration_rule(&go_to_hospital)) ||
(has_locations({LocationType::ICU}) && try_migration_rule(&go_to_icu)) ||
(has_locations({LocationType::Home}) && try_migration_rule(&go_to_quarantine));
}
}

Expand All @@ -164,13 +163,12 @@ void Model::perform_mobility(TimePoint t, TimeSpan dt)
auto& person = get_person(trip.person_id);
auto personal_rng = PersonalRandomNumberGenerator(m_rng, person);
if (!person.is_in_quarantine(t, parameters) && person.get_infection_state(t) != InfectionState::Dead) {
auto& target_location = get_location(trip.migration_destination);
auto& target_location = get_location(trip.destination);
// Check if the Person wears mask if required at targeted location
if ((target_location.is_mask_required() && person.is_compliant(personal_rng, InterventionType::Mask)) ||
!target_location.is_mask_required()) {
if (!target_location.is_mask_required() || person.is_compliant(personal_rng, InterventionType::Mask)) {
// Perform TestingStrategy if required
if (m_testing_strategy.run_strategy(personal_rng, person, target_location, t)) {
migrate(person.get_id(), target_location.get_id(), trip.trip_mode);
change_location(person.get_id(), target_location.get_id(), trip.trip_mode);
if (target_location.is_mask_required()) {
// If the current MaskProtection level is lower than required, the Person changes mask
if (parameters.get<MaskProtection>()[person.get_mask().get_type()] <
Expand Down
2 changes: 1 addition & 1 deletion cpp/models/abm/test_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace abm
*/
enum class TestType : std::uint32_t
{
Generic = 0,
Generic,
Antigen,
PCR,

Expand Down
11 changes: 7 additions & 4 deletions cpp/models/abm/testing_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ bool TestingStrategy::run_strategy(PersonalRandomNumberGenerator& rng, Person& p
return true;
}

// If the Person does not comply to Testing where there is a testing scheme at the target location, it is not allowed to enter.
if (!person.is_compliant(rng, InterventionType::Testing)) {
return false;
}

//lookup schemes for this specific location as well as the location type
//lookup in std::vector instead of std::map should be much faster unless for large numbers of schemes
for (auto key : {std::make_pair(location.get_type(), location.get_id()),
Expand All @@ -188,10 +193,8 @@ bool TestingStrategy::run_strategy(PersonalRandomNumberGenerator& rng, Person& p
if (iter_schemes != m_location_to_schemes_map.end()) {
//apply all testing schemes that are found
auto& schemes = iter_schemes->schemes;
// If the Person does not comply to Testing where there is a testing scheme at the target location, it is not allowed to enter.
// Otherwise, whether the Person is allowed to enter or not depends on the test result(s).
if (!person.is_compliant(rng, InterventionType::Testing) ||
!std::all_of(schemes.begin(), schemes.end(), [&rng, &person, t](TestingScheme& ts) {
// Whether the Person is allowed to enter or not depends on the test result(s).
if (!std::all_of(schemes.begin(), schemes.end(), [&rng, &person, t](TestingScheme& ts) {
return !ts.is_active() || ts.run_scheme(rng, person, t);
})) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions cpp/models/abm/vaccine.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ namespace abm
*/
enum class ExposureType : std::uint32_t
{
NoProtection = 0,
NaturalInfection = 1,
GenericVaccine = 2,
NoProtection,
NaturalInfection,
GenericVaccine,
Count //last!!
};

Expand Down
2 changes: 1 addition & 1 deletion cpp/models/abm/virus_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace abm
*/
enum class VirusVariant : std::uint32_t
{
Wildtype = 0,
Wildtype,

Count // last!!
};
Expand Down
Loading
Loading