-
Notifications
You must be signed in to change notification settings - Fork 16
1284 restructure abm examples and simulations #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xsaschako
wants to merge
10
commits into
main
Choose a base branch
from
1284-restructure-abm-examples-and-simulations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f72f233
delete examples and add some things to the other example
xsaschako b373350
Replace abm_history_example with abm_example in CMakeLists.txt and ad…
xsaschako ecae5ee
Remove abm_simulation and abm_braunschweig executables from CMakeList…
xsaschako 0571bab
restrtucture abm example
xsaschako 9eb941d
Overhaul abm example
xsaschako 5018328
delete rngs
xsaschako bfbd2ba
Remove unused namespace alias for boost::filesystem in abm.cpp
xsaschako c445721
fix
xsaschako c0866a8
another fix
xsaschako 9a4dead
fix
xsaschako File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
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*/}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.Copilot uses AI. Check for mistakes.