Skip to content

Commit fef7ce3

Browse files
364 create abm simulation with percentiles output (#572)
Co-authored-by: Martin J. Kühn <[email protected]>
1 parent e387504 commit fef7ce3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2624
-1986
lines changed

cpp/examples/abm_history_object.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,31 @@ void write_log_to_file(const T& history)
5959

6060
int main()
6161
{
62-
// Set global infection parameters (similar to infection parameters in SECIR model) and initialize the world
63-
mio::abm::GlobalInfectionParameters infection_params;
62+
// This is a minimal example with children and adults < 60y.
63+
// We divided them into 4 different age groups, which are defined as follows:
64+
const size_t NUM_AGE_GROUPS = 4;
65+
const auto AGE_GROUP_0_TO_4 = mio::AgeGroup(NUM_AGE_GROUPS - 4);
66+
const auto AGE_GROUP_5_TO_14 = mio::AgeGroup(NUM_AGE_GROUPS - 3);
67+
const auto AGE_GROUP_15_TO_34 = mio::AgeGroup(NUM_AGE_GROUPS - 2);
68+
const auto AGE_GROUP_35_TO_59 = mio::AgeGroup(NUM_AGE_GROUPS - 1);
6469

65-
// Set same infection parameter for all age groups. For example, the incubation period is 4 days.
66-
infection_params.get<mio::abm::IncubationPeriod>() = 4.;
70+
// Create the world with 4 age groups.
71+
auto world = mio::abm::World(NUM_AGE_GROUPS);
6772

68-
// Create the world with infection parameters.
69-
auto world = mio::abm::World(infection_params);
73+
// Set same infection parameter for all age groups. For example, the incubation period is 4 days.
74+
world.parameters.get<mio::abm::IncubationPeriod>() = 4.;
7075

7176
// There are 3 households for each household group.
7277
int n_households = 3;
7378

7479
// For more than 1 family households we need families. These are parents and children and randoms (which are distributed like the data we have for these households).
75-
auto child = mio::abm::HouseholdMember(); // A child is 50/50% 0-4 or 5-14.
76-
child.set_age_weight(mio::abm::AgeGroup::Age0to4, 1);
77-
child.set_age_weight(mio::abm::AgeGroup::Age5to14, 1);
80+
auto child = mio::abm::HouseholdMember(NUM_AGE_GROUPS); // A child is 50/50% 0-4 or 5-14.
81+
child.set_age_weight(AGE_GROUP_0_TO_4, 1);
82+
child.set_age_weight(AGE_GROUP_5_TO_14, 1);
7883

79-
auto parent = mio::abm::HouseholdMember(); // A parent is 50/50% 15-34 or 35-59.
80-
parent.set_age_weight(mio::abm::AgeGroup::Age15to34, 1);
81-
parent.set_age_weight(mio::abm::AgeGroup::Age35to59, 1);
84+
auto parent = mio::abm::HouseholdMember(NUM_AGE_GROUPS); // A parent is 50/50% 15-34 or 35-59.
85+
parent.set_age_weight(AGE_GROUP_15_TO_34, 1);
86+
parent.set_age_weight(AGE_GROUP_35_TO_59, 1);
8287

8388
// Two-person household with one parent and one child.
8489
auto twoPersonHousehold_group = mio::abm::HouseholdGroup();
@@ -137,8 +142,7 @@ int main()
137142
(mio::abm::InfectionState)(rand() % ((uint32_t)mio::abm::InfectionState::Count - 1));
138143
if (infection_state != mio::abm::InfectionState::Susceptible)
139144
person.add_new_infection(mio::abm::Infection(rng, mio::abm::VirusVariant::Wildtype, person.get_age(),
140-
world.get_global_infection_parameters(), start_date,
141-
infection_state));
145+
world.parameters, start_date, infection_state));
142146
}
143147

