def build_individual_individual_transport_map(
        individual_transport_block_map_arg, transport_block_individual_map_arg,
        transportation_cap_arg):
    individual_individual_transport_dic = {}
    for ind, blocks in individual_transport_block_map_arg.items():
        for block in get_random_sample(blocks, transportation_cap_arg):
            if ind not in individual_individual_transport_dic:
                individual_individual_transport_dic[ind] = set()
            individual_individual_transport_dic[ind].update(
                get_random_sample(
                    set(transport_block_individual_map_arg[block]),
                    transportation_cap_arg))
    return individual_individual_transport_dic
def propagate_to_transportation(env_dic, virus_dic,
                                probability_transport_infection_arg,
                                probability_remote_work_arg,
                                transportation_cap_arg):
    # Contagious people who will go to work
    # [1, 2, 3] go to work
    infected_who_goto_work = [
        i for i in get_contagious_people(virus_dic)
        if i in env_dic[IW_K].keys() and get_r() <
        (1 - probability_remote_work_arg) * env_dic[IBE_K][i]
    ]

    # Infected public transportation blocks with cap 2
    # individuals 1, 2, 3 are in an infected block
    # same for 4, 5, 6
    # Result : [ ({1, 3}, 1), ({5, 6}, 1.5) ] with random sample
    people_sharing_transportation = [
        (get_random_sample(env_dic[ITI_K][i],
                           transportation_cap_arg), env_dic[IBE_K][i])
        for i in infected_who_goto_work
    ]

    infected_bad_luck_transport = [
        i for people, beh_trans in people_sharing_transportation
        for i in people
        if get_r() < probability_transport_infection_arg * beh_trans
    ]

    # INFECTION STATE UPDATE
    update_infection_period(infected_bad_luck_transport, virus_dic)
Ejemplo n.º 3
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
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