def launch_run(params, env_dic, display_progress=True):
    stats = get_zero_stats(params)
    for r in range(params[nrun_key]):

        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]):
            if display_progress:
                print_progress_bar(r * params[nday_key] + day + 1, params[nrun_key] * params[nday_key],
                                   prefix='Progress:', suffix='Complete', length=50)
            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_stats(virus_dic, stats, r, day)
            stats["loc"][r][day] = measure_lockdown_strength(params)

    return stats
示例#2
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 launch_run(params, env_dic, display_progress=True):
    stats = get_zero_stats(params)
    loosening_day = np.zeros((params[nrun_key]))
    for r in range(params[nrun_key]):

        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]) < 1:
            raise AssertionError("Need an additional_scenario parameter")
        days_to_lockdown_loosening = params[additional_scenario_params_key][0]

        days_with_no_cases = 0

        first_day_lockdown_loosening = -1

        virus_dic = get_virus_simulation_t0(params)
        for day in range(params[nday_key]):
            if display_progress:
                print_progress_bar(r * params[nday_key] + day + 1, params[nrun_key] * params[nday_key],
                                   prefix='Progress:', suffix='Complete', length=50)
            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_stats(virus_dic, stats, r, day)
            stats["loc"][r][day] = measure_lockdown_strength(params)

            if stats['new'][r][day] == 0:
                days_with_no_cases += 1
            else:
                days_with_no_cases = 0

            if days_with_no_cases > days_to_lockdown_loosening:
                if first_day_lockdown_loosening == -1:
                    first_day_lockdown_loosening = day
                days_with_no_cases = 0
                soften_full_lockdown(params)
        loosening_day[r] = first_day_lockdown_loosening

    loosening_day_ok = [l_v for l_v in loosening_day if l_v != -1]
    if display_progress:
        print(loosening_day)
        print("Lockdown removal occured %d times in average after %.2f days"
              % (len(loosening_day_ok), sum(loosening_day_ok)/(1+len(loosening_day_ok))))
    return stats
示例#4
0
def launch_run(params, env_dic, display_progress=True):
    if len(params[additional_scenario_params_key]) < 2:
        raise AssertionError("Need more additional_scenario parameter")
    nb_rogue = int(params[additional_scenario_params_key][0])
    rogue_factor = params[additional_scenario_params_key][1]

    stats = get_zero_stats(params)
    for r in range(params[nrun_key]):

        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

        virus_dic = get_virus_simulation_t0(params)
        for day in range(params[nday_key]):
            if display_progress:
                print_progress_bar(r * params[nday_key] + day + 1,
                                   params[nrun_key] * params[nday_key],
                                   prefix='Progress:',
                                   suffix='Complete',
                                   length=50)
            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)

            contagious_people = get_contagious_people(virus_dic)
            if len(contagious_people) > 0:
                rogues = get_random_sample(contagious_people, nb_rogue)
                for rogue in rogues:
                    env_dic[IBE_K][rogue] *= rogue_factor

            update_stats(virus_dic, stats, r, day)
            stats["loc"][r][day] = measure_lockdown_strength(params)

    return stats
示例#5
0
def launch_run(params, env_dic, display_progress=True):
    if len(params[additional_scenario_params_key]) < 1:
        raise AssertionError("Need more additional_scenario parameter")
    percent_increase = params[additional_scenario_params_key][0]

    stats = get_zero_stats(params)
    for r in range(params[nrun_key]):

        params[store_preference_key] = 0.3
        params[remote_work_key] = 0.58
        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
        params[icu_bed_per_thousand_individual_key] = 100
        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]):
            if display_progress:
                print_progress_bar(r * params[nday_key] + day + 1,
                                   params[nrun_key] * params[nday_key],
                                   prefix='Progress:',
                                   suffix='Complete',
                                   length=50)
            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)

            if day > 0 and day % 7 == 0:
                params[work_infection_key] *= (1 + percent_increase)
                params[store_infection_key] *= (1 + percent_increase)
                params[transport_infection_key] *= (1 + percent_increase)
                params[innoculation_number_key] *= (1 + percent_increase)

            update_stats(virus_dic, stats, r, day)
            stats["loc"][r][day] = measure_lockdown_strength(params)

    return stats
def launch_run(params, env_dic):
    stats = get_zero_stats(params)
    for r in range(params[nrun_key]):

        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]):
            time_init = time.time()
            propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
            prof_stats[0] += time.time() - time_init
            prof_nstats[0] += 1
            time_init = time.time()
            propagate_to_transportation(env_dic, virus_dic,
                                        params[transport_infection_key],
                                        params[remote_work_key],
                                        params[transport_contact_cap_key])
            prof_stats[1] += time.time() - time_init
            prof_nstats[1] += 1
            time_init = time.time()
            ind_work = propagate_to_workplaces(env_dic, virus_dic,
                                               params[work_infection_key],
                                               params[remote_work_key])
            prof_stats[2] += time.time() - time_init
            prof_nstats[2] += 1
            time_init = time.time()
            ind_sto = propagate_to_stores(env_dic, virus_dic,
                                          params[store_infection_key],
                                          params[store_preference_key])
            prof_stats[3] += time.time() - time_init
            prof_nstats[3] += 1
            time_init = time.time()
            increment_pandemic_1_day(env_dic, virus_dic, available_beds)
            prof_stats[4] += time.time() - time_init
            prof_nstats[4] += 1

            update_stats(virus_dic, stats, r, day)
            stats["loc"][r][day] = measure_lockdown_strength(params)

    print(prof_stats)
    print(prof_nstats)
    return 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