144148
// Assign locations to the people
@@ -150,17 +154,17 @@ int main()
150154
person.set_assigned_location(hospital);
151155
person.set_assigned_location(icu);
152156
//assign work/school to people depending on their age
153-
if (person.get_age() == mio::abm::AgeGroup::Age5to14) {
157+
if (person.get_age() == AGE_GROUP_5_TO_14) {
154158
person.set_assigned_location(school);
155159
}
156-
if (person.get_age() == mio::abm::AgeGroup::Age15to34 || person.get_age() == mio::abm::AgeGroup::Age35to59) {
160+
if (person.get_age() == AGE_GROUP_15_TO_34 || person.get_age() == AGE_GROUP_35_TO_59) {
157161
person.set_assigned_location(work);
158162
}
159163
}
160164

161165
// During the lockdown, social events are closed for 90% of people.
162166
auto t_lockdown = mio::abm::TimePoint(0) + mio::abm::days(10);
163-
mio::abm::close_social_events(t_lockdown, 0.9, world.get_migration_parameters());
167+
mio::abm::close_social_events(t_lockdown, 0.9, world.parameters);
164168

165169
auto t0 = mio::abm::TimePoint(0);
166170
auto tmax = mio::abm::TimePoint(0) + mio::abm::days(30);

cpp/examples/abm_minimal.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,39 @@ void write_results_to_file(const mio::abm::Simulation& sim)
5050

5151
int main()
5252
{
53-
// Set global infection parameters (similar to infection parameters in SECIR model) and initialize the world
54-
mio::abm::GlobalInfectionParameters infection_params;
53+
// This is a minimal example with children and adults < 60 year old.
54+
// We divided them into 3 different age groups, which are defined as follows:
55+
size_t NUM_AGE_GROUPS = 4;
56+
const auto AGE_GROUP_0_TO_4 = mio::AgeGroup(NUM_AGE_GROUPS - 4);
57+
const auto AGE_GROUP_5_TO_14 = mio::AgeGroup(NUM_AGE_GROUPS - 3);
58+
const auto AGE_GROUP_15_TO_34 = mio::AgeGroup(NUM_AGE_GROUPS - 2);
59+
const auto AGE_GROUP_35_TO_59 = mio::AgeGroup(NUM_AGE_GROUPS - 1);
60+
61+
// Create the world with 3 age groups.
62+
auto world = mio::abm::World(NUM_AGE_GROUPS);
5563

5664
// Set same infection parameter for all age groups. For example, the incubation period is 4 days.
57-
infection_params.get<mio::abm::IncubationPeriod>() = 4.;
65+
world.parameters.get<mio::abm::IncubationPeriod>() = 4.;
66+
67+
// Set the age group the can go to school is AgeGroup(1) (i.e. 5-14)
68+
world.parameters.get<mio::abm::AgeGroupGotoSchool>() = {AGE_GROUP_5_TO_14};
69+
// Set the age group the can go to work is AgeGroup(2) and AgeGroup(3) (i.e. 15-34 and 35-59)
70+
world.parameters.get<mio::abm::AgeGroupGotoWork>() = {AGE_GROUP_15_TO_34, AGE_GROUP_35_TO_59};
5871

59-
// Create the world with infection parameters.
60-
auto world = mio::abm::World(infection_params);
72+
// Check if the parameters satisfy their contraints.
73+
world.parameters.check_constraints();
6174

6275
// There are 3 households for each household group.
6376
int n_households = 3;
6477

6578
// For more than 1 family households we need families. These are parents and children and randoms (which are distributed like the data we have for these households).
66-
auto child = mio::abm::HouseholdMember(); // A child is 50/50% 0-4 or 5-14.
67-
child.set_age_weight(mio::abm::AgeGroup::Age0to4, 1);
68-
child.set_age_weight(mio::abm::AgeGroup::Age5to14, 1);
79+
auto child = mio::abm::HouseholdMember(NUM_AGE_GROUPS); // A child is 50/50% 0-4 or 5-14.
80+
child.set_age_weight(AGE_GROUP_0_TO_4, 1);
81+
child.set_age_weight(AGE_GROUP_0_TO_4, 1);
6982

70-
auto parent = mio::abm::HouseholdMember(); // A parent is 50/50% 15-34 or 35-59.
71-
parent.set_age_weight(mio::abm::AgeGroup::Age15to34, 1);
72-
parent.set_age_weight(mio::abm::AgeGroup::Age35to59, 1);
83+
auto parent = mio::abm::HouseholdMember(NUM_AGE_GROUPS); // A parent is 50/50% 15-34 or 35-59.
84+
parent.set_age_weight(AGE_GROUP_15_TO_34, 1);
85+
parent.set_age_weight(AGE_GROUP_35_TO_59, 1);
7386

7487
// Two-person household with one parent and one child.
7588
auto twoPersonHousehold_group = mio::abm::HouseholdGroup();
@@ -128,8 +141,7 @@ int main()
128141
auto rng = mio::abm::Person::RandomNumberGenerator(world.get_rng(), person);
129142
if (infection_state != mio::abm::InfectionState::Susceptible) {
130143
person.add_new_infection(mio::abm::Infection(rng, mio::abm::VirusVariant::Wildtype, person.get_age(),
131-
world.get_global_infection_parameters(), start_date,
132-
infection_state));
144+
world.parameters, start_date, infection_state));
133145
}
134146
}
135147

