|
25 | 25 | #include "memilio/utils/time_series.h"
|
26 | 26 | #include "memilio/epidemiology/uncertain_matrix.h"
|
27 | 27 | #include "memilio/math/eigen.h"
|
| 28 | +#include "memilio/utils/logging.h" |
| 29 | + |
28 | 30 | #include <vector>
|
29 | 31 |
|
30 | 32 | int main()
|
31 | 33 | {
|
32 |
| - /** Simple example to demonstrate how to run a simulation using an LCT SECIR model. |
33 |
| - Parameters, initial values and subcompartments are not meant to represent a realistic scenario. */ |
| 34 | + // Simple example to demonstrate how to run a simulation using an LCT SECIR model. |
| 35 | + // Parameters, initial values and the number of subcompartments are not meant to represent a realistic scenario. |
34 | 36 |
|
35 |
| - // Set vector that specifies the number of subcompartments. |
36 |
| - std::vector<int> num_subcompartments((int)mio::lsecir::InfectionStateBase::Count, 1); |
37 |
| - num_subcompartments[(int)mio::lsecir::InfectionStateBase::Exposed] = 2; |
38 |
| - num_subcompartments[(int)mio::lsecir::InfectionStateBase::InfectedNoSymptoms] = 3; |
39 |
| - num_subcompartments[(int)mio::lsecir::InfectionStateBase::InfectedCritical] = 5; |
40 |
| - mio::lsecir::InfectionState infection_state(num_subcompartments); |
| 37 | + using Model = mio::lsecir::Model<2, 3, 1, 1, 5>; |
| 38 | + using LctState = Model::LctState; |
41 | 39 |
|
42 | 40 | ScalarType tmax = 20;
|
43 | 41 |
|
44 |
| - // Define initial distribution of the population in the subcompartments. |
45 |
| - Eigen::VectorXd init(infection_state.get_count()); |
46 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::Susceptible)] = 750; |
47 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::Exposed)] = 30; |
48 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::Exposed) + 1] = 20; |
49 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedNoSymptoms)] = 20; |
50 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedNoSymptoms) + 1] = 10; |
51 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedNoSymptoms) + 2] = 10; |
52 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedSymptoms)] = 50; |
53 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedSevere)] = 50; |
54 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedCritical)] = 10; |
55 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedCritical) + 1] = 10; |
56 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedCritical) + 2] = 5; |
57 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedCritical) + 3] = 3; |
58 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::InfectedCritical) + 4] = 2; |
59 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::Recovered)] = 20; |
60 |
| - init[infection_state.get_firstindex(mio::lsecir::InfectionStateBase::Dead)] = 10; |
| 42 | + // Define the initial value vector init with the distribution of the population into subcompartments. |
| 43 | + // This method of defining the vector using a vector of vectors is a bit of overhead, but should remind you how |
| 44 | + // the entries of the initial value vector relate to the defined template parameters of the model or the number of subcompartments. |
| 45 | + // It is also possible to define the initial value vector directly. |
| 46 | + std::vector<std::vector<ScalarType>> initial_populations = {{750}, {30, 20}, {20, 10, 10}, {50}, |
| 47 | + {50}, {10, 10, 5, 3, 2}, {20}, {10}}; |
| 48 | + |
| 49 | + // Assert that initial_populations has the right shape. |
| 50 | + if (initial_populations.size() != (int)LctState::InfectionState::Count) { |
| 51 | + mio::log_error("The number of vectors in initial_populations does not match the number of InfectionStates."); |
| 52 | + return 1; |
| 53 | + } |
| 54 | + if ((initial_populations[(int)LctState::InfectionState::Susceptible].size() != |
| 55 | + LctState::get_num_subcompartments<LctState::InfectionState::Susceptible>()) || |
| 56 | + (initial_populations[(int)LctState::InfectionState::Exposed].size() != |
| 57 | + LctState::get_num_subcompartments<LctState::InfectionState::Exposed>()) || |
| 58 | + (initial_populations[(int)LctState::InfectionState::InfectedNoSymptoms].size() != |
| 59 | + LctState::get_num_subcompartments<LctState::InfectionState::InfectedNoSymptoms>()) || |
| 60 | + (initial_populations[(int)LctState::InfectionState::InfectedSymptoms].size() != |
| 61 | + LctState::get_num_subcompartments<LctState::InfectionState::InfectedSymptoms>()) || |
| 62 | + (initial_populations[(int)LctState::InfectionState::InfectedSevere].size() != |
| 63 | + LctState::get_num_subcompartments<LctState::InfectionState::InfectedSevere>()) || |
| 64 | + (initial_populations[(int)LctState::InfectionState::InfectedCritical].size() != |
| 65 | + LctState::get_num_subcompartments<LctState::InfectionState::InfectedCritical>()) || |
| 66 | + (initial_populations[(int)LctState::InfectionState::Recovered].size() != |
| 67 | + LctState::get_num_subcompartments<LctState::InfectionState::Recovered>()) || |
| 68 | + (initial_populations[(int)LctState::InfectionState::Dead].size() != |
| 69 | + LctState::get_num_subcompartments<LctState::InfectionState::Dead>())) { |
| 70 | + mio::log_error("The length of at least one vector in initial_populations does not match the related number of " |
| 71 | + "subcompartments."); |
| 72 | + return 1; |
| 73 | + } |
| 74 | + |
| 75 | + // Transfer the initial values in initial_populations to the vector init. |
| 76 | + Eigen::VectorXd init = Eigen::VectorXd::Zero(LctState::Count); |
| 77 | + init[(int)LctState::get_first_index<LctState::InfectionState::Susceptible>()] = |
| 78 | + initial_populations[(int)LctState::InfectionState::Susceptible][0]; |
| 79 | + for (unsigned int i = 0; i < LctState::get_num_subcompartments<LctState::InfectionState::Exposed>(); i++) { |
| 80 | + init[(int)LctState::get_first_index<LctState::InfectionState::Exposed>() + i] = |
| 81 | + initial_populations[(int)LctState::InfectionState::Exposed][i]; |
| 82 | + } |
| 83 | + for (unsigned int i = 0; i < LctState::get_num_subcompartments<LctState::InfectionState::InfectedNoSymptoms>(); |
| 84 | + i++) { |
| 85 | + init[(int)LctState::get_first_index<LctState::InfectionState::InfectedNoSymptoms>() + i] = |
| 86 | + initial_populations[(int)LctState::InfectionState::InfectedNoSymptoms][i]; |
| 87 | + } |
| 88 | + for (unsigned int i = 0; i < LctState::get_num_subcompartments<LctState::InfectionState::InfectedSymptoms>(); i++) { |
| 89 | + init[(int)LctState::get_first_index<LctState::InfectionState::InfectedSymptoms>() + i] = |
| 90 | + initial_populations[(int)LctState::InfectionState::InfectedSymptoms][i]; |
| 91 | + } |
| 92 | + for (unsigned int i = 0; i < LctState::get_num_subcompartments<LctState::InfectionState::InfectedSevere>(); i++) { |
| 93 | + init[(int)LctState::get_first_index<LctState::InfectionState::InfectedSevere>() + i] = |
| 94 | + initial_populations[(int)LctState::InfectionState::InfectedSevere][i]; |
| 95 | + } |
| 96 | + for (unsigned int i = 0; i < LctState::get_num_subcompartments<LctState::InfectionState::InfectedCritical>(); i++) { |
| 97 | + init[(int)LctState::get_first_index<LctState::InfectionState::InfectedCritical>() + i] = |
| 98 | + initial_populations[(int)LctState::InfectionState::InfectedCritical][i]; |
| 99 | + } |
| 100 | + init[(int)LctState::get_first_index<LctState::InfectionState::Recovered>()] = |
| 101 | + initial_populations[(int)LctState::InfectionState::Recovered][0]; |
| 102 | + init[(int)LctState::get_first_index<LctState::InfectionState::Dead>()] = |
| 103 | + initial_populations[(int)LctState::InfectionState::Dead][0]; |
61 | 104 |
|
62 | 105 | // Initialize model.
|
63 |
| - mio::lsecir::Model model(std::move(init), infection_state); |
| 106 | + Model model(std::move(init)); |
64 | 107 |
|
65 | 108 | // Set Parameters.
|
66 | 109 | model.parameters.get<mio::lsecir::TimeExposed>() = 3.2;
|
|
0 commit comments