|
| 1 | +/* |
| 2 | +* Copyright (C) 2020-2024 German Aerospace Center (DLR-SC) |
| 3 | +* |
| 4 | +* Authors: Julia Bicker, René Schmieding |
| 5 | +* |
| 6 | +* Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de> |
| 7 | +* |
| 8 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | +* you may not use this file except in compliance with the License. |
| 10 | +* You may obtain a copy of the License at |
| 11 | +* |
| 12 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +* |
| 14 | +* Unless required by applicable law or agreed to in writing, software |
| 15 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +* See the License for the specific language governing permissions and |
| 18 | +* limitations under the License. |
| 19 | +*/ |
| 20 | + |
| 21 | +#include "smm/simulation.h" |
| 22 | +#include "smm/parameters.h" |
| 23 | +#include "memilio/data/analyze_result.h" |
| 24 | +#include "memilio/epidemiology/adoption_rate.h" |
| 25 | + |
| 26 | +enum class InfectionState |
| 27 | +{ |
| 28 | + S, |
| 29 | + E, |
| 30 | + C, |
| 31 | + I, |
| 32 | + R, |
| 33 | + D, |
| 34 | + Count |
| 35 | + |
| 36 | +}; |
| 37 | + |
| 38 | +int main() |
| 39 | +{ |
| 40 | + |
| 41 | + //Example how to run the stochastic metapopulation models with four regions |
| 42 | + const size_t num_regions = 4; |
| 43 | + using Model = mio::smm::Model<num_regions, InfectionState>; |
| 44 | + |
| 45 | + double numE = 12, numC = 4, numI = 12, numR = 0, numD = 0; |
| 46 | + |
| 47 | + Model model; |
| 48 | + //Population are distributed uniformly to the four regions |
| 49 | + for (size_t r = 0; r < num_regions; ++r) { |
| 50 | + model.populations[{mio::regions::Region(r), InfectionState::S}] = |
| 51 | + (1000 - numE - numC - numI - numR - numD) / num_regions; |
| 52 | + model.populations[{mio::regions::Region(r), InfectionState::E}] = numE / num_regions; |
| 53 | + model.populations[{mio::regions::Region(r), InfectionState::C}] = numC / num_regions; |
| 54 | + model.populations[{mio::regions::Region(r), InfectionState::I}] = numI / num_regions; |
| 55 | + model.populations[{mio::regions::Region(r), InfectionState::R}] = numR / num_regions; |
| 56 | + model.populations[{mio::regions::Region(r), InfectionState::D}] = numD / num_regions; |
| 57 | + } |
| 58 | + |
| 59 | + //Set infection state adoption and spatial transition rates |
| 60 | + std::vector<mio::AdoptionRate<InfectionState>> adoption_rates; |
| 61 | + std::vector<mio::smm::TransitionRate<InfectionState>> transition_rates; |
| 62 | + for (size_t r = 0; r < num_regions; ++r) { |
| 63 | + adoption_rates.push_back({InfectionState::S, |
| 64 | + InfectionState::E, |
| 65 | + mio::regions::Region(r), |
| 66 | + 0.1, |
| 67 | + {{InfectionState::C, 1}, {InfectionState::I, 0.5}}}); |
| 68 | + adoption_rates.push_back({InfectionState::E, InfectionState::C, mio::regions::Region(r), 1.0 / 5., {}}); |
| 69 | + adoption_rates.push_back({InfectionState::C, InfectionState::R, mio::regions::Region(r), 0.2 / 3., {}}); |
| 70 | + adoption_rates.push_back({InfectionState::C, InfectionState::I, mio::regions::Region(r), 0.8 / 3., {}}); |
| 71 | + adoption_rates.push_back({InfectionState::I, InfectionState::R, mio::regions::Region(r), 0.99 / 5., {}}); |
| 72 | + adoption_rates.push_back({InfectionState::I, InfectionState::D, mio::regions::Region(r), 0.01 / 5., {}}); |
| 73 | + } |
| 74 | + |
| 75 | + //Agents in infection state D do not transition |
| 76 | + for (size_t s = 0; s < static_cast<size_t>(InfectionState::D); ++s) { |
| 77 | + for (size_t i = 0; i < num_regions; ++i) { |
| 78 | + for (size_t j = 0; j < num_regions; ++j) |
| 79 | + if (i != j) { |
| 80 | + transition_rates.push_back( |
| 81 | + {InfectionState(s), mio::regions::Region(i), mio::regions::Region(j), 0.01}); |
| 82 | + transition_rates.push_back( |
| 83 | + {InfectionState(s), mio::regions::Region(j), mio::regions::Region(i), 0.01}); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + model.parameters.get<mio::smm::AdoptionRates<InfectionState>>() = adoption_rates; |
| 89 | + model.parameters.get<mio::smm::TransitionRates<InfectionState>>() = transition_rates; |
| 90 | + |
| 91 | + double dt = 0.1; |
| 92 | + double tmax = 30.; |
| 93 | + |
| 94 | + auto sim = mio::smm::Simulation(model, 0.0, dt); |
| 95 | + sim.advance(tmax); |
| 96 | + |
| 97 | + auto interpolated_results = mio::interpolate_simulation_result(sim.get_result()); |
| 98 | + interpolated_results.print_table({"S", "E", "C", "I", "R", "D "}); |
| 99 | +} |
0 commit comments