|
| 1 | +/* |
| 2 | +* Copyright (C) 2020-2024 MEmilio |
| 3 | +* |
| 4 | +* Authors: Nils Wassmuth, Rene Schmieding, Martin J. Kuehn |
| 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 | +#include "memilio/utils/logging.h" |
| 21 | +#include "memilio/utils/uncertain_value.h" |
| 22 | +#include "sde_seirvv/model.h" |
| 23 | +#include "sde_seirvv/simulation.h" |
| 24 | + |
| 25 | +#include <vector> |
| 26 | + |
| 27 | +int main() |
| 28 | +{ |
| 29 | + mio::set_log_level(mio::LogLevel::debug); |
| 30 | + |
| 31 | + ScalarType t0 = 0.; |
| 32 | + ScalarType tmid = 100.; |
| 33 | + ScalarType tmax = 400.; |
| 34 | + ScalarType dt = 0.1; |
| 35 | + |
| 36 | + mio::log_info("Simulating SEIRVV; t={} ... {} with dt = {}.", t0, tmax, dt); |
| 37 | + |
| 38 | + mio::sseirvv::Model model; |
| 39 | + |
| 40 | + ScalarType total_population = 180000; |
| 41 | + |
| 42 | + model.populations[{mio::sseirvv::InfectionState::ExposedV1}] = 0; |
| 43 | + model.populations[{mio::sseirvv::InfectionState::ExposedV2}] = 0; |
| 44 | + model.populations[{mio::sseirvv::InfectionState::InfectedV1}] = 7200; |
| 45 | + model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 0; |
| 46 | + model.populations[{mio::sseirvv::InfectionState::RecoveredV1}] = 0; |
| 47 | + model.populations[{mio::sseirvv::InfectionState::RecoveredV2}] = 0; |
| 48 | + model.populations[{mio::sseirvv::InfectionState::ExposedV1V2}] = 0; |
| 49 | + model.populations[{mio::sseirvv::InfectionState::InfectedV1V2}] = 0; |
| 50 | + model.populations[{mio::sseirvv::InfectionState::RecoveredV1V2}] = 0; |
| 51 | + model.populations[{mio::sseirvv::InfectionState::Susceptible}] = |
| 52 | + total_population - |
| 53 | + model.populations[{mio::sseirvv::InfectionState::ExposedV1}] - |
| 54 | + model.populations[{mio::sseirvv::InfectionState::ExposedV2}] - |
| 55 | + model.populations[{mio::sseirvv::InfectionState::InfectedV1}] - |
| 56 | + model.populations[{mio::sseirvv::InfectionState::InfectedV2}] - |
| 57 | + model.populations[{mio::sseirvv::InfectionState::RecoveredV1}] - |
| 58 | + model.populations[{mio::sseirvv::InfectionState::RecoveredV2}] - |
| 59 | + model.populations[{mio::sseirvv::InfectionState::ExposedV1V2}] - |
| 60 | + model.populations[{mio::sseirvv::InfectionState::InfectedV1V2}] - |
| 61 | + model.populations[{mio::sseirvv::InfectionState::RecoveredV1V2}]; |
| 62 | + |
| 63 | + // It is assumed that both variants have the same transmission probability |
| 64 | + // on contact and the same time exposed. The time infected is scaled by |
| 65 | + // 1.35 for the second variant. |
| 66 | + model.parameters.get<mio::sseirvv::ContactPatterns>().get_baseline()(0, 0) = 1; |
| 67 | + model.parameters.set<mio::sseirvv::TransmissionProbabilityOnContactV1>(0.076); |
| 68 | + model.parameters.set<mio::sseirvv::TransmissionProbabilityOnContactV2>(0.076); |
| 69 | + model.parameters.set<mio::sseirvv::TimeExposedV1>(5.33); |
| 70 | + model.parameters.set<mio::sseirvv::TimeExposedV2>(5.33); |
| 71 | + model.parameters.set<mio::sseirvv::TimeInfectedV1>(17.2); |
| 72 | + model.parameters.set<mio::sseirvv::TimeInfectedV2>(17.2 * 1.35); |
| 73 | + |
| 74 | + model.check_constraints(); |
| 75 | + |
| 76 | + // Simulate the model up until tmid, with only the first variant. |
| 77 | + auto sseirv = mio::sseirvv::simulate(t0, tmid, dt, model); |
| 78 | + // Set the model population to the simulation result, so it is used as initial value for the second simulation. |
| 79 | + model.populations.array() = sseirv.get_last_value().cast<mio::UncertainValue<ScalarType>>(); |
| 80 | + // The second variant enters with 100 individuals. This increases the model population to total_population + 100. |
| 81 | + model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 100; |
| 82 | + // Simulate the model from tmid to tmax, now with both variants. |
| 83 | + auto sseirv2 = mio::sseirvv::simulate(tmid, tmax, dt, model); |
| 84 | + |
| 85 | + sseirv.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2", "RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"}); |
| 86 | + sseirv2.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2", "RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"}); |
| 87 | +} |
0 commit comments