示例#1
0
def get_optimised_mixing_matrix(country, decision_vars, mode, duration):
    if decision_vars is None:
        return np.ones((16, 16))

    app_region = covid_19.app.get_region(country)
    build_model = app_region.build_model
    params = copy.deepcopy(app_region.params)

    # Create and run scenario 1
    sc_1_params_update = build_params_for_phases_2_and_3(
        decision_vars, params["default"]["elderly_mixing_reduction"], duration,
        mode)
    sc_1_params = merge_dicts(sc_1_params_update, params["default"])
    params["scenarios"][1] = sc_1_params
    scenario_1 = Scenario(build_model, idx=0, params=params)

    print(
        "WARNING: Make sure to comment the line of code where integration is called in scenairos.py !!!!!!!!!!!!!!"
    )
    scenario_1.run()

    sc_1_model = scenario_1.model
    time_matrix_called = PHASE_2_START_TIME + 30  # could be any time during Phase 2

    return sc_1_model.get_mixing_matrix(time_matrix_called)
示例#2
0
    def run_scenario(self, sc_dict):
        """
        Run a model scenario defined from the scenario dictionary
        :return: a model object
        """
        app_module = import_module(f"apps.{self.app_name}")
        app_region = app_module.app.get_region(self.region_name)

        build_model = app_region.build_model
        params = copy.deepcopy(app_region.params)
        params["default"] = merge_dicts(self.root_model_params,
                                        params["default"])

        # Create and run the optimisation scenario
        params["scenarios"][1] = merge_dicts(sc_dict, params["default"])
        opti_scenario = Scenario(build_model, idx=1, params=params)
        opti_scenario.run(base_model=self.root_model)

        return opti_scenario.model
示例#3
0
    def run_root_model(self):
        # Initialise baseline model
        app_module = import_module(f"apps.{self.app_name}")
        app_region = app_module.app.get_region(self.region_name)
        root_params = copy.deepcopy(app_region.params)

        # Update params using root_model_params
        root_params["default"] = merge_dicts(self.root_model_params,
                                             root_params["default"])

        # Create Scenario object and run root model
        root_scenario = Scenario(app_region.build_model,
                                 idx=0,
                                 params=root_params)
        root_scenario.run()

        self.root_model = root_scenario.model

        return root_params
示例#4
0
def test_merge_dicts__nested_merge__with__conflicting_dict():
    base = {"mixing": {"bar": [7, 8, 9], "baz": [7, 8, 9]}}
    update = {"mixing": {"foo": [1, 2, 3], "bar": [4, 5, 6]}}
    assert merge_dicts(update, base) == {
        "mixing": {"foo": [1, 2, 3], "bar": [4, 5, 6], "baz": [7, 8, 9]}
    }
示例#5
0
def test_merge_dicts__nested_merge__with_empty_dict():
    base = {"mixing": {}}
    update = {"mixing": {"foo": [1, 2, 3], "bar": [4, 5, 6]}}
    assert merge_dicts(update, base) == {"mixing": {"foo": [1, 2, 3], "bar": [4, 5, 6]}}
示例#6
0
def test_merge_dicts__nested_merge__with_none_key():
    base = {"mixing": None}
    update = {"mixing": {"foo": [1, 2, 3], "bar": [4, 5, 6]}}
    assert merge_dicts(update, base) == {"mixing": {"foo": [1, 2, 3], "bar": [4, 5, 6]}}
示例#7
0
def test_merge_dicts__basic_merge__with_none_key():
    base = {"iso3": None}
    update = {"iso3": "PHL"}
    assert merge_dicts(update, base) == {"iso3": "PHL"}