1919*/
2020
2121#include " lct_secir/model.h"
22+ #include " lct_secir/infection_state.h"
2223#include " lct_secir/initializer_flows.h"
2324#include " memilio/config.h"
2425#include " memilio/utils/time_series.h"
2526#include " memilio/epidemiology/uncertain_matrix.h"
27+ #include " memilio/epidemiology/lct_infection_state.h"
2628#include " memilio/math/eigen.h"
2729#include " memilio/utils/logging.h"
2830#include " memilio/compartments/simulation.h"
3335int main ()
3436{
3537 // Simple example to demonstrate how to run a simulation using an LCT-SECIR model.
38+ // One single AgeGroup/Category member is used here.
3639 // Parameters, initial values and the number of subcompartments are not meant to represent a realistic scenario.
3740 constexpr size_t NumExposed = 2 , NumInfectedNoSymptoms = 3 , NumInfectedSymptoms = 1 , NumInfectedSevere = 1 ,
3841 NumInfectedCritical = 5 ;
39- using Model = mio::lsecir::Model<NumExposed, NumInfectedNoSymptoms, NumInfectedSymptoms, NumInfectedSevere,
40- NumInfectedCritical>;
41- using LctState = Model::LctState;
42- using InfectionState = LctState::InfectionState;
43-
42+ using InfState = mio::lsecir::InfectionState;
43+ using LctState = mio::LctInfectionState<InfState, 1 , NumExposed, NumInfectedNoSymptoms, NumInfectedSymptoms,
44+ NumInfectedSevere, NumInfectedCritical, 1 , 1 >;
45+ using Model = mio::lsecir::Model<LctState>;
4446 Model model;
4547
4648 // Variable defines whether the class Initializer is used to define an initial vector from flows or whether a manually
@@ -50,34 +52,33 @@ int main()
5052 ScalarType tmax = 20 ;
5153
5254 // Set Parameters.
53- model.parameters .get <mio::lsecir::TimeExposed>() = 3.2 ;
54- model.parameters .get <mio::lsecir::TimeInfectedNoSymptoms>() = 2 .;
55- model.parameters .get <mio::lsecir::TimeInfectedSymptoms>() = 5.8 ;
56- model.parameters .get <mio::lsecir::TimeInfectedSevere>() = 9.5 ;
57- // It is also possible to change values with the set function.
58- model.parameters .set <mio::lsecir::TimeInfectedCritical>(7.1 );
55+ model.parameters .get <mio::lsecir::TimeExposed>()[0 ] = 3.2 ;
56+ model.parameters .get <mio::lsecir::TimeInfectedNoSymptoms>()[0 ] = 2 .;
57+ model.parameters .get <mio::lsecir::TimeInfectedSymptoms>()[0 ] = 5.8 ;
58+ model.parameters .get <mio::lsecir::TimeInfectedSevere>()[0 ] = 9.5 ;
59+ model.parameters .get <mio::lsecir::TimeInfectedCritical>()[0 ] = 7.1 ;
5960
60- model.parameters .get <mio::lsecir::TransmissionProbabilityOnContact>() = 0.05 ;
61+ model.parameters .get <mio::lsecir::TransmissionProbabilityOnContact>()[ 0 ] = 0.05 ;
6162
6263 mio::ContactMatrixGroup& contact_matrix = model.parameters .get <mio::lsecir::ContactPatterns>();
6364 contact_matrix[0 ] = mio::ContactMatrix (Eigen::MatrixXd::Constant (1 , 1 , 10 ));
6465 // From SimulationTime 5, the contact pattern is reduced to 30% of the initial value.
6566 contact_matrix[0 ].add_damping (0.7 , mio::SimulationTime (5 .));
6667
67- model.parameters .get <mio::lsecir::RelativeTransmissionNoSymptoms>() = 0.7 ;
68- model.parameters .get <mio::lsecir::RiskOfInfectionFromSymptomatic>() = 0.25 ;
69- model.parameters .get <mio::lsecir::RecoveredPerInfectedNoSymptoms>() = 0.09 ;
70- model.parameters .get <mio::lsecir::SeverePerInfectedSymptoms>() = 0.2 ;
71- model.parameters .get <mio::lsecir::CriticalPerSevere>() = 0.25 ;
72- model.parameters .set <mio::lsecir::DeathsPerCritical>(0.3 ) ;
68+ model.parameters .get <mio::lsecir::RelativeTransmissionNoSymptoms>()[ 0 ] = 0.7 ;
69+ model.parameters .get <mio::lsecir::RiskOfInfectionFromSymptomatic>()[ 0 ] = 0.25 ;
70+ model.parameters .get <mio::lsecir::RecoveredPerInfectedNoSymptoms>()[ 0 ] = 0.09 ;
71+ model.parameters .get <mio::lsecir::SeverePerInfectedSymptoms>()[ 0 ] = 0.2 ;
72+ model.parameters .get <mio::lsecir::CriticalPerSevere>()[ 0 ] = 0.25 ;
73+ model.parameters .get <mio::lsecir::DeathsPerCritical>()[ 0 ] = 0.3 ;
7374
7475 if (use_initializer_flows) {
7576 // Example how to use the class Initializer for the definition of an initial vector for the LCT model.
7677
77- ScalarType dt = 0.001 ;
78- ScalarType total_population = 1000000 ;
79- ScalarType deaths = 10 ;
80- ScalarType total_confirmed_cases = 16000 ;
78+ ScalarType dt = 0.001 ;
79+ mio::Vector< ScalarType> total_population = mio::Vector<ScalarType>:: Constant ( 1 , 1000000 .) ;
80+ mio::Vector< ScalarType> deaths = mio::Vector<ScalarType>:: Constant ( 1 , 10 .) ;
81+ mio::Vector< ScalarType> total_confirmed_cases = mio::Vector<ScalarType>:: Constant ( 1 , 16000 .) ;
8182
8283 // Create TimeSeries with num_transitions elements.
8384 int num_transitions = (int )mio::lsecir::InfectionTransition::Count;
@@ -120,22 +121,22 @@ int main()
120121 {50 }, {10 , 10 , 5 , 3 , 2 }, {20 }, {10 }};
121122
122123 // Assert that initial_populations has the right shape.
123- if (initial_populations.size () != (size_t )InfectionState ::Count) {
124+ if (initial_populations.size () != (size_t )InfState ::Count) {
124125 mio::log_error (
125126 " The number of vectors in initial_populations does not match the number of InfectionStates." );
126127 return 1 ;
127128 }
128- if ((initial_populations[(size_t )InfectionState ::Susceptible].size () !=
129- LctState::get_num_subcompartments<InfectionState ::Susceptible>()) ||
130- (initial_populations[(size_t )InfectionState ::Exposed].size () != NumExposed) ||
131- (initial_populations[(size_t )InfectionState ::InfectedNoSymptoms].size () != NumInfectedNoSymptoms) ||
132- (initial_populations[(size_t )InfectionState ::InfectedSymptoms].size () != NumInfectedSymptoms) ||
133- (initial_populations[(size_t )InfectionState ::InfectedSevere].size () != NumInfectedSevere) ||
134- (initial_populations[(size_t )InfectionState ::InfectedCritical].size () != NumInfectedCritical) ||
135- (initial_populations[(size_t )InfectionState ::Recovered].size () !=
136- LctState::get_num_subcompartments<InfectionState ::Recovered>()) ||
137- (initial_populations[(size_t )InfectionState ::Dead].size () !=
138- LctState::get_num_subcompartments<InfectionState ::Dead>())) {
129+ if ((initial_populations[(size_t )InfState ::Susceptible].size () !=
130+ LctState::get_num_subcompartments<InfState ::Susceptible>()) ||
131+ (initial_populations[(size_t )InfState ::Exposed].size () != NumExposed) ||
132+ (initial_populations[(size_t )InfState ::InfectedNoSymptoms].size () != NumInfectedNoSymptoms) ||
133+ (initial_populations[(size_t )InfState ::InfectedSymptoms].size () != NumInfectedSymptoms) ||
134+ (initial_populations[(size_t )InfState ::InfectedSevere].size () != NumInfectedSevere) ||
135+ (initial_populations[(size_t )InfState ::InfectedCritical].size () != NumInfectedCritical) ||
136+ (initial_populations[(size_t )InfState ::Recovered].size () !=
137+ LctState::get_num_subcompartments<InfState ::Recovered>()) ||
138+ (initial_populations[(size_t )InfState ::Dead].size () !=
139+ LctState::get_num_subcompartments<InfState ::Dead>())) {
139140 mio::log_error (
140141 " The length of at least one vector in initial_populations does not match the related number of "
141142 " subcompartments." );
@@ -148,15 +149,16 @@ int main()
148149 flat_initial_populations.insert (flat_initial_populations.end (), vec.begin (), vec.end ());
149150 }
150151 for (size_t i = 0 ; i < LctState::Count; i++) {
151- model.populations [mio::Index<LctState>(i) ] = flat_initial_populations[i];
152+ model.populations [i ] = flat_initial_populations[i];
152153 }
153154 }
154155
155156 // Perform a simulation.
156157 mio::TimeSeries<ScalarType> result = mio::simulate<ScalarType, Model>(0 , tmax, 0.5 , model);
158+ // result.print_table({"S", "E", "C", "I", "H", "U", "R", "D "}, 16, 8);
157159 // The simulation result is divided by subcompartments.
158160 // We call the function calculate_comparttments to get a result according to the InfectionStates.
159161 mio::TimeSeries<ScalarType> population_no_subcompartments = model.calculate_compartments (result);
160162 auto interpolated_results = mio::interpolate_simulation_result (population_no_subcompartments);
161163 interpolated_results.print_table ({" S" , " E" , " C" , " I" , " H" , " U" , " R" , " D " }, 16 , 8 );
162- }
164+ }
0 commit comments