|
| 1 | + |
| 2 | +#include "ide_secir/model.h" |
| 3 | +#include "ide_secir/infection_state.h" |
| 4 | +#include "ide_secir/simulation.h" |
| 5 | +#include "memilio/config.h" |
| 6 | +#include "memilio/epidemiology/age_group.h" |
| 7 | +#include "memilio/math/eigen.h" |
| 8 | +#include "memilio/utils/custom_index_array.h" |
| 9 | +#include "memilio/utils/time_series.h" |
| 10 | +#include "memilio/epidemiology/uncertain_matrix.h" |
| 11 | +#include "memilio/epidemiology/state_age_function.h" |
| 12 | +#include "memilio/data/analyze_result.h" |
| 13 | + |
| 14 | +int main() |
| 15 | +{ |
| 16 | + using Vec = mio::TimeSeries<ScalarType>::Vector; |
| 17 | + |
| 18 | + size_t num_agegroups = 2; |
| 19 | + |
| 20 | + ScalarType tmax = 5; |
| 21 | + mio::CustomIndexArray<ScalarType, mio::AgeGroup> N = |
| 22 | + mio::CustomIndexArray<ScalarType, mio::AgeGroup>(mio::AgeGroup(num_agegroups), 10000.); |
| 23 | + mio::CustomIndexArray<ScalarType, mio::AgeGroup> deaths = |
| 24 | + mio::CustomIndexArray<ScalarType, mio::AgeGroup>(mio::AgeGroup(num_agegroups), 6.); |
| 25 | + ScalarType dt = 1.; |
| 26 | + |
| 27 | + int num_transitions = (int)mio::isecir::InfectionTransition::Count; |
| 28 | + |
| 29 | + // Create TimeSeries with num_transitions * num_agegroups elements where transitions needed for simulation will be |
| 30 | + // stored. |
| 31 | + mio::TimeSeries<ScalarType> init(num_transitions * num_agegroups); |
| 32 | + |
| 33 | + // Add time points for initialization of transitions. |
| 34 | + Vec vec_init(num_transitions * num_agegroups); |
| 35 | + // Values for the Infectiontransitions are the same for all AgeGroups. |
| 36 | + for (size_t group = 0; group < num_agegroups; ++group) { |
| 37 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::SusceptibleToExposed] = 25.0; |
| 38 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::ExposedToInfectedNoSymptoms] = 15.0; |
| 39 | + vec_init[group * num_transitions + |
| 40 | + (int)mio::isecir::InfectionTransition::InfectedNoSymptomsToInfectedSymptoms] = 8.0; |
| 41 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::InfectedNoSymptomsToRecovered] = 4.0; |
| 42 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::InfectedSymptomsToInfectedSevere] = |
| 43 | + 1.0; |
| 44 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::InfectedSymptomsToRecovered] = 4.0; |
| 45 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::InfectedSevereToInfectedCritical] = |
| 46 | + 1.0; |
| 47 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::InfectedSevereToRecovered] = 1.0; |
| 48 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::InfectedCriticalToDead] = 1.0; |
| 49 | + vec_init[group * num_transitions + (int)mio::isecir::InfectionTransition::InfectedCriticalToRecovered] = 1.0; |
| 50 | + } |
| 51 | + |
| 52 | + // Add initial time point to time series. |
| 53 | + init.add_time_point(-10, vec_init); |
| 54 | + // Add further time points until time 0. |
| 55 | + while (init.get_last_time() < -dt / 2) { |
| 56 | + init.add_time_point(init.get_last_time() + dt, vec_init); |
| 57 | + } |
| 58 | + |
| 59 | + // Initialize model. |
| 60 | + mio::isecir::Model model(std::move(init), N, deaths, num_agegroups); |
| 61 | + |
| 62 | + // Uncomment these lines to use a different method to initialize the model using the TimeSeries init. |
| 63 | + // Initialization method with Susceptibles. |
| 64 | + // model.m_populations.get_last_value()[(Eigen::Index)mio::isecir::InfectionState::Susceptible] = 1000; |
| 65 | + // model.m_populations.get_last_value()[(Eigen::Index)mio::isecir::InfectionState::Count + |
| 66 | + // (Eigen::Index)mio::isecir::InfectionState::Susceptible] = 1000; |
| 67 | + // Initialization method with Recovered. |
| 68 | + // model.m_populations.get_last_value()[(Eigen::Index)mio::isecir::InfectionState::Recovered] = 0; |
| 69 | + // model.m_populations.get_last_value()[(Eigen::Index)mio::isecir::InfectionState::Count + |
| 70 | + // (Eigen::Index)mio::isecir::InfectionState::Recovered] = 0; |
| 71 | + |
| 72 | + // Set working parameters. |
| 73 | + // First AgeGroup for Transition Distributions. |
| 74 | + mio::SmootherCosine smoothcos1(2.0); |
| 75 | + mio::StateAgeFunctionWrapper delaydistribution1(smoothcos1); |
| 76 | + std::vector<mio::StateAgeFunctionWrapper> vec_delaydistrib1(num_transitions, delaydistribution1); |
| 77 | + // TransitionDistribution is not used for SusceptibleToExposed. Therefore, the parameter can be set to any value. |
| 78 | + vec_delaydistrib1[(int)mio::isecir::InfectionTransition::SusceptibleToExposed].set_distribution_parameter(-1.); |
| 79 | + |
| 80 | + model.parameters.get<mio::isecir::TransitionDistributions>()[mio::AgeGroup(0)] = vec_delaydistrib1; |
| 81 | + |
| 82 | + //Second AgeGroup for Transition Distributions. |
| 83 | + mio::SmootherCosine smoothcos2(3.0); |
| 84 | + mio::StateAgeFunctionWrapper delaydistribution2(smoothcos2); |
| 85 | + std::vector<mio::StateAgeFunctionWrapper> vec_delaydistrib2(num_transitions, delaydistribution2); |
| 86 | + // TransitionDistribution is not used for SusceptibleToExposed. Therefore, the parameter can be set to any value. |
| 87 | + vec_delaydistrib2[(int)mio::isecir::InfectionTransition::SusceptibleToExposed].set_distribution_parameter(-1.); |
| 88 | + |
| 89 | + model.parameters.get<mio::isecir::TransitionDistributions>()[mio::AgeGroup(1)] = vec_delaydistrib2; |
| 90 | + |
| 91 | + std::vector<ScalarType> vec_prob(num_transitions, 0.5); |
| 92 | + // The following probabilities must be 1, as there is no other way to go. |
| 93 | + vec_prob[Eigen::Index(mio::isecir::InfectionTransition::SusceptibleToExposed)] = 1; |
| 94 | + vec_prob[Eigen::Index(mio::isecir::InfectionTransition::ExposedToInfectedNoSymptoms)] = 1; |
| 95 | + for (mio::AgeGroup group = mio::AgeGroup(0); group < mio::AgeGroup(num_agegroups); ++group) { |
| 96 | + model.parameters.get<mio::isecir::TransitionProbabilities>()[group] = vec_prob; |
| 97 | + } |
| 98 | + |
| 99 | + mio::ContactMatrixGroup contact_matrix = mio::ContactMatrixGroup(1, static_cast<Eigen::Index>(num_agegroups)); |
| 100 | + contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant(num_agegroups, num_agegroups, 10.)); |
| 101 | + model.parameters.get<mio::isecir::ContactPatterns>() = mio::UncertainContactMatrix(contact_matrix); |
| 102 | + |
| 103 | + mio::ExponentialSurvivalFunction exponential(0.5); |
| 104 | + mio::StateAgeFunctionWrapper prob(exponential); |
| 105 | + for (mio::AgeGroup group = mio::AgeGroup(0); group < mio::AgeGroup(num_agegroups); ++group) { |
| 106 | + model.parameters.get<mio::isecir::TransmissionProbabilityOnContact>()[group] = prob; |
| 107 | + model.parameters.get<mio::isecir::RelativeTransmissionNoSymptoms>()[group] = prob; |
| 108 | + model.parameters.get<mio::isecir::RiskOfInfectionFromSymptomatic>()[group] = prob; |
| 109 | + } |
| 110 | + model.parameters.set<mio::isecir::Seasonality>(0.1); |
| 111 | + // Start the simulation on the 40th day of a year (i.e. in February). |
| 112 | + model.parameters.set<mio::isecir::StartDay>(40); |
| 113 | + |
| 114 | + model.check_constraints(dt); |
| 115 | + |
| 116 | + // Carry out simulation. |
| 117 | + mio::isecir::Simulation sim(model, dt); |
| 118 | + sim.advance(tmax); |
| 119 | + |
| 120 | + auto interpolated_results = mio::interpolate_simulation_result(sim.get_result(), dt / 2.); |
| 121 | + |
| 122 | + interpolated_results.print_table( |
| 123 | + {"S1", "E1", "C1", "I1", "H1", "U1", "R1", "D1 ", "S2", "E2", "C2", "I2", "H2", "U2", "R2", "D2 "}, 16, 8); |
| 124 | + // Uncomment this line to print the transitions. |
| 125 | + // sim.get_transitions().print_table({"S->E 1", "E->C 1", "C->I 1", "C->R 1", "I->H 1", "I->R 1", "H->U 1", |
| 126 | + // "H->R 1", "U->D 1", "U->R 1", "S->E 2", "E->C 2", "C->I 2", "C->R 2", |
| 127 | + // "I->H 2", "I->R 2", "H->U 2", "H->R 2", "U->D 2", "U->R 2"}, |
| 128 | + // 16, 8); |
| 129 | +} |
0 commit comments