Skip to content

Commit 8ed8364

Browse files
846 adjust naming and assignment of abm age groups (#871)
1 parent c469590 commit 8ed8364

22 files changed

+695
-686
lines changed

cpp/examples/abm_history_object.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ int main()
6161
{
6262
// This is a minimal example with children and adults < 60y.
6363
// 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);
64+
size_t num_age_groups = 4;
65+
const auto age_group_0_to_4 = mio::AgeGroup(0);
66+
const auto age_group_5_to_14 = mio::AgeGroup(1);
67+
const auto age_group_15_to_34 = mio::AgeGroup(2);
68+
const auto age_group_35_to_59 = mio::AgeGroup(3);
6969

7070
// Create the world with 4 age groups.
71-
auto world = mio::abm::World(NUM_AGE_GROUPS);
71+
auto world = mio::abm::World(num_age_groups);
7272

7373
// Set same infection parameter for all age groups. For example, the incubation period is 4 days.
7474
world.parameters.get<mio::abm::IncubationPeriod>() = 4.;
@@ -77,13 +77,13 @@ int main()
7777
int n_households = 3;
7878

7979
// 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).
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);
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);
8383

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);
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);
8787

8888
// Two-person household with one parent and one child.
8989
auto twoPersonHousehold_group = mio::abm::HouseholdGroup();
@@ -152,10 +152,10 @@ int main()
152152
person.set_assigned_location(hospital);
153153
person.set_assigned_location(icu);
154154
//assign work/school to people depending on their age
155-
if (person.get_age() == AGE_GROUP_5_TO_14) {
155+
if (person.get_age() == age_group_5_to_14) {
156156
person.set_assigned_location(school);
157157
}
158-
if (person.get_age() == AGE_GROUP_15_TO_34 || person.get_age() == AGE_GROUP_35_TO_59) {
158+
if (person.get_age() == age_group_15_to_34 || person.get_age() == age_group_35_to_59) {
159159
person.set_assigned_location(work);
160160
}
161161
}

cpp/models/abm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ child.set_age_weight(age_group_0_to_4, 1);
8282
child.set_age_weight(age_group_0_to_4, 1);
8383

8484
auto parent = mio::abm::HouseholdMember(num_age_groups);
85-
parent.set_age_weight(AGE_GROUP_15_TO_34, 1);
86-
parent.set_age_weight(AGE_GROUP_35_TO_59, 1);
85+
parent.set_age_weight(age_groups_15_to_34, 1);
86+
parent.set_age_weight(age_groups_35_to_59, 1);
8787

8888
// Two-person household with one parent and one child.
8989
auto twoPersonHousehold_group = mio::abm::HouseholdGroup();

cpp/models/abm/household.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class HouseholdMember
6868
*/
6969
void set_age_weight(mio::AgeGroup age_group, int weight)
7070
{
71+
assert((size_t)age_group.size < m_age_weights.numel());
7172
m_age_weights[age_group] = weight;
7273
}
7374

cpp/models/abm/infection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Infection::Infection(Person::RandomNumberGenerator& rng, VirusVariant virus, Age
3232
: m_virus_variant(virus)
3333
, m_detected(detected)
3434
{
35+
assert((size_t)age.size < (size_t)params.get_num_groups());
3536
m_viral_load.start_date = draw_infection_course(rng, age, params, init_date, init_state, latest_exposure);
3637

3738
auto vl_params = params.get<ViralLoadDistributions>()[{virus, age}];
@@ -115,6 +116,7 @@ TimePoint Infection::draw_infection_course(Person::RandomNumberGenerator& rng, A
115116
TimePoint init_date, InfectionState init_state,
116117
std::pair<ExposureType, TimePoint> latest_protection)
117118
{
119+
assert((size_t)age.size < (size_t)params.get_num_groups());
118120
TimePoint start_date = draw_infection_course_backward(rng, age, params, init_date, init_state);
119121
draw_infection_course_forward(rng, age, params, init_date, init_state, latest_protection);
120122
return start_date;
@@ -124,6 +126,7 @@ void Infection::draw_infection_course_forward(Person::RandomNumberGenerator& rng
124126
const Parameters& params, TimePoint init_date, InfectionState start_state,
125127
std::pair<ExposureType, TimePoint> latest_exposure)
126128
{
129+
assert((size_t)age.size < (size_t)params.get_num_groups());
127130
auto t = init_date;
128131
TimeSpan time_period{}; // time period for current infection state
129132
InfectionState next_state{start_state}; // next state to enter
@@ -211,6 +214,7 @@ TimePoint Infection::draw_infection_course_backward(Person::RandomNumberGenerato
211214
const Parameters& params, TimePoint init_date,
212215
InfectionState init_state)
213216
{
217+
assert((size_t)age.size < (size_t)params.get_num_groups());
214218
auto start_date = init_date;
215219
TimeSpan time_period{}; // time period for current infection state
216220
InfectionState previous_state{init_state}; // next state to enter

cpp/models/abm/location.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Location Location::copy_location_without_persons(size_t num_agegroups)
5858
ScalarType Location::transmission_contacts_per_day(uint32_t cell_index, VirusVariant virus, AgeGroup age_receiver,
5959
size_t num_agegroups) const
6060
{
61+
assert((size_t)age_receiver.size < num_agegroups);
6162
ScalarType prob = 0;
6263
for (uint32_t age_transmitter = 0; age_transmitter != num_agegroups; ++age_transmitter) {
6364
prob += m_cells[cell_index].m_cached_exposure_rate_contacts[{virus, static_cast<AgeGroup>(age_transmitter)}] *

cpp/models/abm/testing_strategy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ bool TestingCriteria::operator==(const TestingCriteria& other) const
4343

4444
void TestingCriteria::add_age_group(const AgeGroup age_group)
4545
{
46+
4647
m_ages.insert(static_cast<size_t>(age_group));
4748
}
4849

0 commit comments

Comments
 (0)