Пример #1
0
def do_parallel_run(env_dic, params, run_id, specific_seed, pba: ActorHandle):
    run_stats = get_zero_run_stats(params)
    random.seed(specific_seed)
    np.random.seed(specific_seed)

    params[store_preference_key] = 0.95
    params[remote_work_key] = 0.98
    params[innoculation_number_key] = 5
    available_beds = params[icu_bed_per_thousand_individual_key] * params[
        nindividual_key] / 1000
    virus_dic = get_virus_simulation_t0(params)

    for day in range(params[nday_key]):
        pba.update.remote(1)
        propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
        if not is_weekend(day):
            propagate_to_transportation(env_dic, virus_dic,
                                        params[transport_infection_key],
                                        params[remote_work_key],
                                        params[transport_contact_cap_key])
            propagate_to_workplaces(env_dic, virus_dic,
                                    params[work_infection_key],
                                    params[remote_work_key])
        if is_weekend(day):
            propagate_to_stores(env_dic, virus_dic,
                                params[store_infection_key],
                                params[store_preference_key])
        increment_pandemic_1_day(env_dic, virus_dic, available_beds)

        update_run_stat(virus_dic, run_stats, day)
        run_stats["loc"][day] = measure_lockdown_strength(params)
    return run_id, run_stats
def do_parallel_run(env_dic, params, run_id, specific_seed, pba: ActorHandle):
    run_stats = get_zero_run_stats(params)
    random.seed(specific_seed)
    np.random.seed(specific_seed)

    if len(params[additional_scenario_params_key]) < 1:
        raise AssertionError("Need more additional_scenario parameter")

    nb_to_infect = int(params[additional_scenario_params_key][0])

    params[store_preference_key] = 0.95
    params[remote_work_key] = 0.98
    params[house_infect_key] = 0.5
    params[work_infection_key] = 0.01
    params[transport_infection_key] = 0.01
    params[innoculation_number_key] = 50
    available_beds = params[icu_bed_per_thousand_individual_key] * params[
        nindividual_key] / 1000

    virus_dic = get_virus_simulation_t0(params)
    for day in range(params[nday_key]):
        pba.update.remote(1)
        propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
        if not is_weekend(day):
            propagate_to_transportation(env_dic, virus_dic,
                                        params[transport_infection_key],
                                        params[remote_work_key],
                                        params[transport_contact_cap_key])
            propagate_to_workplaces(env_dic, virus_dic,
                                    params[work_infection_key],
                                    params[remote_work_key])
        if is_weekend(day):
            propagate_to_stores(env_dic, virus_dic,
                                params[store_infection_key],
                                params[store_preference_key])
        increment_pandemic_1_day(env_dic, virus_dic, available_beds)

        update_infection_period(
            get_random_sample(get_healthy_people(virus_dic), nb_to_infect),
            virus_dic)

        update_run_stat(virus_dic, run_stats, day)
        run_stats["loc"][day] = measure_lockdown_strength(params)
    return run_id, run_stats
