コード例 #1
0
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)
コード例 #2
0
def propagate_to_workplaces(env_dic, virus_dic, probability_work_infection_arg,
                            probability_remote_work_arg):
    # [1, 2, 3] go to work
    # Contagious people who will go to work
    infected_gotowork = [
        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 workplaces
    # [ (1, 1.1), (2, 1), (1, 1.4) ]
    infected_workplaces_behavior = [(env_dic[IW_K][i], env_dic[IBE_K][i])
                                    for i in infected_gotowork]

    # Infected workplaces
    # { 1: 1.1* 1.4, 2: 1 }
    infected_workplaces_behavior_dic = reduce_multiply_by_key(
        infected_workplaces_behavior)

    # We build people at those workplaces
    # [ ([1, 2, 3], 1), ([4, 5, 6], 2), ([1, 2, 3], 2) ]
    exposed_individuals_at_work = [
        (env_dic[WI_K][k], beh_p)
        for (k, beh_p) in infected_workplaces_behavior_dic.items()
    ]

    # People who have gone to work (not isolated) and got infected
    infected_backfromwork = [
        i for people, beh_p in exposed_individuals_at_work for i in people
        if get_r() < probability_work_infection_arg * beh_p
    ]

    # INFECTION STATE UPDATE
    update_infection_period(infected_backfromwork, virus_dic)
コード例 #3
0
def pick_age(is_child):
    if is_child:
        l_cs = age_dist_children_cs
        l_dis = age_dist_children
    else:
        l_cs = age_dist_adults_cs
        l_dis = age_dist_adults
    i = next(x[0] for x in enumerate(l_cs.values) if x[1] > get_r())
    min_age_i = l_dis.iloc[i]['min_age']
    max_age_i = l_dis.iloc[i]['max_age']
    return int(min_age_i + (max_age_i - min_age_i) * get_r())
コード例 #4
0
def pick_random_company_size():
    p = get_r()
    if p < 0.44:
        # We picked a TPE
        return int(1 + (TPE_MAX_EMPLOYEES - 1) * get_r())
    elif p < 0.86:
        # We picked a PME
        return int(TPE_MAX_EMPLOYEES +
                   (PME_MAX_EMPLOYEES - TPE_MAX_EMPLOYEES) * get_r())
    else:
        # We picked a PME
        return int(PME_MAX_EMPLOYEES +
                   (GE_MAX_EMPLOYEES - PME_MAX_EMPLOYEES) * get_r())
コード例 #5
0
def isolate_infected(env_dic, virus_dic):
    for i in get_infected_people(virus_dic):
        # Hospitalization risk are linked to more symptoms thus self-isolation
        # isolate_infected is tested every day, so we need to divide get_r with DEA_INIT_K day to decision
        if get_r() * virus_dic[DEA_INIT_K][i] < env_dic[ISYM_K][i] * virus_dic[
                variant_hospitalization_k]:
            virus_dic[STA_K][i] = ISOLATED_V
コード例 #6
0
def propagate_to_houses(env_dic, virus_dic, probability_home_infection_arg):
    # Houses that contain an infected and contagious person with an associated behavior weight
    # ( (1, 1.5), (1, 2), (2, 1) )
    # House 1 with 1.5 and 2 weights and House 2 with weight 1
    infected_houses_behavior = [(env_dic[IH_K][i], env_dic[IBE_K][i])
                                for i in get_contagious_people(virus_dic)]

    # We reduce_multiply_by_key multiply it to get
    # { 1: 1.5 * 2  ,   2: 1 }
    infected_houses_behavior_dic = reduce_multiply_by_key(
        infected_houses_behavior)

    # We build people at those houses with the house behavior
    # [ ([1, 2, 3], 1), ([4, 5, 6], 2), ([1, 2, 3], 2) ]
    people_in_infected_houses = [
        (env_dic[HI_K][hou], beh_p)
        for (hou, beh_p) in infected_houses_behavior_dic.items()
    ]

    # From which we designate newly infected people using weights beh_p
    infected_athome = [
        i for people, beh_p in people_in_infected_houses for i in people
        if get_r() < probability_home_infection_arg * beh_p
    ]

    # INFECTION STATE UPDATE
    update_infection_period(infected_athome, virus_dic)
コード例 #7
0
def decide_hospitalization(env_dic, virus_dic, individual_arg):
    if virus_dic[HOS_K][individual_arg] == 0 and get_r(
    ) < get_hospitalization_rate(env_dic[IAG_K][individual_arg]):
        virus_dic[STA_K][individual_arg] = HOSPITALIZED_V
        family = env_dic[HI_K][env_dic[IH_K][individual_arg]]
        virus_dic[STA_K].update((fm, ISOLATED_V) for fm in family
                                if (virus_dic[STA_K][fm] == INFECTED_V))
コード例 #8
0
def hospitalize_infected(env_dic, virus_dic):
    for i in get_infected_people(virus_dic):
        if virus_dic[HOS_K][i] == 0 and get_r(
        ) < env_dic[IHOS_K][i] * virus_dic[variant_hospitalization_k]:
            virus_dic[STA_K][i] = HOSPITALIZED_V
            family = env_dic[HI_K][env_dic[IH_K][i]]
            virus_dic[STA_K].update((fm, ISOLATED_V) for fm in family
                                    if (virus_dic[STA_K][fm] == INFECTED_V))
コード例 #9
0
def decide_life_immunity(env_dic, virus_dic, individual, icu_factor):
    if virus_dic[DEA_K][individual] == 0:
        # icu_factor only applies on hospitalized people
        if get_r() < get_mortalty_rate(env_dic[IAG_K][individual]) * \
                (icu_factor if (virus_dic[STA_K][individual] == HOSPITALIZED_V) else 1):
            virus_dic[STA_K][individual] = DEAD_V
        else:
            virus_dic[STA_K][individual] = IMMUNE_V
コード例 #10
0
def get_virus_simulation_t0(params_arg):
    number_of_individuals_arg = params_arg[nindividual_key]
    infection_initialization_number_arg = params_arg[innoculation_number_key]
    contagion_bound_args = params_arg[contagion_bounds_key]
    hospitalization_args = params_arg[hospitalization_bounds_key]
    death_bound_args = params_arg[death_bounds_key]
    immunity_bound_args = params_arg[immunity_bounds_key]

    inn_ind_cov = dict(
        zip(range(number_of_individuals_arg), [
            int(get_r() <= infection_initialization_number_arg /
                number_of_individuals_arg)
            for i in range(number_of_individuals_arg)
        ]))

    life_state = dict(
        zip(range(number_of_individuals_arg),
            [HEALTHY_V] * number_of_individuals_arg))

    def get_infection_params():
        return get_infection_parameters(
            contagion_bound_args[0], contagion_bound_args[1],
            hospitalization_args[0], hospitalization_args[1],
            death_bound_args[0], death_bound_args[1], immunity_bound_args[0],
            immunity_bound_args[1])

    time_to_contagion = dict(
        zip(range(number_of_individuals_arg), [
            get_infection_params()[0] for _ in range(number_of_individuals_arg)
        ]))
    time_to_hospital = dict(
        zip(range(number_of_individuals_arg), [
            get_infection_params()[1] for _ in range(number_of_individuals_arg)
        ]))
    time_to_death = dict(
        zip(range(number_of_individuals_arg), [
            get_infection_params()[2] for _ in range(number_of_individuals_arg)
        ]))
    time_to_end_immunity = dict(
        zip(range(number_of_individuals_arg), [
            get_infection_params()[3] for _ in range(number_of_individuals_arg)
        ]))

    infected_individual_init = [k for k, v in inn_ind_cov.items() if v == 1]

    for individual in infected_individual_init:
        life_state[individual] = INFECTED_V

    return {
        CON_K: time_to_contagion,
        HOS_K: time_to_hospital,
        DEA_K: time_to_death,
        IMM_K: time_to_end_immunity,
        STA_K: life_state,
        FN_K: get_infection_params,
        NC_K: 0
    }
コード例 #11
0
def decide_life_immunity(env_dic, virus_dic, icu_factor):
    for i in get_virus_carrier_people(virus_dic):
        if virus_dic[DEA_K][i] == 0:
            # icu_factor only applies on hospitalized people
            if get_r() < env_dic[IDEA_K][i] * virus_dic[variant_mortality_k] \
                    * (icu_factor if (virus_dic[STA_K][i] == HOSPITALIZED_V) else 1):
                virus_dic[STA_K][i] = DEAD_V
            else:
                virus_dic[STA_K][i] = IMMUNE_V
コード例 #12
0
def get_infection_parameters(lower_contagion_bound, upper_contagion_bound,
                             lower_hospitalization_bound,
                             upper_hospitalization_bound, lower_death_bound,
                             upper_death_bound, lower_immunity_bound,
                             upper_immunity_bound):
    # Time to death/immunity , Time to contagiosity
    return int(lower_contagion_bound + (upper_contagion_bound - lower_contagion_bound) * get_r()), \
           int(lower_hospitalization_bound + (upper_hospitalization_bound - lower_hospitalization_bound) * get_r()), \
           int(lower_death_bound + (upper_death_bound - lower_death_bound) * get_r()), \
           int(lower_immunity_bound + (upper_immunity_bound - lower_immunity_bound) * get_r())
コード例 #13
0
def propagate_to_stores(env_dic, virus_dic, probability_store_infection_arg,
                        same_store_preference):
    # Filter on living people because we have a random choice to make in each house
    # People who will go to their store (one person per house as imposed by lockdown)
    # [1, 2, 3, 4, 5, 6] go to the store
    individuals_gotostore = get_random_choice_list([[
        i for i in env_dic[HA_K][h]
        if (is_alive(i, virus_dic) and not (is_isolated(i, virus_dic)))
    ] for h in range(len(env_dic[HA_K]))])

    # Contagious people who will go to their store
    # [1, 4, 5] are infected and going to the store
    individuals_infected_gotostore = [
        i for i in individuals_gotostore if is_contagious(i, virus_dic)
    ]

    # [(2, 0), (3, 1), (6, 2)]  2, 3 and 6 are infected and going to the stores 0, 1 and 2
    # we divide same_store_preference by behavior since high behavior value is bad behavior
    individuals_healthy_gotostore = [
        (i,
         choose_weight_order(env_dic[HS_K][env_dic[IH_K][i]],
                             same_store_preference / env_dic[IBE_K][i]))
        for i in individuals_gotostore if not is_contagious(i, virus_dic)
    ]

    # Stores that will be visited by a contagious person
    # [ (0, 1), (0, 1.3), (2, 1.2)] where stores 0 and 2 are infected with 1, 1.3 and 1.2 weights
    infected_stores = [
        (choose_weight_order(env_dic[HS_K][env_dic[IH_K][i]],
                             same_store_preference / env_dic[IBE_K][i]),
         env_dic[IBE_K][i]) for i in individuals_infected_gotostore
    ]

    # { 0: 1*1.3, 2: 1.2 } are the weights of each infected store
    infected_stores_dic = reduce_multiply_by_key(infected_stores)

    # We get the list of people who are healty + have chosen an infected store + get bad luck with get_r
    # [2, 6] got infected
    gonna_be_infected = [
        ind for (ind, s) in individuals_healthy_gotostore
        if s in infected_stores_dic.keys()
        and get_r() < probability_store_infection_arg * env_dic[IBE_K][ind] *
        infected_stores_dic[s]
    ]

    # INFECTION STATE UPDATE
    update_infection_period(gonna_be_infected, virus_dic)
コード例 #14
0
def get_store_index(indexes, prob_preference_store):
    return [
        index[0] if get_r() < prob_preference_store else index[1]
        for index in indexes
    ]
コード例 #15
0
def build_geo_positions_store(number_store_arg):
    return [(get_r(), get_r()) for i in range(number_store_arg)]