|
| 1 | +############################################################################# |
| 2 | +# Copyright (C) 2020-2024 MEmilio |
| 3 | +# |
| 4 | +# Authors: Henrik Zunker |
| 5 | +# |
| 6 | +# Contact: Martin J. Kuehn <[email protected]> |
| 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 | +import argparse |
| 21 | + |
| 22 | +import numpy as np |
| 23 | + |
| 24 | +from memilio.simulation import Damping |
| 25 | +from memilio.simulation.oseir import Index_InfectionState |
| 26 | +from memilio.simulation.oseir import InfectionState as State |
| 27 | +from memilio.simulation.oseir import (Model, interpolate_simulation_result, |
| 28 | + simulate_flows) |
| 29 | + |
| 30 | + |
| 31 | +def run_oseir_simulation(): |
| 32 | + """ |
| 33 | + Runs the c++ ode seir model using a flow simulation |
| 34 | + """ |
| 35 | + |
| 36 | + # Define population of age groups |
| 37 | + populations = [83000] |
| 38 | + |
| 39 | + days = 100 # number of days to simulate |
| 40 | + dt = 0.1 |
| 41 | + |
| 42 | + # Initialize Parameters |
| 43 | + model = Model() |
| 44 | + |
| 45 | + # Compartment transition duration |
| 46 | + model.parameters.TimeExposed.value = 5.2 |
| 47 | + model.parameters.TimeInfected.value = 6. |
| 48 | + |
| 49 | + # Compartment transition propabilities |
| 50 | + model.parameters.TransmissionProbabilityOnContact.value = 1. |
| 51 | + |
| 52 | + # Initial number of people in each compartment |
| 53 | + model.populations[Index_InfectionState(State.Exposed)] = 100 |
| 54 | + model.populations[Index_InfectionState(State.Infected)] = 50 |
| 55 | + model.populations[Index_InfectionState(State.Recovered)] = 10 |
| 56 | + model.populations.set_difference_from_total( |
| 57 | + (Index_InfectionState(State.Susceptible)), populations[0]) |
| 58 | + |
| 59 | + # model.parameters.ContactPatterns = ContactMatrix(np.r_[0.5]) |
| 60 | + model.parameters.ContactPatterns.baseline = np.ones((1, 1)) |
| 61 | + model.parameters.ContactPatterns.minimum = np.zeros((1, 1)) |
| 62 | + model.parameters.ContactPatterns.add_damping( |
| 63 | + Damping(coeffs=np.r_[0.9], t=30.0, level=0, type=0)) |
| 64 | + |
| 65 | + # Check logical constraints to parameters |
| 66 | + model.check_constraints() |
| 67 | + |
| 68 | + # Run flow simulation |
| 69 | + (result, flows) = simulate_flows(0, days, dt, model) |
| 70 | + |
| 71 | + print(result.print_table(["S", "E", "I", "R"], 16, 5)) |
| 72 | + print(flows.print_table(["S->E", "E->I", "I->R"], 16, 5)) |
| 73 | + |
| 74 | + |
| 75 | +if __name__ == "__main__": |
| 76 | + arg_parser = argparse.ArgumentParser( |
| 77 | + 'ode seir model with flow simulation', |
| 78 | + description='Simple example demonstrating the setup and flow simulation of the OSEIR model.') |
| 79 | + args = arg_parser.parse_args() |
| 80 | + run_oseir_simulation() |
0 commit comments