example_vensim_no_policy_flu.py

  1"""
  2Created on 20 May, 2011
  3
  4This module shows how you can use vensim models directly
  5instead of coding the model in Python. The underlying case
  6is the same as used in fluExample
  7
  8.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
  9                epruyt <e.pruyt (at) tudelft (dot) nl>
 10"""
 11
 12from ema_workbench import (
 13    RealParameter,
 14    TimeSeriesOutcome,
 15    ema_logging,
 16    perform_experiments,
 17    MultiprocessingEvaluator,
 18    save_results,
 19)
 20
 21from ema_workbench.connectors.vensim import VensimModel
 22
 23if __name__ == "__main__":
 24    ema_logging.log_to_stderr(ema_logging.INFO)
 25
 26    model = VensimModel("fluCase", wd=r"./models/flu", model_file=r"FLUvensimV1basecase.vpm")
 27
 28    # outcomes
 29    model.outcomes = [
 30        TimeSeriesOutcome(
 31            "deceased_population_region_1", variable_name="deceased population region 1"
 32        ),
 33        TimeSeriesOutcome("infected_fraction_R1", variable_name="infected fraction R1"),
 34    ]
 35
 36    # Plain Parametric Uncertainties
 37    model.uncertainties = [
 38        RealParameter(
 39            "additional_seasonal_immune_population_fraction_R1",
 40            0,
 41            0.5,
 42            variable_name="additional seasonal immune population fraction R1",
 43        ),
 44        RealParameter(
 45            "additional_seasonal_immune_population_fraction_R2",
 46            0,
 47            0.5,
 48            variable_name="additional seasonal immune population fraction R2",
 49        ),
 50        RealParameter(
 51            "fatality_ratio_region_1", 0.0001, 0.1, variable_name="fatality ratio region 1"
 52        ),
 53        RealParameter(
 54            "fatality_rate_region_2", 0.0001, 0.1, variable_name="fatality rate region 2"
 55        ),
 56        RealParameter(
 57            "initial_immune_fraction_of_the_population_of_region_1",
 58            0,
 59            0.5,
 60            variable_name="initial immune fraction of the population of region 1",
 61        ),
 62        RealParameter(
 63            "initial_immune_fraction_of_the_population_of_region_2",
 64            0,
 65            0.5,
 66            variable_name="initial immune fraction of the population of region 2",
 67        ),
 68        RealParameter(
 69            "normal_interregional_contact_rate",
 70            0,
 71            0.9,
 72            variable_name="normal interregional contact rate",
 73        ),
 74        RealParameter(
 75            "permanent_immune_population_fraction_R1",
 76            0,
 77            0.5,
 78            variable_name="permanent immune population fraction R1",
 79        ),
 80        RealParameter(
 81            "permanent_immune_population_fraction_R2",
 82            0,
 83            0.5,
 84            variable_name="permanent immune population fraction R2",
 85        ),
 86        RealParameter("recovery_time_region_1", 0.1, 0.75, variable_name="recovery time region 1"),
 87        RealParameter("recovery_time_region_2", 0.1, 0.75, variable_name="recovery time region 2"),
 88        RealParameter(
 89            "susceptible_to_immune_population_delay_time_region_1",
 90            0.5,
 91            2,
 92            variable_name="susceptible to immune population delay time region 1",
 93        ),
 94        RealParameter(
 95            "susceptible_to_immune_population_delay_time_region_2",
 96            0.5,
 97            2,
 98            variable_name="susceptible to immune population delay time region 2",
 99        ),
100        RealParameter(
101            "root_contact_rate_region_1", 0.01, 5, variable_name="root contact rate region 1"
102        ),
103        RealParameter(
104            "root_contact_ratio_region_2", 0.01, 5, variable_name="root contact ratio region 2"
105        ),
106        RealParameter(
107            "infection_ratio_region_1", 0, 0.15, variable_name="infection ratio region 1"
108        ),
109        RealParameter("infection_rate_region_2", 0, 0.15, variable_name="infection rate region 2"),
110        RealParameter(
111            "normal_contact_rate_region_1", 10, 100, variable_name="normal contact rate region 1"
112        ),
113        RealParameter(
114            "normal_contact_rate_region_2", 10, 200, variable_name="normal contact rate region 2"
115        ),
116    ]
117
118    nr_experiments = 1000
119    with MultiprocessingEvaluator(model) as evaluator:
120        results = perform_experiments(model, nr_experiments, evaluator=evaluator)
121
122    save_results(results, "./data/1000 flu cases no policy.tar.gz")