def do_parallel_run(env_dic, params, run_id, specific_seed, pba: ActorHandle):
    run_stats = get_zero_run_stats(params)
    random.seed(specific_seed)
    np.random.seed(specific_seed)

    params[store_preference_key] = 0.95
    params[remote_work_key] = 0.98
    params[house_infect_key] = 0.5
    params[work_infection_key] = 0.01
    params[store_infection_key] = 0.001
    params[transport_infection_key] = 0.01
    params[innoculation_number_key] = 50
    available_beds = params[icu_bed_per_thousand_individual_key] * params[
        nindividual_key] / 1000

    if len(params[additional_scenario_params_key]) < 3:
        raise AssertionError("Need more additional_scenario parameter")
    days_to_lockdown_loosening = float(
        params[additional_scenario_params_key][0])
    factor_bed = float(params[additional_scenario_params_key][1])
    max_lockdown = float(params[additional_scenario_params_key][2])

    days_with_no_cases = 0
    days_to_lockdown_change = 0
    first_day_lockdown_loosening = -1

    virus_dic = get_virus_simulation_t0(params)
    for day in range(params[nday_key]):
        pba.update.remote(1)
        propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
        if not is_weekend(day):
            propagate_to_transportation(env_dic, virus_dic,
                                        params[transport_infection_key],
                                        params[remote_work_key],
                                        params[transport_contact_cap_key])
            propagate_to_workplaces(env_dic, virus_dic,
                                    params[work_infection_key],
                                    params[remote_work_key])
        if is_weekend(day):
            propagate_to_stores(env_dic, virus_dic,
                                params[store_infection_key],
                                params[store_preference_key])
        increment_pandemic_1_day(env_dic, virus_dic, available_beds)

        days_to_lockdown_change += 1

        if virus_dic[NC_K] == 0:
            days_with_no_cases += 1
        else:
            days_with_no_cases = 0

        if days_with_no_cases > days_to_lockdown_loosening and days_to_lockdown_change >= 7:
            if first_day_lockdown_loosening == -1:
                first_day_lockdown_loosening = day
            days_with_no_cases = 0
            days_to_lockdown_change = 0
            soften_full_lockdown(params)

        if virus_dic[NC_K] >= available_beds * factor_bed and days_to_lockdown_change >= 7 \
                and measure_lockdown_strength(params) < max_lockdown:
            days_to_lockdown_change = 0
            tighten_full_lockdown(params)

        update_run_stat(virus_dic, run_stats, day)
        run_stats["loc"][day] = measure_lockdown_strength(params)
    return run_id, run_stats
def do_parallel_run(env_dic, params, run_id, specific_seed, pba: ActorHandle):

    random.seed(specific_seed)
    np.random.seed(specific_seed)

    if len(params[additional_scenario_params_key]) < 1:
        raise AssertionError("Need more additional_scenario parameter")
    else:
        rate_daily_vaccinated = int(params[additional_scenario_params_key][0])

    if rate_daily_vaccinated < 0:
        # Morrocan daily rate of vaccination
        rate_daily_vaccinated = 0.00428

    params[store_preference_key] = 0.5
    params[remote_work_key] = 0.5
    params[innoculation_number_key] = 5
    available_beds = params[icu_bed_per_thousand_individual_key] * params[
        nindividual_key] / 1000

    run_stats = get_zero_run_stats(params)

    params[house_infect_key] = 0.5
    params[work_infection_key] = 0.05
    params[store_infection_key] = 0.02
    params[transport_infection_key] = 0.01

    params[immunity_bounds_key] = (
        270, 450)  # assuming about a year of immunity (~flu)
    virus_dic = get_virus_simulation_t0(params)

    for day in range(params[nday_key]):
        pba.update.remote(1)
        old_healthy = [(k, env_dic[IAG_K][k])
                       for k, v in virus_dic[STA_K].items() if v == HEALTHY_V]
        nb_indiv_vaccinated = max(
            0,
            int(params[nindividual_key] * rate_daily_vaccinated *
                (1 - day / 100)))
        if len(old_healthy) > nb_indiv_vaccinated and day <= 100:
            old_sorted = sorted(old_healthy, key=lambda kv: -kv[1])
            old_lucky = [o[0] for o in old_sorted[:nb_indiv_vaccinated]]
            virus_dic[STA_K].update((o, IMMUNE_V) for o in old_lucky)

        propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
        if not is_weekend(day):
            propagate_to_transportation(env_dic, virus_dic,
                                        params[transport_infection_key],
                                        params[remote_work_key],
                                        params[transport_contact_cap_key])
            propagate_to_workplaces(env_dic, virus_dic,
                                    params[work_infection_key],
                                    params[remote_work_key])
        if is_weekend(day):
            propagate_to_stores(env_dic, virus_dic,
                                params[store_infection_key],
                                params[store_preference_key])
        increment_pandemic_1_day(env_dic, virus_dic, available_beds)

        update_run_stat(virus_dic, run_stats, day)
    return run_id, run_stats