@@ -142,17 +154,17 @@ int main()
142154
person.set_assigned_location(hospital);
143155
person.set_assigned_location(icu);
144156
//assign work/school to people depending on their age
145-
if (person.get_age() == mio::abm::AgeGroup::Age5to14) {
157+
if (person.get_age() == AGE_GROUP_0_TO_4) {
146158
person.set_assigned_location(school);
147159
}
148-
if (person.get_age() == mio::abm::AgeGroup::Age15to34 || person.get_age() == mio::abm::AgeGroup::Age35to59) {
160+
if (person.get_age() == AGE_GROUP_15_TO_34 || person.get_age() == AGE_GROUP_35_TO_59) {
149161
person.set_assigned_location(work);
150162
}
151163
}
152164

153165
// During the lockdown, social events are closed for 90% of people.
154166
auto t_lockdown = mio::abm::TimePoint(0) + mio::abm::days(10);
155-
mio::abm::close_social_events(t_lockdown, 0.9, world.get_migration_parameters());
167+
mio::abm::close_social_events(t_lockdown, 0.9, world.parameters);
156168

157169
auto t0 = mio::abm::TimePoint(0);
158170
auto tmax = mio::abm::TimePoint(0) + mio::abm::days(30);

cpp/models/abm/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ The result of the simulation is for each time step the count of persons in each
2323
## Example
2424
An example can also be found at simulations/abm.cpp
2525
```
26-
//setup the infection parameters
27-
mio::abm::GlobalInfectionParameters params;
28-
params.incubation_period = 4.7;
26+
size_t NUM_AGE_GROUPS = 4;
27+
const auto AGE_GROUP_0_TO_4 = mio::AgeGroup(NUM_AGE_GROUPS - 4);
28+
const auto AGE_GROUP_5_TO_14 = mio::AgeGroup(NUM_AGE_GROUPS - 3);
29+
const auto AGE_GROUP_15_TO_34 = mio::AgeGroup(NUM_AGE_GROUPS - 2);
30+
const auto AGE_GROUP_35_TO_59 = mio::AgeGroup(NUM_AGE_GROUPS - 1);
31+
32+
// Create the world with 4 age groups.
33+
auto world = mio::abm::World(NUM_AGE_GROUPS);
34+
//setup the parameters
35+
world.parameters.get<mio::abm::IncubationPeriod>() = 4.;
2936
//...
3037
3138
//create the world with some nodes and persons
32-
mio::abm::World world = mio::abm::World(params);
3339
mio::abm::Location& home = world.add_location(mio::abm::LocationType::Home);
3440
mio::abm::Location& school = world.add_location(mio::abm::LocationType::School);
3541
mio::abm::Location& work = world.add_location(mio::abm::LocationType::Work);

cpp/models/abm/abm.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 German Aerospace Center (DLR-SC)
3-
* & Helmholtz Centre for Infection Research (HZI)
2+
* Copyright (C) 2020-2024 MEmilio
43
*
54
* Authors: Daniel Abele, Majid Abedi, Elisabeth Kluth
65
*
@@ -37,7 +36,6 @@
3736
#include "abm/infection_state.h"
3837
#include "abm/virus_variant.h"
3938
#include "abm/vaccine.h"
40-
#include "abm/age.h"
4139
#include "abm/household.h"
4240
#include "abm/lockdown_rules.h"
4341

cpp/models/abm/age.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)