def test_increment_pandemic_1_day_hospitals_almost_full_indiv_hospitalized(self): # i0 and i1 are hospitalized # i0 is 82 year old # Hospitals are completely full and i0's mortality rate are high # i1 survive and become immune but i0 dies random.seed(22) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 2, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } def get_infection_params(): return get_infection_parameters(2, 7, 7, 21, 21, 39, 30, 60) virus_dic = { CON_K: {0: -8, 1: -9, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: -5, 1: -6, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 1, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, # Two hospitalized people (going to decision next day) STA_K: {0: P, 1: P, 2: P, 3: P, 4: P, 5: P, 6: P, 7: P, 8: P, 9: P}, FN_K: get_infection_params } env_dic[IAG_K][0] = 82 env_dic[IAG_K][1] = 15 increment_pandemic_1_day(env_dic, virus_dic, 1.5) self.assertEqual(virus_dic[STA_K][0], D) self.assertEqual(virus_dic[STA_K][1], M)
def test_increment_pandemic_1_day_hospitals_completely_full(self): # i0 and i1 are hospitalized # Hospitals are completely full # They both die random.seed(22) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 2, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IDEA_K: {0: 0.02, 1: 0.013, 2: 0.02, 3: 0, 4: 0.02, 5: 0.02, 6: 0, 7: 0, 8: 0.02, 9: 0.02}, IHOS_K: {0: 0.025, 1: 0.074, 2: 0.01, 3: 0.03, 4: 0.025, 5: 0.025, 6: 0.03, 7: 0.03, 8: 0.025, 9: 0.025}, ISYM_K: {0: 0.0, 1: 0.02, 2: 0.05, 3: 0.08, 4: 0.13, 5: 0.13, 6: 0.23, 7: 0.26, 8: 0.55}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } virus_dic = { CON_K: {0: -8, 1: -9, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: -5, 1: -6, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 1, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, CON_INIT_K: {0: -8, 1: -9, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_INIT_K: {0: -5, 1: -6, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_INIT_K: {0: 1, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_INIT_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, variant_mortality_k: 1, variant_hospitalization_k: 1, STA_K: {0: P, 1: P, 2: P, 3: P, 4: P, 5: P, 6: P, 7: P, 8: P, 9: P} } increment_pandemic_1_day(env_dic, virus_dic, 0.005) self.assertEqual(virus_dic[STA_K][0], D) self.assertEqual(virus_dic[STA_K][1], D)
def test_increment_pandemic_1_day_isolated_cases(self): # i3 is going to be hospitalized # i3 lives in house h0 # i1, i2 and i3 live in h0 # i0 is infected, thus will be tested and isolated # i1 is immune and must stay like this and i2 is dead random.seed(14) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 82, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } def get_infection_params(): return get_infection_parameters(2, 7, 7, 21, 21, 39, 30, 60) virus_dic = { CON_K: {0: 4, 1: -2, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: 2, 1: 12, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 31, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, STA_K: {0: F, 1: F, 2: D, 3: F, 4: F, 5: M, 6: F, 7: F, 8: M, 9: H}, FN_K: get_infection_params } increment_pandemic_1_day(env_dic, virus_dic, 100) # person 0 will be isolated since a member of his family(person 3)is hospitalized (what a sad story for him) self.assertEqual(virus_dic[STA_K][0], S) self.assertEqual(virus_dic[STA_K][1], M) self.assertEqual(virus_dic[STA_K][2], D) self.assertEqual(virus_dic[STA_K][3], P)
def test_increment_pandemic_1_day_hospitals_empty(self): # i0 and i1 are infected # Hospitals are empty and their mortality rate are low # They survive and become immune random.seed(22) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 2, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } def get_infection_params(): return get_infection_parameters(2, 7, 7, 21, 21, 39, 30, 60) virus_dic = { CON_K: {0: -8, 1: -9, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: -5, 1: -6, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 1, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, STA_K: {0: F, 1: F, 2: P, 3: P, 4: P, 5: P, 6: P, 7: P, 8: P, 9: P}, FN_K: get_infection_params } env_dic[IAG_K][0] = 82 env_dic[IAG_K][1] = 15 increment_pandemic_1_day(env_dic, virus_dic, 1) self.assertEqual(virus_dic[STA_K][0], M) self.assertEqual(virus_dic[STA_K][1], M)
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_increment_pandemic_1_day_hospitals_almost_full_indiv_hospitalized(self): # i0 and i1 are hospitalized # i0 is 82 year old # Hospitals are completely full and i0's mortality rate are high # i1 survive and become immune but i0 dies random.seed(22) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 82, 1: 15, 2: 13, 3: 2, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IDEA_K: {0: 0.52, 1: 0.013, 2: 0.02, 3: 0, 4: 0.02, 5: 0.02, 6: 0, 7: 0, 8: 0.02, 9: 0.02}, IHOS_K: {0: 0.025, 1: 0.074, 2: 0.01, 3: 0.03, 4: 0.025, 5: 0.025, 6: 0.03, 7: 0.03, 8: 0.025, 9: 0.025}, ISYM_K: {0: 0.0, 1: 0.02, 2: 0.05, 3: 0.08, 4: 0.13, 5: 0.13, 6: 0.23, 7: 0.26, 8: 0.55}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } virus_dic = { CON_K: {0: -8, 1: -9, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: -5, 1: -6, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 1, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, CON_INIT_K: {0: -8, 1: -9, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_INIT_K: {0: -5, 1: -6, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_INIT_K: {0: 1, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_INIT_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, variant_mortality_k: 1, variant_hospitalization_k: 1, # Two hospitalized people (going to decision next day) STA_K: {0: P, 1: P, 2: P, 3: P, 4: P, 5: P, 6: P, 7: P, 8: P, 9: P} } increment_pandemic_1_day(env_dic, virus_dic, 1.5) self.assertEqual(virus_dic[STA_K][0], D) self.assertEqual(virus_dic[STA_K][1], M)
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 test_increment_pandemic_1_day_hospitals_completely_full(self): # i0 and i1 are hospitalized # Hospitals are completely full # They both die random.seed(22) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 2, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } def get_infection_params(): return get_infection_parameters(2, 7, 7, 21, 21, 39, 30, 60) virus_dic = { CON_K: {0: -8, 1: -9, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: -5, 1: -6, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 1, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, STA_K: {0: P, 1: P, 2: P, 3: P, 4: P, 5: P, 6: P, 7: P, 8: P, 9: P}, FN_K: get_infection_params } env_dic[IAG_K][0] = 82 env_dic[IAG_K][1] = 15 increment_pandemic_1_day(env_dic, virus_dic, 0.005) self.assertEqual(virus_dic[STA_K][0], D) self.assertEqual(virus_dic[STA_K][1], D)
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
def test_increment_pandemic_1_day(self): random.seed(22) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 2, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } def get_infection_params(): return get_infection_parameters(2, 7, 7, 21, 21, 39, 30, 60) virus_dic = { CON_K: {0: 4, 1: -2, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: 12, 1: 12, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 31, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, STA_K: {0: H, 1: F, 2: D, 3: F, 4: F, 5: M, 6: F, 7: F, 8: M, 9: H}, FN_K: get_infection_params } env_dic[IAG_K][3] = 82 increment_pandemic_1_day(env_dic, virus_dic, 100) self.assertEqual(virus_dic[CON_K][0], 4) self.assertEqual(virus_dic[HOS_K][0], 12) self.assertEqual(virus_dic[DEA_K][0], 31) self.assertEqual(virus_dic[STA_K][0], H) self.assertEqual(virus_dic[CON_K][1], -3) self.assertEqual(virus_dic[HOS_K][1], 11) self.assertEqual(virus_dic[DEA_K][1], 0) self.assertEqual(virus_dic[STA_K][1], M) self.assertEqual(virus_dic[CON_K][2], -5) self.assertEqual(virus_dic[HOS_K][2], 20) self.assertEqual(virus_dic[DEA_K][2], 0) self.assertEqual(virus_dic[STA_K][2], D) self.assertEqual(virus_dic[CON_K][3], -5) self.assertEqual(virus_dic[HOS_K][3], 0) self.assertEqual(virus_dic[DEA_K][3], 21) self.assertEqual(virus_dic[STA_K][3], F) self.assertEqual(virus_dic[CON_K][5], -9) self.assertEqual(virus_dic[DEA_K][5], 0) self.assertEqual(virus_dic[STA_K][5], M) self.assertEqual(virus_dic[CON_K][6], -4) self.assertEqual(virus_dic[HOS_K][6], 13) self.assertEqual(virus_dic[DEA_K][6], 0) self.assertEqual(virus_dic[STA_K][6], M) # Parameters have been reset self.assertEqual(virus_dic[CON_K][8], 6) self.assertEqual(virus_dic[HOS_K][8], 9) self.assertEqual(virus_dic[DEA_K][8], 23) self.assertEqual(virus_dic[IMM_K][8], 49) self.assertEqual(virus_dic[STA_K][8], H)
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 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): 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])
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 test_increment_pandemic_1_day_isolated_cases(self): # i3 is going to be hospitalized # i3 lives in house h0 # i1, i2 and i3 live in h0 # i0 is infected, thus will be tested and isolated # i1 is immune and must stay like this and i2 is dead random.seed(14) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 82, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IDEA_K: {0: 0.02, 1: 0.013, 2: 0.02, 3: 0, 4: 0.02, 5: 0.02, 6: 0, 7: 0, 8: 0.02, 9: 0.02}, IHOS_K: {0: 0.025, 1: 0.074, 2: 0.01, 3: 0.73, 4: 0.025, 5: 0.025, 6: 0.03, 7: 0.03, 8: 0.025, 9: 0.025}, ISYM_K: {0: 0.0, 1: 0.02, 2: 0.05, 3: 0.08, 4: 0.13, 5: 0.13, 6: 0.23, 7: 0.26, 8: 0.55}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } virus_dic = { CON_K: {0: 4, 1: -2, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: 2, 1: 12, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 31, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, CON_INIT_K: {0: 4, 1: -2, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_INIT_K: {0: 2, 1: 12, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_INIT_K: {0: 31, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_INIT_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, variant_mortality_k: 1, variant_hospitalization_k: 1, STA_K: {0: F, 1: F, 2: D, 3: F, 4: F, 5: M, 6: F, 7: F, 8: M, 9: H} } increment_pandemic_1_day(env_dic, virus_dic, 100) # person 0 will be isolated since a member of his family(person 3)is hospitalized (what a sad story for him) self.assertEqual(virus_dic[STA_K][0], S) self.assertEqual(virus_dic[STA_K][1], M) self.assertEqual(virus_dic[STA_K][2], D) self.assertEqual(virus_dic[STA_K][3], P)
def test_increment_pandemic_1_day(self): random.seed(22) env_dic = { HI_K: {0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9]}, IAG_K: {0: 26, 1: 51, 2: 13, 3: 2, 4: 35, 5: 33, 6: 6, 7: 1, 8: 27, 9: 20}, IDEA_K: {0: 0.02, 1: 0.013, 2: 0.02, 3: 0, 4: 0.02, 5: 0.02, 6: 0, 7: 0, 8: 0.02, 9: 0.02}, IHOS_K: {0: 0.025, 1: 0.074, 2: 0.01, 3: 0.03, 4: 0.025, 5: 0.025, 6: 0.03, 7: 0.03, 8: 0.025, 9: 0.025}, ISYM_K: {0: 0.0, 1: 0.02, 2: 0.05, 3: 0.08, 4: 0.13, 5: 0.13, 6: 0.23, 7: 0.26, 8: 0.55}, IH_K: {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2}, } virus_dic = { CON_K: {0: 4, 1: -2, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_K: {0: 12, 1: 12, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_K: {0: 31, 1: 1, 2: 0, 3: 22, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, CON_INIT_K: {0: 4, 1: -2, 2: -5, 3: -4, 4: 6, 5: -9, 6: -3, 7: 2, 8: -9, 9: 5}, HOS_INIT_K: {0: 12, 1: 12, 2: 20, 3: 1, 4: 16, 5: 12, 6: 14, 7: 13, 8: -7, 9: 8}, DEA_INIT_K: {0: 31, 1: 1, 2: 0, 3: 2, 4: 22, 5: 0, 6: 1, 7: 22, 8: -4, 9: 38}, IMM_INIT_K: {0: 53, 1: 47, 2: 52, 3: 51, 4: 58, 5: 58, 6: 44, 7: 53, 8: 1, 9: 55}, variant_mortality_k: 1, variant_hospitalization_k: 1, STA_K: {0: H, 1: F, 2: D, 3: F, 4: F, 5: M, 6: F, 7: F, 8: M, 9: H} } env_dic[IAG_K][3] = 82 increment_pandemic_1_day(env_dic, virus_dic, 100) self.assertEqual(virus_dic[CON_K][0], 4) self.assertEqual(virus_dic[HOS_K][0], 12) self.assertEqual(virus_dic[DEA_K][0], 31) self.assertEqual(virus_dic[STA_K][0], H) self.assertEqual(virus_dic[CON_K][1], -3) self.assertEqual(virus_dic[HOS_K][1], 11) self.assertEqual(virus_dic[DEA_K][1], 0) self.assertEqual(virus_dic[STA_K][1], M) self.assertEqual(virus_dic[CON_K][2], -5) self.assertEqual(virus_dic[HOS_K][2], 20) self.assertEqual(virus_dic[DEA_K][2], 0) self.assertEqual(virus_dic[STA_K][2], D) self.assertEqual(virus_dic[CON_K][3], -5) self.assertEqual(virus_dic[HOS_K][3], 0) self.assertEqual(virus_dic[DEA_K][3], 21) self.assertEqual(virus_dic[STA_K][3], S) self.assertEqual(virus_dic[CON_K][5], -9) self.assertEqual(virus_dic[DEA_K][5], 0) self.assertEqual(virus_dic[STA_K][5], M) self.assertEqual(virus_dic[CON_K][6], -4) self.assertEqual(virus_dic[HOS_K][6], 13) self.assertEqual(virus_dic[DEA_K][6], 0) self.assertEqual(virus_dic[STA_K][6], M) # Parameters have been reset self.assertEqual(virus_dic[CON_K][8], -9) self.assertEqual(virus_dic[HOS_K][8], -7) self.assertEqual(virus_dic[DEA_K][8], -4) self.assertEqual(virus_dic[IMM_K][8], 1) self.assertEqual(virus_dic[STA_K][8], H)
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)}
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
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") 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