コード例 #1
0
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
 def test_propagate_to_workplaces_noworkers(self):
     # Everyone is healthy and stays like that
     env_dic = {
         IW_K: {
             1: 1,
             4: 1,
             5: 0
         },
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: {
             1: 1,
             4: 1,
             5: 1
         }
     }
     virus_dic = {
         CON_K: {
             1: 8,
             4: 1,
             5: 4
         },
         STA_K: {
             1: H,
             4: H,
             5: H
         },
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0)
     self.assertEqual(virus_dic[STA_K][1], H)
     self.assertEqual(virus_dic[STA_K][4], H)
     self.assertEqual(virus_dic[STA_K][5], H)
コード例 #3
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
コード例 #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
コード例 #6
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 test_propagate_to_workplaces_contagious(self):
     # i4 is infected and works at w1 like i1
     # i1 gets infected
     env_dic = {
         IW_K: {1: 1, 4: 1, 5: 0},
         WI_K: {0: [5], 1: [4, 1]},
         IBE_K: {1: 1, 4: 1, 5: 1}
     }
     virus_dic = {
         CON_K: {1: -2, 4: -5, 5: 4},
         STA_K: {1: H, 4: F, 5: H},
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0.1)
     self.assertEqual(virus_dic[STA_K][1], F)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_notcontagious(self):
     # i4 is infected but not contagious and works at w1 like i1
     # i1 stays healthy
     env_dic = {
         IW_K: {1: 1, 4: 1, 5: 0},
         WI_K: {0: [5], 1: [4, 1]},
         IBE_K: {1: 1, 4: 1, 5: 1}
     }
     virus_dic = {
         CON_K: {1: 8, 4: 1, 5: 4},
         STA_K: {1: H, 4: F, 5: H},
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0)
     self.assertEqual(virus_dic[STA_K][1], H)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_carefull(self):
     # i4 is infected and works at w1 like i1
     # They work closely together but i4 has a very good behavior
     # i1 stays healthy
     env_dic = {
         IW_K: {1: 1, 4: 1, 5: 0},
         WI_K: {0: [5], 1: [4, 1]},
         IBE_K: {1: 1, 4: 0.0001, 5: 1}
     }
     virus_dic = {
         CON_K: {1: -2, 4: -5, 5: 4},
         STA_K: {1: H, 4: F, 5: H},
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0)
     self.assertEqual(virus_dic[STA_K][1], H)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_dangerous(self):
     # i4 is infected and works at w1 like i1
     # They should not be in touch but i4 has a very bad behavior
     # i1 gets infected
     env_dic = {
         IW_K: {1: 1, 4: 1, 5: 0},
         WI_K: {0: [5], 1: [4, 1]},
         IBE_K: {1: 1, 4: 100, 5: 1}
     }
     virus_dic = {
         CON_K: {1: -2, 4: -5, 5: 4},
         STA_K: {1: H, 4: F, 5: H},
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.01, 0.1)
     self.assertEqual(virus_dic[STA_K][1], F)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_bad_behavior(self):
     # Nobody should go to work (remote parameter high
     # But i1 and i4 have bad behavior
     # And since i1 is contagious, i4 gets infected
     env_dic = {
         IW_K: {1: 1, 4: 1, 5: 0},
         WI_K: {0: [5], 1: [4, 1]},
         IBE_K: {1: 100, 4: 100, 5: 1}
     }
     virus_dic = {
         CON_K: {1: -2, 4: 1, 5: 4},
         STA_K: {1: F, 4: H, 5: H},
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0.98)
     self.assertEqual(virus_dic[STA_K][1], F)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
