Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 14 additions & 14 deletions cpp/examples/abm_history_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ int main()
{
// This is a minimal example with children and adults < 60y.
// We divided them into 4 different age groups, which are defined as follows:
const size_t NUM_AGE_GROUPS = 4;
const auto AGE_GROUP_0_TO_4 = mio::AgeGroup(NUM_AGE_GROUPS - 4);
const auto AGE_GROUP_5_TO_14 = mio::AgeGroup(NUM_AGE_GROUPS - 3);
const auto AGE_GROUP_15_TO_34 = mio::AgeGroup(NUM_AGE_GROUPS - 2);
const auto AGE_GROUP_35_TO_59 = mio::AgeGroup(NUM_AGE_GROUPS - 1);
size_t num_age_groups = 4;
const auto age_group_0_to_4 = mio::AgeGroup(0);
const auto age_group_5_to_14 = mio::AgeGroup(1);
const auto age_group_15_to_34 = mio::AgeGroup(2);
const auto age_group_35_to_59 = mio::AgeGroup(3);

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

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

// 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).
auto child = mio::abm::HouseholdMember(NUM_AGE_GROUPS); // A child is 50/50% 0-4 or 5-14.
child.set_age_weight(AGE_GROUP_0_TO_4, 1);
child.set_age_weight(AGE_GROUP_5_TO_14, 1);
auto child = mio::abm::HouseholdMember(num_age_groups); // A child is 50/50% 0-4 or 5-14.
child.set_age_weight(age_group_0_to_4, 1);
child.set_age_weight(age_group_5_to_14, 1);

auto parent = mio::abm::HouseholdMember(NUM_AGE_GROUPS); // A parent is 50/50% 15-34 or 35-59.
parent.set_age_weight(AGE_GROUP_15_TO_34, 1);
parent.set_age_weight(AGE_GROUP_35_TO_59, 1);
auto parent = mio::abm::HouseholdMember(num_age_groups); // A parent is 50/50% 15-34 or 35-59.
parent.set_age_weight(age_group_15_to_34, 1);
parent.set_age_weight(age_group_35_to_59, 1);

// Two-person household with one parent and one child.
auto twoPersonHousehold_group = mio::abm::HouseholdGroup();
Expand Down Expand Up @@ -152,10 +152,10 @@ int main()
person.set_assigned_location(hospital);
person.set_assigned_location(icu);
//assign work/school to people depending on their age
if (person.get_age() == AGE_GROUP_5_TO_14) {
if (person.get_age() == age_group_5_to_14) {
person.set_assigned_location(school);
}
if (person.get_age() == AGE_GROUP_15_TO_34 || person.get_age() == AGE_GROUP_35_TO_59) {
if (person.get_age() == age_group_15_to_34 || person.get_age() == age_group_35_to_59) {
person.set_assigned_location(work);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/models/abm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ child.set_age_weight(age_group_0_to_4, 1);
child.set_age_weight(age_group_0_to_4, 1);

auto parent = mio::abm::HouseholdMember(num_age_groups);
parent.set_age_weight(AGE_GROUP_15_TO_34, 1);
parent.set_age_weight(AGE_GROUP_35_TO_59, 1);
parent.set_age_weight(age_groups_15_to_34, 1);
parent.set_age_weight(age_groups_35_to_59, 1);

// Two-person household with one parent and one child.
auto twoPersonHousehold_group = mio::abm::HouseholdGroup();
Expand Down
1 change: 1 addition & 0 deletions cpp/models/abm/household.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class HouseholdMember
*/
void set_age_weight(mio::AgeGroup age_group, int weight)
{
assert((size_t)age_group.size < m_age_weights.numel());
m_age_weights[age_group] = weight;
}

Expand Down
4 changes: 4 additions & 0 deletions cpp/models/abm/infection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Infection::Infection(Person::RandomNumberGenerator& rng, VirusVariant virus, Age
: m_virus_variant(virus)
, m_detected(detected)
{
assert((size_t)age.size < (size_t)params.get_num_groups());
m_viral_load.start_date = draw_infection_course(rng, age, params, init_date, init_state, latest_exposure);

auto vl_params = params.get<ViralLoadDistributions>()[{virus, age}];
Expand Down Expand Up @@ -115,6 +116,7 @@ TimePoint Infection::draw_infection_course(Person::RandomNumberGenerator& rng, A
TimePoint init_date, InfectionState init_state,
std::pair<ExposureType, TimePoint> latest_protection)
{
assert((size_t)age.size < (size_t)params.get_num_groups());
TimePoint start_date = draw_infection_course_backward(rng, age, params, init_date, init_state);
draw_infection_course_forward(rng, age, params, init_date, init_state, latest_protection);
return start_date;
Expand All @@ -124,6 +126,7 @@ void Infection::draw_infection_course_forward(Person::RandomNumberGenerator& rng
const Parameters& params, TimePoint init_date, InfectionState start_state,
std::pair<ExposureType, TimePoint> latest_exposure)
{
assert((size_t)age.size < (size_t)params.get_num_groups());
auto t = init_date;
TimeSpan time_period{}; // time period for current infection state
InfectionState next_state{start_state}; // next state to enter
Expand Down Expand Up @@ -211,6 +214,7 @@ TimePoint Infection::draw_infection_course_backward(Person::RandomNumberGenerato
const Parameters& params, TimePoint init_date,
InfectionState init_state)
{
assert((size_t)age.size < (size_t)params.get_num_groups());
auto start_date = init_date;
TimeSpan time_period{}; // time period for current infection state
InfectionState previous_state{init_state}; // next state to enter
Expand Down
1 change: 1 addition & 0 deletions cpp/models/abm/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Location Location::copy_location_without_persons(size_t num_agegroups)
ScalarType Location::transmission_contacts_per_day(uint32_t cell_index, VirusVariant virus, AgeGroup age_receiver,
size_t num_agegroups) const
{
assert((size_t)age_receiver.size < num_agegroups);
ScalarType prob = 0;
for (uint32_t age_transmitter = 0; age_transmitter != num_agegroups; ++age_transmitter) {
prob += m_cells[cell_index].m_cached_exposure_rate_contacts[{virus, static_cast<AgeGroup>(age_transmitter)}] *
Expand Down
1 change: 1 addition & 0 deletions cpp/models/abm/testing_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bool TestingCriteria::operator==(const TestingCriteria& other) const

void TestingCriteria::add_age_group(const AgeGroup age_group)
{

m_ages.insert(static_cast<size_t>(age_group));
}

Expand Down
Loading