From 605184821eaa761db184623d4a06872f25809f16 Mon Sep 17 00:00:00 2001 From: Sascha Korf <51127093+xsaschako@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:28:00 +0100 Subject: [PATCH 1/2] Fix assert statements for age size comparison --- cpp/examples/abm_history_object.cpp | 2 +- cpp/models/abm/household.h | 2 +- cpp/models/abm/infection.cpp | 8 ++++---- cpp/models/abm/location.cpp | 2 +- cpp/models/abm/world.cpp | 2 +- cpp/tests/abm_helpers.cpp | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cpp/examples/abm_history_object.cpp b/cpp/examples/abm_history_object.cpp index 8f76b8d699..7f6094bc62 100644 --- a/cpp/examples/abm_history_object.cpp +++ b/cpp/examples/abm_history_object.cpp @@ -61,7 +61,7 @@ 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: - size_t num_age_groups = 4; + const 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); diff --git a/cpp/models/abm/household.h b/cpp/models/abm/household.h index c379e7364b..06b7d0a7c2 100644 --- a/cpp/models/abm/household.h +++ b/cpp/models/abm/household.h @@ -68,7 +68,7 @@ class HouseholdMember */ void set_age_weight(mio::AgeGroup age_group, int weight) { - assert((size_t)age_group.size < m_age_weights.numel()); + assert(age_group < m_age_weights.size()); m_age_weights[age_group] = weight; } diff --git a/cpp/models/abm/infection.cpp b/cpp/models/abm/infection.cpp index cf7fc2e15b..a6c9ffff71 100644 --- a/cpp/models/abm/infection.cpp +++ b/cpp/models/abm/infection.cpp @@ -32,7 +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()); + assert(age.get() < 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()[{virus, age}]; @@ -116,7 +116,7 @@ TimePoint Infection::draw_infection_course(Person::RandomNumberGenerator& rng, A TimePoint init_date, InfectionState init_state, std::pair latest_protection) { - assert((size_t)age.size < (size_t)params.get_num_groups()); + assert(age.get() < 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; @@ -126,7 +126,7 @@ void Infection::draw_infection_course_forward(Person::RandomNumberGenerator& rng const Parameters& params, TimePoint init_date, InfectionState start_state, std::pair latest_exposure) { - assert((size_t)age.size < (size_t)params.get_num_groups()); + assert(age.get() < 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 @@ -214,7 +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()); + assert(age.get() < 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 diff --git a/cpp/models/abm/location.cpp b/cpp/models/abm/location.cpp index e53310d2d9..c1ff912720 100644 --- a/cpp/models/abm/location.cpp +++ b/cpp/models/abm/location.cpp @@ -58,7 +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); + assert(age_receiver.get() < 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(age_transmitter)}] * diff --git a/cpp/models/abm/world.cpp b/cpp/models/abm/world.cpp index 03da243b27..630c37b2b2 100755 --- a/cpp/models/abm/world.cpp +++ b/cpp/models/abm/world.cpp @@ -45,7 +45,7 @@ LocationId World::add_location(LocationType type, uint32_t num_cells) Person& World::add_person(const LocationId id, AgeGroup age) { - assert((size_t)age.size < (size_t)parameters.get_num_groups()); + assert(age.get() < params.get_num_groups()); uint32_t person_id = static_cast(m_persons.size()); m_persons.push_back(std::make_unique(m_rng, get_individualized_location(id), age, person_id)); auto& person = *m_persons.back(); diff --git a/cpp/tests/abm_helpers.cpp b/cpp/tests/abm_helpers.cpp index 98a3a12dab..5c10c4828b 100644 --- a/cpp/tests/abm_helpers.cpp +++ b/cpp/tests/abm_helpers.cpp @@ -25,7 +25,7 @@ mio::abm::Person make_test_person(mio::abm::Location& location, mio::AgeGroup ag mio::abm::InfectionState infection_state, mio::abm::TimePoint t, mio::abm::Parameters params) { - assert((size_t)age.size < (size_t)params.get_num_groups()); + assert(age.get() < params.get_num_groups()); auto rng = mio::RandomNumberGenerator(); mio::abm::Person p = mio::abm::Person(rng, location, age); if (infection_state != mio::abm::InfectionState::Susceptible) { @@ -39,7 +39,7 @@ mio::abm::Person make_test_person(mio::abm::Location& location, mio::AgeGroup ag mio::abm::Person& add_test_person(mio::abm::World& world, mio::abm::LocationId loc_id, mio::AgeGroup age, mio::abm::InfectionState infection_state, mio::abm::TimePoint t) { - assert((size_t)age.size < (size_t)world.parameters.get_num_groups()); + assert(age.get() < world.parameters.get_num_groups()); mio::abm::Person& p = world.add_person(loc_id, age); if (infection_state != mio::abm::InfectionState::Susceptible) { auto rng_p = mio::abm::Person::RandomNumberGenerator(world.get_rng(), p); From d517e4868dc44293c5dcd3c0e4b59cd3b91b8fce Mon Sep 17 00:00:00 2001 From: Sascha Korf <51127093+xsaschako@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:13:08 +0100 Subject: [PATCH 2/2] Fix variable name inworld.cpp and identation --- cpp/examples/abm_history_object.cpp | 2 +- cpp/models/abm/world.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/examples/abm_history_object.cpp b/cpp/examples/abm_history_object.cpp index 7f6094bc62..dd3b1224ad 100644 --- a/cpp/examples/abm_history_object.cpp +++ b/cpp/examples/abm_history_object.cpp @@ -61,7 +61,7 @@ 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 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); diff --git a/cpp/models/abm/world.cpp b/cpp/models/abm/world.cpp index 630c37b2b2..da013802b3 100755 --- a/cpp/models/abm/world.cpp +++ b/cpp/models/abm/world.cpp @@ -45,7 +45,7 @@ LocationId World::add_location(LocationType type, uint32_t num_cells) Person& World::add_person(const LocationId id, AgeGroup age) { - assert(age.get() < params.get_num_groups()); + assert(age.get() < parameters.get_num_groups()); uint32_t person_id = static_cast(m_persons.size()); m_persons.push_back(std::make_unique(m_rng, get_individualized_location(id), age, person_id)); auto& person = *m_persons.back();