コード例 #12
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)

    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 test_propagate_to_workplaces_noworkers2(self):
     # Everyone is healthy and stays like that
     env_dic = {
         IW_K: g_d([-1, 1, -1, -1, 1, 0, -1, -1, -1, -1]),
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: g_d([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
     }
     virus_dic = {
         CON_K: g_d([1, 8, 1, 1, 1, 4, 1, 1, 1, 1]),
         STA_K: g_d([H, H, H, H, H, H, H, H, H, H]),
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0)
     self.assertEqual(virus_dic[STA_K][1], H)
     self.assertEqual(virus_dic[STA_K][4], H)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_notcontagious2(self):
     # i4 is infected but not contagious and works at w1 like i1
     # i1 stays healthy
     env_dic = {
         IW_K: g_d([-1, 1, -1, -1, 1, 0, -1, -1, -1, -1]),
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: g_d([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
     }
     virus_dic = {
         CON_K: g_d([1, 8, 1, 1, 1, 4, 1, 1, 1, 1]),
         STA_K: g_d([H, H, H, H, F, H, H, H, H, H]),
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0)
     self.assertEqual(virus_dic[STA_K][1], H)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_contagious2(self):
     # i4 is infected and works at w1 like i1
     # i1 gets infected
     env_dic = {
         IW_K: g_d([-1, 1, -1, -1, 1, 0, -1, -1, -1, -1]),
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: g_d([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
     }
     virus_dic = {
         CON_K: g_d([1, -2, 1, 1, -5, 4, 1, 1, 1, 1]),
         STA_K: g_d([H, H, H, H, F, H, H, H, H, H]),
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0.001)
     self.assertEqual(virus_dic[STA_K][1], F)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_dangerous2(self):
     # i4 is infected and works at w1 like i1
     # They should not be in touch but i4 has a very bad behavior
     # i1 gets infected
     env_dic = {
         IW_K: g_d([-1, 1, -1, -1, 1, 0, -1, -1, -1, -1]),
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: g_d([1, 1, 1, 1, 100, 1, 1, 1, 1, 1])
     }
     virus_dic = {
         CON_K: g_d([1, -2, 1, 1, -5, 4, 1, 1, 1, 1]),
         STA_K: g_d([H, H, H, H, F, H, H, H, H, H]),
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.01, 0.1)
     self.assertEqual(virus_dic[STA_K][1], F)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_bad_behavior2(self):
     # Nobody should go to work (remote parameter high
     # But i1 and i4 have bad behavior
     # And since i1 is contagious, i4 gets infected
     env_dic = {
         IW_K: g_d([-1, 1, -1, -1, 1, 0, -1, -1, -1, -1]),
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: g_d([1, 100, 1, 1, 100, 1, 1, 1, 1, 1])
     }
     virus_dic = {
         CON_K: g_d([1, -2, 1, 1, 1, 4, 1, 1, 1, 1]),
         STA_K: g_d([H, F, H, H, H, H, H, H, H, H]),
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0.98)
     self.assertEqual(virus_dic[STA_K][1], F)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_carefull2(self):
     # i4 is infected and works at w1 like i1
     # They work closely together but i4 has a very good behavior
     # i1 stays healthy
     env_dic = {
         IW_K: g_d([-1, 1, -1, -1, 1, 0, -1, -1, -1, -1]),
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: g_d([1, 1, 1, 1, 0.0001, 1, 1, 1, 1, 1])
     }
     virus_dic = {
         CON_K: g_d([1, -2, 1, 1, -5, 4, 1, 1, 1, 1]),
         STA_K: g_d([H, H, H, H, F, H, H, H, H, H]),
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0)
     self.assertEqual(virus_dic[STA_K][1], H)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_good_behavior(self):
     # Nobody should go to work (remote parameter high
     # i1 have bad behavior but i4 a good behavior
     # And i4 does not get infected
     env_dic = {
         IW_K: {
             1: 1,
             4: 1,
             5: 0
         },
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: {
             1: 100,
             4: 0.01,
             5: 1
         }
     }
     virus_dic = {
         CON_K: {
             1: -2,
             4: 1,
             5: 4
         },
         STA_K: {
             1: F,
             4: H,
             5: H
         },
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 0.99, 0.98)
     self.assertEqual(virus_dic[STA_K][1], F)
     self.assertEqual(virus_dic[STA_K][4], H)
     self.assertEqual(virus_dic[STA_K][5], H)
 def test_propagate_to_workplaces_contagious_carefull(self):
     # i4 is infected and works at w1 like i1
     # i1 does not get infected because he is carefull
     env_dic = {
         IW_K: {
             1: 1,
             4: 1,
             5: 0
         },
         WI_K: {
             0: [5],
             1: [4, 1]
         },
         IBE_K: {
             1: 0.00001,
             4: 1,
             5: 1
         }
     }
     virus_dic = {
         CON_K: {
             1: -2,
             4: -5,
             5: 4
         },
         STA_K: {
             1: H,
             4: F,
             5: H
         },
         NC_K: 0
     }
     propagate_to_workplaces(env_dic, virus_dic, 1, -100000)
     self.assertEqual(virus_dic[STA_K][1], H)
     self.assertEqual(virus_dic[STA_K][4], F)
     self.assertEqual(virus_dic[STA_K][5], H)
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
コード例 #22
0
def launch_run(params, env_dic):
    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]):
        propagate_to_houses(env_dic, virus_dic, params[house_infect_key])
        propagate_to_transportation(env_dic, virus_dic, params[transport_infection_key],
                                    params[remote_work_key], params[transport_contact_cap_key])
        ind_work = propagate_to_workplaces(env_dic, virus_dic, params[work_infection_key], params[remote_work_key])
        ind_sto = 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)
        ind_works.append(ind_work)
        ind_stos.append(ind_sto)
        stas.append(virus_dic[STA_K])
コード例 #23
0
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]) < 3:
        raise AssertionError("Need more additional_scenario parameter")
    else:
        assert (params[additional_scenario_params_key][2] in ["False", "True"])
        rate_daily_vaccinated = int(params[additional_scenario_params_key][0])
        variant_kind = params[additional_scenario_params_key][1]
        restrict_genetic_cost = params[additional_scenario_params_key][
            2] == "True"

    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

    # Variant parameters
    variant_contagiosity = 1
    variant_immunization = 1
    variant_mortality = 1  # tradeoff parameter
    variant_hospital = 1  # tradeoff parameter

    death_stat = []

    for param_variant_iter in range(params[nvariant_key]):
        # Update parameters
        # Range [0.25, 1.75] with a 1/param step (+/- 75%)
        if variant_kind == "C":
            variant_contagiosity = 0.25 + 1.5 * param_variant_iter / params[
                nvariant_key]
        if variant_kind == "I":
            variant_immunization = 1 + 2 * param_variant_iter / params[
                nvariant_key]
        if variant_kind == "M":
            variant_mortality = 0.25 + 1.5 * param_variant_iter / params[
                nvariant_key]
        if variant_kind == "H":
            variant_hospital = 0.25 + 1.5 * param_variant_iter / params[
                nvariant_key]
        if variant_kind == "MH" or variant_kind == "HM":
            variant_mortality = 0.25 + 1.5 * param_variant_iter / params[
                nvariant_key]
            variant_hospital = 1.75 - 1.5 * param_variant_iter / params[
                nvariant_key]

        if restrict_genetic_cost:
            variant_total_cost = variant_contagiosity + variant_immunization + variant_mortality + variant_hospital
            variant_contagiosity /= variant_total_cost
            variant_immunization /= variant_total_cost
            variant_mortality /= variant_total_cost
            variant_hospital /= variant_total_cost

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

        params[variant_mortality_k] = variant_mortality
        params[death_bounds_key] = (8 / variant_mortality,
                                    31 / variant_mortality)

        params[variant_hospitalization_k] = variant_hospital
        params[hospitalization_bounds_key] = (8 / variant_hospital,
                                              16 / variant_hospital)

        # assuming about a year of immunity (~flu)
        params[immunity_bounds_key] = (int(270 / variant_immunization),
                                       int(450 / variant_immunization))
        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)

        death_stat.append(len(get_deadpeople(virus_dic)))
    return run_id, {"dea": np.array(death_stat)}
コード例 #24
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)

    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
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)

    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
コード例 #27
0
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