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) 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 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 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, 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): 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 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 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_houses_careful_daddy_people(self): # i0 is infected and lives with i1, i2 and i3 # But i0 is very carefull with very good behabior (0.01) # He does not infect i1, i2 nor i3 env_dic = { HI_K: { 0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9] }, IH_K: { 0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2 }, IBE_K: { 0: 0.01, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1 } } virus_dic = { CON_K: { 0: -9, 1: 3, 2: 2, 3: 2, 4: -9, 5: 4, 6: 4, 7: 2, 8: 6, 9: 5 }, STA_K: { 0: F, 1: H, 2: H, 3: H, 4: D, 5: H, 6: H, 7: H, 8: M, 9: H }, NC_K: 0 } propagate_to_houses(env_dic, virus_dic, 0.99) self.assertEqual(virus_dic[STA_K][0], F) # careful people do not contaminate self.assertEqual(virus_dic[STA_K][1], H) self.assertEqual(virus_dic[STA_K][2], H) self.assertEqual(virus_dic[STA_K][3], H)
def test_propagate_to_houses_noncontagious_people(self): # i0 is infected and lives with i1, i2 and i3 # But i0 is not contagious yet # He does not infect anyone. env_dic = { HI_K: { 0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9] }, IH_K: { 0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2 }, IBE_K: { 0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1 } } virus_dic = { CON_K: { 0: 4, 1: 3, 2: 2, 3: 2, 4: 6, 5: 4, 6: 4, 7: 2, 8: 6, 9: 5 }, STA_K: { 0: F, 1: H, 2: H, 3: H, 4: D, 5: H, 6: H, 7: H, 8: M, 9: H }, NC_K: 0 } propagate_to_houses(env_dic, virus_dic, 0.99) self.assertEqual(virus_dic[STA_K][1], H) self.assertEqual(virus_dic[STA_K][2], H) self.assertEqual(virus_dic[STA_K][3], H) self.assertEqual(virus_dic[STA_K][5], H) self.assertEqual(virus_dic[STA_K][6], H) self.assertEqual(virus_dic[STA_K][7], H) self.assertEqual(virus_dic[STA_K][9], H)
def test_propagate_to_houses_very_dangerous_daddy_people(self): # i0 is infected and lives with i1 to i9 # But i0 is a very bad daddy (0.99 behavior) # He does infect all his (big) family env_dic = { HI_K: { 0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] }, IH_K: { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0 }, IBE_K: { 0: 0.99, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1 } } virus_dic = { CON_K: { 0: -9, 1: 3, 2: 2, 3: 2, 4: -9, 5: 4, 6: 4, 7: 2, 8: 6, 9: 5 }, STA_K: { 0: F, 1: H, 2: H, 3: H, 4: H, 5: H, 6: H, 7: H, 8: H, 9: H }, NC_K: 0 } propagate_to_houses(env_dic, virus_dic, 0.99) self.assertEqual(virus_dic[STA_K][0], F) self.assertEqual(sum(virus_dic[STA_K].values()), 10)
def test_propagate_to_houses_contagious_people(self): # i0 is infected and lives in h0. He infects i1, i2 and i3 # i4 is dead and does not infect anyone (i5, i6 and i7) # i8 is immune and does not infect i9 env_dic = { HI_K: { 0: [0, 1, 2, 3], 1: [4, 5, 6, 7], 2: [8, 9] }, IH_K: { 0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2 }, IBE_K: { 0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1 } } virus_dic = { CON_K: { 0: -9, 1: 3, 2: 2, 3: 2, 4: -9, 5: 4, 6: 4, 7: 2, 8: 6, 9: 5 }, STA_K: { 0: F, 1: H, 2: H, 3: H, 4: D, 5: H, 6: H, 7: H, 8: M, 9: H }, NC_K: 0 } propagate_to_houses(env_dic, virus_dic, 0.99) self.assertEqual(virus_dic[STA_K][0], F) self.assertEqual(virus_dic[STA_K][4], D) self.assertEqual(virus_dic[STA_K][8], M) # infected people contaminate self.assertEqual(virus_dic[STA_K][1], F) self.assertEqual(virus_dic[STA_K][2], F) self.assertEqual(virus_dic[STA_K][3], F) # Dead people do not contaminate self.assertEqual(virus_dic[STA_K][5], H) self.assertEqual(virus_dic[STA_K][6], H) self.assertEqual(virus_dic[STA_K][7], H) # Immune people do not contaminate self.assertEqual(virus_dic[STA_K][9], 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") 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) 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): 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): 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