def do_parallel_run(env_dic, params, run_id, specific_seed, pba: ActorHandle):
    run_stats = get_zero_run_stats(params)
    random.seed(specific_seed)
    np.random.seed(specific_seed)

    if len(params[additional_scenario_params_key]) < 1:
        raise AssertionError("Need more additional_scenario parameter")

    relock_activated = bool(params[additional_scenario_params_key][0])

    params[innoculation_number_key] = 5

    days_to_lockdown_change = 0
    days_to_lockdown_loosening = 14
    unlock_progress = 0

    pcn = (0.98, 0.5, 0.01, 0.01, 0.02, 0.95)
    #pcn = (0.78, 0.5, 0.05, 0.05, 0.1, 0.55)
    pvn = (0.58, 0.5, 0.05, 0.05, 0.1, 0.30)

    params[remote_work_key] = pcn[0] * unlock_progress + (
        pvn[0] - pcn[0]) * unlock_progress
    params[house_infect_key] = pcn[1] * unlock_progress + (
        pvn[1] - pcn[1]) * unlock_progress
    params[transport_infection_key] = pcn[2] * unlock_progress + (
        pvn[2] - pcn[2]) * unlock_progress
    params[work_infection_key] = pcn[3] * unlock_progress + (
        pvn[3] - pcn[3]) * unlock_progress
    params[store_infection_key] = pcn[4] * unlock_progress + (
        pvn[4] - pcn[4]) * unlock_progress
    params[store_preference_key] = pcn[5] * unlock_progress + (
        pvn[5] - pcn[5]) * unlock_progress

    params[innoculation_number_key] = 5
    available_beds = params[icu_bed_per_thousand_individual_key] * params[
        nindividual_key] / 1000

    virus_dic = get_virus_simulation_t0(params)

    for day in range(params[nday_key]):
        pba.update.remote(1)
        params[remote_work_key] = pcn[0] * unlock_progress + (
            pvn[0] - pcn[0]) * unlock_progress
        params[house_infect_key] = pcn[1] * unlock_progress + (
            pvn[1] - pcn[1]) * unlock_progress
        params[transport_infection_key] = pcn[2] * unlock_progress + (
            pvn[2] - pcn[2]) * unlock_progress
        params[work_infection_key] = pcn[3] * unlock_progress + (
            pvn[3] - pcn[3]) * unlock_progress
        params[store_infection_key] = pcn[4] * unlock_progress + (
            pvn[4] - pcn[4]) * unlock_progress
        params[store_preference_key] = pcn[5] * unlock_progress + (
            pvn[5] - pcn[5]) * unlock_progress

        propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
        if not is_weekend(day):
            propagate_to_transportation(env_dic, virus_dic,
                                        params[transport_infection_key],
                                        params[remote_work_key],
                                        params[transport_contact_cap_key])
            propagate_to_workplaces(env_dic, virus_dic,
                                    params[work_infection_key],
                                    params[remote_work_key])
        if is_weekend(day):
            propagate_to_stores(env_dic, virus_dic,
                                params[store_infection_key],
                                params[store_preference_key])
        increment_pandemic_1_day(env_dic, virus_dic, available_beds)

        days_to_lockdown_change += 1

        if len(get_hospitalized_people(
                virus_dic)) == 0 and days_to_lockdown_change >= 14:
            days_to_lockdown_change = 0
            unlock_progress = min(1, unlock_progress + 0.2)

        if relock_activated:
            if len(get_hospitalized_people(virus_dic)
                   ) >= available_beds and days_to_lockdown_change >= 14:
                days_to_lockdown_change = 0
                unlock_progress = max(0, unlock_progress - 0.2)

        update_run_stat(virus_dic, run_stats, day)
        run_stats["loc"][day] = (1 - unlock_progress
                                 )  # measure_lockdown_strength(params)

    return run_id, run_stats
