Next Steps
We have created several new modules. We need to make sure they are each
initialized with the Context before the simulation starts. Below is main.rs
in its entirety.
// main.rs
// ANCHOR: header
mod incidence_report;
mod infection_manager;
mod people;
mod transmission_manager;
use ixa::{error, info, run_with_args, Context};
static POPULATION: u64 = 100;
static FORCE_OF_INFECTION: f64 = 0.1;
static INFECTION_DURATION: f64 = 10.0;
static MAX_TIME: f64 = 200.0;
// ANCHOR_END: header
fn main() {
let result = run_with_args(|context: &mut Context, _args, _| {
// Add a plan to shut down the simulation after `max_time`, regardless of
// what else is happening in the model.
context.add_plan(MAX_TIME, |context| {
context.shutdown();
});
people::init(context);
transmission_manager::init(context);
infection_manager::init(context);
incidence_report::init(context).expect("Failed to init incidence report");
Ok(())
});
match result {
Ok(_) => {
info!("Simulation finished executing");
}
Err(e) => {
error!("Simulation exited with error: {}", e);
}
}
}
Exercises
- Currently the simulation runs until
MAX_TIMEeven if every single person has been infected and has recovered. Add a check somewhere that callscontext.shutdown()if there is no more work for the simulation to do. Where should this check live? Hint: Usecontext.query_entity_count. - Analyze the data output by the incident reporter. Plot the number of people
with each
InfectionStatuson the same axis to see how they change over the course of the simulation. Are the curves what we expect to see given our abstract model? Hint: Remember this model has a fixed force of infection, unlike a typical SIR model. - Add another property that moderates the risk of infection of the individual.
(Imagine, for example, that some people wash their hands more frequently.)
Give a randomly sampled subpopulation that intervention and add a check to
the transmission module to see if the person that we are attempting to infect
has that property. Change the probability of infection accordingly.
Hint: You will probably need some new constants, a new person property, a new
random number generator, and the
Bernoullidistribution.