You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cpp-tutorials/exercises/exercise01.cpp
+22-7Lines changed: 22 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,21 @@
4
4
5
5
intmain()
6
6
{
7
-
// MEmilio implements various models based on ordinary differential equations (ODEs). ODE-based models are a subclass of compartmental models in which individuals are grouped into subpopulations called compartments.
7
+
// MEmilio implements various models based on ordinary differential equations (ODEs). ODE-based models are a
8
+
// subclass of compartmental models in which individuals are grouped into subpopulations called compartments.
8
9
9
-
// In this tutorial we will setup and run MEmilio's ODE-based SECIR-type model. This model is particularly suited for pathogens with pre- or asymptomatic infection states and when severe or critical symptoms are possible. The model assumes perfect immunity after recovery. The used infection states or compartments are Susceptible (S), Exposed(E), Non-symptomatically Infected (Ins), Symptomatically Infected (Isy), Severely Infected (Isev), Critically Infected (Icri), Dead (D) and Recovered (R). The transitions are depicted in the following figure.
10
+
// In this tutorial we will setup and run MEmilio's ODE-based SECIR-type model. This model is particularly
11
+
// suited for pathogens with pre- or asymptomatic infection states and when severe or critical symptoms are possible.
12
+
// The model assumes perfect immunity after recovery. The used infection states or compartments are Susceptible (S),
// Critically Infected (Icri), Dead (D) and Recovered (R). The transitions are depicted in the following figure.
10
15
11
16
// *** Set up model. ***
12
-
// We need to specify basic parameters. In this tutorial, we use a simple model without spatial resolution and with only one age group.
17
+
// We need to specify basic parameters. In this tutorial, we use a simple model without spatial resolution and
18
+
// with only one age group.
13
19
size_t num_agegroups = 1;
14
-
// We first define the `total_population` size and the simulation horizong through the start day `t0`, and the simulation's end point `tmax`. By default, the ODE is solved with adaptive time stepping and the initial time step is `dt`.
20
+
// We first define the `total_population` size and the simulation horizong through the start day `t0`, and the
21
+
// simulation's end point `tmax`. By default, the ODE is solved with adaptive time stepping and the initial time step is `dt`.
// Next, we have to set the epidemiological model parameters which include the average stay times per infection state, the state transition probabilities, and the contact frequency. A list of all parameters can be found at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html. The parameters can be set as follows:
30
+
// Next, we have to set the epidemiological model parameters which include the average stay times per infection
31
+
// state, the state transition probabilities, and the contact frequency. A list of all parameters can be found
32
+
// at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html. The parameters can be set as follows:
// EXERCISE: Please set the average time individuals spend in the exposed state (TimeExposed) to 4 days
44
53
45
-
// In addition to the parameters, the initial number of individuals in each compartment has to be set. If a compartment is not set, its initial value is zero by default. In this example, we start our simulation with 1 % of the population initially infected, distributing them equally to the `Exposed` and the `InfectedNoSymptoms` state, where the latter contains pre- and asymptomatic infectious individuals. With the last line, we set the remaining part of the population (99%) to be susceptible.
54
+
// In addition to the parameters, the initial number of individuals in each compartment has to be set. If a
55
+
// compartment is not set, its initial value is zero by default. In this example, we start our simulation with 1 %
56
+
// of the population initially infected, distributing them equally to the `Exposed` and the `InfectedNoSymptoms`
57
+
// state, where the latter contains pre- and asymptomatic infectious individuals. With the last line,
58
+
// we set the remaining part of the population (99%) to be susceptible.
// EXERCISE: Please set 2% of the population initially infected. The initially infected should be distributed to the compartpartments as follows: 0.5% is initially exposed (state `Exposed`), 0.5% is non-symptomatically infected (state `InfectedNosymptoms`) and 1% is symptomatically infected (state `InfectedSymptoms`).
52
65
53
-
// To check that all initial parameter and compartmental values are in a meaningful range, MEmilio provides the `check_constraints` function. If a value exceeds its meaningful range, a warning is printed and the function returns `True`, otherwise it returns `False`.
66
+
// To check that all initial parameter and compartmental values are in a meaningful range, MEmilio provides the
67
+
// `check_constraints` function. If a value exceeds its meaningful range, a warning is printed and the function
Copy file name to clipboardExpand all lines: cpp-tutorials/exercises/exercise03.cpp
+15-4Lines changed: 15 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,12 @@
4
4
5
5
intmain()
6
6
{
7
-
// In the previous tutorial, we created, initialized and simulated MEmilio's ODE-based SECIR-type model with one (age) group. In this tutorial, we will show how to incorporate non-pharmaceutical interventions (NPIs) through the use of `Dampings` in the ODE-based SECIR-type model.
7
+
// In the previous tutorial, we created, initialized and simulated MEmilio's ODE-based SECIR-type model with one
8
+
// (age) group. In this tutorial, we will show how to incorporate non-pharmaceutical interventions (NPIs) through
9
+
// the use of `Dampings` in the ODE-based SECIR-type model.
8
10
9
11
// *** Set up model. ***
10
-
// First we create and initialize a SECIR-type model with one age group. For a detailed description on taht, see Tutorial 1.
12
+
// First we create and initialize a SECIR-type model with one age group. For a detailed description, see Tutorial 1.
11
13
size_t num_agegroups = 1;
12
14
ScalarType total_population = 100000;
13
15
ScalarType t0 = 0;
@@ -39,13 +41,22 @@ int main()
39
41
40
42
// EXERCISE: Please set the model's contact frequency to 10.
41
43
42
-
// After the model initialization, we add a contact reduction (`Damping`) that represents an NPI like e.g. mask wearing or social distancing. Dampings are a factor applied to the contact frequency and can be added to the model at fixed simulation time points before simulating. They have a *Level* and a *Type*. A damping with a given level and type replaces the previously active one with the same level and type, while all currently active dampings of one level and different types are summed up. If two dampings have different levels (independent of the type) they are combined multiplicatively. In the following we apply a `Damping` of 0.9 after 10 days and another damping of 0.6 after 20 days which means that the contacts are reduced by 10% and 40%, respectively. To always retain a minimum level of contacts, a minimum contact frequency can be set that is never deceeded. In our example we set this minimum contact rate to 0.
44
+
// After the model initialization, we add a contact reduction (`Damping`) that represents an NPI like
45
+
// mask wearing or social distancing. Dampings are a factor applied to the contact frequency and can be added
46
+
// to the model at fixed simulation time points before simulating. They have a *Level* and a *Type*.
47
+
// A damping with a given level and type replaces the previously active one with the same level and type, while
48
+
// all currently active dampings of one level and different types are summed up. If two dampings have different
49
+
// levels (independent of the type) they are combined multiplicatively. In the following we apply a `Damping`
50
+
// of 0.9 after 10 days and another damping of 0.6 after 20 days which means that the contacts are reduced
51
+
// by 10% and 40%, respectively. To always retain a minimum level of contacts, a minimum contact frequency can
52
+
// be set that is never deceeded. In our example we set this minimum contact rate to 0.
//EXERCISE: Please create a damping that replaces the 10% reduction after 10 days by a 20% reduction. Additionally, add a damping after 40 days that increases the contact rate by 50%.
47
57
48
-
// Again, we start with 0.5% of the population initially in `Exposed` and 0.5% initially in `InfectedNoSymptoms` while the remaining 99% is `Susceptible`.
58
+
// Again, we start with 0.5% of the population initially in `Exposed` and 0.5% initially in `InfectedNoSymptoms`
Copy file name to clipboardExpand all lines: cpp-tutorials/exercises/exercise07.cpp
+21-8Lines changed: 21 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -8,24 +8,31 @@
8
8
9
9
intmain()
10
10
{
11
-
// In the previous tutorials, we saw how to set up and run an age-resolved ODE-based SECIR-type model. However, one limiting assumption of simple ODE-based models is the assumption of homogenous mixing within the population. To overcome this limitation and incorporate spatial heterogeneity, in this example we show how to use MEmilio's graph-based metapopulation model. This model realizes mobility between regions via graph edges, while every region is represented by a graph node containing it's own ODE-based model.
11
+
// In the previous tutorials, we saw how to set up and run an age-resolved ODE-based SECIR-type model.
12
+
// However, one limiting assumption of simple ODE-based models is the assumption of homogenous mixing within
13
+
// the population. To overcome this limitation and incorporate spatial heterogeneity, in this example we show
14
+
// how to use MEmilio's graph-based metapopulation model. This model realizes mobility between regions via
15
+
// graph edges, while every region is represented by a graph node containing it's own ODE-based model.
12
16
13
17
// *** Set up model. ***
14
18
// We set the simulation start time `t0`, the end time `tmax` and the initial step size `dt` as:
15
19
ScalarType t0 = 0;
16
20
ScalarType tmax = 100;
17
21
ScalarType dt = 0.1;
18
22
19
-
// Next, we need to specify the parameters. We will initialize a metapopulation model with two regions. The total population as well as the epidemiological parameters will be the same for both regions.
23
+
// Next, we need to specify the parameters. We will initialize a metapopulation model with two regions.
24
+
// The total population as well as the epidemiological parameters will be the same for both regions.
20
25
ScalarType total_population_per_region = 100000;
21
26
22
27
// We use a model with three age groups for both regions:
// Now, we have to set the epidemiological model parameters which are dependent on age group. A list of all parameters can be found at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html.
28
-
// We choose an increasing risk of severe and critical infections for age group 2 and 3 compared to age group 1. The other parameters are equal for all age groups.
32
+
// Now, we have to set the epidemiological model parameters which are dependent on age group. A list of all
33
+
// parameters can be found at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html.
34
+
// We choose an increasing risk of severe and critical infections for age group 2 and 3 compared to age group 1.
35
+
// The other parameters are equal for all age groups.
29
36
30
37
for (size_t i = 0; i < num_agegroups; i++) {
31
38
// Set infection state stay times (in days)
@@ -65,7 +72,11 @@ int main()
65
72
auto model_region1 = model;
66
73
auto model_region2 = model;
67
74
68
-
// In the graph-based metapopulation model, every graph node gets it's own ODE-based model which is copied when adding a graph node and handing the model to it as parameter. Therefore we can choose different initial conditions (as well as differing parameters) for different graph nodes. In our example, we simulate two regions with only one region having initially infected individuals. We choose 1% initially infected for that region while the other region starts with a totally susceptible population.
75
+
// In the graph-based metapopulation model, every graph node gets it's own ODE-based model which is copied when
76
+
// adding a graph node and handing the model to it as parameter. Therefore we can choose different initial conditions
77
+
// (as well as differing parameters) for different graph nodes. In our example, we simulate two regions with only one
78
+
// region having initially infected individuals. We choose 1% initially infected for that region while the other
79
+
// region starts with a totally susceptible population.
69
80
// The model compartments for the first node are initialized via:
//EXERCISE: Please add the second node to the graph.
89
-
90
-
// If we would simulate the graph-based metapopulation model now, we would just have two independent ODE-based SECIR-type models running with different initial conditions. In reality, there is usually exchange between regions through individuals travelling or commuting from one region to another. This can be realized via graph edges.
91
-
// We here use a symmetric mobility i.e. we have the same number of individuals that travel from node 0 to node 1 as vice versa. We let 10% of the population commute via the edges twice a day.
100
+
// If we would simulate the graph-based metapopulation model now, we would just have two independent ODE-based
101
+
// SECIR-type models running with different initial conditions. In reality, there is usually exchange between
102
+
// regions through individuals travelling or commuting from one region to another. This can be realized via graph edges.
103
+
// We here use a symmetric mobility i.e. we have the same number of individuals that travel from node 0 to node 1
104
+
// as vice versa. We let 10% of the population commute via the edges twice a day.
0 commit comments