Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ add_executable(abm_minimal_example abm_minimal.cpp)
target_link_libraries(abm_minimal_example PRIVATE memilio abm)
target_compile_options(abm_minimal_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(abm_history_example abm_history_object.cpp)
target_link_libraries(abm_history_example PRIVATE memilio abm)
target_compile_options(abm_history_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(abm_example abm.cpp)
target_link_libraries(abm_example PRIVATE memilio abm)
target_compile_options(abm_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ide_seir_example ide_seir.cpp)
target_link_libraries(ide_seir_example PRIVATE memilio ide_seir)
Expand Down
37 changes: 27 additions & 10 deletions cpp/examples/abm_history_object.cpp → cpp/examples/abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,33 @@ int main()
test_parameters, probability);
model.get_testing_strategy().add_testing_scheme(mio::abm::LocationType::Work, testing_scheme_work);

// Assign infection state to each person.
// The infection states are chosen randomly.
auto persons = model.get_persons();
for (auto& person : persons) {
auto rng = mio::abm::PersonalRandomNumberGenerator(person);
mio::abm::InfectionState infection_state =
(mio::abm::InfectionState)(rand() % ((uint32_t)mio::abm::InfectionState::Count - 1));
if (infection_state != mio::abm::InfectionState::Susceptible)
person.add_new_infection(mio::abm::Infection(rng, mio::abm::VirusVariant::Wildtype, person.get_age(),
model.parameters, start_date, infection_state));
for (auto& person : model.get_persons()) {
auto prng = mio::abm::PersonalRandomNumberGenerator(person);
//some % of people are infected, large enough to have some infection activity without everyone dying
auto pct_infected = 0.05;
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extract the magic number 0.05 into a named constant (e.g., initial_infection_probability) to improve readability and make future adjustments easier.

Suggested change
auto pct_infected = 0.05;
auto pct_infected = initial_infection_probability;

Copilot uses AI. Check for mistakes.
if (mio::UniformDistribution<double>::get_instance()(prng, 0.0, 1.0) < pct_infected) {
auto state = mio::abm::InfectionState(
mio::UniformIntDistribution<int>::get_instance()(prng, 1, int(mio::abm::InfectionState::Count) - 1));
auto infection = mio::abm::Infection(prng, mio::abm::VirusVariant::Wildtype, person.get_age(),
model.parameters, mio::abm::TimePoint(0), state);
person.add_new_infection(std::move(infection));
}

//equal chance of (moderate) mask refusal and (moderate) mask eagerness
auto pct_compliance_values = std::array{0.05 /*0*/, 0.2 /*0.25*/, 0.5 /*0.5*/, 0.2 /*0.75*/, 0.05 /*1*/};
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider moving these compliance weight values into a named constant or configuration to clarify their meaning and avoid inline literals.

Copilot uses AI. Check for mistakes.
auto compliance_value = 0.25 * mio::DiscreteDistribution<int>::get_instance()(prng, pct_compliance_values);
person.set_compliance(mio::abm::InterventionType::Mask, compliance_value);
}

//masks at locations
for (auto& loc : model.get_locations()) {
//some % of locations require masks
//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()(model.get_rng()) < pct_require_mask) {
loc.set_required_mask(mio::abm::MaskType::Community);
}
}

// Assign locations to the people
Expand Down
8 changes: 0 additions & 8 deletions cpp/simulations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ if(MEMILIO_HAS_JSONCPP AND MEMILIO_HAS_HDF5)
target_link_libraries(2021_vaccination_delta PRIVATE memilio ode_secirvvs Boost::filesystem ${HDF5_C_LIBRARIES})
target_compile_options(2021_vaccination_delta PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(abm_simulation abm.cpp)
target_link_libraries(abm_simulation PRIVATE memilio abm Boost::filesystem ${HDF5_C_LIBRARIES})
target_compile_options(abm_simulation PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(munich_graph_sim munich_graph_sim)
target_link_libraries(munich_graph_sim PRIVATE memilio ode_secir abm Boost::filesystem ${HDF5_C_LIBRARIES})
target_compile_options(munich_graph_sim PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(abm_braunschweig abm_braunschweig.cpp)
target_link_libraries(abm_braunschweig PRIVATE memilio abm Boost::filesystem ${HDF5_C_LIBRARIES})
target_compile_options(abm_braunschweig PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
endif()
Loading
Loading