def do_parallel_run(env_dic, params, run_id, specific_seed, pba: ActorHandle):
    run_stats = get_zero_run_stats(params)
    random.seed(specific_seed)
    np.random.seed(specific_seed)

    if len(params[additional_scenario_params_key]) < 1:
        raise AssertionError("Need more additional_scenario parameter")

    age_cutoff = int(params[additional_scenario_params_key][0])

    params[innoculation_number_key] = 5

    days_to_lockdown_change = 0
    unlock_progress = 0

    pcn = (0.98, 0.5, 0.01, 0.01, 0.02, 0.95)
    pvn = (0.58, 0.5, 0.05, 0.05, 0.1, 0.30)

    params[remote_work_key] = pcn[0] * unlock_progress + (pvn[0] - pcn[0]) * unlock_progress
    params[house_infect_key] = pcn[1] * unlock_progress + (pvn[1] - pcn[1]) * unlock_progress
    params[transport_infection_key] = pcn[2] * unlock_progress + (pvn[2] - pcn[2]) * unlock_progress
    params[work_infection_key] = pcn[3] * unlock_progress + (pvn[3] - pcn[3]) * unlock_progress
    params[store_infection_key] = pcn[4] * unlock_progress + (pvn[4] - pcn[4]) * unlock_progress
    params[store_preference_key] = pcn[5] * unlock_progress + (pvn[5] - pcn[5]) * unlock_progress

    params[innoculation_number_key] = 5
    available_beds = params[icu_bed_per_thousand_individual_key] * params[nindividual_key] / 1000

    virus_dic = get_virus_simulation_t0(params)

    for day in range(params[nday_key]):
        pba.update.remote(1)
        params[remote_work_key] = pcn[0] * unlock_progress + (pvn[0] - pcn[0]) * unlock_progress
        params[house_infect_key] = pcn[1] * unlock_progress + (pvn[1] - pcn[1]) * unlock_progress
        params[transport_infection_key] = pcn[2] * unlock_progress + (pvn[2] - pcn[2]) * unlock_progress
        params[work_infection_key] = pcn[3] * unlock_progress + (pvn[3] - pcn[3]) * unlock_progress
        params[store_infection_key] = pcn[4] * unlock_progress + (pvn[4] - pcn[4]) * unlock_progress
        params[store_preference_key] = pcn[5] * unlock_progress + (pvn[5] - pcn[5]) * unlock_progress

        propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
        if not is_weekend(day):
            propagate_to_transportation(env_dic, virus_dic, params[transport_infection_key],
                                        params[remote_work_key], params[transport_contact_cap_key])
            propagate_to_workplaces(env_dic, virus_dic, params[work_infection_key], params[remote_work_key])
        if is_weekend(day):
            propagate_to_stores(env_dic, virus_dic, params[store_infection_key], params[store_preference_key])
        increment_pandemic_1_day(env_dic, virus_dic, available_beds)

        days_to_lockdown_change += 1

        young_healthy = [k for k, v in virus_dic[STA_K].items() if v == HEALTHY_V
                         and env_dic[IAD_K][k] == 1 and env_dic[IAG_K][k] <= age_cutoff]

        young_unlucky = np.random.choice(young_healthy,
                                         size=int(min(len(young_healthy), params[nindividual_key]/1000)),
                                         replace=False)
        virus_dic[STA_K].update((y, ISOLATED_V) for y in young_unlucky)

        if len(get_hospitalized_people(virus_dic)) == 0 and days_to_lockdown_change >= 14:
            days_to_lockdown_change = 0
            unlock_progress = min(1, unlock_progress + 0.2)

        if len(get_hospitalized_people(virus_dic)) >= available_beds and days_to_lockdown_change >= 14:
            days_to_lockdown_change = 0
            unlock_progress = max(0, unlock_progress - 0.2)

        update_run_stat(virus_dic, run_stats, day)
        # Override isolation to calculate
        run_stats["iso"][day] = len(young_unlucky)
        run_stats["loc"][day] = (1-unlock_progress)

    return run_id, run_stats