From 0d7e92eab16272ee338cc4eed74beb23f644cae7 Mon Sep 17 00:00:00 2001 From: rakow Date: Tue, 28 Jun 2022 14:22:45 +0200 Subject: [PATCH 001/128] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5186608b1..6bc4aab12 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.github.matsim-org matsim-episim - 21.12 + 22.7-SNAPSHOT MATSim Episim Epidemic simulation for MATSim From 358edd3197d55334708e5d6705a5b1e2ca6c3be4 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Fri, 1 Jul 2022 15:01:30 +0200 Subject: [PATCH 002/128] antibody writer --- .../org/matsim/episim/EpisimReporting.java | 47 +++++++++++-- .../model/listener/WriteAntibodies.java | 70 +++++++++++++++++++ .../modules/SnzCologneProductionScenario.java | 10 ++- 3 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java diff --git a/src/main/java/org/matsim/episim/EpisimReporting.java b/src/main/java/org/matsim/episim/EpisimReporting.java index 93c612905..133809c2d 100644 --- a/src/main/java/org/matsim/episim/EpisimReporting.java +++ b/src/main/java/org/matsim/episim/EpisimReporting.java @@ -100,7 +100,7 @@ public final class EpisimReporting implements BasicEventHandler, Closeable, Exte public final Object2IntMap vaccinations = new Object2IntOpenHashMap<>(); /** - * Map of (VaccinationType, nth Vaccination) -> Number per day + * Map of (VaccinationType, nth Vaccination) -> Number per day */ public final Object2IntMap> vaccinationStats = new Object2IntOpenHashMap<>(); @@ -126,7 +126,6 @@ public final class EpisimReporting implements BasicEventHandler, Closeable, Exte private final ByteArrayOutputStream os; - private final Config config; private final EpisimConfigGroup episimConfig; private final VaccinationConfigGroup vaccinationConfig; @@ -147,6 +146,8 @@ public final class EpisimReporting implements BasicEventHandler, Closeable, Exte private BufferedWriter vaccinationsPerType; private BufferedWriter vaccinationsPerTypeAndNumber; + private final Map externalWriters = new HashMap<>(); + private String memorizedDate = null; /** @@ -205,7 +206,7 @@ public final class EpisimReporting implements BasicEventHandler, Closeable, Exte outdoorFraction = EpisimWriter.prepare(base + "outdoorFraction.tsv", "day", "date", "outdoorFraction"); virusStrains = EpisimWriter.prepare(base + "strains.tsv", "day", "date", (Object[]) VirusStrain.values()); cpuTime = EpisimWriter.prepare(base + "cputime.tsv", "iteration", "where", "what", "when", "thread"); - antibodiesPerPerson = EpisimWriter.prepare(base + "antibodies.tsv", "day", "date", (Object[]) VirusStrain.values()); + antibodiesPerPerson = EpisimWriter.prepare(base + "antibodies.tsv", "day", "date", (Object[]) VirusStrain.values()); vaccinationsPerType = EpisimWriter.prepare(base + "vaccinations.tsv", "day", "date", (Object[]) VaccinationType.values()); vaccinationsPerTypeAndNumber = EpisimWriter.prepare(base + "vaccinationsDetailed.tsv", "day", "date", "type", "number", "amount"); @@ -263,7 +264,7 @@ void append(String date) throws IOException { // Copy non prefixed files to base output if (!base.equals(outDir)) for (String file : List.of("infections.txt", "infectionEvents.txt", "restrictions.txt", "timeUse.txt", "diseaseImport.tsv", - "outdoorFraction.tsv", "strains.tsv", "antibodies.tsv", "vaccinations.tsv", "vaccinationsDetailed.tsv", "events.tar")) { + "outdoorFraction.tsv", "strains.tsv", "antibodies.tsv", "vaccinations.tsv", "vaccinationsDetailed.tsv", "events.tar")) { Path path = Path.of(outDir, file); if (Files.exists(path)) { Files.move(path, Path.of(base + file), StandardCopyOption.REPLACE_EXISTING); @@ -292,6 +293,34 @@ void append(String date) throws IOException { writeConfigFiles(); } + /** + * Create and registered a new writer. Note that this writer should not be used directly, instead use {@link #writeAsync(BufferedWriter, String)} + */ + public BufferedWriter registerWriter(String filename) { + + if (externalWriters.containsKey(filename)) + throw new IllegalStateException("Writer already registered: " + filename); + + BufferedWriter writer = EpisimWriter.prepare(base + filename); + externalWriters.put(filename, writer); + + return writer; + } + + /** + * Appends some content asynchronously to a writer in thread-safe manner. + */ + public void writeAsync(BufferedWriter writer, String content) { + this.writer.append(writer, content); + } + + /** + * Close writer asynchronously. + */ + public void closeAsync(BufferedWriter writer) { + this.writer.close(writer); + } + /** * Checks whether a person is vaccinated (and has full effectiveness). */ @@ -754,7 +783,7 @@ void reportVaccination(Id personId, int iteration, VaccinationType type, * Write container statistic to file. */ void reportContainerUsage(Object2IntMap> maxGroupSize, Object2IntMap> totalUsers, - Map, Object2IntMap> activityUsage) { + Map, Object2IntMap> activityUsage) { BufferedWriter out = EpisimWriter.prepare(base + "containerUsage.txt.gz", "id", "types", "totalUsers", "maxGroupSize"); @@ -798,7 +827,7 @@ void reportAntibodyLevel(Object2DoubleMap antibodies, int n, int it out[1] = date; for (int i = 0; i < VirusStrain.values().length; i++) { - out[i+2] = String.valueOf(antibodies.getDouble(VirusStrain.values()[i]) / n); + out[i + 2] = String.valueOf(antibodies.getDouble(VirusStrain.values()[i]) / n); } writer.append(antibodiesPerPerson, out); @@ -850,6 +879,10 @@ public void close() { writer.close(vaccinationsPerType); writer.close(vaccinationsPerTypeAndNumber); + for (BufferedWriter v : externalWriters.values()) { + writer.close(v); + } + if (singleEvents) { try { zipOut.close(); @@ -1001,7 +1034,7 @@ public void readExternal(ObjectInput in) throws IOException { enum InfectionsWriterFields { time, day, date, nSusceptible, nSusceptibleVaccinated, nInfectedButNotContagious, nInfectedButNotContagiousVaccinated, nContagious, nContagiousVaccinated, nShowingSymptoms, nShowingSymptomsVaccinated, nSeriouslySick, nSeriouslySickVaccinated, nCritical, nCriticalVaccinated, nTotalInfected, nTotalInfectedVaccinated, nInfectedCumulative, nInfectedCumulativeVaccinated, nContagiousCumulative, nContagiousCumulativeVaccinated, nShowingSymptomsCumulative, nShowingSymptomsCumulativeVaccinated, nSeriouslySickCumulative, nSeriouslySickCumulativeVaccinated, nCriticalCumulative, - nCriticalCumulativeVaccinated, nRecovered, nRecoveredVaccinated, nInQuarantineFull, nInQuarantineHome, nVaccinated, nReVaccinated, nTested, nDeceasedCumulative, nDeceasedCumulativeVaccinated, district + nCriticalCumulativeVaccinated, nRecovered, nRecoveredVaccinated, nInQuarantineFull, nInQuarantineHome, nVaccinated, nReVaccinated, nTested, nDeceasedCumulative, nDeceasedCumulativeVaccinated, district } enum InfectionEventsWriterFields {time, infector, infected, infectionType, date, groupSize, facility, virusStrain, probability} diff --git a/src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java b/src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java new file mode 100644 index 000000000..4a7746aca --- /dev/null +++ b/src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java @@ -0,0 +1,70 @@ +package org.matsim.episim.model.listener; + +import com.google.inject.Inject; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.Person; +import org.matsim.episim.EpisimPerson; +import org.matsim.episim.EpisimReporting; +import org.matsim.episim.InfectionEventHandler; +import org.matsim.episim.model.SimulationListener; +import org.matsim.episim.model.VirusStrain; +import org.matsim.facilities.ActivityFacility; +import org.matsim.vehicles.Vehicle; + +import java.io.BufferedWriter; +import java.time.LocalDate; +import java.util.Arrays; +import java.util.Map; +import java.util.SplittableRandom; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * Writes antibody leven into a matrix + */ +public class WriteAntibodies implements SimulationListener { + + private Map, EpisimPerson> persons; + @Inject + private EpisimReporting reporting; + private BufferedWriter writer; + + + @Override + public void init(SplittableRandom rnd, Map, EpisimPerson> persons, Map, InfectionEventHandler.EpisimFacility> facilities, Map, InfectionEventHandler.EpisimVehicle> vehicles) { + this.persons = persons; + this.writer = reporting.registerWriter("antibodiesPerAge.tsv"); + } + + @Override + public void onIterationEnd(int iteration, LocalDate date) { + + if (iteration == 100) { + + String header = VirusStrain.class.getSimpleName() + "\t" + IntStream.range(0, 120).mapToObj(String::valueOf).collect(Collectors.joining("\t")) + "\n"; + + reporting.writeAsync(writer, header); + + for (VirusStrain strain : VirusStrain.values()) { + + // Rolling mean per age group + int[] n = new int[120]; + double[] values = new double[120]; + + for (EpisimPerson p : persons.values()) { + + int i = p.getAge(); + n[i]++; + values[i] = values[i] + (p.getAntibodies(strain) - values[i]) / n[i]; + + } + + String row = strain.name() + "\t" + Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining("\t")) + "\n"; + + reporting.writeAsync(writer, row); + } + + reporting.closeAsync(writer); + } + } +} diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index a71c9ca78..69f40d3c8 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -30,6 +30,7 @@ import org.matsim.episim.model.activity.LocationBasedParticipationModel; import org.matsim.episim.model.input.CreateRestrictionsFromCSV; import org.matsim.episim.model.listener.HouseholdSusceptibility; + import org.matsim.episim.model.listener.WriteAntibodies; import org.matsim.episim.model.progression.AgeDependentDiseaseStatusTransitionModel; import org.matsim.episim.model.progression.DiseaseStatusTransitionModel; import org.matsim.episim.model.testing.TestType; @@ -259,8 +260,13 @@ protected void configure() { .withAgeGroup("60+", 151722) */ - Multibinder.newSetBinder(binder(), SimulationListener.class) - .addBinding().to(HouseholdSusceptibility.class); + Multibinder listener = Multibinder.newSetBinder(binder(), SimulationListener.class); + + listener.addBinding().to(HouseholdSusceptibility.class); + + // Write antibodies, iteration is hard-coded + + // listener.addBinding().to(WriteAntibodies.class); } From 5783618e90c60cca8992cd126ef49ee264beb13b Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 1 Jul 2022 15:21:06 +0200 Subject: [PATCH 003/128] cherrypicked masterJR-utils --- src/main/R/masterJR-utils.R | 573 ++++++++++++++++++++++++++++++++++++ 1 file changed, 573 insertions(+) create mode 100644 src/main/R/masterJR-utils.R diff --git a/src/main/R/masterJR-utils.R b/src/main/R/masterJR-utils.R new file mode 100644 index 000000000..3905c473b --- /dev/null +++ b/src/main/R/masterJR-utils.R @@ -0,0 +1,573 @@ +# Title : TODO +# Objective : TODO +# Created by: jakob +# Created on: 7/22/2021 + + +# Functions: +# read_and_process_episim_infections <- function(directory, facilities_to_district_map) { +# fac_to_district_map <- read_delim(facilities_to_district_map, +# ";", escape_double = FALSE, col_names = FALSE, +# trim_ws = TRUE) %>% +# rename("facility" = "X1") %>% +# rename("district" = "X2") +# +# fac_to_district_map[is.na(fac_to_district_map)] <- "not_berlin" +# +# info_df <- read_delim(paste0(directory, "_info.txt"), delim = ";") +# +# # gathers column names that should be included in final dataframe +# col_names <- colnames(info_df) +# relevant_cols <- col_names[!col_names %in% c("RunScript", "RunId", "Config", "Output")] +# +# episim_df_all_runs <- data.frame() +# +# for (row in seq_len(nrow(info_df))) { +# +# runId <- info_df$RunId[row] +# seed <- info_df$seed[row] +# +# file_name <- paste0(directory, runId, ".infectionEvents.txt") +# +# if (!file.exists(file_name)) { +# warning(paste0(file_name, " does not exist")) +# next +# } +# +# df_for_run <- read_delim(file = file_name, +# "\t", escape_double = FALSE, trim_ws = TRUE) %>% +# select(date, facility) +# +# # adds important variables concerning run to df, so that individual runs can be filtered in later steps +# for (var in relevant_cols) { +# df_for_run[var] <- info_df[row, var] +# } +# +# episim_df_all_runs <- rbind(episim_df_all_runs, df_for_run) +# +# } +# +# episim_df2 <- episim_df_all_runs %>% filter(!grepl("^tr_", facility)) +# +# merged <- episim_df2 %>% +# left_join(fac_to_district_map, by = c("facility"), keep = TRUE) +# +# na_facs <- merged %>% +# filter(is.na(district)) %>% +# pull(facility.x) +# length(unique(na_facs)) +# +# episim_final <- merged %>% +# filter(!is.na(district)) %>% +# filter(district != "not_berlin") %>% +# select(!starts_with("facility")) %>% +# group_by_all() %>% +# count() %>% +# group_by(across(c(-n, -seed))) %>% +# summarise(infections = mean(n)) +# +# return(episim_final) +# } + +convert_infections_into_incidence <- function(directory, infections_raw, aggregate_seeds) { + run_params <- get_run_parameters(directory) + infections <- infections_raw %>% + select(date, nShowingSymptomsCumulative, nSusceptible, district, run_params) %>% + filter(district != "unknown") %>% + arrange(date) %>% + group_by(district, across(run_params)) %>% + mutate(infections_1dayAgo = lag(nShowingSymptomsCumulative, default = 0, order_by = date)) %>% + mutate(infections_7daysAgo = lag(nShowingSymptomsCumulative, default = 0, n = 7, order_by = date)) %>% + mutate(infections = nShowingSymptomsCumulative - infections_1dayAgo) %>% + mutate(infections_week = nShowingSymptomsCumulative - infections_7daysAgo) %>% + mutate(population = first(nSusceptible)) %>% + mutate(incidence = infections_week / population * 100000) %>% + ungroup() %>% + select(-c(population, infections_1dayAgo, infections_7daysAgo, nSusceptible)) %>% + arrange(date) + + if (aggregate_seeds == FALSE) { + return(infections) + } + + infections_aggregated <- infections %>% + group_by(across(-c(nShowingSymptomsCumulative, infections, infections_week, incidence, seed))) %>% + summarise(infections = mean(infections), + nShowingSymptomsCumulative = mean(nShowingSymptomsCumulative), + infections_week = mean(infections_week), + incidence = mean(incidence)) + return(infections_aggregated) + +} + + +geolocate_infections <- function(infections_raw, facilities_to_district_map) { + + # read facilities + fac_to_district_map <- read_delim(facilities_to_district_map, + ";", escape_double = FALSE, col_names = FALSE, + trim_ws = TRUE) %>% + rename("facility" = "X1") %>% + rename("district" = "X2") + + fac_to_district_map[is.na(fac_to_district_map)] <- "not_berlin" + + # filter, merge, & find count per district + merged <- infections_raw %>% + select(-c(time, infector, infected, infectionType, groupSize, virusStrain, probability)) %>% + filter(!grepl("^tr_", facility)) %>% + left_join(fac_to_district_map, by = c("facility"), keep = TRUE) %>% + filter(!is.na(district)) %>% + filter(district != "not_berlin") %>% + select(!starts_with("facility")) %>% + group_by_all() %>% + count() %>% + rename("infections" = "n") + + return(merged) + +} + + +# read_and_process_episim_timeUse <- function(directory) { +# +# info_df <- read_delim(paste0(directory, "_info.txt"), delim = ";") +# +# # gathers column names that should be included in final dataframe +# col_names <- colnames(info_df) +# relevant_cols <- col_names[!col_names %in% c("RunScript", "RunId", "Config", "Output")] +# +# episim_df_all_runs <- data.frame() +# for (row in seq_len(nrow(info_df))) { +# +# runId <- info_df$RunId[row] +# +# file_name <- paste0(directory, runId, ".timeUse.txt") +# +# if (!file.exists(file_name)) { +# warning(paste0(file_name, " does not exist")) +# next +# } +# +# df_for_run <- read_delim(file = file_name, +# "\t", escape_double = FALSE, trim_ws = TRUE) %>% +# pivot_longer(!c("day", "date"), names_to = "activity", values_to = "time") +# +# # adds important variables concerning run to df, so that individual runs can be filtered in later steps +# for (var in relevant_cols) { +# df_for_run[var] <- info_df[row, var] +# } +# +# episim_df_all_runs <- rbind(episim_df_all_runs, df_for_run) +# +# } +# } + +get_run_parameters <- function(directory) { + info_df <- read_delim(paste0(directory, "_info.txt"), delim = ";") + col_names <- colnames(info_df) + run_params <- col_names[!col_names %in% c("RunScript", "RunId", "Config", "Output")] + return(run_params) +} + +read_combine_episim_output <- function(directory, file_root, allow_missing_files) { + + info_df <- read_delim(paste0(directory, "_info.txt"), delim = ";") + + # gathers column names that should be included in final dataframe + col_names <- colnames(info_df) + relevant_cols <- col_names[!col_names %in% c("RunScript", "RunId", "Config", "Output")] + + episim_df_all_runs <- data.frame() + for (row in seq_len(nrow(info_df))) { + + runId <- info_df$RunId[row] + + file_name <- paste0(directory, runId, ".", file_root) + + if (!file.exists(file_name) & allow_missing_files) { + warning(paste0(file_name, " does not exist")) + next + } + + + df_for_run <- read_delim(file = file_name, "\t", escape_double = FALSE, trim_ws = TRUE) + + if (dim(df_for_run)[1] == 0) { + warning(paste0(file_name, " is empty")) + next + } + + # adds important variables concerning run to df, so that individual runs can be filtered in later steps + for (var in relevant_cols) { + df_for_run[var] <- info_df[row, var] + } + + episim_df_all_runs <- rbindlist(list(episim_df_all_runs, df_for_run)) + # episim_df_all_runs <- rbind(episim_df_all_runs, df_for_run) # inefficient + + } + + return(data.frame(episim_df_all_runs)) +} + + +read_and_process_new_rki_data_incidenz <- function(filename) { + rki <- read_excel(filename, + sheet = "LK_7-Tage-Inzidenz (fixiert)", skip = 4) + + rki_berlin <- rki %>% + filter(grepl("berlin", LK, ignore.case = TRUE)) %>% + select(-c("...1", "LKNR")) %>% + pivot_longer(!contains("LK"), names_to = "date", values_to = "cases") + + for (i in seq_len(nrow(rki_berlin))) { + dateX <- as.character(rki_berlin$date[i]) + if (grepl("44", dateX)) { + date_improved <- as.character(excel_numeric_to_date(as.numeric(dateX))) + rki_berlin$date[i] <- date_improved + } else { + date_improved <- dateX + rki_berlin$date[i] <- date_improved + } + } + + ymd <- ymd(rki_berlin$date) + dmy <- dmy(rki_berlin$date) + ymd[is.na(ymd)] <- dmy[is.na(ymd)] # some dates are ambiguous, here we give + rki_berlin$date <- ymd + + + rki_berlin$LK <- rki_berlin$LK %>% + str_replace("SK Berlin ", "") %>% + str_replace("-", "_") %>% + str_replace("ö", "oe") + + + rki_berlin <- rki_berlin %>% + rename(district = LK, incidence = cases) + + return(rki_berlin) +} + +read_and_process_new_rki_data <- function(filename) { + rki <- read_excel(filename, + sheet = "LK_7-Tage-Fallzahlen (fixiert)", skip = 4) + + rki_berlin <- rki %>% + filter(grepl("berlin", LK, ignore.case = TRUE)) %>% + select(-c("...1", "LKNR")) %>% + pivot_longer(!contains("LK"), names_to = "date", values_to = "cases") + + for (i in seq_len(nrow(rki_berlin))) { + dateX <- as.character(rki_berlin$date[i]) + if (grepl("44", dateX)) { + date_improved <- as.character(excel_numeric_to_date(as.numeric(dateX))) + rki_berlin$date[i] <- date_improved + } else { + date_improved <- dateX + rki_berlin$date[i] <- date_improved + } + } + + ymd <- ymd(rki_berlin$date) + dmy <- dmy(rki_berlin$date) + ymd[is.na(ymd)] <- dmy[is.na(ymd)] # some dates are ambiguous, here we give + rki_berlin$date <- ymd + + + rki_berlin$LK <- rki_berlin$LK %>% + str_replace("SK Berlin ", "") %>% + str_replace("-", "_") %>% + str_replace("ö", "oe") + + glimpse(rki_berlin) + + rki_berlin <- rki_berlin %>% + mutate(cases = cases / 7) %>% + rename(district = LK, rki_new = cases) + + return(rki_berlin) +} + +read_and_process_old_rki_data <- function(filename) { + rki_old <- read_csv(filename) + rki_berlin_old <- rki_old %>% + filter(grepl("berlin", Landkreis, ignore.case = TRUE)) %>% + mutate(date = as.Date(Refdatum, format = "%m/%d/%Y"), district = Landkreis) %>% ## TODO: RefDatum or Meldedaturm + select(district, AnzahlFall, date) %>% + group_by(district, date) %>% + summarise(rki_cases_old = sum(AnzahlFall)) %>% + mutate(district = str_replace(district, "SK Berlin ", "")) %>% + mutate(district = str_replace(district, "-", "_")) %>% + mutate(district = str_replace(district, "ö", "oe")) %>% + rename(rki_old = rki_cases_old) + return(rki_berlin_old) +} + +merge_tidy_average <- function(episim_all_runs, rki_new, rki_old) { + # BEFORE MERGING: + # each dataset should have "date", "district" + a seperate column per situation (with good name) + # delete all other columns! + merged_tidy <- episim_all_runs %>% + full_join(rki_new, by = c("date", "district")) %>% + full_join(rki_old, by = c("date", "district")) %>% + pivot_longer(!c("date", "district"), names_to = "scenario", values_to = "infections") + + merged_weekly <- merged_tidy %>% + mutate(week = isoweek(date)) %>% # iso 8601 standard: week always begins with Monday; week 1 must contains January 4th + mutate(year = isoyear(date)) %>% + group_by(across(-c(infections, date))) %>% + summarise(infections = mean(infections, na.rm = TRUE), date = mean(date, na.rm = TRUE)) %>% + ungroup() %>% + select(!c(week, year)) + + return(merged_weekly) + +} + +### Plotting functions +build_plot <- function(df, scale_colors) { + plot <- ggplot(df) + + geom_line(aes(date, incidence, col = Scenario)) + + theme_minimal(base_size = 11) + + theme(legend.position = "bottom", axis.text.x = element_text(angle = 45, hjust=1)) + + labs(x = "Date", y = "7-Day Infections / 100k Pop.") + + scale_x_date(date_breaks = "2 month", date_labels = "%b-%y") + + facet_wrap(~district, ncol = 3) + + scale_color_manual(values = scale_colors) + + print(plot) + + return(plot) +} + +save_png_pdf <- function(.data, name) { + # print(.data) + ggsave(.data, filename = paste0(name, ".png"), path = gbl_image_output, width = 16, height = 12, units = "cm") + ggsave(.data, filename = paste0(name, ".pdf"), path = gbl_image_output, width = 16, height = 12, units = "cm") +} + + +### TIMELINE FUNCTIONS FOR ADAPTIVE RESTRICTIONS +make_timeline <- function(ar_filtered, title) { + timeline_data <- data.frame() + + locations <- unique(ar_filtered$location) + + for (loc in locations) { + + policy_filtered <- ar_filtered %>% filter(location == loc) + + timeline_data_district <- data.frame() + policy <- policy_filtered$policy[1] + start <- policy_filtered$date[1] + + for (row in seq(2, nrow(policy_filtered))) { + + if (policy_filtered$policy[row] == policy) { + next + } + + end <- policy_filtered$date[row] + single <- data.frame(location = loc, policy = policy, start = start, end = end) + timeline_data_district <- rbind(timeline_data_district, single) + + start <- end + policy <- policy_filtered$policy[row] + + } + + end <- policy_filtered$date[row] + + if (start != end) { + single <- data.frame(location = loc, policy = policy, start = start, end = end) + timeline_data_district <- rbind(timeline_data_district, single) + } + + timeline_data <- rbind(timeline_data, timeline_data_district) + } + + + timeline_data_final <- timeline_data %>% + mutate(location = str_replace(location, "_", "-")) %>% + mutate(color = policy) %>% + mutate(color = str_replace(color, "initial", "gray")) %>% + mutate(color = str_replace(color, "restricted", "indianred1")) %>% + mutate(color = str_replace(color, "open", "royalblue1")) + + + # following was adapted from https://github.com/wlhamilton/Patient-ward-movement-timelines/blob/main/R%20script%20for%20formatting%20ward%20movement%20data.R + + plot_data <- gg_vistime(data = timeline_data_final, col.group = "location", col.event = "policy", col.start = "start", col.end = "end", col.color = "color", show_labels = FALSE) + #theme_bw() + + ggplot2::theme( + plot.title = element_text(size = 14), + axis.text.x = element_text(size = 12, color = "black", angle = 30, vjust = 1, hjust = 1), + axis.text.y = element_text(size = 12, color = "black")) + + scale_x_datetime(breaks = breaks_width("1 month"), labels = date_format("%b %y")) + + labs(title = title) + + return(plot_data) + +} + +### SETUP TIMELINE DATA +make_timeline_data <- function(ar_filtered) { + timeline_data <- data.frame() + + locations <- unique(ar_filtered$location) + + for (loc in locations) { + + policy_filtered <- ar_filtered %>% filter(location == loc) + + timeline_data_district <- data.frame() + policy <- policy_filtered$policy[1] + start <- policy_filtered$date[1] + + for (row in seq(2, nrow(policy_filtered))) { + + if (policy_filtered$policy[row] == policy) { + next + } + + end <- policy_filtered$date[row] + single <- data.frame(location = loc, policy = policy, start = start, end = end) + timeline_data_district <- rbind(timeline_data_district, single) + + start <- end + policy <- policy_filtered$policy[row] + + } + + end <- policy_filtered$date[row] + + if (start != end) { + single <- data.frame(location = loc, policy = policy, start = start, end = end) + timeline_data_district <- rbind(timeline_data_district, single) + } + + timeline_data <- rbind(timeline_data, timeline_data_district) + } + + + timeline_data_final <- timeline_data %>% + mutate(location = str_replace(location, "_", "-")) %>% + mutate(color = policy) %>% + mutate(color = str_replace(color, "initial", "gray")) %>% + mutate(color = str_replace(color, "restricted", "indianred1")) %>% + mutate(color = str_replace(color, "open", "royalblue1")) + + return(timeline_data_final) +} + +make_legend <- function() { + data_legend <- data.frame(policy = c("Restriction Policy:", "Initial", "Restricted", "Open"), color = c(rgb(0, 0, 0, 0), "gray", "indianred1", "royalblue1")) + data_legend$start <- c(as.Date("2020-01-01"), as.Date("2020-01-07"), as.Date("2020-01-13"), as.Date("2020-01-19")) + data_legend$end <- c(as.Date("2020-01-06"), as.Date("2020-01-12"), as.Date("2020-01-18"), as.Date("2020-01-24")) + data_legend + plot_legend <- gg_vistime(data = data_legend, + col.event = "policy", + col.color = "color", + show_labels = TRUE, + linewidth = 20, + title = "Legend") + plot_legend + + # Tweak the legend plot + plot_legend <- plot_legend + + theme_void() + + ggplot2::theme( + # plot.title = element_text(size = 11), + plot.title = element_blank(), + # plot.title.position = "plot", + axis.title.x = element_blank(), + axis.text.x = element_blank(), + axis.ticks.x = element_blank(), + axis.title.y = element_blank(), + axis.text.y = element_blank(), + axis.ticks.y = element_blank()) + + return(plot_legend) +} + +make_text <- function(ar) { + + + lockdown_weeks <- ar %>% + group_by(location,policy) %>% + count() %>% + pivot_wider(names_from = policy, values_from = n, values_fill = 0) %>% + mutate(weeks_restricted = paste0(round(restricted / 7, 1), " wks")) %>% + arrange(location) + + + # data = timeline_data_final, col.group = "location", + lockdown_weeks$color <- rgb(0, 0, 0, 0) + lockdown_weeks$start <- c(as.Date("2020-01-1")) + lockdown_weeks$end <- c(as.Date("2020-01-2")) + lockdown_weeks + plot_text <- gg_vistime(data = lockdown_weeks, + col.group = "location", + col.event = "weeks_restricted", + col.color = "color", + show_labels = TRUE, + linewidth = 20, + title = "Lockdown") + + # Tweak the legend plot + plot_text <- plot_text + + ggplot2::theme( + plot.title = element_text(size = 14), + axis.ticks.length = unit(0, "in"), + axis.text.x = element_text(size = 12, color = rgb(0, 0, 0, 0), angle = 30, vjust = 1, hjust = 1), + axis.text.y = element_blank(), + axis.ticks = element_blank(), + axis.title.y = element_blank(), + axis.line.y = element_blank(), + ) + + scale_x_datetime(breaks = breaks_width("1 month"), labels = date_format("%b %y")) + + return(plot_text) + + + make_gt_table <- function(.data) { + gt(.data, rowname_col = "Rf") %>% + tab_stubhead(label = "Rf") %>% + tab_spanner( + label = "Trigger", + columns = trigs + ) %>% + fmt_number( + columns = trigs, + decimals = 1, + use_seps = FALSE + ) + } + + localMaxima <- function(x) { + # Use -Inf instead if x is numeric (non-integer) + y <- diff(c(-.Machine$integer.max, x)) > 0L + rle(y)$lengths + y <- cumsum(rle(y)$lengths) + y <- y[seq.int(1L, length(y), 2L)] + if (x[[1]] == x[[2]]) { + y <- y[-1] + } + y + } + + + localMinima <- function(x) { + # Use -Inf instead if x is numeric (non-integer) + y <- diff(c(.Machine$integer.max, x)) < 0L + rle(y)$lengths + y <- cumsum(rle(y)$lengths) + y <- y[seq.int(1L, length(y), 2L)] + if (x[[1]] == x[[2]]) { + y <- y[-1] + } + y + } +} + From 931f3ba4a447ae904cba3951ae0b1dbaad3f6c94 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Mon, 4 Jul 2022 10:33:55 +0200 Subject: [PATCH 004/128] write antibodies every day --- .../org/matsim/episim/EpisimReporting.java | 1 + .../model/listener/WriteAntibodies.java | 37 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimReporting.java b/src/main/java/org/matsim/episim/EpisimReporting.java index 133809c2d..fc5f427c2 100644 --- a/src/main/java/org/matsim/episim/EpisimReporting.java +++ b/src/main/java/org/matsim/episim/EpisimReporting.java @@ -318,6 +318,7 @@ public void writeAsync(BufferedWriter writer, String content) { * Close writer asynchronously. */ public void closeAsync(BufferedWriter writer) { + externalWriters.values().removeIf(next -> next == writer); this.writer.close(writer); } diff --git a/src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java b/src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java index 4a7746aca..5c2ae65d5 100644 --- a/src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java +++ b/src/main/java/org/matsim/episim/model/listener/WriteAntibodies.java @@ -27,44 +27,41 @@ public class WriteAntibodies implements SimulationListener { private Map, EpisimPerson> persons; @Inject private EpisimReporting reporting; - private BufferedWriter writer; - @Override public void init(SplittableRandom rnd, Map, EpisimPerson> persons, Map, InfectionEventHandler.EpisimFacility> facilities, Map, InfectionEventHandler.EpisimVehicle> vehicles) { this.persons = persons; - this.writer = reporting.registerWriter("antibodiesPerAge.tsv"); } @Override public void onIterationEnd(int iteration, LocalDate date) { - if (iteration == 100) { - - String header = VirusStrain.class.getSimpleName() + "\t" + IntStream.range(0, 120).mapToObj(String::valueOf).collect(Collectors.joining("\t")) + "\n"; - - reporting.writeAsync(writer, header); + String header = VirusStrain.class.getSimpleName() + "\t" + IntStream.range(0, 120).mapToObj(String::valueOf).collect(Collectors.joining("\t")) + "\n"; - for (VirusStrain strain : VirusStrain.values()) { + BufferedWriter writer = reporting.registerWriter(String.format("antibodiesPerAge-%s.tsv", date.toString())); - // Rolling mean per age group - int[] n = new int[120]; - double[] values = new double[120]; + reporting.writeAsync(writer, header); - for (EpisimPerson p : persons.values()) { + for (VirusStrain strain : VirusStrain.values()) { - int i = p.getAge(); - n[i]++; - values[i] = values[i] + (p.getAntibodies(strain) - values[i]) / n[i]; + // Rolling mean per age group + int[] n = new int[120]; + double[] values = new double[120]; - } + for (EpisimPerson p : persons.values()) { - String row = strain.name() + "\t" + Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining("\t")) + "\n"; + int i = p.getAge(); + n[i]++; + values[i] = values[i] + (p.getAntibodies(strain) - values[i]) / n[i]; - reporting.writeAsync(writer, row); } - reporting.closeAsync(writer); + String row = strain.name() + "\t" + Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining("\t")) + "\n"; + + reporting.writeAsync(writer, row); } + + reporting.closeAsync(writer); } + } From 7ee64d897b6edbe358a976f2be152fbb3b1cccd2 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 5 Jul 2022 11:11:37 +0200 Subject: [PATCH 005/128] adapt leisure factor to apply to all act types --- .../java/org/matsim/run/batch/CologneJR.java | 623 ++++++++++++++++++ .../modules/SnzCologneProductionScenario.java | 12 +- 2 files changed, 631 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneJR.java diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java new file mode 100644 index 000000000..5275f4cc5 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -0,0 +1,623 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneJR implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + + double mutEscBa5 = 1.; + double mutEscStrainA = 1.; + + LocalDate start = null; + VaccinationType vaccinationType = null; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + + + if (params != null) { + mutEscBa5 = 3.0; + mutEscStrainA = params.strAEsc; + + start = LocalDate.parse(params.resDate); + vaccinationType = VaccinationType.valueOf(params.vacType); + + + if (params.vacCamp.equals("age")) { + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + } + else if (params.vacCamp.equals("eu")) { + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + } + else if (params.vacCamp.equals("off")) { + + } else { + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } + + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscBa5,mutEscStrainA); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscBa5, double mutEscStrainA) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + + //DELTA + double mRNADelta = 10.9; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + + //BA.1 + double mRNABA1 = 1.9; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / 1.4 / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.omicronUpdate) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + + +// System.out.print("immunityGiver"); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// if (immunityFrom == VirusStrain.OMICRON_BA1) { +// System.out.print( "," + "BA.1"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { +// System.out.print( "," + "BA.2"); +// } else { +// System.out.print( "," + immunityFrom); +// } +// } + + +// for (ImmunityEvent immunityGiver : VaccinationType.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// for (ImmunityEvent immunityGiver : VirusStrain.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } + +// System.out.println(); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new HospitalNumbersFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * params.thFactor); + //restrictions + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + // Restrictions starting on December 1, 2022 + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + //school + if(params.edu.equals("close")) { + if (params.resDate.equals("2022-12-01")) { + builder.restrict(restrictionDate, 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + } + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + //university + builder.restrict(restrictionDate, 0.2, "educ_higher"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_higher"); + } else if (params.edu.equals("maskVent")) { + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.25, + FaceMask.SURGICAL, 0.25)), + "educ_primary", "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); + + } else if (params.edu.equals("normal")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + //pt: masks + if (Boolean.parseBoolean(params.maskPt)) { + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "pt"); + + } + + //shopping: masks + if (Boolean.parseBoolean(params.maskShop)) { + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "shop_daily", "shop_other", "errands"); + } + + //work + builder.restrict(restrictionDate, 0.78 * params.work, "work"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.work, "work"); + + //leisure + builder.restrict(restrictionDate, 0.88 * params.leis, "leisure"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.leis, "leisure"); + + + episimConfig.setPolicy(builder.build()); + + + //mutations + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + //configure new strains + //BA5 + double ba5Inf = 0.9; + double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + + +// STRAIN_A + double strAInf = 1.0; + if (params.strAEsc != 0.) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf * strAInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); + } + + //Configure Disease Import + + configureFutureDiseaseImport(params, episimConfig); + + + //vaccinations + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(true); + vaccinationConfig.setTimePeriodIgA(730.); + + + if(DEBUG_MODE) { +// UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); +// UtilsJR.produceMaskPlot(episimConfig.getPolicy()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + + // add initial impulses for strains + //BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + //BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); + + //StrainA + + if (params.strAEsc != 0.) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse(params.strADate); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrA = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainA = LocalDate.parse("2022-11-18"); // after vaca import + + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainA) && params.strAEsc != 0) { + infPerDayStrA.put(date, ((int) cases * facStrA) == 0 ? 1 : (int) (cases * facStrA)); + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + + if( params.strAEsc!=0.) { + infPerDayBa5.put(dateStrainA.plusDays(1), 1); + infPerDayStrA.put(date.plusDays(1), 1); + } else { + infPerDayBa5.put(date.plusDays(1), 1); + } + + + // + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (params.strAEsc != 0.) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + } + + + public static final class Params { + + // general + @GenerateSeeds(5) + public long seed; + + @Parameter({0.0,1.0,1.3,1.6,1.9,2.2}) + public double actCorrection; + + @Parameter({0.9, 0.95, 1.0,1.05,1.1}) + public double thFactor; + + + //TODO VARY +// @Parameter({0.0,6.}) // 0.0 = strainA is off + @Parameter({0.0}) // 0.0 = strainA is off + public double strAEsc; + + + // General Restriction date +// @StringParameter({"2022-07-01","2022-12-01"}) + @StringParameter({"2022-12-01"}) + public String resDate; + + +// @StringParameter({"off", "age"}) + @StringParameter({"off"}) + String vacCamp; + + // other restrictions + // schools & university // close: rf reduced // maskVent: ciCorrection reduced & surgical mask for most // normal: no changes made +// @StringParameter({"close", "maskVent", "normal"}) + @StringParameter({ "normal"}) + String edu; + + // shopping: mask +// @StringParameter({"true", "false"}) + @StringParameter({"false"}) + String maskShop; + + // pt: mask +// @StringParameter({"true", "false"}) + @StringParameter({"false"}) + String maskPt; + + // work: +// @Parameter({0.5, 1.0}) + @Parameter({1.0}) + double work; + + // leisure +// @Parameter({0.25, 0.5, 0.75, 1.0}) + @Parameter({1.0}) + double leis; + + + // vaccination campaign + @StringParameter({"omicronUpdate"}) + public String vacType; + + @StringParameter({"2022-04-25"}) + public String unResDate; + + // StrainA + @StringParameter({"2022-11-01"}) + public String strADate; + +// @StringParameter({"true"}) +// public String sebaUp; + + // Antibody Model +// @Parameter({3.0}) +// double immuneSigma; + +// @Parameter({730.}) //120, +// public double igATime; + + // BA5 +// @StringParameter({"2022-04-10"}) +// public String ba5Date; +// +// @Parameter({0.9}) //,1.0,1.1,1.2,1.3}) +// double ba5Inf; +// +// @Parameter({3.}) +// public double ba5Esc; + + // @Parameter({0.0, 1.0}) +// public double strAInf; + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneJR.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(70), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index a71c9ca78..a5d02a616 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -508,11 +508,15 @@ public Config config() { //leisure & work factor if (this.restrictions != Restrictions.no) { - if (leisureCorrection != 1) - builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "leisure"); - // builder.applyToRf("2020-10-15", "2020-12-14", (d, rf) -> rf - leisureOffset, "leisure"); + if (leisureCorrection == 0.) { // assume old factor of 1.9, only applied to leisure TODO: get rid of this artifact + builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - 1.9 * (1 - (double) e.get("fraction"))), "leisure"); + } else if (leisureCorrection != 1) { + builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "business", "errands", "leisure", "shop_daily", "shop_other", "visit", "work"); + } + + // builder.applyToRf("2020-10-15", "2020-12-14", (d, rf) -> rf - leisureOffset, "leisure"); - BiFunction workVacFactor = (d, rf) -> rf * 0.92; + BiFunction workVacFactor = (d, rf) -> rf * 0.92; builder.applyToRf("2020-04-03", "2020-04-17", workVacFactor, "work", "business"); builder.applyToRf("2020-06-26", "2020-08-07", workVacFactor, "work", "business"); From d601cb182fa66a8e7a469be15d6a915af619c7ec Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 12 Jul 2022 11:01:03 +0200 Subject: [PATCH 006/128] wip: trying to recalibrate the production scenario to better catch activity levels... --- .../matsim/episim/InfectionEventHandler.java | 56 +++- .../java/org/matsim/run/batch/CologneJR.java | 41 ++- .../modules/SnzCologneProductionScenario.java | 253 +++++++----------- 3 files changed, 170 insertions(+), 180 deletions(-) diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index fccaf2aea..65f0195c6 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -26,6 +26,8 @@ import com.google.inject.util.Types; import com.typesafe.config.ConfigFactory; import it.unimi.dsi.fastutil.objects.*; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; @@ -52,6 +54,8 @@ import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.nio.file.Files; +import java.nio.file.Path; import java.time.DayOfWeek; import java.time.LocalDate; import java.util.*; @@ -201,7 +205,7 @@ public InfectionEventHandler(Injector injector, SplittableRandom rnd) { this.policy = injector.getInstance(ShutdownPolicy.class); this.restrictions = episimConfig.createInitialRestrictions(); this.reporting = injector.getInstance(EpisimReporting.class); - this.localRnd = new SplittableRandom( 65536); // fixed seed, because it should not change between snapshots + this.localRnd = new SplittableRandom(65536); // fixed seed, because it should not change between snapshots this.progressionModel = injector.getInstance(ProgressionModel.class); this.antibodyModel = injector.getInstance(AntibodyModel.class); this.initialInfections = injector.getInstance(InitialInfectionHandler.class); @@ -253,9 +257,9 @@ void init(Map> events) { .sorted(Comparator.comparingInt(p -> ((EpisimPerson) p).getAgeOrDefault(-1)).reversed() .thenComparing(p -> ((EpisimPerson) p).getPersonId())) .forEach(p -> { - Double compliance = EpisimUtils.findValidEntry(vaccinationConfig.getCompliancePerAge(), 1.0, p.getAgeOrDefault(-1)); - p.setVaccinable(localRnd.nextDouble() < compliance); - }); + Double compliance = EpisimUtils.findValidEntry(vaccinationConfig.getCompliancePerAge(), 1.0, p.getAgeOrDefault(-1)); + p.setVaccinable(localRnd.nextDouble() < compliance); + }); listener = (Set) injector.getInstance(Key.get(Types.setOf(SimulationListener.class))); vaccinations = (Set) injector.getInstance(Key.get(Types.setOf(VaccinationModel.class))); @@ -577,16 +581,16 @@ void onSnapshotLoaded(int iteration) { /** * Distribute the containers to the different ReplayEventTasks, by setting * the taskId attribute of the containers to values between 0 and episimConfig.getThreds() - 1, - * so that the sum of numUsers * maxGroupSize has an even distribution + * so that the sum of numUsers * maxGroupSize has an even distribution */ private void balanceContainersByLoad(List, Double>> estimatedLoad) { // We need the containers sorted by the load, with the highest load first. // To get a deterministic distribution, we use the containerId for // sorting the containers with the same estimatedLoad. Comparator, Double>> loadComperator = - Comparator., Double>,Double>comparing( - t -> t.getSecond(), Comparator.reverseOrder()). - thenComparing(t -> t.getFirst().getContainerId().toString()); + Comparator., Double>, Double>comparing( + t -> t.getSecond(), Comparator.reverseOrder()). + thenComparing(t -> t.getFirst().getContainerId().toString()); Collections.sort(estimatedLoad, loadComperator); final int numThreads = episimConfig.getThreads(); @@ -595,7 +599,7 @@ private void balanceContainersByLoad(List, Double>> est for (int i = 0; i < numThreads; i++) loadPerThread[i] = 0.0; - for(Tuple, Double> tuple : estimatedLoad) { + for (Tuple, Double> tuple : estimatedLoad) { // search for the thread/taskId with the minimal load int useThread = 0; Double minLoad = loadPerThread[0]; @@ -618,8 +622,9 @@ private void balanceContainersByLoad(List, Double>> est */ private void balanceContainersByHash(List, Double>> estimatedLoad) { for (Tuple, Double> tuple : estimatedLoad) { - final EpisimContainer container = tuple.getFirst(); - final int useThread = Math.abs(container.getContainerId().hashCode()) % episimConfig.getThreads(); container.setTaskId(useThread); + final EpisimContainer container = tuple.getFirst(); + final int useThread = Math.abs(container.getContainerId().hashCode()) % episimConfig.getThreads(); + container.setTaskId(useThread); } } @@ -772,6 +777,33 @@ public void reset(int iteration) { } } + +// if (date.getDayOfMonth() == 1) { +// try (CSVPrinter csv = new CSVPrinter(Files.newBufferedWriter(Path.of("antibodies_" + date + ".tsv")), CSVFormat.TDF)) { +// +// csv.print("personId"); +// csv.print("age"); +// +// for (VirusStrain strain : VirusStrain.values()) { +// csv.print(strain.toString()); +// } +// csv.println(); +// +// for (EpisimPerson person : personMap.values()) { +// csv.print(person.getPersonId().toString()); +// csv.print(person.getAge()); +// +// for (VirusStrain strain : VirusStrain.values()) { +// csv.print(person.getAntibodies(strain)); +// } +// csv.println(); +// +// } +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } + reporting.reportCpuTime(iteration, "ProgressionModelParallel", "start", -2); progressionModel.afterStateUpdates(personMap, iteration); reporting.reportCpuTime(iteration, "ProgressionModelParallel", "finished", -2); @@ -789,7 +821,7 @@ public void reset(int iteration) { // additional vaccinations: for (VaccinationModel vaccination : vaccinations) { - vaccination.handleVaccination(personMap, date, iteration, now); + vaccination.handleVaccination(personMap, date, iteration, now); } reporting.reportCpuTime(iteration, "VaccinationModel", "finished", -1); diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index 5275f4cc5..4dfb1abe9 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -422,6 +422,21 @@ public Config prepareConfig(int id, Params params) { vaccinationConfig.setTimePeriodIgA(730.); + //modify contact intensity + EpisimConfigGroup.InfectionParams workParams = episimConfig.getOrAddContainerParams("work"); + workParams.setContactIntensity(workParams.getContactIntensity() * params.workCi); + + EpisimConfigGroup.InfectionParams leisureParams = episimConfig.getOrAddContainerParams("leisure"); + leisureParams.setContactIntensity(leisureParams.getContactIntensity() * params.leisureCi); + + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * params.schoolCi); + + if(DEBUG_MODE) { // UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); // UtilsJR.produceMaskPlot(episimConfig.getPolicy()); @@ -500,8 +515,6 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } - // - // save disease import episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); @@ -516,15 +529,31 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi public static final class Params { // general - @GenerateSeeds(5) + @GenerateSeeds(1) public long seed; - @Parameter({0.0,1.0,1.3,1.6,1.9,2.2}) +// @Parameter({0.0, 1.0, 1.5, 2.0, 2.5}) + @Parameter({0.0}) public double actCorrection; - @Parameter({0.9, 0.95, 1.0,1.05,1.1}) +// @Parameter({0.9, 0.95, 1.0,1.05,1.1}) + @Parameter({1.0}) public double thFactor; + @Parameter({1.}) +// @Parameter({0.5, 1., 2.}) + public double schoolCi; + +// @Parameter({1., 2.}) + @Parameter({1.}) + public double workCi; + +// @Parameter({0.5, 1.}) + @Parameter({ 1.}) + public double leisureCi; + + + //TODO VARY // @Parameter({0.0,6.}) // 0.0 = strainA is off @@ -611,7 +640,7 @@ public static void main(String[] args) { RunParallel.OPTION_SETUP, CologneJR.class.getName(), RunParallel.OPTION_PARAMS, Params.class.getName(), RunParallel.OPTION_TASKS, Integer.toString(1), - RunParallel.OPTION_ITERATIONS, Integer.toString(70), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), RunParallel.OPTION_METADATA }; diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index a5d02a616..817946fea 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -69,7 +69,6 @@ public static class Builder extends SnzProductionScenario.Builder 2_352_480 - if (this.sample != 25 && this.sample != 100) - throw new RuntimeException("Sample size not calibrated! Currently only 25% is calibrated. Comment this line out to continue."); + if (this.sample != 25 && this.sample != 100) + throw new RuntimeException("Sample size not calibrated! Currently only 25% is calibrated. Comment this line out to continue."); //general config Config config = ConfigUtils.createConfig(new EpisimConfigGroup()); @@ -287,7 +286,7 @@ public Config config() { //episim config EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 0.96 * 1.06 ); + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 0.96 * 1.06); episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_wt_%dpt_split.xml.gz", sample)) .addDays(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY); @@ -309,27 +308,24 @@ public Config config() { episimConfig.setThreads(8); episimConfig.setDaysInfectious(Integer.MAX_VALUE); - if (sebastianUpdate) { - - episimConfig.getOrAddContainerParams("work").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("work").setSeasonality(0.5); - double leisCi = 0.6; + double leisCi = 0.6; - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(9.24 * leisCi); + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(9.24 * leisCi); - episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_other").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("errands").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("business").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("visit").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("home").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("quarantine_home").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_other").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("errands").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("business").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("visit").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("home").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("quarantine_home").setSeasonality(0.5); - } //progression model //episimConfig.setProgressionConfig(AbstractSnzScenario2020.baseProgressionConfig(Transition.config()).build()); @@ -417,7 +413,6 @@ public Config config() { builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); - { LocalDate masksCenterDate = LocalDate.of(2020, 4, 27); for (int ii = 0; ii <= 14; ii++) { @@ -465,16 +460,16 @@ public Config config() { builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(FaceMask.N95, 0.), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "leisure", "work", "business"); //todo: check builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.N95, 0.0, - FaceMask.SURGICAL, 0.0)), - "shop_daily", "shop_other", "errands"); + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.0, + FaceMask.SURGICAL, 0.0)), + "shop_daily", "shop_other", "errands"); builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.N95, 0.25, - FaceMask.SURGICAL, 0.25)), - "pt"); + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.25, + FaceMask.SURGICAL, 0.25)), + "pt"); //tracing @@ -492,7 +487,7 @@ public Config config() { //outdoorFractions if (this.weatherModel != WeatherModel.no) { - double outdoorAlpha = sebastianUpdate ? 0.8 : 1.0; + double outdoorAlpha = 0.8; SnzProductionScenario.configureWeather(episimConfig, weatherModel, SnzCologneProductionScenario.INPUT.resolve("cologneWeather.csv").toFile(), SnzCologneProductionScenario.INPUT.resolve("weatherDataAvgCologne2000-2020.csv").toFile(), outdoorAlpha @@ -511,12 +506,12 @@ public Config config() { if (leisureCorrection == 0.) { // assume old factor of 1.9, only applied to leisure TODO: get rid of this artifact builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - 1.9 * (1 - (double) e.get("fraction"))), "leisure"); } else if (leisureCorrection != 1) { - builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "business", "errands", "leisure", "shop_daily", "shop_other", "visit", "work"); + builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "business", "errands", "leisure", "shop_daily", "shop_other", "visit", "work"); } - // builder.applyToRf("2020-10-15", "2020-12-14", (d, rf) -> rf - leisureOffset, "leisure"); + // builder.applyToRf("2020-10-15", "2020-12-14", (d, rf) -> rf - leisureOffset, "leisure"); - BiFunction workVacFactor = (d, rf) -> rf * 0.92; + BiFunction workVacFactor = (d, rf) -> rf * 0.92; builder.applyToRf("2020-04-03", "2020-04-17", workVacFactor, "work", "business"); builder.applyToRf("2020-06-26", "2020-08-07", workVacFactor, "work", "business"); @@ -581,13 +576,13 @@ public Config config() { } if (carnivalModel.equals(CarnivalModel.yes)) { - // Friday 25.2 to Monday 28.2 (Rosenmontag) - builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); - builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays - builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival + // Friday 25.2 to Monday 28.2 (Rosenmontag) + builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); + builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays + builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival - builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure"); - builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure"); + builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure"); + builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure"); inputDays.put(LocalDate.parse("2022-02-28"), DayOfWeek.SUNDAY); // set monday to be a sunday } @@ -598,7 +593,7 @@ public Config config() { //configure strains //alpha - double aInf = sebastianUpdate ? 1.9 : 1.7; //todo: choose value, see CologneJR + double aInf = 1.9; // SnzProductionScenario.configureStrains(episimConfig, ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class)); VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(aInf); @@ -607,8 +602,8 @@ public Config config() { //delta - double deltaInf = sebastianUpdate ? 3.1 : 2.7 ; //todo: choose value, see CologneJR - double deltaHos = sebastianUpdate ? 1.0 : 0.9;//todo: choose value, see CologneJR + double deltaInf = 3.1; + double deltaHos = 1.0; virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(deltaInf); virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setFactorSeriouslySick(deltaHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setFactorSeriouslySickVaccinated(deltaHos); @@ -616,8 +611,8 @@ public Config config() { //omicron // double oInf = params.ba1Inf; - double oHos = sebastianUpdate ? 0.2 : 0.13; - double ba1Inf = sebastianUpdate ? 2.2 : 2.4; + double oHos = 0.2; + double ba1Inf = 2.2; if (ba1Inf > 0) { virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(deltaInf * ba1Inf); @@ -628,7 +623,7 @@ public Config config() { //BA.2 - double ba2Inf= 1.7; + double ba2Inf = 1.7; if (ba2Inf > 0) { virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(deltaInf * ba1Inf * ba2Inf); virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorSeriouslySick(oHos); @@ -707,16 +702,15 @@ public Config config() { // if (testing.equals("no")) { // turn of school tests after easter break - kigaPrimaryTests.put(LocalDate.of(2022,4,25), 0.0); - eduTests.put(LocalDate.of(2022,4,25), 0.0); - uniTests.put(LocalDate.of(2022,4,25), 0.0); + kigaPrimaryTests.put(LocalDate.of(2022, 4, 25), 0.0); + eduTests.put(LocalDate.of(2022, 4, 25), 0.0); + uniTests.put(LocalDate.of(2022, 4, 25), 0.0); // } // no more regulation regarding test, we assume once every 2 weeks leisureTests.put(LocalDate.of(2022, 4, 25), 0.1); - rapidTest.setTestingRatePerActivityAndDate((Map.of( "leisure", leisureTests, "work", workTests, @@ -741,7 +735,7 @@ public Config config() { // if (testing.equals("no")) { leisureTestsVaccinated.put(LocalDate.of(2022, 4, 25), 0.0); - workTestsVaccinated.put(LocalDate.of(2022, 4, 25),0.0); + workTestsVaccinated.put(LocalDate.of(2022, 4, 25), 0.0); eduTestsVaccinated.put(LocalDate.of(2022, 4, 25), 0.0); // } @@ -772,10 +766,10 @@ public Config config() { kigaPramaryTestsPCR.put(LocalDate.parse("2021-05-10"), 0.4); // if (testing.equals("no")) { - leisureTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); - workTestsPCR.put(LocalDate.of(2022, 4, 25),0.0); - kigaPramaryTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); - eduTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); + leisureTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); + workTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); + kigaPramaryTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); + eduTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); // } @@ -878,132 +872,67 @@ private void configureDiseaseImport(double cologneFactor, EpisimConfigGroup epis infPerDayWild.put(LocalDate.parse("2020-07-19"), (int) (0.5 * 32)); infPerDayWild.put(LocalDate.parse("2020-08-09"), 1); -// episimConfig.setInfections_pers_per_day(infPerDayWild); - - if (sebastianUpdate) { - - for (Map.Entry entry : infPerDayWild.entrySet()) { - if (entry.getKey().isBefore(LocalDate.parse("2020-08-12"))) { - int value = entry.getValue(); - value = Math.max(1, value); - infPerDayWild.put(entry.getKey(), value); - } + for (Map.Entry entry : infPerDayWild.entrySet()) { + if (entry.getKey().isBefore(LocalDate.parse("2020-08-12"))) { + int value = entry.getValue(); + value = Math.max(1, value); + infPerDayWild.put(entry.getKey(), value); } + } - double facWild = 4.0; - double facAlpha = 4.0; - double facDelta = 4.0; - double facBa1 = 4.0; - double facBa2 = 4.0; - double facBa5 = 4.0; - - LocalDate dateAlpha = LocalDate.parse("2021-01-23"); - LocalDate dateDelta = LocalDate.parse("2021-06-28"); - LocalDate dateBa1 = LocalDate.parse("2021-12-12"); - LocalDate dateBa2 = LocalDate.parse("2022-01-05"); + double facWild = 4.0; + double facAlpha = 4.0; + double facDelta = 4.0; + double facBa1 = 4.0; + double facBa2 = 4.0; - infPerDayAlpha.put(LocalDate.parse("2020-01-01"), 0); - infPerDayDelta.put(LocalDate.parse("2020-01-01"), 0); - infPerDayBa1.put(LocalDate.parse("2020-01-01"), 0); - infPerDayBa2.put(LocalDate.parse("2020-01-01"), 0); - infPerDayBa5.put(LocalDate.parse("2020-01-01"), 0); + infPerDayAlpha.put(LocalDate.parse("2020-01-01"), 0); + infPerDayDelta.put(LocalDate.parse("2020-01-01"), 0); + infPerDayBa1.put(LocalDate.parse("2020-01-01"), 0); + infPerDayBa2.put(LocalDate.parse("2020-01-01"), 0); + infPerDayBa5.put(LocalDate.parse("2020-01-01"), 0); - NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport.csv")); + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport.csv")); - NavigableMap> shares = DataUtils.readVOC(SnzCologneProductionScenario.INPUT.resolve("VOC_Cologne_RKI.csv")); + NavigableMap> shares = DataUtils.readVOC(SnzCologneProductionScenario.INPUT.resolve("VOC_Cologne_RKI.csv")); - // Get import share - BiFunction lookup = (date, strain) -> shares.floorEntry(date).getValue().getOrDefault(strain, 0d); - LocalDate date = null; + // Get import share + BiFunction lookup = (date, strain) -> shares.floorEntry(date).getValue().getOrDefault(strain, 0d); + LocalDate date = null; - for (Map.Entry e : data.entrySet()) { + for (Map.Entry e : data.entrySet()) { - double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City, so we have to scale it to the whole model + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City, so we have to scale it to the whole model - double cases = factor * e.getValue(); - date = e.getKey(); + double cases = factor * e.getValue(); + date = e.getKey(); // infPerDayBa5.put(date, (int) (lookup.apply(date, VirusStrain.OMICRON_BA5) * cases * facBa5)); - infPerDayBa2.put(date, (int) (lookup.apply(date, VirusStrain.OMICRON_BA2) * cases * facBa2)); - infPerDayBa1.put(date, (int) (lookup.apply(date, VirusStrain.OMICRON_BA1) * cases * facBa1)); - infPerDayDelta.put(date,(int) (lookup.apply(date, VirusStrain.DELTA) * cases * facDelta)); - infPerDayAlpha.put(date, (int) (lookup.apply(date, VirusStrain.ALPHA) * cases * facAlpha)); - infPerDayWild.put(date, (int) (lookup.apply(date, VirusStrain.SARS_CoV_2) * cases * facWild)); - - } - - LocalDate wildImportEnds = LocalDate.of(2021, 11, 21); - infPerDayWild = infPerDayWild.entrySet().stream().filter(entry -> entry.getKey().isBefore(wildImportEnds)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - infPerDayWild.put(wildImportEnds, 1); - - LocalDate alphaImportEnds = LocalDate.of(2021, 7, 17); - infPerDayAlpha = infPerDayAlpha.entrySet().stream().filter(entry -> entry.getKey().isBefore(alphaImportEnds)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - infPerDayAlpha.put(alphaImportEnds, 1); - - LocalDate deltaImportEnds = LocalDate.of(2022, 1, 16); - infPerDayDelta = infPerDayDelta.entrySet().stream().filter(entry -> entry.getKey().isBefore(deltaImportEnds)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - infPerDayDelta.put(deltaImportEnds, 1); - + infPerDayBa2.put(date, (int) (lookup.apply(date, VirusStrain.OMICRON_BA2) * cases * facBa2)); + infPerDayBa1.put(date, (int) (lookup.apply(date, VirusStrain.OMICRON_BA1) * cases * facBa1)); + infPerDayDelta.put(date, (int) (lookup.apply(date, VirusStrain.DELTA) * cases * facDelta)); + infPerDayAlpha.put(date, (int) (lookup.apply(date, VirusStrain.ALPHA) * cases * facAlpha)); + infPerDayWild.put(date, (int) (lookup.apply(date, VirusStrain.SARS_CoV_2) * cases * facWild)); - LocalDate dateAfterCsvEnds = date.plusDays(1); - infPerDayBa2.put(dateAfterCsvEnds, 1); - - - - - } else { - - //ALPHA -// Map infPerDayB117 = new HashMap<>(); - infPerDayAlpha.put(LocalDate.parse("2020-01-01"), 0); - - infPerDayAlpha.put(LocalDate.parse("2021-01-16"), 20); - infPerDayAlpha.put(LocalDate.parse("2021-01-16").plusDays(1), 1); - infPerDayAlpha.put(LocalDate.parse("2020-12-31"), 1); - -// episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); - - // DELTA -// Map infPerDayDelta = new HashMap<>(); - infPerDayDelta.put(LocalDate.parse("2020-01-01"), 0); - infPerDayDelta.put(LocalDate.parse("2021-06-21"), 4); - infPerDayDelta.put(LocalDate.parse("2021-06-21").plusDays(7), 1); - - LocalDate summerHolidaysEnd = LocalDate.parse("2021-08-17").minusDays(14); - int imp1 = 120; - int imp2 = 10; - int imp3 = 40; - - SnzCologneProductionScenario.interpolateImport(infPerDayDelta, 1.0, summerHolidaysEnd.minusDays(5 * 7), summerHolidaysEnd, 1, imp1); - SnzCologneProductionScenario.interpolateImport(infPerDayDelta, 1.0, summerHolidaysEnd, summerHolidaysEnd.plusDays(3 * 7), imp1, imp2); - - - LocalDate autumnHolidaysEnd = LocalDate.parse("2021-10-17"); + } - SnzCologneProductionScenario.interpolateImport(infPerDayDelta, 1.0, autumnHolidaysEnd.minusDays(2 * 7), autumnHolidaysEnd, imp2, imp3); - SnzCologneProductionScenario.interpolateImport(infPerDayDelta, 1.0, autumnHolidaysEnd, autumnHolidaysEnd.plusDays(2 * 7), imp3, 1); + LocalDate wildImportEnds = LocalDate.of(2021, 11, 21); + infPerDayWild = infPerDayWild.entrySet().stream().filter(entry -> entry.getKey().isBefore(wildImportEnds)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + infPerDayWild.put(wildImportEnds, 1); + LocalDate alphaImportEnds = LocalDate.of(2021, 7, 17); + infPerDayAlpha = infPerDayAlpha.entrySet().stream().filter(entry -> entry.getKey().isBefore(alphaImportEnds)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + infPerDayAlpha.put(alphaImportEnds, 1); -// episimConfig.setInfections_pers_per_day(VirusStrain.DELTA, infPerDayDelta); + LocalDate deltaImportEnds = LocalDate.of(2022, 1, 16); + infPerDayDelta = infPerDayDelta.entrySet().stream().filter(entry -> entry.getKey().isBefore(deltaImportEnds)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + infPerDayDelta.put(deltaImportEnds, 1); - //BA.1 - String ba1Date = "2021-11-21"; -// Map infPerDayBA1 = new HashMap<>(); - infPerDayBa1.put(LocalDate.parse("2020-01-01"), 0); - infPerDayBa1.put(LocalDate.parse(ba1Date), 4); - infPerDayBa1.put(LocalDate.parse(ba1Date).plusDays(7), 1); -// episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + LocalDate dateAfterCsvEnds = date.plusDays(1); + infPerDayBa2.put(dateAfterCsvEnds, 1); - //BA.2 - String ba2Date = "2021-12-18"; -// Map infPerDayBA2 = new HashMap<>(); - infPerDayBa2.put(LocalDate.parse("2020-01-01"), 0); - infPerDayBa2.put(LocalDate.parse(ba2Date), 4); - infPerDayBa2.put(LocalDate.parse(ba2Date).plusDays(7), 1); -// episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); - } // set all initial infections episimConfig.setInfections_pers_per_day(VirusStrain.SARS_CoV_2, infPerDayWild); From 1ecd3e918f87745bb79e00680043a521049bdb8f Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 20 Jul 2022 16:19:25 +0200 Subject: [PATCH 007/128] calibration run --- .../matsim/episim/InfectionEventHandler.java | 6 ++++ .../java/org/matsim/run/batch/CologneJR.java | 30 +++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 65f0195c6..d339f139c 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -783,6 +783,9 @@ public void reset(int iteration) { // // csv.print("personId"); // csv.print("age"); +// csv.print("nVaccinations"); +// csv.print("nInfections"); +// csv.print("immuneResponseMultiplier"); // // for (VirusStrain strain : VirusStrain.values()) { // csv.print(strain.toString()); @@ -792,6 +795,9 @@ public void reset(int iteration) { // for (EpisimPerson person : personMap.values()) { // csv.print(person.getPersonId().toString()); // csv.print(person.getAge()); +// csv.print(person.getNumVaccinations()); +// csv.print(person.getNumInfections()); +// csv.print(person.getImmuneResponseMultiplier()); // // for (VirusStrain strain : VirusStrain.values()) { // csv.print(person.getAntibodies(strain)); diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index 4dfb1abe9..1aef4748b 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -262,8 +262,8 @@ else if (immunityType == VaccinationType.omicronUpdate) { // System.out.print( "," + immunityFrom); // } // } - - +// +// // for (ImmunityEvent immunityGiver : VaccinationType.values()) { // System.out.print("\n" + immunityGiver); // for (VirusStrain immunityFrom : VirusStrain.values()) { @@ -276,7 +276,7 @@ else if (immunityType == VaccinationType.omicronUpdate) { // System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); // } // } - +// // System.out.println(); } @@ -529,27 +529,27 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi public static final class Params { // general - @GenerateSeeds(1) + @GenerateSeeds(5) public long seed; - -// @Parameter({0.0, 1.0, 1.5, 2.0, 2.5}) - @Parameter({0.0}) + @Parameter({0.0, 1.0, 1.5, 2.0, 2.5}) +// @Parameter({0.0}) public double actCorrection; -// @Parameter({0.9, 0.95, 1.0,1.05,1.1}) - @Parameter({1.0}) + + @Parameter({1.0, 1.1, 1.2}) +// @Parameter({1.0}) public double thFactor; - @Parameter({1.}) -// @Parameter({0.5, 1., 2.}) +// @Parameter({1.}) + @Parameter({0.5, 1.}) public double schoolCi; -// @Parameter({1., 2.}) - @Parameter({1.}) + @Parameter({1., 2.}) +// @Parameter({1.}) public double workCi; -// @Parameter({0.5, 1.}) - @Parameter({ 1.}) + @Parameter({0.25,0.5, 1.}) +// @Parameter({ 1.}) public double leisureCi; From cd731be9fd68f90e36aa32857248c1b354c39b25 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 22 Jul 2022 14:41:23 +0200 Subject: [PATCH 008/128] try new omicronUpdate params --- .../matsim/episim/model/AntibodyModel.java | 47 +- .../episim/model/DefaultAntibodyModel.java | 19 +- .../java/org/matsim/run/batch/CologneJR.java | 14 +- .../matsim/run/batch/CologneScenarioHub.java | 401 ++++++++++++++++++ src/main/python/analysis/utils.py | 2 +- .../model/DefaultAntibodyModelTest.java | 6 +- 6 files changed, 469 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneScenarioHub.java diff --git a/src/main/java/org/matsim/episim/model/AntibodyModel.java b/src/main/java/org/matsim/episim/model/AntibodyModel.java index d58e9e43c..248262400 100644 --- a/src/main/java/org/matsim/episim/model/AntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/AntibodyModel.java @@ -80,6 +80,8 @@ public Config() { //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. //The other values come from Rössler et al. + double mutEscBa5 = 3.0; + //Wildtype double mRNAAlpha = 29.2; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); @@ -89,6 +91,9 @@ public Config() { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -98,6 +103,9 @@ public Config() { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -108,6 +116,9 @@ public Config() { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450. / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -118,10 +129,12 @@ public Config() { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8. / 20.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNADelta / mutEscBa5); //BA.2 - double mRNABA2 = mRNABA1 / 1.4; + double mRNABA2 = mRNABA1; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4. / 20.); initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6. / 20.); @@ -129,11 +142,25 @@ public Config() { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8. / 20.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - - - //refresh factors - Map> antibodyRefreshFactors = new HashMap<>(); - + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNADelta / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / 1.4 / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, 2* mRNADelta); // mRNAAlpha / mutEscBa5 + + Map> antibodyRefreshFactors = new HashMap<>(); for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>(VirusStrain.class)); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -142,7 +169,11 @@ public Config() { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); - } else { + } + else if (immunityType == VaccinationType.omicronUpdate) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); } diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 7345c8927..9cef62394 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -6,10 +6,13 @@ import org.matsim.episim.EpisimUtils; import java.util.Collection; +import java.util.List; import java.util.SplittableRandom; public class DefaultAntibodyModel implements AntibodyModel { + public static final double HALF_LIFE_DAYS = 60; // todo: would 40 work better? + double abLevelAfterBooster; private final AntibodyModel.Config antibodyConfig; private final SplittableRandom localRnd; @@ -19,6 +22,8 @@ public class DefaultAntibodyModel implements AntibodyModel { this.antibodyConfig = antibodyConfig; localRnd = new SplittableRandom(2938); // todo: should it be a fixed seed, i.e not change btwn snapshots + abLevelAfterBooster = antibodyConfig.initialAntibodies.get(VaccinationType.mRNA).get(VirusStrain.DELTA) * 15 * Math.pow(0.5, 180 / HALF_LIFE_DAYS); + } @Override @@ -88,9 +93,8 @@ public void updateAntibodies(EpisimPerson person, int day) { // if no immunity event: exponential decay, day by day: for (VirusStrain strain : VirusStrain.values()) { - double halfLife_days = 60.; double oldAntibodyLevel = person.getAntibodies(strain); - person.setAntibodies(strain, oldAntibodyLevel * Math.pow(0.5, 1 / halfLife_days)); + person.setAntibodies(strain, oldAntibodyLevel * Math.pow(0.5, 1 / HALF_LIFE_DAYS)); } } @@ -126,12 +130,21 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent double initialAntibodies = antibodyConfig.initialAntibodies.get(immunityEventType).get(strain2) * person.getImmuneResponseMultiplier(); antibodies = Math.max(antibodies, initialAntibodies); + List omicronStrains = List.of(VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5); + if (immunityEventType.equals(VaccinationType.omicronUpdate)) { + if (omicronStrains.contains(strain2)){ + +// double abLevel; + antibodies = abLevelAfterBooster * person.getImmuneResponseMultiplier(); + + } + } + // check that new antibody level is at most 150 antibodies = Math.min(150., antibodies); person.setAntibodies(strain2, antibodies); } - } } diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index 1aef4748b..8952dfbc1 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -531,24 +531,26 @@ public static final class Params { // general @GenerateSeeds(5) public long seed; - @Parameter({0.0, 1.0, 1.5, 2.0, 2.5}) + @Parameter({1., 2., 3.}) // @Parameter({0.0}) public double actCorrection; - @Parameter({1.0, 1.1, 1.2}) + + @Parameter({1.0, 1.2, 1.4}) // @Parameter({1.0}) public double thFactor; -// @Parameter({1.}) - @Parameter({0.5, 1.}) + // @Parameter({1.}) + @Parameter({0.25, 0.5, 0.75}) public double schoolCi; - @Parameter({1., 2.}) + @Parameter({0.5, 0.75, 1.0}) // @Parameter({1.}) public double workCi; - @Parameter({0.25,0.5, 1.}) + + @Parameter({0.2, 0.3, 0.4}) // @Parameter({ 1.}) public double leisureCi; diff --git a/src/main/java/org/matsim/run/batch/CologneScenarioHub.java b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java new file mode 100644 index 000000000..f0bcaabb4 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java @@ -0,0 +1,401 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneScenarioHub implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + + double mutEscBa5 = 3.0; + + LocalDate start = LocalDate.of(2022, 9, 15); +// LocalDate start = LocalDate.of(2022, 12, 15); + VaccinationType vaccinationType = null; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + if (params != null) { + vaccinationType = VaccinationType.valueOf(params.vacType); + + + if (params.vacCamp.equals("60plus")) { + compliance.put(60, 0.94/2); // 0.94 is boost rate July 16, 2022 + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + } + // assumption: older age group 2boosted first, then younger, each age group + // will have rate of 50% 2boosted by end of campaign. + // motivation: if we give both age groups same rate, then the older people + // will not be boosted as much as younger people, which seems implausible... + else if (params.vacCamp.equals("18plus")) { + compliance.put(60, 0.94/2); // 0.94 is boost rate July 16, 2022 + compliance.put(18, 0.77/2); // 0.77 is boost rate July 16, 2022 + compliance.put(12, 0.); + compliance.put(0, 0.); + } + else if (params.vacCamp.equals("off")) { + + } else { + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } + + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 91, vaccinationType, compliance)); + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscBa5); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscBa5) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + + //DELTA + double mRNADelta = 10.9; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + + //BA.1 + double mRNABA1 = 1.9; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNADelta / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNADelta / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / 1.4 / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNADelta); // mRNAAlpha / mutEscBa5 + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.omicronUpdate) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new HospitalNumbersFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + //mutations + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + //configure new strains + //BA5 + double ba5Inf = 0.9; + double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + + + //Configure Disease Import + + configureFutureDiseaseImport(params, episimConfig); + + + //vaccinations + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(true); + vaccinationConfig.setTimePeriodIgA(730.); + + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + // add initial impulses for strains + //BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + //BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + + infPerDayBa5.put(date.plusDays(1), 1); + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + } + + + public static final class Params { + + // general + @GenerateSeeds(5) + public long seed; + + + // vaccination campaign + @StringParameter({"off", "60plus", "18plus"}) + String vacCamp; + + @StringParameter({"mRNA","omicronUpdate"}) + public String vacType; + + + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneScenarioHub.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(70), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/python/analysis/utils.py b/src/main/python/analysis/utils.py index 9aa067e45..5e9792e7f 100644 --- a/src/main/python/analysis/utils.py +++ b/src/main/python/analysis/utils.py @@ -312,6 +312,6 @@ def calc_r_reduction(base_case, base_variables, df, group_by=None): if __name__ == "__main__": - aggregate_batch_run("../../../../output/summaries.zip") + aggregate_batch_run("/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-20/3-eu/summaries.zip") diff --git a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java index b36fbfa32..6b226e8bf 100644 --- a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java @@ -178,8 +178,10 @@ public void testNoImmunityEvents() { @Test public void testMixOfVaccinesAndInfections() { - List immunityEvents = List.of(VirusStrain.SARS_CoV_2, VaccinationType.mRNA, VirusStrain.DELTA); - IntList immunityEventDays = IntList.of(50, 200, 600); + List immunityEvents = List.of(VaccinationType.mRNA, VaccinationType.mRNA, VaccinationType.omicronUpdate); + IntList immunityEventDays = IntList.of(1, 181, 451); +// List immunityEvents = List.of(VaccinationType.mRNA); +// IntList immunityEventDays = IntList.of(1); Int2ObjectMap> antibodyLevels = simulateAntibodyLevels(immunityEvents, immunityEventDays, 750, EpisimTestUtils.createPerson()); From 44c9c5b8ea359770c835808143d878dd62307b38 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 22 Jul 2022 15:54:57 +0200 Subject: [PATCH 009/128] minimal diff to omicronUpdate --- src/main/java/org/matsim/episim/model/AntibodyModel.java | 2 +- src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/AntibodyModel.java b/src/main/java/org/matsim/episim/model/AntibodyModel.java index 248262400..aae035520 100644 --- a/src/main/java/org/matsim/episim/model/AntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/AntibodyModel.java @@ -158,7 +158,7 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, 2* mRNADelta); // mRNAAlpha / mutEscBa5 + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNADelta); // mRNAAlpha / mutEscBa5 Map> antibodyRefreshFactors = new HashMap<>(); for (VaccinationType immunityType : VaccinationType.values()) { diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 9cef62394..03080d216 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -133,8 +133,6 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent List omicronStrains = List.of(VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5); if (immunityEventType.equals(VaccinationType.omicronUpdate)) { if (omicronStrains.contains(strain2)){ - -// double abLevel; antibodies = abLevelAfterBooster * person.getImmuneResponseMultiplier(); } From cd822c9ad2876a0aeccfe16380b4e534a86253c7 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Tue, 26 Jul 2022 17:29:19 +0200 Subject: [PATCH 010/128] age inf and susp configurable per strain --- .../org/matsim/episim/EpisimConfigGroup.java | 74 ---------------- .../matsim/episim/VirusStrainConfigGroup.java | 88 +++++++++++++++++++ ...ependentInfectionModelWithSeasonality.java | 20 ++--- ...ependentInfectionModelWithSeasonality.java | 30 +++++-- .../model/InfectionModelWithAntibodies.java | 16 ++-- 5 files changed, 126 insertions(+), 102 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimConfigGroup.java b/src/main/java/org/matsim/episim/EpisimConfigGroup.java index ebe364d1a..2badeb3b2 100644 --- a/src/main/java/org/matsim/episim/EpisimConfigGroup.java +++ b/src/main/java/org/matsim/episim/EpisimConfigGroup.java @@ -70,8 +70,6 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { private static final String SNAPSHOT_SEED = "snapshotSeed"; private static final String LEISUREOUTDOORFRACTION = "leisureOutdoorFraction"; private static final String INPUT_DAYS = "inputDays"; - private static final String AGE_SUSCEPTIBILITY = "ageSusceptibility"; - private static final String AGE_INFECTIVITY = "ageInfectivity"; private static final String DAYS_INFECTIOUS = "daysInfectious"; private static final String ACTIVITY_HANDLING = "activityHandling"; private static final String THREADS = "threads"; @@ -167,23 +165,7 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { private SingleEventFile singleEventFile = SingleEventFile.yes; private boolean endEarly = false; private int threads = 2; - /** - * Child susceptibility used in AgeDependentInfectionModelWithSeasonality. - * Taken from https://doi.org/10.1101/2020.06.03.20121145 - */ - private final NavigableMap ageSusceptibility = new TreeMap<>(Map.of( - 19, 0.45, - 20, 1d - )); - /** - * Child infectivity used in AgeDependentInfectionModelWithSeasonality. - * Taken from https://doi.org/10.1101/2020.06.03.20121145 - */ - private final NavigableMap ageInfectivity = new TreeMap<>(Map.of( - 19, 0.85, - 20, 1d - )); /** * Compliance if a curfew is set. @@ -543,62 +525,6 @@ public void setDaysInfectious(int daysInfectious) { this.daysInfectious = daysInfectious; } - @StringGetter(AGE_SUSCEPTIBILITY) - String getAgeSusceptibilityString() { - return JOINER.join(ageSusceptibility); - } - - @StringSetter(AGE_SUSCEPTIBILITY) - void setAgeSusceptibility(String config) { - Map map = SPLITTER.split(config); - setAgeSusceptibility(map.entrySet().stream().collect(Collectors.toMap( - e -> Integer.parseInt(e.getKey()), e -> Double.parseDouble(e.getValue()) - ))); - } - - /** - * Return susceptibility for different age groups. - */ - public NavigableMap getAgeSusceptibility() { - return ageSusceptibility; - } - - /** - * Set susceptibility for all age groups, previous entries will be overwritten. - */ - public void setAgeSusceptibility(Map ageSusceptibility) { - this.ageSusceptibility.clear(); - this.ageSusceptibility.putAll(ageSusceptibility); - } - - @StringGetter(AGE_INFECTIVITY) - String getAgeInfectivityString() { - return JOINER.join(ageInfectivity); - } - - @StringSetter(AGE_INFECTIVITY) - void setAgeInfectivity(String config) { - Map map = SPLITTER.split(config); - setAgeInfectivity(map.entrySet().stream().collect(Collectors.toMap( - e -> Integer.parseInt(e.getKey()), e -> Double.parseDouble(e.getValue()) - ))); - } - - /** - * Return infectivity for different age groups. - */ - public NavigableMap getAgeInfectivity() { - return ageInfectivity; - } - - /** - * Set infectivity for all age groups, previous entries will be overwritten. - */ - public void setAgeInfectivity(Map ageSusceptibility) { - this.ageInfectivity.clear(); - this.ageInfectivity.putAll(ageSusceptibility); - } - /** * Sets the leisure outdoor fraction for the whole simulation period. */ diff --git a/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java b/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java index 9498d57de..6b9a39f67 100644 --- a/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java +++ b/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java @@ -1,17 +1,25 @@ package org.matsim.episim; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; import org.matsim.core.config.ConfigGroup; import org.matsim.core.config.ReflectiveConfigGroup; import org.matsim.episim.model.VirusStrain; import java.util.EnumMap; import java.util.Map; +import java.util.NavigableMap; +import java.util.TreeMap; +import java.util.stream.Collectors; /** * Config option specific to {@link org.matsim.episim.model.VirusStrain}. */ public class VirusStrainConfigGroup extends ReflectiveConfigGroup { + private static final Splitter.MapSplitter SPLITTER = Splitter.on(";").withKeyValueSeparator("="); + private static final Joiner.MapJoiner JOINER = Joiner.on(";").withKeyValueSeparator("="); + private static final String GROUPNAME = "virusStrains"; /** @@ -84,6 +92,8 @@ public static final class StrainParams extends ReflectiveConfigGroup { private static final String FACTOR_SERIOUSLY_SICK = "factorSeriouslySick"; private static final String FACTOR_CRITICAL = "factorCritical"; private static final String FACTOR_SERIOUSLY_SICK_VAC = "factorSeriouslySickVaccinated"; + private static final String AGE_SUSCEPTIBILITY = "ageSusceptibility"; + private static final String AGE_INFECTIVITY = "ageInfectivity"; /** * Type of the strain. @@ -110,6 +120,24 @@ public static final class StrainParams extends ReflectiveConfigGroup { */ private double factorSeriouslySickVaccinated = 1.0; + /** + * Child susceptibility used in AgeDependentInfectionModelWithSeasonality. + * Taken from https://doi.org/10.1101/2020.06.03.20121145 + */ + private final NavigableMap ageSusceptibility = new TreeMap<>(Map.of( + 19, 0.45, + 20, 1d + )); + + /** + * Child infectivity used in AgeDependentInfectionModelWithSeasonality. + * Taken from https://doi.org/10.1101/2020.06.03.20121145 + */ + private final NavigableMap ageInfectivity = new TreeMap<>(Map.of( + 19, 0.85, + 20, 1d + )); + StrainParams() { super(SET_TYPE); } @@ -187,5 +215,65 @@ public void setFactorSeriouslySickVaccinated(double factorSeriouslySickVaccinate public double getFactorSeriouslySickVaccinated() { return factorSeriouslySickVaccinated; } + + + @StringGetter(AGE_SUSCEPTIBILITY) + String getAgeSusceptibilityString() { + return JOINER.join(ageSusceptibility); + } + + @StringSetter(AGE_SUSCEPTIBILITY) + void setAgeSusceptibility(String config) { + Map map = SPLITTER.split(config); + setAgeSusceptibility(map.entrySet().stream().collect(Collectors.toMap( + e -> Integer.parseInt(e.getKey()), e -> Double.parseDouble(e.getValue()) + ))); + } + + /** + * Return susceptibility for different age groups. + */ + public NavigableMap getAgeSusceptibility() { + return ageSusceptibility; + } + + /** + * Set susceptibility for all age groups, previous entries will be overwritten. + */ + public void setAgeSusceptibility(Map ageSusceptibility) { + this.ageSusceptibility.clear(); + this.ageSusceptibility.putAll(ageSusceptibility); + } + + @StringGetter(AGE_INFECTIVITY) + String getAgeInfectivityString() { + return JOINER.join(ageInfectivity); + } + + @StringSetter(AGE_INFECTIVITY) + void setAgeInfectivity(String config) { + Map map = SPLITTER.split(config); + setAgeInfectivity(map.entrySet().stream().collect(Collectors.toMap( + e -> Integer.parseInt(e.getKey()), e -> Double.parseDouble(e.getValue()) + ))); + } + + /** + * Return infectivity for different age groups. + */ + public NavigableMap getAgeInfectivity() { + return ageInfectivity; + } + + /** + * Set infectivity for all age groups, previous entries will be overwritten. + */ + public void setAgeInfectivity(Map ageSusceptibility) { + this.ageInfectivity.clear(); + this.ageInfectivity.putAll(ageSusceptibility); + } + } + + } diff --git a/src/main/java/org/matsim/episim/model/AgeAndProgressionDependentInfectionModelWithSeasonality.java b/src/main/java/org/matsim/episim/model/AgeAndProgressionDependentInfectionModelWithSeasonality.java index 77c495b71..869a8a262 100644 --- a/src/main/java/org/matsim/episim/model/AgeAndProgressionDependentInfectionModelWithSeasonality.java +++ b/src/main/java/org/matsim/episim/model/AgeAndProgressionDependentInfectionModelWithSeasonality.java @@ -8,6 +8,7 @@ import org.matsim.episim.*; import org.matsim.episim.policy.Restriction; +import java.util.EnumMap; import java.util.Map; import java.util.SplittableRandom; @@ -26,8 +27,8 @@ public final class AgeAndProgressionDependentInfectionModelWithSeasonality imple private final VaccinationConfigGroup vaccinationConfig; private final VirusStrainConfigGroup virusStrainConfig; - private final double[] susceptibility = new double[128]; - private final double[] infectivity = new double[susceptibility.length]; + private final Map susceptibility = new EnumMap<>(VirusStrain.class); + private final Map infectivity = new EnumMap<>(VirusStrain.class); private final RealDistribution distribution; /** @@ -50,11 +51,8 @@ public final class AgeAndProgressionDependentInfectionModelWithSeasonality imple this.reporting = reporting; this.rnd = rnd; - // pre-compute interpolated age dependent entries - for (int i = 0; i < susceptibility.length; i++) { - susceptibility[i] = EpisimUtils.interpolateEntry(episimConfig.getAgeSusceptibility(), i); - infectivity[i] = EpisimUtils.interpolateEntry(episimConfig.getAgeInfectivity(), i); - } + AgeDependentInfectionModelWithSeasonality.preComputeAgeDependency(susceptibility, infectivity, virusStrainConfig); + // based on https://arxiv.org/abs/2007.06602 distribution = new NormalDistribution(0.5, 2.6); scale = 1 / distribution.density(distribution.getNumericalMean()); @@ -81,8 +79,8 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto //noinspection ConstantConditions // ci corr can not be null, because sim is initialized with non null value double ciCorrection = Math.min(restrictions.get(act1.getContainerName()).getCiCorrection(), restrictions.get(act2.getContainerName()).getCiCorrection()); - double susceptibility = this.susceptibility[target.getAge()]; - double infectivity = this.infectivity[infector.getAge()]; + double susceptibility = this.susceptibility.get(infector.getVirusStrain())[target.getAge()]; + double infectivity = this.infectivity.get(infector.getVirusStrain())[infector.getAge()]; // apply reduced susceptibility of vaccinated persons VirusStrainConfigGroup.StrainParams strain = virusStrainConfig.getParams(infector.getVirusStrain()); @@ -110,8 +108,8 @@ private double calcUnVacInfectionProbability(EpisimPerson target, EpisimPerson i //noinspection ConstantConditions // ci corr can not be null, because sim is initialized with non null value double ciCorrection = Math.min(restrictions.get(act1.getContainerName()).getCiCorrection(), restrictions.get(act2.getContainerName()).getCiCorrection()); - double susceptibility = this.susceptibility[target.getAge()]; - double infectivity = this.infectivity[infector.getAge()]; + double susceptibility = this.susceptibility.get(infector.getVirusStrain())[target.getAge()]; + double infectivity = this.infectivity.get(infector.getVirusStrain())[infector.getAge()]; // apply reduced susceptibility of vaccinated persons VirusStrainConfigGroup.StrainParams strain = virusStrainConfig.getParams(infector.getVirusStrain()); diff --git a/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java b/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java index 99df4019d..f76bd1f3c 100644 --- a/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java +++ b/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java @@ -6,6 +6,7 @@ import org.matsim.episim.*; import org.matsim.episim.policy.Restriction; +import java.util.EnumMap; import java.util.Map; import java.util.SplittableRandom; @@ -23,8 +24,8 @@ public final class AgeDependentInfectionModelWithSeasonality implements Infectio private final VaccinationConfigGroup vaccinationConfig; private final VirusStrainConfigGroup virusStrainConfig; - private final double[] susceptibility = new double[128]; - private final double[] infectivity = new double[susceptibility.length]; + private final Map susceptibility = new EnumMap<>(VirusStrain.class); + private final Map infectivity = new EnumMap<>(VirusStrain.class); private double outdoorFactor; private int iteration; @@ -38,10 +39,23 @@ public final class AgeDependentInfectionModelWithSeasonality implements Infectio this.reporting = reporting; this.rnd = rnd; - // pre-compute interpolated age dependent entries - for (int i = 0; i < susceptibility.length; i++) { - susceptibility[i] = EpisimUtils.interpolateEntry(episimConfig.getAgeSusceptibility(), i); - infectivity[i] = EpisimUtils.interpolateEntry(episimConfig.getAgeInfectivity(), i); + preComputeAgeDependency(susceptibility, infectivity, virusStrainConfig); + } + + /** + * Pre-compute interpolated age dependent entries + */ + static void preComputeAgeDependency(Map susceptibility, Map infectivity, VirusStrainConfigGroup virusStrainConfig) { + + for (VirusStrain strain : VirusStrain.values()) { + + double[] susp = susceptibility.computeIfAbsent(strain, k -> new double[128]); + double[] inf = infectivity.computeIfAbsent(strain, k -> new double[susp.length]); + + for (int i = 0; i < susp.length; i++) { + susp[i] = EpisimUtils.interpolateEntry(virusStrainConfig.getParams(strain).getAgeSusceptibility(), i); + inf[i] = EpisimUtils.interpolateEntry(virusStrainConfig.getParams(strain).getAgeInfectivity(), i); + } } } @@ -61,8 +75,8 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto //noinspection ConstantConditions // ci corr can not be null, because sim is initialized with non null value double ciCorrection = Math.min(restrictions.get(act1.getContainerName()).getCiCorrection(), restrictions.get(act2.getContainerName()).getCiCorrection()); - double susceptibility = this.susceptibility[target.getAge()]; - double infectivity = this.infectivity[infector.getAge()]; + double susceptibility = this.susceptibility.get(infector.getVirusStrain())[target.getAge()]; + double infectivity = this.infectivity.get(infector.getVirusStrain())[infector.getAge()]; // apply reduced susceptibility of vaccinated persons VirusStrainConfigGroup.StrainParams params = virusStrainConfig.getParams(infector.getVirusStrain()); diff --git a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java index 24444e702..b769b056d 100644 --- a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java +++ b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java @@ -8,6 +8,7 @@ import org.matsim.episim.*; import org.matsim.episim.policy.Restriction; +import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.SplittableRandom; @@ -25,8 +26,8 @@ public final class InfectionModelWithAntibodies implements InfectionModel { private final VaccinationConfigGroup vaccinationConfig; private final VirusStrainConfigGroup virusStrainConfig; - private final double[] susceptibility = new double[128]; - private final double[] infectivity = new double[susceptibility.length]; + private final Map susceptibility = new EnumMap<>(VirusStrain.class); + private final Map infectivity = new EnumMap<>(VirusStrain.class); private final RealDistribution distribution; /** @@ -49,11 +50,8 @@ public final class InfectionModelWithAntibodies implements InfectionModel { this.reporting = reporting; this.rnd = rnd; - // pre-compute interpolated age dependent entries - for (int i = 0; i < susceptibility.length; i++) { - susceptibility[i] = EpisimUtils.interpolateEntry(episimConfig.getAgeSusceptibility(), i); - infectivity[i] = EpisimUtils.interpolateEntry(episimConfig.getAgeInfectivity(), i); - } + AgeDependentInfectionModelWithSeasonality.preComputeAgeDependency(susceptibility, infectivity, virusStrainConfig); + // based on https://arxiv.org/abs/2007.06602 distribution = new NormalDistribution(0.5, 2.6); scale = 1 / distribution.density(distribution.getNumericalMean()); @@ -80,8 +78,8 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto //noinspection ConstantConditions // ci corr can not be null, because sim is initialized with non null value double ciCorrection = Math.min(restrictions.get(act1.getContainerName()).getCiCorrection(), restrictions.get(act2.getContainerName()).getCiCorrection()); - double susceptibility = this.susceptibility[target.getAge()]; - double infectivity = this.infectivity[infector.getAge()]; + double susceptibility = this.susceptibility.get(infector.getVirusStrain())[target.getAge()]; + double infectivity = this.infectivity.get(infector.getVirusStrain())[infector.getAge()]; VirusStrainConfigGroup.StrainParams strain = virusStrainConfig.getParams(infector.getVirusStrain()); From 389c98e0fcf0612b0dadad2592ecacaadd8c5a6b Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Tue, 26 Jul 2022 17:54:07 +0200 Subject: [PATCH 011/128] ignore unconfigured strains --- .../java/org/matsim/episim/VirusStrainConfigGroup.java | 7 +++++++ .../model/AgeDependentInfectionModelWithSeasonality.java | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java b/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java index 6b9a39f67..17e7fce4d 100644 --- a/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java +++ b/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java @@ -61,6 +61,13 @@ public StrainParams getOrAddParams(VirusStrain strain) { return strains.get(strain); } + /** + * Whether params for strain are present. + */ + public boolean hasParams(VirusStrain strain) { + return strains.containsKey(strain); + } + @Override public ConfigGroup createParameterSet(String type) { if (StrainParams.SET_TYPE.equals(type)) { diff --git a/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java b/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java index f76bd1f3c..081bba8bc 100644 --- a/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java +++ b/src/main/java/org/matsim/episim/model/AgeDependentInfectionModelWithSeasonality.java @@ -49,12 +49,17 @@ static void preComputeAgeDependency(Map susceptibility, M for (VirusStrain strain : VirusStrain.values()) { + if (!virusStrainConfig.hasParams(strain)) + continue; + double[] susp = susceptibility.computeIfAbsent(strain, k -> new double[128]); double[] inf = infectivity.computeIfAbsent(strain, k -> new double[susp.length]); + VirusStrainConfigGroup.StrainParams strainConfig = virusStrainConfig.getParams(strain); + for (int i = 0; i < susp.length; i++) { - susp[i] = EpisimUtils.interpolateEntry(virusStrainConfig.getParams(strain).getAgeSusceptibility(), i); - inf[i] = EpisimUtils.interpolateEntry(virusStrainConfig.getParams(strain).getAgeInfectivity(), i); + susp[i] = EpisimUtils.interpolateEntry(strainConfig.getAgeSusceptibility(), i); + inf[i] = EpisimUtils.interpolateEntry(strainConfig.getAgeInfectivity(), i); } } } From e82c88ceb28deb980ce678489da5589f9a2d46b5 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 27 Jul 2022 12:14:58 +0200 Subject: [PATCH 012/128] added analysis to calculate the secondary attack rate over time. added todo for RValuesFromEvents --- src/main/R/Covid19ScenarioHubSubmission.R | 80 ++++++ .../episim/analysis/RValuesFromEvents.java | 1 + .../SecondaryAttackRateFromEvents.java | 244 ++++++++++++++++++ .../java/org/matsim/run/AnalysisCommand.java | 2 +- 4 files changed, 326 insertions(+), 1 deletion(-) create mode 100644 src/main/R/Covid19ScenarioHubSubmission.R create mode 100644 src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java diff --git a/src/main/R/Covid19ScenarioHubSubmission.R b/src/main/R/Covid19ScenarioHubSubmission.R new file mode 100644 index 000000000..126ee1f23 --- /dev/null +++ b/src/main/R/Covid19ScenarioHubSubmission.R @@ -0,0 +1,80 @@ +source("/Users/jakob/git/matsim-episim/src/main/R/masterJR-utils.R", encoding = 'utf-8') + +library(lubridate) +library(tidyverse) +library(readr) + + + + + +# Global variables +directory <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-20/3-eu-noAgg/" + +origin_date <- ymd("2022-07-24") # first day (sunday) of epiweek 30, 2022 +end_date <- ymd("2023-07-29") # last day (saturday) of epiweek 30, 2023 (latest possible value) + + +## read & prep infections +infections_raw <- read_combine_episim_output_zipped(directory,"infections.txt.csv") + +infections_incidence <- convert_infections_into_incidence(directory,infections_raw,FALSE) %>% + select(-c(infections_week,nShowingSymptomsCumulative, district, incidence)) + + +population <- infections_raw[1,"nSusceptible"] + +infections_ready <- infections_incidence %>% + filter(date >= origin_date & date <= end_date) %>% + # mutate(weekday = lubridate::wday(date, label = TRUE)) %>% + mutate(year = epiyear(date)) %>% + mutate(epiweek = epiweek(date)) %>% + group_by(seed,vacCamp,vacType,year,epiweek) %>% + summarise(infections = sum(infections), target_end_date = last(date) ) %>% + mutate(value = infections * 100000 / population) %>% + mutate(target_variable = "inc infection") %>% + select(year, epiweek, target_end_date, target_variable, value, seed, vacCamp, vacType) + + +## read & prep hospitalizations +hosp_raw <- read_combine_episim_output_zipped(directory,"post.hospital.tsv") + +hosp_ready <- hosp_raw %>% + filter(date >= origin_date & date <= end_date) %>% + mutate(year = year(date)) %>% + mutate(wkday = lubridate::wday(date, label = TRUE)) %>% + filter(wkday == "Sat") %>% + filter(measurement == "intakesHosp") %>% + filter(severity == "Omicron") %>% + mutate(epiweek = epiweek(date)) %>% + rename("target_end_date" = date, value = n) %>% + mutate(target_variable = "inc hosp") %>% + select(year, epiweek, target_end_date, target_variable, value, seed, vacCamp, vacType) + +# combine two dataframes and modify columns to match specs +combined <- rbind(infections_ready, hosp_ready) + + +seed <- unique(combined$seed) +sample <- seq(length(seed)) +map <- data.frame(seed,sample) + +final <- combined %>% filter(vacCamp!="off") %>% + mutate(scenario_id = paste0(vacCamp,"_",vacType)) %>% + mutate(scenario_id = case_when(scenario_id == "60plus_omicronUpdate"~"A-2022-07-24", + scenario_id == "18plus_omicronUpdate"~"B-2022-07-24", + scenario_id == "60plus_mRNA"~"C-2022-07-24", + scenario_id == "18plus_mRNA"~"D-2022-07-24")) %>% + merge(map,by ="seed") %>% + mutate(horizon = paste0(case_when(year == 2022 ~ epiweek - 29, year == 2023~ (52-29) + epiweek), " wk")) %>% + mutate("origin_date" = "2022-07-24") %>% + mutate("location" = "DE") %>% + select(origin_date,scenario_id,target_variable, horizon, target_end_date, location, sample, value) + +write.csv(final, paste0(directory,"submission.csv"), row.names = FALSE) + + + + + + diff --git a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java index 6de4fffda..e06472b4d 100644 --- a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java @@ -209,6 +209,7 @@ private static class RHandler implements EpisimPersonStatusEventHandler, EpisimI /** * If a person is infected another time it will be removed from {@link #infectedPersons} and put here. + * TODO: what happens if person is infected >2x? */ private final List handledInfections = new ArrayList<>(); diff --git a/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java b/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java new file mode 100644 index 000000000..20f5569fd --- /dev/null +++ b/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java @@ -0,0 +1,244 @@ +/* *********************************************************************** * + * project: org.matsim.* + * EditRoutesTest.java + * * + * *********************************************************************** * + * * + * copyright : (C) 2020 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.episim.analysis; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.config.Configurator; +import org.matsim.api.core.v01.population.Person; +import org.matsim.api.core.v01.population.Population; +import org.matsim.core.population.PopulationUtils; +import org.matsim.episim.EpisimPerson.DiseaseStatus; +import org.matsim.episim.events.EpisimPersonStatusEvent; +import org.matsim.episim.events.EpisimPersonStatusEventHandler; +import org.matsim.run.AnalysisCommand; +import picocli.CommandLine; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.*; +import java.util.Map.Entry; +import java.util.function.Function; +import java.util.stream.Collectors; + + +/** + * @author jakobrehmann + * Calculates secondary attack rate for all runs in given directory + * Output is written to secondaryAttackRate.txt in the working directory + */ + +@CommandLine.Command( + name = "calculateSecondaryAttackRate", + description = "Calculate Secondary Attack Rate" +) +public class SecondaryAttackRateFromEvents implements OutputAnalysis { + + private static final Logger log = LogManager.getLogger(SecondaryAttackRateFromEvents.class); + +// @CommandLine.Option(names = "--output", defaultValue = "./output/") + @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-22/1-calibration/output") + private Path output; + + @CommandLine.Option(names = "--start-date", defaultValue = "2020-02-24") + private LocalDate startDate; + +// @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") + @CommandLine.Option(names = "--input", defaultValue = "../shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input") + private String input; + + @CommandLine.Option(names = "--population-file", defaultValue = "/cologne_snz_entirePopulation_emptyPlans_withDistricts_25pt_split.xml.gz") + private String populationFile; + + + private Map personToHousehold; + + private Map personCountPerHousehold; + + + public static void main(String[] args) { + System.exit(new CommandLine(new SecondaryAttackRateFromEvents()).execute(args)); + } + + @Override + public Integer call() throws Exception { + Configurator.setLevel("org.matsim.core.config", Level.WARN); + Configurator.setLevel("org.matsim.core.controler", Level.WARN); + Configurator.setLevel("org.matsim.core.events", Level.WARN); + Configurator.setLevel("org.matsim.core.utils", Level.WARN); + + if (!Files.exists(output)) { + log.error("Output path {} does not exist.", output); + return 2; + } + + Population population = PopulationUtils.readPopulation(input + populationFile); + + personToHousehold = new HashMap<>(); + for (Person person : population.getPersons().values()) { + if(person.getAttributes().getAttribute("district").equals("Köln")) + personToHousehold.put(person.getId().toString(), person.getAttributes().getAttribute("homeId").toString()); + } + + personCountPerHousehold = personToHousehold.values().stream() + .collect(Collectors.groupingBy(Function.identity(), + Collectors.counting())); + + OptionalDouble x = personCountPerHousehold.values().stream().mapToLong(Long::longValue).average(); + + AnalysisCommand.forEachScenario(output, scenario -> { + try { + analyzeOutput(scenario); + } catch (IOException e) { + log.error("Failed processing {}", scenario, e); + } + }); + + log.info("Done"); + + return 0; + } + + @Override + public void analyzeOutput(Path output) throws IOException { + + String id = AnalysisCommand.getScenarioPrefix(output); + + + SecondaryAttackRateHandler hhHandler = new SecondaryAttackRateHandler(personToHousehold); + + List eventFiles = AnalysisCommand.forEachEvent(output, s -> { + }, hhHandler); + + Map> itToHouseholdToInfections = hhHandler.getItToHouseholdToInfections(); + + BufferedWriter bw = Files.newBufferedWriter(output.resolve(id + "secondaryAttackRate.txt")); + bw.write("day\tdate\trate"); + + int rollingAverage = 3; + for (int i = 0 + rollingAverage; i <= eventFiles.size() - rollingAverage; i++) { + + if (startDate.plusDays(i).getDayOfWeek() != DayOfWeek.THURSDAY) { + continue; + } + + long totalHhInfectionsForWeek = 0; + long totalHhMemberCnt = 0; + for (int j = i - rollingAverage; j <= i + rollingAverage; j++) { + + if (itToHouseholdToInfections.containsKey(j)) { + for (Entry hhToInfections : itToHouseholdToInfections.get(j).entrySet()) { + totalHhInfectionsForWeek += hhToInfections.getValue(); + totalHhMemberCnt = totalHhMemberCnt + personCountPerHousehold.get(hhToInfections.getKey()) - 1; + } + } + } + double secondaryAttackRate = (double) totalHhInfectionsForWeek / totalHhMemberCnt; + bw.write("\n" + i + "\t" + startDate.plusDays(i).toString() + "\t" + secondaryAttackRate); + } + bw.close(); + log.info("Calculated results for scenario {}", output); + } + + private static class SecondaryAttackRateHandler implements EpisimPersonStatusEventHandler { + + /** + * personID to hh Id + */ + Map personToHousehold; + + /** + * keys: all agents who are currently the index agent for their household + * values: day at which they became contagious + */ + Map indexPersons = new HashMap<>(); + + /** + * keys: all households that currently contain an index agent. + * values: count of how many agents in index agent's hh are infected before index agent recovers + */ + Map householdToInfections = new HashMap<>(); + + /** + * This map aggregates all information required to calculate secondary attack rate. Households are + * entered here once the index agent recovers, but are backdated to the day they become contagious. + * keys: iterations at which index agents become contagious + * values: map containing household id and how many house mates were infected + */ + Map> itToHouseholdToInfections = new HashMap<>(); + + + public SecondaryAttackRateHandler(Map personToHousehold) { + this.personToHousehold = personToHousehold; + } + + public Map> getItToHouseholdToInfections() { + return itToHouseholdToInfections; + } + + @Override + public void handleEvent(EpisimPersonStatusEvent event) { + + int day = (int) (event.getTime() / 86400); + String personId = event.getPersonId().toString(); + String hhId = personToHousehold.get(personId); + + if (event.getDiseaseStatus() == DiseaseStatus.contagious) { + if (indexPersons.containsKey(personId)) { + throw new RuntimeException("person was already contagious, but was never removed from indexPersons when recovered"); + } + + if (householdToInfections.containsKey(hhId)) { + householdToInfections.merge(hhId, 1, Integer::sum); + } else { + indexPersons.put(personId, day); + householdToInfections.put(hhId, 0); + } + } + + if (event.getDiseaseStatus() == DiseaseStatus.recovered) { + if (indexPersons.containsKey(personId)) { + + // update global map with household infections for index agent who has just recovered (back-dated to day contagious) + Integer dayContagious = indexPersons.get(personId); + itToHouseholdToInfections.putIfAbsent(dayContagious, new HashMap<>()); + itToHouseholdToInfections.get(dayContagious).put(hhId, householdToInfections.get(hhId)); + + // now that hh infections have been saved to global map, remove from temp maps. + householdToInfections.remove(hhId); + indexPersons.remove(personId); + + } + } + } + + } + +} + + + + diff --git a/src/main/java/org/matsim/run/AnalysisCommand.java b/src/main/java/org/matsim/run/AnalysisCommand.java index ff7610d0d..fb20ef60c 100644 --- a/src/main/java/org/matsim/run/AnalysisCommand.java +++ b/src/main/java/org/matsim/run/AnalysisCommand.java @@ -57,7 +57,7 @@ CommandLine.HelpCommand.class, AutoComplete.GenerateCompletion.class, RValuesFromEvents.class, ExtractInfectionsByAge.class, CreateContactGraph.class, ExtractInfectionGraph.class, VaccinationEffectivenessFromPotentialInfections.class, - VaccinationEffectiveness.class, FilterEvents.class, HospitalNumbersFromEvents.class + VaccinationEffectiveness.class, FilterEvents.class, HospitalNumbersFromEvents.class, SecondaryAttackRateFromEvents.class }, subcommandsRepeatable = true ) From 04f53d7f40c7ae26aa8b8c695f257824d37b7510 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 27 Jul 2022 12:16:11 +0200 Subject: [PATCH 013/128] changed bash scripts and r utils --- src/main/R/masterJR-utils.R | 39 +++++++++++++++++++ .../java/org/matsim/run/batch/CologneJR.java | 10 +++-- .../matsim/run/batch/CologneScenarioHub.java | 9 +++-- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/main/R/masterJR-utils.R b/src/main/R/masterJR-utils.R index 3905c473b..2720bc9ac 100644 --- a/src/main/R/masterJR-utils.R +++ b/src/main/R/masterJR-utils.R @@ -3,6 +3,8 @@ # Created by: jakob # Created on: 7/22/2021 +library(data.table) + # Functions: # read_and_process_episim_infections <- function(directory, facilities_to_district_map) { @@ -211,6 +213,43 @@ read_combine_episim_output <- function(directory, file_root, allow_missing_files return(data.frame(episim_df_all_runs)) } +read_combine_episim_output_zipped <- function(directory, file_root) { + + info_df <- read_delim(paste0(directory, "_info.txt"), delim = ";") + + # gathers column names that should be included in final dataframe + col_names <- colnames(info_df) + relevant_cols <- col_names[!col_names %in% c("RunScript", "RunId", "Config", "Output")] + + episim_df_all_runs <- data.frame() + for (row in seq_len(nrow(info_df))) { + + runId <- info_df$RunId[row] + + zipDir <- paste0(directory,"summaries/",runId,".zip") + + file_name <- paste0(runId, ".", file_root) + + df_for_run <- read_delim(unz(zipDir, file_name)) + + if (dim(df_for_run)[1] == 0) { + warning(paste0(file_name, " is empty")) + next + } + + # adds important variables concerning run to df, so that individual runs can be filtered in later steps + for (var in relevant_cols) { + df_for_run[var] <- info_df[row, var] + } + + episim_df_all_runs <- rbindlist(list(episim_df_all_runs, df_for_run)) + + } + + return(data.frame(episim_df_all_runs)) +} + + read_and_process_new_rki_data_incidenz <- function(filename) { rki <- read_excel(filename, diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index 8952dfbc1..a041f1c0f 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -423,11 +423,13 @@ public Config prepareConfig(int id, Params params) { //modify contact intensity - EpisimConfigGroup.InfectionParams workParams = episimConfig.getOrAddContainerParams("work"); - workParams.setContactIntensity(workParams.getContactIntensity() * params.workCi); + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * params.workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * params.workCi); + + + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * params.leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * params.leisureCi); - EpisimConfigGroup.InfectionParams leisureParams = episimConfig.getOrAddContainerParams("leisure"); - leisureParams.setContactIntensity(leisureParams.getContactIntensity() * params.leisureCi); episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * params.schoolCi); episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * params.schoolCi); diff --git a/src/main/java/org/matsim/run/batch/CologneScenarioHub.java b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java index f0bcaabb4..57226c354 100644 --- a/src/main/java/org/matsim/run/batch/CologneScenarioHub.java +++ b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java @@ -259,10 +259,11 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( - new VaccinationEffectiveness().withArgs(), - new RValuesFromEvents().withArgs(), - new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new HospitalNumbersFromEvents().withArgs() +// new VaccinationEffectiveness().withArgs(), +// new RValuesFromEvents().withArgs(), +// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), +// new HospitalNumbersFromEvents().withArgs() + new SecondaryAttackRateFromEvents().withArgs() ); } From 6f48fd0398ae7cf3c9a5e0196e1516f5fd8cd66b Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 27 Jul 2022 12:40:58 +0200 Subject: [PATCH 014/128] reverted certain omicronUpdate changes --- .../org/matsim/episim/model/DefaultAntibodyModel.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 03080d216..b60b19979 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -12,7 +12,7 @@ public class DefaultAntibodyModel implements AntibodyModel { public static final double HALF_LIFE_DAYS = 60; // todo: would 40 work better? - double abLevelAfterBooster; + private final AntibodyModel.Config antibodyConfig; private final SplittableRandom localRnd; @@ -22,7 +22,6 @@ public class DefaultAntibodyModel implements AntibodyModel { this.antibodyConfig = antibodyConfig; localRnd = new SplittableRandom(2938); // todo: should it be a fixed seed, i.e not change btwn snapshots - abLevelAfterBooster = antibodyConfig.initialAntibodies.get(VaccinationType.mRNA).get(VirusStrain.DELTA) * 15 * Math.pow(0.5, 180 / HALF_LIFE_DAYS); } @@ -130,13 +129,6 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent double initialAntibodies = antibodyConfig.initialAntibodies.get(immunityEventType).get(strain2) * person.getImmuneResponseMultiplier(); antibodies = Math.max(antibodies, initialAntibodies); - List omicronStrains = List.of(VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5); - if (immunityEventType.equals(VaccinationType.omicronUpdate)) { - if (omicronStrains.contains(strain2)){ - antibodies = abLevelAfterBooster * person.getImmuneResponseMultiplier(); - - } - } // check that new antibody level is at most 150 antibodies = Math.min(150., antibodies); From 7d8ec742b5f2de03b043da0b7fad9f616fe4d0ef Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 28 Jul 2022 16:32:06 +0200 Subject: [PATCH 015/128] wip: hospital post processing for hub submission --- .../analysis/HospitalNumbersFromEvents.java | 49 +- .../HospitalNumbersFromEventsPlotter.java | 1149 +++++++++-------- 2 files changed, 615 insertions(+), 583 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index be464ea69..10120e5f7 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -59,12 +59,12 @@ ) public class HospitalNumbersFromEvents implements OutputAnalysis { - @CommandLine.Option(names = "--output", defaultValue = "./output/") -// @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-06-16/2/analysis/policy_leis75/") +// @CommandLine.Option(names = "--output", defaultValue = "./output/") + @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-20/3-eu/analysis/base/") private Path output; - @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") -// @CommandLine.Option(names = "--input", defaultValue = "../shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input") +// @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") + @CommandLine.Option(names = "--input", defaultValue = "../shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input") private String input; @CommandLine.Option(names = "--population-file", defaultValue = "/cologne_snz_entirePopulation_emptyPlans_withDistricts_25pt_split.xml.gz") @@ -81,18 +81,13 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private final String DATE = "date"; private final String DAY = "day"; - private final String INTAKES_HOSP = "intakesHosp"; - private final String INTAKES_ICU = "intakesIcu"; - private final String OCCUPANCY_HOSP = "occupancyHosp"; - private final String OCCUPANCY_ICU = "occupancyIcu"; + @Inject private Scenario scenario; private Population population; - private List> filteredPopulationIds; - // source: incidence wave vs. hospitalization wave in cologne/nrw (see https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit?usp=sharing) private static final Object2IntMap lagBetweenInfectionAndHospitalisation = new Object2IntAVLTreeMap<>( Map.of(VirusStrain.SARS_CoV_2, 14, @@ -149,11 +144,8 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double beta = 1.2; - private final int populationCntOfficialKoelln = 919_936; - private final int populationCntOfficialNrw = 17_930_000; - - private static final double hospitalFactor = 0.4; + private static final double hospitalFactor = 0.20; // base private static final double factorWild = 1.0; @@ -161,18 +153,20 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double factorAlpha = 1.0 * factorWild; // delta: 2.3x more severe than alpha - Hospital admission and emergency care attendance risk for SARS-CoV-2 delta (B.1.617.2) compared with alpha (B.1.1.7) variants of concern: a cohort study - private static final double factorDelta = 1.6 * factorWild; + private static final double factorDelta = 1.0 * factorWild;//1.6 * factorWild; // omicron: approx 0.3x (intrinsic) severity of delta - Comparative analysis of the risks of hospitalisation and death associated with SARS-CoV-2 omicron (B.1.1.529) and delta (B.1.617.2) variants in England: a cohort study - private static final double factorOmicron = 0.3 * factorDelta; // * reportedShareOmicron / reportedShareDelta + private static final double factorOmicron = 0.5 * factorDelta; // reportedShareOmicron / reportedShareDelta + + private static final double factorBA5 = 1.5 * factorOmicron; -// private static final List strainFactors = List.of(factorOmicron, factorDelta); // ?? private static final double factorWildAndAlphaICU = 1.; private static final double factorDeltaICU = 1.; private static final double factorOmicronICU = 1.; + private static final double factorBA5ICU = 1.; private String outputAppendix = ""; @@ -200,10 +194,10 @@ public Integer call() throws Exception { // Part 1: calculate hospitalizations for each seed and save as csv -// List pathList = new ArrayList<>(); + List pathList = new ArrayList<>(); AnalysisCommand.forEachScenario(output, pathToScenario -> { try { -// pathList.add(pathToScenario); + pathList.add(pathToScenario); // analyzeOutput is where the hospitalization post processing occurs analyzeOutput(pathToScenario); @@ -217,6 +211,9 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, outputAppendix, startDate, "Omicron"); + + // } @@ -312,13 +309,13 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t double occupancyIcu = handler.postProcessHospitalFilledBedsICU.getOrDefault(day, 0) * 100_000. / popSize; bw.newLine(); - bw.write(AnalysisCommand.TSV.join(day, date, "intakesHosp", handler.name , intakesHosp)); + bw.write(AnalysisCommand.TSV.join(day, date, HospitalNumbersFromEventsPlotter.INTAKES_HOSP, handler.name , intakesHosp)); bw.newLine(); - bw.write(AnalysisCommand.TSV.join(day, date, "intakesICU", handler.name, intakesIcu)); + bw.write(AnalysisCommand.TSV.join(day, date, HospitalNumbersFromEventsPlotter.INTAKES_ICU, handler.name, intakesIcu)); bw.newLine(); - bw.write(AnalysisCommand.TSV.join(day, date, "occupancyHosp ", handler.name, occupancyHosp)); + bw.write(AnalysisCommand.TSV.join(day, date, HospitalNumbersFromEventsPlotter.OCCUPANCY_HOSP, handler.name, occupancyHosp)); bw.newLine(); - bw.write(AnalysisCommand.TSV.join(day, date, "occupancyICU", handler.name, occupancyIcu)); + bw.write(AnalysisCommand.TSV.join(day, date, HospitalNumbersFromEventsPlotter.OCCUPANCY_ICU, handler.name, occupancyIcu)); } } @@ -327,7 +324,7 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t } - private int getWeeklyHospitalizations(Int2IntMap hospMap, Integer today) { + static int getWeeklyHospitalizations(Int2IntMap hospMap, Integer today) { int weeklyHospitalizations = 0; for (int i = 0; i < 7; i++) { try { @@ -724,8 +721,8 @@ private ConfigHolder configure(double facA, double facAICU) { strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorCritical(factorOmicronICU); strainConfig.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorSeriouslySick(factorOmicron); strainConfig.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorCritical(factorOmicronICU); - strainConfig.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(factorOmicron); - strainConfig.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(factorOmicronICU); + strainConfig.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(factorBA5); + strainConfig.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(factorBA5ICU); strainConfig.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(facA); strainConfig.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(facAICU); diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java index e4b5d7ca0..0f5635581 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java @@ -1,561 +1,596 @@ -//package org.matsim.episim.analysis; -// -//import it.unimi.dsi.fastutil.ints.*; -//import org.apache.commons.csv.CSVFormat; -//import org.apache.commons.csv.CSVParser; -//import org.apache.commons.csv.CSVPrinter; -//import org.apache.commons.csv.CSVRecord; -//import org.matsim.run.AnalysisCommand; -//import tech.tablesaw.api.*; -//import tech.tablesaw.plotly.components.Axis; -//import tech.tablesaw.plotly.components.Figure; -//import tech.tablesaw.plotly.components.Layout; -//import tech.tablesaw.plotly.components.Page; -//import tech.tablesaw.plotly.traces.ScatterTrace; -//import tech.tablesaw.table.TableSliceGroup; -// -//import java.io.*; -//import java.nio.charset.StandardCharsets; -//import java.nio.file.Files; -//import java.nio.file.Path; -//import java.time.LocalDate; -//import java.time.format.DateTimeFormatter; -//import java.time.temporal.ChronoUnit; -//import java.util.List; -// -//public class HospitalNumbersFromEventsPlotter { -// -// -// private static void aggregateAndProducePlots(Path output, List pathList) throws IOException { -// -// -// // read hospitalization tsv for all seeds and aggregate them! -// // NOTE: all other parameters should be the same, otherwise the results will be useless! -// Int2DoubleSortedMap intakeHosp = new Int2DoubleAVLTreeMap(); -// Int2DoubleSortedMap intakeIcu = new Int2DoubleAVLTreeMap(); -// Int2DoubleSortedMap occupancyHosp = new Int2DoubleAVLTreeMap(); -// Int2DoubleSortedMap occupancyIcu = new Int2DoubleAVLTreeMap(); -// -//// Int2DoubleSortedMap hospNoImmunity = new Int2DoubleAVLTreeMap(); -//// Int2DoubleSortedMap hospBaseImmunity = new Int2DoubleAVLTreeMap(); -//// Int2DoubleSortedMap hospBoosted = new Int2DoubleAVLTreeMap(); -//// -//// Int2DoubleSortedMap incNoImmunity = new Int2DoubleAVLTreeMap(); -//// Int2DoubleSortedMap incBaseImmunity = new Int2DoubleAVLTreeMap(); -//// Int2DoubleSortedMap incBoosted = new Int2DoubleAVLTreeMap(); -// -// -// -// -// for (Path path : pathList) { -// -// String id = AnalysisCommand.getScenarioPrefix(path); -// -// final Path tsvPath = path.resolve(id + "post.hospital" + outputAppendix + ".tsv"); -// -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(tsvPath), CSVFormat.DEFAULT.withDelimiter('\t').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// -// int day = Integer.parseInt(record.get(DAY)); +package org.matsim.episim.analysis; + +import it.unimi.dsi.fastutil.ints.*; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVPrinter; +import org.apache.commons.csv.CSVRecord; +import org.matsim.episim.model.VirusStrain; +import org.matsim.run.AnalysisCommand; +import tech.tablesaw.api.*; +import tech.tablesaw.plotly.components.Axis; +import tech.tablesaw.plotly.components.Figure; +import tech.tablesaw.plotly.components.Layout; +import tech.tablesaw.plotly.components.Page; +import tech.tablesaw.plotly.traces.ScatterTrace; +import tech.tablesaw.table.TableSliceGroup; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.List; + +public class HospitalNumbersFromEventsPlotter { + private static final String DATE = "date"; + private static final String DAY = "day"; + final static String INTAKES_HOSP = "intakesHosp"; + final static String INTAKES_ICU = "intakesIcu"; + final static String OCCUPANCY_HOSP = "occupancyHosp"; + final static String OCCUPANCY_ICU = "occupancyIcu"; + + private final static double populationCntOfficialNrw = 17_930_000; + private final static double populationCntOfficialKoelln = 919_936; + + + + + static void aggregateAndProducePlots(Path output, List pathList, String outputAppendix, LocalDate startDate, String strainToPlot) throws IOException { + + + // read hospitalization tsv for all seeds and aggregate them! + // NOTE: all other parameters should be the same, otherwise the results will be useless! + Int2DoubleSortedMap intakeHosp = new Int2DoubleAVLTreeMap(); + Int2DoubleSortedMap intakeIcu = new Int2DoubleAVLTreeMap(); + Int2DoubleSortedMap occupancyHosp = new Int2DoubleAVLTreeMap(); + Int2DoubleSortedMap occupancyIcu = new Int2DoubleAVLTreeMap(); + +// Int2DoubleSortedMap hospNoImmunity = new Int2DoubleAVLTreeMap(); +// Int2DoubleSortedMap hospBaseImmunity = new Int2DoubleAVLTreeMap(); +// Int2DoubleSortedMap hospBoosted = new Int2DoubleAVLTreeMap(); +// +// Int2DoubleSortedMap incNoImmunity = new Int2DoubleAVLTreeMap(); +// Int2DoubleSortedMap incBaseImmunity = new Int2DoubleAVLTreeMap(); +// Int2DoubleSortedMap incBoosted = new Int2DoubleAVLTreeMap(); + + + + + for (Path path : pathList) { + + String id = AnalysisCommand.getScenarioPrefix(path); + + final Path tsvPath = path.resolve(id + "post.hospital" + outputAppendix + ".tsv"); + + try (CSVParser parser = new CSVParser(Files.newBufferedReader(tsvPath), CSVFormat.DEFAULT.withDelimiter('\t').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + + if (!record.get("severity").equals(strainToPlot)) { + continue; + } + + int day = Integer.parseInt(record.get(DAY)); + + double n = Double.parseDouble(record.get("n")); + switch (record.get("measurement")) { + case INTAKES_HOSP: + intakeHosp.mergeDouble(day, n / pathList.size(), Double::sum); + break; + case INTAKES_ICU: + intakeIcu.mergeDouble(day, n / pathList.size(), Double::sum); + break; + case OCCUPANCY_HOSP: + occupancyHosp.mergeDouble(day, n / pathList.size(), Double::sum); + break; + case OCCUPANCY_ICU: + occupancyIcu.mergeDouble(day, n / pathList.size(), Double::sum); + break; + default: + throw new RuntimeException("not valid measurement"); + } + // intakeHosp.mergeDouble(day, Double.parseDouble(record.get(INTAKES_HOSP)) / pathList.size(), Double::sum); // intakeIcu.mergeDouble(day, Double.parseDouble(record.get(INTAKES_ICU)) / pathList.size(), Double::sum); // occupancyHosp.mergeDouble(day, Double.parseDouble(record.get(OCCUPANCY_HOSP)) / pathList.size(), Double::sum); // occupancyIcu.mergeDouble(day, Double.parseDouble(record.get(OCCUPANCY_ICU)) / pathList.size(), Double::sum); -// -//// hospNoImmunity.mergeDouble(day, Double.parseDouble(record.get("hospNoImmunity")) / pathList.size(), Double::sum); -//// hospBaseImmunity.mergeDouble(day, Double.parseDouble(record.get("hospBaseImmunity")) / pathList.size(), Double::sum); -//// hospBoosted.mergeDouble(day, Double.parseDouble(record.get("hospBoosted")) / pathList.size(), Double::sum); -//// -//// incNoImmunity.mergeDouble(day, Double.parseDouble(record.get("incNoImmunity")) / pathList.size(), Double::sum); -//// incBaseImmunity.mergeDouble(day, Double.parseDouble(record.get("incBaseImmunity")) / pathList.size(), Double::sum); -//// incBoosted.mergeDouble(day, Double.parseDouble(record.get("incBoosted")) / pathList.size(), Double::sum); -// } -// } -// } -// -// // read rki data and add to tsv -// Int2DoubleMap rkiHospIncidence = new Int2DoubleAVLTreeMap(); -// Int2DoubleMap rkiHospIncidenceAdj = new Int2DoubleAVLTreeMap(); -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../covid-sim/src/assets/rki-deutschland-hospitalization.csv")), -// CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// if (!record.get("Bundesland").equals("Nordrhein-Westfalen")) { -// continue; -// } -// LocalDate date = LocalDate.parse((record.get("Datum"))); -// int day = (int) startDate.until(date, ChronoUnit.DAYS); -// -// double incidence; -// try { -// incidence = Double.parseDouble(record.get("PS_adjustierte_7T_Hospitalisierung_Inzidenz")); -// } catch (NumberFormatException e) { -// incidence = Double.NaN; -// -// } -// -// -// rkiHospIncidence.put(day, incidence); -// -// double incidenceAdj; -// if (date.isBefore(LocalDate.of(2020, 12, 10))) { -// incidenceAdj = incidence; -// } else if (date.isBefore(LocalDate.of(2021, 1, 11))) { -// incidenceAdj = 23. / 16. * incidence; -// } else if (date.isBefore(LocalDate.of(2021, 3, 22))) { -// incidenceAdj = 8. / 6. * incidence; -// } else if (date.isBefore(LocalDate.of(2021, 5, 3))) { -// incidenceAdj = 15./11. * incidence; -// } else if (date.isBefore(LocalDate.of(2021, 11, 8))) { -// incidenceAdj = incidence; -// } else if (date.isBefore(LocalDate.of(2021, 12, 6))) { -// incidenceAdj = 16. / 13. * incidence; -// } else if (date.isBefore(LocalDate.of(2022, 1, 24))) { -// incidenceAdj = incidence; -// } else { -// incidenceAdj = 11./14 * incidence; -// } -// rkiHospIncidenceAdj.put(day, incidenceAdj); -// } -// } -// -// Int2IntMap reportedIcuCases = new Int2IntAVLTreeMap(); -// -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/Fallzahlen/DIVI/nrw-divi-processed-ICUincidence-until20220504.csv")), -// CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// String dateStr = record.get("date").split("T")[0]; -// LocalDate date = LocalDate.parse(dateStr); -// int day = (int) startDate.until(date, ChronoUnit.DAYS); -// -// int cases = 0; -// try { -// cases = Integer.parseInt(record.get("erstaufnahmen")); -// } catch (NumberFormatException ignored) { -// -// } -// -// reportedIcuCases.put(day, cases); -// } -// } -// -// -// Int2DoubleMap reportedIcuIncidence = new Int2DoubleAVLTreeMap(); -// for (Integer day : reportedIcuCases.keySet()) { -// // calculates Incidence - 7day hospitalizations per 100,000 residents -// -// double xxx = getWeeklyHospitalizations(reportedIcuCases, day) * 100_000. / populationCntOfficialNrw; -// reportedIcuIncidence.put((int) day, xxx); -// -// } -// -// Int2DoubleMap hospIncidenceKoeln = new Int2DoubleAVLTreeMap(); -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/KoelnHospIncidence.csv")), -// CSVFormat.DEFAULT.withDelimiter(';').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// String dateStr = record.get("date").split("T")[0]; -// LocalDate date = LocalDate.parse(dateStr); -// int day = (int) startDate.until(date, ChronoUnit.DAYS); -// -// double incidence; -// try { -// incidence = Double.parseDouble(record.get("7-Tage-KH-Inz-Koelln")) * 2 ; //TODO -// -// } catch (NumberFormatException e) { -// incidence = 0.; -// } -// -// hospIncidenceKoeln.put(day, incidence); -// } -// } -// -// // read rki data and add to columns -// // pink plot from covid-sim: general beds -// // https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/KoelnAllgemeinpatienten.csv (pinke Linie) -// Int2DoubleMap reportedBeds = new Int2DoubleAVLTreeMap(); -// Int2DoubleMap reportedBedsAdj = new Int2DoubleAVLTreeMap(); -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/KoelnAllgemeinpatienten.csv")), -// CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// String dateStr = record.get("date").split("T")[0]; -// LocalDate date = LocalDate.parse(dateStr); -// int day = (int) startDate.until(date, ChronoUnit.DAYS); -// -// double incidence; -// try { -// incidence = Double.parseDouble(record.get("allgemeinpatienten")) * 100_000. / populationCntOfficialKoelln; -// } catch (NumberFormatException e) { -// incidence = 0.; -// } -// -// reportedBeds.put(day, incidence); -// -// -// -// double incidenceAdj; -// if (date.isBefore(LocalDate.of(2020, 12, 10))) { -// incidenceAdj = incidence; -// } else if (date.isBefore(LocalDate.of(2021, 1, 11))) { -// incidenceAdj = 23. / 16. * incidence; -// } else if (date.isBefore(LocalDate.of(2021, 3, 22))) { -// incidenceAdj = 8. / 6. * incidence; -// } else if (date.isBefore(LocalDate.of(2021, 5, 3))) { -// incidenceAdj = 15./11. * incidence; -// } else if (date.isBefore(LocalDate.of(2021, 11, 8))) { -// incidenceAdj = incidence; -// } else if (date.isBefore(LocalDate.of(2021, 12, 6))) { -// incidenceAdj = 16. / 13. * incidence; -// } else if (date.isBefore(LocalDate.of(2022, 1, 24))) { -// incidenceAdj = incidence; -// } else { -// incidenceAdj = 11./14 * incidence; -// } -// reportedBedsAdj.put(day, incidenceAdj); -// } -// } -// -// -// //green plot from covid-sim (Ich denke, das ist die Spalte "faelle_covid_aktuell", aber ich bin nicht ganz sicher.) -// //https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/episim/original-data/Fallzahlen/DIVI/cologne-divi-processed.csv (grüne Linie) -// Int2DoubleMap reportedBedsICU = new Int2DoubleAVLTreeMap(); -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/Fallzahlen/DIVI/cologne-divi-processed.csv")), -// CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// String dateStr = record.get("date").split("T")[0]; -// LocalDate date = LocalDate.parse(dateStr); -// int day = (int) startDate.until(date, ChronoUnit.DAYS); -// -// double incidence = 0.; -// try { -// incidence = Double.parseDouble(record.get("faelle_covid_aktuell")) * 100_000. / populationCntOfficialKoelln; -// } catch (NumberFormatException ignored) { -// -// } -// -// reportedBedsICU.put(day, incidence); -// } -// } -// -// -// //https://www.dkgev.de/dkg/coronavirus-fakten-und-infos/aktuelle-bettenbelegung/ -// Int2DoubleMap reportedBedsNrw = new Int2DoubleAVLTreeMap(); -// Int2DoubleMap reportedBedsIcuNrw = new Int2DoubleAVLTreeMap(); -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("/Users/jakob/Downloads/Covid_csvgesamt(2).csv")), -// CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// -// if (!record.get("Bundesland").equals("Nordrhein-Westfalen")) { -// continue; -// } -// -// String dateStr = record.get("Datum"); -// LocalDate date = LocalDate.parse(dateStr); -// int day = (int) startDate.until(date, ChronoUnit.DAYS); -// -// double incidence = 0.; -// try { -// incidence = Double.parseDouble(record.get("Betten")) * 100_000. / populationCntOfficialNrw; -// } catch (NumberFormatException ignored) { -// } -// -// if (record.get("Bettenart").equals("Intensivbett")) { -// reportedBedsIcuNrw.put(day, incidence); -// } else if (record.get("Bettenart").equals("Normalbett")) { -// reportedBedsNrw.put(day, incidence); -// } -// -// } -// } -// -// -// // https://datawrapper.dwcdn.net/sjUZF/334/ -// Int2DoubleMap reportedBedsNrw2 = new Int2DoubleAVLTreeMap(); -// Int2DoubleMap reportedBedsIcuNrw2 = new Int2DoubleAVLTreeMap(); -// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/nrwBettBelegung.csv")), -// CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { -// -// for (CSVRecord record : parser) { -// -// -// String dateStr = record.get("Datum"); -// LocalDate date = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("d.M.yyyy")); -// int day = (int) startDate.until(date, ChronoUnit.DAYS); -// -// try { -// double incidence = Double.parseDouble(record.get("Stationär")) * 100_000. / populationCntOfficialNrw; -// reportedBedsNrw2.put(day, incidence); -// } catch (NumberFormatException ignored) { -// } -// -// try { -// double incidence = Double.parseDouble(record.get("Patienten auf der
Intensivstation")) * 100_000. / populationCntOfficialNrw; -// reportedBedsIcuNrw2.put(day, incidence); -// } catch (NumberFormatException ignored) { -// } -// -// -// } -// } -// -// -// // Produce TSV w/ aggregated data as well as all rki numbers -// try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(output.resolve("post.hospital.agg" + outputAppendix + ".tsv")), CSVFormat.DEFAULT.withDelimiter('\t'))) { -// -// printer.printRecord(DAY, DATE, INTAKES_HOSP, INTAKES_ICU, OCCUPANCY_HOSP, OCCUPANCY_ICU, "rkiIncidence", "rkiHospRate", "rkiCriticalRate"); //"hospNoImmunity", "hospBaseImmunity", "hospBoosted", "incNoImmunity", "incBaseImmunity", "incBoosted"); -// -// double maxIteration = Double.max(Double.max(intakeHosp.lastIntKey(), intakeIcu.lastIntKey()), Double.max(occupancyHosp.lastIntKey(), occupancyIcu.lastIntKey())); -// -// for (int day = 0; day <= maxIteration; day++) { -// LocalDate date = startDate.plusDays(day); -// printer.printRecord( -// day, -// date, -// intakeHosp.get(day), -// intakeIcu.get(day), -// occupancyHosp.get(day), -// occupancyIcu.get(day), -// rkiHospIncidence.get(day), -// reportedBeds.get(day), -// reportedBedsICU.get(day) -//// hospNoImmunity.get(day), -//// hospBaseImmunity.get(day), -//// hospBoosted.get(day), -//// incNoImmunity.get(day), -//// incBaseImmunity.get(day), -//// incBoosted.get(day) -// ); -// } -// } -// -// // PLOT 1: People admitted to hospital -// { -// IntColumn records = IntColumn.create("day"); -// DateColumn recordsDate = DateColumn.create("date"); -// DoubleColumn values = DoubleColumn.create("hospitalizations"); -// StringColumn groupings = StringColumn.create("scenario"); -// -// // model: intakeHosp -// for (Int2DoubleMap.Entry entry : intakeHosp.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// values.append(intakeHosp.getOrDefault(day, Double.NaN)); -// groupings.append("model: intakeHosp"); -// } -// -// // model: intakeIcu -// for (Int2DoubleMap.Entry entry : intakeIcu.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// values.append(intakeIcu.getOrDefault(day, Double.NaN)); -// groupings.append("model: intakeICU"); -// } -// -// -// for (Int2DoubleMap.Entry entry : rkiHospIncidence.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// final double value = rkiHospIncidence.getOrDefault(day, Double.NaN); -// if (Double.isNaN(value)) { -// values.appendMissing(); -// } else { -// values.append(value); -// } -// groupings.append("reported: intakeHosp (rki, nrw adjusted)"); -// } -// -// for (Int2DoubleMap.Entry entry : rkiHospIncidenceAdj.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// final double value = rkiHospIncidenceAdj.getOrDefault(day, Double.NaN); -// if (Double.isNaN(value)) { -// values.appendMissing(); -// } else { -// values.append(value); -// } -// groupings.append("reported: intakeHosp (rki, nrw adjusted, SARI)"); -// } -// -// for (Int2DoubleMap.Entry entry : hospIncidenceKoeln.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// final double value = hospIncidenceKoeln.getOrDefault(day, Double.NaN); -// if (Double.isNaN(value)) { -// values.appendMissing(); -// } else { -// values.append(value); -// } -// groupings.append("reported: intakeHosp (köln)"); -// } -// -// for (Int2DoubleMap.Entry entry : reportedIcuIncidence.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// final double value = reportedIcuIncidence.getOrDefault(day, Double.NaN); -// if (Double.isNaN(value)) { -// values.appendMissing(); -// } else { -// values.append(value); -// } -// groupings.append("reported: intakeIcu (divi, nrw)"); -// } -// -// -// producePlot(recordsDate, values, groupings, "", "7-Tage Hospitalisierungsinzidenz", "HospIncidence" + outputAppendix + ".html"); -// } -// -// -// // PLOT 2: People taking up beds in hospital (regular and ICU) -// { -// IntColumn records = IntColumn.create("day"); -// DateColumn recordsDate = DateColumn.create("date"); -// DoubleColumn values = DoubleColumn.create("hospitalizations"); -// StringColumn groupings = StringColumn.create("scenario"); -// -// -// for (Int2DoubleMap.Entry entry : occupancyHosp.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(occupancyHosp.get(day)); -// groupings.append("generalBeds"); -// } -// -// for (Int2DoubleMap.Entry entry : occupancyIcu.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(occupancyIcu.get(day)); -// groupings.append("ICUBeds"); -// } -// -// -// for (Int2DoubleMap.Entry entry : reportedBeds.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(entry.getDoubleValue()); -// groupings.append("Reported: General Beds"); -// -// } -// -// for (Int2DoubleMap.Entry entry : reportedBedsAdj.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(entry.getDoubleValue()); -// groupings.append("Reported: General Beds (SARI)"); -// } -// -// -// for (Int2DoubleMap.Entry entry : reportedBedsICU.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(entry.getDoubleValue()); -// groupings.append("Reported: ICU Beds"); -// -// } -// -// -// for (Int2DoubleMap.Entry entry : reportedBedsNrw.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(entry.getDoubleValue()); -// groupings.append("Reported: General Beds (NRW)"); -// -// } -// -// -// for (Int2DoubleMap.Entry entry : reportedBedsIcuNrw.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(entry.getDoubleValue()); -// groupings.append("Reported: ICU Beds (NRW)"); -// -// } -// -// for (Int2DoubleMap.Entry entry : reportedBedsNrw2.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(entry.getDoubleValue()); -// groupings.append("Reported: General Beds (NRW2)"); -// -// } -// -// for (Int2DoubleMap.Entry entry : reportedBedsIcuNrw2.int2DoubleEntrySet()) { -// int day = entry.getIntKey(); -// records.append(day); -// recordsDate.append(startDate.plusDays(day)); -// -// values.append(entry.getDoubleValue()); -// groupings.append("Reported: ICU Beds (NRW2)"); -// -// } -// -// -// -// // Make plot -// producePlot(recordsDate, values, groupings, "Filled Beds", "Beds Filled / 100k Population", "FilledBeds" + outputAppendix + ".html"); -// } -// -// -// } -// -// private static void producePlot(DateColumn records, DoubleColumn values, StringColumn groupings, String title, String yAxisTitle, String filename) { -// // Make plot -// Table table = Table.create(title); -// table.addColumns(records); -// table.addColumns(values); -// table.addColumns(groupings); -// -// TableSliceGroup tables = table.splitOn(table.categoricalColumn("scenario")); -// -// Axis xAxis = Axis.builder().title("Datum").build(); -// Axis yAxis = Axis.builder().range(0., 20.) -// // .type(Axis.Type.LOG) -// .title(yAxisTitle).build(); -// -// Layout layout = Layout.builder(title).xAxis(xAxis).yAxis(yAxis).showLegend(true).height(500).width(1000).build(); -// -// ScatterTrace[] traces = new ScatterTrace[tables.size()]; -// for (int i = 0; i < tables.size(); i++) { -// List tableList = tables.asTableList(); -// traces[i] = ScatterTrace.builder(tableList.get(i).dateColumn("date"), tableList.get(i).numberColumn("hospitalizations")) -// .showLegend(true) -// .name(tableList.get(i).name()) -// .mode(ScatterTrace.Mode.LINE) -// .build(); -// } -// var figure = new Figure(layout, traces); -// -// try (Writer writer = new OutputStreamWriter(new FileOutputStream(output.resolve(filename).toString()), StandardCharsets.UTF_8)) { -// writer.write(Page.pageBuilder(figure, "target").build().asJavascript()); -// } catch (IOException e) { -// throw new UncheckedIOException(e); -// } -// } -// -//} + +// hospNoImmunity.mergeDouble(day, Double.parseDouble(record.get("hospNoImmunity")) / pathList.size(), Double::sum); +// hospBaseImmunity.mergeDouble(day, Double.parseDouble(record.get("hospBaseImmunity")) / pathList.size(), Double::sum); +// hospBoosted.mergeDouble(day, Double.parseDouble(record.get("hospBoosted")) / pathList.size(), Double::sum); +// +// incNoImmunity.mergeDouble(day, Double.parseDouble(record.get("incNoImmunity")) / pathList.size(), Double::sum); +// incBaseImmunity.mergeDouble(day, Double.parseDouble(record.get("incBaseImmunity")) / pathList.size(), Double::sum); +// incBoosted.mergeDouble(day, Double.parseDouble(record.get("incBoosted")) / pathList.size(), Double::sum); + } + } + } + + // read rki data and add to tsv + Int2DoubleMap rkiHospIncidence = new Int2DoubleAVLTreeMap(); + Int2DoubleMap rkiHospIncidenceAdj = new Int2DoubleAVLTreeMap(); + try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../covid-sim/src/assets/rki-deutschland-hospitalization.csv")), + CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + if (!record.get("Bundesland").equals("Nordrhein-Westfalen")) { + continue; + } + LocalDate date = LocalDate.parse((record.get("Datum"))); + int day = (int) startDate.until(date, ChronoUnit.DAYS); + + double incidence; + try { + incidence = Double.parseDouble(record.get("PS_adjustierte_7T_Hospitalisierung_Inzidenz")); + } catch (NumberFormatException e) { + incidence = Double.NaN; + + } + + + rkiHospIncidence.put(day, incidence); + + double incidenceAdj; + if (date.isBefore(LocalDate.of(2020, 12, 10))) { + incidenceAdj = incidence; + } else if (date.isBefore(LocalDate.of(2021, 1, 11))) { + incidenceAdj = 23. / 16. * incidence; + } else if (date.isBefore(LocalDate.of(2021, 3, 22))) { + incidenceAdj = 8. / 6. * incidence; + } else if (date.isBefore(LocalDate.of(2021, 5, 3))) { + incidenceAdj = 15./11. * incidence; + } else if (date.isBefore(LocalDate.of(2021, 11, 8))) { + incidenceAdj = incidence; + } else if (date.isBefore(LocalDate.of(2021, 12, 6))) { + incidenceAdj = 16. / 13. * incidence; + } else if (date.isBefore(LocalDate.of(2022, 1, 24))) { + incidenceAdj = incidence; + } else { + incidenceAdj = 11./14 * incidence; + } + rkiHospIncidenceAdj.put(day, incidenceAdj); + } + } + + Int2IntMap reportedIcuCases = new Int2IntAVLTreeMap(); + + try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/Fallzahlen/DIVI/nrw-divi-processed-ICUincidence-until20220504.csv")), + CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + String dateStr = record.get("date").split("T")[0]; + LocalDate date = LocalDate.parse(dateStr); + int day = (int) startDate.until(date, ChronoUnit.DAYS); + + int cases = 0; + try { + cases = Integer.parseInt(record.get("erstaufnahmen")); + } catch (NumberFormatException ignored) { + + } + + reportedIcuCases.put(day, cases); + } + } + + + Int2DoubleMap reportedIcuIncidence = new Int2DoubleAVLTreeMap(); + for (Integer day : reportedIcuCases.keySet()) { + // calculates Incidence - 7day hospitalizations per 100,000 residents + + double xxx = HospitalNumbersFromEvents.getWeeklyHospitalizations(reportedIcuCases, day) * 100_000. / populationCntOfficialNrw; + reportedIcuIncidence.put((int) day, xxx); + + } + + Int2DoubleMap hospIncidenceKoeln = new Int2DoubleAVLTreeMap(); + try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/KoelnHospIncidence.csv")), + CSVFormat.DEFAULT.withDelimiter(';').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + String dateStr = record.get("date").split("T")[0]; + LocalDate date = LocalDate.parse(dateStr); + int day = (int) startDate.until(date, ChronoUnit.DAYS); + + double incidence; + try { + incidence = Double.parseDouble(record.get("7-Tage-KH-Inz-Koelln")) * 2 ; //TODO + + } catch (NumberFormatException e) { + incidence = 0.; + } + + hospIncidenceKoeln.put(day, incidence); + } + } + + // read rki data and add to columns + // pink plot from covid-sim: general beds + // https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/KoelnAllgemeinpatienten.csv (pinke Linie) + Int2DoubleMap reportedBeds = new Int2DoubleAVLTreeMap(); + Int2DoubleMap reportedBedsAdj = new Int2DoubleAVLTreeMap(); + try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/KoelnAllgemeinpatienten.csv")), + CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + String dateStr = record.get("date").split("T")[0]; + LocalDate date = LocalDate.parse(dateStr); + int day = (int) startDate.until(date, ChronoUnit.DAYS); + + double incidence; + try { + incidence = Double.parseDouble(record.get("allgemeinpatienten")) * 100_000. / populationCntOfficialKoelln; + } catch (NumberFormatException e) { + incidence = 0.; + } + + reportedBeds.put(day, incidence); + + + + double incidenceAdj; + if (date.isBefore(LocalDate.of(2020, 12, 10))) { + incidenceAdj = incidence; + } else if (date.isBefore(LocalDate.of(2021, 1, 11))) { + incidenceAdj = 23. / 16. * incidence; + } else if (date.isBefore(LocalDate.of(2021, 3, 22))) { + incidenceAdj = 8. / 6. * incidence; + } else if (date.isBefore(LocalDate.of(2021, 5, 3))) { + incidenceAdj = 15./11. * incidence; + } else if (date.isBefore(LocalDate.of(2021, 11, 8))) { + incidenceAdj = incidence; + } else if (date.isBefore(LocalDate.of(2021, 12, 6))) { + incidenceAdj = 16. / 13. * incidence; + } else if (date.isBefore(LocalDate.of(2022, 1, 24))) { + incidenceAdj = incidence; + } else { + incidenceAdj = 11./14 * incidence; + } + reportedBedsAdj.put(day, incidenceAdj); + } + } + + + //green plot from covid-sim (Ich denke, das ist die Spalte "faelle_covid_aktuell", aber ich bin nicht ganz sicher.) + //https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/episim/original-data/Fallzahlen/DIVI/cologne-divi-processed.csv (grüne Linie) + Int2DoubleMap reportedBedsICU = new Int2DoubleAVLTreeMap(); + try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/Fallzahlen/DIVI/cologne-divi-processed.csv")), + CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + String dateStr = record.get("date").split("T")[0]; + LocalDate date = LocalDate.parse(dateStr); + int day = (int) startDate.until(date, ChronoUnit.DAYS); + + double incidence = 0.; + try { + incidence = Double.parseDouble(record.get("faelle_covid_aktuell")) * 100_000. / populationCntOfficialKoelln; + } catch (NumberFormatException ignored) { + + } + + reportedBedsICU.put(day, incidence); + } + } + + + //https://www.dkgev.de/dkg/coronavirus-fakten-und-infos/aktuelle-bettenbelegung/ + Int2DoubleMap reportedBedsNrw = new Int2DoubleAVLTreeMap(); + Int2DoubleMap reportedBedsIcuNrw = new Int2DoubleAVLTreeMap(); + try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("/Users/jakob/Downloads/Covid_csvgesamt(2).csv")), + CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + + if (!record.get("Bundesland").equals("Nordrhein-Westfalen")) { + continue; + } + + String dateStr = record.get("Datum"); + LocalDate date = LocalDate.parse(dateStr); + int day = (int) startDate.until(date, ChronoUnit.DAYS); + + double incidence = 0.; + try { + incidence = Double.parseDouble(record.get("Betten")) * 100_000. / populationCntOfficialNrw; + } catch (NumberFormatException ignored) { + } + + if (record.get("Bettenart").equals("Intensivbett")) { + reportedBedsIcuNrw.put(day, incidence); + } else if (record.get("Bettenart").equals("Normalbett")) { + reportedBedsNrw.put(day, incidence); + } + + } + } + + + // https://datawrapper.dwcdn.net/sjUZF/334/ + Int2DoubleMap reportedBedsNrw2 = new Int2DoubleAVLTreeMap(); + Int2DoubleMap reportedBedsIcuNrw2 = new Int2DoubleAVLTreeMap(); + try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("../public-svn/matsim/scenarios/countries/de/episim/original-data/hospital-cases/cologne/nrwBettBelegung.csv")), + CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { + + for (CSVRecord record : parser) { + + + String dateStr = record.get("Datum"); + LocalDate date = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("d.M.yyyy")); + int day = (int) startDate.until(date, ChronoUnit.DAYS); + + try { + double incidence = Double.parseDouble(record.get("Stationär")) * 100_000. / populationCntOfficialNrw; + reportedBedsNrw2.put(day, incidence); + } catch (NumberFormatException ignored) { + } + + try { + double incidence = Double.parseDouble(record.get("Patienten auf der
Intensivstation")) * 100_000. / populationCntOfficialNrw; + reportedBedsIcuNrw2.put(day, incidence); + } catch (NumberFormatException ignored) { + } + + + } + } + + + // Produce TSV w/ aggregated data as well as all rki numbers + try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(output.resolve("post.hospital.agg" + outputAppendix + ".tsv")), CSVFormat.DEFAULT.withDelimiter('\t'))) { + + printer.printRecord(DAY, DATE, INTAKES_HOSP, INTAKES_ICU, OCCUPANCY_HOSP, OCCUPANCY_ICU, "rkiIncidence", "rkiHospRate", "rkiCriticalRate"); //"hospNoImmunity", "hospBaseImmunity", "hospBoosted", "incNoImmunity", "incBaseImmunity", "incBoosted"); + + double maxIteration = Double.max(Double.max(intakeHosp.lastIntKey(), intakeIcu.lastIntKey()), Double.max(occupancyHosp.lastIntKey(), occupancyIcu.lastIntKey())); + + for (int day = 0; day <= maxIteration; day++) { + LocalDate date = startDate.plusDays(day); + printer.printRecord( + day, + date, + intakeHosp.get(day), + intakeIcu.get(day), + occupancyHosp.get(day), + occupancyIcu.get(day), + rkiHospIncidence.get(day), + reportedBeds.get(day), + reportedBedsICU.get(day) +// hospNoImmunity.get(day), +// hospBaseImmunity.get(day), +// hospBoosted.get(day), +// incNoImmunity.get(day), +// incBaseImmunity.get(day), +// incBoosted.get(day) + ); + } + } + + // PLOT 1: People admitted to hospital + { + IntColumn records = IntColumn.create("day"); + DateColumn recordsDate = DateColumn.create("date"); + DoubleColumn values = DoubleColumn.create("hospitalizations"); + StringColumn groupings = StringColumn.create("scenario"); + + // model: intakeHosp + for (Int2DoubleMap.Entry entry : intakeHosp.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + values.append(intakeHosp.getOrDefault(day, Double.NaN)); + groupings.append("model: intakeHosp"); + } + + // model: intakeIcu + for (Int2DoubleMap.Entry entry : intakeIcu.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + values.append(intakeIcu.getOrDefault(day, Double.NaN)); + groupings.append("model: intakeICU"); + } + + + for (Int2DoubleMap.Entry entry : rkiHospIncidence.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + final double value = rkiHospIncidence.getOrDefault(day, Double.NaN); + if (Double.isNaN(value)) { + values.appendMissing(); + } else { + values.append(value); + } + groupings.append("reported: intakeHosp (rki, nrw adjusted)"); + } + + for (Int2DoubleMap.Entry entry : rkiHospIncidenceAdj.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + final double value = rkiHospIncidenceAdj.getOrDefault(day, Double.NaN); + if (Double.isNaN(value)) { + values.appendMissing(); + } else { + values.append(value); + } + groupings.append("reported: intakeHosp (rki, nrw adjusted, SARI)"); + } + + for (Int2DoubleMap.Entry entry : hospIncidenceKoeln.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + final double value = hospIncidenceKoeln.getOrDefault(day, Double.NaN); + if (Double.isNaN(value)) { + values.appendMissing(); + } else { + values.append(value); + } + groupings.append("reported: intakeHosp (köln)"); + } + + for (Int2DoubleMap.Entry entry : reportedIcuIncidence.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + final double value = reportedIcuIncidence.getOrDefault(day, Double.NaN); + if (Double.isNaN(value)) { + values.appendMissing(); + } else { + values.append(value); + } + groupings.append("reported: intakeIcu (divi, nrw)"); + } + + + producePlot(recordsDate, values, groupings, "", "7-Tage Hospitalisierungsinzidenz", "HospIncidence" + outputAppendix + ".html", output); + } + + + // PLOT 2: People taking up beds in hospital (regular and ICU) + { + IntColumn records = IntColumn.create("day"); + DateColumn recordsDate = DateColumn.create("date"); + DoubleColumn values = DoubleColumn.create("hospitalizations"); + StringColumn groupings = StringColumn.create("scenario"); + + + for (Int2DoubleMap.Entry entry : occupancyHosp.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(occupancyHosp.get(day)); + groupings.append("generalBeds"); + } + + for (Int2DoubleMap.Entry entry : occupancyIcu.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(occupancyIcu.get(day)); + groupings.append("ICUBeds"); + } + + + for (Int2DoubleMap.Entry entry : reportedBeds.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(entry.getDoubleValue()); + groupings.append("Reported: General Beds"); + + } + + for (Int2DoubleMap.Entry entry : reportedBedsAdj.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(entry.getDoubleValue()); + groupings.append("Reported: General Beds (SARI)"); + } + + + for (Int2DoubleMap.Entry entry : reportedBedsICU.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(entry.getDoubleValue()); + groupings.append("Reported: ICU Beds"); + + } + + + for (Int2DoubleMap.Entry entry : reportedBedsNrw.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(entry.getDoubleValue()); + groupings.append("Reported: General Beds (NRW)"); + + } + + + for (Int2DoubleMap.Entry entry : reportedBedsIcuNrw.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(entry.getDoubleValue()); + groupings.append("Reported: ICU Beds (NRW)"); + + } + + for (Int2DoubleMap.Entry entry : reportedBedsNrw2.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(entry.getDoubleValue()); + groupings.append("Reported: General Beds (NRW2)"); + + } + + for (Int2DoubleMap.Entry entry : reportedBedsIcuNrw2.int2DoubleEntrySet()) { + int day = entry.getIntKey(); + records.append(day); + recordsDate.append(startDate.plusDays(day)); + + values.append(entry.getDoubleValue()); + groupings.append("Reported: ICU Beds (NRW2)"); + + } + + + + // Make plot + producePlot(recordsDate, values, groupings, "Filled Beds", "Beds Filled / 100k Population", "FilledBeds" + outputAppendix + ".html", output); + } + + + } + + private static void producePlot(DateColumn records, DoubleColumn values, StringColumn groupings, String title, String yAxisTitle, String filename, Path output) { + // Make plot + Table table = Table.create(title); + table.addColumns(records); + table.addColumns(values); + table.addColumns(groupings); + + TableSliceGroup tables = table.splitOn(table.categoricalColumn("scenario")); + + Axis xAxis = Axis.builder().title("Datum").build(); + Axis yAxis = Axis.builder().range(0., 20.) + // .type(Axis.Type.LOG) + .title(yAxisTitle).build(); + + Layout layout = Layout.builder(title).xAxis(xAxis).yAxis(yAxis).showLegend(true).height(500).width(1000).build(); + + ScatterTrace[] traces = new ScatterTrace[tables.size()]; + for (int i = 0; i < tables.size(); i++) { + List
tableList = tables.asTableList(); + traces[i] = ScatterTrace.builder(tableList.get(i).dateColumn("date"), tableList.get(i).numberColumn("hospitalizations")) + .showLegend(true) + .name(tableList.get(i).name()) + .mode(ScatterTrace.Mode.LINE) + .build(); + } + var figure = new Figure(layout, traces); + + try (Writer writer = new OutputStreamWriter(new FileOutputStream(output.resolve(filename).toString()), StandardCharsets.UTF_8)) { + writer.write(Page.pageBuilder(figure, "target").build().asJavascript()); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + +} From 8fa3d1283bc38ae10586965902a928986e5b2cdb Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Tue, 2 Aug 2022 09:50:46 +0200 Subject: [PATCH 016/128] adding aggregation to post processing --- src/main/python/analysis/utils.py | 12 ++++++++++-- src/main/resources/collect.sh | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/python/analysis/utils.py b/src/main/python/analysis/utils.py index 9aa067e45..8872eb6c1 100644 --- a/src/main/python/analysis/utils.py +++ b/src/main/python/analysis/utils.py @@ -310,8 +310,16 @@ def calc_r_reduction(base_case, base_variables, df, group_by=None): return result + if __name__ == "__main__": - - aggregate_batch_run("../../../../output/summaries.zip") + + import argparse + + parser = argparse.ArgumentParser(description="Aggregate batch run over multiple seeds") + parser.add_argument("file", type=str, nargs=1, help="Path to summaries zip", default="../../../../output/summaries.zip") + + args = parser.parse_args() + + aggregate_batch_run(args.file[0]) diff --git a/src/main/resources/collect.sh b/src/main/resources/collect.sh index b81a0f413..dbcb60ddd 100755 --- a/src/main/resources/collect.sh +++ b/src/main/resources/collect.sh @@ -79,4 +79,15 @@ zip "$cwd/summaries.zip" -r ./* cd "$cwd" || exit -rm -r tmp \ No newline at end of file +rm -r tmp + +if grep -q seed metadata.yaml; then + + echo "Aggregating seeds..." + + module load anaconda3/2019.10 + source "$EPISIM_INPUT/../env/bin/activate" + + python "$EPISIM_INPUT/../env/utils.py" "$cwd/summaries.zip" + +fi \ No newline at end of file From 8233229da3f49a0cc41037f42250de3eb72b7239 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 2 Aug 2022 10:18:55 +0200 Subject: [PATCH 017/128] run 2022-08-01/2-calibration --- .../java/org/matsim/run/batch/CologneJR.java | 373 +++++++++++------- 1 file changed, 241 insertions(+), 132 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index a041f1c0f..c645c7005 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -12,6 +12,7 @@ import org.matsim.episim.*; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; +import org.matsim.episim.model.testing.TestType; import org.matsim.episim.model.vaccination.VaccinationModel; import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; import org.matsim.episim.policy.FixedPolicy; @@ -39,53 +40,54 @@ public Module getBindings(int id, @Nullable Params params) { @Override protected void configure() { - Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); - - set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); +// Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); +// +// set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); - double mutEscBa5 = 1.; - double mutEscStrainA = 1.; + double mutEscBa5 = 3.0; + double mutEscStrainA = 0.; - LocalDate start = null; - VaccinationType vaccinationType = null; +// LocalDate start = null; +// VaccinationType vaccinationType = null; - Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); - compliance.put(60, 0.0); - compliance.put(18, 0.0); - compliance.put(12, 0.0); - compliance.put(0, 0.0); +// Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); +// compliance.put(60, 0.0); +// compliance.put(18, 0.0); +// compliance.put(12, 0.0); +// compliance.put(0, 0.0); if (params != null) { - mutEscBa5 = 3.0; - mutEscStrainA = params.strAEsc; - - start = LocalDate.parse(params.resDate); - vaccinationType = VaccinationType.valueOf(params.vacType); - + mutEscBa5 = params.ba5Esc; - if (params.vacCamp.equals("age")) { - compliance.put(60, 0.85); // 60+ - compliance.put(18, 0.55); // 18-59 - compliance.put(12, 0.20); // 12-17 - compliance.put(0, 0.0); // 0 - 11 - } - else if (params.vacCamp.equals("eu")) { - compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) - compliance.put(18, 0.); - compliance.put(12, 0.); - compliance.put(0, 0.); - } - else if (params.vacCamp.equals("off")) { - - } else { - throw new RuntimeException("Not a valid option for vaccinationCampaignType"); - } + mutEscStrainA = params.strAEsc; +// +// start = LocalDate.parse(params.resDate); +// vaccinationType = VaccinationType.valueOf(params.vacType); +// +// +// if (params.vacCamp.equals("age")) { +// compliance.put(60, 0.85); // 60+ +// compliance.put(18, 0.55); // 18-59 +// compliance.put(12, 0.20); // 12-17 +// compliance.put(0, 0.0); // 0 - 11 +// } +// else if (params.vacCamp.equals("eu")) { +// compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) +// compliance.put(18, 0.); +// compliance.put(12, 0.); +// compliance.put(0, 0.); +// } +// else if (params.vacCamp.equals("off")) { +// +// } else { +// throw new RuntimeException("Not a valid option for vaccinationCampaignType"); +// } } - - bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); +// +// bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); //initial antibodies Map> initialAntibodies = new HashMap<>(); @@ -308,7 +310,8 @@ public Collection postProcessing() { new VaccinationEffectiveness().withArgs(), new RValuesFromEvents().withArgs(), new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new HospitalNumbersFromEvents().withArgs() + new HospitalNumbersFromEvents().withArgs(), + new SecondaryAttackRateFromEvents().withArgs() ); } @@ -334,66 +337,20 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * params.thFactor); - //restrictions - FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - // Restrictions starting on December 1, 2022 - LocalDate restrictionDate = LocalDate.parse(params.resDate); - //school - if(params.edu.equals("close")) { - if (params.resDate.equals("2022-12-01")) { - builder.restrict(restrictionDate, 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - } - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - //university - builder.restrict(restrictionDate, 0.2, "educ_higher"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_higher"); - } else if (params.edu.equals("maskVent")) { - builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.N95, 0.25, - FaceMask.SURGICAL, 0.25)), - "educ_primary", "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); + //--------------------------------------- + // S T R A I N S + //--------------------------------------- - } else if (params.edu.equals("normal")) { - - } else { - throw new RuntimeException("param value doesn't exist"); - } - - //pt: masks - if (Boolean.parseBoolean(params.maskPt)) { - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "pt"); - - } - - //shopping: masks - if (Boolean.parseBoolean(params.maskShop)) { - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "shop_daily", "shop_other", "errands"); - } - - //work - builder.restrict(restrictionDate, 0.78 * params.work, "work"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.work, "work"); - - //leisure - builder.restrict(restrictionDate, 0.88 * params.leis, "leisure"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.leis, "leisure"); - - - episimConfig.setPolicy(builder.build()); + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - //mutations - VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); - //configure new strains //BA5 - double ba5Inf = 0.9; + double ba5Inf = 1.0; double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); @@ -411,12 +368,128 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); } - //Configure Disease Import + // remove age-based susceptibility of strains starting with DELTA + + if (!Boolean.parseBoolean(params.ageSusc)) { + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : List.of(VirusStrain.DELTA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A)) { + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } + } + + // increase infectivity of alpha + virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * params.alphaTheta); + + virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); + double ba1Inf = params.ba1Inf; // 2.0,2.1,2.2 + double ba2Inf = 1.7; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); + + + + + + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + Map infPerDayAlpha = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.ALPHA, new TreeMap<>())); + + + // reconfig disease import of alpha + LocalDate startDateAlpha = LocalDate.parse(params.alphaDate); + + for (int i = 0; i < 7; i++) { + infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); + } + + + infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); + + episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); + configureFutureDiseaseImport(params, episimConfig); + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + //school + if(params.schoolUpdate.equals("yes")) { + // school closed completely until 21.2.2022 + builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); + builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + } else if (params.schoolUpdate.equals("no")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + if (params.schoolTest.equals("later")) { + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); +// TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); +// Map> testingRateForActivitiesPCR = pcrTest.getTestingRateForActivities(); + + + for (LocalDate date = LocalDate.parse("2021-03-19"); date.isBefore(LocalDate.parse("2021-04-25")); date = date.plusDays(1)) { + + testingRateForActivitiesRapid.get("educ_kiga").put(date, 0.); + testingRateForActivitiesRapid.get("educ_primary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_secondary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_tertiary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_other").put(date, 0.); + + } + + testingRateForActivitiesRapid.get("educ_kiga").put(LocalDate.parse("2021-09-20"), 0.); + testingRateForActivitiesRapid.get("educ_primary").put(LocalDate.parse("2021-09-20"), 0.); + +// testingRateForActivitiesPCR.get("educ_primary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_secondary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); + + } else if (params.schoolTest.equals("base")) { + + }else { + throw new RuntimeException("param value doesn't exist"); + } + + + // masks + //pt: masks + if (params.maskType.equals("45to45")) { + for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { + builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); + + } + } else if (params.maskType.equals("base")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } - //vaccinations + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + // vaccination VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); vaccinationConfig.setUseIgA(true); vaccinationConfig.setTimePeriodIgA(730.); @@ -439,20 +512,29 @@ public Config prepareConfig(int id, Params params) { episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * params.schoolCi); - if(DEBUG_MODE) { -// UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); -// UtilsJR.produceMaskPlot(episimConfig.getPolicy()); + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } - return config; + return config; } private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); // add initial impulses for strains + //BA.1 + LocalDate ba1Date = LocalDate.parse(params.ba1Date); + for (int i = 0; i < 7; i++) { + infPerDayBa1.put(ba1Date.plusDays(i), 4); + } + infPerDayBa2.put(ba1Date.plusDays(7), 1); + + //BA.2 LocalDate ba2Date = LocalDate.parse("2021-12-18"); for (int i = 0; i < 7; i++) { @@ -516,9 +598,8 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi infPerDayBa5.put(date.plusDays(1), 1); } - - // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); @@ -527,91 +608,119 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } } - public static final class Params { + // general @GenerateSeeds(5) public long seed; - @Parameter({1., 2., 3.}) + + @Parameter({0.9}) + public double deltaTheta; + + @Parameter({1.7,1.9,2.1}) + public double ba1Inf; + + @StringParameter({"2021-11-20", "2021-11-27", "2021-12-04"}) + public String ba1Date; + + @Parameter({2.8, 2.9, 3.0}) + public double ba5Esc; + + @Parameter({1.3}) // @Parameter({0.0}) public double actCorrection; - - @Parameter({1.0, 1.2, 1.4}) + @Parameter({1.2}) // @Parameter({1.0}) public double thFactor; // @Parameter({1.}) - @Parameter({0.25, 0.5, 0.75}) + @Parameter({0.75}) public double schoolCi; - @Parameter({0.5, 0.75, 1.0}) + @Parameter({0.75}) // @Parameter({1.}) public double workCi; - - @Parameter({0.2, 0.3, 0.4}) + @Parameter({0.4}) // @Parameter({ 1.}) public double leisureCi; + @StringParameter({"yes"}) + public String schoolUpdate; + + @StringParameter({"45to45"}) + public String maskType; + + @StringParameter({"later"}) + public String schoolTest; + + @StringParameter({"false"}) + public String ageSusc; +// @Parameter({0.90, .95, 1.}) +// public double deltaTheta; + @StringParameter({"2021-01-15"}) + public String alphaDate; - //TODO VARY -// @Parameter({0.0,6.}) // 0.0 = strainA is off - @Parameter({0.0}) // 0.0 = strainA is off + @Parameter({1.4}) + public double alphaTheta; + + @StringParameter({"2022-11-01"}) + public String strADate; + + @Parameter({0.0}) public double strAEsc; // General Restriction date // @StringParameter({"2022-07-01","2022-12-01"}) - @StringParameter({"2022-12-01"}) - public String resDate; - - +// @StringParameter({"2022-12-01"}) +// public String resDate; +// +// // @StringParameter({"off", "age"}) - @StringParameter({"off"}) - String vacCamp; - +// @StringParameter({"off"}) +// String vacCamp; +// // other restrictions // schools & university // close: rf reduced // maskVent: ciCorrection reduced & surgical mask for most // normal: no changes made // @StringParameter({"close", "maskVent", "normal"}) - @StringParameter({ "normal"}) - String edu; +// @StringParameter({ "normal"}) +// String edu; // shopping: mask // @StringParameter({"true", "false"}) - @StringParameter({"false"}) - String maskShop; +// @StringParameter({"false"}) +// String maskShop; // pt: mask // @StringParameter({"true", "false"}) - @StringParameter({"false"}) - String maskPt; +// @StringParameter({"false"}) +// String maskPt; // work: // @Parameter({0.5, 1.0}) - @Parameter({1.0}) - double work; +// @Parameter({1.0}) +// double work; // leisure // @Parameter({0.25, 0.5, 0.75, 1.0}) - @Parameter({1.0}) - double leis; +// @Parameter({1.0}) +// double leis; // vaccination campaign - @StringParameter({"omicronUpdate"}) - public String vacType; +// @StringParameter({"omicronUpdate"}) +// public String vacType; - @StringParameter({"2022-04-25"}) - public String unResDate; +// @StringParameter({"2022-04-25"}) +// public String unResDate; // StrainA - @StringParameter({"2022-11-01"}) - public String strADate; // @StringParameter({"true"}) // public String sebaUp; From 0cfb799d68a7be5009b8a23163292f384f4b4450 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 2 Aug 2022 10:34:59 +0200 Subject: [PATCH 018/128] run 2022-08-01/3-meausre --- .../matsim/run/batch/CologneBMBF20220805.java | 787 ++++++++++++++++++ .../java/org/matsim/run/batch/CologneJR.java | 2 +- 2 files changed, 788 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF20220805.java diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java new file mode 100644 index 000000000..dfb8310c0 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -0,0 +1,787 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.testing.TestType; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF20220805 implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + + double mutEscBa5 = 3.0; + double mutEscStrainA = 0.; + + LocalDate start = null; + VaccinationType vaccinationType = null; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + + + if (params != null) { + mutEscBa5 = params.ba5Esc; + + mutEscStrainA = params.strAEsc; + + start = LocalDate.parse(params.resDate); + vaccinationType = VaccinationType.valueOf(params.vacType); + + + if (params.vacCamp.equals("age")) { + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + } + else if (params.vacCamp.equals("eu")) { + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + } + else if (params.vacCamp.equals("off")) { + + } else { + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } +// + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscBa5,mutEscStrainA); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscBa5, double mutEscStrainA) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + + //DELTA + double mRNADelta = 10.9; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + + //BA.1 + double mRNABA1 = 1.9; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / 1.4 / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.omicronUpdate) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + + +// System.out.print("immunityGiver"); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// if (immunityFrom == VirusStrain.OMICRON_BA1) { +// System.out.print( "," + "BA.1"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { +// System.out.print( "," + "BA.2"); +// } else { +// System.out.print( "," + immunityFrom); +// } +// } +// +// +// for (ImmunityEvent immunityGiver : VaccinationType.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// for (ImmunityEvent immunityGiver : VirusStrain.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// +// System.out.println(); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new HospitalNumbersFromEvents().withArgs(), + new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * params.thFactor); + + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + +// virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); + + //BA5 + double ba5Inf = 1.0; + double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + + +// STRAIN_A + double strAInf = 1.0; + if (params.strAEsc != 0.) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf * strAInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); + } + + // remove age-based susceptibility of strains starting with DELTA + + if (!Boolean.parseBoolean(params.ageSusc)) { + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : List.of(VirusStrain.DELTA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A)) { + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } + } + + // increase infectivity of alpha + virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * params.alphaTheta); + + virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); + double ba1Inf = params.ba1Inf; // 2.0,2.1,2.2 + double ba2Inf = 1.7; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); + + + + + + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + Map infPerDayAlpha = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.ALPHA, new TreeMap<>())); + + + // reconfig disease import of alpha + LocalDate startDateAlpha = LocalDate.parse(params.alphaDate); + + for (int i = 0; i < 7; i++) { + infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); + } + + + infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); + + episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); + + + configureFutureDiseaseImport(params, episimConfig); + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + //school + if(params.schoolUpdate.equals("yes")) { + // school closed completely until 21.2.2022 + builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); + builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + } else if (params.schoolUpdate.equals("no")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + if (params.schoolTest.equals("later")) { + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); +// TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); +// Map> testingRateForActivitiesPCR = pcrTest.getTestingRateForActivities(); + + + for (LocalDate date = LocalDate.parse("2021-03-19"); date.isBefore(LocalDate.parse("2021-04-25")); date = date.plusDays(1)) { + + testingRateForActivitiesRapid.get("educ_kiga").put(date, 0.); + testingRateForActivitiesRapid.get("educ_primary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_secondary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_tertiary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_other").put(date, 0.); + + } + + testingRateForActivitiesRapid.get("educ_kiga").put(LocalDate.parse("2021-09-20"), 0.); + testingRateForActivitiesRapid.get("educ_primary").put(LocalDate.parse("2021-09-20"), 0.); + +// testingRateForActivitiesPCR.get("educ_primary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_secondary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); + + } else if (params.schoolTest.equals("base")) { + + }else { + throw new RuntimeException("param value doesn't exist"); + } + + + // masks + //pt: masks + if (params.maskType.equals("45to45")) { + for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { + builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); + + } + } else if (params.maskType.equals("base")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + // Restrictions starting on December 1, 2022 + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + //school + if(params.edu.equals("close")) { + if (params.resDate.equals("2022-12-01")) { + builder.restrict(restrictionDate, 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + } + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + //university + builder.restrict(restrictionDate, 0.2, "educ_higher"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_higher"); + } else if (params.edu.equals("maskVent")) { + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.25, + FaceMask.SURGICAL, 0.25)), + "educ_primary", "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); + + } else if (params.edu.equals("normal")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + //pt: masks + if (Boolean.parseBoolean(params.maskPt)) { + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "pt"); + + } + + //shopping: masks + if (Boolean.parseBoolean(params.maskShop)) { + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "shop_daily", "shop_other", "errands"); + } + + //work + builder.restrict(restrictionDate, 0.78 * params.work, "work"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.work, "work"); + + //leisure + builder.restrict(restrictionDate, 0.88 * params.leis, "leisure"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.leis, "leisure"); + + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + // vaccination + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(true); + vaccinationConfig.setTimePeriodIgA(730.); + + + //modify contact intensity + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * params.workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * params.workCi); + + + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * params.leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * params.leisureCi); + + + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * params.schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * params.schoolCi); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + + // add initial impulses for strains + //BA.1 +// LocalDate ba1Date = LocalDate.parse(params.ba1Date); +// for (int i = 0; i < 7; i++) { +// infPerDayBa1.put(ba1Date.plusDays(i), 4); +// } +// infPerDayBa1.put(ba1Date.plusDays(7), 1); + + + //BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + //BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); + + //StrainA + + if (params.strAEsc != 0.) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse(params.strADate); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrA = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainA = LocalDate.parse("2022-11-18"); // after vaca import + + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainA) && params.strAEsc != 0) { + infPerDayStrA.put(date, ((int) cases * facStrA) == 0 ? 1 : (int) (cases * facStrA)); + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + + if( params.strAEsc!=0.) { + infPerDayBa5.put(dateStrainA.plusDays(1), 1); + infPerDayStrA.put(date.plusDays(1), 1); + } else { + infPerDayBa5.put(date.plusDays(1), 1); + } + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (params.strAEsc != 0.) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + } + + public static final class Params { + + + // general + @GenerateSeeds(5) + public long seed; + + @Parameter({0.9}) + public double deltaTheta; + + @Parameter({1.9}) + public double ba1Inf; + +// @StringParameter({"2021-11-20", "2021-11-27", "2021-12-04"}) +// public String ba1Date; + + @Parameter({2.9,}) + public double ba5Esc; + + @Parameter({1.3}) +// @Parameter({0.0}) + public double actCorrection; + + + @Parameter({1.2}) +// @Parameter({1.0}) + public double thFactor; + + // @Parameter({1.}) + @Parameter({0.75}) + public double schoolCi; + + @Parameter({0.75}) +// @Parameter({1.}) + public double workCi; + + @Parameter({0.4}) +// @Parameter({ 1.}) + public double leisureCi; + + @StringParameter({"yes"}) + public String schoolUpdate; + + @StringParameter({"45to45"}) + public String maskType; + + @StringParameter({"later"}) + public String schoolTest; + + @StringParameter({"false"}) + public String ageSusc; + +// @Parameter({0.90, .95, 1.}) +// public double deltaTheta; + + @StringParameter({"2021-01-15"}) + public String alphaDate; + + @Parameter({1.4}) + public double alphaTheta; + + @StringParameter({"2022-11-01"}) + public String strADate; + + @Parameter({6.0}) + public double strAEsc; + + + // General Restriction date +// @StringParameter({"2022-07-01","2022-12-01"}) + @StringParameter({"2022-12-01"}) + public String resDate; +// +// + @StringParameter({"off", "age"}) +// @StringParameter({"off"}) + String vacCamp; +// + // other restrictions + // schools & university // close: rf reduced // maskVent: ciCorrection reduced & surgical mask for most // normal: no changes made + @StringParameter({"close", "maskVent", "normal"}) +// @StringParameter({ "normal"}) + String edu; + + // shopping: mask + @StringParameter({"true", "false"}) +// @StringParameter({"false"}) + String maskShop; + + // pt: mask + @StringParameter({"true", "false"}) +// @StringParameter({"false"}) + String maskPt; + + // work: + @Parameter({0.5, 1.0}) +// @Parameter({1.0}) + double work; + + // leisure + @Parameter({0.5, 0.75, 1.0}) +// @Parameter({1.0}) + double leis; + + + // vaccination campaign + @StringParameter({"omicronUpdate"}) + public String vacType; + +// @StringParameter({"2022-04-25"}) +// public String unResDate; + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF20220805.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index c645c7005..6a80782ee 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -532,7 +532,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi for (int i = 0; i < 7; i++) { infPerDayBa1.put(ba1Date.plusDays(i), 4); } - infPerDayBa2.put(ba1Date.plusDays(7), 1); + infPerDayBa1.put(ba1Date.plusDays(7), 1); //BA.2 From 96d7fad19d0912a033ec567b877b6b533bcd750d Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 2 Aug 2022 14:29:16 +0200 Subject: [PATCH 019/128] updates bash scripts & add scenario hub r script --- src/main/R/Covid19ScenarioHubSubmission.R | 36 +++-- .../matsim/run/batch/CologneBMBF20220805.java | 137 ++++++++++-------- .../java/org/matsim/run/batch/CologneJR.java | 82 ++++++----- .../matsim/run/batch/CologneScenarioHub.java | 13 +- 4 files changed, 151 insertions(+), 117 deletions(-) diff --git a/src/main/R/Covid19ScenarioHubSubmission.R b/src/main/R/Covid19ScenarioHubSubmission.R index 126ee1f23..8505c634e 100644 --- a/src/main/R/Covid19ScenarioHubSubmission.R +++ b/src/main/R/Covid19ScenarioHubSubmission.R @@ -1,4 +1,3 @@ -source("/Users/jakob/git/matsim-episim/src/main/R/masterJR-utils.R", encoding = 'utf-8') library(lubridate) library(tidyverse) @@ -6,15 +5,17 @@ library(readr) - +rm(list=ls()) +source("/Users/jakob/git/matsim-episim/src/main/R/masterJR-utils.R", encoding = 'utf-8') # Global variables -directory <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-20/3-eu-noAgg/" +directory <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-27/4-eu-noAgg/" origin_date <- ymd("2022-07-24") # first day (sunday) of epiweek 30, 2022 end_date <- ymd("2023-07-29") # last day (saturday) of epiweek 30, 2023 (latest possible value) + ## read & prep infections infections_raw <- read_combine_episim_output_zipped(directory,"infections.txt.csv") @@ -22,7 +23,10 @@ infections_incidence <- convert_infections_into_incidence(directory,infections_r select(-c(infections_week,nShowingSymptomsCumulative, district, incidence)) -population <- infections_raw[1,"nSusceptible"] +population_cologne <- infections_raw[1, "nSusceptible"] + +population_germany <- 83695430 #https://www.destatis.de/EN/Themes/Society-Environment/Population/Current-Population/Tables/liste-current-population.html +scale_factor <- population_germany / population_cologne # pop germany / pop koelln infections_ready <- infections_incidence %>% filter(date >= origin_date & date <= end_date) %>% @@ -30,8 +34,7 @@ infections_ready <- infections_incidence %>% mutate(year = epiyear(date)) %>% mutate(epiweek = epiweek(date)) %>% group_by(seed,vacCamp,vacType,year,epiweek) %>% - summarise(infections = sum(infections), target_end_date = last(date) ) %>% - mutate(value = infections * 100000 / population) %>% + summarise(value = sum(infections) * scale_factor, target_end_date = last(date) ) %>% mutate(target_variable = "inc infection") %>% select(year, epiweek, target_end_date, target_variable, value, seed, vacCamp, vacType) @@ -48,11 +51,15 @@ hosp_ready <- hosp_raw %>% filter(severity == "Omicron") %>% mutate(epiweek = epiweek(date)) %>% rename("target_end_date" = date, value = n) %>% + mutate(value = value * population_cologne / 100000 * scale_factor) %>% mutate(target_variable = "inc hosp") %>% select(year, epiweek, target_end_date, target_variable, value, seed, vacCamp, vacType) # combine two dataframes and modify columns to match specs combined <- rbind(infections_ready, hosp_ready) +# combined <- infections_ready #todo revert + + seed <- unique(combined$seed) @@ -66,12 +73,23 @@ final <- combined %>% filter(vacCamp!="off") %>% scenario_id == "60plus_mRNA"~"C-2022-07-24", scenario_id == "18plus_mRNA"~"D-2022-07-24")) %>% merge(map,by ="seed") %>% - mutate(horizon = paste0(case_when(year == 2022 ~ epiweek - 29, year == 2023~ (52-29) + epiweek), " wk")) %>% + mutate(horizon = case_when(year == 2022 ~ epiweek - 29, year == 2023~ (52-29) + epiweek)) %>% mutate("origin_date" = "2022-07-24") %>% mutate("location" = "DE") %>% - select(origin_date,scenario_id,target_variable, horizon, target_end_date, location, sample, value) + mutate(value = round(value)) %>% + select(origin_date,scenario_id, horizon, target_end_date, location, sample,target_variable, value) %>% + arrange(scenario_id,sample,horizon) %>% + mutate(horizon = paste0(horizon," wk")) + +write.csv(final,"/Users/jakob/git/covid19-scenario-hub-europe/data-processed/MODUS_Covid-Episim/2022-07-24-MODUS_Covid-Episim.csv", row.names = FALSE) + + -write.csv(final, paste0(directory,"submission.csv"), row.names = FALSE) +# xxx <- read.delim("/Users/jakob/antibodies_2022-07-23.tsv",sep = "\t") +# +# yyy <- xxx %>% filter(nVaccinations == 0 & nInfections == 0) +# +# nrow(yyy)/nrow(xxx) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index dfb8310c0..552ee866e 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -45,7 +45,8 @@ protected void configure() { set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); - double mutEscBa5 = 3.0; + double mutEscBa5 = 2.9; + double mutEscStrainA = 0.; LocalDate start = null; @@ -60,7 +61,7 @@ protected void configure() { if (params != null) { - mutEscBa5 = params.ba5Esc; +// mutEscBa5 = params.ba5Esc; mutEscStrainA = params.strAEsc; @@ -290,7 +291,7 @@ private SnzCologneProductionScenario getBindings(double pHousehold, Params param return new SnzCologneProductionScenario.Builder() .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) .setSebastianUpdate(true) - .setLeisureCorrection(params == null ? 0.0 : params.actCorrection) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) .setScaleForActivityLevels(1.3) .setSuscHouseholds_pct(pHousehold) .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) @@ -336,7 +337,7 @@ public Config prepareConfig(int id, Params params) { EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * params.thFactor); + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2); @@ -370,7 +371,8 @@ public Config prepareConfig(int id, Params params) { // remove age-based susceptibility of strains starting with DELTA - if (!Boolean.parseBoolean(params.ageSusc)) { + String ageSusc = "false"; + if (!Boolean.parseBoolean(ageSusc)) { TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( 19, 1d, 20, 1d @@ -382,10 +384,11 @@ public Config prepareConfig(int id, Params params) { } // increase infectivity of alpha - virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * params.alphaTheta); + virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * 1.4); - virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); - double ba1Inf = params.ba1Inf; // 2.0,2.1,2.2 + double deltaTheta = 0.9; + virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * deltaTheta); + double ba1Inf = 1.9; // 2.0,2.1,2.2 double ba2Inf = 1.7; virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); @@ -403,7 +406,7 @@ public Config prepareConfig(int id, Params params) { // reconfig disease import of alpha - LocalDate startDateAlpha = LocalDate.parse(params.alphaDate); + LocalDate startDateAlpha = LocalDate.parse("2021-01-15"); for (int i = 0; i < 7; i++) { infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); @@ -424,19 +427,21 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); //school - if(params.schoolUpdate.equals("yes")) { + String schoolUpdate = "yes"; + if(schoolUpdate.equals("yes")) { // school closed completely until 21.2.2022 builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - } else if (params.schoolUpdate.equals("no")) { + } else if (schoolUpdate.equals("no")) { } else { throw new RuntimeException("param value doesn't exist"); } - if (params.schoolTest.equals("later")) { + String schoolTest = "later"; + if (schoolTest.equals("later")) { TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); // TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); @@ -462,7 +467,7 @@ public Config prepareConfig(int id, Params params) { testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); - } else if (params.schoolTest.equals("base")) { + } else if (schoolTest.equals("base")) { }else { throw new RuntimeException("param value doesn't exist"); @@ -471,12 +476,13 @@ public Config prepareConfig(int id, Params params) { // masks //pt: masks - if (params.maskType.equals("45to45")) { + String maskType = "45to45"; + if (maskType.equals("45to45")) { for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); } - } else if (params.maskType.equals("base")) { + } else if (maskType.equals("base")) { } else { throw new RuntimeException("param value doesn't exist"); @@ -543,20 +549,23 @@ public Config prepareConfig(int id, Params params) { //modify contact intensity - episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * params.workCi); - episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * params.workCi); + double workCi = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * params.leisureCi); - episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * params.leisureCi); + double leisureCi = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); - episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * params.schoolCi); + double schoolCi = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); if (DEBUG_MODE) { @@ -600,7 +609,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi if (params.strAEsc != 0.) { infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strADate = LocalDate.parse(params.strADate); + LocalDate strADate = LocalDate.parse("2022-11-01"); for (int i = 0; i < 7; i++) { infPerDayStrA.put(strADate.plusDays(i), 4); } @@ -662,62 +671,62 @@ public static final class Params { @GenerateSeeds(5) public long seed; - @Parameter({0.9}) - public double deltaTheta; - - @Parameter({1.9}) - public double ba1Inf; +// @Parameter({0.9}) +// public double deltaTheta; +// +// @Parameter({1.9}) +// public double ba1Inf; // @StringParameter({"2021-11-20", "2021-11-27", "2021-12-04"}) // public String ba1Date; - @Parameter({2.9,}) - public double ba5Esc; +// @Parameter({2.9,}) +// public double ba5Esc; - @Parameter({1.3}) -// @Parameter({0.0}) - public double actCorrection; +// @Parameter({1.3}) +//// @Parameter({0.0}) +// public double actCorrection; - @Parameter({1.2}) +// @Parameter({1.2}) // @Parameter({1.0}) - public double thFactor; +// public double thFactor; // @Parameter({1.}) - @Parameter({0.75}) - public double schoolCi; - - @Parameter({0.75}) -// @Parameter({1.}) - public double workCi; - - @Parameter({0.4}) -// @Parameter({ 1.}) - public double leisureCi; - - @StringParameter({"yes"}) - public String schoolUpdate; - - @StringParameter({"45to45"}) - public String maskType; +// @Parameter({0.75}) +// public double schoolCi; +// +// @Parameter({0.75}) +//// @Parameter({1.}) +// public double workCi; +// +// @Parameter({0.4}) +//// @Parameter({ 1.}) +// public double leisureCi; - @StringParameter({"later"}) - public String schoolTest; +// @StringParameter({"yes"}) +// public String schoolUpdate; +// +// @StringParameter({"45to45"}) +// public String maskType; +// +// @StringParameter({"later"}) +// public String schoolTest; - @StringParameter({"false"}) - public String ageSusc; +// @StringParameter({"false"}) +// public String ageSusc; // @Parameter({0.90, .95, 1.}) // public double deltaTheta; - @StringParameter({"2021-01-15"}) - public String alphaDate; +// @StringParameter({"2021-01-15"}) +// public String alphaDate; - @Parameter({1.4}) - public double alphaTheta; +// @Parameter({1.4}) +// public double alphaTheta; - @StringParameter({"2022-11-01"}) - public String strADate; +// @StringParameter({"2022-11-01"}) +// public String strADate; @Parameter({6.0}) public double strAEsc; diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index 6a80782ee..5b2dd762c 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -290,7 +290,7 @@ private SnzCologneProductionScenario getBindings(double pHousehold, Params param return new SnzCologneProductionScenario.Builder() .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) .setSebastianUpdate(true) - .setLeisureCorrection(params == null ? 0.0 : params.actCorrection) + .setLeisureCorrection(1.3)//params == null ? 0.0 : params.actCorrection) .setScaleForActivityLevels(1.3) .setSuscHouseholds_pct(pHousehold) .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) @@ -336,7 +336,8 @@ public Config prepareConfig(int id, Params params) { EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * params.thFactor); + double thFactor = 1.2; + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * thFactor); @@ -370,7 +371,7 @@ public Config prepareConfig(int id, Params params) { // remove age-based susceptibility of strains starting with DELTA - if (!Boolean.parseBoolean(params.ageSusc)) { + if (!Boolean.parseBoolean("false")) { TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( 19, 1d, 20, 1d @@ -424,19 +425,21 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); //school - if(params.schoolUpdate.equals("yes")) { + String schoolUpdate = "yes"; + if(schoolUpdate.equals("yes")) { // school closed completely until 21.2.2022 builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - } else if (params.schoolUpdate.equals("no")) { + } else if (schoolUpdate.equals("no")) { } else { throw new RuntimeException("param value doesn't exist"); } - if (params.schoolTest.equals("later")) { + String schoolTest = "later"; + if (schoolTest.equals("later")) { TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); // TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); @@ -462,7 +465,7 @@ public Config prepareConfig(int id, Params params) { testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); - } else if (params.schoolTest.equals("base")) { + } else if (schoolTest.equals("base")) { }else { throw new RuntimeException("param value doesn't exist"); @@ -471,12 +474,13 @@ public Config prepareConfig(int id, Params params) { // masks //pt: masks - if (params.maskType.equals("45to45")) { + String maskType = "45to45"; + if (maskType.equals("45to45")) { for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); } - } else if (params.maskType.equals("base")) { + } else if (maskType.equals("base")) { } else { throw new RuntimeException("param value doesn't exist"); @@ -496,20 +500,22 @@ public Config prepareConfig(int id, Params params) { //modify contact intensity - episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * params.workCi); - episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * params.workCi); + double workCi = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); + double leisureCi = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * params.leisureCi); - episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * params.leisureCi); - - episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * params.schoolCi); - episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * params.schoolCi); + double schoolCi = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); if (DEBUG_MODE) { @@ -627,38 +633,38 @@ public static final class Params { @Parameter({2.8, 2.9, 3.0}) public double ba5Esc; - @Parameter({1.3}) +// @Parameter({1.3}) // @Parameter({0.0}) - public double actCorrection; +// public double actCorrection; - @Parameter({1.2}) +// @Parameter({1.2}) // @Parameter({1.0}) - public double thFactor; +// public double thFactor; // @Parameter({1.}) - @Parameter({0.75}) - public double schoolCi; +// @Parameter({0.75}) +// public double schoolCi; - @Parameter({0.75}) +// @Parameter({0.75}) // @Parameter({1.}) - public double workCi; +// public double workCi; - @Parameter({0.4}) +// @Parameter({0.4}) // @Parameter({ 1.}) - public double leisureCi; +// public double leisureCi; - @StringParameter({"yes"}) - public String schoolUpdate; +// @StringParameter({"yes"}) +// public String schoolUpdate; - @StringParameter({"45to45"}) - public String maskType; +// @StringParameter({"45to45"}) +// public String maskType; - @StringParameter({"later"}) - public String schoolTest; +// @StringParameter({"later"}) +// public String schoolTest; - @StringParameter({"false"}) - public String ageSusc; +// @StringParameter({"false"}) +// public String ageSusc; // @Parameter({0.90, .95, 1.}) // public double deltaTheta; diff --git a/src/main/java/org/matsim/run/batch/CologneScenarioHub.java b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java index 57226c354..e7c3a5b36 100644 --- a/src/main/java/org/matsim/run/batch/CologneScenarioHub.java +++ b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java @@ -27,7 +27,7 @@ */ public class CologneScenarioHub implements BatchRun { - boolean DEBUG_MODE = false; + boolean DEBUG_MODE = true; int runCount = 0; @Nullable @@ -241,6 +241,7 @@ else if (immunityType == VaccinationType.omicronUpdate) { private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { return new SnzCologneProductionScenario.Builder() + .setLeisureCorrection(0.0) .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) .setSebastianUpdate(true) .setScaleForActivityLevels(1.3) @@ -259,10 +260,10 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( -// new VaccinationEffectiveness().withArgs(), -// new RValuesFromEvents().withArgs(), -// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), -// new HospitalNumbersFromEvents().withArgs() + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new HospitalNumbersFromEvents().withArgs(), new SecondaryAttackRateFromEvents().withArgs() ); } @@ -369,7 +370,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi public static final class Params { // general - @GenerateSeeds(5) + @GenerateSeeds(10) public long seed; From 01c49c3d0637dcafc1a4d9ec5e682359ef650504 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 2 Aug 2022 14:31:56 +0200 Subject: [PATCH 020/128] misc changes --- src/main/R/masterJR-utils.R | 9 ++++ .../matsim/episim/InfectionEventHandler.java | 1 + .../matsim/episim/VirusStrainConfigGroup.java | 4 +- .../matsim/episim/analysis/FilterEvents.java | 4 +- .../analysis/HospitalNumbersFromEvents.java | 14 ++--- .../SecondaryAttackRateFromEvents.java | 53 ++++++++++++------- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../modules/SnzCologneProductionScenario.java | 35 +++++++++--- 8 files changed, 82 insertions(+), 42 deletions(-) diff --git a/src/main/R/masterJR-utils.R b/src/main/R/masterJR-utils.R index 2720bc9ac..7d633dd3e 100644 --- a/src/main/R/masterJR-utils.R +++ b/src/main/R/masterJR-utils.R @@ -222,10 +222,19 @@ read_combine_episim_output_zipped <- function(directory, file_root) { relevant_cols <- col_names[!col_names %in% c("RunScript", "RunId", "Config", "Output")] episim_df_all_runs <- data.frame() + + # runsToInclude <- c("calibration1824","calibration288","calibration1056", "calibration2208","calibration672","calibration1440") for (row in seq_len(nrow(info_df))) { runId <- info_df$RunId[row] + # if(runId %in% runsToInclude){ + # + # } else{ + # next + # } + + zipDir <- paste0(directory,"summaries/",runId,".zip") file_name <- paste0(runId, ".", file_root) diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index d339f139c..09d5b3225 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -778,6 +778,7 @@ public void reset(int iteration) { } +// if (date.equals(LocalDate.parse("2022-07-23"))) { // if (date.getDayOfMonth() == 1) { // try (CSVPrinter csv = new CSVPrinter(Files.newBufferedWriter(Path.of("antibodies_" + date + ".tsv")), CSVFormat.TDF)) { // diff --git a/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java b/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java index 17e7fce4d..8c3dcacd9 100644 --- a/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java +++ b/src/main/java/org/matsim/episim/VirusStrainConfigGroup.java @@ -275,9 +275,9 @@ public NavigableMap getAgeInfectivity() { /** * Set infectivity for all age groups, previous entries will be overwritten. */ - public void setAgeInfectivity(Map ageSusceptibility) { + public void setAgeInfectivity(Map ageInfectivity) { this.ageInfectivity.clear(); - this.ageInfectivity.putAll(ageSusceptibility); + this.ageInfectivity.putAll(ageInfectivity); } } diff --git a/src/main/java/org/matsim/episim/analysis/FilterEvents.java b/src/main/java/org/matsim/episim/analysis/FilterEvents.java index b93bf76f8..5e44e6a87 100644 --- a/src/main/java/org/matsim/episim/analysis/FilterEvents.java +++ b/src/main/java/org/matsim/episim/analysis/FilterEvents.java @@ -30,8 +30,8 @@ public class FilterEvents implements OutputAnalysis { private static final Logger log = LogManager.getLogger(FilterEvents.class); - // @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/cologne/2022-02-17/1/output-filtered") - @CommandLine.Option(names = "--output", defaultValue = "./output/") + @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-27/4-eu/analysis") +// @CommandLine.Option(names = "--output", defaultValue = "./output/") private Path output; @CommandLine.Parameters(paramLabel = "TYPE", arity = "0..*", description = "Names of event types to keep") diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 10120e5f7..18dfc56d1 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,10 +60,10 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-20/3-eu/analysis/base/") + @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-27/4-eu/analysis") private Path output; -// @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") +// @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @CommandLine.Option(names = "--input", defaultValue = "../shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input") private String input; @@ -260,7 +260,7 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t ); // feed the output events file to the handler, so that the hospitalizations may be calculated - AnalysisCommand.forEachEvent(pathToScenario, s -> { + List eventFiles = AnalysisCommand.forEachEvent(pathToScenario, s -> { }, handlers.toArray(new Handler[0])); // for (Double facA : strainFactors) { @@ -283,12 +283,6 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t for (Handler handler : handlers) { - int maxIteration = Math.max( - Math.max(handler.postProcessHospitalAdmissions.keySet().lastInt(), - handler.postProcessICUAdmissions.keySet().lastInt()), - Math.max(handler.postProcessHospitalFilledBeds.keySet().lastInt(), - handler.postProcessHospitalFilledBedsICU.keySet().lastInt())); - // calculates the number of agents in the scenario's population (25% sample) who live in Cologne // this is used to normalize the hospitalization values @@ -296,7 +290,7 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t .filter(x -> x.getAttributes().getAttribute("district").equals(district)).count(); - for (int day = 0; day <= maxIteration; day++) { + for (int day = 0; day < eventFiles.size(); day++) { LocalDate date = startDate.plusDays(day); // calculates Incidence - 7day hospitalizations per 100,000 residents diff --git a/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java b/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java index 20f5569fd..410483c8b 100644 --- a/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java @@ -20,10 +20,12 @@ package org.matsim.episim.analysis; +import com.google.inject.Inject; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.config.Configurator; +import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Population; import org.matsim.core.population.PopulationUtils; @@ -59,24 +61,25 @@ public class SecondaryAttackRateFromEvents implements OutputAnalysis { private static final Logger log = LogManager.getLogger(SecondaryAttackRateFromEvents.class); -// @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-22/1-calibration/output") + @CommandLine.Option(names = "--output", defaultValue = "./output/") +// @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-22/1-calibration/output") private Path output; @CommandLine.Option(names = "--start-date", defaultValue = "2020-02-24") private LocalDate startDate; -// @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") - @CommandLine.Option(names = "--input", defaultValue = "../shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input") + @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") +// @CommandLine.Option(names = "--input", defaultValue = "../shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input") private String input; @CommandLine.Option(names = "--population-file", defaultValue = "/cologne_snz_entirePopulation_emptyPlans_withDistricts_25pt_split.xml.gz") private String populationFile; - private Map personToHousehold; + @Inject + private Scenario scenario; - private Map personCountPerHousehold; + private Population population; public static void main(String[] args) { @@ -95,19 +98,7 @@ public Integer call() throws Exception { return 2; } - Population population = PopulationUtils.readPopulation(input + populationFile); - - personToHousehold = new HashMap<>(); - for (Person person : population.getPersons().values()) { - if(person.getAttributes().getAttribute("district").equals("Köln")) - personToHousehold.put(person.getId().toString(), person.getAttributes().getAttribute("homeId").toString()); - } - - personCountPerHousehold = personToHousehold.values().stream() - .collect(Collectors.groupingBy(Function.identity(), - Collectors.counting())); - - OptionalDouble x = personCountPerHousehold.values().stream().mapToLong(Long::longValue).average(); + population = PopulationUtils.readPopulation(input + populationFile); AnalysisCommand.forEachScenario(output, scenario -> { try { @@ -127,6 +118,20 @@ public void analyzeOutput(Path output) throws IOException { String id = AnalysisCommand.getScenarioPrefix(output); + if (scenario != null) + population = scenario.getPopulation(); + + + Map personToHousehold = new HashMap<>(); + for (Person person : population.getPersons().values()) { + if(person.getAttributes().getAttribute("district").equals("Köln")) + personToHousehold.put(person.getId().toString(), person.getAttributes().getAttribute("homeId").toString()); + } + + Map personCountPerHousehold = personToHousehold.values().stream() + .collect(Collectors.groupingBy(Function.identity(), + Collectors.counting())); + SecondaryAttackRateHandler hhHandler = new SecondaryAttackRateHandler(personToHousehold); @@ -204,6 +209,13 @@ public void handleEvent(EpisimPersonStatusEvent event) { int day = (int) (event.getTime() / 86400); String personId = event.getPersonId().toString(); + + // if agent does not live in district being evaluated + if (!personToHousehold.containsKey(personId)) { + return; + } + + String hhId = personToHousehold.get(personId); if (event.getDiseaseStatus() == DiseaseStatus.contagious) { @@ -211,7 +223,8 @@ public void handleEvent(EpisimPersonStatusEvent event) { throw new RuntimeException("person was already contagious, but was never removed from indexPersons when recovered"); } - if (householdToInfections.containsKey(hhId)) { + //todo: if they become contagious on the same day, don't count that case? + if (householdToInfections.containsKey(hhId) ) { householdToInfections.merge(hhId, 1, Integer::sum); } else { indexPersons.put(personId, day); diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 2f8a78654..e5adb286d 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneJR") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20220805") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneJR$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20220805$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 50479f8cd..ebb8b2fb8 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -356,7 +356,7 @@ public Config config() { //restrictions and masks CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); - activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20220610.csv")); + activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20220723.csv")); activityParticipation.setScale(this.scale); activityParticipation.setLeisureAsNightly(this.leisureNightly); @@ -637,13 +637,24 @@ public Config config() { virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorCritical(oHos); } - //testing + //--------------------------------------- + // T E S T I N G + //--------------------------------------- + + // this section is split into four nested sections: + // A) RAPID test + // i) unvaccinated + // ii) vaccinated + // B) PCR Test + // i) unvaccinated + // ii) vaccinated + + // load testing config group and set general parameters TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); testingConfigGroup.setTestAllPersonsAfter(LocalDate.parse("2021-10-01")); - TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); - TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + testingConfigGroup.setStrategy(TestingConfigGroup.Strategy.ACTIVITIES); @@ -659,11 +670,13 @@ public Config config() { actsList.add("educ_higher"); testingConfigGroup.setActivities(actsList); + + // 1) Rapid test + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); rapidTest.setFalseNegativeRate(0.3); rapidTest.setFalsePositiveRate(0.03); - pcrTest.setFalseNegativeRate(0.1); - pcrTest.setFalsePositiveRate(0.01); + // 1i) unvaccianted testingConfigGroup.setHouseholdCompliance(1.0); @@ -729,6 +742,7 @@ public Config config() { "educ_other", eduTests ))); + // 1ii) vaccinated Map leisureTestsVaccinated = new HashMap<>(); Map workTestsVaccinated = new HashMap<>(); Map eduTestsVaccinated = new HashMap<>(); @@ -759,6 +773,13 @@ public Config config() { ))); + // 2) PCR Test + TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + pcrTest.setFalseNegativeRate(0.1); + pcrTest.setFalsePositiveRate(0.01); + + // 2i) unvaccinated + Map leisureTestsPCR = new HashMap(); Map workTestsPCR = new HashMap(); Map kigaPramaryTestsPCR = new HashMap(); @@ -791,6 +812,8 @@ public Config config() { "educ_other", eduTestsPCR ))); + // 2ii) vaccinated + Map leisureTestsPCRVaccinated = new HashMap<>(); Map workTestsPCRVaccinated = new HashMap<>(); Map eduTestsPCRVaccinated = new HashMap<>(); From 4deec53d0cacc7c769c6fa8656cd3427c02f8a81 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Tue, 2 Aug 2022 14:53:00 +0200 Subject: [PATCH 021/128] two different omicron vaccinations --- .../org/matsim/episim/model/AntibodyModel.java | 14 +++++++------- .../org/matsim/episim/model/VaccinationType.java | 3 ++- .../java/org/matsim/run/batch/Berlin220215.java | 4 ++-- .../matsim/run/batch/CologneBMBF20220805.java | 16 ++++++++-------- .../org/matsim/run/batch/CologneBMBF220211.java | 2 +- .../org/matsim/run/batch/CologneBMBF220217.java | 2 +- .../matsim/run/batch/CologneBMBF220217BA2.java | 2 +- .../org/matsim/run/batch/CologneBMBF220426.java | 16 ++++++++-------- .../org/matsim/run/batch/CologneBMBF220628.java | 16 ++++++++-------- .../matsim/run/batch/CologneBMBF220628_3G.java | 16 ++++++++-------- .../org/matsim/run/batch/CologneCalibration.java | 2 +- .../java/org/matsim/run/batch/CologneJR.java | 16 ++++++++-------- .../java/org/matsim/run/batch/CologneSM.java | 14 +++++++------- .../org/matsim/run/batch/CologneScenarioHub.java | 14 +++++++------- .../modules/SnzCologneProductionScenario.java | 2 +- .../episim/model/DefaultAntibodyModelTest.java | 2 +- 16 files changed, 71 insertions(+), 70 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/AntibodyModel.java b/src/main/java/org/matsim/episim/model/AntibodyModel.java index aae035520..31a8cfc27 100644 --- a/src/main/java/org/matsim/episim/model/AntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/AntibodyModel.java @@ -93,7 +93,7 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -105,7 +105,7 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -118,7 +118,7 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -131,7 +131,7 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNADelta / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNADelta / mutEscBa5); //BA.2 double mRNABA2 = mRNABA1; @@ -144,7 +144,7 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNADelta / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNADelta / mutEscBa5); //BA.5 @@ -158,7 +158,7 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNADelta); // mRNAAlpha / mutEscBa5 + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNADelta); // mRNAAlpha / mutEscBa5 Map> antibodyRefreshFactors = new HashMap<>(); for (VaccinationType immunityType : VaccinationType.values()) { @@ -170,7 +170,7 @@ public Config() { } else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { diff --git a/src/main/java/org/matsim/episim/model/VaccinationType.java b/src/main/java/org/matsim/episim/model/VaccinationType.java index c51b94efb..57f9be945 100644 --- a/src/main/java/org/matsim/episim/model/VaccinationType.java +++ b/src/main/java/org/matsim/episim/model/VaccinationType.java @@ -8,7 +8,8 @@ public enum VaccinationType implements ImmunityEvent { generic, mRNA, vector, - omicronUpdate, + ba1Update, + ba5Update, /** * Not a real vaccination, but used to describe the profile for persons that have been infected and gained a natural immunity. diff --git a/src/main/java/org/matsim/run/batch/Berlin220215.java b/src/main/java/org/matsim/run/batch/Berlin220215.java index 3506f74e6..4edb83da6 100644 --- a/src/main/java/org/matsim/run/batch/Berlin220215.java +++ b/src/main/java/org/matsim/run/batch/Berlin220215.java @@ -597,7 +597,7 @@ private void adaptVacinationEffectiveness(VaccinationConfigGroup vaccinationConf ) ; - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate) + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update) .setDaysBeforeFullEffect(fullEffectMRNA) .setFactorShowingSymptoms(VaccinationConfigGroup.forStrain(VirusStrain.SARS_CoV_2) .atFullEffect(factorSymptomsMRNA) @@ -697,7 +697,7 @@ private void configureBooster(VaccinationConfigGroup vaccinationConfig, double b .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate) + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update) .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 552ee866e..02145cc67 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -146,7 +146,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -158,7 +158,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -171,7 +171,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -184,7 +184,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); //BA.2 double mRNABA2 = mRNABA1; @@ -197,7 +197,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); //BA.5 @@ -211,7 +211,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); //StrainA double mRNAStrainA = mRNABa5 / mutEscStrainA; @@ -224,7 +224,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -236,7 +236,7 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF220211.java b/src/main/java/org/matsim/run/batch/CologneBMBF220211.java index dc98b9f81..85164364b 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF220211.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF220211.java @@ -514,7 +514,7 @@ private void configureBooster(VaccinationConfigGroup vaccinationConfig, double b .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate) + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update) .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF220217.java b/src/main/java/org/matsim/run/batch/CologneBMBF220217.java index 8509837e1..0bec78ff6 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF220217.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF220217.java @@ -613,7 +613,7 @@ private void configureBooster(VaccinationConfigGroup vaccinationConfig, double b vaccinationConfig.setReVaccinationCapacity_pers_per_day(boosterVaccinations); vaccinationConfig.getOrAddParams(VaccinationType.mRNA).setBoostWaitPeriod(boostAfter_months * 30 + 6 * 7); - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate).setBoostWaitPeriod(boostAfter_months * 30 + 6 * 7); + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update).setBoostWaitPeriod(boostAfter_months * 30 + 6 * 7); vaccinationConfig.getOrAddParams(VaccinationType.vector).setBoostWaitPeriod(boostAfter_months * 30 + 9 * 7); ; } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF220217BA2.java b/src/main/java/org/matsim/run/batch/CologneBMBF220217BA2.java index e3a3cd79e..066f14c69 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF220217BA2.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF220217BA2.java @@ -497,7 +497,7 @@ private void configureBooster(VaccinationConfigGroup vaccinationConfig, double b .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate) + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update) .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF220426.java b/src/main/java/org/matsim/run/batch/CologneBMBF220426.java index a3ed2ee69..fcc6300ac 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF220426.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF220426.java @@ -121,7 +121,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -132,7 +132,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -144,7 +144,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -156,7 +156,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); //BA.2 double mRNABA2 = mRNABA1; @@ -168,7 +168,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); //StrainA double mRNAStrainA = mRNABA2 / mutEscOm; @@ -180,7 +180,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / 1.4 / mutEscOm); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscOm); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscOm); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscOm); for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -192,7 +192,7 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { @@ -657,7 +657,7 @@ private void configureBooster(VaccinationConfigGroup vaccinationConfig, double b .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate) + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update) .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF220628.java b/src/main/java/org/matsim/run/batch/CologneBMBF220628.java index f3b47b325..0bdcd0dde 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF220628.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF220628.java @@ -143,7 +143,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -155,7 +155,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -168,7 +168,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -181,7 +181,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); //BA.2 double mRNABA2 = mRNABA1; @@ -194,7 +194,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); //BA.5 @@ -208,7 +208,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); //StrainA double mRNAStrainA = mRNABa5 / mutEscStrainA; @@ -221,7 +221,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -233,7 +233,7 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF220628_3G.java b/src/main/java/org/matsim/run/batch/CologneBMBF220628_3G.java index 741e260a6..66947f742 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF220628_3G.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF220628_3G.java @@ -219,7 +219,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -231,7 +231,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -244,7 +244,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -257,7 +257,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); //BA.2 double mRNABA2 = mRNABA1; @@ -270,7 +270,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); //BA.5 @@ -284,7 +284,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); //StrainA double mRNAStrainA = mRNABa5 / mutEscStrainA; @@ -297,7 +297,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -309,7 +309,7 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { diff --git a/src/main/java/org/matsim/run/batch/CologneCalibration.java b/src/main/java/org/matsim/run/batch/CologneCalibration.java index 3c1e8bca1..a1f650888 100644 --- a/src/main/java/org/matsim/run/batch/CologneCalibration.java +++ b/src/main/java/org/matsim/run/batch/CologneCalibration.java @@ -461,7 +461,7 @@ private void configureBooster(VaccinationConfigGroup vaccinationConfig, double b .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate) + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update) .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; diff --git a/src/main/java/org/matsim/run/batch/CologneJR.java b/src/main/java/org/matsim/run/batch/CologneJR.java index 5b2dd762c..8d29664ef 100644 --- a/src/main/java/org/matsim/run/batch/CologneJR.java +++ b/src/main/java/org/matsim/run/batch/CologneJR.java @@ -145,7 +145,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -157,7 +157,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -170,7 +170,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -183,7 +183,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); //BA.2 double mRNABA2 = mRNABA1; @@ -196,7 +196,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); //BA.5 @@ -210,7 +210,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); //StrainA double mRNAStrainA = mRNABa5 / mutEscStrainA; @@ -223,7 +223,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -235,7 +235,7 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { diff --git a/src/main/java/org/matsim/run/batch/CologneSM.java b/src/main/java/org/matsim/run/batch/CologneSM.java index 75cd341e2..8a7c5ac87 100644 --- a/src/main/java/org/matsim/run/batch/CologneSM.java +++ b/src/main/java/org/matsim/run/batch/CologneSM.java @@ -124,7 +124,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -135,7 +135,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -147,7 +147,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -159,7 +159,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); //BA.2 double mRNABA2 = mRNABA1; @@ -171,7 +171,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); //StrainA double mRNAStrainA = mRNABA2 / mutEscOm; @@ -183,7 +183,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / 1.4 / mutEscOm); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscOm); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscOm); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscOm); for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -195,7 +195,7 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { diff --git a/src/main/java/org/matsim/run/batch/CologneScenarioHub.java b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java index e7c3a5b36..d521f11ce 100644 --- a/src/main/java/org/matsim/run/batch/CologneScenarioHub.java +++ b/src/main/java/org/matsim/run/batch/CologneScenarioHub.java @@ -139,7 +139,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -151,7 +151,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); //DELTA double mRNADelta = 10.9; @@ -164,7 +164,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); //BA.1 double mRNABA1 = 1.9; @@ -177,7 +177,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA1, mRNADelta / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNADelta / mutEscBa5); //BA.2 double mRNABA2 = mRNABA1; @@ -190,7 +190,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA2, mRNADelta / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNADelta / mutEscBa5); //BA.5 @@ -204,7 +204,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.omicronUpdate).put(VirusStrain.OMICRON_BA5, mRNADelta); // mRNAAlpha / mutEscBa5 + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNADelta); // mRNAAlpha / mutEscBa5 for (VaccinationType immunityType : VaccinationType.values()) { @@ -217,7 +217,7 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.vector) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); } - else if (immunityType == VaccinationType.omicronUpdate) { + else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } else { diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index ebb8b2fb8..df3ad5c76 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -988,7 +988,7 @@ private void configureBooster(VaccinationConfigGroup vaccinationConfig, double b .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; - vaccinationConfig.getOrAddParams(VaccinationType.omicronUpdate) + vaccinationConfig.getOrAddParams(VaccinationType.ba1Update) .setBoostWaitPeriod(boostAfter * 30 + 6 * 7); ; diff --git a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java index 6b226e8bf..3f4a28436 100644 --- a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java @@ -178,7 +178,7 @@ public void testNoImmunityEvents() { @Test public void testMixOfVaccinesAndInfections() { - List immunityEvents = List.of(VaccinationType.mRNA, VaccinationType.mRNA, VaccinationType.omicronUpdate); + List immunityEvents = List.of(VaccinationType.mRNA, VaccinationType.mRNA, VaccinationType.ba1Update); IntList immunityEventDays = IntList.of(1, 181, 451); // List immunityEvents = List.of(VaccinationType.mRNA); // IntList immunityEventDays = IntList.of(1); From a3d1e2bfdd2bbdc6d05d087de84720862add6789 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 2 Aug 2022 15:22:46 +0200 Subject: [PATCH 022/128] readded changes to utils --- src/main/python/analysis/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/python/analysis/utils.py b/src/main/python/analysis/utils.py index 5e9792e7f..f42ad2392 100644 --- a/src/main/python/analysis/utils.py +++ b/src/main/python/analysis/utils.py @@ -310,8 +310,16 @@ def calc_r_reduction(base_case, base_variables, df, group_by=None): return result + if __name__ == "__main__": - aggregate_batch_run("/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-20/3-eu/summaries.zip") - + import argparse + + parser = argparse.ArgumentParser(description="Aggregate batch run over multiple seeds") + parser.add_argument("file", type=str, nargs=1, help="Path to summaries zip", default="../../../../output/summaries.zip") + args = parser.parse_args() + + aggregate_batch_run(args.file[0]) + + From 45225e94d03ddbdd3a58df83e964fc6c21a46153 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Tue, 2 Aug 2022 16:12:26 +0200 Subject: [PATCH 023/128] runs for bmbf report --- .../matsim/run/batch/CologneBMBF20220805.java | 127 +++++++++++++----- 1 file changed, 90 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 02145cc67..09492142e 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -44,7 +44,7 @@ protected void configure() { set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); - + double mutEscBa1 = 10.9 / 1.9; double mutEscBa5 = 2.9; double mutEscStrainA = 0.; @@ -58,10 +58,14 @@ protected void configure() { compliance.put(12, 0.0); compliance.put(0, 0.0); - - + String vacCamp = "off"; + if (params != null) { // mutEscBa5 = params.ba5Esc; + + if (!params.vacType.equals("off")) { + vacCamp = "age"; + } mutEscStrainA = params.strAEsc; @@ -69,19 +73,19 @@ protected void configure() { vaccinationType = VaccinationType.valueOf(params.vacType); - if (params.vacCamp.equals("age")) { + if (vacCamp.equals("age")) { compliance.put(60, 0.85); // 60+ compliance.put(18, 0.55); // 18-59 compliance.put(12, 0.20); // 12-17 compliance.put(0, 0.0); // 0 - 11 } - else if (params.vacCamp.equals("eu")) { + else if (vacCamp.equals("eu")) { compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) compliance.put(18, 0.); compliance.put(12, 0.); compliance.put(0, 0.); } - else if (params.vacCamp.equals("off")) { + else if (vacCamp.equals("off")) { } else { throw new RuntimeException("Not a valid option for vaccinationCampaignType"); @@ -93,7 +97,7 @@ else if (params.vacCamp.equals("off")) { //initial antibodies Map> initialAntibodies = new HashMap<>(); Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscBa5,mutEscStrainA); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscBa1, mutEscBa5, mutEscStrainA); AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); @@ -108,7 +112,7 @@ else if (params.vacCamp.equals("off")) { private void configureAntibodies(Map> initialAntibodies, Map> antibodyRefreshFactors, - double mutEscBa5, double mutEscStrainA) { + double mutEscBa1, double mutEscBa5, double mutEscStrainA) { for (VaccinationType immunityType : VaccinationType.values()) { initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -146,7 +150,8 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscBa1 / mutEscBa5); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -158,7 +163,8 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscBa1 / mutEscBa5); //DELTA double mRNADelta = 10.9; @@ -171,10 +177,11 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); //BA.1 - double mRNABA1 = 1.9; + double mRNABA1 = mRNADelta / mutEscBa1; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); @@ -185,6 +192,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); //BA.2 double mRNABA2 = mRNABA1; @@ -198,6 +206,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); //BA.5 @@ -212,6 +221,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); //StrainA double mRNAStrainA = mRNABa5 / mutEscStrainA; @@ -224,7 +234,22 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 0.2 / 6.4); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNADelta / mutEscBa1 / mutEscBa5); + for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -360,14 +385,22 @@ public Config prepareConfig(int id, Params params) { // STRAIN_A - double strAInf = 1.0; - if (params.strAEsc != 0.) { + if (params.strAInf != 0.) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf * strAInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf * params.strAInf); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); } + +// STRAIN_B + if (params.strBInf != 0.) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf * params.strBInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); + } // remove age-based susceptibility of strains starting with DELTA @@ -487,10 +520,11 @@ public Config prepareConfig(int id, Params params) { } else { throw new RuntimeException("param value doesn't exist"); } - +/* // Restrictions starting on December 1, 2022 LocalDate restrictionDate = LocalDate.parse(params.resDate); + //school if(params.edu.equals("close")) { if (params.resDate.equals("2022-12-01")) { @@ -533,7 +567,7 @@ public Config prepareConfig(int id, Params params) { //leisure builder.restrict(restrictionDate, 0.88 * params.leis, "leisure"); builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.leis, "leisure"); - +*/ episimConfig.setPolicy(builder.build()); @@ -581,6 +615,8 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + // add initial impulses for strains //BA.1 @@ -606,8 +642,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi infPerDayBa5.put(ba5Date.plusDays(7), 1); //StrainA - - if (params.strAEsc != 0.) { + if (params.strAInf != 0.) { infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); LocalDate strADate = LocalDate.parse("2022-11-01"); for (int i = 0; i < 7; i++) { @@ -615,6 +650,16 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } + + //StrainB + if (params.strBInf != 0.) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } // add projected disease import for vacation waves after initial disease import @@ -625,6 +670,8 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import LocalDate dateStrainA = LocalDate.parse("2022-11-18"); // after vaca import + LocalDate dateStrainB = LocalDate.parse("2022-11-18"); // after vaca import + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); LocalDate date = null; @@ -634,7 +681,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi // double cases = factor * entry.getValue(); - if (date.isAfter(dateStrainA) && params.strAEsc != 0) { + if (date.isAfter(dateStrainA) && params.strAInf != 0) { infPerDayStrA.put(date, ((int) cases * facStrA) == 0 ? 1 : (int) (cases * facStrA)); infPerDayBa5.put(date, 1); infPerDayBa2.put(date, 1); @@ -647,7 +694,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } - if( params.strAEsc!=0.) { + if( params.strAInf!=0.) { infPerDayBa5.put(dateStrainA.plusDays(1), 1); infPerDayStrA.put(date.plusDays(1), 1); } else { @@ -659,7 +706,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); - if (params.strAEsc != 0.) { + if (params.strAInf != 0.) { episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); } } @@ -728,8 +775,14 @@ public static final class Params { // @StringParameter({"2022-11-01"}) // public String strADate; - @Parameter({6.0}) + @Parameter({3.0, 6.0}) public double strAEsc; + + @Parameter({0.0, 1.0}) + public double strAInf; + + @Parameter({0.0, 1.0}) + public double strBInf; // General Restriction date @@ -738,39 +791,39 @@ public static final class Params { public String resDate; // // - @StringParameter({"off", "age"}) +// @StringParameter({"off", "age"}) // @StringParameter({"off"}) - String vacCamp; +// String vacCamp; // // other restrictions // schools & university // close: rf reduced // maskVent: ciCorrection reduced & surgical mask for most // normal: no changes made - @StringParameter({"close", "maskVent", "normal"}) +// @StringParameter({"close", "maskVent", "normal"}) // @StringParameter({ "normal"}) - String edu; +// String edu; // shopping: mask - @StringParameter({"true", "false"}) +// @StringParameter({"true", "false"}) // @StringParameter({"false"}) - String maskShop; +// String maskShop; // pt: mask - @StringParameter({"true", "false"}) +// @StringParameter({"true", "false"}) // @StringParameter({"false"}) - String maskPt; +// String maskPt; // work: - @Parameter({0.5, 1.0}) +// @Parameter({0.5, 1.0}) // @Parameter({1.0}) - double work; +// double work; // leisure - @Parameter({0.5, 0.75, 1.0}) +// @Parameter({0.5, 0.75, 1.0}) // @Parameter({1.0}) - double leis; +// double leis; // vaccination campaign - @StringParameter({"omicronUpdate"}) + @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) public String vacType; // @StringParameter({"2022-04-25"}) From a41f74ccda518ffd958474af72e21945ea1e1fdc Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Tue, 2 Aug 2022 17:13:36 +0200 Subject: [PATCH 024/128] update bmbf runs --- .../matsim/run/batch/CologneBMBF20220805.java | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 09492142e..8cba92944 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -44,6 +44,7 @@ protected void configure() { set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + double mutEscDelta = 29.2 / 10.9; double mutEscBa1 = 10.9 / 1.9; double mutEscBa5 = 2.9; @@ -97,7 +98,7 @@ else if (vacCamp.equals("off")) { //initial antibodies Map> initialAntibodies = new HashMap<>(); Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscBa1, mutEscBa5, mutEscStrainA); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA); AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); @@ -112,7 +113,7 @@ else if (vacCamp.equals("off")) { private void configureAntibodies(Map> initialAntibodies, Map> antibodyRefreshFactors, - double mutEscBa1, double mutEscBa5, double mutEscStrainA) { + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA) { for (VaccinationType immunityType : VaccinationType.values()) { initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -150,8 +151,9 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscBa1 / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -163,11 +165,12 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscBa1 / mutEscBa5); - + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + //DELTA - double mRNADelta = 10.9; + double mRNADelta = mRNAAlpha / mutEscDelta; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); @@ -177,6 +180,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, mRNADelta * 450./300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); @@ -191,6 +195,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); @@ -205,6 +210,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); @@ -220,6 +226,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); @@ -234,6 +241,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); @@ -247,6 +255,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 0.2 / 6.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 0.2 / 6.4); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 0.2 / 6.4); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, mRNADelta * 450./300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNADelta / mutEscBa1); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNADelta / mutEscBa1 / mutEscBa5); @@ -264,6 +273,9 @@ else if (immunityType == VaccinationType.vector) { else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } else { antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); } @@ -387,7 +399,7 @@ public Config prepareConfig(int id, Params params) { // STRAIN_A if (params.strAInf != 0.) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf * params.strAInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf * params.strAInf); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); @@ -396,7 +408,7 @@ public Config prepareConfig(int id, Params params) { // STRAIN_B if (params.strBInf != 0.) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf * params.strBInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf * params.strBInf); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); @@ -665,12 +677,11 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi // add projected disease import for vacation waves after initial disease import int facBa2 = 4; int facBa5 = 4; - int facStrA = 4; + int facStrAB = 4; LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import - LocalDate dateStrainA = LocalDate.parse("2022-11-18"); // after vaca import - LocalDate dateStrainB = LocalDate.parse("2022-11-18"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); @@ -681,8 +692,20 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi // double cases = factor * entry.getValue(); - if (date.isAfter(dateStrainA) && params.strAInf != 0) { - infPerDayStrA.put(date, ((int) cases * facStrA) == 0 ? 1 : (int) (cases * facStrA)); + if (date.isAfter(dateStrainAB) && (params.strAInf != 0 || params.strBInf != 0)) { + if (params.strAInf != 0 && params.strBInf != 0) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (params.strAInf != 0) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (params.strBInf != 0) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } infPerDayBa5.put(date, 1); infPerDayBa2.put(date, 1); } else if (date.isAfter(dateBa5)) { @@ -694,13 +717,6 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } - if( params.strAInf!=0.) { - infPerDayBa5.put(dateStrainA.plusDays(1), 1); - infPerDayStrA.put(date.plusDays(1), 1); - } else { - infPerDayBa5.put(date.plusDays(1), 1); - } - // save disease import episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); @@ -709,6 +725,9 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi if (params.strAInf != 0.) { episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); } + if (params.strBInf != 0.) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } } public static final class Params { From 304c994a5069bcf742d50ac442c03da2b6457d92 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 2 Aug 2022 17:36:38 +0200 Subject: [PATCH 025/128] added StrainA & StrainB in relevant locations --- .../model/InfectionModelWithAntibodies.java | 23 ++++++++++++++++--- .../model/testing/DefaultTestingModel.java | 5 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java index b769b056d..66438fb50 100644 --- a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java +++ b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java @@ -109,13 +109,30 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto igaFactor = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); } else if (vaccinationConfig.getUseIgA()) { - List crossImmunityStrains = List.of(VirusStrain.OMICRON_BA1,VirusStrain.OMICRON_BA2,VirusStrain.OMICRON_BA5,VirusStrain.STRAIN_A); + List crossImmunityStrainsOmicron = List.of(VirusStrain.OMICRON_BA1,VirusStrain.OMICRON_BA2,VirusStrain.OMICRON_BA5,VirusStrain.STRAIN_A); + List crossImmunityStrainsDelta = List.of(VirusStrain.DELTA, VirusStrain.STRAIN_B); - if(crossImmunityStrains.contains(infector.getVirusStrain())){ + + if(crossImmunityStrainsOmicron.contains(infector.getVirusStrain())){ int lastInfectionWithStrain = 0; boolean targetHadStrain = false; for (int ii = 0; ii < target.getNumInfections(); ii++) { - if (crossImmunityStrains.contains(target.getVirusStrain(ii))){ + if (crossImmunityStrainsOmicron.contains(target.getVirusStrain(ii))){ + targetHadStrain = true; + lastInfectionWithStrain = ii; + } + } + + if (targetHadStrain) { + double fac = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); + fac = fac / 1.4; + igaFactor = Math.max(fac, igaFactor); + } + } else if(crossImmunityStrainsDelta.contains(infector.getVirusStrain())) { + int lastInfectionWithStrain = 0; + boolean targetHadStrain = false; + for (int ii = 0; ii < target.getNumInfections(); ii++) { + if (crossImmunityStrainsDelta.contains(target.getVirusStrain(ii))) { targetHadStrain = true; lastInfectionWithStrain = ii; } diff --git a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java index 9ba82116a..676fd06e3 100644 --- a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java +++ b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java @@ -203,9 +203,10 @@ protected boolean testAndQuarantine(EpisimPerson person, int day, TestingConfigG double rate = params.getFalseNegativeRate(); // TODO: configurable - if (params.getType().equals (TestType.RAPID_TEST) && (person.getVirusStrain() == VirusStrain.OMICRON_BA1 || + if (params.getType().equals(TestType.RAPID_TEST) && (person.getVirusStrain() == VirusStrain.OMICRON_BA1 || person.getVirusStrain() == VirusStrain.OMICRON_BA2 || - person.getVirusStrain() == VirusStrain.OMICRON_BA5) ){ + person.getVirusStrain() == VirusStrain.OMICRON_BA5 || + person.getVirusStrain() == VirusStrain.STRAIN_A)) { rate = 0.5; } From a865bc606db6dc69e3d8faa347cd1d54410dc7c5 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 2 Aug 2022 18:10:26 +0200 Subject: [PATCH 026/128] run 2022-08-2/1-vax --- .../matsim/run/batch/CologneBMBF20220805.java | 168 ++---------------- 1 file changed, 12 insertions(+), 156 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 8cba92944..46b1c581a 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -60,10 +60,10 @@ protected void configure() { compliance.put(0, 0.0); String vacCamp = "off"; - + if (params != null) { // mutEscBa5 = params.ba5Esc; - + if (!params.vacType.equals("off")) { vacCamp = "age"; } @@ -168,7 +168,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); - + //DELTA double mRNADelta = mRNAAlpha / mutEscDelta; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); @@ -244,8 +244,8 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); - - //StrainB + + //StrainB initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNADelta); initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNADelta * 150./300.); initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNADelta * 64./300.); @@ -404,7 +404,7 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); } - + // STRAIN_B if (params.strBInf != 0.) { @@ -532,54 +532,6 @@ public Config prepareConfig(int id, Params params) { } else { throw new RuntimeException("param value doesn't exist"); } -/* - // Restrictions starting on December 1, 2022 - LocalDate restrictionDate = LocalDate.parse(params.resDate); - - - //school - if(params.edu.equals("close")) { - if (params.resDate.equals("2022-12-01")) { - builder.restrict(restrictionDate, 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - } - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - //university - builder.restrict(restrictionDate, 0.2, "educ_higher"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.2, rf), "educ_higher"); - } else if (params.edu.equals("maskVent")) { - builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.N95, 0.25, - FaceMask.SURGICAL, 0.25)), - "educ_primary", "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); - - } else if (params.edu.equals("normal")) { - - } else { - throw new RuntimeException("param value doesn't exist"); - } - - //pt: masks - if (Boolean.parseBoolean(params.maskPt)) { - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "pt"); - - } - - //shopping: masks - if (Boolean.parseBoolean(params.maskShop)) { - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45, FaceMask.SURGICAL, 0.45)), "shop_daily", "shop_other", "errands"); - } - - //work - builder.restrict(restrictionDate, 0.78 * params.work, "work"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.work, "work"); - - //leisure - builder.restrict(restrictionDate, 0.88 * params.leis, "leisure"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * params.leis, "leisure"); -*/ episimConfig.setPolicy(builder.build()); @@ -590,7 +542,7 @@ public Config prepareConfig(int id, Params params) { // vaccination VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); - vaccinationConfig.setUseIgA(true); + vaccinationConfig.setUseIgA(Boolean.parseBoolean(params.igA)); vaccinationConfig.setTimePeriodIgA(730.); @@ -662,7 +614,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } - + //StrainB if (params.strBInf != 0.) { infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); @@ -731,123 +683,27 @@ else if (params.strBInf != 0) { } public static final class Params { - - // general @GenerateSeeds(5) public long seed; -// @Parameter({0.9}) -// public double deltaTheta; -// -// @Parameter({1.9}) -// public double ba1Inf; - -// @StringParameter({"2021-11-20", "2021-11-27", "2021-12-04"}) -// public String ba1Date; - -// @Parameter({2.9,}) -// public double ba5Esc; - -// @Parameter({1.3}) -//// @Parameter({0.0}) -// public double actCorrection; - - -// @Parameter({1.2}) -// @Parameter({1.0}) -// public double thFactor; - - // @Parameter({1.}) -// @Parameter({0.75}) -// public double schoolCi; -// -// @Parameter({0.75}) -//// @Parameter({1.}) -// public double workCi; -// -// @Parameter({0.4}) -//// @Parameter({ 1.}) -// public double leisureCi; - -// @StringParameter({"yes"}) -// public String schoolUpdate; -// -// @StringParameter({"45to45"}) -// public String maskType; -// -// @StringParameter({"later"}) -// public String schoolTest; - -// @StringParameter({"false"}) -// public String ageSusc; - -// @Parameter({0.90, .95, 1.}) -// public double deltaTheta; - -// @StringParameter({"2021-01-15"}) -// public String alphaDate; - -// @Parameter({1.4}) -// public double alphaTheta; - -// @StringParameter({"2022-11-01"}) -// public String strADate; - @Parameter({3.0, 6.0}) public double strAEsc; - + @Parameter({0.0, 1.0}) public double strAInf; - + @Parameter({0.0, 1.0}) public double strBInf; - - // General Restriction date -// @StringParameter({"2022-07-01","2022-12-01"}) @StringParameter({"2022-12-01"}) public String resDate; -// -// -// @StringParameter({"off", "age"}) -// @StringParameter({"off"}) -// String vacCamp; -// - // other restrictions - // schools & university // close: rf reduced // maskVent: ciCorrection reduced & surgical mask for most // normal: no changes made -// @StringParameter({"close", "maskVent", "normal"}) -// @StringParameter({ "normal"}) -// String edu; - - // shopping: mask -// @StringParameter({"true", "false"}) -// @StringParameter({"false"}) -// String maskShop; - - // pt: mask -// @StringParameter({"true", "false"}) -// @StringParameter({"false"}) -// String maskPt; - - // work: -// @Parameter({0.5, 1.0}) -// @Parameter({1.0}) -// double work; - - // leisure -// @Parameter({0.5, 0.75, 1.0}) -// @Parameter({1.0}) -// double leis; - + @StringParameter({"false", "true"}) + public String igA; // vaccination campaign @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) public String vacType; - -// @StringParameter({"2022-04-25"}) -// public String unResDate; - } From 66dd907a09c0e48dc18fbe645ee65949c1df7069 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 3 Aug 2022 07:42:27 +0200 Subject: [PATCH 027/128] updates to post processing --- .../java/org/matsim/run/batch/CologneBMBF20220805.java | 7 ++++--- src/main/resources/collect.sh | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 46b1c581a..309276895 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -51,7 +51,7 @@ protected void configure() { double mutEscStrainA = 0.; LocalDate start = null; - VaccinationType vaccinationType = null; + VaccinationType vaccinationType = VaccinationType.mRNA; Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); compliance.put(60, 0.0); @@ -66,12 +66,13 @@ protected void configure() { if (!params.vacType.equals("off")) { vacCamp = "age"; + vaccinationType = VaccinationType.valueOf(params.vacType); } mutEscStrainA = params.strAEsc; start = LocalDate.parse(params.resDate); - vaccinationType = VaccinationType.valueOf(params.vacType); + if (vacCamp.equals("age")) { @@ -348,7 +349,7 @@ public Collection postProcessing() { new VaccinationEffectiveness().withArgs(), new RValuesFromEvents().withArgs(), new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new HospitalNumbersFromEvents().withArgs(), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input"), new SecondaryAttackRateFromEvents().withArgs() ); } diff --git a/src/main/resources/collect.sh b/src/main/resources/collect.sh index dbcb60ddd..06b491666 100755 --- a/src/main/resources/collect.sh +++ b/src/main/resources/collect.sh @@ -48,6 +48,7 @@ aggregate_run() { copy_output *.strains.tsv $tmp/$run copy_output *.vaccinations.tsv $tmp/$run copy_output *.vaccinationsDetailed.tsv $tmp/$run + copy_output *.secondaryAttackRate.txt $tmp/$run copy_output *.config.xml $tmp/$run for OUTPUT in *.post.*.*; do From b4983191c5e88be4a9b549979385ea3c26f217a9 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 3 Aug 2022 08:23:19 +0200 Subject: [PATCH 028/128] fixed test. data was changed retroactively; thus tests have to be updated --- src/test/java/org/matsim/episim/DataUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/matsim/episim/DataUtilsTest.java b/src/test/java/org/matsim/episim/DataUtilsTest.java index f414cdc41..c734c4ccc 100644 --- a/src/test/java/org/matsim/episim/DataUtilsTest.java +++ b/src/test/java/org/matsim/episim/DataUtilsTest.java @@ -39,7 +39,7 @@ public void voc() throws IOException { assertThat(result.get(LocalDate.of(2022,5,29))) .containsEntry(VirusStrain.OMICRON_BA1, 0.002) - .containsEntry(VirusStrain.OMICRON_BA2, 0.825); + .containsEntry(VirusStrain.OMICRON_BA2, 0.823); } } From 3e5b11d6c9755f9896ea2e1564cd07afacf99273 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 3 Aug 2022 09:33:20 +0200 Subject: [PATCH 029/128] updated hospital post processing to include strainB --- .../analysis/HospitalNumbersFromEvents.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 18dfc56d1..d1daa8eea 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -96,7 +96,8 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { VirusStrain.OMICRON_BA1, 14, VirusStrain.OMICRON_BA2, 14, VirusStrain.OMICRON_BA5, 14, - VirusStrain.STRAIN_A, 14 + VirusStrain.STRAIN_A, 14, + VirusStrain.STRAIN_B, 14 )); // source: hospitalization wave vs. ICU wave in cologne/nrw (see https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit?usp=sharing) @@ -107,7 +108,8 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { VirusStrain.OMICRON_BA1, 6, VirusStrain.OMICRON_BA2, 6, VirusStrain.OMICRON_BA5, 6, - VirusStrain.STRAIN_A, 6 + VirusStrain.STRAIN_A, 6, + VirusStrain.STRAIN_B, 6 )); // Austria study in https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit#gid=0 @@ -118,7 +120,8 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { VirusStrain.OMICRON_BA1, 7, VirusStrain.OMICRON_BA2, 7, VirusStrain.OMICRON_BA5,7, - VirusStrain.STRAIN_A, 7 + VirusStrain.STRAIN_A, 7, + VirusStrain.STRAIN_B, 7 )); private static final Object2IntMap daysInICU = new Object2IntAVLTreeMap<>( @@ -128,7 +131,8 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { VirusStrain.OMICRON_BA1, 10, VirusStrain.OMICRON_BA2, 10, VirusStrain.OMICRON_BA5,10, - VirusStrain.STRAIN_A, 10 + VirusStrain.STRAIN_A, 10, + VirusStrain.STRAIN_B, 10 )); // ?? @@ -139,7 +143,8 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { VirusStrain.OMICRON_BA1, 60, VirusStrain.OMICRON_BA2, 60, VirusStrain.OMICRON_BA5,60, - VirusStrain.STRAIN_A, 60 + VirusStrain.STRAIN_A, 60, + VirusStrain.STRAIN_B, 60 )); @@ -721,6 +726,11 @@ private ConfigHolder configure(double facA, double facAICU) { strainConfig.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(facA); strainConfig.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(facAICU); + strainConfig.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(facA); + strainConfig.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(facAICU); + + + // configure vaccinationConfig: set beta factor VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); From ac2dda128dca54c9b20b296c99d0c7a80f03bf0b Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Wed, 3 Aug 2022 16:06:00 +0200 Subject: [PATCH 030/128] update bmbf runs --- .../matsim/run/batch/CologneBMBF20220805.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 309276895..7f764f30a 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -152,7 +152,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); @@ -166,7 +166,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); @@ -177,11 +177,11 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); @@ -194,9 +194,9 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); @@ -209,9 +209,9 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); @@ -223,11 +223,11 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / 1.4 / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscBa5); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); @@ -240,25 +240,25 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscBa5 / mutEscBa5); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); //StrainB - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNADelta); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNADelta * 150./300.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNADelta * 450./300.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, mRNADelta * 450./300.); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNADelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNADelta / mutEscBa1 / mutEscBa5); + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscBa5 / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscBa5 / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscBa5 / mutEscBa5); for (VaccinationType immunityType : VaccinationType.values()) { From a42d298be8641f4a50a9ec4e41c4d47204e5035f Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 10:25:07 +0200 Subject: [PATCH 031/128] 2022-08-02/3-vax --- .../progression/AntibodyDependentTransitionModel.java | 2 +- .../java/org/matsim/run/batch/CologneBMBF20220805.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index db92cacf5..627dd3346 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -155,7 +155,7 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup antibodiesAfterLastImmunityEvent *= 4; } // b) if strain is omicron, an additional factor of 3.7 is applied - if (strain.equals(VirusStrain.OMICRON_BA1) || strain.equals(VirusStrain.OMICRON_BA2) || strain.equals(VirusStrain.OMICRON_BA5) || strain.equals(VirusStrain.STRAIN_A)) { + if (strain.equals(VirusStrain.OMICRON_BA1) || strain.equals(VirusStrain.OMICRON_BA2) || strain.equals(VirusStrain.OMICRON_BA5) || strain.equals(VirusStrain.STRAIN_A) || strain.equals(VirusStrain.STRAIN_B)) { antibodiesAfterLastImmunityEvent *= 3.7; } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 7f764f30a..58f6cb58c 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -349,6 +349,7 @@ public Collection postProcessing() { new VaccinationEffectiveness().withArgs(), new RValuesFromEvents().withArgs(), new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input"), new SecondaryAttackRateFromEvents().withArgs() ); @@ -543,7 +544,7 @@ public Config prepareConfig(int id, Params params) { // vaccination VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); - vaccinationConfig.setUseIgA(Boolean.parseBoolean(params.igA)); + vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); vaccinationConfig.setTimePeriodIgA(730.); @@ -580,7 +581,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); - Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); // add initial impulses for strains @@ -700,8 +701,8 @@ public static final class Params { @StringParameter({"2022-12-01"}) public String resDate; - @StringParameter({"false", "true"}) - public String igA; +// @StringParameter({"false", "true"}) +// public String igA; // vaccination campaign @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) public String vacType; From b2af66dff6efd9a6579d61135b258d6ed198adf3 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 10:25:40 +0200 Subject: [PATCH 032/128] changed cross immunity --- .../model/InfectionModelWithAntibodies.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java index 66438fb50..0ce86be8d 100644 --- a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java +++ b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java @@ -109,9 +109,7 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto igaFactor = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); } else if (vaccinationConfig.getUseIgA()) { - List crossImmunityStrainsOmicron = List.of(VirusStrain.OMICRON_BA1,VirusStrain.OMICRON_BA2,VirusStrain.OMICRON_BA5,VirusStrain.STRAIN_A); - List crossImmunityStrainsDelta = List.of(VirusStrain.DELTA, VirusStrain.STRAIN_B); - + List crossImmunityStrainsOmicron = List.of(VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A, VirusStrain.STRAIN_B); if(crossImmunityStrainsOmicron.contains(infector.getVirusStrain())){ int lastInfectionWithStrain = 0; @@ -123,21 +121,6 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto } } - if (targetHadStrain) { - double fac = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); - fac = fac / 1.4; - igaFactor = Math.max(fac, igaFactor); - } - } else if(crossImmunityStrainsDelta.contains(infector.getVirusStrain())) { - int lastInfectionWithStrain = 0; - boolean targetHadStrain = false; - for (int ii = 0; ii < target.getNumInfections(); ii++) { - if (crossImmunityStrainsDelta.contains(target.getVirusStrain(ii))) { - targetHadStrain = true; - lastInfectionWithStrain = ii; - } - } - if (targetHadStrain) { double fac = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); fac = fac / 1.4; From dde0414f06eca1353a3ff5a730238e056fce86a4 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 10:26:25 +0200 Subject: [PATCH 033/128] update post processing script --- .../java/org/matsim/episim/analysis/FilterEvents.java | 2 +- .../matsim/episim/analysis/HospitalNumbersFromEvents.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/FilterEvents.java b/src/main/java/org/matsim/episim/analysis/FilterEvents.java index 5e44e6a87..c56fac278 100644 --- a/src/main/java/org/matsim/episim/analysis/FilterEvents.java +++ b/src/main/java/org/matsim/episim/analysis/FilterEvents.java @@ -30,7 +30,7 @@ public class FilterEvents implements OutputAnalysis { private static final Logger log = LogManager.getLogger(FilterEvents.class); - @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-27/4-eu/analysis") + @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-08-02/2-vax-b/analysis") // @CommandLine.Option(names = "--output", defaultValue = "./output/") private Path output; diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index d1daa8eea..4530fd4ac 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,7 +60,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-07-27/4-eu/analysis") + @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-08-02/3-vax/analysis") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -150,7 +150,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double beta = 1.2; - private static final double hospitalFactor = 0.20; + private static final double hospitalFactor = 0.3; // base private static final double factorWild = 1.0; @@ -158,10 +158,10 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double factorAlpha = 1.0 * factorWild; // delta: 2.3x more severe than alpha - Hospital admission and emergency care attendance risk for SARS-CoV-2 delta (B.1.617.2) compared with alpha (B.1.1.7) variants of concern: a cohort study - private static final double factorDelta = 1.0 * factorWild;//1.6 * factorWild; + private static final double factorDelta = 1.2 * factorWild;//1.6 * factorWild; // omicron: approx 0.3x (intrinsic) severity of delta - Comparative analysis of the risks of hospitalisation and death associated with SARS-CoV-2 omicron (B.1.1.529) and delta (B.1.617.2) variants in England: a cohort study - private static final double factorOmicron = 0.5 * factorDelta; // reportedShareOmicron / reportedShareDelta + private static final double factorOmicron = 0.3 * factorDelta; // reportedShareOmicron / reportedShareDelta private static final double factorBA5 = 1.5 * factorOmicron; From 196e0753c9f27614e685f19e04bbe701a2fa8900 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 10:37:24 +0200 Subject: [PATCH 034/128] update testing model to handle StrainB as an Omicron variant --- .../org/matsim/episim/model/testing/DefaultTestingModel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java index 676fd06e3..09b447c84 100644 --- a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java +++ b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java @@ -206,7 +206,8 @@ protected boolean testAndQuarantine(EpisimPerson person, int day, TestingConfigG if (params.getType().equals(TestType.RAPID_TEST) && (person.getVirusStrain() == VirusStrain.OMICRON_BA1 || person.getVirusStrain() == VirusStrain.OMICRON_BA2 || person.getVirusStrain() == VirusStrain.OMICRON_BA5 || - person.getVirusStrain() == VirusStrain.STRAIN_A)) { + person.getVirusStrain() == VirusStrain.STRAIN_A || + person.getVirusStrain() == VirusStrain.STRAIN_B)) { rate = 0.5; } From 87ffe7d83ce9673ec38495668acc23d3252f162c Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Thu, 4 Aug 2022 10:50:44 +0200 Subject: [PATCH 035/128] update bmbf runs --- .../matsim/run/batch/CologneBMBF20220805.java | 83 ++++++++++--------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 58f6cb58c..511e2ca4e 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -49,6 +49,7 @@ protected void configure() { double mutEscBa5 = 2.9; double mutEscStrainA = 0.; + double mutEscStrainB = 0.; LocalDate start = null; VaccinationType vaccinationType = VaccinationType.mRNA; @@ -68,8 +69,12 @@ protected void configure() { vacCamp = "age"; vaccinationType = VaccinationType.valueOf(params.vacType); } - - mutEscStrainA = params.strAEsc; + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } start = LocalDate.parse(params.resDate); @@ -99,7 +104,7 @@ else if (vacCamp.equals("off")) { //initial antibodies Map> initialAntibodies = new HashMap<>(); Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); @@ -114,7 +119,7 @@ else if (vacCamp.equals("off")) { private void configureAntibodies(Map> initialAntibodies, Map> antibodyRefreshFactors, - double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA) { + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { for (VaccinationType immunityType : VaccinationType.values()) { initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -196,7 +201,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); @@ -211,7 +216,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); @@ -227,7 +232,7 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); @@ -242,23 +247,24 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscBa5 / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); //StrainB - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNABa5); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNABa5 * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNABa5 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscBa5); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscBa5); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscBa5 / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscBa5 / mutEscBa5); + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscBa5); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscBa5 / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); for (VaccinationType immunityType : VaccinationType.values()) { @@ -399,18 +405,18 @@ public Config prepareConfig(int id, Params params) { // STRAIN_A - if (params.strAInf != 0.) { + if (!params.StrainA.equals("off")) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf * params.strAInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); } // STRAIN_B - if (params.strBInf != 0.) { + if (!params.StrainB.equals("off")) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf * params.strBInf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); @@ -608,7 +614,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi infPerDayBa5.put(ba5Date.plusDays(7), 1); //StrainA - if (params.strAInf != 0.) { + if (!params.StrainA.equals("off")) { infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); LocalDate strADate = LocalDate.parse("2022-11-01"); for (int i = 0; i < 7; i++) { @@ -618,7 +624,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } //StrainB - if (params.strBInf != 0.) { + if (!params.StrainB.equals("off")) { infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); LocalDate strBDate = LocalDate.parse("2022-11-01"); for (int i = 0; i < 7; i++) { @@ -646,15 +652,15 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi // double cases = factor * entry.getValue(); - if (date.isAfter(dateStrainAB) && (params.strAInf != 0 || params.strBInf != 0)) { - if (params.strAInf != 0 && params.strBInf != 0) { + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); } - else if (params.strAInf != 0) { + else if (!params.StrainA.equals("off")) { infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); } - else if (params.strBInf != 0) { + else if (!params.StrainB.equals("off")) { infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); } else { @@ -676,10 +682,10 @@ else if (params.strBInf != 0) { episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); - if (params.strAInf != 0.) { + if (!params.StrainA.equals("off")) { episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); } - if (params.strBInf != 0.) { + if (!params.StrainB.equals("off")) { episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); } } @@ -688,15 +694,12 @@ public static final class Params { // general @GenerateSeeds(5) public long seed; - - @Parameter({3.0, 6.0}) - public double strAEsc; - - @Parameter({0.0, 1.0}) - public double strAInf; - - @Parameter({0.0, 1.0}) - public double strBInf; + + @StringParameter({"off", "3.0", "6.0"}) + public String StrainA; + + @StringParameter({"off", "3.0", "6.0"}) + public String StrainB; @StringParameter({"2022-12-01"}) public String resDate; From f313c21f4908e1392a371a7012631405fd136f47 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 11:24:43 +0200 Subject: [PATCH 036/128] jakob/2022-08-04/1-vax --- .../episim/analysis/HospitalNumbersFromEvents.java | 9 +++++---- .../org/matsim/episim/analysis/RValuesFromEvents.java | 1 - .../java/org/matsim/run/batch/CologneBMBF20220805.java | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 4530fd4ac..336e7ce0a 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,7 +60,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-08-02/3-vax/analysis") + @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-08-02/3-vax/analysis/strainA") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -216,7 +216,8 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, outputAppendix, startDate, "Omicron"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); // } @@ -256,8 +257,8 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t BufferedWriter bw = Files.newBufferedWriter(tsvPath); bw.write(AnalysisCommand.TSV.join(DAY, DATE,"measurement", "severity", "n")); // + "\thospNoImmunity\thospBaseImmunity\thospBoosted\tincNoImmunity\tincBaseImmunity\tincBoosted")); - ConfigHolder holderOmicron = configure(factorOmicron,factorOmicronICU) ; - ConfigHolder holderDelta = configure(factorDelta,factorDeltaICU) ; + ConfigHolder holderOmicron = configure(factorBA5, factorBA5ICU); + ConfigHolder holderDelta = configure(factorDelta, factorDeltaICU); List handlers = List.of( new Handler("Omicron", population, holderOmicron ), diff --git a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java index e06472b4d..6de4fffda 100644 --- a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java @@ -209,7 +209,6 @@ private static class RHandler implements EpisimPersonStatusEventHandler, EpisimI /** * If a person is infected another time it will be removed from {@link #infectedPersons} and put here. - * TODO: what happens if person is infected >2x? */ private final List handledInfections = new ArrayList<>(); diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java index 511e2ca4e..9b5267e15 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805.java @@ -356,8 +356,8 @@ public Collection postProcessing() { new RValuesFromEvents().withArgs(), new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), new FilterEvents().withArgs("--output","./output/"), - new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input"), - new SecondaryAttackRateFromEvents().withArgs() + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() ); } @@ -694,10 +694,10 @@ public static final class Params { // general @GenerateSeeds(5) public long seed; - + @StringParameter({"off", "3.0", "6.0"}) public String StrainA; - + @StringParameter({"off", "3.0", "6.0"}) public String StrainB; From acc544707fd906f19ca67f4a656f9c83751a2d00 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 14:13:13 +0200 Subject: [PATCH 037/128] new batch, jakob/2022-08-04/2-ifsg --- .../analysis/HospitalNumbersFromEvents.java | 8 +- .../HospitalNumbersFromEventsPlotter.java | 4 +- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../run/batch/CologneBMBF20220805_IfSG.java | 987 ++++++++++++++++++ 4 files changed, 994 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 336e7ce0a..f27cda57d 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -173,8 +173,6 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double factorOmicronICU = 1.; private static final double factorBA5ICU = 1.; - private String outputAppendix = ""; - public static void main(String[] args) { System.exit(new CommandLine(new HospitalNumbersFromEvents()).execute(args)); } @@ -216,8 +214,8 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); // } @@ -235,7 +233,7 @@ public void analyzeOutput(Path pathToScenario) throws IOException { String id = AnalysisCommand.getScenarioPrefix(pathToScenario); // builds the path to the output file that is produced by this analysis - final Path tsvPath = pathToScenario.resolve(id + "post.hospital" + outputAppendix + ".tsv"); + final Path tsvPath = pathToScenario.resolve(id + "post.hospital.tsv"); // calculates hospitalizations calculateHospitalizationsAndWriteOutput(pathToScenario, tsvPath); diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java index 0f5635581..5de57065d 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java @@ -63,7 +63,7 @@ static void aggregateAndProducePlots(Path output, List pathList, String ou String id = AnalysisCommand.getScenarioPrefix(path); - final Path tsvPath = path.resolve(id + "post.hospital" + outputAppendix + ".tsv"); + final Path tsvPath = path.resolve(id + "post.hospital.tsv"); try (CSVParser parser = new CSVParser(Files.newBufferedReader(tsvPath), CSVFormat.DEFAULT.withDelimiter('\t').withFirstRecordAsHeader())) { @@ -340,7 +340,7 @@ static void aggregateAndProducePlots(Path output, List pathList, String ou // Produce TSV w/ aggregated data as well as all rki numbers - try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(output.resolve("post.hospital.agg" + outputAppendix + ".tsv")), CSVFormat.DEFAULT.withDelimiter('\t'))) { + try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(output.resolve("post.hospital.agg.tsv")), CSVFormat.DEFAULT.withDelimiter('\t'))) { printer.printRecord(DAY, DATE, INTAKES_HOSP, INTAKES_ICU, OCCUPANCY_HOSP, OCCUPANCY_ICU, "rkiIncidence", "rkiHospRate", "rkiCriticalRate"); //"hospNoImmunity", "hospBaseImmunity", "hospBoosted", "incNoImmunity", "incBaseImmunity", "incBoosted"); diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index e5adb286d..243c94955 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20220805") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_IfSG") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20220805$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_IfSG$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java new file mode 100644 index 000000000..17a72c694 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java @@ -0,0 +1,987 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.testing.FlexibleTestingModel; +import org.matsim.episim.model.testing.TestType; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.*; +import java.util.function.BiFunction; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF20220805_IfSG implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // BIND ANTIBODY MODEL + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 2.9; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + if (params != null && !params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (params != null && !params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } + + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + + // BIND VACCINATION MODEL + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + LocalDate start = LocalDate.parse("2022-12-01"); + + VaccinationType vaccinationType = VaccinationType.mRNA; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + String vacCamp = "off"; + + if (params != null) { + + if (!params.vacType.equals("off")) { + vacCamp = "age"; + vaccinationType = VaccinationType.valueOf(params.vacType); + } + +// start = LocalDate.parse(params.resDate); + + + switch (vacCamp) { + case "age": + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + break; + case "eu": + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + break; + case "off": + break; + default: + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } + + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + + + // BIND TESTING MODEL + if (params != null){ + + // date of no restrictions and new restrictions + String unResDate = "2022-04-25"; + LocalDate unresDate = LocalDate.parse(unResDate); + LocalDate resDate = LocalDate.parse(params.resDate); + +// String[] s = params.gpMonths.split("-"); + + // Green pass validity for vaccinated and infected +// int vacDays = Integer.parseInt(s[0]) * 30; +// int infDays = Integer.parseInt(s[1]) * 30; + + // set days gp is valid + int vacDays = 3 * 30; + int infDays = 3 * 30; + + // set testing scheme for each activity type + final CologneBMBF220628_3G.TestScheme leisTest; + final CologneBMBF220628_3G.TestScheme workTest; + final CologneBMBF220628_3G.TestScheme eduTest; + if (params.leis.equals("test") || params.leis.equals("all")) { + leisTest= CologneBMBF220628_3G.TestScheme.gp; + } else if (params.leis.equals("none") || params.leis.equals("mask")) { + leisTest = CologneBMBF220628_3G.TestScheme.none; + } else { + throw new RuntimeException(); + } + + + if (params.work.equals("test") || params.work.equals("all")) { + workTest= CologneBMBF220628_3G.TestScheme.all; + } else if (params.work.equals("none") || params.work.equals("mask")|| params.work.equals("homeOff")) { + workTest = CologneBMBF220628_3G.TestScheme.none; + } else { + throw new RuntimeException(); + } + + if (params.edu.equals("maskVentTest")) { + eduTest = CologneBMBF220628_3G.TestScheme.all; + } else if (params.edu.equals("none")) { + eduTest = CologneBMBF220628_3G.TestScheme.none; + } else {throw new RuntimeException();} + + bind(FlexibleTestingModel.TestRate.class).toInstance((person, day, dow, date, test, vac) -> { + + if (date.isBefore(unresDate)) + return vac.hasValidVaccination(person, day, date); + + // When restrictions have been lifted, days valid is set to a high number + // many tests are voluntary + if (date.isBefore(resDate)) + return vac.hasValidVaccination(person, day, date, 360); + + // this returns true if for any activities, the person requires increased testing regime + BiFunction anyUnVac = (act, red) -> { + + boolean res = false; + CologneBMBF220628_3G.TestScheme scheme = null; + + + if (act.equals("leisure")) + scheme = leisTest; + else if (act.equals("work")) + scheme = workTest; + else if (act.startsWith("edu")) + scheme = eduTest; + + // null and none, will be false + if (scheme == CologneBMBF220628_3G.TestScheme.all) + res = true; + else if (scheme == CologneBMBF220628_3G.TestScheme.gp) { + res = (person.getNumVaccinations() == 0 || person.daysSince(EpisimPerson.VaccinationStatus.yes, day) > vacDays) + && !person.isRecentlyRecovered(day, infDays); + + } + + return red || res; + }; + + return !person.matchActivities(dow, anyUnVac, false); + }); + + bind(FlexibleTestingModel.TestPolicy.class).toInstance(new FlexibleTestingModel.TestPolicy() { + @Override + public boolean shouldTest(EpisimPerson person, int day, DayOfWeek dow, LocalDate date, + TestingConfigGroup test, VaccinationConfigGroup vac) { + + if (date.isBefore(unresDate)) { + + boolean testAllPersons = test.getTestAllPersonsAfter() != null && date.isAfter(test.getTestAllPersonsAfter()); + return testAllPersons || !vac.hasGreenPass(person, day, date); + } + + // after restrictions everybody is tested according to the rates + return true; + } + }); + + } + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + + +// System.out.print("immunityGiver"); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// if (immunityFrom == VirusStrain.OMICRON_BA1) { +// System.out.print( "," + "BA.1"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { +// System.out.print( "," + "BA.2"); +// } else { +// System.out.print( "," + immunityFrom); +// } +// } +// +// +// for (ImmunityEvent immunityGiver : VaccinationType.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// for (ImmunityEvent immunityGiver : VirusStrain.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// +// System.out.println(); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2); + + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + +// virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); + + //BA5 + double ba5Inf = 1.0; + double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); + } + +// STRAIN_B + if (!params.StrainB.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); + } + + // remove age-based susceptibility of strains starting with DELTA + + String ageSusc = "false"; + if (!Boolean.parseBoolean(ageSusc)) { + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : List.of(VirusStrain.DELTA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A)) { + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } + } + + // increase infectivity of alpha + virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * 1.4); + + double deltaTheta = 0.9; + virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * deltaTheta); + double ba1Inf = 1.9; // 2.0,2.1,2.2 + double ba2Inf = 1.7; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); + + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + Map infPerDayAlpha = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.ALPHA, new TreeMap<>())); + + + // reconfig disease import of alpha + LocalDate startDateAlpha = LocalDate.parse("2021-01-15"); + + for (int i = 0; i < 7; i++) { + infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); + } + + + infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); + + episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); + + + configureFutureDiseaseImport(params, episimConfig); + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + //school + String schoolUpdate = "yes"; + if(schoolUpdate.equals("yes")) { + // school closed completely until 21.2.2022 + builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); + builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + } else if (schoolUpdate.equals("no")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + String schoolTest = "later"; + if (schoolTest.equals("later")) { + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); +// TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); +// Map> testingRateForActivitiesPCR = pcrTest.getTestingRateForActivities(); + + + for (LocalDate date = LocalDate.parse("2021-03-19"); date.isBefore(LocalDate.parse("2021-04-25")); date = date.plusDays(1)) { + + testingRateForActivitiesRapid.get("educ_kiga").put(date, 0.); + testingRateForActivitiesRapid.get("educ_primary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_secondary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_tertiary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_other").put(date, 0.); + + } + + testingRateForActivitiesRapid.get("educ_kiga").put(LocalDate.parse("2021-09-20"), 0.); + testingRateForActivitiesRapid.get("educ_primary").put(LocalDate.parse("2021-09-20"), 0.); + +// testingRateForActivitiesPCR.get("educ_primary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_secondary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); + + } else if (schoolTest.equals("base")) { + + }else { + throw new RuntimeException("param value doesn't exist"); + } + + + // masks + //pt: masks + String maskType = "45to45"; + if (maskType.equals("45to45")) { + for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { + builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); + + } + } else if (maskType.equals("base")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + // ----------------------------------------- + + // new restrictions from IfSG + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + // testing rates + + double gpTestRate = 0.; + + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesPcr = pcrTest.getTestingRateForActivities(); + Map> testingRateForActivitiesPcrVac = pcrTest.getTestingRateForActivitiesVaccinated(); + + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); + Map> testingRateForActivitiesRapidVac = rapidTest.getTestingRateForActivitiesVaccinated(); + + + // school + { + //pcr tests for younger kids + testingRateForActivitiesPcr.get("educ_kiga").put(restrictionDate, 0.4); + testingRateForActivitiesPcr.get("educ_primary").put(restrictionDate, 0.4); + testingRateForActivitiesPcrVac.get("educ_kiga").put(restrictionDate, gpTestRate); + testingRateForActivitiesPcrVac.get("educ_primary").put(restrictionDate, gpTestRate); + + //add rapid tests for older kids + testingRateForActivitiesRapid.get("educ_secondary").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_tertiary").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_higher").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_other").put(restrictionDate, 0.6); + testingRateForActivitiesRapidVac.get("educ_secondary").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_tertiary").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_higher").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_other").put(restrictionDate, gpTestRate); + } + + // work + { + testingRateForActivitiesRapid.get("work").put(restrictionDate, 0.6); + testingRateForActivitiesRapidVac.get("work").put(restrictionDate, gpTestRate); + } + + // leisure: + { + testingRateForActivitiesRapid.get("leisure").put(restrictionDate, 0.45); + testingRateForActivitiesRapidVac.get("leisure").put(restrictionDate, gpTestRate); + } + + //WORK + double homeOfficeFactor = 0.5; + switch (params.work) { + case "none": + break; + case "homeOff": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "test": + // handled in getBindings + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.9)), "work", "business"); + break; + case "all": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //LEISURE + switch (params.leis) { + case "none": + break; + case "test": + // handled in getBindings + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45)), "leisure"); + case "all": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45)), "leisure"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // shop, errands + switch (params.errands) { + case "none": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //SCHOOL + // todo check mask rate + if (params.edu.equals("maskVentTest")) { + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.25, + FaceMask.SURGICAL, 0.25)), + "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); + + } else if (params.edu.equals("none")) { + + } else { + throw new RuntimeException("invalid parameter"); + } + + + // pt + switch (params.pt) { + case "none": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + // vaccination + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); + vaccinationConfig.setTimePeriodIgA(730.); + + + //modify contact intensity + double workCi = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); + + + double leisureCi = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); + + + double schoolCi = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + + // add initial impulses for strains + //BA.1 +// LocalDate ba1Date = LocalDate.parse(params.ba1Date); +// for (int i = 0; i < 7; i++) { +// infPerDayBa1.put(ba1Date.plusDays(i), 4); +// } +// infPerDayBa1.put(ba1Date.plusDays(7), 1); + + + //BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + //BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB + if (!params.StrainB.equals("off")) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + + + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + if (!params.StrainB.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + @StringParameter({"6.0"}) + public String StrainA; + + @StringParameter({"off"}) + public String StrainB; + + @StringParameter({"2022-10-01"}) + public String resDate; + + // @StringParameter({"false", "true"}) +// public String igA; + // vaccination campaign + @StringParameter({"ba5Update", "mRNA", "off"}) + public String vacType; + + + //measures in the work context: + // homeOff = 50% home office = work Rf cut in half + // + @StringParameter({"none", "homeOff", "test", "mask", "all"}) + public String work; + + @StringParameter({"none", "mask", "test", "all"}) + public String leis; + + // mask restrictions for "shop_daily", "shop_other", "errands" + @StringParameter({"none", "mask"}) + public String errands; + + @StringParameter({"none", "maskVentTest"}) + public String edu; + + @StringParameter({"mask"}) + public String pt; + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF20220805_IfSG.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + From dfc758fbfdf74cc1546beb7b65966cfcb1f99ee9 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Thu, 4 Aug 2022 15:06:30 +0200 Subject: [PATCH 038/128] add mobility and weather script --- src/main/R/mobilityAndWeather.R | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/main/R/mobilityAndWeather.R diff --git a/src/main/R/mobilityAndWeather.R b/src/main/R/mobilityAndWeather.R new file mode 100644 index 000000000..7cc6fd72b --- /dev/null +++ b/src/main/R/mobilityAndWeather.R @@ -0,0 +1,68 @@ +library(tidyverse) +library(lubridate) +library (RCurl) +library(gridExtra) + + +# Weather Data +weatherData <- read_delim("https://bulk.meteostat.net/daily/10382.csv.gz", delim = ",", col_names = FALSE, col_types = cols( + X1 = col_date(format = ""), + X2 = col_double(), + X3 = col_double(), + X4 = col_double(), + X5 = col_double(), + X6 = col_double(), + X7 = col_double(), + X8 = col_double(), + X9 = col_double(), + X10 = col_double(), + X11 = col_double() +)) +colnames(weatherData) <- c("date", "tavg", "tmin", "tmax", "prcp", "snow", "wdir", "wspd", "wpgt", "pres", "tsun") + +weatherDataByWeek <- weatherData %>% + mutate( week = paste0(isoweek(date), "-", isoyear(date))) %>% + group_by( week ) %>% + summarize( date=mean(date), tavg=mean(tavg), tmin=mean(tmin), tmax=mean(tmax), prcp=mean(prcp), snow=mean(snow), wdir=mean(wdir), wspd=mean(wspd), wpgt=mean(wpgt), pres=mean(pres), tsun=mean(tsun)) + + +# Google Mobility Report +googleMobilityReportRaw <- read_csv(getURL("https://www.gstatic.com/covid19/mobility/Global_Mobility_Report.csv")) + +googleMobilityReport <- googleMobilityReportRaw %>% + filter(sub_region_1 == "Berlin") %>% + select(-c(country_region_code, country_region, sub_region_1, sub_region_2, metro_area, iso_3166_2_code, census_fips_code, place_id)) %>% + mutate(notAtHome = -residential_percent_change_from_baseline) %>% + pivot_longer(!date, names_to = "type", values_to = "restriction") %>% + filter(type == "notAtHome") %>% + mutate(weekday = wday(date, week_start = 1)) %>% + filter(weekday < "6") %>% + mutate( week = paste0(isoweek(date), "-", isoyear(date))) %>% + group_by( week, type ) %>% + summarize( restriction=mean(restriction), date=mean(date)) + +# Senozon Restrictions +snzRestrictionsFile <- "BerlinSnzData_daily_until20220204.csv" +svnLocation <- "/Users/sebastianmuller/git/shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/" + +snzRestrictions <- read_delim(paste0(svnLocation, snzRestrictionsFile), delim = "\t") %>% + pivot_longer(!date, names_to = "type", values_to = "restriction") %>% + mutate(newDate = as.Date(strptime(date, "%Y%m%d"))) %>% + mutate(weekday = wday(newDate, week_start = 1)) %>% + filter(weekday < "6") %>% + filter(type == "notAtHome") %>% + mutate( week = paste0(isoweek(newDate), "-", isoyear(newDate))) %>% + group_by( week, type ) %>% + summarize( restriction=mean(restriction), newDate=mean(newDate)) + +# Google Mobility and weather +ggplot() + + geom_point(data = googleMobilityReport, mapping=aes(x = date, y = restriction), colour = "red") + + geom_point(data = snzRestrictions, mapping=aes(x = newDate, y = restriction), colour = "blue") + + geom_point(data = weatherDataByWeek, mapping=aes(x = date, y = tmax), colour = "black") + + theme(legend.position = "bottom") + + xlim(c(as.Date("2020-02-24"), as.Date("2022-07-30"))) + + labs( + title="Time spent not at home (google and senozon) and max temperature (Berlin)", + caption="Source: Google, Senozon", + x="date", y="Reduction in % / tmax") From a43cba72e1cfb5e26a6b1e70995beb0e8ced6d3a Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 15:35:51 +0200 Subject: [PATCH 039/128] added pre-processing script to randomly split leisure into leisPublic and leisPrivate --- ...tiateLeisureActivitiesInEventsCologne.java | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java diff --git a/src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java b/src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java new file mode 100644 index 000000000..c2703ead7 --- /dev/null +++ b/src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java @@ -0,0 +1,180 @@ +package org.matsim.scenarioCreation; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.*; +import org.matsim.api.core.v01.events.handler.ActivityEndEventHandler; +import org.matsim.api.core.v01.events.handler.ActivityStartEventHandler; +import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; +import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.EventsUtils; +import org.matsim.core.events.algorithms.EventWriterXML; +import org.matsim.core.utils.io.IOUtils; +import org.matsim.facilities.ActivityFacility; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +/* +appends living space to "home" activities in events file, +e.g. home_35 indicates that agent has between 30 and 40 m2 of living space. + */ +public class DifferentiateLeisureActivitiesInEventsCologne { + + public static final String ROOT = "../shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input/"; + private static final int SAMPLE = 25; + + public static void main(String[] args) throws IOException { + + // collect event files + List eventFiles = new ArrayList<>(); + + eventFiles.add(ROOT + "cologne_snz_episim_events_wt_"+ SAMPLE +"pt_split.xml.gz"); + eventFiles.add(ROOT + "cologne_snz_episim_events_sa_"+ SAMPLE +"pt_split.xml.gz"); + eventFiles.add(ROOT + "cologne_snz_episim_events_so_"+ SAMPLE +"pt_split.xml.gz"); + + + // 1) get list of all facilities where leisure events take place + + Set leisureFacilitiesFullWeek = new HashSet<>(); + + for (String events : eventFiles) { + + EventsManager manager = EventsUtils.createEventsManager(); + + FacilityFinder handler = new FacilityFinder(); + + manager.addHandler(handler); + EventsUtils.readEvents(manager, events); + + leisureFacilitiesFullWeek.addAll(handler.leisureFacilities); + } + + // 2) make list of facilities assigned to leisPrivate & leisPublic + Set facilitiesPublic = new HashSet<>(); + Set facilitiesPrivate = new HashSet<>(); + + Random rnd = new Random(4711); + for (String facility : leisureFacilitiesFullWeek) { + if (rnd.nextDouble() > 0.5) { + facilitiesPublic.add(facility); + } else { + facilitiesPrivate.add(facility); + } + } + + + // 3) process events to replace all leisure activity types + for (String events : eventFiles) { + + EventsManager manager = EventsUtils.createEventsManager(); + + LeisureSplitter handler = new LeisureSplitter(facilitiesPublic,facilitiesPrivate); + + manager.addHandler(handler); + EventsUtils.readEvents(manager, events); + + + String outputName =events.replace(".xml.gz", "") + "_withLeisureSplit.xml.gz"; + + EventWriterXML writer = new EventWriterXML( + IOUtils.getOutputStream(IOUtils.getFileUrl(outputName), false) + ); + + handler.modifiedEvents.forEach(writer::handleEvent); + writer.closeFile(); + + } + + } + + public static class FacilityFinder implements ActivityEndEventHandler, ActivityStartEventHandler{ + + Set leisureFacilities = new HashSet<>(); + + @Override + public void handleEvent(ActivityEndEvent activityEndEvent) { + if (activityEndEvent.getActType().equals("lesiure")) { + leisureFacilities.add(activityEndEvent.getFacilityId().toString()); + } + + } + + @Override + public void handleEvent(ActivityStartEvent activityStartEvent) { + if (activityStartEvent.getActType().equals("lesiure")) { + leisureFacilities.add(activityStartEvent.getFacilityId().toString()); + } + } + } + + + public static class LeisureSplitter implements ActivityEndEventHandler, ActivityStartEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler { + final List modifiedEvents = new ArrayList<>(); + + final Set facilitiesPublic; + final Set facilitiesPrivate; + + LeisureSplitter(Set facilitiesPublic, Set facilitiesPrivate) { + this.facilitiesPublic = facilitiesPublic; + this.facilitiesPrivate = facilitiesPrivate; + } + + @Override + public void handleEvent(ActivityEndEvent activityEndEvent) { + Id facilityId = activityEndEvent.getFacilityId(); + + String actType = activityEndEvent.getActType(); + actType = getModifiedLeisureAct(facilityId, actType); + + ActivityEndEvent modifiedEvent = new ActivityEndEvent(activityEndEvent.getTime(), + activityEndEvent.getPersonId(), + activityEndEvent.getLinkId(), + facilityId, + actType); + + modifiedEvents.add(modifiedEvent); + } + + + @Override + public void handleEvent(ActivityStartEvent activityStartEvent) { + Id facilityId = activityStartEvent.getFacilityId(); + String actType = activityStartEvent.getActType(); + + actType = getModifiedLeisureAct(facilityId, actType); + ActivityStartEvent modifiedEvent = new ActivityStartEvent(activityStartEvent.getTime(), + activityStartEvent.getPersonId(), + activityStartEvent.getLinkId(), + facilityId, + actType); + + modifiedEvents.add(modifiedEvent); + } + + private String getModifiedLeisureAct(Id facilityId, String actType) { + if (actType.equals("leisure")) { + if (facilitiesPublic.contains(facilityId.toString())) { + actType = "leisPublic"; + } else if (facilitiesPrivate.contains(facilityId.toString())) { + actType = "leisPrivate"; + } else { + throw new RuntimeException("all leisure facilities should have been designated either public or private"); + } + + } + return actType; + } + + @Override + public void handleEvent(PersonEntersVehicleEvent personEntersVehicleEvent) { + modifiedEvents.add(personEntersVehicleEvent); + } + + @Override + public void handleEvent(PersonLeavesVehicleEvent personLeavesVehicleEvent) { + modifiedEvents.add(personLeavesVehicleEvent); + } + } +} From d0d216c773a41f828934ae7a103a3f5b982c6e8b Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 18:47:16 +0200 Subject: [PATCH 040/128] went through entire code to add actType "leisPrivate" & "leisPublic" with the exact same attributes as as "leisure" --- .../analysis/REAnalyzeTimelineOfEvents.java | 176 +-- .../episim/analysis/RValuesFromEvents.java | 4 +- .../input/CreateRestrictionsFromSnz.java | 8 +- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../batch/CologneBMBF20220805_leisSplit.java | 1006 +++++++++++++++++ .../run/modules/AbstractSnzScenario.java | 4 + .../modules/SnzCologneProductionScenario.java | 71 +- .../run/modules/SnzProductionScenario.java | 2 + ...tiateLeisureActivitiesInEventsCologne.java | 6 +- 9 files changed, 1159 insertions(+), 122 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java diff --git a/src/main/java/org/matsim/episim/analysis/REAnalyzeTimelineOfEvents.java b/src/main/java/org/matsim/episim/analysis/REAnalyzeTimelineOfEvents.java index baf2bc6d1..3a833cdf1 100644 --- a/src/main/java/org/matsim/episim/analysis/REAnalyzeTimelineOfEvents.java +++ b/src/main/java/org/matsim/episim/analysis/REAnalyzeTimelineOfEvents.java @@ -1,88 +1,88 @@ -package org.matsim.episim.analysis; - -import java.util.HashMap; -import java.util.Map; - -import org.matsim.api.core.v01.events.ActivityEndEvent; -import org.matsim.api.core.v01.events.handler.ActivityEndEventHandler; -import org.matsim.api.core.v01.population.Population; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.events.EventsUtils; -import org.matsim.core.events.MatsimEventsReader; -import org.matsim.core.population.PopulationUtils; - -public class REAnalyzeTimelineOfEvents { - - private final static Map> mapOfActivityEnds = new HashMap<>(); - private static int numberEndAct = 0; - private static Population population; - - public static void main(String[] args) { -// String inputFileEvents = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_episim_events_wt_25pt_split.xml.gz"; - String inputFileEvents = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_episim_events_sa_25pt_split.xml.gz"; -// String inputFileEvents = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_episim_events_so_25pt_split.xml.gz"; - String inputFilePop = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_entirePopulation_emptyPlans_withDistricts_25pt_split.xml.gz"; - - population = PopulationUtils.readPopulation(inputFilePop); - - EventsManager events = EventsUtils.createEventsManager(); - - REActivityTimelinenEventHandler reActivityDurationEventHandler = new REActivityTimelinenEventHandler(); - - events.addHandler(reActivityDurationEventHandler); - - MatsimEventsReader reader = new MatsimEventsReader(events); - - reader.readFile(inputFileEvents); - - for (int i = 0; i < Types.values().length; i++) { - System.out.print(Types.values()[i].toString() + ";"); - } - - for (Integer hours = 0; hours < 30; hours++) { - System.out.println(); - System.out.print(hours + ";"); - for (int i = 0; i < Types.values().length; i++) { - - String actType = Types.values()[i].toString(); - if (mapOfActivityEnds.get(actType).containsKey(hours)) - System.out.print(mapOfActivityEnds.get(actType).get(hours) * 4 + ";"); - else - System.out.print(0 + ";"); - } - System.out.println(); - } - System.out.println("Gesamt: " + numberEndAct * 4); - - } - - private static class REActivityTimelinenEventHandler implements ActivityEndEventHandler { - - @Override - public void handleEvent(ActivityEndEvent event) { - - if (population.getPersons().get(event.getPersonId()).getAttributes().getAttribute("district") != null - && population.getPersons().get(event.getPersonId()).getAttributes().getAttribute("district") - .toString().equals("Berlin")) { - numberEndAct++; - Integer beginningHour = Integer.valueOf((int) Math.floor(event.getTime() / 3600)); - if (mapOfActivityEnds.containsKey(event.getActType())) - if (mapOfActivityEnds.get(event.getActType()).containsKey(beginningHour)) - mapOfActivityEnds.get(event.getActType()).put(beginningHour, - mapOfActivityEnds.get(event.getActType()).get(beginningHour) + 1); - else { - mapOfActivityEnds.get(event.getActType()).put(beginningHour, 1); - } - else { - mapOfActivityEnds.put(event.getActType(), new HashMap<>()); - mapOfActivityEnds.get(event.getActType()).put(beginningHour, 1); - } - } - } - } - - private enum Types { - educ_kiga, business, errands, home, leisure, shop_daily, shop_other, visit, work, educ_higher, educ_tertiary, - educ_other, educ_primary, educ_secondary - } -} +package org.matsim.episim.analysis; + +import java.util.HashMap; +import java.util.Map; + +import org.matsim.api.core.v01.events.ActivityEndEvent; +import org.matsim.api.core.v01.events.handler.ActivityEndEventHandler; +import org.matsim.api.core.v01.population.Population; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.EventsUtils; +import org.matsim.core.events.MatsimEventsReader; +import org.matsim.core.population.PopulationUtils; + +public class REAnalyzeTimelineOfEvents { + + private final static Map> mapOfActivityEnds = new HashMap<>(); + private static int numberEndAct = 0; + private static Population population; + + public static void main(String[] args) { +// String inputFileEvents = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_episim_events_wt_25pt_split.xml.gz"; + String inputFileEvents = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_episim_events_sa_25pt_split.xml.gz"; +// String inputFileEvents = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_episim_events_so_25pt_split.xml.gz"; + String inputFilePop = "../shared-svn/projects/episim/matsim-files/snz/BerlinV2/episim-input/be_2020-week_snz_entirePopulation_emptyPlans_withDistricts_25pt_split.xml.gz"; + + population = PopulationUtils.readPopulation(inputFilePop); + + EventsManager events = EventsUtils.createEventsManager(); + + REActivityTimelinenEventHandler reActivityDurationEventHandler = new REActivityTimelinenEventHandler(); + + events.addHandler(reActivityDurationEventHandler); + + MatsimEventsReader reader = new MatsimEventsReader(events); + + reader.readFile(inputFileEvents); + + for (int i = 0; i < Types.values().length; i++) { + System.out.print(Types.values()[i].toString() + ";"); + } + + for (Integer hours = 0; hours < 30; hours++) { + System.out.println(); + System.out.print(hours + ";"); + for (int i = 0; i < Types.values().length; i++) { + + String actType = Types.values()[i].toString(); + if (mapOfActivityEnds.get(actType).containsKey(hours)) + System.out.print(mapOfActivityEnds.get(actType).get(hours) * 4 + ";"); + else + System.out.print(0 + ";"); + } + System.out.println(); + } + System.out.println("Gesamt: " + numberEndAct * 4); + + } + + private static class REActivityTimelinenEventHandler implements ActivityEndEventHandler { + + @Override + public void handleEvent(ActivityEndEvent event) { + + if (population.getPersons().get(event.getPersonId()).getAttributes().getAttribute("district") != null + && population.getPersons().get(event.getPersonId()).getAttributes().getAttribute("district") + .toString().equals("Berlin")) { + numberEndAct++; + Integer beginningHour = Integer.valueOf((int) Math.floor(event.getTime() / 3600)); + if (mapOfActivityEnds.containsKey(event.getActType())) + if (mapOfActivityEnds.get(event.getActType()).containsKey(beginningHour)) + mapOfActivityEnds.get(event.getActType()).put(beginningHour, + mapOfActivityEnds.get(event.getActType()).get(beginningHour) + 1); + else { + mapOfActivityEnds.get(event.getActType()).put(beginningHour, 1); + } + else { + mapOfActivityEnds.put(event.getActType(), new HashMap<>()); + mapOfActivityEnds.get(event.getActType()).put(beginningHour, 1); + } + } + } + } + + private enum Types { + educ_kiga, business, errands, home, leisure, leisPrivate, leisPublic, shop_daily, shop_other, visit, work, educ_higher, educ_tertiary, + educ_other, educ_primary, educ_secondary + } +} diff --git a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java index 6de4fffda..cdefe1f7e 100644 --- a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java @@ -66,7 +66,7 @@ public class RValuesFromEvents implements OutputAnalysis { * Activity types used by this analysis. */ private static final List ACTIVITY_TYPES = List.of( - "home", "leisure", "schools", "day care", "university", "work&business", "pt", "other" + "home", "leisure", "leisPrivate", "leisPublic", "schools", "day care", "university", "work&business", "pt", "other" ); @CommandLine.Option(names = "--output", defaultValue = "./output/") @@ -286,6 +286,8 @@ private static String getActivityType(String infectionType) { else if (infectionType.endsWith("educ_higher")) activityType = "university"; else if (infectionType.endsWith("educ_kiga")) activityType = "day care"; else if (infectionType.endsWith("leisure")) activityType = "leisure"; + else if (infectionType.endsWith("leisPublic")) activityType = "leisPublic"; + else if (infectionType.endsWith("leisPrivate")) activityType = "leisPrivate"; else if (infectionType.endsWith("work") || infectionType.endsWith("business")) activityType = "work&business"; else if (infectionType.endsWith("home")) activityType = "home"; else if (infectionType.startsWith("pt")) activityType = "pt"; diff --git a/src/main/java/org/matsim/episim/model/input/CreateRestrictionsFromSnz.java b/src/main/java/org/matsim/episim/model/input/CreateRestrictionsFromSnz.java index 12171e614..27842d819 100644 --- a/src/main/java/org/matsim/episim/model/input/CreateRestrictionsFromSnz.java +++ b/src/main/java/org/matsim/episim/model/input/CreateRestrictionsFromSnz.java @@ -227,7 +227,7 @@ static HashMap> readDurations(File file, HashMa sums.mergeDouble("notAtHome", duration, Double::sum); - if (!actType.equals("education") && !actType.equals("leisure")) { + if (!actType.equals("education") && !actType.startsWith("leis")) { sums.mergeDouble("notAtHomeExceptLeisureAndEdu", duration, Double::sum); } if (!actType.equals("education")) { @@ -267,7 +267,7 @@ static Object2DoubleMap readDurations(File file, IntSet zipCodes) throws sums.mergeDouble("notAtHome", duration, Double::sum); - if (!actType.equals("education") && !actType.equals("leisure")) { + if (!actType.equals("education") && !actType.startsWith("leis")) { sums.mergeDouble("notAtHomeExceptLeisureAndEdu", duration, Double::sum); } if (!actType.equals("education")) { @@ -896,8 +896,8 @@ public HashMap findZipCodesForAnyArea(String anyArea) throws IOE + possibleAreas.toString() + " Choose one and start again."); return zipCodes; } - - + + /** Finds the date after the last day in the given output file. * @param startDateStillUsingBaseDays * @param filesWithData diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 243c94955..45ab4c306 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_IfSG") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_leisSplit") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_IfSG$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_leisSplit$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java new file mode 100644 index 000000000..07e933148 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java @@ -0,0 +1,1006 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.testing.FlexibleTestingModel; +import org.matsim.episim.model.testing.TestType; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.*; +import java.util.function.BiFunction; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF20220805_leisSplit implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // BIND ANTIBODY MODEL + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 2.9; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + if (params != null && !params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (params != null && !params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } + + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + + // BIND VACCINATION MODEL + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + LocalDate start = LocalDate.parse("2022-12-01"); + + VaccinationType vaccinationType = VaccinationType.mRNA; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + String vacCamp = "off"; + + if (params != null) { + + if (!params.vacType.equals("off")) { + vacCamp = "age"; + vaccinationType = VaccinationType.valueOf(params.vacType); + } + +// start = LocalDate.parse(params.resDate); + + + switch (vacCamp) { + case "age": + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + break; + case "eu": + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + break; + case "off": + break; + default: + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } + + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + + + // BIND TESTING MODEL + if (params != null){ + + // date of no restrictions and new restrictions + String unResDate = "2022-04-25"; + LocalDate unresDate = LocalDate.parse(unResDate); + LocalDate resDate = LocalDate.parse(params.resDate); + +// String[] s = params.gpMonths.split("-"); + + // Green pass validity for vaccinated and infected +// int vacDays = Integer.parseInt(s[0]) * 30; +// int infDays = Integer.parseInt(s[1]) * 30; + + // set days gp is valid + int vacDays = 3 * 30; + int infDays = 3 * 30; + + // set testing scheme for each activity type + final CologneBMBF220628_3G.TestScheme leisTest; + final CologneBMBF220628_3G.TestScheme workTest; + final CologneBMBF220628_3G.TestScheme eduTest; + if (params.leis.equals("test") || params.leis.equals("all")) { + leisTest= CologneBMBF220628_3G.TestScheme.gp; + } else if (params.leis.equals("none") || params.leis.equals("mask")) { + leisTest = CologneBMBF220628_3G.TestScheme.none; + } else { + throw new RuntimeException(); + } + + + if (params.work.equals("test") || params.work.equals("all")) { + workTest= CologneBMBF220628_3G.TestScheme.all; + } else if (params.work.equals("none") || params.work.equals("mask")|| params.work.equals("homeOff")) { + workTest = CologneBMBF220628_3G.TestScheme.none; + } else { + throw new RuntimeException(); + } + + if (params.edu.equals("maskVentTest")) { + eduTest = CologneBMBF220628_3G.TestScheme.all; + } else if (params.edu.equals("none")) { + eduTest = CologneBMBF220628_3G.TestScheme.none; + } else {throw new RuntimeException();} + + bind(FlexibleTestingModel.TestRate.class).toInstance((person, day, dow, date, test, vac) -> { + + if (date.isBefore(unresDate)) + return vac.hasValidVaccination(person, day, date); + + // When restrictions have been lifted, days valid is set to a high number + // many tests are voluntary + if (date.isBefore(resDate)) + return vac.hasValidVaccination(person, day, date, 360); + + // this returns true if for any activities, the person requires increased testing regime + BiFunction anyUnVac = (act, red) -> { + + boolean res = false; + CologneBMBF220628_3G.TestScheme scheme = null; + + + if (act.startsWith("leis")) + scheme = leisTest; + else if (act.equals("work")) + scheme = workTest; + else if (act.startsWith("edu")) + scheme = eduTest; + + // null and none, will be false + if (scheme == CologneBMBF220628_3G.TestScheme.all) + res = true; + else if (scheme == CologneBMBF220628_3G.TestScheme.gp) { + res = (person.getNumVaccinations() == 0 || person.daysSince(EpisimPerson.VaccinationStatus.yes, day) > vacDays) + && !person.isRecentlyRecovered(day, infDays); + + } + + return red || res; + }; + + return !person.matchActivities(dow, anyUnVac, false); + }); + + bind(FlexibleTestingModel.TestPolicy.class).toInstance(new FlexibleTestingModel.TestPolicy() { + @Override + public boolean shouldTest(EpisimPerson person, int day, DayOfWeek dow, LocalDate date, + TestingConfigGroup test, VaccinationConfigGroup vac) { + + if (date.isBefore(unresDate)) { + + boolean testAllPersons = test.getTestAllPersonsAfter() != null && date.isAfter(test.getTestAllPersonsAfter()); + return testAllPersons || !vac.hasGreenPass(person, day, date); + } + + // after restrictions everybody is tested according to the rates + return true; + } + }); + + } + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + + +// System.out.print("immunityGiver"); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// if (immunityFrom == VirusStrain.OMICRON_BA1) { +// System.out.print( "," + "BA.1"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { +// System.out.print( "," + "BA.2"); +// } else { +// System.out.print( "," + immunityFrom); +// } +// } +// +// +// for (ImmunityEvent immunityGiver : VaccinationType.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// for (ImmunityEvent immunityGiver : VirusStrain.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// +// System.out.println(); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0 && params.leisSplit.equals("private")){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2); + + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + +// virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); + + //BA5 + double ba5Inf = 1.0; + double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); + } + +// STRAIN_B + if (!params.StrainB.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); + } + + // remove age-based susceptibility of strains starting with DELTA + + String ageSusc = "false"; + if (!Boolean.parseBoolean(ageSusc)) { + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : List.of(VirusStrain.DELTA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A)) { + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } + } + + // increase infectivity of alpha + virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * 1.4); + + double deltaTheta = 0.9; + virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * deltaTheta); + double ba1Inf = 1.9; // 2.0,2.1,2.2 + double ba2Inf = 1.7; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); + + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + Map infPerDayAlpha = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.ALPHA, new TreeMap<>())); + + + // reconfig disease import of alpha + LocalDate startDateAlpha = LocalDate.parse("2021-01-15"); + + for (int i = 0; i < 7; i++) { + infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); + } + + + infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); + + episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); + + + configureFutureDiseaseImport(params, episimConfig); + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + //school + String schoolUpdate = "yes"; + if(schoolUpdate.equals("yes")) { + // school closed completely until 21.2.2022 + builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); + builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + } else if (schoolUpdate.equals("no")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + String schoolTest = "later"; + if (schoolTest.equals("later")) { + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); +// TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); +// Map> testingRateForActivitiesPCR = pcrTest.getTestingRateForActivities(); + + + for (LocalDate date = LocalDate.parse("2021-03-19"); date.isBefore(LocalDate.parse("2021-04-25")); date = date.plusDays(1)) { + + testingRateForActivitiesRapid.get("educ_kiga").put(date, 0.); + testingRateForActivitiesRapid.get("educ_primary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_secondary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_tertiary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_other").put(date, 0.); + + } + + testingRateForActivitiesRapid.get("educ_kiga").put(LocalDate.parse("2021-09-20"), 0.); + testingRateForActivitiesRapid.get("educ_primary").put(LocalDate.parse("2021-09-20"), 0.); + +// testingRateForActivitiesPCR.get("educ_primary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_secondary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); + + } else if (schoolTest.equals("base")) { + + }else { + throw new RuntimeException("param value doesn't exist"); + } + + + // masks + //pt: masks + String maskType = "45to45"; + if (maskType.equals("45to45")) { + for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { + builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); + + } + } else if (maskType.equals("base")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + // ----------------------------------------- + + // new restrictions from IfSG + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + // testing rates + + double gpTestRate = 0.; + + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesPcr = pcrTest.getTestingRateForActivities(); + Map> testingRateForActivitiesPcrVac = pcrTest.getTestingRateForActivitiesVaccinated(); + + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); + Map> testingRateForActivitiesRapidVac = rapidTest.getTestingRateForActivitiesVaccinated(); + + + // school + { + //pcr tests for younger kids + testingRateForActivitiesPcr.get("educ_kiga").put(restrictionDate, 0.4); + testingRateForActivitiesPcr.get("educ_primary").put(restrictionDate, 0.4); + testingRateForActivitiesPcrVac.get("educ_kiga").put(restrictionDate, gpTestRate); + testingRateForActivitiesPcrVac.get("educ_primary").put(restrictionDate, gpTestRate); + + //add rapid tests for older kids + testingRateForActivitiesRapid.get("educ_secondary").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_tertiary").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_higher").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_other").put(restrictionDate, 0.6); + testingRateForActivitiesRapidVac.get("educ_secondary").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_tertiary").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_higher").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_other").put(restrictionDate, gpTestRate); + } + + // work + { + testingRateForActivitiesRapid.get("work").put(restrictionDate, 0.6); + testingRateForActivitiesRapidVac.get("work").put(restrictionDate, gpTestRate); + } + + // leisure: + { + testingRateForActivitiesRapid.get("leisure").put(restrictionDate, 0.45); + testingRateForActivitiesRapidVac.get("leisure").put(restrictionDate, gpTestRate); + } + + //WORK + double homeOfficeFactor = 0.5; + switch (params.work) { + case "none": + break; + case "homeOff": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "test": + // handled in getBindings + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.9)), "work", "business"); + break; + case "all": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //LEISURE + switch (params.leis) { + case "none": + break; + case "test": + // handled in getBindings + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45)), "leisure", "leisPublic", "leisPrivate"); + case "all": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45)), "leisure", "leisPublic", "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // shop, errands + switch (params.errands) { + case "none": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //SCHOOL + // todo check mask rate + if (params.edu.equals("maskVentTest")) { + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.25, + FaceMask.SURGICAL, 0.25)), + "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); + + } else if (params.edu.equals("none")) { + + } else { + throw new RuntimeException("invalid parameter"); + } + + + // pt + switch (params.pt) { + case "none": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + + // LEISURE SPLIT + Double leisureFactor = 0.0; + if (params.leisSplit.equals("private") || params.leisSplit.equals("both")) { + builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPrivate"); + } + + if (params.leisSplit.equals("public")|| params.leisSplit.equals("both")) { + builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPublic"); + + } + + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + // vaccination + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); + vaccinationConfig.setTimePeriodIgA(730.); + + + //modify contact intensity + double workCi = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); + + + double leisureCi = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisPublic").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisPrivate").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); + + + double schoolCi = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + + // add initial impulses for strains + //BA.1 +// LocalDate ba1Date = LocalDate.parse(params.ba1Date); +// for (int i = 0; i < 7; i++) { +// infPerDayBa1.put(ba1Date.plusDays(i), 4); +// } +// infPerDayBa1.put(ba1Date.plusDays(7), 1); + + + //BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + //BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB + if (!params.StrainB.equals("off")) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + + + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + if (!params.StrainB.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + // LEISURE SPLIT + @StringParameter({"none", "private", "public", "both"}) + public String leisSplit; + + + @StringParameter({"6.0"}) + public String StrainA; + + @StringParameter({"off"}) + public String StrainB; + + @StringParameter({"2022-10-01"}) + public String resDate; + + // @StringParameter({"false", "true"}) +// public String igA; + // vaccination campaign + @StringParameter({"off"}) + public String vacType; + + + //measures in the work context: + // homeOff = 50% home office = work Rf cut in half + // + @StringParameter({"none"}) + public String work; + + @StringParameter({"none"}) + public String leis; + + // mask restrictions for "shop_daily", "shop_other", "errands" + @StringParameter({"none"}) + public String errands; + + @StringParameter({"none"}) + public String edu; + + @StringParameter({"mask"}) + public String pt; + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF20220805_leisSplit.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(30), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/modules/AbstractSnzScenario.java b/src/main/java/org/matsim/run/modules/AbstractSnzScenario.java index a34c0d335..f80b41756 100644 --- a/src/main/java/org/matsim/run/modules/AbstractSnzScenario.java +++ b/src/main/java/org/matsim/run/modules/AbstractSnzScenario.java @@ -29,6 +29,10 @@ public static void addParams(EpisimConfigGroup episimConfig) { episimConfig.getOrAddContainerParams("leisure") .setContactIntensity(5.0); + episimConfig.getOrAddContainerParams("leisPublic") + .setContactIntensity(5.0); + episimConfig.getOrAddContainerParams("leisPrivate") + .setContactIntensity(5.0); episimConfig.getOrAddContainerParams("educ_kiga") .setContactIntensity(10.0); episimConfig.getOrAddContainerParams("educ_primary") diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index df3ad5c76..5701c54ea 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -294,13 +294,13 @@ public Config config() { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 0.96 * 1.06); - episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_wt_%dpt_split.xml.gz", sample)) + episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_wt_%dpt_split_withLeisureSplit.xml.gz", sample)) .addDays(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY); - episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_sa_%dpt_split.xml.gz", sample)) + episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_sa_%dpt_split_withLeisureSplit.xml.gz", sample)) .addDays(DayOfWeek.SATURDAY); - episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_so_%dpt_split.xml.gz", sample)) + episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_so_%dpt_split_withLeisureSplit.xml.gz", sample)) .addDays(DayOfWeek.SUNDAY); episimConfig.setActivityHandling(activityHandling); @@ -319,6 +319,8 @@ public Config config() { double leisCi = 0.6; episimConfig.getOrAddContainerParams("leisure").setContactIntensity(9.24 * leisCi); + episimConfig.getOrAddContainerParams("leisPrivate").setContactIntensity(9.24 * leisCi); + episimConfig.getOrAddContainerParams("leisPublic").setContactIntensity(9.24 * leisCi); episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(0.5); episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(0.5); @@ -439,7 +441,7 @@ public Config config() { } //curfew - builder.restrict("2021-04-17", Restriction.ofClosingHours(21, 5), "leisure", "visit"); + builder.restrict("2021-04-17", Restriction.ofClosingHours(21, 5), "leisure","leisPublic","leisPrivate", "visit"); Map curfewCompliance = new HashMap(); curfewCompliance.put(LocalDate.parse("2021-04-17"), 1.0); curfewCompliance.put(LocalDate.parse("2021-05-31"), 0.0); @@ -448,12 +450,12 @@ public Config config() { // vaccinated individuals (even tho they are allowed to complete activities, they will naturally reduce their activities) LocalDate transition2gTo3g = LocalDate.of(2022, 3, 4); double leis = 1.0; - builder.restrict(LocalDate.parse("2021-12-01"), Restriction.ofVaccinatedRf(0.75), "leisure"); - builder.restrict(transition2gTo3g, Restriction.ofVaccinatedRf(leis), "leisure"); + builder.restrict(LocalDate.parse("2021-12-01"), Restriction.ofVaccinatedRf(0.75), "leisure","leisPublic","leisPrivate"); + builder.restrict(transition2gTo3g, Restriction.ofVaccinatedRf(leis), "leisure","leisPublic","leisPrivate"); //2G for unvaccinated susceptible agents (will move more activities in private homes, thats why we assume 0.75 for both vaccinated and unvaccinated) - builder.restrict(LocalDate.parse("2021-11-22"), Restriction.ofSusceptibleRf(0.75), "leisure"); - builder.restrict(transition2gTo3g, Restriction.ofSusceptibleRf(leis), "leisure"); + builder.restrict(LocalDate.parse("2021-11-22"), Restriction.ofSusceptibleRf(0.75), "leisure","leisPublic","leisPrivate"); + builder.restrict(transition2gTo3g, Restriction.ofSusceptibleRf(leis), "leisure","leisPublic","leisPrivate"); double schoolFac = 0.5; builder.restrict(LocalDate.parse("2021-08-17"), Restriction.ofCiCorrection(1 - (0.5 * schoolFac)), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); @@ -463,7 +465,7 @@ public Config config() { builder.restrict(LocalDate.parse("2021-12-02"), Restriction.ofMask(FaceMask.N95, 0.9 * schoolFac), "educ_primary", "educ_secondary", "educ_tertiary", "educ_other"); // mask mandate removed - builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(FaceMask.N95, 0.), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "leisure", "work", "business"); //todo: check + builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(FaceMask.N95, 0.), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "leisure","leisPublic","leisPrivate","work", "business"); //todo: check builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, @@ -510,9 +512,9 @@ public Config config() { if (this.restrictions != Restrictions.no) { if (leisureCorrection == 0.) { // assume old factor of 1.9, only applied to leisure TODO: get rid of this artifact - builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - 1.9 * (1 - (double) e.get("fraction"))), "leisure"); + builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - 1.9 * (1 - (double) e.get("fraction"))), "leisure","leisPublic","leisPrivate"); } else if (leisureCorrection != 1) { - builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "business", "errands", "leisure", "shop_daily", "shop_other", "visit", "work"); + builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "business", "errands", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "work"); } // builder.applyToRf("2020-10-15", "2020-12-14", (d, rf) -> rf - leisureOffset, "leisure"); @@ -583,12 +585,12 @@ public Config config() { if (carnivalModel.equals(CarnivalModel.yes)) { // Friday 25.2 to Monday 28.2 (Rosenmontag) - builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); - builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays - builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival + builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); + builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays + builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival - builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure"); - builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure"); + builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure","leisPublic","leisPrivate"); + builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure","leisPublic","leisPrivate"); inputDays.put(LocalDate.parse("2022-02-28"), DayOfWeek.SUNDAY); // set monday to be a sunday } @@ -660,6 +662,8 @@ public Config config() { List actsList = new ArrayList(); actsList.add("leisure"); + actsList.add("leisPublic"); + actsList.add("leisPrivate"); actsList.add("work"); actsList.add("business"); actsList.add("educ_kiga"); @@ -730,7 +734,7 @@ public Config config() { leisureTests.put(LocalDate.of(2022, 4, 25), 0.1); - rapidTest.setTestingRatePerActivityAndDate((Map.of( + Map> testingRatePerAct = new HashMap<>(Map.of( "leisure", leisureTests, "work", workTests, "business", workTests, @@ -740,7 +744,12 @@ public Config config() { "educ_tertiary", eduTests, "educ_higher", uniTests, "educ_other", eduTests - ))); + )); + + testingRatePerAct.put("leisPrivate", leisureTests); + testingRatePerAct.put("leisPublic", leisureTests); + + rapidTest.setTestingRatePerActivityAndDate(testingRatePerAct); // 1ii) vaccinated Map leisureTestsVaccinated = new HashMap<>(); @@ -760,7 +769,7 @@ public Config config() { // } - rapidTest.setTestingRatePerActivityAndDateVaccinated((Map.of( + Map> testingRatePerActVac = new HashMap<>(Map.of( "leisure", leisureTestsVaccinated, "work", workTestsVaccinated, "business", workTestsVaccinated, @@ -770,7 +779,13 @@ public Config config() { "educ_tertiary", eduTestsVaccinated, "educ_higher", eduTestsVaccinated, "educ_other", eduTestsVaccinated - ))); + )); + + testingRatePerActVac.put("leisPrivate", leisureTestsVaccinated); + testingRatePerActVac.put("leisPublic", leisureTestsVaccinated); + + + rapidTest.setTestingRatePerActivityAndDateVaccinated(testingRatePerActVac); // 2) PCR Test @@ -800,7 +815,7 @@ public Config config() { // } - pcrTest.setTestingRatePerActivityAndDate((Map.of( + Map> testingRatePerActPCR = new HashMap<>(Map.of( "leisure", leisureTestsPCR, "work", workTestsPCR, "business", workTestsPCR, @@ -810,7 +825,11 @@ public Config config() { "educ_tertiary", eduTestsPCR, "educ_higher", eduTestsPCR, "educ_other", eduTestsPCR - ))); + )); + + testingRatePerActPCR.put("leisPrivate", leisureTestsPCR); + testingRatePerActPCR.put("leisPublic", leisureTestsPCR); + pcrTest.setTestingRatePerActivityAndDate(testingRatePerActPCR); // 2ii) vaccinated @@ -821,7 +840,7 @@ public Config config() { workTestsPCRVaccinated.put(LocalDate.parse("2020-01-01"), 0.); eduTestsPCRVaccinated.put(LocalDate.parse("2020-01-01"), 0.); - pcrTest.setTestingRatePerActivityAndDateVaccinated((Map.of( + Map> testingRatePerActVacPCR = new HashMap<>(Map.of( "leisure", leisureTestsPCRVaccinated, "work", workTestsPCRVaccinated, "business", workTestsPCRVaccinated, @@ -831,7 +850,11 @@ public Config config() { "educ_tertiary", eduTestsPCRVaccinated, "educ_higher", eduTestsPCRVaccinated, "educ_other", eduTestsPCRVaccinated - ))); + )); + + testingRatePerActVacPCR.put("leisPrivate", leisureTestsPCRVaccinated); + testingRatePerActVacPCR.put("leisPublic", leisureTestsPCRVaccinated); + pcrTest.setTestingRatePerActivityAndDateVaccinated(testingRatePerActVacPCR); rapidTest.setTestingCapacity_pers_per_day(Map.of( LocalDate.of(1970, 1, 1), 0, diff --git a/src/main/java/org/matsim/run/modules/SnzProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzProductionScenario.java index ce36a5a3a..80ad0d0c6 100644 --- a/src/main/java/org/matsim/run/modules/SnzProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzProductionScenario.java @@ -76,6 +76,8 @@ public static void configureContactIntensities(EpisimConfigGroup episimConfig) { episimConfig.getOrAddContainerParams("pt", "tr").setContactIntensity(10.0).setSpacesPerFacility(spaces); episimConfig.getOrAddContainerParams("work").setContactIntensity(1.47).setSpacesPerFacility(spaces); episimConfig.getOrAddContainerParams("leisure").setContactIntensity(9.24).setSpacesPerFacility(spaces).setSeasonality(1.0); + episimConfig.getOrAddContainerParams("leisPublic").setContactIntensity(9.24).setSpacesPerFacility(spaces).setSeasonality(1.0); + episimConfig.getOrAddContainerParams("leisPrivate").setContactIntensity(9.24).setSpacesPerFacility(spaces).setSeasonality(1.0); // episimConfig.getOrAddContainerParams("restaurant").setContactIntensity(9.24).setSpacesPerFacility(spaces).setSeasonal(true); episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(11.0).setSpacesPerFacility(spaces); episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(11.0).setSpacesPerFacility(spaces); diff --git a/src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java b/src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java index c2703ead7..e13811793 100644 --- a/src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java +++ b/src/main/java/org/matsim/scenarioCreation/DifferentiateLeisureActivitiesInEventsCologne.java @@ -76,7 +76,7 @@ public static void main(String[] args) throws IOException { EventsUtils.readEvents(manager, events); - String outputName =events.replace(".xml.gz", "") + "_withLeisureSplit.xml.gz"; + String outputName = events.replace(".xml.gz", "") + "_withLeisureSplit.xml.gz"; EventWriterXML writer = new EventWriterXML( IOUtils.getOutputStream(IOUtils.getFileUrl(outputName), false) @@ -95,7 +95,7 @@ public static class FacilityFinder implements ActivityEndEventHandler, ActivityS @Override public void handleEvent(ActivityEndEvent activityEndEvent) { - if (activityEndEvent.getActType().equals("lesiure")) { + if (activityEndEvent.getActType().equals("leisure")) { leisureFacilities.add(activityEndEvent.getFacilityId().toString()); } @@ -103,7 +103,7 @@ public void handleEvent(ActivityEndEvent activityEndEvent) { @Override public void handleEvent(ActivityStartEvent activityStartEvent) { - if (activityStartEvent.getActType().equals("lesiure")) { + if (activityStartEvent.getActType().equals("leisure")) { leisureFacilities.add(activityStartEvent.getFacilityId().toString()); } } From f7244621ba8f83412611050664d43a4e302e69f6 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 19:36:29 +0200 Subject: [PATCH 041/128] fixed testing programm --- .../org/matsim/run/batch/CologneBMBF20220805_IfSG.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java index 17a72c694..4a2deceff 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java @@ -12,6 +12,7 @@ import org.matsim.episim.*; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; +import org.matsim.episim.model.testing.DefaultTestingModel; import org.matsim.episim.model.testing.FlexibleTestingModel; import org.matsim.episim.model.testing.TestType; import org.matsim.episim.model.vaccination.VaccinationModel; @@ -450,7 +451,7 @@ private SnzCologneProductionScenario getBindings(double pHousehold, Params param .setScaleForActivityLevels(1.3) .setSuscHouseholds_pct(pHousehold) .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) -// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) .setInfectionModel(InfectionModelWithAntibodies.class) .build(); } @@ -475,8 +476,8 @@ public Collection postProcessing() { @Override public Config prepareConfig(int id, Params params) { - if (DEBUG_MODE) { - if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (DEBUG_MODE ) { + if (runCount == 0 && params.edu.equals("maskVentTest")){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; From 6ec0e4096987ba0bb0e62423038f6aa587fa8bb3 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 4 Aug 2022 20:32:03 +0200 Subject: [PATCH 042/128] updated batch to fix contact intensity of leisure acts --- .../batch/CologneBMBF20220805_leisSplit.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java index 07e933148..90e7f61df 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java @@ -12,6 +12,7 @@ import org.matsim.episim.*; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; +import org.matsim.episim.model.testing.DefaultTestingModel; import org.matsim.episim.model.testing.FlexibleTestingModel; import org.matsim.episim.model.testing.TestType; import org.matsim.episim.model.vaccination.VaccinationModel; @@ -450,7 +451,7 @@ private SnzCologneProductionScenario getBindings(double pHousehold, Params param .setScaleForActivityLevels(1.3) .setSuscHouseholds_pct(pHousehold) .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) -// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) .setInfectionModel(InfectionModelWithAntibodies.class) .build(); } @@ -476,7 +477,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0 && params.leisSplit.equals("private")){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -694,8 +695,8 @@ public Config prepareConfig(int id, Params params) { // leisure: { - testingRateForActivitiesRapid.get("leisure").put(restrictionDate, 0.45); - testingRateForActivitiesRapidVac.get("leisure").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapid.get("leisPublic").put(restrictionDate, 0.9); + testingRateForActivitiesRapidVac.get("leisPublic").put(restrictionDate, gpTestRate); } //WORK @@ -730,9 +731,9 @@ public Config prepareConfig(int id, Params params) { // handled in getBindings break; case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45)), "leisure", "leisPublic", "leisPrivate"); + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); case "all": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.45)), "leisure", "leisPublic", "leisPrivate"); + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); break; default: throw new RuntimeException("invalid parameter"); @@ -780,15 +781,15 @@ public Config prepareConfig(int id, Params params) { // LEISURE SPLIT - Double leisureFactor = 0.0; - if (params.leisSplit.equals("private") || params.leisSplit.equals("both")) { - builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPrivate"); - } - - if (params.leisSplit.equals("public")|| params.leisSplit.equals("both")) { - builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPublic"); - - } +// Double leisureFactor = 0.0; +// if (params.leisSplit.equals("private") || params.leisSplit.equals("both")) { +// builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPrivate"); +// } +// +// if (params.leisSplit.equals("public")|| params.leisSplit.equals("both")) { +// builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPublic"); +// +// } episimConfig.setPolicy(builder.build()); @@ -812,8 +813,8 @@ public Config prepareConfig(int id, Params params) { double leisureCi = 0.4; episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisPublic").getContactIntensity() * leisureCi); - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisPrivate").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("leisPublic").setContactIntensity(episimConfig.getOrAddContainerParams("leisPublic").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("leisPrivate").setContactIntensity(episimConfig.getOrAddContainerParams("leisPrivate").getContactIntensity() * leisureCi); episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); @@ -948,8 +949,8 @@ public static final class Params { public long seed; // LEISURE SPLIT - @StringParameter({"none", "private", "public", "both"}) - public String leisSplit; +// @StringParameter({"none", "private", "public", "both"}) +// public String leisSplit; @StringParameter({"6.0"}) @@ -974,7 +975,7 @@ public static final class Params { @StringParameter({"none"}) public String work; - @StringParameter({"none"}) + @StringParameter({"none", "mask", "test", "all"}) public String leis; // mask restrictions for "shop_daily", "shop_other", "errands" From 6b605edb9ba0926bf212377e98c42fcb06a6138f Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 5 Aug 2022 10:46:23 +0200 Subject: [PATCH 043/128] update batch for new full run --- .../run/batch/CologneBMBF20220805_leisSplit.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java index 90e7f61df..f60407d6e 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java @@ -948,11 +948,6 @@ public static final class Params { @GenerateSeeds(5) public long seed; - // LEISURE SPLIT -// @StringParameter({"none", "private", "public", "both"}) -// public String leisSplit; - - @StringParameter({"6.0"}) public String StrainA; @@ -965,24 +960,24 @@ public static final class Params { // @StringParameter({"false", "true"}) // public String igA; // vaccination campaign - @StringParameter({"off"}) + @StringParameter({"ba5Update", "mRNA", "off"}) public String vacType; //measures in the work context: // homeOff = 50% home office = work Rf cut in half // - @StringParameter({"none"}) + @StringParameter({"none", "homeOff", "test", "mask", "all"}) public String work; @StringParameter({"none", "mask", "test", "all"}) public String leis; // mask restrictions for "shop_daily", "shop_other", "errands" - @StringParameter({"none"}) + @StringParameter({"none", "mask"}) public String errands; - @StringParameter({"none"}) + @StringParameter({"none", "maskVentTest"}) public String edu; @StringParameter({"mask"}) From 03e5207e75f7f775228d440b85dcde47958a5522 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 5 Aug 2022 12:54:48 +0200 Subject: [PATCH 044/128] added flag to forEachEvent() to specify whether we prefer using reduced events --- .../analysis/ExtractInfectionsByAge.java | 2 +- .../matsim/episim/analysis/FilterEvents.java | 2 +- .../analysis/HospitalNumbersFromEvents.java | 50 ++++++++++++++++--- .../episim/analysis/InicidencePerStrain.java | 16 +----- .../episim/analysis/RValuesFromEvents.java | 3 +- .../SecondaryAttackRateFromEvents.java | 2 +- .../analysis/VaccinationEffectiveness.java | 7 ++- ...nEffectivenessFromPotentialInfections.java | 3 +- .../java/org/matsim/run/AnalysisCommand.java | 18 ++++--- .../run/batch/CologneBMBF20220805_IfSG.java | 8 +-- 10 files changed, 66 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/ExtractInfectionsByAge.java b/src/main/java/org/matsim/episim/analysis/ExtractInfectionsByAge.java index 363f58e58..b81904462 100644 --- a/src/main/java/org/matsim/episim/analysis/ExtractInfectionsByAge.java +++ b/src/main/java/org/matsim/episim/analysis/ExtractInfectionsByAge.java @@ -232,7 +232,7 @@ private void readScenario(Path path) throws IOException { } } , - (EpisimPersonStatusEventHandler) e -> { + false, (EpisimPersonStatusEventHandler) e -> { if (!counts.containsKey(e.getDiseaseStatus())) return; diff --git a/src/main/java/org/matsim/episim/analysis/FilterEvents.java b/src/main/java/org/matsim/episim/analysis/FilterEvents.java index c56fac278..8cf0fb5b5 100644 --- a/src/main/java/org/matsim/episim/analysis/FilterEvents.java +++ b/src/main/java/org/matsim/episim/analysis/FilterEvents.java @@ -77,7 +77,7 @@ public void analyzeOutput(Path output) throws IOException { AnalysisCommand.forEachEvent(output, s -> { handler.reset(-1); - }, handler); + }, false, handler); handler.closeEntry(); zipOut.close(); diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index f27cda57d..977e13228 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -216,6 +216,8 @@ public Integer call() throws Exception { HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); // } @@ -259,13 +261,19 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t ConfigHolder holderDelta = configure(factorDelta, factorDeltaICU); List handlers = List.of( - new Handler("Omicron", population, holderOmicron ), - new Handler("Delta", population, holderDelta) + new Handler("Omicron", population, holderOmicron, 0.0), + new Handler("Delta", population, holderDelta, 0.0), + new Handler("Omicron-Paxlovid-0.25", population, holderOmicron, 0.25), + new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), + new Handler("Omicron-Paxlovid-0.50", population, holderOmicron, 0.5), + new Handler("Delta-Paxlovid-0.50", population, holderDelta, 0.5), + new Handler("Omicron-Paxlovid-0.75", population, holderOmicron, 0.75), + new Handler("Delta-Paxlovid-0.75", population, holderDelta, 0.75) ); // feed the output events file to the handler, so that the hospitalizations may be calculated List eventFiles = AnalysisCommand.forEachEvent(pathToScenario, s -> { - }, handlers.toArray(new Handler[0])); + }, true, handlers.toArray(new Handler[0])); // for (Double facA : strainFactors) { @@ -345,6 +353,10 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis private final Random rnd; private final ConfigHolder holder; + private final double paxlovidCompliance; + + private final int paxlovidDay; + final Int2IntSortedMap postProcessHospitalAdmissions; final Int2IntSortedMap postProcessICUAdmissions; final Int2IntSortedMap postProcessHospitalFilledBeds; @@ -368,7 +380,7 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis private final AgeDependentDiseaseStatusTransitionModel transitionModel; - Handler(String name, Population population, ConfigHolder holder) { + Handler(String name, Population population, ConfigHolder holder, double paxlovidCompliance) { // instantiate the custom event handler that calculates hospitalizations based on events this.name = name; @@ -376,6 +388,8 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis this.population = population; this.rnd = new Random(1234); this.holder = holder; + this.paxlovidCompliance = paxlovidCompliance; + this.paxlovidDay = (int) LocalDate.of(2020, 2, 25).datesUntil(LocalDate.of(2022, 11, 1)).count(); this.postProcessHospitalAdmissions = new Int2IntAVLTreeMap(); this.postProcessICUAdmissions = new Int2IntAVLTreeMap(); @@ -479,6 +493,18 @@ private int getAge(Id personId) { return (int) population.getPersons().get(personId).getAttributes().getAttribute("microm:modeled:age"); } + + /* + % infected who get paxlovid (for a certain age group): + + 75% of people over 60 get paxlovid + + + 75% of people with antibodyResponse below 0.3 + + effectivity: 66% reduction, chance of hospitalization * 0.33 + + + */ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain strain, int infectionIteration) { @@ -498,9 +524,9 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st postProcessHospitalAdmissions.mergeInt(inHospital, 1, Integer::sum); - if (person.getNumVaccinations()==0) { + if (person.getNumVaccinations() == 0) { hospNoImmunity.mergeInt(inHospital, 1, Integer::sum); - } else if (person.getNumVaccinations()==1) { + } else if (person.getNumVaccinations() == 1) { hospBaseImmunity.mergeInt(inHospital, 1, Integer::sum); } else { hospBoostered.mergeInt(inHospital, 1, Integer::sum); @@ -554,9 +580,18 @@ private boolean goToHospital(ImmunizablePerson person, int day) { double strainFactor = holder.strainConfig.getParams(person.getVirusStrain()).getFactorSeriouslySick(); double immunityFactor = transitionModel.getSeriouslySickFactor(person, holder.vaccinationConfig, day); + double paxlovidFactor = 1.0; + if (person.getAge() > 60 && day >= this.paxlovidDay) { + if (rnd.nextDouble() < this.paxlovidCompliance) { + paxlovidFactor = 0.33; // todo + } + } + + // 0.36 (old) * 1.2 (delta) * ... (immunisation) = return rnd.nextDouble() < ageFactor * strainFactor - * immunityFactor; + * immunityFactor + * paxlovidFactor; } /** @@ -608,7 +643,6 @@ static final class ImmunizablePerson implements Immunizable{ private double antibodyLevelAtInfection = 0; private int age; - ImmunizablePerson(Id personId, int age) { this.personId = personId; this.age = age; diff --git a/src/main/java/org/matsim/episim/analysis/InicidencePerStrain.java b/src/main/java/org/matsim/episim/analysis/InicidencePerStrain.java index 1e99c72ec..1ac629133 100644 --- a/src/main/java/org/matsim/episim/analysis/InicidencePerStrain.java +++ b/src/main/java/org/matsim/episim/analysis/InicidencePerStrain.java @@ -25,26 +25,15 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.config.Configurator; -import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.events.ActivityStartEvent; -import org.matsim.api.core.v01.events.handler.ActivityStartEventHandler; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Population; -import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.events.EventsUtils; -import org.matsim.core.events.MatsimEventsReader; import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.core.utils.io.UncheckedIOException; -import org.matsim.episim.EpisimUtils; import org.matsim.episim.EpisimPerson.DiseaseStatus; import org.matsim.episim.events.*; -import org.matsim.episim.model.VaccinationType; -import org.matsim.episim.model.VirusStrain; import org.matsim.run.AnalysisCommand; -import org.matsim.run.modules.AbstractSnzScenario2020; import org.matsim.utils.objectattributes.attributable.Attributes; import picocli.CommandLine; @@ -54,11 +43,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.LocalDate; -import java.time.temporal.ChronoUnit; import java.util.*; -import java.util.Map.Entry; import java.util.concurrent.Callable; -import java.util.stream.Collectors; /** @@ -140,7 +126,7 @@ private void calcValues(Path scenario) throws IOException { Handler handler = new Handler(population, startDate, symptoms, seriouslySick); - AnalysisCommand.forEachEvent(scenario, s -> {}, handler); + AnalysisCommand.forEachEvent(scenario, s -> {}, false, handler); int persons = 0; for (Person p : population.getPersons().values()) { diff --git a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java index 6de4fffda..c9c50e072 100644 --- a/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/RValuesFromEvents.java @@ -45,7 +45,6 @@ import java.time.LocalDate; import java.util.*; import java.util.Map.Entry; -import java.util.concurrent.Callable; import java.util.stream.Collectors; @@ -115,7 +114,7 @@ public void analyzeOutput(Path output) throws IOException { RHandler rHandler = new RHandler(); List eventFiles = AnalysisCommand.forEachEvent(output, s -> { - }, infHandler, rHandler); + }, false, infHandler, rHandler); BufferedWriter bw = Files.newBufferedWriter(output.resolve(id + "infectionsPerActivity.txt")); bw.write("day\tdate\tactivity\tinfections\tinfectionsShare\tscenario"); diff --git a/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java b/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java index 410483c8b..93a5e2eaf 100644 --- a/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/SecondaryAttackRateFromEvents.java @@ -136,7 +136,7 @@ public void analyzeOutput(Path output) throws IOException { SecondaryAttackRateHandler hhHandler = new SecondaryAttackRateHandler(personToHousehold); List eventFiles = AnalysisCommand.forEachEvent(output, s -> { - }, hhHandler); + }, false, hhHandler); Map> itToHouseholdToInfections = hhHandler.getItToHouseholdToInfections(); diff --git a/src/main/java/org/matsim/episim/analysis/VaccinationEffectiveness.java b/src/main/java/org/matsim/episim/analysis/VaccinationEffectiveness.java index 8c3c6f8b4..f9434418b 100644 --- a/src/main/java/org/matsim/episim/analysis/VaccinationEffectiveness.java +++ b/src/main/java/org/matsim/episim/analysis/VaccinationEffectiveness.java @@ -47,7 +47,6 @@ import java.nio.file.Path; import java.time.LocalDate; import java.util.*; - import java.util.concurrent.Callable; /** @@ -159,7 +158,7 @@ public void analyzeOutput(Path output) throws IOException { Handler handler = new Handler(data, startDate); AnalysisCommand.forEachEvent(output, s -> { - }, handler); + }, false, handler); int days4aggregation = 14; @@ -399,7 +398,7 @@ public void analyzeOutput(Path output) throws IOException { if (vacOmicronPerPeriod.containsKey(i)) omicronInfected = vacOmicronPerPeriod.get(i); - + int omicronBA2Infected = 0; if (vacOmicronBA2PerPeriod.containsKey(i)) @@ -429,7 +428,7 @@ public void analyzeOutput(Path output) throws IOException { if (cgOmicronPerPeriod.containsKey(i)) cgOmicronInfected = cgOmicronPerPeriod.get(i); - + int cgOmicronBA2Infected = 0; if (cgOmicronBA2PerPeriod.containsKey(i)) diff --git a/src/main/java/org/matsim/episim/analysis/VaccinationEffectivenessFromPotentialInfections.java b/src/main/java/org/matsim/episim/analysis/VaccinationEffectivenessFromPotentialInfections.java index d70d27466..f35cb0d02 100644 --- a/src/main/java/org/matsim/episim/analysis/VaccinationEffectivenessFromPotentialInfections.java +++ b/src/main/java/org/matsim/episim/analysis/VaccinationEffectivenessFromPotentialInfections.java @@ -43,7 +43,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.*; -import java.util.concurrent.Callable; @CommandLine.Command( @@ -99,7 +98,7 @@ public void analyzeOutput(Path output) throws IOException { Handler handler = new Handler(); - AnalysisCommand.forEachEvent(output, s -> {}, handler); + AnalysisCommand.forEachEvent(output, s -> {}, false, handler); // Entries with rarely used vaccines are filtered List collect = new ArrayList<>(handler.vac.keySet()); diff --git a/src/main/java/org/matsim/run/AnalysisCommand.java b/src/main/java/org/matsim/run/AnalysisCommand.java index fb20ef60c..af4ca1865 100644 --- a/src/main/java/org/matsim/run/AnalysisCommand.java +++ b/src/main/java/org/matsim/run/AnalysisCommand.java @@ -109,14 +109,15 @@ public static void forEachScenario(Path output, Consumer function) throws /** * Reads in all event file from a scenario. * - * @param scenario path of the scenario, which contains the event folder - * @param callback will be executed before reading an event file and pass the path - * @param handler handler for the events + * @param scenario path of the scenario, which contains the event folder + * @param callback will be executed before reading an event file and pass the path + * @param preferReducedEvents + * @param handler handler for the events * @return list of read event files */ - public static List forEachEvent(Path scenario, Consumer callback, EventHandler... handler) { + public static List forEachEvent(Path scenario, Consumer callback, boolean preferReducedEvents, EventHandler... handler) { - Path events = getEvents(scenario); + Path events = getEvents(scenario, preferReducedEvents); if (events == null) { log.warn("No events found at {}", scenario); return List.of(); @@ -208,17 +209,20 @@ public static String getScenarioPrefix(Path scenario) throws IOException { * Check if events are present for the scenario. This method fallbacks to reduced events, if original are not present. */ @Nullable - public static Path getEvents(Path scenario) { + public static Path getEvents(Path scenario, boolean preferReducedEvents) { if (Files.isDirectory(scenario.resolve("events")) && !isEmpty(scenario.resolve("events"))) { return scenario.resolve("events"); } try { + + Optional o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events.tar")).findFirst(); - if (o.isEmpty()) + if (o.isEmpty() || preferReducedEvents) { o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events_reduced.tar")).findFirst(); + } return o.orElse(null); } catch (IOException e) { diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java index 4a2deceff..d97811840 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java @@ -464,10 +464,10 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( - new VaccinationEffectiveness().withArgs(), - new RValuesFromEvents().withArgs(), - new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new FilterEvents().withArgs("--output","./output/"), +// new VaccinationEffectiveness().withArgs(), +// new RValuesFromEvents().withArgs(), +// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), +// new FilterEvents().withArgs("--output","./output/"), new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") // new SecondaryAttackRateFromEvents().withArgs() ); From 0be45b5a63d3e760a33f1c1f801e18a905d4a8b7 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 5 Aug 2022 12:59:16 +0200 Subject: [PATCH 045/128] added flag to forEachEvent() to specify whether we prefer using reduced events --- .../analysis/HospitalNumbersFromEvents.java | 8 ++++---- .../java/org/matsim/run/AnalysisCommand.java | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 977e13228..558ee1409 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -214,10 +214,10 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); // } diff --git a/src/main/java/org/matsim/run/AnalysisCommand.java b/src/main/java/org/matsim/run/AnalysisCommand.java index af4ca1865..09eaf9c72 100644 --- a/src/main/java/org/matsim/run/AnalysisCommand.java +++ b/src/main/java/org/matsim/run/AnalysisCommand.java @@ -216,15 +216,23 @@ public static Path getEvents(Path scenario, boolean preferReducedEvents) { } try { + Optional o; + if (preferReducedEvents) { + o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events_reduced.tar")).findFirst(); + if (o.isEmpty()) { + o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events.tar")).findFirst(); + } + } else { + o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events.tar")).findFirst(); - Optional o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events.tar")).findFirst(); - - if (o.isEmpty() || preferReducedEvents) { - o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events_reduced.tar")).findFirst(); + if (o.isEmpty()) { + o = Files.list(scenario).filter(p -> p.getFileName().toString().endsWith("events_reduced.tar")).findFirst(); + } } return o.orElse(null); + } catch (IOException e) { log.error("Error finding event files for {}", scenario); return null; From cbd8af1fc3c548e1cb3b39bbd80e980305269202 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 5 Aug 2022 19:56:54 +0200 Subject: [PATCH 046/128] removed xmas rf reductions --- .../matsim/run/batch/CologneBMBF20220805_IfSG.java | 14 +++++++------- .../run/modules/SnzCologneProductionScenario.java | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java index d97811840..30f8d60e9 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java @@ -464,10 +464,10 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( -// new VaccinationEffectiveness().withArgs(), -// new RValuesFromEvents().withArgs(), -// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), -// new FilterEvents().withArgs("--output","./output/"), + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") // new SecondaryAttackRateFromEvents().withArgs() ); @@ -477,7 +477,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE ) { - if (runCount == 0 && params.edu.equals("maskVentTest")){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -754,8 +754,8 @@ public Config prepareConfig(int id, Params params) { //SCHOOL // todo check mask rate if (params.edu.equals("maskVentTest")) { - builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + builder.restrict(restrictionDate, Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDate, Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, FaceMask.N95, 0.25, FaceMask.SURGICAL, 0.25)), diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index df3ad5c76..c54539b7b 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -412,11 +412,12 @@ public Config config() { builder.restrict(LocalDate.parse("2022-10-04"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2022-10-15"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); //Weihnachtsferien - builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); - builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); + //TODO: uncomment xmas again +// builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); +// builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); +// +// builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); +// builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); { From f14d0815bfce7b67901cd74efdd0e94dbae27345 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Sat, 6 Aug 2022 10:44:05 +0200 Subject: [PATCH 047/128] runs jakob/2022-08-04/9a&9b --- .../run/batch/CologneBMBF20220805_leisSplit.java | 13 ++++++++----- .../run/modules/SnzCologneProductionScenario.java | 11 ++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java index f60407d6e..28e1fb0ab 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java @@ -752,14 +752,17 @@ public Config prepareConfig(int id, Params params) { } //SCHOOL - // todo check mask rate if (params.edu.equals("maskVentTest")) { builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, - FaceMask.N95, 0.25, - FaceMask.SURGICAL, 0.25)), - "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); + FaceMask.N95, 0.45, + FaceMask.SURGICAL, 0.45)), + "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.90)), + "educ_higher"); } else if (params.edu.equals("none")) { @@ -954,7 +957,7 @@ public static final class Params { @StringParameter({"off"}) public String StrainB; - @StringParameter({"2022-10-01"}) + @StringParameter({"2022-12-01"}) public String resDate; // @StringParameter({"false", "true"}) diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 5701c54ea..d117903ad 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -414,11 +414,12 @@ public Config config() { builder.restrict(LocalDate.parse("2022-10-04"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2022-10-15"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); //Weihnachtsferien - builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); - builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); + //todo revert +// builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); +// builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); +// +// builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); +// builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); { From d4e116eacc2d38c19b807d03c2a57ea9622ae9f4 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Sat, 6 Aug 2022 11:11:09 +0200 Subject: [PATCH 048/128] runs jakob/2022-08-06/1-vax --- .../run/batch/CologneBMBF20220805_IfSG.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java index 30f8d60e9..57bc3a72e 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_IfSG.java @@ -934,10 +934,10 @@ public static final class Params { @GenerateSeeds(5) public long seed; - @StringParameter({"6.0"}) + @StringParameter({"off","3.0","6.0"}) public String StrainA; - @StringParameter({"off"}) + @StringParameter({"off", "3.0", "6.0"}) public String StrainB; @StringParameter({"2022-10-01"}) @@ -946,27 +946,32 @@ public static final class Params { // @StringParameter({"false", "true"}) // public String igA; // vaccination campaign - @StringParameter({"ba5Update", "mRNA", "off"}) + @StringParameter({"ba1Update","ba5Update", "mRNA", "off"}) public String vacType; //measures in the work context: // homeOff = 50% home office = work Rf cut in half // - @StringParameter({"none", "homeOff", "test", "mask", "all"}) +// @StringParameter({"none", "homeOff", "test", "mask", "all"}) + @StringParameter({"none"}) public String work; - @StringParameter({"none", "mask", "test", "all"}) +// @StringParameter({"none", "mask", "test", "all"}) + @StringParameter({"none"}) public String leis; // mask restrictions for "shop_daily", "shop_other", "errands" - @StringParameter({"none", "mask"}) +// @StringParameter({"none", "mask"}) + @StringParameter({"none"}) public String errands; - @StringParameter({"none", "maskVentTest"}) +// @StringParameter({"none", "maskVentTest"}) + @StringParameter({"none"}) public String edu; - @StringParameter({"mask"}) +// @StringParameter({"mask"}) + @StringParameter({"none"}) public String pt; } From 6be0760e9c584bc4550126f8b4a225ce8abbfa7d Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 23 Aug 2022 19:14:33 +0200 Subject: [PATCH 049/128] minor --- .../progression/AgeDependentDiseaseStatusTransitionModel.java | 4 +++- .../org/matsim/run/batch/CologneBMBF20220805_leisSplit.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/matsim/episim/model/progression/AgeDependentDiseaseStatusTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AgeDependentDiseaseStatusTransitionModel.java index 85b7e564e..6f72b99c0 100644 --- a/src/main/java/org/matsim/episim/model/progression/AgeDependentDiseaseStatusTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AgeDependentDiseaseStatusTransitionModel.java @@ -94,6 +94,8 @@ public double getProbaOfTransitioningToSeriouslySick(Immunizable person) { proba = 36. / 100; } + return proba * episimConfig.getHospitalFactor(); + // source 2 // if (age < 10) { @@ -153,7 +155,7 @@ public double getProbaOfTransitioningToSeriouslySick(Immunizable person) { // proba = 27.3 / 100; // } - return proba * episimConfig.getHospitalFactor(); + } @Override diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java index 28e1fb0ab..ceffd1490 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java @@ -695,6 +695,9 @@ public Config prepareConfig(int id, Params params) { // leisure: { +// testingRateForActivitiesRapid.get("leisPrivate").put(restrictionDate, 0.0); // was 0.1 +// testingRateForActivitiesRapidVac.get("leisPrivate").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapid.get("leisPublic").put(restrictionDate, 0.9); testingRateForActivitiesRapidVac.get("leisPublic").put(restrictionDate, gpTestRate); } From 8e5dcce37f3b20cf1dc9476dc91faeb3e5548fb6 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 1 Sep 2022 19:02:16 -0400 Subject: [PATCH 050/128] reinstitute xmas vacation --- .../run/modules/SnzCologneProductionScenario.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index c54539b7b..df3ad5c76 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -412,12 +412,11 @@ public Config config() { builder.restrict(LocalDate.parse("2022-10-04"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2022-10-15"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); //Weihnachtsferien - //TODO: uncomment xmas again -// builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); -// builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); -// -// builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); -// builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); + builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); + builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); { From ad576606f9cb8d7a3c530c4716365bf6a924c49c Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 15 Sep 2022 19:46:35 -0400 Subject: [PATCH 051/128] Vary Household Susceptibility --- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../batch/CologneVaryHhSusceptibility.java | 753 ++++++++++++++++++ 2 files changed, 755 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 243c94955..66b48dc94 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_IfSG") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneVaryHhSusceptibility") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20220805_IfSG$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneVaryHhSusceptibility$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java new file mode 100644 index 000000000..c86a1c07a --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -0,0 +1,753 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.testing.TestType; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneVaryHhSusceptibility implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 2.9; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + LocalDate start = null; + VaccinationType vaccinationType = VaccinationType.mRNA; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + String vacCamp = "off"; + + if (params != null) { +// mutEscBa5 = params.ba5Esc; + + if (!params.vacType.equals("off")) { + vacCamp = "age"; + vaccinationType = VaccinationType.valueOf(params.vacType); + } + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } + + start = LocalDate.parse(params.resDate); + + + + if (vacCamp.equals("age")) { + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + } + else if (vacCamp.equals("eu")) { + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + } + else if (vacCamp.equals("off")) { + + } else { + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } +// + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + +// double pHousehold = 1.0; + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(params.pctHh, params.hhSusc) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + + +// System.out.print("immunityGiver"); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// if (immunityFrom == VirusStrain.OMICRON_BA1) { +// System.out.print( "," + "BA.1"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { +// System.out.print( "," + "BA.2"); +// } else { +// System.out.print( "," + immunityFrom); +// } +// } +// +// +// for (ImmunityEvent immunityGiver : VaccinationType.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// for (ImmunityEvent immunityGiver : VirusStrain.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// +// System.out.println(); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * params.thetaFactor); + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + +// virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); + + //BA5 + double ba5Inf = 1.0; + double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); + } + +// STRAIN_B + if (!params.StrainB.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); + } + + // remove age-based susceptibility of strains starting with DELTA + + String ageSusc = "false"; + if (!Boolean.parseBoolean(ageSusc)) { + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : List.of(VirusStrain.DELTA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A)) { + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } + } + + // increase infectivity of alpha + virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * 1.4); + + double deltaTheta = 0.9; + virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * deltaTheta); + double ba1Inf = 1.9; // 2.0,2.1,2.2 + double ba2Inf = 1.7; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); + + + + + + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + Map infPerDayAlpha = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.ALPHA, new TreeMap<>())); + + + // reconfig disease import of alpha + LocalDate startDateAlpha = LocalDate.parse("2021-01-15"); + + for (int i = 0; i < 7; i++) { + infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); + } + + + infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); + + episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); + + + configureFutureDiseaseImport(params, episimConfig); + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + //school + String schoolUpdate = "yes"; + if(schoolUpdate.equals("yes")) { + // school closed completely until 21.2.2022 + builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); + builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + } else if (schoolUpdate.equals("no")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + String schoolTest = "later"; + if (schoolTest.equals("later")) { + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); +// TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); +// Map> testingRateForActivitiesPCR = pcrTest.getTestingRateForActivities(); + + + for (LocalDate date = LocalDate.parse("2021-03-19"); date.isBefore(LocalDate.parse("2021-04-25")); date = date.plusDays(1)) { + + testingRateForActivitiesRapid.get("educ_kiga").put(date, 0.); + testingRateForActivitiesRapid.get("educ_primary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_secondary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_tertiary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_other").put(date, 0.); + + } + + testingRateForActivitiesRapid.get("educ_kiga").put(LocalDate.parse("2021-09-20"), 0.); + testingRateForActivitiesRapid.get("educ_primary").put(LocalDate.parse("2021-09-20"), 0.); + +// testingRateForActivitiesPCR.get("educ_primary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_secondary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); + + } else if (schoolTest.equals("base")) { + + }else { + throw new RuntimeException("param value doesn't exist"); + } + + + // masks + //pt: masks + String maskType = "45to45"; + if (maskType.equals("45to45")) { + for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { + builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); + + } + } else if (maskType.equals("base")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + // vaccination + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); + vaccinationConfig.setTimePeriodIgA(730.); + + + //modify contact intensity + double workCi = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); + + + double leisureCi = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); + + + double schoolCi = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + + // add initial impulses for strains + //BA.1 +// LocalDate ba1Date = LocalDate.parse(params.ba1Date); +// for (int i = 0; i < 7; i++) { +// infPerDayBa1.put(ba1Date.plusDays(i), 4); +// } +// infPerDayBa1.put(ba1Date.plusDays(7), 1); + + + //BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + //BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB + if (!params.StrainB.equals("off")) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + + + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + if (!params.StrainB.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + @Parameter({1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6}) + public double thetaFactor; + + @Parameter({0.0, 0.1, 0.25, 0.5}) +// @Parameter({0.5}) + public double pctHh; + + @Parameter({0.01}) + public double hhSusc; + + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"off"}) + public String StrainA; + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"off"}) + public String StrainB; + + @StringParameter({"2022-12-01"}) + public String resDate; + +// @StringParameter({"false", "true"}) +// public String igA; + // vaccination campaign +// @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) + @StringParameter({"off"}) + public String vacType; + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneVaryHhSusceptibility.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + From 0be04bbeabf698e2527de6798fe3617cd694b003 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Tue, 20 Sep 2022 11:12:44 +0200 Subject: [PATCH 052/128] refactor reporting of persons stats --- .../org/matsim/episim/EpisimReporting.java | 39 +++++++++++++++++++ .../matsim/episim/InfectionEventHandler.java | 38 +++--------------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimReporting.java b/src/main/java/org/matsim/episim/EpisimReporting.java index fc5f427c2..5c25493ed 100644 --- a/src/main/java/org/matsim/episim/EpisimReporting.java +++ b/src/main/java/org/matsim/episim/EpisimReporting.java @@ -29,6 +29,8 @@ import it.unimi.dsi.fastutil.objects.ObjectIntPair; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; @@ -50,6 +52,7 @@ import java.nio.file.*; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.time.LocalDate; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -834,6 +837,42 @@ void reportAntibodyLevel(Object2DoubleMap antibodies, int n, int it writer.append(antibodiesPerPerson, out); } + /** + * Write detailed person information. Huge files and for debugging only. + */ + void reportDetailedPersonStats(LocalDate date, Collection persons) { + + try (CSVPrinter csv = new CSVPrinter(Files.newBufferedWriter(Path.of(base + "antibodies_" + date + ".tsv")), CSVFormat.TDF)) { + + csv.print("personId"); + csv.print("age"); + csv.print("nVaccinations"); + csv.print("nInfections"); + csv.print("immuneResponseMultiplier"); + + for (VirusStrain strain : VirusStrain.values()) { + csv.print(strain.toString()); + } + csv.println(); + + for (EpisimPerson person : persons) { + csv.print(person.getPersonId().toString()); + csv.print(person.getAge()); + csv.print(person.getNumVaccinations()); + csv.print(person.getNumInfections()); + csv.print(person.getImmuneResponseMultiplier()); + + for (VirusStrain strain : VirusStrain.values()) { + csv.print(person.getAntibodies(strain)); + } + csv.println(); + + } + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * Write outdoor fraction for each day. */ diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 09d5b3225..af6f6a140 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -777,39 +777,11 @@ public void reset(int iteration) { } } - -// if (date.equals(LocalDate.parse("2022-07-23"))) { -// if (date.getDayOfMonth() == 1) { -// try (CSVPrinter csv = new CSVPrinter(Files.newBufferedWriter(Path.of("antibodies_" + date + ".tsv")), CSVFormat.TDF)) { -// -// csv.print("personId"); -// csv.print("age"); -// csv.print("nVaccinations"); -// csv.print("nInfections"); -// csv.print("immuneResponseMultiplier"); -// -// for (VirusStrain strain : VirusStrain.values()) { -// csv.print(strain.toString()); -// } -// csv.println(); -// -// for (EpisimPerson person : personMap.values()) { -// csv.print(person.getPersonId().toString()); -// csv.print(person.getAge()); -// csv.print(person.getNumVaccinations()); -// csv.print(person.getNumInfections()); -// csv.print(person.getImmuneResponseMultiplier()); -// -// for (VirusStrain strain : VirusStrain.values()) { -// csv.print(person.getAntibodies(strain)); -// } -// csv.println(); -// -// } -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } + /* + if (date.equals(LocalDate.parse("2022-07-23"))) { + reporting.reportDetailedPersonStats(date, personMap.values()); + } + */ reporting.reportCpuTime(iteration, "ProgressionModelParallel", "start", -2); progressionModel.afterStateUpdates(personMap, iteration); From 2d7b9a77256c368d0698bf0df1015dbe2313a401 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Fri, 23 Sep 2022 09:55:44 +0200 Subject: [PATCH 053/128] refactor reporting of persons stats --- .../org/matsim/episim/EpisimReporting.java | 39 +++++++++++++++++++ .../matsim/episim/InfectionEventHandler.java | 39 +++---------------- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimReporting.java b/src/main/java/org/matsim/episim/EpisimReporting.java index fc5f427c2..5c25493ed 100644 --- a/src/main/java/org/matsim/episim/EpisimReporting.java +++ b/src/main/java/org/matsim/episim/EpisimReporting.java @@ -29,6 +29,8 @@ import it.unimi.dsi.fastutil.objects.ObjectIntPair; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; @@ -50,6 +52,7 @@ import java.nio.file.*; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.time.LocalDate; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -834,6 +837,42 @@ void reportAntibodyLevel(Object2DoubleMap antibodies, int n, int it writer.append(antibodiesPerPerson, out); } + /** + * Write detailed person information. Huge files and for debugging only. + */ + void reportDetailedPersonStats(LocalDate date, Collection persons) { + + try (CSVPrinter csv = new CSVPrinter(Files.newBufferedWriter(Path.of(base + "antibodies_" + date + ".tsv")), CSVFormat.TDF)) { + + csv.print("personId"); + csv.print("age"); + csv.print("nVaccinations"); + csv.print("nInfections"); + csv.print("immuneResponseMultiplier"); + + for (VirusStrain strain : VirusStrain.values()) { + csv.print(strain.toString()); + } + csv.println(); + + for (EpisimPerson person : persons) { + csv.print(person.getPersonId().toString()); + csv.print(person.getAge()); + csv.print(person.getNumVaccinations()); + csv.print(person.getNumInfections()); + csv.print(person.getImmuneResponseMultiplier()); + + for (VirusStrain strain : VirusStrain.values()) { + csv.print(person.getAntibodies(strain)); + } + csv.println(); + + } + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * Write outdoor fraction for each day. */ diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 09d5b3225..ec3972f79 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -776,40 +776,11 @@ public void reset(int iteration) { antibodies.mergeDouble(kv.getKey(), kv.getDoubleValue(), Double::sum); } } - - -// if (date.equals(LocalDate.parse("2022-07-23"))) { -// if (date.getDayOfMonth() == 1) { -// try (CSVPrinter csv = new CSVPrinter(Files.newBufferedWriter(Path.of("antibodies_" + date + ".tsv")), CSVFormat.TDF)) { -// -// csv.print("personId"); -// csv.print("age"); -// csv.print("nVaccinations"); -// csv.print("nInfections"); -// csv.print("immuneResponseMultiplier"); -// -// for (VirusStrain strain : VirusStrain.values()) { -// csv.print(strain.toString()); -// } -// csv.println(); -// -// for (EpisimPerson person : personMap.values()) { -// csv.print(person.getPersonId().toString()); -// csv.print(person.getAge()); -// csv.print(person.getNumVaccinations()); -// csv.print(person.getNumInfections()); -// csv.print(person.getImmuneResponseMultiplier()); -// -// for (VirusStrain strain : VirusStrain.values()) { -// csv.print(person.getAntibodies(strain)); -// } -// csv.println(); -// -// } -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } + + if (date.getDayOfMonth() == 1) { + reporting.reportDetailedPersonStats(date, personMap.values()); + } + reporting.reportCpuTime(iteration, "ProgressionModelParallel", "start", -2); progressionModel.afterStateUpdates(personMap, iteration); From fb1d006a36777aa2309398ddbf1bebae4649431b Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Fri, 23 Sep 2022 09:56:03 +0200 Subject: [PATCH 054/128] more theta options --- .../java/org/matsim/run/batch/CologneVaryHhSusceptibility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index c86a1c07a..08021d52a 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -705,7 +705,7 @@ public static final class Params { @GenerateSeeds(5) public long seed; - @Parameter({1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6}) + @Parameter({1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.8, 2.0, 2.2}) public double thetaFactor; @Parameter({0.0, 0.1, 0.25, 0.5}) From f2b59092220a5c9afc42f566f7b1baf78e0b4b73 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Thu, 29 Sep 2022 16:26:22 +0200 Subject: [PATCH 055/128] new params --- .../org/matsim/run/batch/CologneVaryHhSusceptibility.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 08021d52a..dfd6b641b 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -705,10 +705,10 @@ public static final class Params { @GenerateSeeds(5) public long seed; - @Parameter({1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.8, 2.0, 2.2}) + @Parameter({1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2}) public double thetaFactor; - @Parameter({0.0, 0.1, 0.25, 0.5}) + @Parameter({0.3, 0.35, 0.4, 0.45, 0.5}) // @Parameter({0.5}) public double pctHh; From 0941a74a13ce28707b1103bf832253881bcba979 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Thu, 29 Sep 2022 16:44:55 +0200 Subject: [PATCH 056/128] update default antibody model config --- .../matsim/episim/model/AntibodyModel.java | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/AntibodyModel.java b/src/main/java/org/matsim/episim/model/AntibodyModel.java index 31a8cfc27..b7b5456f4 100644 --- a/src/main/java/org/matsim/episim/model/AntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/AntibodyModel.java @@ -80,7 +80,9 @@ public Config() { //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. //The other values come from Rössler et al. - double mutEscBa5 = 3.0; + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 2.9; //Wildtype double mRNAAlpha = 29.2; @@ -92,8 +94,8 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); //Alpha initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); @@ -104,47 +106,47 @@ public Config() { initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); //DELTA - double mRNADelta = 10.9; + double mRNADelta = mRNAAlpha / mutEscDelta; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150. / 300.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64. / 300.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64. / 300.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450. / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.2 / 6.4); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); //BA.1 - double mRNABA1 = 1.9; + double mRNABA1 = mRNADelta / mutEscBa1; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4. / 20.); //??? - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6. / 20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6. / 20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8. / 20.); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); //todo: is 1.4 - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNADelta / mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); //BA.2 double mRNABA2 = mRNABA1; initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4. / 20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6. / 20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6. / 20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8. / 20.); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNADelta / mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); //BA.5 @@ -154,14 +156,14 @@ public Config() { initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / 1.4 / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); //todo ??? - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNADelta); // mRNAAlpha / mutEscBa5 - + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); Map> antibodyRefreshFactors = new HashMap<>(); - for (VaccinationType immunityType : VaccinationType.values()) { + + for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>(VirusStrain.class)); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -173,6 +175,9 @@ public Config() { else if (immunityType == VaccinationType.ba1Update) { antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } else { antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); } From 6f2035b329a04db05e9401357842ea463adad867 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 10:45:13 +0200 Subject: [PATCH 057/128] updated batch & commented immunisation stats output --- .../matsim/episim/InfectionEventHandler.java | 13 ++- .../batch/CologneVaryHhSusceptibility.java | 95 ++++++++++++------- 2 files changed, 71 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index ec3972f79..5fd9ea8bc 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -776,11 +776,14 @@ public void reset(int iteration) { antibodies.mergeDouble(kv.getKey(), kv.getDoubleValue(), Double::sum); } } - - if (date.getDayOfMonth() == 1) { - reporting.reportDetailedPersonStats(date, personMap.values()); - } - + + // uncomment if you want immunisation stats to be printed on a certain + // date or e.g. every month. This produces a lot of large files so use + // sparingly. +// if (date.getDayOfMonth() == 1) { +// reporting.reportDetailedPersonStats(date, personMap.values()); +// } + reporting.reportCpuTime(iteration, "ProgressionModelParallel", "start", -2); progressionModel.afterStateUpdates(personMap, iteration); diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index dfd6b641b..6866a542f 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -7,6 +7,7 @@ import com.google.inject.util.Modules; import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import jdk.jshell.execution.Util; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.episim.*; @@ -377,7 +378,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0 && params.importSummer2022.equals("on")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -396,6 +397,10 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * params.thetaFactor); + //snapshot + episimConfig.setSnapshotInterval(766); + + //--------------------------------------- // S T R A I N S //--------------------------------------- @@ -551,6 +556,14 @@ public Config prepareConfig(int id, Params params) { throw new RuntimeException("param value doesn't exist"); } + if (params.skipSchool.equals("yes")) { + builder.restrict(LocalDate.parse("2022-08-09"), 0.2, "educ_kiga", "educ_primary", "educ_secondary", "educ_tertiary", "educ_other"); + } else if (params.skipSchool.equals("no")) { + + } else { + throw new RuntimeException(); + } + episimConfig.setPolicy(builder.build()); @@ -586,7 +599,6 @@ public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); - } return config; @@ -654,39 +666,47 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import - NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); - LocalDate date = null; - for (Map.Entry entry : data.entrySet()) { - date = entry.getKey(); - double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model + if (params.importSummer2022.equals("on")) { + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model // - double cases = factor * entry.getValue(); + double cases = factor * entry.getValue(); - if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { - if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - } - else if (!params.StrainA.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else if (!params.StrainB.equals("off")) { - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else { - throw new RuntimeException(); + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); } - infPerDayBa5.put(date, 1); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa5)) { - infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa2)) { - infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); - } + } + } else if (params.importSummer2022.equals("off")) { + } else { + throw new RuntimeException(); } + + + // save disease import episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); @@ -705,11 +725,22 @@ public static final class Params { @GenerateSeeds(5) public long seed; - @Parameter({1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2}) +// @StringParameter({"on", "off"}) + @StringParameter({"on"}) + public String importSummer2022; + +// @StringParameter({"yes", "no"}) + @StringParameter({"no"}) + public String skipSchool; + + + +// @Parameter({1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2}) + @Parameter({1.7}) public double thetaFactor; - @Parameter({0.3, 0.35, 0.4, 0.45, 0.5}) -// @Parameter({0.5}) +// @Parameter({0.3, 0.35, 0.4, 0.45, 0.5}) + @Parameter({0.35}) public double pctHh; @Parameter({0.01}) From 6918ccd60e3645164798111d4e1b9e4c215eee44 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 11:42:48 +0200 Subject: [PATCH 058/128] added new params to batch --- .../batch/CologneVaryHhSusceptibility.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 6866a542f..84138bc38 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -7,7 +7,6 @@ import com.google.inject.util.Modules; import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2DoubleMap; -import jdk.jshell.execution.Util; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.episim.*; @@ -556,13 +555,13 @@ public Config prepareConfig(int id, Params params) { throw new RuntimeException("param value doesn't exist"); } - if (params.skipSchool.equals("yes")) { - builder.restrict(LocalDate.parse("2022-08-09"), 0.2, "educ_kiga", "educ_primary", "educ_secondary", "educ_tertiary", "educ_other"); - } else if (params.skipSchool.equals("no")) { - } else { - throw new RuntimeException(); - } + // Ci Correction after summer vacation 2022 (more air flow?) + builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), params.eduRfVacation, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); episimConfig.setPolicy(builder.build()); @@ -589,12 +588,12 @@ public Config prepareConfig(int id, Params params) { double schoolCi = 0.75; - episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); if (DEBUG_MODE) { @@ -725,15 +724,19 @@ public static final class Params { @GenerateSeeds(5) public long seed; -// @StringParameter({"on", "off"}) - @StringParameter({"on"}) + @StringParameter({"on", "off"}) public String importSummer2022; -// @StringParameter({"yes", "no"}) - @StringParameter({"no"}) - public String skipSchool; + @Parameter({0.5, 0.75, 1.0}) + public double eduSeasonality; + // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow + @Parameter({0.25, 0.5, 0.75}) + public double ciCorr; + //how much "school" activity takes places during vacation summmer 2022 + @Parameter({0.2, 0.4, 0.6, 0.8, 1.0}) + public double eduRfVacation; // @Parameter({1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2}) @Parameter({1.7}) From 7b5fe6cab00737db6869a4c18ab3420f2ea99d61 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 11:59:03 +0200 Subject: [PATCH 059/128] run jakob/2022-10-07/2-fix (added snapshot) --- .../org/matsim/run/batch/CologneVaryHhSusceptibility.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 84138bc38..102e3e3a1 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -397,7 +397,9 @@ public Config prepareConfig(int id, Params params) { //snapshot - episimConfig.setSnapshotInterval(766); +// episimConfig.setSnapshotInterval(766); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-07/" + params.seed + "-766-2022-03-31.zip"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- From 5147bf56dd03680c4a0770771ae54342147d2f61 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 12:46:30 +0200 Subject: [PATCH 060/128] moved disease import --- .../batch/CologneVaryHhSusceptibility.java | 104 ++---------------- .../java/org/matsim/run/batch/UtilsJR.java | 32 +++++- .../modules/SnzCologneProductionScenario.java | 89 +++++++++++---- 3 files changed, 107 insertions(+), 118 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 102e3e3a1..7b1c96392 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -7,6 +7,7 @@ import com.google.inject.util.Modules; import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import jdk.jshell.execution.Util; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.episim.*; @@ -31,7 +32,7 @@ */ public class CologneVaryHhSusceptibility implements BatchRun { - boolean DEBUG_MODE = false; + boolean DEBUG_MODE = true; int runCount = 0; @Nullable @@ -119,6 +120,7 @@ else if (vacCamp.equals("off")) { if (params == null) return; // double pHousehold = 1.0; + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. bind(HouseholdSusceptibility.Config.class).toInstance( HouseholdSusceptibility.newConfig() .withSusceptibleHouseholds(params.pctHh, params.hhSusc) @@ -310,33 +312,7 @@ else if (immunityType == VaccinationType.ba5Update) { } - -// System.out.print("immunityGiver"); -// for (VirusStrain immunityFrom : VirusStrain.values()) { -// if (immunityFrom == VirusStrain.OMICRON_BA1) { -// System.out.print( "," + "BA.1"); -// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { -// System.out.print( "," + "BA.2"); -// } else { -// System.out.print( "," + immunityFrom); -// } -// } -// -// -// for (ImmunityEvent immunityGiver : VaccinationType.values()) { -// System.out.print("\n" + immunityGiver); -// for (VirusStrain immunityFrom : VirusStrain.values()) { -// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); -// } -// } -// for (ImmunityEvent immunityGiver : VirusStrain.values()) { -// System.out.print("\n" + immunityGiver); -// for (VirusStrain immunityFrom : VirusStrain.values()) { -// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); -// } -// } -// -// System.out.println(); +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); } }); @@ -471,22 +447,6 @@ public Config prepareConfig(int id, Params params) { // I M P O R T //--------------------------------------- - Map infPerDayAlpha = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.ALPHA, new TreeMap<>())); - - - // reconfig disease import of alpha - LocalDate startDateAlpha = LocalDate.parse("2021-01-15"); - - for (int i = 0; i < 7; i++) { - infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); - } - - - infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); - - episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); - - configureFutureDiseaseImport(params, episimConfig); //--------------------------------------- @@ -572,30 +532,14 @@ public Config prepareConfig(int id, Params params) { // M I S C //--------------------------------------- - // vaccination - VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); - vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); - vaccinationConfig.setTimePeriodIgA(730.); - - //modify contact intensity - double workCi = 0.75; - episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); - episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); - - - double leisureCi = 0.4; - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); - episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); - - - double schoolCi = 0.75; - episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi).setSeasonality(params.eduSeasonality); + // modify seasonality + episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); if (DEBUG_MODE) { @@ -612,30 +556,6 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); - - // add initial impulses for strains - //BA.1 -// LocalDate ba1Date = LocalDate.parse(params.ba1Date); -// for (int i = 0; i < 7; i++) { -// infPerDayBa1.put(ba1Date.plusDays(i), 4); -// } -// infPerDayBa1.put(ba1Date.plusDays(7), 1); - - - //BA.2 - LocalDate ba2Date = LocalDate.parse("2021-12-18"); - for (int i = 0; i < 7; i++) { - infPerDayBa2.put(ba2Date.plusDays(i), 4); - } - infPerDayBa2.put(ba2Date.plusDays(7), 1); - - //BA.5 - LocalDate ba5Date = LocalDate.parse("2022-04-10"); - for (int i = 0; i < 7; i++) { - infPerDayBa5.put(ba5Date.plusDays(i), 4); - } - infPerDayBa5.put(ba5Date.plusDays(7), 1); - //StrainA if (!params.StrainA.equals("off")) { infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); @@ -706,8 +626,6 @@ else if (!params.StrainB.equals("off")) { } - - // save disease import episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); diff --git a/src/main/java/org/matsim/run/batch/UtilsJR.java b/src/main/java/org/matsim/run/batch/UtilsJR.java index 3ff3edfee..fc0a43d71 100644 --- a/src/main/java/org/matsim/run/batch/UtilsJR.java +++ b/src/main/java/org/matsim/run/batch/UtilsJR.java @@ -2,6 +2,8 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigValue; +import org.matsim.episim.model.ImmunityEvent; +import org.matsim.episim.model.VaccinationType; import org.matsim.episim.model.VirusStrain; import tech.tablesaw.api.DateColumn; import tech.tablesaw.api.DoubleColumn; @@ -104,7 +106,7 @@ static void produceMaskPlot(Config policyConfig) { // } } -// producePlot(recordsDate,values,groupings,"import by strain", "import", "importByStrain.html"); +// producePlot(recordsDate,values,groupings,"import by strain", "import", "importByStrain-old22.html"); @@ -146,4 +148,32 @@ private static void producePlot(DateColumn records, DoubleColumn values, StringC } + protected static void printInitialAntibodiesToConsole(Map> initialAntibodies) { + System.out.print("immunityGiver"); + for (VirusStrain immunityFrom : VirusStrain.values()) { + if (immunityFrom == VirusStrain.OMICRON_BA1) { + System.out.print( "," + "BA.1"); + } else if (immunityFrom == VirusStrain.OMICRON_BA2) { + System.out.print( "," + "BA.2"); + } else { + System.out.print( "," + immunityFrom); + } + } + + + for (ImmunityEvent immunityGiver : VaccinationType.values()) { + System.out.print("\n" + immunityGiver); + for (VirusStrain immunityFrom : VirusStrain.values()) { + System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); + } + } + for (ImmunityEvent immunityGiver : VirusStrain.values()) { + System.out.print("\n" + immunityGiver); + for (VirusStrain immunityFrom : VirusStrain.values()) { + System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); + } + } + + System.out.println(); + } } diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index df3ad5c76..61e49dc6f 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -314,44 +314,56 @@ public Config config() { episimConfig.setThreads(8); episimConfig.setDaysInfectious(Integer.MAX_VALUE); - episimConfig.getOrAddContainerParams("work").setSeasonality(0.5); - - double leisCi = 0.6; - - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(9.24 * leisCi); - - episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("educ_other").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("errands").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("business").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("visit").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("home").setSeasonality(0.5); - episimConfig.getOrAddContainerParams("quarantine_home").setSeasonality(0.5); - - //progression model //episimConfig.setProgressionConfig(AbstractSnzScenario2020.baseProgressionConfig(Transition.config()).build()); episimConfig.setProgressionConfig(SnzProductionScenario.progressionConfig(Transition.config()).build());// TODO: why does this immediately override? - //inital infections and import + //DISEASE IMPORT episimConfig.setInitialInfections(Integer.MAX_VALUE); if (this.diseaseImport != DiseaseImport.no) { - // SnzProductionScenario.configureDiseaseImport(episimConfig, diseaseImport, importOffset, - // cologneFactor * imprtFctMult, importFactorBeforeJune, importFactorAfterJune); - //disease import 2020 configureDiseaseImport(cologneFactor, episimConfig); } - //contact intensities + //CONTACT INTENSITY SnzProductionScenario.configureContactIntensities(episimConfig); + //work + double workCi = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); + + //leisure & visit + double leisureCi = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * 0.6 * leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); + + + //school + double schoolCi = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); + + + //SEASONALITY + episimConfig.getOrAddContainerParams("work").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("educ_other").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("errands").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("business").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("visit").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("home").setSeasonality(0.5); + episimConfig.getOrAddContainerParams("quarantine_home").setSeasonality(0.5); //restrictions and masks CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); @@ -909,6 +921,7 @@ private void configureDiseaseImport(double cologneFactor, EpisimConfigGroup epis } } + double facWild = 4.0; double facAlpha = 4.0; double facDelta = 4.0; @@ -962,6 +975,34 @@ private void configureDiseaseImport(double cologneFactor, EpisimConfigGroup epis LocalDate dateAfterCsvEnds = date.plusDays(1); infPerDayBa2.put(dateAfterCsvEnds, 1); + // initial import alpha + LocalDate startDateAlpha = LocalDate.parse("2021-01-15"); + for (int i = 0; i < 7; i++) { + infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); + } + infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); + + // initial import BA.1 // TODO: Why did we comment this out +// LocalDate ba1Date = LocalDate.parse(params.ba1Date); +// for (int i = 0; i < 7; i++) { +// infPerDayBa1.put(ba1Date.plusDays(i), 4); +// } +// infPerDayBa1.put(ba1Date.plusDays(7), 1); + + + // initial import BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + // initial import BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); // set all initial infections episimConfig.setInfections_pers_per_day(VirusStrain.SARS_CoV_2, infPerDayWild); From e13455161d5dc0a59d17ae8931c269344dd7ed63 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 13:01:47 +0200 Subject: [PATCH 061/128] moved strain configuration to prod scenario --- .../batch/CologneVaryHhSusceptibility.java | 38 ++++------------- .../modules/SnzCologneProductionScenario.java | 42 ++++++++++--------- 2 files changed, 30 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 7b1c96392..2a6c422ec 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -384,34 +384,25 @@ public Config prepareConfig(int id, Params params) { VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - -// virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); - - //BA5 - double ba5Inf = 1.0; - double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); - + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); // STRAIN_A if (!params.StrainA.equals("off")) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); } // STRAIN_B if (!params.StrainB.equals("off")) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); } // remove age-based susceptibility of strains starting with DELTA @@ -428,19 +419,6 @@ public Config prepareConfig(int id, Params params) { } } - // increase infectivity of alpha - virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * 1.4); - - double deltaTheta = 0.9; - virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * deltaTheta); - double ba1Inf = 1.9; // 2.0,2.1,2.2 - double ba2Inf = 1.7; - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); - - - - //--------------------------------------- diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 61e49dc6f..6ebb69723 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -609,10 +609,10 @@ public Config config() { episimConfig.setPolicy(builder.build()); + //configure strains //alpha - double aInf = 1.9; -// SnzProductionScenario.configureStrains(episimConfig, ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class)); + double aInf = 1.9 * 1.4; VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(aInf); virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setFactorSeriouslySick(0.5); @@ -620,34 +620,36 @@ public Config config() { //delta - double deltaInf = 3.1; + double deltaInf = 3.1 * 0.9; double deltaHos = 1.0; virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(deltaInf); virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setFactorSeriouslySick(deltaHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setFactorSeriouslySickVaccinated(deltaHos); - //omicron -// double oInf = params.ba1Inf; + //BA.1 double oHos = 0.2; - double ba1Inf = 2.2; - - if (ba1Inf > 0) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(deltaInf * ba1Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorSeriouslySick(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorSeriouslySickVaccinated(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorCritical(oHos); - } + double ba1Inf = 1.9 * deltaInf; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(ba1Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorCritical(oHos); //BA.2 - double ba2Inf = 1.7; - if (ba2Inf > 0) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(deltaInf * ba1Inf * ba2Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorSeriouslySick(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorSeriouslySickVaccinated(oHos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorCritical(oHos); - } + double ba2Inf = 1.7 * ba1Inf; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(ba2Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorCritical(oHos); + + //BA.5 + double ba5Inf = ba2Inf; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + //--------------------------------------- // T E S T I N G From 2f6aa0fbcf4c1bb97004780ef770d2dc67c85893 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 15:43:48 +0200 Subject: [PATCH 062/128] updated tests --- .../batch/CologneVaryHhSusceptibility.java | 51 +------------------ .../modules/SnzCologneProductionScenario.java | 51 +++++++++---------- 2 files changed, 25 insertions(+), 77 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 2a6c422ec..1010c8675 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -405,7 +405,7 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); } - // remove age-based susceptibility of strains starting with DELTA + // remove age-based susceptibility of strains starting with DELTA TODO: how to integrate into the prod scenario? String ageSusc = "false"; if (!Boolean.parseBoolean(ageSusc)) { @@ -433,61 +433,12 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - //school - String schoolUpdate = "yes"; - if(schoolUpdate.equals("yes")) { - // school closed completely until 21.2.2022 - builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); - builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - } else if (schoolUpdate.equals("no")) { - - } else { - throw new RuntimeException("param value doesn't exist"); - } - - String schoolTest = "later"; - if (schoolTest.equals("later")) { - TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); - TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); -// TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); - Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); -// Map> testingRateForActivitiesPCR = pcrTest.getTestingRateForActivities(); - - - for (LocalDate date = LocalDate.parse("2021-03-19"); date.isBefore(LocalDate.parse("2021-04-25")); date = date.plusDays(1)) { - - testingRateForActivitiesRapid.get("educ_kiga").put(date, 0.); - testingRateForActivitiesRapid.get("educ_primary").put(date, 0.); - testingRateForActivitiesRapid.get("educ_secondary").put(date, 0.); - testingRateForActivitiesRapid.get("educ_tertiary").put(date, 0.); - testingRateForActivitiesRapid.get("educ_other").put(date, 0.); - - } - - testingRateForActivitiesRapid.get("educ_kiga").put(LocalDate.parse("2021-09-20"), 0.); - testingRateForActivitiesRapid.get("educ_primary").put(LocalDate.parse("2021-09-20"), 0.); - -// testingRateForActivitiesPCR.get("educ_primary").put(LocalDate.parse("2021-05-10"), 0.4); - testingRateForActivitiesRapid.get("educ_secondary").put(LocalDate.parse("2021-05-10"), 0.4); - testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); - testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); - - } else if (schoolTest.equals("base")) { - - }else { - throw new RuntimeException("param value doesn't exist"); - } - - // masks //pt: masks String maskType = "45to45"; if (maskType.equals("45to45")) { for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); - } } else if (maskType.equals("base")) { diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 6ebb69723..9b557ada8 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -392,9 +392,10 @@ public Config config() { //Herbstferien builder.restrict(LocalDate.parse("2020-10-12"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2020-10-23"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - //Weihnachtsferien TODO: check end date; shouldn't it be 2021-01-06 + //Weihnachtsferien builder.restrict(LocalDate.parse("2020-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.restrict(LocalDate.parse("2021-01-11"), 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); + builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); //Osterferien builder.restrict(LocalDate.parse("2021-03-29"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2021-04-10"), 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); @@ -431,6 +432,8 @@ public Config config() { builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); + + { LocalDate masksCenterDate = LocalDate.of(2020, 4, 27); for (int ii = 0; ii <= 14; ii++) { @@ -694,29 +697,33 @@ public Config config() { testingConfigGroup.setHouseholdCompliance(1.0); - LocalDate testingStartDate = LocalDate.parse("2021-03-19"); - Map leisureTests = new HashMap(); Map workTests = new HashMap(); Map eduTests = new HashMap(); Map kigaPrimaryTests = new HashMap(); Map uniTests = new HashMap(); + leisureTests.put(LocalDate.parse("2020-01-01"), 0.); workTests.put(LocalDate.parse("2020-01-01"), 0.); eduTests.put(LocalDate.parse("2020-01-01"), 0.); kigaPrimaryTests.put(LocalDate.parse("2020-01-01"), 0.); uniTests.put(LocalDate.parse("2020-01-01"), 0.); + + LocalDate testingStartDate = LocalDate.parse("2021-03-19"); + for (int i = 1; i <= 31; i++) { leisureTests.put(testingStartDate.plusDays(i), 0.1 * i / 31.); workTests.put(testingStartDate.plusDays(i), 0.1 * i / 31.); - eduTests.put(testingStartDate.plusDays(i), 0.4 * i / 31.); - kigaPrimaryTests.put(testingStartDate.plusDays(i), 0.4 * i / 31.); uniTests.put(testingStartDate.plusDays(i), 0.8 * i / 31.); +// eduTests.put(testingStartDateEdu.plusDays(i), 0.4 * i / 31.); +// kigaPrimaryTests.put(testingStartDateEdu.plusDays(i), 0.4 * i / 31.); } - kigaPrimaryTests.put(LocalDate.parse("2021-05-10"), 0.0); + eduTests.put(LocalDate.parse("2021-04-25"), 0.4); + +// kigaPrimaryTests.put(LocalDate.parse("2021-05-10"), 0.0); workTests.put(LocalDate.parse("2021-06-04"), 0.05); @@ -733,23 +740,19 @@ public Config config() { // 3g removed for work workTests.put(LocalDate.of(2022, 3, 20), 0.); -// if (testing.equals("no")) { // turn of school tests after easter break - kigaPrimaryTests.put(LocalDate.of(2022, 4, 25), 0.0); +// kigaPrimaryTests.put(LocalDate.of(2022, 4, 25), 0.0); eduTests.put(LocalDate.of(2022, 4, 25), 0.0); uniTests.put(LocalDate.of(2022, 4, 25), 0.0); -// } - - // no more regulation regarding test, we assume once every 2 weeks - leisureTests.put(LocalDate.of(2022, 4, 25), 0.1); + leisureTests.put(LocalDate.of(2022, 4, 25), 0.1); // no more regulation regarding test, we assume once every 2 weeks rapidTest.setTestingRatePerActivityAndDate((Map.of( "leisure", leisureTests, "work", workTests, "business", workTests, - "educ_kiga", eduTests, - "educ_primary", eduTests, + "educ_kiga", kigaPrimaryTests, + "educ_primary", kigaPrimaryTests, "educ_secondary", eduTests, "educ_tertiary", eduTests, "educ_higher", uniTests, @@ -796,30 +799,24 @@ public Config config() { Map leisureTestsPCR = new HashMap(); Map workTestsPCR = new HashMap(); - Map kigaPramaryTestsPCR = new HashMap(); + Map kigaPrimaryTestsPCR = new HashMap(); Map eduTestsPCR = new HashMap(); leisureTestsPCR.put(LocalDate.parse("2020-01-01"), 0.); workTestsPCR.put(LocalDate.parse("2020-01-01"), 0.); - kigaPramaryTestsPCR.put(LocalDate.parse("2020-01-01"), 0.); + kigaPrimaryTestsPCR.put(LocalDate.parse("2020-01-01"), 0.); eduTestsPCR.put(LocalDate.parse("2020-01-01"), 0.); - kigaPramaryTestsPCR.put(LocalDate.parse("2021-05-10"), 0.4); - -// if (testing.equals("no")) { - leisureTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); - workTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); - kigaPramaryTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); - eduTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); -// } + kigaPrimaryTestsPCR.put(LocalDate.parse("2021-05-10"), 0.4); + kigaPrimaryTestsPCR.put(LocalDate.of(2022, 4, 25), 0.0); pcrTest.setTestingRatePerActivityAndDate((Map.of( "leisure", leisureTestsPCR, "work", workTestsPCR, "business", workTestsPCR, - "educ_kiga", kigaPramaryTestsPCR, - "educ_primary", kigaPramaryTestsPCR, + "educ_kiga", kigaPrimaryTestsPCR, + "educ_primary", kigaPrimaryTestsPCR, "educ_secondary", eduTestsPCR, "educ_tertiary", eduTestsPCR, "educ_higher", eduTestsPCR, From 2e9c04876d4761776dfb2f0db72b77a274c3cde3 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 15:59:59 +0200 Subject: [PATCH 063/128] simplified some params and moved masks to prod scenario --- .../batch/CologneVaryHhSusceptibility.java | 31 ++----------------- .../modules/SnzCologneProductionScenario.java | 6 ++++ 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 1010c8675..33ed39cd4 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -32,7 +32,7 @@ */ public class CologneVaryHhSusceptibility implements BatchRun { - boolean DEBUG_MODE = true; + boolean DEBUG_MODE = false; int runCount = 0; @Nullable @@ -123,7 +123,7 @@ else if (vacCamp.equals("off")) { // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. bind(HouseholdSusceptibility.Config.class).toInstance( HouseholdSusceptibility.newConfig() - .withSusceptibleHouseholds(params.pctHh, params.hhSusc) + .withSusceptibleHouseholds(0.35, 0.01) // .withNonVaccinableHouseholds(params.nonVaccinableHh) // .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) // .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) @@ -364,12 +364,11 @@ public Config prepareConfig(int id, Params params) { Config config = module.config(); - config.global().setRandomSeed(params.seed); EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * params.thetaFactor); + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot @@ -433,20 +432,6 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - // masks - //pt: masks - String maskType = "45to45"; - if (maskType.equals("45to45")) { - for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { - builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); - } - } else if (maskType.equals("base")) { - - } else { - throw new RuntimeException("param value doesn't exist"); - } - - // Ci Correction after summer vacation 2022 (more air flow?) builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); @@ -587,16 +572,6 @@ public static final class Params { @Parameter({0.2, 0.4, 0.6, 0.8, 1.0}) public double eduRfVacation; -// @Parameter({1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2}) - @Parameter({1.7}) - public double thetaFactor; - -// @Parameter({0.3, 0.35, 0.4, 0.45, 0.5}) - @Parameter({0.35}) - public double pctHh; - - @Parameter({0.01}) - public double hhSusc; // @StringParameter({"off", "3.0", "6.0"}) diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 9b557ada8..5e69a63a5 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -473,10 +473,16 @@ public Config config() { double schoolFac = 0.5; builder.restrict(LocalDate.parse("2021-08-17"), Restriction.ofCiCorrection(1 - (0.5 * schoolFac)), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { + builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); + } + builder.restrict(LocalDate.parse("2021-08-17"), Restriction.ofMask(FaceMask.N95, 0.9 * schoolFac), "educ_primary", "educ_secondary", "educ_higher", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2021-11-02"), Restriction.ofMask(FaceMask.N95, 0.0), "educ_primary", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2021-12-02"), Restriction.ofMask(FaceMask.N95, 0.9 * schoolFac), "educ_primary", "educ_secondary", "educ_tertiary", "educ_other"); + + // mask mandate removed builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(FaceMask.N95, 0.), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "leisure", "work", "business"); //todo: check From 386b4c740ddb9cce8defe8602040b13aeec292ce Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 16:09:49 +0200 Subject: [PATCH 064/128] cherry pick old batch class into this branch --- .../batch/CologneBMBF20220805_leisSplit.java | 1008 +++++++++++++++++ 1 file changed, 1008 insertions(+) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java new file mode 100644 index 000000000..b3d96ffbf --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20220805_leisSplit.java @@ -0,0 +1,1008 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.testing.DefaultTestingModel; +import org.matsim.episim.model.testing.FlexibleTestingModel; +import org.matsim.episim.model.testing.TestType; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.*; +import java.util.function.BiFunction; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF20220805_leisSplit implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // BIND ANTIBODY MODEL + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 2.9; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + if (params != null && !params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (params != null && !params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } + + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + + // BIND VACCINATION MODEL + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + LocalDate start = LocalDate.parse("2022-12-01"); + + VaccinationType vaccinationType = VaccinationType.mRNA; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + String vacCamp = "off"; + + if (params != null) { + + if (!params.vacType.equals("off")) { + vacCamp = "age"; + vaccinationType = VaccinationType.valueOf(params.vacType); + } + +// start = LocalDate.parse(params.resDate); + + + switch (vacCamp) { + case "age": + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + break; + case "eu": + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + break; + case "off": + break; + default: + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } + + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + + + // BIND TESTING MODEL + if (params != null){ + + // date of no restrictions and new restrictions + String unResDate = "2022-04-25"; + LocalDate unresDate = LocalDate.parse(unResDate); + LocalDate resDate = LocalDate.parse(params.resDate); + +// String[] s = params.gpMonths.split("-"); + + // Green pass validity for vaccinated and infected +// int vacDays = Integer.parseInt(s[0]) * 30; +// int infDays = Integer.parseInt(s[1]) * 30; + + // set days gp is valid + int vacDays = 3 * 30; + int infDays = 3 * 30; + + // set testing scheme for each activity type + final CologneBMBF220628_3G.TestScheme leisTest; + final CologneBMBF220628_3G.TestScheme workTest; + final CologneBMBF220628_3G.TestScheme eduTest; + if (params.leis.equals("test") || params.leis.equals("all")) { + leisTest= CologneBMBF220628_3G.TestScheme.gp; + } else if (params.leis.equals("none") || params.leis.equals("mask")) { + leisTest = CologneBMBF220628_3G.TestScheme.none; + } else { + throw new RuntimeException(); + } + + + if (params.work.equals("test") || params.work.equals("all")) { + workTest= CologneBMBF220628_3G.TestScheme.all; + } else if (params.work.equals("none") || params.work.equals("mask")|| params.work.equals("homeOff")) { + workTest = CologneBMBF220628_3G.TestScheme.none; + } else { + throw new RuntimeException(); + } + + if (params.edu.equals("maskVentTest")) { + eduTest = CologneBMBF220628_3G.TestScheme.all; + } else if (params.edu.equals("none")) { + eduTest = CologneBMBF220628_3G.TestScheme.none; + } else {throw new RuntimeException();} + + bind(FlexibleTestingModel.TestRate.class).toInstance((person, day, dow, date, test, vac) -> { + + if (date.isBefore(unresDate)) + return vac.hasValidVaccination(person, day, date); + + // When restrictions have been lifted, days valid is set to a high number + // many tests are voluntary + if (date.isBefore(resDate)) + return vac.hasValidVaccination(person, day, date, 360); + + // this returns true if for any activities, the person requires increased testing regime + BiFunction anyUnVac = (act, red) -> { + + boolean res = false; + CologneBMBF220628_3G.TestScheme scheme = null; + + + if (act.startsWith("leis")) + scheme = leisTest; + else if (act.equals("work")) + scheme = workTest; + else if (act.startsWith("edu")) + scheme = eduTest; + + // null and none, will be false + if (scheme == CologneBMBF220628_3G.TestScheme.all) + res = true; + else if (scheme == CologneBMBF220628_3G.TestScheme.gp) { + res = (person.getNumVaccinations() == 0 || person.daysSince(EpisimPerson.VaccinationStatus.yes, day) > vacDays) + && !person.isRecentlyRecovered(day, infDays); + + } + + return red || res; + }; + + return !person.matchActivities(dow, anyUnVac, false); + }); + + bind(FlexibleTestingModel.TestPolicy.class).toInstance(new FlexibleTestingModel.TestPolicy() { + @Override + public boolean shouldTest(EpisimPerson person, int day, DayOfWeek dow, LocalDate date, + TestingConfigGroup test, VaccinationConfigGroup vac) { + + if (date.isBefore(unresDate)) { + + boolean testAllPersons = test.getTestAllPersonsAfter() != null && date.isAfter(test.getTestAllPersonsAfter()); + return testAllPersons || !vac.hasGreenPass(person, day, date); + } + + // after restrictions everybody is tested according to the rates + return true; + } + }); + + } + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + + +// System.out.print("immunityGiver"); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// if (immunityFrom == VirusStrain.OMICRON_BA1) { +// System.out.print( "," + "BA.1"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { +// System.out.print( "," + "BA.2"); +// } else { +// System.out.print( "," + immunityFrom); +// } +// } +// +// +// for (ImmunityEvent immunityGiver : VaccinationType.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// for (ImmunityEvent immunityGiver : VirusStrain.values()) { +// System.out.print("\n" + immunityGiver); +// for (VirusStrain immunityFrom : VirusStrain.values()) { +// System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); +// } +// } +// +// System.out.println(); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) + .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0){ //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2); + + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + +// virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * params.deltaTheta); + + //BA5 + double ba5Inf = 1.0; + double oHos = virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getFactorSeriouslySick(); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA2).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(oHos); + } + +// STRAIN_B + if (!params.StrainB.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(oHos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(oHos); + } + + // remove age-based susceptibility of strains starting with DELTA + + String ageSusc = "false"; + if (!Boolean.parseBoolean(ageSusc)) { + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : List.of(VirusStrain.DELTA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A)) { + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } + } + + // increase infectivity of alpha + virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).getInfectiousness() * 1.4); + + double deltaTheta = 0.9; + virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * deltaTheta); + double ba1Inf = 1.9; // 2.0,2.1,2.2 + double ba2Inf = 1.7; + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA1).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA2).setInfectiousness(virusStrainConfigGroup.getOrAddParams(VirusStrain.DELTA).getInfectiousness() * ba1Inf * ba2Inf); + + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + Map infPerDayAlpha = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.ALPHA, new TreeMap<>())); + + + // reconfig disease import of alpha + LocalDate startDateAlpha = LocalDate.parse("2021-01-15"); + + for (int i = 0; i < 7; i++) { + infPerDayAlpha.put(startDateAlpha.plusDays(i), 4); + } + + + infPerDayAlpha.put(startDateAlpha.plusDays(7), 1); + + episimConfig.setInfections_pers_per_day(VirusStrain.ALPHA, infPerDayAlpha); + + + configureFutureDiseaseImport(params, episimConfig); + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + //school + String schoolUpdate = "yes"; + if(schoolUpdate.equals("yes")) { + // school closed completely until 21.2.2022 + builder.restrict(LocalDate.parse("2021-01-11"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2021-02-21"), 0.5, "educ_primary"); + builder.restrict(LocalDate.parse("2021-03-15"), 0.5, "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + } else if (schoolUpdate.equals("no")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + String schoolTest = "later"; + if (schoolTest.equals("later")) { + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); +// TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); +// Map> testingRateForActivitiesPCR = pcrTest.getTestingRateForActivities(); + + + for (LocalDate date = LocalDate.parse("2021-03-19"); date.isBefore(LocalDate.parse("2021-04-25")); date = date.plusDays(1)) { + + testingRateForActivitiesRapid.get("educ_kiga").put(date, 0.); + testingRateForActivitiesRapid.get("educ_primary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_secondary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_tertiary").put(date, 0.); + testingRateForActivitiesRapid.get("educ_other").put(date, 0.); + + } + + testingRateForActivitiesRapid.get("educ_kiga").put(LocalDate.parse("2021-09-20"), 0.); + testingRateForActivitiesRapid.get("educ_primary").put(LocalDate.parse("2021-09-20"), 0.); + +// testingRateForActivitiesPCR.get("educ_primary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_secondary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_tertiary").put(LocalDate.parse("2021-05-10"), 0.4); + testingRateForActivitiesRapid.get("educ_other").put(LocalDate.parse("2021-05-10"), 0.4); + + } else if (schoolTest.equals("base")) { + + }else { + throw new RuntimeException("param value doesn't exist"); + } + + + // masks + //pt: masks + String maskType = "45to45"; + if (maskType.equals("45to45")) { + for (LocalDate date = LocalDate.parse("2020-04-21"); date.isBefore(LocalDate.parse("2021-05-01")); date = date.plusDays(1)) { + builder.restrict(date, Restriction.ofMask(Map.of(FaceMask.CLOTH, 0.45, FaceMask.SURGICAL, 0.45)), "pt", "errands", "shop_daily", "shop_other"); + + } + } else if (maskType.equals("base")) { + + } else { + throw new RuntimeException("param value doesn't exist"); + } + + // ----------------------------------------- + + // new restrictions from IfSG + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + // testing rates + + double gpTestRate = 0.; + + TestingConfigGroup testingConfigGroup = ConfigUtils.addOrGetModule(config, TestingConfigGroup.class); + TestingConfigGroup.TestingParams pcrTest = testingConfigGroup.getOrAddParams(TestType.PCR); + Map> testingRateForActivitiesPcr = pcrTest.getTestingRateForActivities(); + Map> testingRateForActivitiesPcrVac = pcrTest.getTestingRateForActivitiesVaccinated(); + + TestingConfigGroup.TestingParams rapidTest = testingConfigGroup.getOrAddParams(TestType.RAPID_TEST); + Map> testingRateForActivitiesRapid = rapidTest.getTestingRateForActivities(); + Map> testingRateForActivitiesRapidVac = rapidTest.getTestingRateForActivitiesVaccinated(); + + + // school + { + //pcr tests for younger kids + testingRateForActivitiesPcr.get("educ_kiga").put(restrictionDate, 0.4); + testingRateForActivitiesPcr.get("educ_primary").put(restrictionDate, 0.4); + testingRateForActivitiesPcrVac.get("educ_kiga").put(restrictionDate, gpTestRate); + testingRateForActivitiesPcrVac.get("educ_primary").put(restrictionDate, gpTestRate); + + //add rapid tests for older kids + testingRateForActivitiesRapid.get("educ_secondary").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_tertiary").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_higher").put(restrictionDate, 0.6); + testingRateForActivitiesRapid.get("educ_other").put(restrictionDate, 0.6); + testingRateForActivitiesRapidVac.get("educ_secondary").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_tertiary").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_higher").put(restrictionDate, gpTestRate); + testingRateForActivitiesRapidVac.get("educ_other").put(restrictionDate, gpTestRate); + } + + // work + { + testingRateForActivitiesRapid.get("work").put(restrictionDate, 0.6); + testingRateForActivitiesRapidVac.get("work").put(restrictionDate, gpTestRate); + } + + // leisure: + { +// testingRateForActivitiesRapid.get("leisPrivate").put(restrictionDate, 0.0); // was 0.1 +// testingRateForActivitiesRapidVac.get("leisPrivate").put(restrictionDate, gpTestRate); + + testingRateForActivitiesRapid.get("leisPublic").put(restrictionDate, 0.9); + testingRateForActivitiesRapidVac.get("leisPublic").put(restrictionDate, gpTestRate); + } + + //WORK + double homeOfficeFactor = 0.5; + switch (params.work) { + case "none": + break; + case "homeOff": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "test": + // handled in getBindings + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.9)), "work", "business"); + break; + case "all": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //LEISURE + switch (params.leis) { + case "none": + break; + case "test": + // handled in getBindings + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); + case "all": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // shop, errands + switch (params.errands) { + case "none": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //SCHOOL + if (params.edu.equals("maskVentTest")) { + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofCiCorrection(0.5), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.45, + FaceMask.SURGICAL, 0.45)), + "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse(params.resDate), Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.90)), + "educ_higher"); + + } else if (params.edu.equals("none")) { + + } else { + throw new RuntimeException("invalid parameter"); + } + + + // pt + switch (params.pt) { + case "none": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + + // LEISURE SPLIT +// Double leisureFactor = 0.0; +// if (params.leisSplit.equals("private") || params.leisSplit.equals("both")) { +// builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPrivate"); +// } +// +// if (params.leisSplit.equals("public")|| params.leisSplit.equals("both")) { +// builder.applyToRf(LocalDate.of(2020,3,1).plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * leisureFactor, "leisPublic"); +// +// } + + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + // vaccination + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); + vaccinationConfig.setTimePeriodIgA(730.); + + + //modify contact intensity + double workCi = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); + + + double leisureCi = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("leisPublic").setContactIntensity(episimConfig.getOrAddContainerParams("leisPublic").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("leisPrivate").setContactIntensity(episimConfig.getOrAddContainerParams("leisPrivate").getContactIntensity() * leisureCi); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); + + + double schoolCi = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + + // add initial impulses for strains + //BA.1 +// LocalDate ba1Date = LocalDate.parse(params.ba1Date); +// for (int i = 0; i < 7; i++) { +// infPerDayBa1.put(ba1Date.plusDays(i), 4); +// } +// infPerDayBa1.put(ba1Date.plusDays(7), 1); + + + //BA.2 + LocalDate ba2Date = LocalDate.parse("2021-12-18"); + for (int i = 0; i < 7; i++) { + infPerDayBa2.put(ba2Date.plusDays(i), 4); + } + infPerDayBa2.put(ba2Date.plusDays(7), 1); + + //BA.5 + LocalDate ba5Date = LocalDate.parse("2022-04-10"); + for (int i = 0; i < 7; i++) { + infPerDayBa5.put(ba5Date.plusDays(i), 4); + } + infPerDayBa5.put(ba5Date.plusDays(7), 1); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB + if (!params.StrainB.equals("off")) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + + + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + if (!params.StrainB.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + @StringParameter({"6.0"}) + public String StrainA; + + @StringParameter({"off"}) + public String StrainB; + + @StringParameter({"2022-12-01"}) + public String resDate; + + // @StringParameter({"false", "true"}) +// public String igA; + // vaccination campaign + @StringParameter({"ba5Update", "mRNA", "off"}) + public String vacType; + + + //measures in the work context: + // homeOff = 50% home office = work Rf cut in half + // + @StringParameter({"none", "homeOff", "test", "mask", "all"}) + public String work; + + @StringParameter({"none", "mask", "test", "all"}) + public String leis; + + // mask restrictions for "shop_daily", "shop_other", "errands" + @StringParameter({"none", "mask"}) + public String errands; + + @StringParameter({"none", "maskVentTest"}) + public String edu; + + @StringParameter({"mask"}) + public String pt; + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF20220805_leisSplit.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(30), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + From 40e1f7ad01b7a1664ee6b41d2b3ce6464949a68c Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 16:40:35 +0200 Subject: [PATCH 065/128] some more cleanup --- .../batch/CologneVaryHhSusceptibility.java | 16 --- .../modules/SnzCologneProductionScenario.java | 117 ++++++++++++------ 2 files changed, 76 insertions(+), 57 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 33ed39cd4..08fa5f99b 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -404,22 +404,6 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); } - // remove age-based susceptibility of strains starting with DELTA TODO: how to integrate into the prod scenario? - - String ageSusc = "false"; - if (!Boolean.parseBoolean(ageSusc)) { - TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( - 19, 1d, - 20, 1d - )); - - for (VirusStrain strain : List.of(VirusStrain.DELTA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A)) { - virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); - } - } - - - //--------------------------------------- // I M P O R T //--------------------------------------- diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index fb0a2d73f..2ca6715e7 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -273,7 +273,6 @@ protected void configure() { @Singleton public Config config() { - LocalDate restrictionDate = LocalDate.parse("2022-03-01"); double cologneFactor = 0.5; // Cologne model has about half as many agents as Berlin model, -> 2_352_480 if (this.sample != 25 && this.sample != 100) @@ -289,6 +288,8 @@ public Config config() { config.plans().setInputFile(inputForSample("cologne_snz_entirePopulation_emptyPlans_withDistricts_%dpt_split.xml.gz", sample)); + config.controler().setOutputDirectory("output-snzWeekScenario-" + sample + "%"); + //episim config EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); @@ -316,10 +317,12 @@ public Config config() { //progression model //episimConfig.setProgressionConfig(AbstractSnzScenario2020.baseProgressionConfig(Transition.config()).build()); - episimConfig.setProgressionConfig(SnzProductionScenario.progressionConfig(Transition.config()).build());// TODO: why does this immediately override? + episimConfig.setProgressionConfig(SnzProductionScenario.progressionConfig(Transition.config()).build()); - //DISEASE IMPORT + //--------------------------------------- + // I M P O R T + //--------------------------------------- episimConfig.setInitialInfections(Integer.MAX_VALUE); if (this.diseaseImport != DiseaseImport.no) { @@ -328,7 +331,10 @@ public Config config() { } - //CONTACT INTENSITY + //---------------------------------------------------------------------------- + // C O N T A C T I N T E N S I T Y / S E A S O N A L I T Y + //---------------------------------------------------------------------------- + SnzProductionScenario.configureContactIntensities(episimConfig); //work double workCi = 0.75; @@ -374,7 +380,10 @@ public Config config() { episimConfig.getOrAddContainerParams("home").setSeasonality(0.5); episimConfig.getOrAddContainerParams("quarantine_home").setSeasonality(0.5); - //restrictions and masks + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20220723.csv")); @@ -504,34 +513,23 @@ public Config config() { "pt"); - //tracing - if (this.tracing == Tracing.yes) { - - SnzProductionScenario.configureTracing(config, cologneFactor); - - } - - Map inputDays = new HashMap<>(); inputDays.put(LocalDate.parse("2021-11-01"), DayOfWeek.SUNDAY); episimConfig.setInputDays(inputDays); - //outdoorFractions - if (this.weatherModel != WeatherModel.no) { - - double outdoorAlpha = 0.8; - SnzProductionScenario.configureWeather(episimConfig, weatherModel, - SnzCologneProductionScenario.INPUT.resolve("cologneWeather.csv").toFile(), - SnzCologneProductionScenario.INPUT.resolve("weatherDataAvgCologne2000-2020.csv").toFile(), outdoorAlpha - ); + if (carnivalModel.equals(CarnivalModel.yes)) { + // Friday 25.2 to Monday 28.2 (Rosenmontag) + builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); + builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays + builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival + builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure","leisPublic","leisPrivate"); + builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure","leisPublic","leisPrivate"); - } else { - episimConfig.setLeisureOutdoorFraction(Map.of( - LocalDate.of(2020, 1, 1), 0.) - ); + inputDays.put(LocalDate.parse("2022-02-28"), DayOfWeek.SUNDAY); // set monday to be a sunday } + //leisure & work factor if (this.restrictions != Restrictions.no) { @@ -567,7 +565,9 @@ public Config config() { } - + //--------------------------------------- + // V A C C I N A T I O N S + //--------------------------------------- if (this.vaccinations.equals(Vaccinations.yes)) { VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); @@ -607,26 +607,33 @@ public Config config() { } - if (carnivalModel.equals(CarnivalModel.yes)) { - // Friday 25.2 to Monday 28.2 (Rosenmontag) - builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); - builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays - builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival + builder.setHospitalScale(this.scale); - builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure","leisPublic","leisPrivate"); - builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure","leisPublic","leisPrivate"); + episimConfig.setPolicy(builder.build()); - inputDays.put(LocalDate.parse("2022-02-28"), DayOfWeek.SUNDAY); // set monday to be a sunday - } + //--------------------------------------- + // S T R A I N S + //--------------------------------------- - builder.setHospitalScale(this.scale); + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + + // remove age-differentiation in susceptibility for all strains expect WILD & ALPHA + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : VirusStrain.values()) { + if (strain.equals(VirusStrain.SARS_CoV_2) || strain.equals(VirusStrain.ALPHA)) { + continue; + } + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } - episimConfig.setPolicy(builder.build()); - //configure strains //alpha double aInf = 1.9 * 1.4; - VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(aInf); virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setFactorSeriouslySick(0.5); virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setFactorSeriouslySickVaccinated(0.5); @@ -881,7 +888,18 @@ public Config config() { LocalDate.of(1970, 1, 1), 0, testingStartDate, Integer.MAX_VALUE)); - //tracing + + //--------------------------------------- + // T R A C I N G + //--------------------------------------- + + + if (this.tracing == Tracing.yes) { + + SnzProductionScenario.configureTracing(config, cologneFactor); + + } + TracingConfigGroup tracingConfig = ConfigUtils.addOrGetModule(config, TracingConfigGroup.class); boolean qv = false; // if (params.qV.equals("yes")) { @@ -910,7 +928,24 @@ public Config config() { // restrictionDate, qs )); - config.controler().setOutputDirectory("output-snzWeekScenario-" + sample + "%"); + //--------------------------------------- + // W E A T H E R + //--------------------------------------- + if (this.weatherModel != WeatherModel.no) { + + double outdoorAlpha = 0.8; + SnzProductionScenario.configureWeather(episimConfig, weatherModel, + SnzCologneProductionScenario.INPUT.resolve("cologneWeather.csv").toFile(), + SnzCologneProductionScenario.INPUT.resolve("weatherDataAvgCologne2000-2020.csv").toFile(), outdoorAlpha + ); + + + } else { + episimConfig.setLeisureOutdoorFraction(Map.of( + LocalDate.of(2020, 1, 1), 0.) + ); + } + return config; } From 047059f41c030b11e2b059e3e55cc3c6f888d5a5 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 16:51:24 +0200 Subject: [PATCH 066/128] created new batch for october 2022 bmbf report --- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../matsim/run/batch/CologneBMBF202210XX.java | 595 ++++++++++++++++++ .../batch/CologneVaryHhSusceptibility.java | 7 +- 3 files changed, 600 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 66b48dc94..4c19cb003 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneVaryHhSusceptibility") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneVaryHhSusceptibility$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java new file mode 100644 index 000000000..03569c054 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -0,0 +1,595 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.DataUtils; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF202210XX implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 2.9; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + LocalDate start = null; + VaccinationType vaccinationType = VaccinationType.mRNA; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + String vacCamp = "off"; + + if (params != null) { +// mutEscBa5 = params.ba5Esc; + + if (!params.vacType.equals("off")) { + vacCamp = "age"; + vaccinationType = VaccinationType.valueOf(params.vacType); + } + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } + + start = LocalDate.parse(params.resDate); + + + + if (vacCamp.equals("age")) { + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + } + else if (vacCamp.equals("eu")) { + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + } + else if (vacCamp.equals("off")) { + + } else { + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } +// + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + +// double pHousehold = 1.0; + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(0.35, 0.01) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0 && params.importSummer2022.equals("on")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + + //snapshot +// episimConfig.setSnapshotInterval(766); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-07/" + params.seed + "-766-2022-03-31.zip"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); + } + +// STRAIN_B + if (!params.StrainB.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); + } + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + configureFutureDiseaseImport(params, episimConfig); + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + // Ci Correction after summer vacation 2022 (more air flow?) + builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), params.eduRfVacation, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + + // modify seasonality + episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB + if (!params.StrainB.equals("off")) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + + + if (params.importSummer2022.equals("on")) { + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + } else if (params.importSummer2022.equals("off")) { + } else { + throw new RuntimeException(); + } + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + if (!params.StrainB.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + @StringParameter({"on", "off"}) + public String importSummer2022; + + @Parameter({0.5, 0.75, 1.0}) + public double eduSeasonality; + + // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow + @Parameter({0.25, 0.5, 0.75}) + public double ciCorr; + + //how much "school" activity takes places during vacation summmer 2022 + @Parameter({0.2, 0.4, 0.6, 0.8, 1.0}) + public double eduRfVacation; + + + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"3.0"}) + public String StrainA; + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"off"}) + public String StrainB; + + @StringParameter({"2022-11-15","2022-12-01","2022-12-15"}) + public String resDate; + + + // vaccination campaign +// @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) + @StringParameter({"off"}) + public String vacType; + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF202210XX.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java index 08fa5f99b..8a5dc83bb 100644 --- a/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java +++ b/src/main/java/org/matsim/run/batch/CologneVaryHhSusceptibility.java @@ -559,18 +559,17 @@ public static final class Params { // @StringParameter({"off", "3.0", "6.0"}) - @StringParameter({"off"}) + @StringParameter({"3.0"}) public String StrainA; // @StringParameter({"off", "3.0", "6.0"}) @StringParameter({"off"}) public String StrainB; - @StringParameter({"2022-12-01"}) + @StringParameter({"2022-11-15","2022-12-01","2022-12-15"}) public String resDate; -// @StringParameter({"false", "true"}) -// public String igA; + // vaccination campaign // @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) @StringParameter({"off"}) From 5ece00f98096151ed58d6b3617a65344bf21c660 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 7 Oct 2022 17:59:26 +0200 Subject: [PATCH 067/128] added Restrictions for new BMBF report run jakob/2022-10-07/3-measures --- .../matsim/run/batch/CologneBMBF202210XX.java | 115 +++++++++++++++++- 1 file changed, 109 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index 03569c054..4cb9aa58e 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -417,6 +417,83 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + //work + double homeOfficeFactor = 0.5; + switch (params.work) { + case "base": + break; + case "half": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure public + switch (params.leisPublic) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); + case "zero": + builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); + break; + case "half": + builder.restrict(restrictionDate, 0.76 * 0.5, "leisPublic"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPublic"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure private + switch (params.leisPrivate) { + case "base": + break; + case "half": + builder.restrict(restrictionDate, 0.76 * 0.5, "leisPrivate"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // shop, errands + switch (params.errands) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //school + switch (params.edu) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other"); + break; + case "half": + builder.restrict(restrictionDate, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + // Ci Correction after summer vacation 2022 (more air flow?) builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); @@ -543,18 +620,45 @@ public static final class Params { @GenerateSeeds(5) public long seed; - @StringParameter({"on", "off"}) + + // NEW RESTRICTIONS + @StringParameter({"2022-11-15","2022-12-01","2022-12-15"}) + public String resDate; + + //measures in the work context: + // homeOff = 50% home office = work Rf cut in half + // + @StringParameter({"base", "half", "mask"}) + public String work; + + // leisure Public + @StringParameter({"base", "mask", "zero", "half"}) + public String leisPublic; + + // leisure Private + @StringParameter({"base", "half"}) + public String leisPrivate; + + // mask restrictions for "shop_daily", "shop_other", "errands" + @StringParameter({"base", "mask"}) + public String errands; + + //edu + @StringParameter({"none", "mask", "half"}) + public String edu; + + @StringParameter({"off"}) public String importSummer2022; - @Parameter({0.5, 0.75, 1.0}) + @Parameter({0.5}) public double eduSeasonality; // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow - @Parameter({0.25, 0.5, 0.75}) + @Parameter({0.75}) public double ciCorr; //how much "school" activity takes places during vacation summmer 2022 - @Parameter({0.2, 0.4, 0.6, 0.8, 1.0}) + @Parameter({ 0.8}) public double eduRfVacation; @@ -567,8 +671,7 @@ public static final class Params { @StringParameter({"off"}) public String StrainB; - @StringParameter({"2022-11-15","2022-12-01","2022-12-15"}) - public String resDate; + // vaccination campaign From 461e7481482b705e16359b87a8f257d7a548efb9 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Mon, 10 Oct 2022 00:04:16 +0200 Subject: [PATCH 068/128] misc, reorganisation --- .../analysis/HospitalNumbersFromEvents.java | 14 +- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../matsim/run/batch/CologneBMBF202210XX.java | 2 +- .../batch/CologneBMBF202210XX_SNAPSHOT.java | 696 ++++++++++++++++++ .../modules/SnzCologneProductionScenario.java | 98 +-- 5 files changed, 755 insertions(+), 59 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 558ee1409..9edb232b1 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -262,13 +262,13 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t List handlers = List.of( new Handler("Omicron", population, holderOmicron, 0.0), - new Handler("Delta", population, holderDelta, 0.0), - new Handler("Omicron-Paxlovid-0.25", population, holderOmicron, 0.25), - new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), - new Handler("Omicron-Paxlovid-0.50", population, holderOmicron, 0.5), - new Handler("Delta-Paxlovid-0.50", population, holderDelta, 0.5), - new Handler("Omicron-Paxlovid-0.75", population, holderOmicron, 0.75), - new Handler("Delta-Paxlovid-0.75", population, holderDelta, 0.75) + new Handler("Delta", population, holderDelta, 0.0) +// new Handler("Omicron-Paxlovid-0.25", population, holderOmicron, 0.25), +// new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), +// new Handler("Omicron-Paxlovid-0.50", population, holderOmicron, 0.5), +// new Handler("Delta-Paxlovid-0.50", population, holderDelta, 0.5), +// new Handler("Omicron-Paxlovid-0.75", population, holderOmicron, 0.75), +// new Handler("Delta-Paxlovid-0.75", population, holderDelta, 0.75) ); // feed the output events file to the handler, so that the hospitalizations may be calculated diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 4c19cb003..1558adfc1 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_SNAPSHOT") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_SNAPSHOT$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index 4cb9aa58e..007192bb9 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -644,7 +644,7 @@ public static final class Params { public String errands; //edu - @StringParameter({"none", "mask", "half"}) + @StringParameter({"base", "mask", "half"}) public String edu; @StringParameter({"off"}) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java new file mode 100644 index 000000000..ebca76b5b --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -0,0 +1,696 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.DataUtils; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF202210XX_SNAPSHOT implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 2.9; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + LocalDate start = null; + VaccinationType vaccinationType = VaccinationType.mRNA; + + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.0); + compliance.put(18, 0.0); + compliance.put(12, 0.0); + compliance.put(0, 0.0); + + String vacCamp = "off"; + + if (params != null) { +// mutEscBa5 = params.ba5Esc; + + if (!params.vacType.equals("off")) { + vacCamp = "age"; + vaccinationType = VaccinationType.valueOf(params.vacType); + } + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } + + start = LocalDate.parse(params.resDate); + + + + if (vacCamp.equals("age")) { + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + } + else if (vacCamp.equals("eu")) { + compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) + compliance.put(18, 0.); + compliance.put(12, 0.); + compliance.put(0, 0.); + } + else if (vacCamp.equals("off")) { + + } else { + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } +// + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + +// double pHousehold = 1.0; + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(0.35, 0.01) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0 && params.importSummer2022.equals("on")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + + //snapshot + episimConfig.setSnapshotInterval(766); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-07/" + params.seed + "-766-2022-03-31.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); + } + +// STRAIN_B + if (!params.StrainB.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); + } + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + configureFutureDiseaseImport(params, episimConfig); + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + //work + double homeOfficeFactor = 0.5; + switch (params.work) { + case "base": + break; + case "half": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure public + switch (params.leisPublic) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); + case "zero": + builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); + break; + case "half": + builder.restrict(restrictionDate, 0.76 * 0.5, "leisPublic"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPublic"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure private + switch (params.leisPrivate) { + case "base": + break; + case "half": + builder.restrict(restrictionDate, 0.76 * 0.5, "leisPrivate"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // shop, errands + switch (params.errands) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //school + switch (params.edu) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other"); + break; + case "half": + builder.restrict(restrictionDate, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // Ci Correction after summer vacation 2022 (more air flow?) + builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), params.eduRfVacation, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + + // modify seasonality + episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); + episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB + if (!params.StrainB.equals("off")) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + + + if (params.importSummer2022.equals("on")) { + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + } else if (params.importSummer2022.equals("off")) { + } else { + throw new RuntimeException(); + } + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + if (!params.StrainB.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + + // NEW RESTRICTIONS + @StringParameter({"2022-11-15"}) + public String resDate; + + //measures in the work context: + // homeOff = 50% home office = work Rf cut in half + // + @StringParameter({"base"}) + public String work; + + // leisure Public + @StringParameter({"base"}) + public String leisPublic; + + // leisure Private + @StringParameter({"base"}) + public String leisPrivate; + + // mask restrictions for "shop_daily", "shop_other", "errands" + @StringParameter({"base"}) + public String errands; + + //edu + @StringParameter({"base"}) + public String edu; + + @StringParameter({"off"}) + public String importSummer2022; + + @Parameter({0.5}) + public double eduSeasonality; + + // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow + @Parameter({0.75}) + public double ciCorr; + + //how much "school" activity takes places during vacation summmer 2022 + @Parameter({ 0.8}) + public double eduRfVacation; + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"3.0"}) + public String StrainA; + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"off"}) + public String StrainB; + + + + + // vaccination campaign +// @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) + @StringParameter({"off"}) + public String vacType; + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF202210XX_SNAPSHOT.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 2ca6715e7..c25baa5a8 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -384,6 +384,9 @@ public Config config() { // R E S T R I C T I O N S //--------------------------------------- + Map inputDays = new HashMap<>(); + inputDays.put(LocalDate.parse("2021-11-01"), DayOfWeek.SUNDAY); + CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20220723.csv")); @@ -449,7 +452,53 @@ public Config config() { builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); + if (carnivalModel.equals(CarnivalModel.yes)) { + // Friday 25.2 to Monday 28.2 (Rosenmontag) + builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); + builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays + builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival + builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure","leisPublic","leisPrivate"); + builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure","leisPublic","leisPrivate"); + inputDays.put(LocalDate.parse("2022-02-28"), DayOfWeek.SUNDAY); // set monday to be a sunday + } + episimConfig.setInputDays(inputDays); + + + //leisure & work factor + if (this.restrictions != Restrictions.no) { + + if (leisureCorrection == 0.) { // assume old factor of 1.9, only applied to leisure TODO: get rid of this artifact + builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - 1.9 * (1 - (double) e.get("fraction"))), "leisure","leisPublic","leisPrivate"); + } else if (leisureCorrection != 1) { + builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "business", "errands", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "work"); + } + + // builder.applyToRf("2020-10-15", "2020-12-14", (d, rf) -> rf - leisureOffset, "leisure"); + BiFunction workVacFactor = (d, rf) -> rf * 0.92; + + builder.applyToRf("2020-04-03", "2020-04-17", workVacFactor, "work", "business"); + builder.applyToRf("2020-06-26", "2020-08-07", workVacFactor, "work", "business"); + builder.applyToRf("2020-10-09", "2020-10-23", workVacFactor, "work", "business"); + builder.applyToRf("2020-12-18", "2021-01-01", workVacFactor, "work", "business"); + builder.applyToRf("2021-01-29", "2021-02-05", workVacFactor, "work", "business"); + builder.applyToRf("2021-03-26", "2021-04-09", workVacFactor, "work", "business"); + builder.applyToRf("2021-07-01", "2021-08-13", workVacFactor, "work", "business"); + builder.applyToRf("2021-10-08", "2021-10-22", workVacFactor, "work", "business"); + builder.applyToRf("2021-12-22", "2022-01-05", workVacFactor, "work", "business"); + + + builder.restrict(LocalDate.parse("2022-04-11"), 0.78 * 0.92, "work", "business"); + builder.restrict(LocalDate.parse("2022-04-23"), 0.78, "work", "business"); + builder.restrict(LocalDate.parse("2022-06-27"), 0.78 * 0.92, "work", "business"); + builder.restrict(LocalDate.parse("2022-08-09"), 0.78, "work", "business"); + builder.restrict(LocalDate.parse("2022-10-04"), 0.78 * 0.92, "work", "business"); + builder.restrict(LocalDate.parse("2022-10-15"), 0.78, "work", "business"); + builder.restrict(LocalDate.parse("2022-12-23"), 0.78 * 0.92, "work", "business"); + builder.restrict(LocalDate.parse("2023-01-06"), 0.78, "work", "business"); + } + + //MASKS { LocalDate masksCenterDate = LocalDate.of(2020, 4, 27); for (int ii = 0; ii <= 14; ii++) { @@ -513,58 +562,9 @@ public Config config() { "pt"); - Map inputDays = new HashMap<>(); - inputDays.put(LocalDate.parse("2021-11-01"), DayOfWeek.SUNDAY); - episimConfig.setInputDays(inputDays); - - if (carnivalModel.equals(CarnivalModel.yes)) { - // Friday 25.2 to Monday 28.2 (Rosenmontag) - builder.restrict(LocalDate.parse("2022-02-25"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); - builder.restrict(LocalDate.parse("2022-02-27"), 1., "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // sunday, to overwrite the setting on sundays - builder.restrict(LocalDate.parse("2022-03-01"), 0.7, "work", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "errands", "business"); // tuesday, back to normal after carnival - - builder.restrict(LocalDate.parse("2022-02-25"), Restriction.ofCiCorrection(2.0), "leisure","leisPublic","leisPrivate"); - builder.restrict(LocalDate.parse("2022-03-01"), Restriction.ofCiCorrection(1.0), "leisure","leisPublic","leisPrivate"); - - inputDays.put(LocalDate.parse("2022-02-28"), DayOfWeek.SUNDAY); // set monday to be a sunday - } - - - //leisure & work factor - if (this.restrictions != Restrictions.no) { - - if (leisureCorrection == 0.) { // assume old factor of 1.9, only applied to leisure TODO: get rid of this artifact - builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - 1.9 * (1 - (double) e.get("fraction"))), "leisure","leisPublic","leisPrivate"); - } else if (leisureCorrection != 1) { - builder.apply("2020-10-15", "2020-12-14", (d, e) -> e.put("fraction", 1 - leisureCorrection * (1 - (double) e.get("fraction"))), "business", "errands", "leisure","leisPublic","leisPrivate", "shop_daily", "shop_other", "visit", "work"); - } - // builder.applyToRf("2020-10-15", "2020-12-14", (d, rf) -> rf - leisureOffset, "leisure"); - - BiFunction workVacFactor = (d, rf) -> rf * 0.92; - - builder.applyToRf("2020-04-03", "2020-04-17", workVacFactor, "work", "business"); - builder.applyToRf("2020-06-26", "2020-08-07", workVacFactor, "work", "business"); - builder.applyToRf("2020-10-09", "2020-10-23", workVacFactor, "work", "business"); - builder.applyToRf("2020-12-18", "2021-01-01", workVacFactor, "work", "business"); - builder.applyToRf("2021-01-29", "2021-02-05", workVacFactor, "work", "business"); - builder.applyToRf("2021-03-26", "2021-04-09", workVacFactor, "work", "business"); - builder.applyToRf("2021-07-01", "2021-08-13", workVacFactor, "work", "business"); - builder.applyToRf("2021-10-08", "2021-10-22", workVacFactor, "work", "business"); - builder.applyToRf("2021-12-22", "2022-01-05", workVacFactor, "work", "business"); - - - builder.restrict(LocalDate.parse("2022-04-11"), 0.78 * 0.92, "work", "business"); - builder.restrict(LocalDate.parse("2022-04-23"), 0.78, "work", "business"); - builder.restrict(LocalDate.parse("2022-06-27"), 0.78 * 0.92, "work", "business"); - builder.restrict(LocalDate.parse("2022-08-09"), 0.78, "work", "business"); - builder.restrict(LocalDate.parse("2022-10-04"), 0.78 * 0.92, "work", "business"); - builder.restrict(LocalDate.parse("2022-10-15"), 0.78, "work", "business"); - builder.restrict(LocalDate.parse("2022-12-23"), 0.78 * 0.92, "work", "business"); - builder.restrict(LocalDate.parse("2023-01-06"), 0.78, "work", "business"); - } //--------------------------------------- // V A C C I N A T I O N S //--------------------------------------- From 74638350e9b464ad9652ff364c4bb6917d63f094 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Mon, 10 Oct 2022 12:13:26 +0200 Subject: [PATCH 069/128] several bug fixes involving infectivity of BA5 & StrainA, and with leisure Contact intensity --- .../matsim/run/batch/CologneBMBF202210XX.java | 7 ++- ... => CologneBMBF202210XX_SNAPSHOT_old.java} | 4 +- .../modules/SnzCologneProductionScenario.java | 63 ++++++++----------- 3 files changed, 33 insertions(+), 41 deletions(-) rename src/main/java/org/matsim/run/batch/{CologneBMBF202210XX_SNAPSHOT.java => CologneBMBF202210XX_SNAPSHOT_old.java} (99%) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index 007192bb9..29177996f 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -49,7 +49,7 @@ protected void configure() { double mutEscDelta = 29.2 / 10.9; double mutEscBa1 = 10.9 / 1.9; - double mutEscBa5 = 2.9; + double mutEscBa5 = 2.9; // 0.1 -> 3.8 double mutEscStrainA = 0.; double mutEscStrainB = 0.; @@ -374,7 +374,8 @@ public Config prepareConfig(int id, Params params) { //snapshot // episimConfig.setSnapshotInterval(766); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-07/" + params.seed + "-766-2022-03-31.zip"); +// episimConfig.setSnapshotPrefix(params.seed +"-"); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-09/" + params.seed + "--766-2022-03-31.zip"); episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); @@ -390,7 +391,7 @@ public Config prepareConfig(int id, Params params) { // STRAIN_A if (!params.StrainA.equals("off")) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT_old.java similarity index 99% rename from src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java rename to src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT_old.java index ebca76b5b..9cd61a58c 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT_old.java @@ -31,7 +31,7 @@ /** * Batch for Bmbf runs */ -public class CologneBMBF202210XX_SNAPSHOT implements BatchRun { +public class CologneBMBF202210XX_SNAPSHOT_old implements BatchRun { boolean DEBUG_MODE = false; int runCount = 0; @@ -681,7 +681,7 @@ public static final class Params { public static void main(String[] args) { String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202210XX_SNAPSHOT.class.getName(), + RunParallel.OPTION_SETUP, CologneBMBF202210XX_SNAPSHOT_old.class.getName(), RunParallel.OPTION_PARAMS, Params.class.getName(), RunParallel.OPTION_TASKS, Integer.toString(1), RunParallel.OPTION_ITERATIONS, Integer.toString(1000), diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index c25baa5a8..be5f95087 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -337,37 +337,30 @@ public Config config() { SnzProductionScenario.configureContactIntensities(episimConfig); //work - double workCi = 0.75; - episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCi); - episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCi); + double workCiMod = 0.75; + episimConfig.getOrAddContainerParams("work").setContactIntensity(episimConfig.getOrAddContainerParams("work").getContactIntensity() * workCiMod); + episimConfig.getOrAddContainerParams("business").setContactIntensity(episimConfig.getOrAddContainerParams("business").getContactIntensity() * workCiMod); //leisure & visit - double leisureCi = 0.4; - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * 0.6 * leisureCi); - episimConfig.getOrAddContainerParams("leisPublic").setContactIntensity(episimConfig.getOrAddContainerParams("leisPublic").getContactIntensity() * 0.6 * leisureCi); - episimConfig.getOrAddContainerParams("leisPrivate").setContactIntensity(episimConfig.getOrAddContainerParams("leisPrivate").getContactIntensity() * 0.6 * leisureCi); - episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCi); + double leisureCiMod = 0.4; + episimConfig.getOrAddContainerParams("leisure").setContactIntensity(episimConfig.getOrAddContainerParams("leisure").getContactIntensity() * leisureCiMod); + episimConfig.getOrAddContainerParams("leisPublic").setContactIntensity(episimConfig.getOrAddContainerParams("leisPublic").getContactIntensity() * leisureCiMod); + episimConfig.getOrAddContainerParams("leisPrivate").setContactIntensity(episimConfig.getOrAddContainerParams("leisPrivate").getContactIntensity() * leisureCiMod); + episimConfig.getOrAddContainerParams("visit").setContactIntensity(episimConfig.getOrAddContainerParams("visit").getContactIntensity() * leisureCiMod); //school - double schoolCi = 0.75; - episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCi); - episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCi); + double schoolCiMod = 0.75; + episimConfig.getOrAddContainerParams("educ_kiga").setContactIntensity(episimConfig.getOrAddContainerParams("educ_kiga").getContactIntensity() * schoolCiMod); + episimConfig.getOrAddContainerParams("educ_primary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_primary").getContactIntensity() * schoolCiMod); + episimConfig.getOrAddContainerParams("educ_secondary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_secondary").getContactIntensity() * schoolCiMod); + episimConfig.getOrAddContainerParams("educ_tertiary").setContactIntensity(episimConfig.getOrAddContainerParams("educ_tertiary").getContactIntensity() * schoolCiMod); + episimConfig.getOrAddContainerParams("educ_higher").setContactIntensity(episimConfig.getOrAddContainerParams("educ_higher").getContactIntensity() * schoolCiMod); + episimConfig.getOrAddContainerParams("educ_other").setContactIntensity(episimConfig.getOrAddContainerParams("educ_other").getContactIntensity() * schoolCiMod); //SEASONALITY episimConfig.getOrAddContainerParams("work").setSeasonality(0.5); - - double leisCi = 0.6; - - episimConfig.getOrAddContainerParams("leisure").setContactIntensity(9.24 * leisCi); - episimConfig.getOrAddContainerParams("leisPrivate").setContactIntensity(9.24 * leisCi); - episimConfig.getOrAddContainerParams("leisPublic").setContactIntensity(9.24 * leisCi); - episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(0.5); episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(0.5); episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(0.5); @@ -618,20 +611,6 @@ public Config config() { VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - // remove age-differentiation in susceptibility for all strains expect WILD & ALPHA - TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( - 19, 1d, - 20, 1d - )); - - for (VirusStrain strain : VirusStrain.values()) { - if (strain.equals(VirusStrain.SARS_CoV_2) || strain.equals(VirusStrain.ALPHA)) { - continue; - } - virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); - } - - //alpha double aInf = 1.9 * 1.4; virusStrainConfigGroup.getOrAddParams(VirusStrain.ALPHA).setInfectiousness(aInf); @@ -670,6 +649,18 @@ public Config config() { virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySickVaccinated(oHos); virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(oHos); + // remove age-differentiation in susceptibility for all strains expect WILD & ALPHA + TreeMap nonSteppedAgeSusceptibility = new TreeMap<>(Map.of( + 19, 1d, + 20, 1d + )); + + for (VirusStrain strain : VirusStrain.values()) { + if (strain.equals(VirusStrain.SARS_CoV_2) || strain.equals(VirusStrain.ALPHA) || strain.equals(VirusStrain.B1351)) { + continue; + } + virusStrainConfigGroup.getOrAddParams(strain).setAgeSusceptibility(nonSteppedAgeSusceptibility); + } //--------------------------------------- // T E S T I N G From 520488175e1de4d42e1dd7ffea0354537d7f92fe Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 11 Oct 2022 10:36:17 +0200 Subject: [PATCH 070/128] cherrypick vaccination strategy from the eu scenario hub branch. --- .../org/matsim/episim/EpisimReporting.java | 16 ++ .../model/InfectionModelWithAntibodies.java | 2 +- ...ccinationStrategyReoccurringCampaigns.java | 199 ++++++++++++++++++ .../matsim/run/batch/CologneBMBF202210XX.java | 8 +- 4 files changed, 221 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java diff --git a/src/main/java/org/matsim/episim/EpisimReporting.java b/src/main/java/org/matsim/episim/EpisimReporting.java index 5c25493ed..3830f1801 100644 --- a/src/main/java/org/matsim/episim/EpisimReporting.java +++ b/src/main/java/org/matsim/episim/EpisimReporting.java @@ -67,6 +67,22 @@ */ public final class EpisimReporting implements BasicEventHandler, Closeable, Externalizable { + /** + * Age groups used for various outputs. AgeGroup -> minimum age of age group. + * Important: age groups must be in descending order + */ + public enum AgeGroup { + age_60_plus(60), + age_18_59(18), + age_12_17(12), + age_0_11(0); + + public final int lowerBoundAge; + + AgeGroup(int lowerBoundAge) { + this.lowerBoundAge = lowerBoundAge; + } + } private static final Logger log = LogManager.getLogger(EpisimReporting.class); private static final AtomicInteger specificInfectionsCnt = new AtomicInteger(300); diff --git a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java index 0ce86be8d..b59b45bb3 100644 --- a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java +++ b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java @@ -14,7 +14,7 @@ import java.util.SplittableRandom; /** - * Extension of the {@link DefaultInfectionModel}, with age, time and seasonality-dependen additions. + * Extension of the {@link DefaultInfectionModel}, with age, time and seasonality-dependent additions. */ public final class InfectionModelWithAntibodies implements InfectionModel { diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java new file mode 100644 index 000000000..eebd453ff --- /dev/null +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java @@ -0,0 +1,199 @@ +package org.matsim.episim.model.vaccination; + +import com.google.inject.Inject; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.population.Person; +import org.matsim.api.core.v01.population.Population; +import org.matsim.episim.EpisimPerson; +import org.matsim.episim.EpisimReporting; +import org.matsim.episim.EpisimUtils; +import org.matsim.episim.model.VaccinationType; + +import java.time.LocalDate; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Update vaccination campaign. + */ +public class VaccinationStrategyReoccurringCampaigns implements VaccinationModel { + + private final int dailyVaccinationsToBeDistributed; + + private final SplittableRandom rnd; + private final Config config; + + // LocalDate of beginning of vaccination campaign -> age-group -> number of vaccinations left + private final Map> vaccinationsLeftPerAgePerCampaign; + + + @Inject + public VaccinationStrategyReoccurringCampaigns(SplittableRandom rnd, Config config, Scenario scenario) { + this.rnd = rnd; + this.config = config; + + Population population = scenario.getPopulation(); + + + // number of agents in each age group + int agentCnt_0_11 = (int) population.getPersons().values().stream().filter(p -> ((int) p.getAttributes().getAttribute("microm:modeled:age") >= 0 && (int) p.getAttributes().getAttribute("microm:modeled:age") < 12)).count(); + int agentCnt_12_17 = (int) population.getPersons().values().stream().filter(p -> ((int) p.getAttributes().getAttribute("microm:modeled:age") >= 12 && (int) p.getAttributes().getAttribute("microm:modeled:age") < 18)).count(); + int agentCnt_18_59 = (int) population.getPersons().values().stream().filter(p -> ((int) p.getAttributes().getAttribute("microm:modeled:age") >= 18 && (int) p.getAttributes().getAttribute("microm:modeled:age") < 60)).count(); + int agentCnt_60_plus = (int) population.getPersons().values().stream().filter(p -> (int) p.getAttributes().getAttribute("microm:modeled:age") >= 60).count(); + + //multiply compliance by these numbers -> total number of vaccines to be applied to age group + int vaxCnt_0_11 = (int) (agentCnt_0_11 * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_0_11)); + int vaxCnt_12_17 = (int) (agentCnt_12_17 * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_12_17)); + int vaxCnt_18_59 = (int) (agentCnt_18_59 * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_18_59)); + int vaxCnt_60_plus = (int) (agentCnt_60_plus * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_60_plus)); + + // put these vaccination counts in map form + Object2IntMap vaccinationsLeftPerAge = new Object2IntOpenHashMap(Map.of( + EpisimReporting.AgeGroup.age_0_11, vaxCnt_0_11, + EpisimReporting.AgeGroup.age_12_17, vaxCnt_12_17, + EpisimReporting.AgeGroup.age_18_59, vaxCnt_18_59, + EpisimReporting.AgeGroup.age_60_plus, vaxCnt_60_plus + )); + + // create a age-group vaccinations remaining counter for each vaccination campaign (will count down to 0) + // each map is a copy of map created above + this.vaccinationsLeftPerAgePerCampaign = new HashMap<>(); + for (LocalDate startDate : config.startDateToVaccinationCampaign.keySet()) { + this.vaccinationsLeftPerAgePerCampaign.put(startDate, new HashMap<>(vaccinationsLeftPerAge)); + } + + // calculate total number of vaccinations: + int totalVaccinationsDistributedPerCampaign = vaccinationsLeftPerAge.values().intStream().sum(); + dailyVaccinationsToBeDistributed = totalVaccinationsDistributedPerCampaign / config.campaignDuration; + + } + + @Override + public void handleVaccination(Map, EpisimPerson> persons, LocalDate date, int iteration, double now) { + + + // we check that the compliance of at least one age group is greater than 0.0. If not, there will be no vaccinations anyway + if (dailyVaccinationsToBeDistributed <= 0) { + return; + } + + + // Loop through all vaccination campaigns (via the start date of said campaign) + for (LocalDate vaccinationCampaignStartDate : config.startDateToVaccinationCampaign.keySet()) { + // Check whether current date falls within vaccination campaign + if (date.isAfter(vaccinationCampaignStartDate.minusDays(1)) && date.isBefore(vaccinationCampaignStartDate.plusDays(config.campaignDuration))) { + + // vaccine type associated with campaign + VaccinationType vaccinationType = config.startDateToVaccinationCampaign.get(vaccinationCampaignStartDate); + + // define eligible candidates for booster campaigns: + // ?) if the person is vaccinable, whatever that means + // a) not infected at the moment + // b) is either already vaccinated or boostered, depending on the configuration + // c) hasn't been vaccinated in the previous 90 days + List candidates = persons.values().stream() + .filter(EpisimPerson::isVaccinable) // todo: what determines who is vaccinable? + .filter(p -> p.getDiseaseStatus() == EpisimPerson.DiseaseStatus.susceptible) + .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) // only boostered people are reboostered + .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > 90) // only people who've had their last vaccination more than 90 days ago + .collect(Collectors.toList()); + + + // create vaccinations-remaining counter for current day + int vaccinationsLeft = this.dailyVaccinationsToBeDistributed; + + // group candidates into age groups + Map> candidatesPerAgeGroup = new HashMap<>(); + for (EpisimReporting.AgeGroup ageGroup : EpisimReporting.AgeGroup.values()) { + candidatesPerAgeGroup.put(ageGroup, new ArrayList<>()); + } + for (EpisimPerson person : candidates) { + for (EpisimReporting.AgeGroup ageGroup : EpisimReporting.AgeGroup.values()) { + if (person.getAge() >= ageGroup.lowerBoundAge) { + candidatesPerAgeGroup.get(ageGroup).add(person); + break; + } + } + } + + // Apply vaccinations, oldest age-group first. Stop vaccinations for day if: + // a) no vaccines left for the day + // b) no age-group has any more candidates + // c) no age-group has any more vaccines left (for entire campaign) + + Iterator ageGroupIterator = Arrays.stream(EpisimReporting.AgeGroup.values()).iterator(); +// int ageIndex = AgeGroup.values().length - 1; + while (ageGroupIterator.hasNext() && vaccinationsLeft > 0) { + EpisimReporting.AgeGroup ageGroup = ageGroupIterator.next(); + + int vaccinationsLeftForAgeGroup = vaccinationsLeftPerAgePerCampaign.get(vaccinationCampaignStartDate).get(ageGroup); + + // list is shuffled to avoid eventual bias + List candidatesForAge = candidatesPerAgeGroup.get(ageGroup); + Collections.shuffle(candidatesForAge, new Random(EpisimUtils.getSeed(rnd))); + +// +// int vaccinesForDayAndAgeGroup = Math.min(candidatesForAge.size(), vaccinationsLeft); + Iterator candidateIterator = candidatesForAge.stream().iterator(); + EpisimPerson person; + while(candidateIterator.hasNext() && vaccinationsLeft > 0 && vaccinationsLeftForAgeGroup > 0){ + person = candidateIterator.next(); + + vaccinate(person, iteration, vaccinationType); + vaccinationsLeft--; + vaccinationsLeftForAgeGroup--; + } + vaccinationsLeftPerAgePerCampaign.get(vaccinationCampaignStartDate).put(ageGroup, vaccinationsLeftForAgeGroup); + } + + if (vaccinationsLeft > 0) { + System.out.println(vaccinationsLeft + " vaccinations were left over at end of day "); + } + } + } + } + + + public static class Config { + + /** + * Start Dates of vaccination campaigns. + */ + private final Map startDateToVaccinationCampaign; + /** + * Duration of vaccination campaign. + */ + private final int campaignDuration; + + private final Object2DoubleMap complianceByAge; + + private final VaccinationPool vaccinationPool; + + public enum VaccinationPool { + + vaccinated(1), + + boostered(2); + + private final int vaxCnt; + + VaccinationPool(int vaxCnt) { + this.vaxCnt = vaxCnt; + } + + } + + + public Config(Map startDateToVaccinationCampaign, int campaignDuration, Object2DoubleMap complianceByAge, VaccinationPool vaccinationPool) { + this.startDateToVaccinationCampaign = startDateToVaccinationCampaign; + this.campaignDuration = campaignDuration; + this.complianceByAge = complianceByAge; + this.vaccinationPool = vaccinationPool; + } + } + +} diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index 29177996f..dedacc203 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -49,7 +49,8 @@ protected void configure() { double mutEscDelta = 29.2 / 10.9; double mutEscBa1 = 10.9 / 1.9; - double mutEscBa5 = 2.9; // 0.1 -> 3.8 +// double mutEscBa5 = 2.9; // 0.1 -> 3.8 + double mutEscBa5 = 5.0; double mutEscStrainA = 0.; double mutEscStrainB = 0.; @@ -375,7 +376,7 @@ public Config prepareConfig(int id, Params params) { //snapshot // episimConfig.setSnapshotInterval(766); // episimConfig.setSnapshotPrefix(params.seed +"-"); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-09/" + params.seed + "--766-2022-03-31.zip"); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-10/" + params.seed + "--766-2022-03-31.zip"); episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); @@ -442,6 +443,7 @@ public Config prepareConfig(int id, Params params) { break; case "mask": builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); + break; case "zero": builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); @@ -665,7 +667,7 @@ public static final class Params { // @StringParameter({"off", "3.0", "6.0"}) - @StringParameter({"3.0"}) + @StringParameter({"6.0"}) public String StrainA; // @StringParameter({"off", "3.0", "6.0"}) From e2bc529f116c8dcdbd86f2882efa0e06fe160376 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 12 Oct 2022 12:13:26 +0200 Subject: [PATCH 071/128] vaccination runs --- .../analysis/HospitalNumbersFromEvents.java | 8 +- ...ccinationStrategyReoccurringCampaigns.java | 5 +- .../matsim/run/batch/CologneBMBF202210XX.java | 132 +++++++++++------- .../modules/SnzCologneProductionScenario.java | 24 ++-- 4 files changed, 104 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 9edb232b1..8b1f2735c 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,7 +60,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "../public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-08-02/3-vax/analysis/strainA") + @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/xxx/") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -162,7 +162,9 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // omicron: approx 0.3x (intrinsic) severity of delta - Comparative analysis of the risks of hospitalisation and death associated with SARS-CoV-2 omicron (B.1.1.529) and delta (B.1.617.2) variants in England: a cohort study private static final double factorOmicron = 0.3 * factorDelta; // reportedShareOmicron / reportedShareDelta +// private static final double factorOmicron = 0.6 * factorDelta; // reportedShareOmicron / reportedShareDelta +// private static final double factorBA5 = 1.0 * factorOmicron; private static final double factorBA5 = 1.5 * factorOmicron; @@ -214,8 +216,8 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java index eebd453ff..fc9056080 100644 --- a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java @@ -59,7 +59,7 @@ public VaccinationStrategyReoccurringCampaigns(SplittableRandom rnd, Config conf EpisimReporting.AgeGroup.age_60_plus, vaxCnt_60_plus )); - // create a age-group vaccinations remaining counter for each vaccination campaign (will count down to 0) + // create an age-group vaccinations remaining counter for each vaccination campaign (will count down to 0) // each map is a copy of map created above this.vaccinationsLeftPerAgePerCampaign = new HashMap<>(); for (LocalDate startDate : config.startDateToVaccinationCampaign.keySet()) { @@ -99,7 +99,8 @@ public void handleVaccination(Map, EpisimPerson> persons, LocalDate d .filter(EpisimPerson::isVaccinable) // todo: what determines who is vaccinable? .filter(p -> p.getDiseaseStatus() == EpisimPerson.DiseaseStatus.susceptible) .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) // only boostered people are reboostered - .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > 90) // only people who've had their last vaccination more than 90 days ago + .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > 180) // only people who've had their last vaccination more than 90 days ago + .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > 180) // only people who've had their last vaccination more than 90 days ago .collect(Collectors.toList()); diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index dedacc203..30e37312f 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -7,17 +7,17 @@ import com.google.inject.util.Modules; import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.BatchRun; -import org.matsim.episim.DataUtils; -import org.matsim.episim.EpisimConfigGroup; -import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.*; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; import org.matsim.episim.model.listener.HouseholdSusceptibility; import org.matsim.episim.model.vaccination.VaccinationModel; import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; import org.matsim.episim.policy.FixedPolicy; import org.matsim.episim.policy.Restriction; import org.matsim.run.RunParallel; @@ -26,6 +26,7 @@ import javax.annotation.Nullable; import java.time.LocalDate; import java.util.*; +import java.util.stream.Collectors; /** @@ -43,10 +44,55 @@ public Module getBindings(int id, @Nullable Params params) { @Override protected void configure() { + // VACCINATION MODEL Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); - set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + // default values (if params==null) + Map startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(LocalDate.parse("2022-10-01"), VaccinationType.ba5Update); + Object2DoubleMap compliance = new Object2DoubleAVLTreeMap(); + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.0); + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.0); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.0); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); + + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered; + + int campaignDuration = 60; + + if (params != null) { + + + if (params.vacCamp.equals("60plus")) { + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.94/2); // 0.94 is boost rate July 16, 2022 + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.); + } + // assumption: older age group 2boosted first, then younger, each age group + // will have rate of 50% 2boosted by end of campaign. + // motivation: if we give both age groups same rate, then the older people + // will not be boosted as much as younger people, which seems implausible... + else if (params.vacCamp.equals("18plus")) { + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.95/2); // boost rates as of oct 11 2022 + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.77/2); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.36/2); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); + } else if (params.vacCamp.equals("off")) { + + } else { + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + } + } + + + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool)); + + + // ANTIBODY MODEL + // default values double mutEscDelta = 29.2 / 10.9; double mutEscBa1 = 10.9 / 1.9; // double mutEscBa5 = 2.9; // 0.1 -> 3.8 @@ -55,55 +101,16 @@ protected void configure() { double mutEscStrainA = 0.; double mutEscStrainB = 0.; - LocalDate start = null; - VaccinationType vaccinationType = VaccinationType.mRNA; - - Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); - compliance.put(60, 0.0); - compliance.put(18, 0.0); - compliance.put(12, 0.0); - compliance.put(0, 0.0); - - String vacCamp = "off"; - if (params != null) { // mutEscBa5 = params.ba5Esc; - if (!params.vacType.equals("off")) { - vacCamp = "age"; - vaccinationType = VaccinationType.valueOf(params.vacType); - } if (!params.StrainA.equals("off")) { mutEscStrainA = Double.parseDouble(params.StrainA); } if (!params.StrainB.equals("off")) { mutEscStrainB = Double.parseDouble(params.StrainB); } - - start = LocalDate.parse(params.resDate); - - - - if (vacCamp.equals("age")) { - compliance.put(60, 0.85); // 60+ - compliance.put(18, 0.55); // 18-59 - compliance.put(12, 0.20); // 12-17 - compliance.put(0, 0.0); // 0 - 11 - } - else if (vacCamp.equals("eu")) { - compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) - compliance.put(18, 0.); - compliance.put(12, 0.); - compliance.put(0, 0.); - } - else if (vacCamp.equals("off")) { - - } else { - throw new RuntimeException("Not a valid option for vaccinationCampaignType"); - } } -// - bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); //initial antibodies Map> initialAntibodies = new HashMap<>(); @@ -121,7 +128,7 @@ else if (vacCamp.equals("off")) { if (params == null) return; -// double pHousehold = 1.0; + // HOUSEHOLD SUSCEPTIBILITY // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. bind(HouseholdSusceptibility.Config.class).toInstance( HouseholdSusceptibility.newConfig() @@ -413,6 +420,26 @@ public Config prepareConfig(int id, Params params) { configureFutureDiseaseImport(params, episimConfig); + // modify import: + LocalDate impModDate = LocalDate.parse("2022-01-31"); + if (params.impRedBa1 != 1.0) { + NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); + for (Map.Entry entry : impBa1.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa1.put(entry.getKey(), (int) (entry.getValue() * params.impRedBa1)); + } + } + } + + if (params.impRedBa2 != 1.0) { + NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); + for (Map.Entry entry : impBa2.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa2.put(entry.getKey(), (int) (entry.getValue() * params.impRedBa2)); + } + } + } + //--------------------------------------- // R E S T R I C T I O N S //--------------------------------------- @@ -623,6 +650,12 @@ public static final class Params { @GenerateSeeds(5) public long seed; + @Parameter({0.0}) + public double impRedBa1; + + @Parameter({0.0}) + public double impRedBa2; + // NEW RESTRICTIONS @StringParameter({"2022-11-15","2022-12-01","2022-12-15"}) @@ -679,8 +712,13 @@ public static final class Params { // vaccination campaign // @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) - @StringParameter({"off"}) - public String vacType; +// @StringParameter({"off"}) +// public String vacType; + + @StringParameter({"18plus"}) +// @StringParameter({"off", "60plus", "18plus"}) + String vacCamp; + } diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index be5f95087..d855db9fa 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -382,7 +382,7 @@ public Config config() { CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); - activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20220723.csv")); + activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20221003.csv")); activityParticipation.setScale(this.scale); activityParticipation.setLeisureAsNightly(this.leisureNightly); @@ -438,12 +438,12 @@ public Config config() { //Herbstferien builder.restrict(LocalDate.parse("2022-10-04"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); builder.restrict(LocalDate.parse("2022-10-15"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - //Weihnachtsferien - builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + //Weihnachtsferien todo: reinstate xmas +// builder.restrict(LocalDate.parse("2022-12-23"), 0.2, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); +// builder.restrict(LocalDate.parse("2023-01-06"), 1.0, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); - builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); +// builder.restrict(LocalDate.parse("2022-12-19"), 0.2, "educ_higher"); +// builder.restrict(LocalDate.parse("2022-12-31"), 1.0, "educ_higher"); if (carnivalModel.equals(CarnivalModel.yes)) { // Friday 25.2 to Monday 28.2 (Rosenmontag) @@ -479,16 +479,14 @@ public Config config() { builder.applyToRf("2021-07-01", "2021-08-13", workVacFactor, "work", "business"); builder.applyToRf("2021-10-08", "2021-10-22", workVacFactor, "work", "business"); builder.applyToRf("2021-12-22", "2022-01-05", workVacFactor, "work", "business"); + builder.applyToRf("2022-04-11", "2022-04-23", workVacFactor, "work", "business"); + builder.applyToRf("2022-06-27", "2022-08-09", workVacFactor, "work", "business"); - - builder.restrict(LocalDate.parse("2022-04-11"), 0.78 * 0.92, "work", "business"); - builder.restrict(LocalDate.parse("2022-04-23"), 0.78, "work", "business"); - builder.restrict(LocalDate.parse("2022-06-27"), 0.78 * 0.92, "work", "business"); - builder.restrict(LocalDate.parse("2022-08-09"), 0.78, "work", "business"); builder.restrict(LocalDate.parse("2022-10-04"), 0.78 * 0.92, "work", "business"); builder.restrict(LocalDate.parse("2022-10-15"), 0.78, "work", "business"); - builder.restrict(LocalDate.parse("2022-12-23"), 0.78 * 0.92, "work", "business"); - builder.restrict(LocalDate.parse("2023-01-06"), 0.78, "work", "business"); + //todo: revert xmas factor +// builder.restrict(LocalDate.parse("2022-12-23"), 0.78 * 0.92, "work", "business"); +// builder.restrict(LocalDate.parse("2023-01-06"), 0.78, "work", "business"); } //MASKS From f3226013b16fae7cd7111987764e395163036800 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 12 Oct 2022 12:39:38 +0200 Subject: [PATCH 072/128] removed pesky plot --- .../HospitalNumbersFromEventsPlotter.java | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java index 5de57065d..0f369f177 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java @@ -278,35 +278,35 @@ static void aggregateAndProducePlots(Path output, List pathList, String ou //https://www.dkgev.de/dkg/coronavirus-fakten-und-infos/aktuelle-bettenbelegung/ - Int2DoubleMap reportedBedsNrw = new Int2DoubleAVLTreeMap(); - Int2DoubleMap reportedBedsIcuNrw = new Int2DoubleAVLTreeMap(); - try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("/Users/jakob/Downloads/Covid_csvgesamt(2).csv")), - CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { - - for (CSVRecord record : parser) { - - if (!record.get("Bundesland").equals("Nordrhein-Westfalen")) { - continue; - } - - String dateStr = record.get("Datum"); - LocalDate date = LocalDate.parse(dateStr); - int day = (int) startDate.until(date, ChronoUnit.DAYS); - - double incidence = 0.; - try { - incidence = Double.parseDouble(record.get("Betten")) * 100_000. / populationCntOfficialNrw; - } catch (NumberFormatException ignored) { - } - - if (record.get("Bettenart").equals("Intensivbett")) { - reportedBedsIcuNrw.put(day, incidence); - } else if (record.get("Bettenart").equals("Normalbett")) { - reportedBedsNrw.put(day, incidence); - } - - } - } +// Int2DoubleMap reportedBedsNrw = new Int2DoubleAVLTreeMap(); +// Int2DoubleMap reportedBedsIcuNrw = new Int2DoubleAVLTreeMap(); +// try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of("/Users/jakob/Downloads/Covid_csvgesamt(2).csv")), +// CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) { +// +// for (CSVRecord record : parser) { +// +// if (!record.get("Bundesland").equals("Nordrhein-Westfalen")) { +// continue; +// } +// +// String dateStr = record.get("Datum"); +// LocalDate date = LocalDate.parse(dateStr); +// int day = (int) startDate.until(date, ChronoUnit.DAYS); +// +// double incidence = 0.; +// try { +// incidence = Double.parseDouble(record.get("Betten")) * 100_000. / populationCntOfficialNrw; +// } catch (NumberFormatException ignored) { +// } +// +// if (record.get("Bettenart").equals("Intensivbett")) { +// reportedBedsIcuNrw.put(day, incidence); +// } else if (record.get("Bettenart").equals("Normalbett")) { +// reportedBedsNrw.put(day, incidence); +// } +// +// } +// } // https://datawrapper.dwcdn.net/sjUZF/334/ @@ -509,26 +509,26 @@ static void aggregateAndProducePlots(Path output, List pathList, String ou } - for (Int2DoubleMap.Entry entry : reportedBedsNrw.int2DoubleEntrySet()) { - int day = entry.getIntKey(); - records.append(day); - recordsDate.append(startDate.plusDays(day)); - - values.append(entry.getDoubleValue()); - groupings.append("Reported: General Beds (NRW)"); - - } - - - for (Int2DoubleMap.Entry entry : reportedBedsIcuNrw.int2DoubleEntrySet()) { - int day = entry.getIntKey(); - records.append(day); - recordsDate.append(startDate.plusDays(day)); +// for (Int2DoubleMap.Entry entry : reportedBedsNrw.int2DoubleEntrySet()) { +// int day = entry.getIntKey(); +// records.append(day); +// recordsDate.append(startDate.plusDays(day)); +// +// values.append(entry.getDoubleValue()); +// groupings.append("Reported: General Beds (NRW)"); +// +// } - values.append(entry.getDoubleValue()); - groupings.append("Reported: ICU Beds (NRW)"); - } +// for (Int2DoubleMap.Entry entry : reportedBedsIcuNrw.int2DoubleEntrySet()) { +// int day = entry.getIntKey(); +// records.append(day); +// recordsDate.append(startDate.plusDays(day)); +// +// values.append(entry.getDoubleValue()); +// groupings.append("Reported: ICU Beds (NRW)"); +// +// } for (Int2DoubleMap.Entry entry : reportedBedsNrw2.int2DoubleEntrySet()) { int day = entry.getIntKey(); From 213709206f2de4a9753b659d48b81dd29f9ffcb1 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Wed, 12 Oct 2022 15:18:01 +0200 Subject: [PATCH 073/128] print outs for debugging of hospital model --- .../analysis/HospitalNumbersFromEvents.java | 21 +++++++++++++++++-- .../AntibodyDependentTransitionModel.java | 4 ++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 8b1f2735c..96e1f8aa5 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -263,8 +263,8 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t ConfigHolder holderDelta = configure(factorDelta, factorDeltaICU); List handlers = List.of( - new Handler("Omicron", population, holderOmicron, 0.0), - new Handler("Delta", population, holderDelta, 0.0) + new Handler("Omicron", population, holderOmicron, 0.0) +// new Handler("Delta", population, holderDelta, 0.0) // new Handler("Omicron-Paxlovid-0.25", population, holderOmicron, 0.25), // new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), // new Handler("Omicron-Paxlovid-0.50", population, holderOmicron, 0.5), @@ -420,6 +420,11 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis @Override public void handleEvent(EpisimInfectionEvent event) { + + if (!event.getPersonId().toString().equals("12102f5")) + return; + System.out.println(event.getTime() / 86400. + " " + event.getVirusStrain()); + ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); @@ -469,6 +474,10 @@ public void handleEvent(EpisimInfectionEvent event) { @Override public void handleEvent(EpisimVaccinationEvent event) { + + if (!event.getPersonId().toString().equals("12102f5")) + return; + ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); String district = (String) population.getPersons().get(person.personId).getAttributes().getAttribute("district"); @@ -581,6 +590,14 @@ private boolean goToHospital(ImmunizablePerson person, int day) { double ageFactor = transitionModel.getProbaOfTransitioningToSeriouslySick(person); double strainFactor = holder.strainConfig.getParams(person.getVirusStrain()).getFactorSeriouslySick(); double immunityFactor = transitionModel.getSeriouslySickFactor(person, holder.vaccinationConfig, day); + + System.out.println("+++ day: " + day); + System.out.println(person.getPersonId().toString()); + System.out.println(ageFactor); + System.out.println(strainFactor); + System.out.println(immunityFactor); + System.out.println(); + double paxlovidFactor = 1.0; if (person.getAge() > 60 && day >= this.paxlovidDay) { diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 627dd3346..16274655e 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -148,6 +148,10 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup double antibodiesAfterLastImmunityEvent = person.getAntibodyLevelAtInfection() * Math.pow(2., daysSinceLastImmunityEvent / 60.); + + System.out.println("antibodiesAfterLastImmunityEvent: " + antibodiesAfterLastImmunityEvent); + System.out.println("person.getAntibodyLevelAtInfection(): " + person.getAntibodyLevelAtInfection()); + // Two modifications to antibody level below: // a) we multiply the antibody level by 4 if the agent is boostered From 6a47d8ae269af2d402b6e8870a4bf8f56ef48f15 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 12 Oct 2022 15:22:43 +0200 Subject: [PATCH 074/128] wip --- .../analysis/HospitalNumbersFromEvents.java | 26 +++++-------------- .../AntibodyDependentTransitionModel.java | 3 ++- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 8b1f2735c..74d2f0075 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,7 +60,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/xxx/") + @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/yyy/") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -277,24 +277,6 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t List eventFiles = AnalysisCommand.forEachEvent(pathToScenario, s -> { }, true, handlers.toArray(new Handler[0])); -// for (Double facA : strainFactors) { - - // configure post processing run -// double facAICU = 0.; -// String diseaseSevName = ""; -// if (facA == factorWild) { -// diseaseSevName = "Alpha"; -// facAICU = factorWildAndAlphaICU; -// } else if (facA == factorDelta) { -// diseaseSevName = "Delta"; -// facAICU = factorDeltaICU; -// } else if (facA == factorOmicron) { -// diseaseSevName = "Omicron"; -// facAICU = factorOmicronICU; -// } else { -// throw new RuntimeException("not clear what to do"); -// } - for (Handler handler : handlers) { @@ -590,6 +572,12 @@ private boolean goToHospital(ImmunizablePerson person, int day) { } // 0.36 (old) * 1.2 (delta) * ... (immunisation) = + // if returned values (ageFactor, strainFactor, immunityFactor) are high: chance of going to hosp is high / protection is low + System.out.println("Remaining Risk: " + (ageFactor + * strainFactor + * immunityFactor + * paxlovidFactor)); + return rnd.nextDouble() < ageFactor * strainFactor * immunityFactor diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 627dd3346..1bce7528f 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -159,7 +159,8 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup antibodiesAfterLastImmunityEvent *= 3.7; } - return 1. / (1. + Math.pow( antibodiesAfterLastImmunityEvent, vaccinationConfig.getBeta())); + // returns remaining risk of infection (1 is full risk, 0 is no risk), opposite of vaccine effectiveness + return 1- 1. / (1. + Math.pow( antibodiesAfterLastImmunityEvent, vaccinationConfig.getBeta())); // -- From c25f3025fc8aeb2eb834f0e59a763ffaeec3e5e4 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 13 Oct 2022 09:54:55 +0200 Subject: [PATCH 075/128] toggle immune response multiplier for non-initial immunity events --- .../analysis/HospitalNumbersFromEvents.java | 41 +++++++++++-------- .../matsim/episim/model/AntibodyModel.java | 10 ++++- .../episim/model/DefaultAntibodyModel.java | 9 +++- .../model/InfectionModelWithAntibodies.java | 1 + .../AntibodyDependentTransitionModel.java | 8 ++-- .../matsim/run/batch/CologneBMBF202210XX.java | 4 +- .../model/DefaultAntibodyModelTest.java | 11 +++-- 7 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index b6c78d09a..4437f0196 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -216,8 +216,8 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); @@ -402,11 +402,11 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis @Override public void handleEvent(EpisimInfectionEvent event) { - + if (!event.getPersonId().toString().equals("12102f5")) return; - System.out.println(event.getTime() / 86400. + " " + event.getVirusStrain()); - + //System.out.println(event.getTime() / 86400. + " " + event.getVirusStrain()); + ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); @@ -425,6 +425,7 @@ public void handleEvent(EpisimInfectionEvent event) { updateHospitalizationsPost(person, event.getVirusStrain(), day); + if (person.getNumVaccinations()==0) { incNoImmunity.mergeInt(day, 1, Integer::sum); } else if (person.getNumVaccinations()==1) { @@ -456,10 +457,10 @@ public void handleEvent(EpisimInfectionEvent event) { @Override public void handleEvent(EpisimVaccinationEvent event) { - + if (!event.getPersonId().toString().equals("12102f5")) return; - + ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); String district = (String) population.getPersons().get(person.personId).getAttributes().getAttribute("district"); @@ -569,16 +570,18 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st */ private boolean goToHospital(ImmunizablePerson person, int day) { + + double ageFactor = transitionModel.getProbaOfTransitioningToSeriouslySick(person); double strainFactor = holder.strainConfig.getParams(person.getVirusStrain()).getFactorSeriouslySick(); + //System.out.println("+++ day: " + day); +// //System.out.println("id: " + person.getPersonId().toString()); + //System.out.println("age factor : " + ageFactor); + //System.out.println("strain factor : " + strainFactor); double immunityFactor = transitionModel.getSeriouslySickFactor(person, holder.vaccinationConfig, day); - - System.out.println("+++ day: " + day); - System.out.println(person.getPersonId().toString()); - System.out.println(ageFactor); - System.out.println(strainFactor); - System.out.println(immunityFactor); - System.out.println(); + //System.out.println("immunity factor : " + immunityFactor); + + double paxlovidFactor = 1.0; @@ -590,10 +593,12 @@ private boolean goToHospital(ImmunizablePerson person, int day) { // 0.36 (old) * 1.2 (delta) * ... (immunisation) = // if returned values (ageFactor, strainFactor, immunityFactor) are high: chance of going to hosp is high / protection is low - System.out.println("Remaining Risk: " + (ageFactor - * strainFactor - * immunityFactor - * paxlovidFactor)); +// System.out.println("Remaining Risk: " + (ageFactor +// * strainFactor +// * immunityFactor +// * paxlovidFactor)); + +// System.out.println(); return rnd.nextDouble() < ageFactor * strainFactor diff --git a/src/main/java/org/matsim/episim/model/AntibodyModel.java b/src/main/java/org/matsim/episim/model/AntibodyModel.java index b7b5456f4..d75a07b94 100644 --- a/src/main/java/org/matsim/episim/model/AntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/AntibodyModel.java @@ -49,6 +49,7 @@ public static class Config { final Map> initialAntibodies; final Map> antibodyRefreshFactors; private double immuneReponseSigma = 0.; + private boolean useImmuneResponseForMultiplier = true; public Config() { @@ -162,7 +163,7 @@ public Config() { initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); Map> antibodyRefreshFactors = new HashMap<>(); - + for (VaccinationType immunityType : VaccinationType.values()) { antibodyRefreshFactors.put(immunityType, new EnumMap<>(VirusStrain.class)); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -209,6 +210,13 @@ public double getImmuneReponseSigma() { public void setImmuneReponseSigma(double immuneReponseSigma) { this.immuneReponseSigma = immuneReponseSigma; } + + public boolean getUseImmuneResponseForMultiplier() { + return this.useImmuneResponseForMultiplier; + } + public void setUseImmuneResponseForMultiplier(boolean useImmuneResponseForMultiplier) { + this.useImmuneResponseForMultiplier = useImmuneResponseForMultiplier; + } } } diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index b60b19979..f5c32240e 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -121,10 +121,15 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent double antibodies = person.getAntibodies(strain2); // refresh antibodies; ensure that antibody level does not decrease. - if (refreshFactor * person.getImmuneResponseMultiplier() >= 1) { - antibodies = antibodies * refreshFactor * person.getImmuneResponseMultiplier(); + if (antibodyConfig.getUseImmuneResponseForMultiplier()) { + if (refreshFactor * person.getImmuneResponseMultiplier() >= 1) { + antibodies = antibodies * refreshFactor * person.getImmuneResponseMultiplier(); + } + }else { + antibodies = antibodies * refreshFactor; } + // check that new antibody level at least as high as initial antibodies double initialAntibodies = antibodyConfig.initialAntibodies.get(immunityEventType).get(strain2) * person.getImmuneResponseMultiplier(); antibodies = Math.max(antibodies, initialAntibodies); diff --git a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java index b59b45bb3..3b1f76e8c 100644 --- a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java +++ b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java @@ -134,6 +134,7 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto lastUnVac = calcInfectionProbabilityWoImmunity(target, infector, restrictions, act1, act2, contactIntensity, jointTimeInContainer, indoorOutdoorFactor, shedding, intake, infectivity, susceptibility); + // remaining risk --> lower val, lower risk, max risk at 1 double immunityFactor = 1.0 / (1.0 + Math.pow(relativeAntibodyLevelTarget, vaccinationConfig.getBeta())); return 1 - Math.exp(-episimConfig.getCalibrationParameter() * susceptibility * infectivity * contactIntensity * jointTimeInContainer * ciCorrection diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index de13a15b5..4c8653c2e 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -148,9 +148,9 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup double antibodiesAfterLastImmunityEvent = person.getAntibodyLevelAtInfection() * Math.pow(2., daysSinceLastImmunityEvent / 60.); - - System.out.println("antibodiesAfterLastImmunityEvent: " + antibodiesAfterLastImmunityEvent); - System.out.println("person.getAntibodyLevelAtInfection(): " + person.getAntibodyLevelAtInfection()); + +// System.out.println("antibodiesAfterLastImmunityEvent: " + antibodiesAfterLastImmunityEvent); +// System.out.println("antibodies now : " + person.getAntibodyLevelAtInfection()); // Two modifications to antibody level below: @@ -164,7 +164,7 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup } // returns remaining risk of infection (1 is full risk, 0 is no risk), opposite of vaccine effectiveness - return 1- 1. / (1. + Math.pow( antibodiesAfterLastImmunityEvent, vaccinationConfig.getBeta())); + return 1. / (1. + Math.pow(antibodiesAfterLastImmunityEvent,vaccinationConfig.getBeta())); // -- diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index 30e37312f..b2d3a4d51 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -362,7 +362,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0 && params.importSummer2022.equals("on")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -645,6 +645,8 @@ else if (!params.StrainB.equals("off")) { } } + + public static final class Params { // general @GenerateSeeds(5) diff --git a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java index 3f4a28436..a2fc656c8 100644 --- a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java @@ -178,12 +178,15 @@ public void testNoImmunityEvents() { @Test public void testMixOfVaccinesAndInfections() { - List immunityEvents = List.of(VaccinationType.mRNA, VaccinationType.mRNA, VaccinationType.ba1Update); - IntList immunityEventDays = IntList.of(1, 181, 451); + List immunityEvents = List.of(VirusStrain.DELTA, VaccinationType.mRNA, VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5,VirusStrain.OMICRON_BA5,VirusStrain.OMICRON_BA5); + IntList immunityEventDays = IntList.of(538, 644,720,736,845,958,979); // List immunityEvents = List.of(VaccinationType.mRNA); // IntList immunityEventDays = IntList.of(1); - Int2ObjectMap> antibodyLevels = simulateAntibodyLevels(immunityEvents, immunityEventDays, 750, EpisimTestUtils.createPerson()); + EpisimPerson person = EpisimTestUtils.createPerson(); + person.setImmuneResponseMultiplier(10); + + Int2ObjectMap> antibodyLevels = simulateAntibodyLevels(immunityEvents, immunityEventDays, 1000, person); // Plot 1: nAb { @@ -222,7 +225,7 @@ public void testMixOfVaccinesAndInfections() { double nAb = strainToAntibodyMap.getOrDefault(strain, 0.); - var beta = 1.; + var beta = 1.2; var fact = 0.001; double immunityFactor = 1.0 / (1.0 + Math.pow(nAb, beta)); final double probaWVacc = 1 - Math.exp(-fact * immunityFactor); From cae8645ae64a3fa6c62be646d79cd985f2799c44 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 13 Oct 2022 10:37:00 +0200 Subject: [PATCH 076/128] changed hospitalisation post processing such that a person's immune protection against hospitalisation is calculated using the maximum antibodies (wrt the strain they were infected with) they have ever had. --- .../java/org/matsim/episim/EpisimPerson.java | 34 +++++++- .../java/org/matsim/episim/Immunizable.java | 5 ++ .../episim/model/DefaultAntibodyModel.java | 14 ++-- .../AntibodyDependentTransitionModel.java | 84 ++++--------------- 4 files changed, 60 insertions(+), 77 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index 92e5453a6..07d88e9a5 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -208,10 +208,15 @@ public final class EpisimPerson implements Immunizable, Attributable { */ private final Object2DoubleMap antibodies = new Object2DoubleOpenHashMap<>(); + /** + * Maximal antibody level reached by agent w/ respect to each strain + */ + private final Object2DoubleMap maximalAntibodyLevel = new Object2DoubleOpenHashMap<>(); + /** * Antibody level at last infection. */ - private double antibodyLevelAtInfection = 0; + private double antibodyLevelAtInfection = 0.; /** * Immune response multiplier, which is used to scale the antibody increase due to an immunity event @@ -304,6 +309,12 @@ void read(ObjectInput in, Map, EpisimPerson> persons) throws IOExcept antibodies.put(strain, in.readDouble()); } + n = in.readInt(); + for (int i = 0; i < n; i++) { + VirusStrain strain = VirusStrain.values()[in.readInt()]; + maximalAntibodyLevel.put(strain, in.readDouble()); + } + status = DiseaseStatus.values()[in.readInt()]; quarantineStatus = QuarantineStatus.values()[in.readInt()]; quarantineDate = in.readInt(); @@ -371,6 +382,12 @@ void write(ObjectOutput out) throws IOException { out.writeDouble(kv.getDoubleValue()); } + out.writeInt(maximalAntibodyLevel.size()); + for (Object2DoubleMap.Entry kv : maximalAntibodyLevel.object2DoubleEntrySet()) { + out.writeInt(kv.getKey().ordinal()); + out.writeDouble(kv.getDoubleValue()); + } + out.writeInt(status.ordinal()); out.writeInt(quarantineStatus.ordinal()); out.writeInt(quarantineDate); @@ -576,6 +593,11 @@ public double getAntibodyLevelAtInfection() { return antibodyLevelAtInfection; } + public Object2DoubleMap getMaximalAntibodyLevel() { + return maximalAntibodyLevel; + } + + public double getAntibodies(VirusStrain strain) { return antibodies.getDouble(strain); } @@ -584,8 +606,16 @@ public Object2DoubleMap getAntibodies() { return antibodies; } - public double setAntibodies(VirusStrain strain, double value) { + public double setAntibodies(VirusStrain strain, double value, boolean increaseAb) { + + if(increaseAb) { + if (value > maximalAntibodyLevel.getDouble(strain)) { + maximalAntibodyLevel.put(strain, value); + } + } + return antibodies.put(strain, value); + } /** diff --git a/src/main/java/org/matsim/episim/Immunizable.java b/src/main/java/org/matsim/episim/Immunizable.java index 46f8ab93e..4e1e5a40a 100644 --- a/src/main/java/org/matsim/episim/Immunizable.java +++ b/src/main/java/org/matsim/episim/Immunizable.java @@ -2,6 +2,7 @@ import it.unimi.dsi.fastutil.doubles.DoubleList; import it.unimi.dsi.fastutil.ints.IntList; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import org.matsim.core.api.internal.HasPersonId; import org.matsim.episim.model.VirusStrain; @@ -47,6 +48,10 @@ public interface Immunizable extends HasPersonId { */ double getAntibodyLevelAtInfection(); + /** + * Returns highest antibody level that agent has had in their past. + */ + Object2DoubleMap getMaximalAntibodyLevel(); /** * Returns whether agent has experienced given disease status at any time in the course of the simulation diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index f5c32240e..a328ce81f 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -6,7 +6,6 @@ import org.matsim.episim.EpisimUtils; import java.util.Collection; -import java.util.List; import java.util.SplittableRandom; public class DefaultAntibodyModel implements AntibodyModel { @@ -41,7 +40,8 @@ public void init(Collection persons, int iteration) { person.setImmuneResponseMultiplier(immuneResponseMultiplier); for (VirusStrain strain : VirusStrain.values()) { - person.setAntibodies(strain, 0.0); + person.setAntibodies(strain, 0.0, false); + person.getMaximalAntibodyLevel().put(strain, 0.0); } if (iteration > 1) { @@ -69,7 +69,7 @@ public void updateAntibodies(EpisimPerson person, int day) { // todo: is this needed, now that we have an init if (day == 0) { for (VirusStrain strain : VirusStrain.values()) { - person.setAntibodies(strain, 0.0); + person.setAntibodies(strain, 0.0, false); } } @@ -93,7 +93,7 @@ public void updateAntibodies(EpisimPerson person, int day) { // if no immunity event: exponential decay, day by day: for (VirusStrain strain : VirusStrain.values()) { double oldAntibodyLevel = person.getAntibodies(strain); - person.setAntibodies(strain, oldAntibodyLevel * Math.pow(0.5, 1 / HALF_LIFE_DAYS)); + person.setAntibodies(strain, oldAntibodyLevel * Math.pow(0.5, 1 / HALF_LIFE_DAYS), false); } } @@ -109,7 +109,7 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent antibodies = Math.min(150., antibodies * person.getImmuneResponseMultiplier()); - person.setAntibodies(strain2, antibodies); + person.setAntibodies(strain2, antibodies, true); } @@ -129,16 +129,14 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent antibodies = antibodies * refreshFactor; } - // check that new antibody level at least as high as initial antibodies double initialAntibodies = antibodyConfig.initialAntibodies.get(immunityEventType).get(strain2) * person.getImmuneResponseMultiplier(); antibodies = Math.max(antibodies, initialAntibodies); - // check that new antibody level is at most 150 antibodies = Math.min(150., antibodies); - person.setAntibodies(strain2, antibodies); + person.setAntibodies(strain2, antibodies, true); } } } diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 4c8653c2e..8ebf5627d 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -114,41 +114,32 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup int numVaccinations = person.getNumVaccinations(); int numInfections = person.getNumInfections() - 1; - // Version from Sander - // -- -// if (numVaccinations + numInfections == 1) { -// return 0.3; -// } -// -// if (numVaccinations + numInfections > 1) { -// return 0.1; -// } -// -// return 1.0; - // -- - // version with antibodies if (numVaccinations == 0 && numInfections == 0) return 1.0; VirusStrain strain = person.getVirusStrain(); - int lastVaccination = 0; + double abNoWaning; + if (true) { + abNoWaning = person.getMaximalAntibodyLevel().getDouble(strain); + } else { + int lastVaccination = 0; - if (numVaccinations > 0) - lastVaccination = person.getVaccinationDates().getInt(numVaccinations - 1); + if (numVaccinations > 0) + lastVaccination = person.getVaccinationDates().getInt(numVaccinations - 1); - int lastInfection = 0; + int lastInfection = 0; - if (numInfections > 0) - lastInfection = (int) (person.getInfectionDates().getDouble(numInfections - 1) / 86400.); - - int lastImmunityEvent = Math.max(lastVaccination, lastInfection); - int daysSinceLastImmunityEvent = day - lastImmunityEvent; + if (numInfections > 0) + lastInfection = (int) (person.getInfectionDates().getDouble(numInfections - 1) / 86400.); + int lastImmunityEvent = Math.max(lastVaccination, lastInfection); + int daysSinceLastImmunityEvent = day - lastImmunityEvent; - double antibodiesAfterLastImmunityEvent = person.getAntibodyLevelAtInfection() * Math.pow(2., daysSinceLastImmunityEvent / 60.); + abNoWaning = person.getAntibodyLevelAtInfection() * Math.pow(2., daysSinceLastImmunityEvent / 60.); + } // System.out.println("antibodiesAfterLastImmunityEvent: " + antibodiesAfterLastImmunityEvent); // System.out.println("antibodies now : " + person.getAntibodyLevelAtInfection()); @@ -156,57 +147,16 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup // Two modifications to antibody level below: // a) we multiply the antibody level by 4 if the agent is boostered if (numVaccinations > 1) { - antibodiesAfterLastImmunityEvent *= 4; + abNoWaning *= 4; } // b) if strain is omicron, an additional factor of 3.7 is applied if (strain.equals(VirusStrain.OMICRON_BA1) || strain.equals(VirusStrain.OMICRON_BA2) || strain.equals(VirusStrain.OMICRON_BA5) || strain.equals(VirusStrain.STRAIN_A) || strain.equals(VirusStrain.STRAIN_B)) { - antibodiesAfterLastImmunityEvent *= 3.7; + abNoWaning *= 3.7; } // returns remaining risk of infection (1 is full risk, 0 is no risk), opposite of vaccine effectiveness - return 1. / (1. + Math.pow(antibodiesAfterLastImmunityEvent,vaccinationConfig.getBeta())); - + return 1. / (1. + Math.pow(abNoWaning,vaccinationConfig.getBeta())); - // -- - // even older version -// -// double veSeriouslySick = 0.0; -// -// //vaccinated persons that are boostered either by infection or by 3rd shot -// if (numVaccinations > 1 || (numVaccinations > 0 && numInfections > 1)) { -// if (strain == VirusStrain.OMICRON_BA1 || strain == VirusStrain.OMICRON_BA2) -// veSeriouslySick = 0.9; -// else -// veSeriouslySick = 0.95; -// } -// -// //vaccinated persons or persons who have had a severe course of disease in the past -// // I think this does not work, because old states are removed when changing from recovered to susceptible. SM -// else if (numVaccinations == 1 || person.hadDiseaseStatus(DiseaseStatus.seriouslySick)) { -//// else if (numVaccinations == 1 || person.hadStrain(VirusStrain.SARS_CoV_2) || person.hadStrain(VirusStrain.ALPHA) || person.hadStrain(VirusStrain.DELTA)) -// -// if (strain == VirusStrain.OMICRON_BA1 || strain == VirusStrain.OMICRON_BA2) -// veSeriouslySick = 0.55; -// else -// veSeriouslySick = 0.9; -// } -// -// -// else { -// if (strain == VirusStrain.OMICRON_BA1 || strain == VirusStrain.OMICRON_BA2) -// veSeriouslySick = 0.55; -// else -// veSeriouslySick = 0.6; -// } -// -// double factorInf = person.getImmunityFactor(vaccinationConfig.getBeta()); -// -// double factorSeriouslySick = (1.0 - veSeriouslySick) / factorInf; -// -// factorSeriouslySick = Math.min(1.0, factorSeriouslySick); -// factorSeriouslySick = Math.max(0.0, factorSeriouslySick); -// -// return factorSeriouslySick; } @Override From 4649dc87bb88616170f54f9e1c44d4e3440cfe37 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 13 Oct 2022 11:59:00 +0200 Subject: [PATCH 077/128] refactored maxAntibodies. Include maxAntibodies in EpisimInfectionEvent --- .../java/org/matsim/episim/EpisimPerson.java | 25 +++++++++++----- .../java/org/matsim/episim/Immunizable.java | 9 ++++-- .../analysis/HospitalNumbersFromEvents.java | 29 ++++++++++++++----- .../episim/events/EpisimEventsReader.java | 6 +++- .../episim/events/EpisimInfectionEvent.java | 12 +++++++- .../episim/model/AbstractContactModel.java | 2 +- .../episim/model/DefaultAntibodyModel.java | 23 +++++++++++---- .../AntibodyDependentTransitionModel.java | 4 +-- 8 files changed, 81 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index 07d88e9a5..d546bfe01 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -593,11 +593,15 @@ public double getAntibodyLevelAtInfection() { return antibodyLevelAtInfection; } - public Object2DoubleMap getMaximalAntibodyLevel() { + public Object2DoubleMap getMaxAntibodies() { return maximalAntibodyLevel; } + public double getMaxAntibodies(VirusStrain virusStrain) { + return maximalAntibodyLevel.getDouble(virusStrain); + } + public double getAntibodies(VirusStrain strain) { return antibodies.getDouble(strain); } @@ -606,18 +610,22 @@ public Object2DoubleMap getAntibodies() { return antibodies; } - public double setAntibodies(VirusStrain strain, double value, boolean increaseAb) { - - if(increaseAb) { - if (value > maximalAntibodyLevel.getDouble(strain)) { - maximalAntibodyLevel.put(strain, value); - } - } + public double setAntibodies(VirusStrain strain, double value) { return antibodies.put(strain, value); } + /** + * Sets the maximum antibodies agent has had versus a particular strain. + * todo: Does not check if new max value is in fact greater than previous max. + */ + public void setMaxAntibodies(VirusStrain strain, double maxAb) { + + this.maximalAntibodyLevel.put(strain, maxAb); + + } + /** * Days elapsed since a certain status was set. * This will always round the change as if it happened on the start of a day. @@ -1076,6 +1084,7 @@ public PerformedActivity getNextActivity(DayOfWeek day, double time) { return null; } + /** * Disease status of a person. */ diff --git a/src/main/java/org/matsim/episim/Immunizable.java b/src/main/java/org/matsim/episim/Immunizable.java index 4e1e5a40a..c915f480b 100644 --- a/src/main/java/org/matsim/episim/Immunizable.java +++ b/src/main/java/org/matsim/episim/Immunizable.java @@ -49,9 +49,14 @@ public interface Immunizable extends HasPersonId { double getAntibodyLevelAtInfection(); /** - * Returns highest antibody level that agent has had in their past. + * Returns highest antibody level that agent has had in their past for all strains */ - Object2DoubleMap getMaximalAntibodyLevel(); + Object2DoubleMap getMaxAntibodies(); + + /** + * Returns highest antibody level that agent has had in their past for a specific strain. + */ + double getMaxAntibodies(VirusStrain strain); /** * Returns whether agent has experienced given disease status at any time in the course of the simulation diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 4437f0196..24ff99b38 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -263,8 +263,8 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t ConfigHolder holderDelta = configure(factorDelta, factorDeltaICU); List handlers = List.of( - new Handler("Omicron", population, holderOmicron, 0.0) -// new Handler("Delta", population, holderDelta, 0.0) + new Handler("Omicron", population, holderOmicron, 0.0), + new Handler("Delta", population, holderDelta, 0.0) // new Handler("Omicron-Paxlovid-0.25", population, holderOmicron, 0.25), // new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), // new Handler("Omicron-Paxlovid-0.50", population, holderOmicron, 0.5), @@ -403,8 +403,8 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis @Override public void handleEvent(EpisimInfectionEvent event) { - if (!event.getPersonId().toString().equals("12102f5")) - return; +// if (!event.getPersonId().toString().equals("12102f5")) +// return; //System.out.println(event.getTime() / 86400. + " " + event.getVirusStrain()); @@ -417,13 +417,15 @@ public void handleEvent(EpisimInfectionEvent event) { return; } + VirusStrain virusStrain = event.getVirusStrain(); person.addInfection(event.getTime()); person.setAntibodyLevelAtInfection(event.getAntibodies()); - person.setVirusStrain(event.getVirusStrain()); + person.getMaxAntibodies().put(virusStrain, event.getMaxAntibodies()); + person.setVirusStrain(virusStrain); int day = (int) (event.getTime() / 86_400); - updateHospitalizationsPost(person, event.getVirusStrain(), day); + updateHospitalizationsPost(person, virusStrain, day); if (person.getNumVaccinations()==0) { @@ -458,8 +460,8 @@ public void handleEvent(EpisimInfectionEvent event) { @Override public void handleEvent(EpisimVaccinationEvent event) { - if (!event.getPersonId().toString().equals("12102f5")) - return; +// if (!event.getPersonId().toString().equals("12102f5")) +// return; ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); @@ -653,6 +655,12 @@ static final class ImmunizablePerson implements Immunizable{ * Antibody level at last infection. */ private double antibodyLevelAtInfection = 0; + + /** + * Maximal antibody level reached by agent w/ respect to each strain + */ + private final Object2DoubleMap maximalAntibodyLevel = new Object2DoubleOpenHashMap<>(); + private int age; ImmunizablePerson(Id personId, int age) { @@ -714,6 +722,11 @@ public double getAntibodyLevelAtInfection() { return antibodyLevelAtInfection; } + @Override + public Object2DoubleMap getMaxAntibodies() { + return maximalAntibodyLevel; + } + @Override public boolean hadDiseaseStatus(EpisimPerson.DiseaseStatus status) { throw new UnsupportedOperationException("this method is not supported by Holder"); diff --git a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java index 8c6511983..07f3bc98b 100644 --- a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java +++ b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java @@ -92,8 +92,12 @@ private MatsimEventsReader.CustomEventMapper getEpisimInfectionEventMapper() { antibodies = Double.parseDouble(attributes.get(EpisimInfectionEvent.ANTIBODIES)); } + double maxAntibodies = -1; + if (attributes.containsKey(EpisimInfectionEvent.MAX_ANTIBODIES)) { + maxAntibodies = Double.parseDouble(attributes.get(EpisimInfectionEvent.MAX_ANTIBODIES)); + } - return new EpisimInfectionEvent(time, person, infector, container, type, groupSize, virusStrain, probability, antibodies); + return new EpisimInfectionEvent(time, person, infector, container, type, groupSize, virusStrain, probability, antibodies, maxAntibodies); }; } diff --git a/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java b/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java index 0a1e28e90..c42de8a1a 100644 --- a/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java +++ b/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java @@ -25,6 +25,7 @@ public class EpisimInfectionEvent extends Event implements HasPersonId, Comparab static final String PROBABILITY = "probability"; static final String GROUP_SIZE = "groupSize"; static final String ANTIBODIES = "antibodies"; + static final String MAX_ANTIBODIES = "maxAntibodies"; private final Id personId; private final Id infectorId; @@ -34,13 +35,14 @@ public class EpisimInfectionEvent extends Event implements HasPersonId, Comparab private final VirusStrain virusStrain; private final double probability; private final double antibodies; + private final double maxAntibodies; /** * Constructor. */ public EpisimInfectionEvent(double time, Id personId, Id infectorId, Id containerId, String infectionType, - int groupSize, VirusStrain strain, double probability, double antibodies) { + int groupSize, VirusStrain strain, double probability, double antibodies, double maxAntibodies) { super(time); this.personId = personId; @@ -51,6 +53,7 @@ public EpisimInfectionEvent(double time, Id personId, Id infecto this.virusStrain = strain; this.probability = probability; this.antibodies = antibodies; + this.maxAntibodies = maxAntibodies; } @Override @@ -103,6 +106,13 @@ public double getAntibodies() { return antibodies; } + /** + * Maximum antibodies ever reached by agent with respect to infecting strain + */ + public double getMaxAntibodies() { + return maxAntibodies; + } + @Override public Map getAttributes() { Map attr = super.getAttributes(); diff --git a/src/main/java/org/matsim/episim/model/AbstractContactModel.java b/src/main/java/org/matsim/episim/model/AbstractContactModel.java index cdf0df3a7..c7f6389f9 100644 --- a/src/main/java/org/matsim/episim/model/AbstractContactModel.java +++ b/src/main/java/org/matsim/episim/model/AbstractContactModel.java @@ -389,7 +389,7 @@ protected void infectPerson(EpisimPerson personWrapper, EpisimPerson infector, d personWrapper.possibleInfection( new EpisimInfectionEvent(now, personWrapper.getPersonId(), infector.getPersonId(), container.getContainerId(), infectionType.toString(), container.getPersons().size(), infector.getVirusStrain(), prob, - personWrapper.getAntibodies(infector.getVirusStrain())) + personWrapper.getAntibodies(infector.getVirusStrain()),personWrapper.getMaxAntibodies(infector.getVirusStrain())) ); // check infection immediately if there is only one thread diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index a328ce81f..213e0acb4 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -40,8 +40,8 @@ public void init(Collection persons, int iteration) { person.setImmuneResponseMultiplier(immuneResponseMultiplier); for (VirusStrain strain : VirusStrain.values()) { - person.setAntibodies(strain, 0.0, false); - person.getMaximalAntibodyLevel().put(strain, 0.0); + person.setAntibodies(strain, 0.0); + person.setMaxAntibodies(strain, 0.0); } if (iteration > 1) { @@ -69,7 +69,7 @@ public void updateAntibodies(EpisimPerson person, int day) { // todo: is this needed, now that we have an init if (day == 0) { for (VirusStrain strain : VirusStrain.values()) { - person.setAntibodies(strain, 0.0, false); + person.setAntibodies(strain, 0.0); } } @@ -93,7 +93,7 @@ public void updateAntibodies(EpisimPerson person, int day) { // if no immunity event: exponential decay, day by day: for (VirusStrain strain : VirusStrain.values()) { double oldAntibodyLevel = person.getAntibodies(strain); - person.setAntibodies(strain, oldAntibodyLevel * Math.pow(0.5, 1 / HALF_LIFE_DAYS), false); + person.setAntibodies(strain, oldAntibodyLevel * Math.pow(0.5, 1 / HALF_LIFE_DAYS)); } } @@ -109,7 +109,13 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent antibodies = Math.min(150., antibodies * person.getImmuneResponseMultiplier()); - person.setAntibodies(strain2, antibodies, true); + person.setAntibodies(strain2, antibodies); + + // if antibodies against a strain2 are higher than previous maximum, replace maximum + // should always be the case for initial immunization + if (antibodies > person.getMaxAntibodies(strain2)) { + person.setMaxAntibodies(strain2, antibodies); + } } @@ -136,7 +142,12 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent // check that new antibody level is at most 150 antibodies = Math.min(150., antibodies); - person.setAntibodies(strain2, antibodies, true); + person.setAntibodies(strain2, antibodies); + + // if antibodies against a strain2 are higher than previous maximum, replace maximum + if (antibodies > person.getMaxAntibodies(strain2)) { + person.setMaxAntibodies(strain2, antibodies); + } } } } diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 8ebf5627d..2aca952b3 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -121,8 +121,8 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup VirusStrain strain = person.getVirusStrain(); double abNoWaning; - if (true) { - abNoWaning = person.getMaximalAntibodyLevel().getDouble(strain); + if (false) { + abNoWaning = person.getMaxAntibodies(strain); } else { int lastVaccination = 0; From 946fad334d19e22b56b0aeb01edd0432fd1b2c45 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 13 Oct 2022 12:13:02 +0200 Subject: [PATCH 078/128] wip --- .../java/org/matsim/episim/EpisimPerson.java | 27 +++++++++++-------- .../java/org/matsim/episim/Immunizable.java | 4 +++ .../analysis/HospitalNumbersFromEvents.java | 17 +++++++++--- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index d546bfe01..4017a2d40 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -593,15 +593,30 @@ public double getAntibodyLevelAtInfection() { return antibodyLevelAtInfection; } + /** + * get map with max antibodies reached per strain (before current infection) + */ public Object2DoubleMap getMaxAntibodies() { return maximalAntibodyLevel; } - + /** + * Get max antibodies reached for a particular strain (before current infection) + */ public double getMaxAntibodies(VirusStrain virusStrain) { return maximalAntibodyLevel.getDouble(virusStrain); } + /** + * Sets the maximum antibodies agent has had versus a particular strain. + * todo: Does not check if new max value is in fact greater than previous max. + */ + public void setMaxAntibodies(VirusStrain strain, double maxAb) { + + this.maximalAntibodyLevel.put(strain, maxAb); + + } + public double getAntibodies(VirusStrain strain) { return antibodies.getDouble(strain); } @@ -616,16 +631,6 @@ public double setAntibodies(VirusStrain strain, double value) { } - /** - * Sets the maximum antibodies agent has had versus a particular strain. - * todo: Does not check if new max value is in fact greater than previous max. - */ - public void setMaxAntibodies(VirusStrain strain, double maxAb) { - - this.maximalAntibodyLevel.put(strain, maxAb); - - } - /** * Days elapsed since a certain status was set. * This will always round the change as if it happened on the start of a day. diff --git a/src/main/java/org/matsim/episim/Immunizable.java b/src/main/java/org/matsim/episim/Immunizable.java index c915f480b..d13b55495 100644 --- a/src/main/java/org/matsim/episim/Immunizable.java +++ b/src/main/java/org/matsim/episim/Immunizable.java @@ -58,6 +58,10 @@ public interface Immunizable extends HasPersonId { */ double getMaxAntibodies(VirusStrain strain); + /** + * sets max antibody level that agent has had in their past for a specific strain. + */ + void setMaxAntibodies(VirusStrain strain, double maxAb); /** * Returns whether agent has experienced given disease status at any time in the course of the simulation */ diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 24ff99b38..7292323f3 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -420,11 +420,13 @@ public void handleEvent(EpisimInfectionEvent event) { VirusStrain virusStrain = event.getVirusStrain(); person.addInfection(event.getTime()); person.setAntibodyLevelAtInfection(event.getAntibodies()); - person.getMaxAntibodies().put(virusStrain, event.getMaxAntibodies()); person.setVirusStrain(virusStrain); + person.setMaxAntibodies(virusStrain, event.getMaxAntibodies()); + int day = (int) (event.getTime() / 86_400); + updateHospitalizationsPost(person, virusStrain, day); @@ -659,7 +661,7 @@ static final class ImmunizablePerson implements Immunizable{ /** * Maximal antibody level reached by agent w/ respect to each strain */ - private final Object2DoubleMap maximalAntibodyLevel = new Object2DoubleOpenHashMap<>(); + private final Object2DoubleMap maxAntibodies = new Object2DoubleOpenHashMap<>(); private int age; @@ -724,7 +726,16 @@ public double getAntibodyLevelAtInfection() { @Override public Object2DoubleMap getMaxAntibodies() { - return maximalAntibodyLevel; + return maxAntibodies; + } + + @Override + public double getMaxAntibodies(VirusStrain strain) { + return maxAntibodies.getDouble(strain); + } + + public void setMaxAntibodies(VirusStrain strain, double maxAb){ + this.maxAntibodies.put(strain, maxAb); } @Override From d51c1217d20c80f51a37fef9d228a9f4886ffcaa Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 13 Oct 2022 12:56:03 +0200 Subject: [PATCH 079/128] fixed episim infection event to include max antibodies --- src/main/java/org/matsim/episim/events/EpisimEventsReader.java | 1 + .../java/org/matsim/episim/events/EpisimInfectionEvent.java | 1 + .../matsim/episim/model/vaccination/VaccinationFromData.java | 1 + src/test/java/org/matsim/episim/EpisimTestUtils.java | 2 +- .../java/org/matsim/episim/model/DefaultInfectionModelTest.java | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java index 07f3bc98b..67a04bc02 100644 --- a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java +++ b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java @@ -125,6 +125,7 @@ private MatsimEventsReader.CustomEventMapper getEpisimPotentialInfectionEventMap } return new EpisimPotentialInfectionEvent(time, person, infector, container, type, groupSize, virusStrain, probability, unVacProb, antibodies, rnd); + }; } diff --git a/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java b/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java index c42de8a1a..19f805302 100644 --- a/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java +++ b/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java @@ -124,6 +124,7 @@ public Map getAttributes() { attr.put(PROBABILITY, Double.toString(probability)); attr.put(VIRUS_STRAIN, virusStrain.toString()); attr.put(ANTIBODIES, Double.toString(antibodies)); + attr.put(MAX_ANTIBODIES, Double.toString(maxAntibodies)); return attr; } diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationFromData.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationFromData.java index eca9f62c5..2e74533a4 100644 --- a/src/main/java/org/matsim/episim/model/vaccination/VaccinationFromData.java +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationFromData.java @@ -224,6 +224,7 @@ private int vaccinate(Map, EpisimPerson> persons, TreeMap candidates = perAge[ii]; diff --git a/src/test/java/org/matsim/episim/EpisimTestUtils.java b/src/test/java/org/matsim/episim/EpisimTestUtils.java index a9e00f7c4..47831181c 100644 --- a/src/test/java/org/matsim/episim/EpisimTestUtils.java +++ b/src/test/java/org/matsim/episim/EpisimTestUtils.java @@ -190,7 +190,7 @@ public static EpisimPerson createPerson(boolean vaccinable, int age) { * Helper method to infect a person. */ public static EpisimPerson infectPerson(EpisimPerson p, VirusStrain strain, double now) { - p.possibleInfection(new EpisimInfectionEvent(now, p.getPersonId(), p.getPersonId(), null, "undefined", 1, strain, 1.0, -1)); + p.possibleInfection(new EpisimInfectionEvent(now, p.getPersonId(), p.getPersonId(), null, "undefined", 1, strain, 1.0, -1,-1)); p.checkInfection(); return p; } diff --git a/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java b/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java index 3dbd5d501..1d3229fb2 100644 --- a/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java @@ -123,7 +123,7 @@ public void immunityEffectiveness() { EpisimPerson p = EpisimTestUtils.createPerson(true, -1); - p.possibleInfection(new EpisimInfectionEvent(0, p.getPersonId(), p.getPersonId(), null, "somewhere", 1, VirusStrain.SARS_CoV_2, 1d, -1)); + p.possibleInfection(new EpisimInfectionEvent(0, p.getPersonId(), p.getPersonId(), null, "somewhere", 1, VirusStrain.SARS_CoV_2, 1d, -1,-1)); p.checkInfection(); p.setDiseaseStatus(1000, EpisimPerson.DiseaseStatus.recovered); p.setDiseaseStatus(2000, EpisimPerson.DiseaseStatus.susceptible); From e7d75c88bf7619917cab04c5d79c77a3ee79821e Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 13 Oct 2022 15:06:52 +0200 Subject: [PATCH 080/128] made option for max ab level to be used configurable also, run jakob/2022-10-13/1b-fix-noSnp --- .../matsim/episim/VaccinationConfigGroup.java | 27 +- .../AntibodyDependentTransitionModel.java | 2 +- ...java => CologneBMBF202210XX_SNAPSHOT.java} | 248 ++++++++++++------ 3 files changed, 197 insertions(+), 80 deletions(-) rename src/main/java/org/matsim/run/batch/{CologneBMBF202210XX_SNAPSHOT_old.java => CologneBMBF202210XX_SNAPSHOT.java} (80%) diff --git a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java index 1c7cb027a..6a2f2d93d 100644 --- a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java +++ b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java @@ -36,6 +36,8 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { private static final String GROUPNAME = "episimVaccination"; + private static final String USE_MAX_ANTIBODIES_FOR_HOSPITALISATION = "useMaxAntibodiesForHospitalisation"; + /** * Amount of vaccinations available per day. @@ -72,6 +74,14 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { private boolean useIgA = false; private double timePeriodIgA = 120.; + /** + * if false, the antibody level after previous immunisation is used, + * which may or may not be the absolute maximum + */ + private boolean useMaxAntibodiesForHospitalisation = false; + + + /** * Deadline after which days valid is in effect. */ @@ -253,7 +263,7 @@ public boolean getUseIgA() { } @StringSetter(TIME_PERIOD_IGA) - public void setTimePeriodIgA(double timePeriodIgA){ + public void setTimePeriodIgA(double timePeriodIgA) { this.timePeriodIgA = timePeriodIgA; } @@ -276,6 +286,16 @@ public LocalDate getValidDeadline() { return validDeadline; } + @StringSetter(USE_MAX_ANTIBODIES_FOR_HOSPITALISATION) + public void setUseMaxAntibodiesForHospitalisation(boolean useMaxAntibodiesForHospitalisation) { + this.useMaxAntibodiesForHospitalisation = useMaxAntibodiesForHospitalisation; + } + + @StringGetter(USE_MAX_ANTIBODIES_FOR_HOSPITALISATION) + public boolean getUseMaxAntibodiesForHospitalisation() { + return this.useMaxAntibodiesForHospitalisation; + } + /** * Check if person is recently recovered or vaccinated. */ @@ -338,9 +358,10 @@ public boolean hasValidVaccination(EpisimPerson person, int day, LocalDate date, /** * Computes the minimum factor over all vaccinations. + * * @param person person - * @param day current iteration - * @param f function of VaccinationParams to retrieve the desired factor + * @param day current iteration + * @param f function of VaccinationParams to retrieve the desired factor * @return minimum factor or 1 if not vaccinated */ public double getMinFactor(EpisimPerson person, int day, VaccinationFactorFunction f) { diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 2aca952b3..8deed51a8 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -121,7 +121,7 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup VirusStrain strain = person.getVirusStrain(); double abNoWaning; - if (false) { + if (vaccinationConfig.getUseMaxAntibodiesForHospitalisation()) { abNoWaning = person.getMaxAntibodies(strain); } else { int lastVaccination = 0; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT_old.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java similarity index 80% rename from src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT_old.java rename to src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java index 9cd61a58c..6a3a02ca5 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT_old.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -7,17 +7,17 @@ import com.google.inject.util.Modules; import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.BatchRun; -import org.matsim.episim.DataUtils; -import org.matsim.episim.EpisimConfigGroup; -import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.*; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; import org.matsim.episim.model.listener.HouseholdSusceptibility; import org.matsim.episim.model.vaccination.VaccinationModel; import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; import org.matsim.episim.policy.FixedPolicy; import org.matsim.episim.policy.Restriction; import org.matsim.run.RunParallel; @@ -31,7 +31,7 @@ /** * Batch for Bmbf runs */ -public class CologneBMBF202210XX_SNAPSHOT_old implements BatchRun { +public class CologneBMBF202210XX_SNAPSHOT implements BatchRun { boolean DEBUG_MODE = false; int runCount = 0; @@ -43,35 +43,86 @@ public Module getBindings(int id, @Nullable Params params) { @Override protected void configure() { + // VACCINATION MODEL Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); - set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + LocalDate start = LocalDate.parse("2022-12-01"); + VaccinationType vaccinationType = VaccinationType.ba5Update; + int campaignDuration = 30; + + // this is the vaccination campaign from the previous report + if (params != null && params.vacCamp.equals("old")) { + set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); + Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); + compliance.put(60, 0.85); // 60+ + compliance.put(18, 0.55); // 18-59 + compliance.put(12, 0.20); // 12-17 + compliance.put(0, 0.0); // 0 - 11 + bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, campaignDuration, vaccinationType, compliance)); + // this is the updated vaccination campaign + } else { + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + Map startDateToVaccination = new HashMap<>(); + + Object2DoubleMap compliance = new Object2DoubleAVLTreeMap(); + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.0); + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.0); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.0); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); + + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered; + + + if (params != null) { + if (params.vacCamp.equals("new")) { + + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.85); + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.55); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.20); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); + + startDateToVaccination.put(LocalDate.parse("2022-12-01"), vaccinationType); + + } else if (params.vacCamp.equals("newHalf")) { + + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.95 / 2); + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.77 / 2); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.36 / 2); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); + + startDateToVaccination.put(LocalDate.parse("2022-12-01"), vaccinationType); + + } else if (params.vacCamp.equals("off")) { + + } else { + + throw new RuntimeException("Not a valid option for vaccinationCampaignType"); + + } + } + + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool)); + + } + + + + // ANTIBODY MODEL + // default values double mutEscDelta = 29.2 / 10.9; double mutEscBa1 = 10.9 / 1.9; - double mutEscBa5 = 2.9; +// double mutEscBa5 = 2.9; // 0.1 -> 3.8 + double mutEscBa5 = 5.0; double mutEscStrainA = 0.; double mutEscStrainB = 0.; - LocalDate start = null; - VaccinationType vaccinationType = VaccinationType.mRNA; - - Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); - compliance.put(60, 0.0); - compliance.put(18, 0.0); - compliance.put(12, 0.0); - compliance.put(0, 0.0); - - String vacCamp = "off"; if (params != null) { -// mutEscBa5 = params.ba5Esc; +// mutEscBa1 = params.ba1Esc; + mutEscBa5 = params.ba5Esc; - if (!params.vacType.equals("off")) { - vacCamp = "age"; - vaccinationType = VaccinationType.valueOf(params.vacType); - } if (!params.StrainA.equals("off")) { mutEscStrainA = Double.parseDouble(params.StrainA); } @@ -79,30 +130,7 @@ protected void configure() { mutEscStrainB = Double.parseDouble(params.StrainB); } - start = LocalDate.parse(params.resDate); - - - - if (vacCamp.equals("age")) { - compliance.put(60, 0.85); // 60+ - compliance.put(18, 0.55); // 18-59 - compliance.put(12, 0.20); // 12-17 - compliance.put(0, 0.0); // 0 - 11 - } - else if (vacCamp.equals("eu")) { - compliance.put(60, 0.40); // half of 80% (which reflects the current percentage of people in Dland who are boostered) - compliance.put(18, 0.); - compliance.put(12, 0.); - compliance.put(0, 0.); - } - else if (vacCamp.equals("off")) { - - } else { - throw new RuntimeException("Not a valid option for vaccinationCampaignType"); - } } -// - bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, 30, vaccinationType, compliance)); //initial antibodies Map> initialAntibodies = new HashMap<>(); @@ -114,13 +142,14 @@ else if (vacCamp.equals("off")) { double immuneSigma = 3.0; if (params != null) { antibodyConfig.setImmuneReponseSigma(immuneSigma); + antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean(params.immResp)); } bind(AntibodyModel.Config.class).toInstance(antibodyConfig); if (params == null) return; -// double pHousehold = 1.0; + // HOUSEHOLD SUSCEPTIBILITY // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. bind(HouseholdSusceptibility.Config.class).toInstance( HouseholdSusceptibility.newConfig() @@ -341,9 +370,9 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( - new VaccinationEffectiveness().withArgs(), +// new VaccinationEffectiveness().withArgs(), new RValuesFromEvents().withArgs(), - new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), +// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), new FilterEvents().withArgs("--output","./output/"), new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") // new SecondaryAttackRateFromEvents().withArgs() @@ -354,7 +383,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0 && params.importSummer2022.equals("on")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -371,11 +400,14 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); - //snapshot - episimConfig.setSnapshotInterval(766); -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-07/" + params.seed + "-766-2022-03-31.zip"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); +// episimConfig.setSnapshotInterval(766); +// episimConfig.setSnapshotPrefix(params.seed +"-"); + if (params.snp.equals("on")) { + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-10/" + params.seed + "--766-2022-03-31.zip"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + } + //--------------------------------------- @@ -390,7 +422,7 @@ public Config prepareConfig(int id, Params params) { // STRAIN_A if (!params.StrainA.equals("off")) { - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); @@ -405,12 +437,41 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); } + // VAX + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); + vaccinationConfig.setUseMaxAntibodiesForHospitalisation(Boolean.parseBoolean(params.maxAb)); + //--------------------------------------- // I M P O R T //--------------------------------------- configureFutureDiseaseImport(params, episimConfig); + // modify import: + LocalDate impModDate = LocalDate.parse("2022-01-31"); + double impRedBa1 = 0.0; + double impRedBa2 = 0.0; + if (impRedBa1 != 1.0) { + NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); + for (Map.Entry entry : impBa1.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); + } + } + } + + if (impRedBa2 != 1.0) { + NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); + for (Map.Entry entry : impBa2.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); + } + } + } + + + //--------------------------------------- // R E S T R I C T I O N S //--------------------------------------- @@ -441,6 +502,7 @@ public Config prepareConfig(int id, Params params) { break; case "mask": builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); + break; case "zero": builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); @@ -495,7 +557,7 @@ public Config prepareConfig(int id, Params params) { } // Ci Correction after summer vacation 2022 (more air flow?) - builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); +// builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); // vary amount of "school" activity that takes place during vacation @@ -510,12 +572,12 @@ public Config prepareConfig(int id, Params params) { // modify seasonality - episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); if (DEBUG_MODE) { @@ -562,8 +624,8 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import - - if (params.importSummer2022.equals("on")) { + String importSummer2022 = "off"; + if (importSummer2022.equals("on")) { NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); LocalDate date = null; for (Map.Entry entry : data.entrySet()) { @@ -596,7 +658,7 @@ else if (!params.StrainB.equals("off")) { } } - } else if (params.importSummer2022.equals("off")) { + } else if (importSummer2022.equals("off")) { } else { throw new RuntimeException(); } @@ -617,12 +679,41 @@ else if (!params.StrainB.equals("off")) { public static final class Params { // general - @GenerateSeeds(5) + @GenerateSeeds(4) public long seed; +// @StringParameter({"true", "false"}) +// public String useIgA; + + @StringParameter({"off"}) + public String snp; + + @StringParameter({"true", "false"}) + public String immResp; + + @StringParameter({"true", "false"}) + public String maxAb; + + @StringParameter({"old", "new", "newHalf","off"}) + String vacCamp; + + +// @Parameter({4., 5., 6., 7., 8., 9., 10.}) +// public double ba1Esc; + + @Parameter({4., 4.5, 5., 5.5, 6.}) + public double ba5Esc; + +// @Parameter({0.0}) +// public double impRedBa1; + +// @Parameter({0.0}) +// public double impRedBa2; + + // NEW RESTRICTIONS - @StringParameter({"2022-11-15"}) + @StringParameter({"2022-12-15"}) public String resDate; //measures in the work context: @@ -647,22 +738,25 @@ public static final class Params { @StringParameter({"base"}) public String edu; - @StringParameter({"off"}) - public String importSummer2022; +// @StringParameter({"off"}) +// public String importSummer2022; - @Parameter({0.5}) - public double eduSeasonality; +// @Parameter({0.5}) +// public double eduSeasonality; // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow - @Parameter({0.75}) - public double ciCorr; +// @Parameter({0.75}) +// public double ciCorr; //how much "school" activity takes places during vacation summmer 2022 + @Parameter({ 0.8}) public double eduRfVacation; + + // @StringParameter({"off", "3.0", "6.0"}) - @StringParameter({"3.0"}) + @StringParameter({"6.0"}) public String StrainA; // @StringParameter({"off", "3.0", "6.0"}) @@ -674,14 +768,16 @@ public static final class Params { // vaccination campaign // @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) - @StringParameter({"off"}) - public String vacType; +// @StringParameter({"off"}) +// public String vacType; + + } public static void main(String[] args) { String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202210XX_SNAPSHOT_old.class.getName(), + RunParallel.OPTION_SETUP, CologneBMBF202210XX_SNAPSHOT.class.getName(), RunParallel.OPTION_PARAMS, Params.class.getName(), RunParallel.OPTION_TASKS, Integer.toString(1), RunParallel.OPTION_ITERATIONS, Integer.toString(1000), From a989290edcdb6cfb905d17c8cb9c9dba9166382b Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 14 Oct 2022 11:27:20 +0200 Subject: [PATCH 081/128] update batches --- ...ccinationStrategyReoccurringCampaigns.java | 22 +++++--- .../matsim/run/batch/CologneBMBF202210XX.java | 2 +- .../batch/CologneBMBF202210XX_SNAPSHOT.java | 53 ++++++++++++------- .../model/DefaultAntibodyModelTest.java | 36 ++++++++++++- 4 files changed, 86 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java index fc9056080..76bcb0276 100644 --- a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java @@ -96,12 +96,12 @@ public void handleVaccination(Map, EpisimPerson> persons, LocalDate d // b) is either already vaccinated or boostered, depending on the configuration // c) hasn't been vaccinated in the previous 90 days List candidates = persons.values().stream() - .filter(EpisimPerson::isVaccinable) // todo: what determines who is vaccinable? - .filter(p -> p.getDiseaseStatus() == EpisimPerson.DiseaseStatus.susceptible) - .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) // only boostered people are reboostered - .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > 180) // only people who've had their last vaccination more than 90 days ago - .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > 180) // only people who've had their last vaccination more than 90 days ago - .collect(Collectors.toList()); + .filter(EpisimPerson::isVaccinable) // todo: what determines who is vaccinable? + .filter(p -> p.getDiseaseStatus() == EpisimPerson.DiseaseStatus.susceptible) + .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) // only boostered people are reboostered + .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > config.minDaysAfterVaccination) // only people who've had their last vaccination more than 90 days ago + .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > config.minDaysAfterInfection) // only people who've had their last vaccination more than 90 days ago + .collect(Collectors.toList()); // create vaccinations-remaining counter for current day @@ -174,6 +174,10 @@ public static class Config { private final VaccinationPool vaccinationPool; + private final int minDaysAfterVaccination; + + private final int minDaysAfterInfection; + public enum VaccinationPool { vaccinated(1), @@ -189,11 +193,15 @@ public enum VaccinationPool { } - public Config(Map startDateToVaccinationCampaign, int campaignDuration, Object2DoubleMap complianceByAge, VaccinationPool vaccinationPool) { + public Config(Map startDateToVaccinationCampaign, int campaignDuration, Object2DoubleMap complianceByAge, VaccinationPool vaccinationPool, int minDaysAfterInfection, int minDaysAfterVaccination) { + this.startDateToVaccinationCampaign = startDateToVaccinationCampaign; this.campaignDuration = campaignDuration; this.complianceByAge = complianceByAge; this.vaccinationPool = vaccinationPool; + this.minDaysAfterInfection = minDaysAfterInfection; + this.minDaysAfterVaccination = minDaysAfterVaccination; + } } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index b2d3a4d51..cb51abf88 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -88,7 +88,7 @@ else if (params.vacCamp.equals("18plus")) { } - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool)); + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool, 180, 180)); // ANTIBODY MODEL diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java index 6a3a02ca5..37a7df72d 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -51,6 +51,9 @@ protected void configure() { VaccinationType vaccinationType = VaccinationType.ba5Update; int campaignDuration = 30; + int minDaysAfterInfection = 180; + int minDaysAfterVaccination = 180; + // this is the vaccination campaign from the previous report if (params != null && params.vacCamp.equals("old")) { set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); @@ -73,9 +76,13 @@ protected void configure() { VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered; - if (params != null) { - if (params.vacCamp.equals("new")) { + vaccinationPool = params.vacPool; + minDaysAfterInfection = (int) params.minDaysAfterImm; + minDaysAfterVaccination = (int) params.minDaysAfterImm; + + if (params.vacCamp.equals("off")) { + } else if(params.vacCamp.equals("new")) { compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.85); compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.55); @@ -84,25 +91,29 @@ protected void configure() { startDateToVaccination.put(LocalDate.parse("2022-12-01"), vaccinationType); - } else if (params.vacCamp.equals("newHalf")) { - - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.95 / 2); - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.77 / 2); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.36 / 2); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); - - startDateToVaccination.put(LocalDate.parse("2022-12-01"), vaccinationType); - - } else if (params.vacCamp.equals("off")) { - } else { - throw new RuntimeException("Not a valid option for vaccinationCampaignType"); - + double comp = Double.parseDouble(params.vacCamp) / 100.; + //these are new rates of boostered people + if (params.vacPool.equals(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered)) { + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.85 * comp); + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.66 * comp); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.31 * comp); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0 * comp); + } else if (params.vacPool.equals(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated)) { + compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.90 * comp); + compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.83 * comp); + compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.69 * comp); + compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.20 * comp); + } else { + throw new RuntimeException(); + } + startDateToVaccination.put(LocalDate.parse("2022-12-01"), vaccinationType); } + } - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool)); + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination)); } @@ -694,14 +705,20 @@ public static final class Params { @StringParameter({"true", "false"}) public String maxAb; - @StringParameter({"old", "new", "newHalf","off"}) + @StringParameter({"off", "old", "new", "50","60","70","80", "90","100"}) // 9 String vacCamp; + @EnumParameter(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.class) + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vacPool; + + + @Parameter({0., 90., 180.}) + public double minDaysAfterImm; // @Parameter({4., 5., 6., 7., 8., 9., 10.}) // public double ba1Esc; - @Parameter({4., 4.5, 5., 5.5, 6.}) + @Parameter({5.}) public double ba5Esc; // @Parameter({0.0}) diff --git a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java index a2fc656c8..17e351140 100644 --- a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java @@ -184,7 +184,7 @@ public void testMixOfVaccinesAndInfections() { // IntList immunityEventDays = IntList.of(1); EpisimPerson person = EpisimTestUtils.createPerson(); - person.setImmuneResponseMultiplier(10); + person.setImmuneResponseMultiplier(0.1); Int2ObjectMap> antibodyLevels = simulateAntibodyLevels(immunityEvents, immunityEventDays, 1000, person); @@ -303,6 +303,40 @@ public void testImmunityResponseMultiplier() { } + @Test + public void testyTest(){ + + List people = new ArrayList<>(); + + for (int i = 0; i < 90_000; i++) { + people.add("boostered"); + } + + for (int i = 0; i < 10_000; i++) { + people.add("vaccinated"); + } + + Collections.shuffle(people); + + double cntVaccinated = 0; + double cntBoostered = 0; + for (int i = 0; i < 50_000; i++) { + if (people.get(i).equals("vaccinated")) { + cntVaccinated++; + }else { + cntBoostered++; + } + } + + System.out.println(cntVaccinated / 10_000); + System.out.println(cntBoostered / 90_000); + + + + + return; + + } @Test From d98f22d9cf6bf33193994832741b79baf6ab1fe8 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 14 Oct 2022 12:47:18 +0200 Subject: [PATCH 082/128] modified vaccination strategy and batch --- ...ccinationStrategyReoccurringCampaigns.java | 112 +++++------------- .../matsim/run/batch/CologneBMBF202210XX.java | 6 +- .../batch/CologneBMBF202210XX_SNAPSHOT.java | 102 ++++++---------- 3 files changed, 70 insertions(+), 150 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java index 76bcb0276..60ab7bf65 100644 --- a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java @@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.IdSet; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Population; @@ -27,8 +28,9 @@ public class VaccinationStrategyReoccurringCampaigns implements VaccinationModel private final SplittableRandom rnd; private final Config config; - // LocalDate of beginning of vaccination campaign -> age-group -> number of vaccinations left - private final Map> vaccinationsLeftPerAgePerCampaign; + private final IdSet boostBa5Yes = new IdSet<>(Person.class); + + private final IdSet boostBa5Emergency = new IdSet<>(Person.class); @Inject @@ -38,50 +40,30 @@ public VaccinationStrategyReoccurringCampaigns(SplittableRandom rnd, Config conf Population population = scenario.getPopulation(); + for (Person person : population.getPersons().values()) { - // number of agents in each age group - int agentCnt_0_11 = (int) population.getPersons().values().stream().filter(p -> ((int) p.getAttributes().getAttribute("microm:modeled:age") >= 0 && (int) p.getAttributes().getAttribute("microm:modeled:age") < 12)).count(); - int agentCnt_12_17 = (int) population.getPersons().values().stream().filter(p -> ((int) p.getAttributes().getAttribute("microm:modeled:age") >= 12 && (int) p.getAttributes().getAttribute("microm:modeled:age") < 18)).count(); - int agentCnt_18_59 = (int) population.getPersons().values().stream().filter(p -> ((int) p.getAttributes().getAttribute("microm:modeled:age") >= 18 && (int) p.getAttributes().getAttribute("microm:modeled:age") < 60)).count(); - int agentCnt_60_plus = (int) population.getPersons().values().stream().filter(p -> (int) p.getAttributes().getAttribute("microm:modeled:age") >= 60).count(); - - //multiply compliance by these numbers -> total number of vaccines to be applied to age group - int vaxCnt_0_11 = (int) (agentCnt_0_11 * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_0_11)); - int vaxCnt_12_17 = (int) (agentCnt_12_17 * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_12_17)); - int vaxCnt_18_59 = (int) (agentCnt_18_59 * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_18_59)); - int vaxCnt_60_plus = (int) (agentCnt_60_plus * config.complianceByAge.getDouble(EpisimReporting.AgeGroup.age_60_plus)); - - // put these vaccination counts in map form - Object2IntMap vaccinationsLeftPerAge = new Object2IntOpenHashMap(Map.of( - EpisimReporting.AgeGroup.age_0_11, vaxCnt_0_11, - EpisimReporting.AgeGroup.age_12_17, vaxCnt_12_17, - EpisimReporting.AgeGroup.age_18_59, vaxCnt_18_59, - EpisimReporting.AgeGroup.age_60_plus, vaxCnt_60_plus - )); - - // create an age-group vaccinations remaining counter for each vaccination campaign (will count down to 0) - // each map is a copy of map created above - this.vaccinationsLeftPerAgePerCampaign = new HashMap<>(); - for (LocalDate startDate : config.startDateToVaccinationCampaign.keySet()) { - this.vaccinationsLeftPerAgePerCampaign.put(startDate, new HashMap<>(vaccinationsLeftPerAge)); + double randomNum = rnd.nextDouble(); + if (randomNum < 0.5) { + boostBa5Yes.add(person.getId()); + } + if (randomNum < 0.75) { + boostBa5Emergency.add(person.getId()); + } } // calculate total number of vaccinations: - int totalVaccinationsDistributedPerCampaign = vaccinationsLeftPerAge.values().intStream().sum(); - dailyVaccinationsToBeDistributed = totalVaccinationsDistributedPerCampaign / config.campaignDuration; + dailyVaccinationsToBeDistributed = 10_000 / 4 ; } @Override public void handleVaccination(Map, EpisimPerson> persons, LocalDate date, int iteration, double now) { - // we check that the compliance of at least one age group is greater than 0.0. If not, there will be no vaccinations anyway if (dailyVaccinationsToBeDistributed <= 0) { return; } - // Loop through all vaccination campaigns (via the start date of said campaign) for (LocalDate vaccinationCampaignStartDate : config.startDateToVaccinationCampaign.keySet()) { // Check whether current date falls within vaccination campaign @@ -96,63 +78,31 @@ public void handleVaccination(Map, EpisimPerson> persons, LocalDate d // b) is either already vaccinated or boostered, depending on the configuration // c) hasn't been vaccinated in the previous 90 days List candidates = persons.values().stream() - .filter(EpisimPerson::isVaccinable) // todo: what determines who is vaccinable? + .filter(EpisimPerson::isVaccinable) .filter(p -> p.getDiseaseStatus() == EpisimPerson.DiseaseStatus.susceptible) - .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) // only boostered people are reboostered + .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > config.minDaysAfterVaccination) // only people who've had their last vaccination more than 90 days ago .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > config.minDaysAfterInfection) // only people who've had their last vaccination more than 90 days ago + .filter(p -> date.isAfter(config.emergencyDate.minusDays(1)) ? boostBa5Emergency.contains(p.getPersonId()) : boostBa5Yes.contains(p.getPersonId())) .collect(Collectors.toList()); + // create vaccinations-remaining counter for current day int vaccinationsLeft = this.dailyVaccinationsToBeDistributed; - - // group candidates into age groups - Map> candidatesPerAgeGroup = new HashMap<>(); - for (EpisimReporting.AgeGroup ageGroup : EpisimReporting.AgeGroup.values()) { - candidatesPerAgeGroup.put(ageGroup, new ArrayList<>()); - } - for (EpisimPerson person : candidates) { - for (EpisimReporting.AgeGroup ageGroup : EpisimReporting.AgeGroup.values()) { - if (person.getAge() >= ageGroup.lowerBoundAge) { - candidatesPerAgeGroup.get(ageGroup).add(person); - break; - } - } + if (date.isAfter(config.emergencyDate.minusDays(1))) { + vaccinationsLeft *= 2; } - // Apply vaccinations, oldest age-group first. Stop vaccinations for day if: - // a) no vaccines left for the day - // b) no age-group has any more candidates - // c) no age-group has any more vaccines left (for entire campaign) - - Iterator ageGroupIterator = Arrays.stream(EpisimReporting.AgeGroup.values()).iterator(); -// int ageIndex = AgeGroup.values().length - 1; - while (ageGroupIterator.hasNext() && vaccinationsLeft > 0) { - EpisimReporting.AgeGroup ageGroup = ageGroupIterator.next(); - - int vaccinationsLeftForAgeGroup = vaccinationsLeftPerAgePerCampaign.get(vaccinationCampaignStartDate).get(ageGroup); - - // list is shuffled to avoid eventual bias - List candidatesForAge = candidatesPerAgeGroup.get(ageGroup); - Collections.shuffle(candidatesForAge, new Random(EpisimUtils.getSeed(rnd))); - -// -// int vaccinesForDayAndAgeGroup = Math.min(candidatesForAge.size(), vaccinationsLeft); - Iterator candidateIterator = candidatesForAge.stream().iterator(); - EpisimPerson person; - while(candidateIterator.hasNext() && vaccinationsLeft > 0 && vaccinationsLeftForAgeGroup > 0){ - person = candidateIterator.next(); - - vaccinate(person, iteration, vaccinationType); - vaccinationsLeft--; - vaccinationsLeftForAgeGroup--; - } - vaccinationsLeftPerAgePerCampaign.get(vaccinationCampaignStartDate).put(ageGroup, vaccinationsLeftForAgeGroup); - } + // list is shuffled to avoid eventual bias + if (candidates.size() != 0) + Collections.shuffle(candidates, new Random(EpisimUtils.getSeed(rnd))); - if (vaccinationsLeft > 0) { - System.out.println(vaccinationsLeft + " vaccinations were left over at end of day "); + int n = Math.min(candidates.size(), vaccinationsLeft); + for (int i = 0; i < n; i++) { + EpisimPerson person = candidates.get(i); + vaccinate(person, iteration, vaccinationType); + vaccinationsLeft--; } } } @@ -170,14 +120,14 @@ public static class Config { */ private final int campaignDuration; - private final Object2DoubleMap complianceByAge; - private final VaccinationPool vaccinationPool; private final int minDaysAfterVaccination; private final int minDaysAfterInfection; + private final LocalDate emergencyDate; + public enum VaccinationPool { vaccinated(1), @@ -193,14 +143,14 @@ public enum VaccinationPool { } - public Config(Map startDateToVaccinationCampaign, int campaignDuration, Object2DoubleMap complianceByAge, VaccinationPool vaccinationPool, int minDaysAfterInfection, int minDaysAfterVaccination) { + public Config(Map startDateToVaccinationCampaign, int campaignDuration, VaccinationPool vaccinationPool, int minDaysAfterInfection, int minDaysAfterVaccination, LocalDate emergencyDate) { this.startDateToVaccinationCampaign = startDateToVaccinationCampaign; this.campaignDuration = campaignDuration; - this.complianceByAge = complianceByAge; this.vaccinationPool = vaccinationPool; this.minDaysAfterInfection = minDaysAfterInfection; this.minDaysAfterVaccination = minDaysAfterVaccination; + this.emergencyDate = emergencyDate; } } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index cb51abf88..28192cac9 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -88,7 +88,11 @@ else if (params.vacCamp.equals("18plus")) { } - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool, 180, 180)); + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, + campaignDuration, + vaccinationPool, + 180, + 180, LocalDate.MAX)); // ANTIBODY MODEL diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java index 37a7df72d..821c38ec5 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -45,85 +45,51 @@ protected void configure() { // VACCINATION MODEL Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); - - - LocalDate start = LocalDate.parse("2022-12-01"); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + // fixed values + LocalDate start = LocalDate.parse("2022-10-15"); VaccinationType vaccinationType = VaccinationType.ba5Update; - int campaignDuration = 30; + int campaignDuration = 300000; + // default values, to be changed if params != null int minDaysAfterInfection = 180; int minDaysAfterVaccination = 180; + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered; + LocalDate emergencyDate = LocalDate.MAX; + Map startDateToVaccination = new HashMap<>(); - // this is the vaccination campaign from the previous report - if (params != null && params.vacCamp.equals("old")) { - set.addBinding().to(VaccinationStrategyBMBF0617.class).in(Singleton.class); - Int2DoubleMap compliance = new Int2DoubleAVLTreeMap(); - compliance.put(60, 0.85); // 60+ - compliance.put(18, 0.55); // 18-59 - compliance.put(12, 0.20); // 12-17 - compliance.put(0, 0.0); // 0 - 11 - bind(VaccinationStrategyBMBF0617.Config.class).toInstance(new VaccinationStrategyBMBF0617.Config(start, campaignDuration, vaccinationType, compliance)); - // this is the updated vaccination campaign - } else { - set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); - Map startDateToVaccination = new HashMap<>(); - - Object2DoubleMap compliance = new Object2DoubleAVLTreeMap(); - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.0); - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.0); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.0); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); - - VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered; - - if (params != null) { - vaccinationPool = params.vacPool; - minDaysAfterInfection = (int) params.minDaysAfterImm; - minDaysAfterVaccination = (int) params.minDaysAfterImm; - - if (params.vacCamp.equals("off")) { - } else if(params.vacCamp.equals("new")) { - - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.85); - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.55); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.20); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); - - startDateToVaccination.put(LocalDate.parse("2022-12-01"), vaccinationType); - - } else { - - double comp = Double.parseDouble(params.vacCamp) / 100.; - //these are new rates of boostered people - if (params.vacPool.equals(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered)) { - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.85 * comp); - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.66 * comp); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.31 * comp); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0 * comp); - } else if (params.vacPool.equals(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated)) { - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.90 * comp); - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.83 * comp); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.69 * comp); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.20 * comp); - } else { - throw new RuntimeException(); - } - startDateToVaccination.put(LocalDate.parse("2022-12-01"), vaccinationType); - } + if (params != null) { + minDaysAfterInfection = (int) params.minDaysAfterImm; + minDaysAfterVaccination = (int) params.minDaysAfterImm; + vaccinationPool = params.vacPool; - } + switch (params.vacCamp) { + case "off": - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, compliance, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination)); + startDateToVaccination.put(LocalDate.MAX, vaccinationType); + break; + case "on": + + startDateToVaccination.put(start, vaccinationType); + + break; + case "emergency": + startDateToVaccination.put(start, vaccinationType); + emergencyDate = LocalDate.parse("2022-12-01"); + break; + default: + throw new RuntimeException(); + } } + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate)); // ANTIBODY MODEL // default values double mutEscDelta = 29.2 / 10.9; double mutEscBa1 = 10.9 / 1.9; -// double mutEscBa5 = 2.9; // 0.1 -> 3.8 double mutEscBa5 = 5.0; double mutEscStrainA = 0.; @@ -132,7 +98,7 @@ protected void configure() { if (params != null) { // mutEscBa1 = params.ba1Esc; - mutEscBa5 = params.ba5Esc; +// mutEscBa5 = params.ba5Esc; if (!params.StrainA.equals("off")) { mutEscStrainA = Double.parseDouble(params.StrainA); @@ -705,21 +671,21 @@ public static final class Params { @StringParameter({"true", "false"}) public String maxAb; - @StringParameter({"off", "old", "new", "50","60","70","80", "90","100"}) // 9 + + @StringParameter({"off", "on", "emergency"}) String vacCamp; @EnumParameter(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.class) VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vacPool; - @Parameter({0., 90., 180.}) public double minDaysAfterImm; // @Parameter({4., 5., 6., 7., 8., 9., 10.}) // public double ba1Esc; - @Parameter({5.}) - public double ba5Esc; +// @Parameter({5.}) +// public double ba5Esc; // @Parameter({0.0}) // public double impRedBa1; From f4fdc076e88557d489f5d9f6a52725e142a829ad Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 14 Oct 2022 14:12:38 +0200 Subject: [PATCH 083/128] remove configurability of use max ab now use max ab level ever reached to calculate chance of going to hospital --- .../matsim/episim/VaccinationConfigGroup.java | 25 +- .../analysis/HospitalNumbersFromEvents.java | 5 +- .../AntibodyDependentTransitionModel.java | 24 +- .../batch/CologneBMBF202210XX_SNAPSHOT.java | 27 +- .../CologneBMBF202210XX_vaccination.java | 768 ++++++++++++++++++ 5 files changed, 781 insertions(+), 68 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java diff --git a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java index 6a2f2d93d..47a4f8ec8 100644 --- a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java +++ b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java @@ -36,8 +36,6 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { private static final String GROUPNAME = "episimVaccination"; - private static final String USE_MAX_ANTIBODIES_FOR_HOSPITALISATION = "useMaxAntibodiesForHospitalisation"; - /** * Amount of vaccinations available per day. @@ -74,14 +72,6 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { private boolean useIgA = false; private double timePeriodIgA = 120.; - /** - * if false, the antibody level after previous immunisation is used, - * which may or may not be the absolute maximum - */ - private boolean useMaxAntibodiesForHospitalisation = false; - - - /** * Deadline after which days valid is in effect. */ @@ -286,16 +276,6 @@ public LocalDate getValidDeadline() { return validDeadline; } - @StringSetter(USE_MAX_ANTIBODIES_FOR_HOSPITALISATION) - public void setUseMaxAntibodiesForHospitalisation(boolean useMaxAntibodiesForHospitalisation) { - this.useMaxAntibodiesForHospitalisation = useMaxAntibodiesForHospitalisation; - } - - @StringGetter(USE_MAX_ANTIBODIES_FOR_HOSPITALISATION) - public boolean getUseMaxAntibodiesForHospitalisation() { - return this.useMaxAntibodiesForHospitalisation; - } - /** * Check if person is recently recovered or vaccinated. */ @@ -358,10 +338,9 @@ public boolean hasValidVaccination(EpisimPerson person, int day, LocalDate date, /** * Computes the minimum factor over all vaccinations. - * * @param person person - * @param day current iteration - * @param f function of VaccinationParams to retrieve the desired factor + * @param day current iteration + * @param f function of VaccinationParams to retrieve the desired factor * @return minimum factor or 1 if not vaccinated */ public double getMinFactor(EpisimPerson person, int day, VaccinationFactorFunction f) { diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 7292323f3..37835de03 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,7 +60,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/yyy/") + @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/qqq") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -328,9 +328,6 @@ static int getWeeklyHospitalizations(Int2IntMap hospMap, Integer today) { public static final class Handler implements EpisimVaccinationEventHandler, EpisimInfectionEventHandler { - - - final Map, ImmunizablePerson> data; private final String name; private final Population population; diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 8deed51a8..90843910e 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -120,29 +120,7 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup VirusStrain strain = person.getVirusStrain(); - double abNoWaning; - if (vaccinationConfig.getUseMaxAntibodiesForHospitalisation()) { - abNoWaning = person.getMaxAntibodies(strain); - } else { - int lastVaccination = 0; - - if (numVaccinations > 0) - lastVaccination = person.getVaccinationDates().getInt(numVaccinations - 1); - - int lastInfection = 0; - - if (numInfections > 0) - lastInfection = (int) (person.getInfectionDates().getDouble(numInfections - 1) / 86400.); - - int lastImmunityEvent = Math.max(lastVaccination, lastInfection); - int daysSinceLastImmunityEvent = day - lastImmunityEvent; - - - abNoWaning = person.getAntibodyLevelAtInfection() * Math.pow(2., daysSinceLastImmunityEvent / 60.); - } -// System.out.println("antibodiesAfterLastImmunityEvent: " + antibodiesAfterLastImmunityEvent); -// System.out.println("antibodies now : " + person.getAntibodyLevelAtInfection()); - + double abNoWaning = person.getMaxAntibodies(strain); // Two modifications to antibody level below: // a) we multiply the antibody level by 4 if the agent is boostered diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java index 821c38ec5..5374d9686 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -61,7 +61,7 @@ protected void configure() { if (params != null) { minDaysAfterInfection = (int) params.minDaysAfterImm; minDaysAfterVaccination = (int) params.minDaysAfterImm; - vaccinationPool = params.vacPool; +// vaccinationPool = params.vacPool; switch (params.vacCamp) { case "off": @@ -378,8 +378,8 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot -// episimConfig.setSnapshotInterval(766); -// episimConfig.setSnapshotPrefix(params.seed +"-"); + episimConfig.setSnapshotInterval(30); + episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); if (params.snp.equals("on")) { episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-10/" + params.seed + "--766-2022-03-31.zip"); episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); @@ -414,11 +414,6 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); } - // VAX - VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); - vaccinationConfig.setUseIgA(Boolean.parseBoolean("true")); - vaccinationConfig.setUseMaxAntibodiesForHospitalisation(Boolean.parseBoolean(params.maxAb)); - //--------------------------------------- // I M P O R T //--------------------------------------- @@ -656,7 +651,7 @@ else if (!params.StrainB.equals("off")) { public static final class Params { // general - @GenerateSeeds(4) + @GenerateSeeds(5) public long seed; // @StringParameter({"true", "false"}) @@ -665,20 +660,16 @@ public static final class Params { @StringParameter({"off"}) public String snp; - @StringParameter({"true", "false"}) + @StringParameter({"false"}) public String immResp; - @StringParameter({"true", "false"}) - public String maxAb; - - - @StringParameter({"off", "on", "emergency"}) + @StringParameter({"off"}) String vacCamp; - @EnumParameter(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.class) - VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vacPool; +// @EnumParameter(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.class) +// VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vacPool; - @Parameter({0., 90., 180.}) + @Parameter({180.}) public double minDaysAfterImm; // @Parameter({4., 5., 6., 7., 8., 9., 10.}) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java new file mode 100644 index 000000000..b62b77d34 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java @@ -0,0 +1,768 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.FilterEvents; +import org.matsim.episim.analysis.HospitalNumbersFromEvents; +import org.matsim.episim.analysis.OutputAnalysis; +import org.matsim.episim.analysis.RValuesFromEvents; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF202210XX_vaccination implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // VACCINATION MODEL + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + // fixed values + LocalDate start = LocalDate.parse("2022-10-15"); + VaccinationType vaccinationType = VaccinationType.ba5Update; + int campaignDuration = 300000; + + // default values, to be changed if params != null + int minDaysAfterInfection = 180; + int minDaysAfterVaccination = 180; + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered; + LocalDate emergencyDate = LocalDate.MAX; + Map startDateToVaccination = new HashMap<>(); + + if (params != null) { + minDaysAfterInfection = (int) params.minDaysAfterImm; + minDaysAfterVaccination = (int) params.minDaysAfterImm; + vaccinationPool = params.vacPool; + + switch (params.vacCamp) { + case "off": + + startDateToVaccination.put(LocalDate.MAX, vaccinationType); + + break; + case "on": + + startDateToVaccination.put(start, vaccinationType); + + break; + case "emergency": + startDateToVaccination.put(start, vaccinationType); + emergencyDate = LocalDate.parse("2022-12-01"); + break; + default: + throw new RuntimeException(); + } + } + + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate)); + + + // ANTIBODY MODEL + // default values + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 5.0; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + + if (params != null) { +// mutEscBa1 = params.ba1Esc; +// mutEscBa5 = params.ba5Esc; + + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!params.StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(params.StrainB); + } + + } + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean(params.immResp)); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + + // HOUSEHOLD SUSCEPTIBILITY + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(0.35, 0.01) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( +// new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), +// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + //snapshot +// episimConfig.setSnapshotInterval(766); +// episimConfig.setSnapshotPrefix(params.seed +"-"); + if (params.snp.equals("on")) { + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-10/" + params.seed + "--766-2022-03-31.zip"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + } + + + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); + } + +// STRAIN_B + if (!params.StrainB.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); + } + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + configureFutureDiseaseImport(params, episimConfig); + + // modify import: + LocalDate impModDate = LocalDate.parse("2022-01-31"); + double impRedBa1 = 0.0; + double impRedBa2 = 0.0; + if (impRedBa1 != 1.0) { + NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); + for (Map.Entry entry : impBa1.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); + } + } + } + + if (impRedBa2 != 1.0) { + NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); + for (Map.Entry entry : impBa2.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); + } + } + } + + + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + LocalDate restrictionDate = LocalDate.parse(params.resDate); + + //work + double homeOfficeFactor = 0.5; + switch (params.work) { + case "base": + break; + case "half": + builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure public + switch (params.leisPublic) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); + break; + case "zero": + builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); + break; + case "half": + builder.restrict(restrictionDate, 0.76 * 0.5, "leisPublic"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPublic"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure private + switch (params.leisPrivate) { + case "base": + break; + case "half": + builder.restrict(restrictionDate, 0.76 * 0.5, "leisPrivate"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // shop, errands + switch (params.errands) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //school + switch (params.edu) { + case "base": + break; + case "mask": + builder.restrict(restrictionDate, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other"); + break; + case "half": + builder.restrict(restrictionDate, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // Ci Correction after summer vacation 2022 (more air flow?) +// builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), params.eduRfVacation, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + + // modify seasonality +// episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); +// episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB + if (!params.StrainB.equals("off")) { + infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strBDate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrB.put(strBDate.plusDays(i), 4); + } + infPerDayStrB.put(strBDate.plusDays(7), 1); + } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + + String importSummer2022 = "off"; + if (importSummer2022.equals("on")) { + NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); + LocalDate date = null; + for (Map.Entry entry : data.entrySet()) { + date = entry.getKey(); + double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// + double cases = factor * entry.getValue(); + + if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { + if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); + } + else if (!params.StrainA.equals("off")) { + infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else if (!params.StrainB.equals("off")) { + infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); + } + else { + throw new RuntimeException(); + } + infPerDayBa5.put(date, 1); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa5)) { + infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); + infPerDayBa2.put(date, 1); + } else if (date.isAfter(dateBa2)) { + infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); + } + + } + } else if (importSummer2022.equals("off")) { + } else { + throw new RuntimeException(); + } + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } + if (!params.StrainB.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); + } + } + + public static final class Params { + // general + @GenerateSeeds(4) + public long seed; + +// @StringParameter({"true", "false"}) +// public String useIgA; + + @StringParameter({"off"}) + public String snp; + + @StringParameter({"true", "false"}) + public String immResp; + + @StringParameter({"true", "false"}) + public String maxAb; + + + @StringParameter({"off", "on", "emergency"}) + String vacCamp; + + @EnumParameter(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.class) + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vacPool; + + @Parameter({0., 90., 180.}) + public double minDaysAfterImm; + +// @Parameter({4., 5., 6., 7., 8., 9., 10.}) +// public double ba1Esc; + +// @Parameter({5.}) +// public double ba5Esc; + +// @Parameter({0.0}) +// public double impRedBa1; + +// @Parameter({0.0}) +// public double impRedBa2; + + + + // NEW RESTRICTIONS + @StringParameter({"2022-12-15"}) + public String resDate; + + //measures in the work context: + // homeOff = 50% home office = work Rf cut in half + // + @StringParameter({"base"}) + public String work; + + // leisure Public + @StringParameter({"base"}) + public String leisPublic; + + // leisure Private + @StringParameter({"base"}) + public String leisPrivate; + + // mask restrictions for "shop_daily", "shop_other", "errands" + @StringParameter({"base"}) + public String errands; + + //edu + @StringParameter({"base"}) + public String edu; + +// @StringParameter({"off"}) +// public String importSummer2022; + +// @Parameter({0.5}) +// public double eduSeasonality; + + // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow +// @Parameter({0.75}) +// public double ciCorr; + + //how much "school" activity takes places during vacation summmer 2022 + + @Parameter({ 0.8}) + public double eduRfVacation; + + + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"6.0"}) + public String StrainA; + +// @StringParameter({"off", "3.0", "6.0"}) + @StringParameter({"off"}) + public String StrainB; + + + + + // vaccination campaign +// @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) +// @StringParameter({"off"}) +// public String vacType; + + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF202210XX_vaccination.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + From ee74493c22f27de9ac20641d9be4150c2d2e1c4a Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 14 Oct 2022 18:14:30 +0200 Subject: [PATCH 084/128] batches for jakob/2022-10-14/3-meas --- .../analysis/HospitalNumbersFromEvents.java | 23 +- ...ccinationStrategyReoccurringCampaigns.java | 5 +- .../batch/CologneBMBF202210XX_SNAPSHOT.java | 2 - .../batch/CologneBMBF202210XX_measures.java | 679 ++++++++++++++++++ 4 files changed, 696 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 37835de03..7f3fcb8a8 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,7 +60,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/qqq") + @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-10-14/1-vac/analysis") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -161,12 +161,17 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double factorDelta = 1.2 * factorWild;//1.6 * factorWild; // omicron: approx 0.3x (intrinsic) severity of delta - Comparative analysis of the risks of hospitalisation and death associated with SARS-CoV-2 omicron (B.1.1.529) and delta (B.1.617.2) variants in England: a cohort study - private static final double factorOmicron = 0.3 * factorDelta; // reportedShareOmicron / reportedShareDelta -// private static final double factorOmicron = 0.6 * factorDelta; // reportedShareOmicron / reportedShareDelta +// private static final double factorOmicron = 0.3 * factorDelta; // reportedShareOmicron / reportedShareDelta + private static final double factorOmicron = 0.6 * factorDelta;// reportedShareOmicron / reportedShareDelta -// private static final double factorBA5 = 1.0 * factorOmicron; private static final double factorBA5 = 1.5 * factorOmicron; + private static final double factorScen2 = factorBA5;// reportedShareOmicron / reportedShareDelta + private static final double factorScen3 = factorBA5 * 3;// reportedShareOmicron / reportedShareDelta + + +// private static final double factorBA5 = 1.0 * factorOmicron; + // ?? @@ -216,8 +221,8 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); + HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); @@ -259,13 +264,13 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t BufferedWriter bw = Files.newBufferedWriter(tsvPath); bw.write(AnalysisCommand.TSV.join(DAY, DATE,"measurement", "severity", "n")); // + "\thospNoImmunity\thospBaseImmunity\thospBoosted\tincNoImmunity\tincBaseImmunity\tincBoosted")); - ConfigHolder holderOmicron = configure(factorBA5, factorBA5ICU); - ConfigHolder holderDelta = configure(factorDelta, factorDeltaICU); + ConfigHolder holderOmicron = configure(factorScen2, 1.0); // scenario 2 + ConfigHolder holderDelta = configure(factorScen3, 1.0); //scenario 3 List handlers = List.of( new Handler("Omicron", population, holderOmicron, 0.0), new Handler("Delta", population, holderDelta, 0.0) -// new Handler("Omicron-Paxlovid-0.25", population, holderOmicron, 0.25), +// new Handler("Omicron-Paxlovid-0.25 ", population, holderOmicron, 0.25), // new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), // new Handler("Omicron-Paxlovid-0.50", population, holderOmicron, 0.5), // new Handler("Delta-Paxlovid-0.50", population, holderDelta, 0.5), diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java index 60ab7bf65..154c56502 100644 --- a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java @@ -52,7 +52,7 @@ public VaccinationStrategyReoccurringCampaigns(SplittableRandom rnd, Config conf } // calculate total number of vaccinations: - dailyVaccinationsToBeDistributed = 10_000 / 4 ; + dailyVaccinationsToBeDistributed = 1_500 / 4; } @@ -84,6 +84,7 @@ public void handleVaccination(Map, EpisimPerson> persons, LocalDate d .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > config.minDaysAfterVaccination) // only people who've had their last vaccination more than 90 days ago .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > config.minDaysAfterInfection) // only people who've had their last vaccination more than 90 days ago .filter(p -> date.isAfter(config.emergencyDate.minusDays(1)) ? boostBa5Emergency.contains(p.getPersonId()) : boostBa5Yes.contains(p.getPersonId())) + .filter(p -> !p.hadVaccinationType(vaccinationType)) // todo remove in future .collect(Collectors.toList()); @@ -91,7 +92,7 @@ public void handleVaccination(Map, EpisimPerson> persons, LocalDate d // create vaccinations-remaining counter for current day int vaccinationsLeft = this.dailyVaccinationsToBeDistributed; if (date.isAfter(config.emergencyDate.minusDays(1))) { - vaccinationsLeft *= 2; + vaccinationsLeft *= 10; } // list is shuffled to avoid eventual bias diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java index 5374d9686..82f5e8a49 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -385,8 +385,6 @@ public Config prepareConfig(int id, Params params) { episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); } - - //--------------------------------------- // S T R A I N S //--------------------------------------- diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java new file mode 100644 index 000000000..1c7727f56 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java @@ -0,0 +1,679 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.DataUtils; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF202210XX_measures implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + LocalDate restrictionDateIfsg = LocalDate.parse("2022-11-15"); + LocalDate restrictionDateEmergency = restrictionDateIfsg.plusWeeks(3); + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // VACCINATION MODEL + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + // fixed values + LocalDate start = LocalDate.parse("2022-10-15"); + VaccinationType vaccinationType = VaccinationType.ba5Update; + int campaignDuration = 300000; + + // default values, to be changed if params != null + int minDaysAfterInfection = 180; + int minDaysAfterVaccination = 180; + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated; + LocalDate emergencyDate = LocalDate.MAX; + Map startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(start, vaccinationType); + + if (params != null) { + if (params.vacCamp.equals("base")) { + + } else if(params.vacCamp.equals("ifsg90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("ifsg180")){ + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("emergency90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + emergencyDate = restrictionDateEmergency; + } else if(params.vacCamp.equals("emergency180")) { + emergencyDate = restrictionDateEmergency; + }else { + throw new RuntimeException(); + } + } + + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate)); + + + // ANTIBODY MODEL + // default values + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 5.0; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + + if (params != null) { +// mutEscBa1 = params.ba1Esc; +// mutEscBa5 = params.ba5Esc; + +// String StrainA = "6.0"; + String StrainB = "off"; + + + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(StrainB); + } + + } + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean("false")); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + + // HOUSEHOLD SUSCEPTIBILITY + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(0.35, 0.01) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + //snapshot +// episimConfig.setSnapshotInterval(30); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-14/" + params.seed + "-2022-09-11"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); + } + +// STRAIN_B +// if (!params.StrainB.equals("off")) { +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); +// } + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + configureFutureDiseaseImport(params, episimConfig); + + // modify import: + LocalDate impModDate = LocalDate.parse("2022-01-31"); + double impRedBa1 = 0.0; + double impRedBa2 = 0.0; + if (impRedBa1 != 1.0) { + NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); + for (Map.Entry entry : impBa1.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); + } + } + } + + if (impRedBa2 != 1.0) { + NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); + for (Map.Entry entry : impBa2.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); + } + } + } + + + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + + + //ifsg + if ("base".equals(params.ifsg)) { + + } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { + double compliance = Double.parseDouble(params.ifsg) / 100.; + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, compliance)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + } else { + throw new RuntimeException(); + } + + // EMERGENCY RESTRICTIONS + //work + builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); + double homeOfficeFactor = 0.5; + switch (params.work) { + case "base": + break; + case "half": + builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "mask": + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure public + private + switch (params.leis) { + case "base": + break; + case "pub50": + builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic"); + break; + case "pubPriv50": + builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic", "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //school + switch (params.edu) { + case "base": + break; + case "mask": + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + case "half&mask": + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + + builder.restrict(restrictionDateEmergency, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB +// if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strBDate = LocalDate.parse("2022-11-01"); +// for (int i = 0; i < 7; i++) { +// infPerDayStrB.put(strBDate.plusDays(i), 4); +// } +// infPerDayStrB.put(strBDate.plusDays(7), 1); +// } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + +// String importSummer2022 = "off"; +// if (importSummer2022.equals("on")) { +// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); +// LocalDate date = null; +// for (Map.Entry entry : data.entrySet()) { +// date = entry.getKey(); +// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +//// +// double cases = factor * entry.getValue(); +// +// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { +// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// } +// else if (!params.StrainA.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else { +// throw new RuntimeException(); +// } +// infPerDayBa5.put(date, 1); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa5)) { +// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa2)) { +// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); +// } +// +// } +// } else if (importSummer2022.equals("off")) { +// } else { +// throw new RuntimeException(); +// } + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } +// if (!params.StrainB.equals("off")) { +// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); +// } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + //IFSG + @StringParameter({"base","45", "90"}) + public String ifsg; + + // Vacciantion Campaign + @StringParameter({"base", "ifsg90", "ifsg180", "emergency90", "emergency180"}) + String vacCamp; + + // NEW RESTRICTIONS + @StringParameter({"base", "half", "mask"}) + public String work; + + // leisure Public + @StringParameter({"base","pubPriv50", "pub50"}) + public String leis; + + //edu + @StringParameter({"base", "half&mask", "mask"}) + public String edu; + + @StringParameter({"6.0"}) + public String StrainA; + + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF202210XX_measures.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + From 7a386e049188c2c6d7dc13c4bd662a3774323003 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 18 Oct 2022 12:04:00 +0200 Subject: [PATCH 085/128] new runs --- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../batch/CologneBMBF202210XX_SNAPSHOT.java | 382 +++++++---------- .../batch/CologneBMBF202210XX_measures.java | 20 +- .../CologneBMBF202210XX_vaccination.java | 398 +++++++----------- 4 files changed, 324 insertions(+), 480 deletions(-) diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 1558adfc1..5ff87582f 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_SNAPSHOT") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_vaccination") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_SNAPSHOT$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_vaccination$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java index 82f5e8a49..f8d163db1 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -5,18 +5,16 @@ import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; import com.google.inject.util.Modules; -import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; -import it.unimi.dsi.fastutil.ints.Int2DoubleMap; -import it.unimi.dsi.fastutil.objects.Object2DoubleAVLTreeMap; -import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.*; +import org.matsim.episim.BatchRun; +import org.matsim.episim.DataUtils; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; import org.matsim.episim.model.listener.HouseholdSusceptibility; import org.matsim.episim.model.vaccination.VaccinationModel; -import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; import org.matsim.episim.policy.FixedPolicy; import org.matsim.episim.policy.Restriction; @@ -36,6 +34,9 @@ public class CologneBMBF202210XX_SNAPSHOT implements BatchRun startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(start, vaccinationType); if (params != null) { - minDaysAfterInfection = (int) params.minDaysAfterImm; - minDaysAfterVaccination = (int) params.minDaysAfterImm; -// vaccinationPool = params.vacPool; - - switch (params.vacCamp) { - case "off": - - startDateToVaccination.put(LocalDate.MAX, vaccinationType); - - break; - case "on": - - startDateToVaccination.put(start, vaccinationType); - - break; - case "emergency": - startDateToVaccination.put(start, vaccinationType); - emergencyDate = LocalDate.parse("2022-12-01"); - break; - default: - throw new RuntimeException(); + if (params.vacCamp.equals("base")) { + + } else if(params.vacCamp.equals("ifsg90")){ // wrong + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("ifsg180")){ // right + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("emergency90")){ // this is right + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + emergencyDate = restrictionDateEmergency; + } else if(params.vacCamp.equals("emergency180")) { // this is wrong + emergencyDate = restrictionDateEmergency; + }else { + throw new RuntimeException(); } } @@ -100,11 +98,15 @@ protected void configure() { // mutEscBa1 = params.ba1Esc; // mutEscBa5 = params.ba5Esc; +// String StrainA = "6.0"; + String StrainB = "off"; + + if (!params.StrainA.equals("off")) { mutEscStrainA = Double.parseDouble(params.StrainA); } - if (!params.StrainB.equals("off")) { - mutEscStrainB = Double.parseDouble(params.StrainB); + if (!StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(StrainB); } } @@ -119,7 +121,7 @@ protected void configure() { double immuneSigma = 3.0; if (params != null) { antibodyConfig.setImmuneReponseSigma(immuneSigma); - antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean(params.immResp)); + antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean("false")); } bind(AntibodyModel.Config.class).toInstance(antibodyConfig); @@ -348,10 +350,10 @@ public Metadata getMetadata() { public Collection postProcessing() { return List.of( // new VaccinationEffectiveness().withArgs(), - new RValuesFromEvents().withArgs(), +// new RValuesFromEvents().withArgs(), // new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new FilterEvents().withArgs("--output","./output/"), - new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new FilterEvents().withArgs("--output","./output/"), +// new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") // new SecondaryAttackRateFromEvents().withArgs() ); } @@ -360,7 +362,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -380,10 +382,8 @@ public Config prepareConfig(int id, Params params) { //snapshot episimConfig.setSnapshotInterval(30); episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - if (params.snp.equals("on")) { - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-10/" + params.seed + "--766-2022-03-31.zip"); - episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - } +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-14/" + params.seed + "-930-2022-09-11.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- // S T R A I N S @@ -404,13 +404,13 @@ public Config prepareConfig(int id, Params params) { } // STRAIN_B - if (!params.StrainB.equals("off")) { - - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); - } +// if (!params.StrainB.equals("off")) { +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); +// } //--------------------------------------- // I M P O R T @@ -448,61 +448,51 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - LocalDate restrictionDate = LocalDate.parse(params.resDate); + + //ifsg + if ("base".equals(params.ifsg)) { + + } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { + double compliance = Double.parseDouble(params.ifsg) / 100.; + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, compliance)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "pt"); + } else { + throw new RuntimeException(); + } + + // EMERGENCY RESTRICTIONS //work + builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); double homeOfficeFactor = 0.5; switch (params.work) { case "base": break; case "half": - builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); break; case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "work", "business"); + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); break; default: throw new RuntimeException("invalid parameter"); } - // leisure public - switch (params.leisPublic) { + // leisure public + private + switch (params.leis) { case "base": break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); - break; - case "zero": - builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); + case "pub50": + builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic"); break; - case "half": - builder.restrict(restrictionDate, 0.76 * 0.5, "leisPublic"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPublic"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // leisure private - switch (params.leisPrivate) { - case "base": - break; - case "half": - builder.restrict(restrictionDate, 0.76 * 0.5, "leisPrivate"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPrivate"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // shop, errands - switch (params.errands) { - case "base": - break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + case "pubPriv50": + builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic", "leisPrivate"); break; default: throw new RuntimeException("invalid parameter"); @@ -513,25 +503,28 @@ public Config prepareConfig(int id, Params params) { case "base": break; case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of( + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other"); + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); break; - case "half": - builder.restrict(restrictionDate, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + case "half&mask": + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + + builder.restrict(restrictionDateEmergency, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); break; default: throw new RuntimeException("invalid parameter"); } - // Ci Correction after summer vacation 2022 (more air flow?) -// builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - // vary amount of "school" activity that takes place during vacation - builder.restrict(LocalDate.parse("2022-06-27"), params.eduRfVacation, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); episimConfig.setPolicy(builder.build()); @@ -541,15 +534,6 @@ public Config prepareConfig(int id, Params params) { //--------------------------------------- - // modify seasonality -// episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); - - if (DEBUG_MODE) { UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); } @@ -575,63 +559,63 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } //StrainB - if (!params.StrainB.equals("off")) { - infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strBDate = LocalDate.parse("2022-11-01"); - for (int i = 0; i < 7; i++) { - infPerDayStrB.put(strBDate.plusDays(i), 4); - } - infPerDayStrB.put(strBDate.plusDays(7), 1); - } +// if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strBDate = LocalDate.parse("2022-11-01"); +// for (int i = 0; i < 7; i++) { +// infPerDayStrB.put(strBDate.plusDays(i), 4); +// } +// infPerDayStrB.put(strBDate.plusDays(7), 1); +// } // add projected disease import for vacation waves after initial disease import - int facBa2 = 4; - int facBa5 = 4; - int facStrAB = 4; - - LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import - LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import - LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import - - String importSummer2022 = "off"; - if (importSummer2022.equals("on")) { - NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); - LocalDate date = null; - for (Map.Entry entry : data.entrySet()) { - date = entry.getKey(); - double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// int facBa2 = 4; +// int facBa5 = 4; +// int facStrAB = 4; // - double cases = factor * entry.getValue(); - - if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { - if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - } - else if (!params.StrainA.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else if (!params.StrainB.equals("off")) { - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else { - throw new RuntimeException(); - } - infPerDayBa5.put(date, 1); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa5)) { - infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa2)) { - infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); - } - - } - } else if (importSummer2022.equals("off")) { - } else { - throw new RuntimeException(); - } +// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import +// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import +// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import +// +// String importSummer2022 = "off"; +// if (importSummer2022.equals("on")) { +// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); +// LocalDate date = null; +// for (Map.Entry entry : data.entrySet()) { +// date = entry.getKey(); +// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +//// +// double cases = factor * entry.getValue(); +// +// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { +// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// } +// else if (!params.StrainA.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else { +// throw new RuntimeException(); +// } +// infPerDayBa5.put(date, 1); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa5)) { +// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa2)) { +// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); +// } +// +// } +// } else if (importSummer2022.equals("off")) { +// } else { +// throw new RuntimeException(); +// } // save disease import @@ -642,9 +626,9 @@ else if (!params.StrainB.equals("off")) { if (!params.StrainA.equals("off")) { episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); } - if (!params.StrainB.equals("off")) { - episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); - } +// if (!params.StrainB.equals("off")) { +// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); +// } } public static final class Params { @@ -652,97 +636,29 @@ public static final class Params { @GenerateSeeds(5) public long seed; -// @StringParameter({"true", "false"}) -// public String useIgA; - - @StringParameter({"off"}) - public String snp; - - @StringParameter({"false"}) - public String immResp; + //IFSG + @StringParameter({"base"}) + public String ifsg; - @StringParameter({"off"}) + // Vacciantion Campaign + @StringParameter({"base"}) String vacCamp; -// @EnumParameter(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.class) -// VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vacPool; - - @Parameter({180.}) - public double minDaysAfterImm; - -// @Parameter({4., 5., 6., 7., 8., 9., 10.}) -// public double ba1Esc; - -// @Parameter({5.}) -// public double ba5Esc; - -// @Parameter({0.0}) -// public double impRedBa1; - -// @Parameter({0.0}) -// public double impRedBa2; - - - // NEW RESTRICTIONS - @StringParameter({"2022-12-15"}) - public String resDate; - - //measures in the work context: - // homeOff = 50% home office = work Rf cut in half - // @StringParameter({"base"}) public String work; // leisure Public @StringParameter({"base"}) - public String leisPublic; - - // leisure Private - @StringParameter({"base"}) - public String leisPrivate; - - // mask restrictions for "shop_daily", "shop_other", "errands" - @StringParameter({"base"}) - public String errands; + public String leis; //edu @StringParameter({"base"}) public String edu; -// @StringParameter({"off"}) -// public String importSummer2022; - -// @Parameter({0.5}) -// public double eduSeasonality; - - // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow -// @Parameter({0.75}) -// public double ciCorr; - - //how much "school" activity takes places during vacation summmer 2022 - - @Parameter({ 0.8}) - public double eduRfVacation; - - - -// @StringParameter({"off", "3.0", "6.0"}) @StringParameter({"6.0"}) public String StrainA; -// @StringParameter({"off", "3.0", "6.0"}) - @StringParameter({"off"}) - public String StrainB; - - - - - // vaccination campaign -// @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) -// @StringParameter({"off"}) -// public String vacType; - } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java index 1c7727f56..f556c666f 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java @@ -67,6 +67,9 @@ protected void configure() { minDaysAfterInfection = 90; minDaysAfterVaccination = 90; + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("ifsg90vax180")){ + minDaysAfterInfection = 90; emergencyDate = restrictionDateIfsg; } else if(params.vacCamp.equals("ifsg180")){ emergencyDate = restrictionDateIfsg; @@ -74,6 +77,9 @@ protected void configure() { minDaysAfterInfection = 90; minDaysAfterVaccination = 90; emergencyDate = restrictionDateEmergency; + } else if(params.vacCamp.equals("emergency90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDateEmergency; } else if(params.vacCamp.equals("emergency180")) { emergencyDate = restrictionDateEmergency; }else { @@ -362,7 +368,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -382,7 +388,7 @@ public Config prepareConfig(int id, Params params) { //snapshot // episimConfig.setSnapshotInterval(30); // episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-14/" + params.seed + "-2022-09-11"); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-930-2022-09-11.zip"); episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- @@ -461,6 +467,7 @@ public Config prepareConfig(int id, Params params) { "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way } else { throw new RuntimeException(); } @@ -476,7 +483,10 @@ public Config prepareConfig(int id, Params params) { builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); break; - case "mask": + case "half&mask": + builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); break; default: @@ -640,11 +650,11 @@ public static final class Params { public String ifsg; // Vacciantion Campaign - @StringParameter({"base", "ifsg90", "ifsg180", "emergency90", "emergency180"}) + @StringParameter({"base", "ifsg90vax180", "ifsg180", "emergency180", "emergency90vax180"}) String vacCamp; // NEW RESTRICTIONS - @StringParameter({"base", "half", "mask"}) + @StringParameter({"base", "half", "half&mask"}) public String work; // leisure Public diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java index b62b77d34..424a0a740 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java @@ -7,11 +7,11 @@ import com.google.inject.util.Modules; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.*; -import org.matsim.episim.analysis.FilterEvents; -import org.matsim.episim.analysis.HospitalNumbersFromEvents; -import org.matsim.episim.analysis.OutputAnalysis; -import org.matsim.episim.analysis.RValuesFromEvents; +import org.matsim.episim.BatchRun; +import org.matsim.episim.DataUtils; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; import org.matsim.episim.model.listener.HouseholdSusceptibility; import org.matsim.episim.model.vaccination.VaccinationModel; @@ -34,6 +34,9 @@ public class CologneBMBF202210XX_vaccination implements BatchRun startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(start, vaccinationType); if (params != null) { - minDaysAfterInfection = (int) params.minDaysAfterImm; - minDaysAfterVaccination = (int) params.minDaysAfterImm; - vaccinationPool = params.vacPool; - - switch (params.vacCamp) { - case "off": - - startDateToVaccination.put(LocalDate.MAX, vaccinationType); - - break; - case "on": - - startDateToVaccination.put(start, vaccinationType); - - break; - case "emergency": - startDateToVaccination.put(start, vaccinationType); - emergencyDate = LocalDate.parse("2022-12-01"); - break; - default: - throw new RuntimeException(); + if (params.vacCamp.equals("base")) { + + } else if(params.vacCamp.equals("ifsg90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("ifsg90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("ifsg180")){ + emergencyDate = restrictionDateIfsg; + } else if(params.vacCamp.equals("emergency90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + emergencyDate = restrictionDateEmergency; + } else if(params.vacCamp.equals("emergency90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDateEmergency; + } else if(params.vacCamp.equals("emergency180")) { + emergencyDate = restrictionDateEmergency; + }else { + throw new RuntimeException(); } } @@ -98,11 +104,15 @@ protected void configure() { // mutEscBa1 = params.ba1Esc; // mutEscBa5 = params.ba5Esc; +// String StrainA = "6.0"; + String StrainB = "off"; + + if (!params.StrainA.equals("off")) { mutEscStrainA = Double.parseDouble(params.StrainA); } - if (!params.StrainB.equals("off")) { - mutEscStrainB = Double.parseDouble(params.StrainB); + if (!StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(StrainB); } } @@ -117,7 +127,7 @@ protected void configure() { double immuneSigma = 3.0; if (params != null) { antibodyConfig.setImmuneReponseSigma(immuneSigma); - antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean(params.immResp)); + antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean("false")); } bind(AntibodyModel.Config.class).toInstance(antibodyConfig); @@ -345,9 +355,9 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( -// new VaccinationEffectiveness().withArgs(), + new VaccinationEffectiveness().withArgs(), new RValuesFromEvents().withArgs(), -// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), new FilterEvents().withArgs("--output","./output/"), new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") // new SecondaryAttackRateFromEvents().withArgs() @@ -358,7 +368,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -376,14 +386,10 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot -// episimConfig.setSnapshotInterval(766); -// episimConfig.setSnapshotPrefix(params.seed +"-"); - if (params.snp.equals("on")) { - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-10/" + params.seed + "--766-2022-03-31.zip"); - episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - } - - +// episimConfig.setSnapshotInterval(30); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-930-2022-09-11.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- // S T R A I N S @@ -404,13 +410,13 @@ public Config prepareConfig(int id, Params params) { } // STRAIN_B - if (!params.StrainB.equals("off")) { - - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); - } +// if (!params.StrainB.equals("off")) { +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); +// } //--------------------------------------- // I M P O R T @@ -448,61 +454,51 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - LocalDate restrictionDate = LocalDate.parse(params.resDate); + + //ifsg + if ("base".equals(params.ifsg)) { + + } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { + double compliance = Double.parseDouble(params.ifsg) / 100.; + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, compliance)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way + } else { + throw new RuntimeException(); + } + + // EMERGENCY RESTRICTIONS //work + builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); double homeOfficeFactor = 0.5; switch (params.work) { case "base": break; case "half": - builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); - break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "work", "business"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // leisure public - switch (params.leisPublic) { - case "base": + builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); break; case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); - break; - case "zero": - builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); - break; - case "half": - builder.restrict(restrictionDate, 0.76 * 0.5, "leisPublic"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPublic"); + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); break; default: throw new RuntimeException("invalid parameter"); } - // leisure private - switch (params.leisPrivate) { + // leisure public + private + switch (params.leis) { case "base": break; - case "half": - builder.restrict(restrictionDate, 0.76 * 0.5, "leisPrivate"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPrivate"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // shop, errands - switch (params.errands) { - case "base": + case "pub50": + builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic"); break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); + case "pubPriv50": + builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic", "leisPrivate"); break; default: throw new RuntimeException("invalid parameter"); @@ -513,25 +509,28 @@ public Config prepareConfig(int id, Params params) { case "base": break; case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of( + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other"); + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); break; - case "half": - builder.restrict(restrictionDate, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + case "half&mask": + builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + + builder.restrict(restrictionDateEmergency, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); break; default: throw new RuntimeException("invalid parameter"); } - // Ci Correction after summer vacation 2022 (more air flow?) -// builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - // vary amount of "school" activity that takes place during vacation - builder.restrict(LocalDate.parse("2022-06-27"), params.eduRfVacation, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); episimConfig.setPolicy(builder.build()); @@ -541,15 +540,6 @@ public Config prepareConfig(int id, Params params) { //--------------------------------------- - // modify seasonality -// episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); -// episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); - - if (DEBUG_MODE) { UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); } @@ -575,63 +565,63 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } //StrainB - if (!params.StrainB.equals("off")) { - infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strBDate = LocalDate.parse("2022-11-01"); - for (int i = 0; i < 7; i++) { - infPerDayStrB.put(strBDate.plusDays(i), 4); - } - infPerDayStrB.put(strBDate.plusDays(7), 1); - } +// if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strBDate = LocalDate.parse("2022-11-01"); +// for (int i = 0; i < 7; i++) { +// infPerDayStrB.put(strBDate.plusDays(i), 4); +// } +// infPerDayStrB.put(strBDate.plusDays(7), 1); +// } // add projected disease import for vacation waves after initial disease import - int facBa2 = 4; - int facBa5 = 4; - int facStrAB = 4; - - LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import - LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import - LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import - - String importSummer2022 = "off"; - if (importSummer2022.equals("on")) { - NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); - LocalDate date = null; - for (Map.Entry entry : data.entrySet()) { - date = entry.getKey(); - double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +// int facBa2 = 4; +// int facBa5 = 4; +// int facStrAB = 4; // - double cases = factor * entry.getValue(); - - if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { - if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - } - else if (!params.StrainA.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else if (!params.StrainB.equals("off")) { - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else { - throw new RuntimeException(); - } - infPerDayBa5.put(date, 1); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa5)) { - infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa2)) { - infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); - } - - } - } else if (importSummer2022.equals("off")) { - } else { - throw new RuntimeException(); - } +// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import +// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import +// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import +// +// String importSummer2022 = "off"; +// if (importSummer2022.equals("on")) { +// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); +// LocalDate date = null; +// for (Map.Entry entry : data.entrySet()) { +// date = entry.getKey(); +// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +//// +// double cases = factor * entry.getValue(); +// +// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { +// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// } +// else if (!params.StrainA.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else { +// throw new RuntimeException(); +// } +// infPerDayBa5.put(date, 1); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa5)) { +// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa2)) { +// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); +// } +// +// } +// } else if (importSummer2022.equals("off")) { +// } else { +// throw new RuntimeException(); +// } // save disease import @@ -642,111 +632,39 @@ else if (!params.StrainB.equals("off")) { if (!params.StrainA.equals("off")) { episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); } - if (!params.StrainB.equals("off")) { - episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); - } +// if (!params.StrainB.equals("off")) { +// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); +// } } public static final class Params { // general - @GenerateSeeds(4) + @GenerateSeeds(5) public long seed; -// @StringParameter({"true", "false"}) -// public String useIgA; - - @StringParameter({"off"}) - public String snp; - - @StringParameter({"true", "false"}) - public String immResp; + //IFSG + @StringParameter({"base","45", "90"}) + public String ifsg; - @StringParameter({"true", "false"}) - public String maxAb; - - - @StringParameter({"off", "on", "emergency"}) + // Vacciantion Campaign + @StringParameter({"base", "ifsg90","ifsg90vax180", "ifsg180", "emergency90", "emergency180", "emergency90vax180"}) String vacCamp; - @EnumParameter(VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.class) - VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vacPool; - - @Parameter({0., 90., 180.}) - public double minDaysAfterImm; - -// @Parameter({4., 5., 6., 7., 8., 9., 10.}) -// public double ba1Esc; - -// @Parameter({5.}) -// public double ba5Esc; - -// @Parameter({0.0}) -// public double impRedBa1; - -// @Parameter({0.0}) -// public double impRedBa2; - - - // NEW RESTRICTIONS - @StringParameter({"2022-12-15"}) - public String resDate; - - //measures in the work context: - // homeOff = 50% home office = work Rf cut in half - // @StringParameter({"base"}) public String work; // leisure Public @StringParameter({"base"}) - public String leisPublic; - - // leisure Private - @StringParameter({"base"}) - public String leisPrivate; - - // mask restrictions for "shop_daily", "shop_other", "errands" - @StringParameter({"base"}) - public String errands; + public String leis; //edu @StringParameter({"base"}) public String edu; -// @StringParameter({"off"}) -// public String importSummer2022; - -// @Parameter({0.5}) -// public double eduSeasonality; - - // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow -// @Parameter({0.75}) -// public double ciCorr; - - //how much "school" activity takes places during vacation summmer 2022 - - @Parameter({ 0.8}) - public double eduRfVacation; - - - -// @StringParameter({"off", "3.0", "6.0"}) @StringParameter({"6.0"}) public String StrainA; -// @StringParameter({"off", "3.0", "6.0"}) - @StringParameter({"off"}) - public String StrainB; - - - - - // vaccination campaign -// @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) -// @StringParameter({"off"}) -// public String vacType; - } From 0cdd0a1622e6b293ac07f995fa564603a38c0c02 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Tue, 18 Oct 2022 15:10:34 +0200 Subject: [PATCH 086/128] aggregate vaccination data --- src/main/python/analysis/utils.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/python/analysis/utils.py b/src/main/python/analysis/utils.py index f42ad2392..88cf77079 100644 --- a/src/main/python/analysis/utils.py +++ b/src/main/python/analysis/utils.py @@ -245,14 +245,25 @@ def aggregate_batch_run(run): with zipfile.ZipFile(zip_buffer, "w", compresslevel=9, compression=zipfile.ZIP_DEFLATED) as zInner: for filename, dfs in files.items(): + concat = pd.concat(dfs) - by_row_index = concat.groupby(concat.index) - # Ignore files that can't be aggregated - try: - means = by_row_index.mean() - except Exception as e: - continue + # Tidy data needs to be aggregated separatly + if "vaccinationsDetailed.tsv" in filename: + + grouped = concat.groupby(["day", "date", "type", "number"]) + means = grouped.agg(amount=("amount", "mean")) + means = means.reset_index() + + else: + + # Aggregate by computung the mean + try: + by_row_index = concat.groupby(concat.index) + means = by_row_index.mean() + except Exception as e: + # Ignore files that can't be aggregated + continue # attach non numeric columns without aggregating nonNumeric = dfs[0].columns.difference(means.columns) From 495782924d9975e424554161f69f45513b6aa642 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 18 Oct 2022 15:11:47 +0200 Subject: [PATCH 087/128] run jakob/2022-10-18/3-meas --- ...ccinationStrategyReoccurringCampaigns.java | 17 +++-- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../matsim/run/batch/CologneBMBF202210XX.java | 6 +- .../batch/CologneBMBF202210XX_SNAPSHOT.java | 3 +- .../batch/CologneBMBF202210XX_measures.java | 74 ++++++++++--------- .../CologneBMBF202210XX_vaccination.java | 7 +- 6 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java index 154c56502..bc17e2498 100644 --- a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java @@ -1,16 +1,12 @@ package org.matsim.episim.model.vaccination; import com.google.inject.Inject; -import it.unimi.dsi.fastutil.objects.Object2DoubleMap; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.IdSet; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Population; import org.matsim.episim.EpisimPerson; -import org.matsim.episim.EpisimReporting; import org.matsim.episim.EpisimUtils; import org.matsim.episim.model.VaccinationType; @@ -77,12 +73,19 @@ public void handleVaccination(Map, EpisimPerson> persons, LocalDate d // a) not infected at the moment // b) is either already vaccinated or boostered, depending on the configuration // c) hasn't been vaccinated in the previous 90 days + final int minDaysAfterInfection; + if (date.isBefore(config.dateToTurnDownMinDaysAfterInfectionTo90)) { + minDaysAfterInfection = config.minDaysAfterInfection; + } else { + minDaysAfterInfection = 90; + } + List candidates = persons.values().stream() .filter(EpisimPerson::isVaccinable) .filter(p -> p.getDiseaseStatus() == EpisimPerson.DiseaseStatus.susceptible) .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > config.minDaysAfterVaccination) // only people who've had their last vaccination more than 90 days ago - .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > config.minDaysAfterInfection) // only people who've had their last vaccination more than 90 days ago + .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > minDaysAfterInfection) // only people who've had their last vaccination more than 90 days ago .filter(p -> date.isAfter(config.emergencyDate.minusDays(1)) ? boostBa5Emergency.contains(p.getPersonId()) : boostBa5Yes.contains(p.getPersonId())) .filter(p -> !p.hadVaccinationType(vaccinationType)) // todo remove in future .collect(Collectors.toList()); @@ -128,6 +131,7 @@ public static class Config { private final int minDaysAfterInfection; private final LocalDate emergencyDate; + private final LocalDate dateToTurnDownMinDaysAfterInfectionTo90; public enum VaccinationPool { @@ -144,7 +148,7 @@ public enum VaccinationPool { } - public Config(Map startDateToVaccinationCampaign, int campaignDuration, VaccinationPool vaccinationPool, int minDaysAfterInfection, int minDaysAfterVaccination, LocalDate emergencyDate) { + public Config(Map startDateToVaccinationCampaign, int campaignDuration, VaccinationPool vaccinationPool, int minDaysAfterInfection, int minDaysAfterVaccination, LocalDate emergencyDate, LocalDate dateToTurnDownMinDaysAfterInfectionTo90) { this.startDateToVaccinationCampaign = startDateToVaccinationCampaign; this.campaignDuration = campaignDuration; @@ -152,6 +156,7 @@ public Config(Map startDateToVaccinationCampaign, in this.minDaysAfterInfection = minDaysAfterInfection; this.minDaysAfterVaccination = minDaysAfterVaccination; this.emergencyDate = emergencyDate; + this.dateToTurnDownMinDaysAfterInfectionTo90 = dateToTurnDownMinDaysAfterInfectionTo90; } } diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 5ff87582f..3efd951a1 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_vaccination") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_measures") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_vaccination$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_measures$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java index 28192cac9..961053b42 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java @@ -5,8 +5,6 @@ import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; import com.google.inject.util.Modules; -import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; -import it.unimi.dsi.fastutil.ints.Int2DoubleMap; import it.unimi.dsi.fastutil.objects.Object2DoubleAVLTreeMap; import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import org.matsim.core.config.Config; @@ -16,7 +14,6 @@ import org.matsim.episim.model.*; import org.matsim.episim.model.listener.HouseholdSusceptibility; import org.matsim.episim.model.vaccination.VaccinationModel; -import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF0617; import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; import org.matsim.episim.policy.FixedPolicy; import org.matsim.episim.policy.Restriction; @@ -26,7 +23,6 @@ import javax.annotation.Nullable; import java.time.LocalDate; import java.util.*; -import java.util.stream.Collectors; /** @@ -92,7 +88,7 @@ else if (params.vacCamp.equals("18plus")) { campaignDuration, vaccinationPool, 180, - 180, LocalDate.MAX)); + 180, LocalDate.MAX, LocalDate.MAX)); // ANTIBODY MODEL diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java index f8d163db1..545d95e8e 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java @@ -8,7 +8,6 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.episim.BatchRun; -import org.matsim.episim.DataUtils; import org.matsim.episim.EpisimConfigGroup; import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.analysis.*; @@ -81,7 +80,7 @@ protected void configure() { } } - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate)); + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, LocalDate.MAX)); // ANTIBODY MODEL diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java index f556c666f..690657e4c 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java @@ -8,7 +8,6 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.episim.BatchRun; -import org.matsim.episim.DataUtils; import org.matsim.episim.EpisimConfigGroup; import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.analysis.*; @@ -34,8 +33,9 @@ public class CologneBMBF202210XX_measures implements BatchRun startDateToVaccination = new HashMap<>(); startDateToVaccination.put(start, vaccinationType); if (params != null) { - if (params.vacCamp.equals("base")) { + if (params.vacCamp.equals("base")) { // + - } else if(params.vacCamp.equals("ifsg90")){ + } else if(params.vacCamp.equals("ph1_90")){ minDaysAfterInfection = 90; minDaysAfterVaccination = 90; - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("ifsg90vax180")){ + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_90vax180")){ minDaysAfterInfection = 90; - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("ifsg180")){ - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("emergency90")){ + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_180")){ // + + emergencyDate = restrictionDatePhase1; + } else if (params.vacCamp.equals("ph1_180_ph2_inf90vax180")) { + emergencyDate = restrictionDatePhase1; + dateToTurnDownMinDaysAfterInfection = restrictionDatePhase2; + // same as ifsg180 but after phase 2 date, minDaysAfterInfection = 90; + }else if(params.vacCamp.equals("ph2_90")){ minDaysAfterInfection = 90; minDaysAfterVaccination = 90; - emergencyDate = restrictionDateEmergency; - } else if(params.vacCamp.equals("emergency90vax180")){ + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_inf90vax180")){ minDaysAfterInfection = 90; - emergencyDate = restrictionDateEmergency; - } else if(params.vacCamp.equals("emergency180")) { - emergencyDate = restrictionDateEmergency; + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_180")) { + emergencyDate = restrictionDatePhase2; }else { throw new RuntimeException(); } } - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate)); + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, dateToTurnDownMinDaysAfterInfection)); // ANTIBODY MODEL @@ -388,9 +393,8 @@ public Config prepareConfig(int id, Params params) { //snapshot // episimConfig.setSnapshotInterval(30); // episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-930-2022-09-11.zip"); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - //--------------------------------------- // S T R A I N S //--------------------------------------- @@ -461,13 +465,13 @@ public Config prepareConfig(int id, Params params) { } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { double compliance = Double.parseDouble(params.ifsg) / 100.; - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of( + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, FaceMask.SURGICAL, compliance)), "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way } else { throw new RuntimeException(); } @@ -480,14 +484,14 @@ public Config prepareConfig(int id, Params params) { case "base": break; case "half": - builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); break; case "half&mask": - builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); break; default: throw new RuntimeException("invalid parameter"); @@ -498,10 +502,10 @@ public Config prepareConfig(int id, Params params) { case "base": break; case "pub50": - builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic"); + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic"); break; case "pubPriv50": - builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic", "leisPrivate"); + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic", "leisPrivate"); break; default: throw new RuntimeException("invalid parameter"); @@ -512,21 +516,21 @@ public Config prepareConfig(int id, Params params) { case "base": break; case "mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.90)), "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); break; case "half&mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.90)), "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(restrictionDateEmergency, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDatePhase2, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); break; default: throw new RuntimeException("invalid parameter"); @@ -650,7 +654,7 @@ public static final class Params { public String ifsg; // Vacciantion Campaign - @StringParameter({"base", "ifsg90vax180", "ifsg180", "emergency180", "emergency90vax180"}) + @StringParameter({"base", "ph1_180", "ph1_180_ph2_inf90vax180"}) String vacCamp; // NEW RESTRICTIONS diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java index 424a0a740..82c0c539c 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java @@ -8,7 +8,6 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.episim.BatchRun; -import org.matsim.episim.DataUtils; import org.matsim.episim.EpisimConfigGroup; import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.analysis.*; @@ -87,7 +86,7 @@ protected void configure() { } } - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate)); + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, LocalDate.MAX)); // ANTIBODY MODEL @@ -388,8 +387,8 @@ public Config prepareConfig(int id, Params params) { //snapshot // episimConfig.setSnapshotInterval(30); // episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-930-2022-09-11.zip"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- // S T R A I N S From 1da12a983cfb715882450c81a873b42cbaffc174 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 26 Oct 2022 13:20:28 +0200 Subject: [PATCH 088/128] cleanup before merge to develop --- .../analysis/HospitalNumbersFromEvents.java | 22 +- .../matsim/episim/model/AntibodyModel.java | 8 - .../episim/model/DefaultAntibodyModel.java | 10 +- ...measures.java => CologneBMBF20221024.java} | 5 +- .../matsim/run/batch/CologneBMBF202210XX.java | 741 ------------------ .../batch/CologneBMBF202210XX_SNAPSHOT.java | 679 ---------------- .../CologneBMBF202210XX_vaccination.java | 685 ---------------- 7 files changed, 5 insertions(+), 2145 deletions(-) rename src/main/java/org/matsim/run/batch/{CologneBMBF202210XX_measures.java => CologneBMBF20221024.java} (99%) delete mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java delete mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java delete mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 7f3fcb8a8..c4bbd2e76 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -59,8 +59,7 @@ ) public class HospitalNumbersFromEvents implements OutputAnalysis { -// @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-10-14/1-vac/analysis") + @CommandLine.Option(names = "--output", defaultValue = "./output/") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -405,11 +404,6 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis @Override public void handleEvent(EpisimInfectionEvent event) { -// if (!event.getPersonId().toString().equals("12102f5")) -// return; - //System.out.println(event.getTime() / 86400. + " " + event.getVirusStrain()); - - ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); @@ -580,12 +574,7 @@ private boolean goToHospital(ImmunizablePerson person, int day) { double ageFactor = transitionModel.getProbaOfTransitioningToSeriouslySick(person); double strainFactor = holder.strainConfig.getParams(person.getVirusStrain()).getFactorSeriouslySick(); - //System.out.println("+++ day: " + day); -// //System.out.println("id: " + person.getPersonId().toString()); - //System.out.println("age factor : " + ageFactor); - //System.out.println("strain factor : " + strainFactor); double immunityFactor = transitionModel.getSeriouslySickFactor(person, holder.vaccinationConfig, day); - //System.out.println("immunity factor : " + immunityFactor); @@ -597,15 +586,6 @@ private boolean goToHospital(ImmunizablePerson person, int day) { } } - // 0.36 (old) * 1.2 (delta) * ... (immunisation) = - // if returned values (ageFactor, strainFactor, immunityFactor) are high: chance of going to hosp is high / protection is low -// System.out.println("Remaining Risk: " + (ageFactor -// * strainFactor -// * immunityFactor -// * paxlovidFactor)); - -// System.out.println(); - return rnd.nextDouble() < ageFactor * strainFactor * immunityFactor diff --git a/src/main/java/org/matsim/episim/model/AntibodyModel.java b/src/main/java/org/matsim/episim/model/AntibodyModel.java index d75a07b94..39fc90af1 100644 --- a/src/main/java/org/matsim/episim/model/AntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/AntibodyModel.java @@ -49,8 +49,6 @@ public static class Config { final Map> initialAntibodies; final Map> antibodyRefreshFactors; private double immuneReponseSigma = 0.; - private boolean useImmuneResponseForMultiplier = true; - public Config() { @@ -211,12 +209,6 @@ public void setImmuneReponseSigma(double immuneReponseSigma) { this.immuneReponseSigma = immuneReponseSigma; } - public boolean getUseImmuneResponseForMultiplier() { - return this.useImmuneResponseForMultiplier; - } - public void setUseImmuneResponseForMultiplier(boolean useImmuneResponseForMultiplier) { - this.useImmuneResponseForMultiplier = useImmuneResponseForMultiplier; - } } } diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 213e0acb4..ab70267d6 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -126,14 +126,8 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent // antibodies before refresh double antibodies = person.getAntibodies(strain2); - // refresh antibodies; ensure that antibody level does not decrease. - if (antibodyConfig.getUseImmuneResponseForMultiplier()) { - if (refreshFactor * person.getImmuneResponseMultiplier() >= 1) { - antibodies = antibodies * refreshFactor * person.getImmuneResponseMultiplier(); - } - }else { - antibodies = antibodies * refreshFactor; - } + // refresh antibodies + antibodies = antibodies * refreshFactor; // check that new antibody level at least as high as initial antibodies double initialAntibodies = antibodyConfig.initialAntibodies.get(immunityEventType).get(strain2) * person.getImmuneResponseMultiplier(); diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java b/src/main/java/org/matsim/run/batch/CologneBMBF20221024.java similarity index 99% rename from src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java rename to src/main/java/org/matsim/run/batch/CologneBMBF20221024.java index 690657e4c..798cd49e1 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_measures.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20221024.java @@ -28,7 +28,7 @@ /** * Batch for Bmbf runs */ -public class CologneBMBF202210XX_measures implements BatchRun { +public class CologneBMBF20221024 implements BatchRun { boolean DEBUG_MODE = false; int runCount = 0; @@ -132,7 +132,6 @@ protected void configure() { double immuneSigma = 3.0; if (params != null) { antibodyConfig.setImmuneReponseSigma(immuneSigma); - antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean("false")); } bind(AntibodyModel.Config.class).toInstance(antibodyConfig); @@ -678,7 +677,7 @@ public static final class Params { public static void main(String[] args) { String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202210XX_measures.class.getName(), + RunParallel.OPTION_SETUP, CologneBMBF20221024.class.getName(), RunParallel.OPTION_PARAMS, Params.class.getName(), RunParallel.OPTION_TASKS, Integer.toString(1), RunParallel.OPTION_ITERATIONS, Integer.toString(1000), diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java deleted file mode 100644 index 961053b42..000000000 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX.java +++ /dev/null @@ -1,741 +0,0 @@ -package org.matsim.run.batch; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.util.Modules; -import it.unimi.dsi.fastutil.objects.Object2DoubleAVLTreeMap; -import it.unimi.dsi.fastutil.objects.Object2DoubleMap; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.*; -import org.matsim.episim.analysis.*; -import org.matsim.episim.model.*; -import org.matsim.episim.model.listener.HouseholdSusceptibility; -import org.matsim.episim.model.vaccination.VaccinationModel; -import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; -import org.matsim.episim.policy.FixedPolicy; -import org.matsim.episim.policy.Restriction; -import org.matsim.run.RunParallel; -import org.matsim.run.modules.SnzCologneProductionScenario; - -import javax.annotation.Nullable; -import java.time.LocalDate; -import java.util.*; - - -/** - * Batch for Bmbf runs - */ -public class CologneBMBF202210XX implements BatchRun { - - boolean DEBUG_MODE = false; - int runCount = 0; - - @Nullable - @Override - public Module getBindings(int id, @Nullable Params params) { - return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { - @Override - protected void configure() { - - // VACCINATION MODEL - Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); - set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); - - // default values (if params==null) - Map startDateToVaccination = new HashMap<>(); - startDateToVaccination.put(LocalDate.parse("2022-10-01"), VaccinationType.ba5Update); - - Object2DoubleMap compliance = new Object2DoubleAVLTreeMap(); - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.0); - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.0); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.0); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); - - VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.boostered; - - int campaignDuration = 60; - - if (params != null) { - - - if (params.vacCamp.equals("60plus")) { - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.94/2); // 0.94 is boost rate July 16, 2022 - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.); - } - // assumption: older age group 2boosted first, then younger, each age group - // will have rate of 50% 2boosted by end of campaign. - // motivation: if we give both age groups same rate, then the older people - // will not be boosted as much as younger people, which seems implausible... - else if (params.vacCamp.equals("18plus")) { - compliance.put(EpisimReporting.AgeGroup.age_60_plus, 0.95/2); // boost rates as of oct 11 2022 - compliance.put(EpisimReporting.AgeGroup.age_18_59, 0.77/2); - compliance.put(EpisimReporting.AgeGroup.age_12_17, 0.36/2); - compliance.put(EpisimReporting.AgeGroup.age_0_11, 0.0); - } else if (params.vacCamp.equals("off")) { - - } else { - throw new RuntimeException("Not a valid option for vaccinationCampaignType"); - } - } - - - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, - campaignDuration, - vaccinationPool, - 180, - 180, LocalDate.MAX, LocalDate.MAX)); - - - // ANTIBODY MODEL - // default values - double mutEscDelta = 29.2 / 10.9; - double mutEscBa1 = 10.9 / 1.9; -// double mutEscBa5 = 2.9; // 0.1 -> 3.8 - double mutEscBa5 = 5.0; - - double mutEscStrainA = 0.; - double mutEscStrainB = 0.; - - if (params != null) { -// mutEscBa5 = params.ba5Esc; - - if (!params.StrainA.equals("off")) { - mutEscStrainA = Double.parseDouble(params.StrainA); - } - if (!params.StrainB.equals("off")) { - mutEscStrainB = Double.parseDouble(params.StrainB); - } - } - - //initial antibodies - Map> initialAntibodies = new HashMap<>(); - Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); - - AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); - - double immuneSigma = 3.0; - if (params != null) { - antibodyConfig.setImmuneReponseSigma(immuneSigma); - } - - bind(AntibodyModel.Config.class).toInstance(antibodyConfig); - - if (params == null) return; - - // HOUSEHOLD SUSCEPTIBILITY - // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. - bind(HouseholdSusceptibility.Config.class).toInstance( - HouseholdSusceptibility.newConfig() - .withSusceptibleHouseholds(0.35, 0.01) -// .withNonVaccinableHouseholds(params.nonVaccinableHh) -// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) -// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) - ); - - } - - private void configureAntibodies(Map> initialAntibodies, - Map> antibodyRefreshFactors, - double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { - for (VaccinationType immunityType : VaccinationType.values()) { - initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - - if (immunityType == VaccinationType.mRNA) { - initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 - } - else if (immunityType == VaccinationType.vector) { - initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 - } - else { - initialAntibodies.get(immunityType).put(virusStrain, 5.0); - } - } - } - - for (VirusStrain immunityType : VirusStrain.values()) { - initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - initialAntibodies.get(immunityType).put(virusStrain, 5.0); - } - } - - //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. - //The other values come from Rössler et al. - - //Wildtype - double mRNAAlpha = 29.2; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); - - //Alpha - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); - - //DELTA - double mRNADelta = mRNAAlpha / mutEscDelta; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); - - //BA.1 - double mRNABA1 = mRNADelta / mutEscBa1; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); - - //BA.2 - double mRNABA2 = mRNABA1; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); - - - //BA.5 - double mRNABa5 = mRNABA2 / mutEscBa5; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); - - //StrainA - double mRNAStrainA = mRNABa5 / mutEscStrainA; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); - - //StrainB - double mRNAStrainB = mRNABA2 / mutEscStrainB; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); - - - for (VaccinationType immunityType : VaccinationType.values()) { - antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - - if (immunityType == VaccinationType.mRNA) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else if (immunityType == VaccinationType.vector) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); - } - else if (immunityType == VaccinationType.ba1Update) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else if (immunityType == VaccinationType.ba5Update) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else { - antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); - } - - } - } - - for (VirusStrain immunityType : VirusStrain.values()) { - antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - } - - -// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); - - } - }); - - } - - private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { - return new SnzCologneProductionScenario.Builder() - .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) - .setSebastianUpdate(true) - .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) - .setScaleForActivityLevels(1.3) - .setSuscHouseholds_pct(pHousehold) - .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) -// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) - .setInfectionModel(InfectionModelWithAntibodies.class) - .build(); - } - - @Override - public Metadata getMetadata() { - return Metadata.of("cologne", "calibration"); - } - - @Override - public Collection postProcessing() { - return List.of( - new VaccinationEffectiveness().withArgs(), - new RValuesFromEvents().withArgs(), - new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new FilterEvents().withArgs("--output","./output/"), - new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") -// new SecondaryAttackRateFromEvents().withArgs() - ); - } - - @Override - public Config prepareConfig(int id, Params params) { - - if (DEBUG_MODE) { - if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { - runCount++; - } else { - return null; - } - } - - SnzCologneProductionScenario module = getBindings(0.0, params); - - Config config = module.config(); - - config.global().setRandomSeed(params.seed); - - EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); - - - //snapshot -// episimConfig.setSnapshotInterval(766); -// episimConfig.setSnapshotPrefix(params.seed +"-"); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-10/" + params.seed + "--766-2022-03-31.zip"); - episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - - - //--------------------------------------- - // S T R A I N S - //--------------------------------------- - - VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - - double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); - double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); - -// STRAIN_A - if (!params.StrainA.equals("off")) { - - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); - } - -// STRAIN_B - if (!params.StrainB.equals("off")) { - - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); - } - - //--------------------------------------- - // I M P O R T - //--------------------------------------- - - configureFutureDiseaseImport(params, episimConfig); - - // modify import: - LocalDate impModDate = LocalDate.parse("2022-01-31"); - if (params.impRedBa1 != 1.0) { - NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); - for (Map.Entry entry : impBa1.entrySet()) { - if (entry.getKey().isAfter(impModDate)) { - impBa1.put(entry.getKey(), (int) (entry.getValue() * params.impRedBa1)); - } - } - } - - if (params.impRedBa2 != 1.0) { - NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); - for (Map.Entry entry : impBa2.entrySet()) { - if (entry.getKey().isAfter(impModDate)) { - impBa2.put(entry.getKey(), (int) (entry.getValue() * params.impRedBa2)); - } - } - } - - //--------------------------------------- - // R E S T R I C T I O N S - //--------------------------------------- - - FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - - LocalDate restrictionDate = LocalDate.parse(params.resDate); - - //work - double homeOfficeFactor = 0.5; - switch (params.work) { - case "base": - break; - case "half": - builder.restrict(restrictionDate, 0.78 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); - break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "work", "business"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // leisure public - switch (params.leisPublic) { - case "base": - break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "leisPublic"); - break; - case "zero": - builder.restrict(restrictionDate, 0.0, "leisPublic"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> 0.0, "leisPublic"); - break; - case "half": - builder.restrict(restrictionDate, 0.76 * 0.5, "leisPublic"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPublic"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // leisure private - switch (params.leisPrivate) { - case "base": - break; - case "half": - builder.restrict(restrictionDate, 0.76 * 0.5, "leisPrivate"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> rf * 0.5, "leisPrivate"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // shop, errands - switch (params.errands) { - case "base": - break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "shop_daily", "shop_other", "errands"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - //school - switch (params.edu) { - case "base": - break; - case "mask": - builder.restrict(restrictionDate, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other"); - break; - case "half": - builder.restrict(restrictionDate, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - builder.applyToRf(restrictionDate.plusDays(1).toString(), restrictionDate.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // Ci Correction after summer vacation 2022 (more air flow?) - builder.restrict(LocalDate.parse("2022-08-09"), Restriction.ofCiCorrection(params.ciCorr), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - - // vary amount of "school" activity that takes place during vacation - builder.restrict(LocalDate.parse("2022-06-27"), params.eduRfVacation, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - episimConfig.setPolicy(builder.build()); - - - //--------------------------------------- - // M I S C - //--------------------------------------- - - - // modify seasonality - episimConfig.getOrAddContainerParams("educ_kiga").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_primary").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_secondary").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_tertiary").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_higher").setSeasonality(params.eduSeasonality); - episimConfig.getOrAddContainerParams("educ_other").setSeasonality(params.eduSeasonality); - - - if (DEBUG_MODE) { - UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); - } - - return config; - } - - private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { - Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); - Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); - Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); - Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); - Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); - - //StrainA - if (!params.StrainA.equals("off")) { - infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strADate = LocalDate.parse("2022-11-01"); - for (int i = 0; i < 7; i++) { - infPerDayStrA.put(strADate.plusDays(i), 4); - } - infPerDayStrA.put(strADate.plusDays(7), 1); - } - - //StrainB - if (!params.StrainB.equals("off")) { - infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strBDate = LocalDate.parse("2022-11-01"); - for (int i = 0; i < 7; i++) { - infPerDayStrB.put(strBDate.plusDays(i), 4); - } - infPerDayStrB.put(strBDate.plusDays(7), 1); - } - - - // add projected disease import for vacation waves after initial disease import - int facBa2 = 4; - int facBa5 = 4; - int facStrAB = 4; - - LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import - LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import - LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import - - - if (params.importSummer2022.equals("on")) { - NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); - LocalDate date = null; - for (Map.Entry entry : data.entrySet()) { - date = entry.getKey(); - double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model -// - double cases = factor * entry.getValue(); - - if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { - if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); - } - else if (!params.StrainA.equals("off")) { - infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else if (!params.StrainB.equals("off")) { - infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); - } - else { - throw new RuntimeException(); - } - infPerDayBa5.put(date, 1); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa5)) { - infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); - infPerDayBa2.put(date, 1); - } else if (date.isAfter(dateBa2)) { - infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); - } - - } - } else if (params.importSummer2022.equals("off")) { - } else { - throw new RuntimeException(); - } - - - // save disease import - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); - - if (!params.StrainA.equals("off")) { - episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); - } - if (!params.StrainB.equals("off")) { - episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); - } - } - - - - public static final class Params { - // general - @GenerateSeeds(5) - public long seed; - - @Parameter({0.0}) - public double impRedBa1; - - @Parameter({0.0}) - public double impRedBa2; - - - // NEW RESTRICTIONS - @StringParameter({"2022-11-15","2022-12-01","2022-12-15"}) - public String resDate; - - //measures in the work context: - // homeOff = 50% home office = work Rf cut in half - // - @StringParameter({"base", "half", "mask"}) - public String work; - - // leisure Public - @StringParameter({"base", "mask", "zero", "half"}) - public String leisPublic; - - // leisure Private - @StringParameter({"base", "half"}) - public String leisPrivate; - - // mask restrictions for "shop_daily", "shop_other", "errands" - @StringParameter({"base", "mask"}) - public String errands; - - //edu - @StringParameter({"base", "mask", "half"}) - public String edu; - - @StringParameter({"off"}) - public String importSummer2022; - - @Parameter({0.5}) - public double eduSeasonality; - - // ci correction of schools starting on Aug 9 (when school begins again), relates to air flow - @Parameter({0.75}) - public double ciCorr; - - //how much "school" activity takes places during vacation summmer 2022 - @Parameter({ 0.8}) - public double eduRfVacation; - - - -// @StringParameter({"off", "3.0", "6.0"}) - @StringParameter({"6.0"}) - public String StrainA; - -// @StringParameter({"off", "3.0", "6.0"}) - @StringParameter({"off"}) - public String StrainB; - - - - - // vaccination campaign -// @StringParameter({"ba1Update", "ba5Update", "mRNA", "off"}) -// @StringParameter({"off"}) -// public String vacType; - - @StringParameter({"18plus"}) -// @StringParameter({"off", "60plus", "18plus"}) - String vacCamp; - - } - - - public static void main(String[] args) { - String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202210XX.class.getName(), - RunParallel.OPTION_PARAMS, Params.class.getName(), - RunParallel.OPTION_TASKS, Integer.toString(1), - RunParallel.OPTION_ITERATIONS, Integer.toString(1000), - RunParallel.OPTION_METADATA - }; - - RunParallel.main(args2); - } - - -} - diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java deleted file mode 100644 index 545d95e8e..000000000 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_SNAPSHOT.java +++ /dev/null @@ -1,679 +0,0 @@ -package org.matsim.run.batch; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.util.Modules; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.BatchRun; -import org.matsim.episim.EpisimConfigGroup; -import org.matsim.episim.VirusStrainConfigGroup; -import org.matsim.episim.analysis.*; -import org.matsim.episim.model.*; -import org.matsim.episim.model.listener.HouseholdSusceptibility; -import org.matsim.episim.model.vaccination.VaccinationModel; -import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; -import org.matsim.episim.policy.FixedPolicy; -import org.matsim.episim.policy.Restriction; -import org.matsim.run.RunParallel; -import org.matsim.run.modules.SnzCologneProductionScenario; - -import javax.annotation.Nullable; -import java.time.LocalDate; -import java.util.*; - - -/** - * Batch for Bmbf runs - */ -public class CologneBMBF202210XX_SNAPSHOT implements BatchRun { - - boolean DEBUG_MODE = false; - int runCount = 0; - - LocalDate restrictionDateIfsg = LocalDate.parse("2022-11-15"); - LocalDate restrictionDateEmergency = restrictionDateIfsg.plusWeeks(3); - - @Nullable - @Override - public Module getBindings(int id, @Nullable Params params) { - return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { - @Override - protected void configure() { - - // VACCINATION MODEL - Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); - set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); - // fixed values - LocalDate start = LocalDate.parse("2022-10-15"); - VaccinationType vaccinationType = VaccinationType.ba5Update; - int campaignDuration = 300000; - - // default values, to be changed if params != null - int minDaysAfterInfection = 180; - int minDaysAfterVaccination = 180; - VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated; - LocalDate emergencyDate = LocalDate.MAX; - Map startDateToVaccination = new HashMap<>(); - startDateToVaccination.put(start, vaccinationType); - - if (params != null) { - if (params.vacCamp.equals("base")) { - - } else if(params.vacCamp.equals("ifsg90")){ // wrong - minDaysAfterInfection = 90; - minDaysAfterVaccination = 90; - - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("ifsg180")){ // right - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("emergency90")){ // this is right - minDaysAfterInfection = 90; - minDaysAfterVaccination = 90; - emergencyDate = restrictionDateEmergency; - } else if(params.vacCamp.equals("emergency180")) { // this is wrong - emergencyDate = restrictionDateEmergency; - }else { - throw new RuntimeException(); - } - } - - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, LocalDate.MAX)); - - - // ANTIBODY MODEL - // default values - double mutEscDelta = 29.2 / 10.9; - double mutEscBa1 = 10.9 / 1.9; - double mutEscBa5 = 5.0; - - double mutEscStrainA = 0.; - double mutEscStrainB = 0.; - - - if (params != null) { -// mutEscBa1 = params.ba1Esc; -// mutEscBa5 = params.ba5Esc; - -// String StrainA = "6.0"; - String StrainB = "off"; - - - if (!params.StrainA.equals("off")) { - mutEscStrainA = Double.parseDouble(params.StrainA); - } - if (!StrainB.equals("off")) { - mutEscStrainB = Double.parseDouble(StrainB); - } - - } - - //initial antibodies - Map> initialAntibodies = new HashMap<>(); - Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); - - AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); - - double immuneSigma = 3.0; - if (params != null) { - antibodyConfig.setImmuneReponseSigma(immuneSigma); - antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean("false")); - } - - bind(AntibodyModel.Config.class).toInstance(antibodyConfig); - - if (params == null) return; - - // HOUSEHOLD SUSCEPTIBILITY - // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. - bind(HouseholdSusceptibility.Config.class).toInstance( - HouseholdSusceptibility.newConfig() - .withSusceptibleHouseholds(0.35, 0.01) -// .withNonVaccinableHouseholds(params.nonVaccinableHh) -// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) -// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) - ); - - } - - private void configureAntibodies(Map> initialAntibodies, - Map> antibodyRefreshFactors, - double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { - for (VaccinationType immunityType : VaccinationType.values()) { - initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - - if (immunityType == VaccinationType.mRNA) { - initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 - } - else if (immunityType == VaccinationType.vector) { - initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 - } - else { - initialAntibodies.get(immunityType).put(virusStrain, 5.0); - } - } - } - - for (VirusStrain immunityType : VirusStrain.values()) { - initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - initialAntibodies.get(immunityType).put(virusStrain, 5.0); - } - } - - //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. - //The other values come from Rössler et al. - - //Wildtype - double mRNAAlpha = 29.2; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); - - //Alpha - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); - - //DELTA - double mRNADelta = mRNAAlpha / mutEscDelta; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); - - //BA.1 - double mRNABA1 = mRNADelta / mutEscBa1; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); - - //BA.2 - double mRNABA2 = mRNABA1; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); - - - //BA.5 - double mRNABa5 = mRNABA2 / mutEscBa5; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); - - //StrainA - double mRNAStrainA = mRNABa5 / mutEscStrainA; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); - - //StrainB - double mRNAStrainB = mRNABA2 / mutEscStrainB; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); - - - for (VaccinationType immunityType : VaccinationType.values()) { - antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - - if (immunityType == VaccinationType.mRNA) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else if (immunityType == VaccinationType.vector) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); - } - else if (immunityType == VaccinationType.ba1Update) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else if (immunityType == VaccinationType.ba5Update) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else { - antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); - } - - } - } - - for (VirusStrain immunityType : VirusStrain.values()) { - antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - } - - -// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); - - } - }); - - } - - private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { - return new SnzCologneProductionScenario.Builder() - .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) - .setSebastianUpdate(true) - .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) - .setScaleForActivityLevels(1.3) - .setSuscHouseholds_pct(pHousehold) - .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) -// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) - .setInfectionModel(InfectionModelWithAntibodies.class) - .build(); - } - - @Override - public Metadata getMetadata() { - return Metadata.of("cologne", "calibration"); - } - - @Override - public Collection postProcessing() { - return List.of( -// new VaccinationEffectiveness().withArgs(), -// new RValuesFromEvents().withArgs(), -// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), -// new FilterEvents().withArgs("--output","./output/"), -// new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") -// new SecondaryAttackRateFromEvents().withArgs() - ); - } - - @Override - public Config prepareConfig(int id, Params params) { - - if (DEBUG_MODE) { - if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { - runCount++; - } else { - return null; - } - } - - SnzCologneProductionScenario module = getBindings(0.0, params); - - Config config = module.config(); - - config.global().setRandomSeed(params.seed); - - EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); - - //snapshot - episimConfig.setSnapshotInterval(30); - episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-14/" + params.seed + "-930-2022-09-11.zip"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - - //--------------------------------------- - // S T R A I N S - //--------------------------------------- - - VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - - double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); - double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); - -// STRAIN_A - if (!params.StrainA.equals("off")) { - - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); - } - -// STRAIN_B -// if (!params.StrainB.equals("off")) { -// -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); -// } - - //--------------------------------------- - // I M P O R T - //--------------------------------------- - - configureFutureDiseaseImport(params, episimConfig); - - // modify import: - LocalDate impModDate = LocalDate.parse("2022-01-31"); - double impRedBa1 = 0.0; - double impRedBa2 = 0.0; - if (impRedBa1 != 1.0) { - NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); - for (Map.Entry entry : impBa1.entrySet()) { - if (entry.getKey().isAfter(impModDate)) { - impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); - } - } - } - - if (impRedBa2 != 1.0) { - NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); - for (Map.Entry entry : impBa2.entrySet()) { - if (entry.getKey().isAfter(impModDate)) { - impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); - } - } - } - - - - //--------------------------------------- - // R E S T R I C T I O N S - //--------------------------------------- - - FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - - - - //ifsg - if ("base".equals(params.ifsg)) { - - } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { - double compliance = Double.parseDouble(params.ifsg) / 100.; - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, compliance)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "pt"); - } else { - throw new RuntimeException(); - } - - // EMERGENCY RESTRICTIONS - //work - builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); - double homeOfficeFactor = 0.5; - switch (params.work) { - case "base": - break; - case "half": - builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); - break; - case "mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // leisure public + private - switch (params.leis) { - case "base": - break; - case "pub50": - builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic"); - break; - case "pubPriv50": - builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic", "leisPrivate"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - //school - switch (params.edu) { - case "base": - break; - case "mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, 0.0, - FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - break; - case "half&mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, 0.0, - FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - - builder.restrict(restrictionDateEmergency, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // vary amount of "school" activity that takes place during vacation - builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - episimConfig.setPolicy(builder.build()); - - - //--------------------------------------- - // M I S C - //--------------------------------------- - - - if (DEBUG_MODE) { - UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); - } - - return config; - } - - private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { - Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); - Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); - Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); - Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); - Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); - - //StrainA - if (!params.StrainA.equals("off")) { - infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strADate = LocalDate.parse("2022-11-01"); - for (int i = 0; i < 7; i++) { - infPerDayStrA.put(strADate.plusDays(i), 4); - } - infPerDayStrA.put(strADate.plusDays(7), 1); - } - - //StrainB -// if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); -// LocalDate strBDate = LocalDate.parse("2022-11-01"); -// for (int i = 0; i < 7; i++) { -// infPerDayStrB.put(strBDate.plusDays(i), 4); -// } -// infPerDayStrB.put(strBDate.plusDays(7), 1); -// } - - - // add projected disease import for vacation waves after initial disease import -// int facBa2 = 4; -// int facBa5 = 4; -// int facStrAB = 4; -// -// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import -// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import -// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import -// -// String importSummer2022 = "off"; -// if (importSummer2022.equals("on")) { -// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); -// LocalDate date = null; -// for (Map.Entry entry : data.entrySet()) { -// date = entry.getKey(); -// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model -//// -// double cases = factor * entry.getValue(); -// -// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { -// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// } -// else if (!params.StrainA.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else { -// throw new RuntimeException(); -// } -// infPerDayBa5.put(date, 1); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa5)) { -// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa2)) { -// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); -// } -// -// } -// } else if (importSummer2022.equals("off")) { -// } else { -// throw new RuntimeException(); -// } - - - // save disease import - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); - - if (!params.StrainA.equals("off")) { - episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); - } -// if (!params.StrainB.equals("off")) { -// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); -// } - } - - public static final class Params { - // general - @GenerateSeeds(5) - public long seed; - - //IFSG - @StringParameter({"base"}) - public String ifsg; - - // Vacciantion Campaign - @StringParameter({"base"}) - String vacCamp; - - // NEW RESTRICTIONS - @StringParameter({"base"}) - public String work; - - // leisure Public - @StringParameter({"base"}) - public String leis; - - //edu - @StringParameter({"base"}) - public String edu; - - @StringParameter({"6.0"}) - public String StrainA; - - - } - - - public static void main(String[] args) { - String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202210XX_SNAPSHOT.class.getName(), - RunParallel.OPTION_PARAMS, Params.class.getName(), - RunParallel.OPTION_TASKS, Integer.toString(1), - RunParallel.OPTION_ITERATIONS, Integer.toString(1000), - RunParallel.OPTION_METADATA - }; - - RunParallel.main(args2); - } - - -} - diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java b/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java deleted file mode 100644 index 82c0c539c..000000000 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202210XX_vaccination.java +++ /dev/null @@ -1,685 +0,0 @@ -package org.matsim.run.batch; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.util.Modules; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.BatchRun; -import org.matsim.episim.EpisimConfigGroup; -import org.matsim.episim.VirusStrainConfigGroup; -import org.matsim.episim.analysis.*; -import org.matsim.episim.model.*; -import org.matsim.episim.model.listener.HouseholdSusceptibility; -import org.matsim.episim.model.vaccination.VaccinationModel; -import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; -import org.matsim.episim.policy.FixedPolicy; -import org.matsim.episim.policy.Restriction; -import org.matsim.run.RunParallel; -import org.matsim.run.modules.SnzCologneProductionScenario; - -import javax.annotation.Nullable; -import java.time.LocalDate; -import java.util.*; - - -/** - * Batch for Bmbf runs - */ -public class CologneBMBF202210XX_vaccination implements BatchRun { - - boolean DEBUG_MODE = false; - int runCount = 0; - - LocalDate restrictionDateIfsg = LocalDate.parse("2022-11-15"); - LocalDate restrictionDateEmergency = restrictionDateIfsg.plusWeeks(3); - - @Nullable - @Override - public Module getBindings(int id, @Nullable Params params) { - return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { - @Override - protected void configure() { - - // VACCINATION MODEL - Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); - set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); - // fixed values - LocalDate start = LocalDate.parse("2022-10-15"); - VaccinationType vaccinationType = VaccinationType.ba5Update; - int campaignDuration = 300000; - - // default values, to be changed if params != null - int minDaysAfterInfection = 180; - int minDaysAfterVaccination = 180; - VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated; - LocalDate emergencyDate = LocalDate.MAX; - Map startDateToVaccination = new HashMap<>(); - startDateToVaccination.put(start, vaccinationType); - - if (params != null) { - if (params.vacCamp.equals("base")) { - - } else if(params.vacCamp.equals("ifsg90")){ - minDaysAfterInfection = 90; - minDaysAfterVaccination = 90; - - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("ifsg90vax180")){ - minDaysAfterInfection = 90; - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("ifsg180")){ - emergencyDate = restrictionDateIfsg; - } else if(params.vacCamp.equals("emergency90")){ - minDaysAfterInfection = 90; - minDaysAfterVaccination = 90; - emergencyDate = restrictionDateEmergency; - } else if(params.vacCamp.equals("emergency90vax180")){ - minDaysAfterInfection = 90; - emergencyDate = restrictionDateEmergency; - } else if(params.vacCamp.equals("emergency180")) { - emergencyDate = restrictionDateEmergency; - }else { - throw new RuntimeException(); - } - } - - bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, LocalDate.MAX)); - - - // ANTIBODY MODEL - // default values - double mutEscDelta = 29.2 / 10.9; - double mutEscBa1 = 10.9 / 1.9; - double mutEscBa5 = 5.0; - - double mutEscStrainA = 0.; - double mutEscStrainB = 0.; - - - if (params != null) { -// mutEscBa1 = params.ba1Esc; -// mutEscBa5 = params.ba5Esc; - -// String StrainA = "6.0"; - String StrainB = "off"; - - - if (!params.StrainA.equals("off")) { - mutEscStrainA = Double.parseDouble(params.StrainA); - } - if (!StrainB.equals("off")) { - mutEscStrainB = Double.parseDouble(StrainB); - } - - } - - //initial antibodies - Map> initialAntibodies = new HashMap<>(); - Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); - - AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); - - double immuneSigma = 3.0; - if (params != null) { - antibodyConfig.setImmuneReponseSigma(immuneSigma); - antibodyConfig.setUseImmuneResponseForMultiplier(Boolean.parseBoolean("false")); - } - - bind(AntibodyModel.Config.class).toInstance(antibodyConfig); - - if (params == null) return; - - // HOUSEHOLD SUSCEPTIBILITY - // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. - bind(HouseholdSusceptibility.Config.class).toInstance( - HouseholdSusceptibility.newConfig() - .withSusceptibleHouseholds(0.35, 0.01) -// .withNonVaccinableHouseholds(params.nonVaccinableHh) -// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) -// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) - ); - - } - - private void configureAntibodies(Map> initialAntibodies, - Map> antibodyRefreshFactors, - double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { - for (VaccinationType immunityType : VaccinationType.values()) { - initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - - if (immunityType == VaccinationType.mRNA) { - initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 - } - else if (immunityType == VaccinationType.vector) { - initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 - } - else { - initialAntibodies.get(immunityType).put(virusStrain, 5.0); - } - } - } - - for (VirusStrain immunityType : VirusStrain.values()) { - initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - initialAntibodies.get(immunityType).put(virusStrain, 5.0); - } - } - - //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. - //The other values come from Rössler et al. - - //Wildtype - double mRNAAlpha = 29.2; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); - - //Alpha - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); - - //DELTA - double mRNADelta = mRNAAlpha / mutEscDelta; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); - - //BA.1 - double mRNABA1 = mRNADelta / mutEscBa1; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); - - //BA.2 - double mRNABA2 = mRNABA1; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); - - - //BA.5 - double mRNABa5 = mRNABA2 / mutEscBa5; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); - - //StrainA - double mRNAStrainA = mRNABa5 / mutEscStrainA; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); - - //StrainB - double mRNAStrainB = mRNABA2 / mutEscStrainB; - initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); - initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); - initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); - initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); - initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); - initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); - initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); - initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); - initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); - initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); - initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); - - - for (VaccinationType immunityType : VaccinationType.values()) { - antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - - if (immunityType == VaccinationType.mRNA) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else if (immunityType == VaccinationType.vector) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); - } - else if (immunityType == VaccinationType.ba1Update) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else if (immunityType == VaccinationType.ba5Update) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - else { - antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); - } - - } - } - - for (VirusStrain immunityType : VirusStrain.values()) { - antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); - for (VirusStrain virusStrain : VirusStrain.values()) { - antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); - } - } - - -// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); - - } - }); - - } - - private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { - return new SnzCologneProductionScenario.Builder() - .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) - .setSebastianUpdate(true) - .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) - .setScaleForActivityLevels(1.3) - .setSuscHouseholds_pct(pHousehold) - .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) -// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) - .setInfectionModel(InfectionModelWithAntibodies.class) - .build(); - } - - @Override - public Metadata getMetadata() { - return Metadata.of("cologne", "calibration"); - } - - @Override - public Collection postProcessing() { - return List.of( - new VaccinationEffectiveness().withArgs(), - new RValuesFromEvents().withArgs(), - new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new FilterEvents().withArgs("--output","./output/"), - new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") -// new SecondaryAttackRateFromEvents().withArgs() - ); - } - - @Override - public Config prepareConfig(int id, Params params) { - - if (DEBUG_MODE) { - if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { - runCount++; - } else { - return null; - } - } - - SnzCologneProductionScenario module = getBindings(0.0, params); - - Config config = module.config(); - - config.global().setRandomSeed(params.seed); - - EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); - - //snapshot -// episimConfig.setSnapshotInterval(30); -// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); - episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - - //--------------------------------------- - // S T R A I N S - //--------------------------------------- - - VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - - double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); - double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); - -// STRAIN_A - if (!params.StrainA.equals("off")) { - - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); - } - -// STRAIN_B -// if (!params.StrainB.equals("off")) { -// -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); -// } - - //--------------------------------------- - // I M P O R T - //--------------------------------------- - - configureFutureDiseaseImport(params, episimConfig); - - // modify import: - LocalDate impModDate = LocalDate.parse("2022-01-31"); - double impRedBa1 = 0.0; - double impRedBa2 = 0.0; - if (impRedBa1 != 1.0) { - NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); - for (Map.Entry entry : impBa1.entrySet()) { - if (entry.getKey().isAfter(impModDate)) { - impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); - } - } - } - - if (impRedBa2 != 1.0) { - NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); - for (Map.Entry entry : impBa2.entrySet()) { - if (entry.getKey().isAfter(impModDate)) { - impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); - } - } - } - - - - //--------------------------------------- - // R E S T R I C T I O N S - //--------------------------------------- - - FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - - - - //ifsg - if ("base".equals(params.ifsg)) { - - } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { - double compliance = Double.parseDouble(params.ifsg) / 100.; - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, compliance)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); - builder.restrict(restrictionDateIfsg, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way - } else { - throw new RuntimeException(); - } - - // EMERGENCY RESTRICTIONS - //work - builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); - double homeOfficeFactor = 0.5; - switch (params.work) { - case "base": - break; - case "half": - builder.restrict(restrictionDateEmergency, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); - break; - case "mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // leisure public + private - switch (params.leis) { - case "base": - break; - case "pub50": - builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic"); - break; - case "pubPriv50": - builder.restrict(restrictionDateEmergency, 0.88 * 0.5, "leisPublic", "leisPrivate"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - //school - switch (params.edu) { - case "base": - break; - case "mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, 0.0, - FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - break; - case "half&mask": - builder.restrict(restrictionDateEmergency, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, 0.0, - FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - - builder.restrict(restrictionDateEmergency, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.applyToRf(restrictionDateEmergency.plusDays(1).toString(), restrictionDateEmergency.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // vary amount of "school" activity that takes place during vacation - builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); - - episimConfig.setPolicy(builder.build()); - - - //--------------------------------------- - // M I S C - //--------------------------------------- - - - if (DEBUG_MODE) { - UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); - } - - return config; - } - - private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { - Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); - Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); - Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); - Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); - Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); - - //StrainA - if (!params.StrainA.equals("off")) { - infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strADate = LocalDate.parse("2022-11-01"); - for (int i = 0; i < 7; i++) { - infPerDayStrA.put(strADate.plusDays(i), 4); - } - infPerDayStrA.put(strADate.plusDays(7), 1); - } - - //StrainB -// if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); -// LocalDate strBDate = LocalDate.parse("2022-11-01"); -// for (int i = 0; i < 7; i++) { -// infPerDayStrB.put(strBDate.plusDays(i), 4); -// } -// infPerDayStrB.put(strBDate.plusDays(7), 1); -// } - - - // add projected disease import for vacation waves after initial disease import -// int facBa2 = 4; -// int facBa5 = 4; -// int facStrAB = 4; -// -// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import -// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import -// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import -// -// String importSummer2022 = "off"; -// if (importSummer2022.equals("on")) { -// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); -// LocalDate date = null; -// for (Map.Entry entry : data.entrySet()) { -// date = entry.getKey(); -// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model -//// -// double cases = factor * entry.getValue(); -// -// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { -// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// } -// else if (!params.StrainA.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else { -// throw new RuntimeException(); -// } -// infPerDayBa5.put(date, 1); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa5)) { -// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa2)) { -// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); -// } -// -// } -// } else if (importSummer2022.equals("off")) { -// } else { -// throw new RuntimeException(); -// } - - - // save disease import - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); - episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); - - if (!params.StrainA.equals("off")) { - episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); - } -// if (!params.StrainB.equals("off")) { -// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); -// } - } - - public static final class Params { - // general - @GenerateSeeds(5) - public long seed; - - //IFSG - @StringParameter({"base","45", "90"}) - public String ifsg; - - // Vacciantion Campaign - @StringParameter({"base", "ifsg90","ifsg90vax180", "ifsg180", "emergency90", "emergency180", "emergency90vax180"}) - String vacCamp; - - // NEW RESTRICTIONS - @StringParameter({"base"}) - public String work; - - // leisure Public - @StringParameter({"base"}) - public String leis; - - //edu - @StringParameter({"base"}) - public String edu; - - @StringParameter({"6.0"}) - public String StrainA; - - - } - - - public static void main(String[] args) { - String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202210XX_vaccination.class.getName(), - RunParallel.OPTION_PARAMS, Params.class.getName(), - RunParallel.OPTION_TASKS, Integer.toString(1), - RunParallel.OPTION_ITERATIONS, Integer.toString(1000), - RunParallel.OPTION_METADATA - }; - - RunParallel.main(args2); - } - - -} - From 62c2fdfc04f674e60f69aabcf1a9f51a9d11fdf6 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 26 Oct 2022 13:31:15 +0200 Subject: [PATCH 089/128] update logic for maxAntibodies --- .../java/org/matsim/episim/EpisimPerson.java | 22 ++++++++++--------- .../java/org/matsim/episim/Immunizable.java | 2 +- .../analysis/HospitalNumbersFromEvents.java | 4 ++-- .../episim/model/DefaultAntibodyModel.java | 10 +++------ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index 4017a2d40..0e6fb5f6e 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -211,7 +211,7 @@ public final class EpisimPerson implements Immunizable, Attributable { /** * Maximal antibody level reached by agent w/ respect to each strain */ - private final Object2DoubleMap maximalAntibodyLevel = new Object2DoubleOpenHashMap<>(); + private final Object2DoubleMap maxAntibodies = new Object2DoubleOpenHashMap<>(); /** * Antibody level at last infection. @@ -312,7 +312,7 @@ void read(ObjectInput in, Map, EpisimPerson> persons) throws IOExcept n = in.readInt(); for (int i = 0; i < n; i++) { VirusStrain strain = VirusStrain.values()[in.readInt()]; - maximalAntibodyLevel.put(strain, in.readDouble()); + maxAntibodies.put(strain, in.readDouble()); } status = DiseaseStatus.values()[in.readInt()]; @@ -382,8 +382,8 @@ void write(ObjectOutput out) throws IOException { out.writeDouble(kv.getDoubleValue()); } - out.writeInt(maximalAntibodyLevel.size()); - for (Object2DoubleMap.Entry kv : maximalAntibodyLevel.object2DoubleEntrySet()) { + out.writeInt(maxAntibodies.size()); + for (Object2DoubleMap.Entry kv : maxAntibodies.object2DoubleEntrySet()) { out.writeInt(kv.getKey().ordinal()); out.writeDouble(kv.getDoubleValue()); } @@ -597,23 +597,25 @@ public double getAntibodyLevelAtInfection() { * get map with max antibodies reached per strain (before current infection) */ public Object2DoubleMap getMaxAntibodies() { - return maximalAntibodyLevel; + return maxAntibodies; } /** * Get max antibodies reached for a particular strain (before current infection) */ public double getMaxAntibodies(VirusStrain virusStrain) { - return maximalAntibodyLevel.getDouble(virusStrain); + return maxAntibodies.getDouble(virusStrain); } /** - * Sets the maximum antibodies agent has had versus a particular strain. - * todo: Does not check if new max value is in fact greater than previous max. + * Updates maximum antibodies agent has had versus a particular strain (only if maxAb is in fact higher + * than previous maximum) */ - public void setMaxAntibodies(VirusStrain strain, double maxAb) { + public void updateMaxAntibodies(VirusStrain strain, double maxAb) { - this.maximalAntibodyLevel.put(strain, maxAb); + if (!this.maxAntibodies.containsKey(strain) || maxAb > this.maxAntibodies.getDouble(strain)) { + this.maxAntibodies.put(strain, maxAb); + } } diff --git a/src/main/java/org/matsim/episim/Immunizable.java b/src/main/java/org/matsim/episim/Immunizable.java index d13b55495..bd2208d2a 100644 --- a/src/main/java/org/matsim/episim/Immunizable.java +++ b/src/main/java/org/matsim/episim/Immunizable.java @@ -61,7 +61,7 @@ public interface Immunizable extends HasPersonId { /** * sets max antibody level that agent has had in their past for a specific strain. */ - void setMaxAntibodies(VirusStrain strain, double maxAb); + void updateMaxAntibodies(VirusStrain strain, double maxAb); /** * Returns whether agent has experienced given disease status at any time in the course of the simulation */ diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index c4bbd2e76..364d0b68c 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -418,7 +418,7 @@ public void handleEvent(EpisimInfectionEvent event) { person.setAntibodyLevelAtInfection(event.getAntibodies()); person.setVirusStrain(virusStrain); - person.setMaxAntibodies(virusStrain, event.getMaxAntibodies()); + person.updateMaxAntibodies(virusStrain, event.getMaxAntibodies()); int day = (int) (event.getTime() / 86_400); @@ -716,7 +716,7 @@ public double getMaxAntibodies(VirusStrain strain) { return maxAntibodies.getDouble(strain); } - public void setMaxAntibodies(VirusStrain strain, double maxAb){ + public void updateMaxAntibodies(VirusStrain strain, double maxAb){ this.maxAntibodies.put(strain, maxAb); } diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index ab70267d6..819bf5402 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -41,7 +41,7 @@ public void init(Collection persons, int iteration) { for (VirusStrain strain : VirusStrain.values()) { person.setAntibodies(strain, 0.0); - person.setMaxAntibodies(strain, 0.0); + person.updateMaxAntibodies(strain, 0.0); } if (iteration > 1) { @@ -113,9 +113,7 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent // if antibodies against a strain2 are higher than previous maximum, replace maximum // should always be the case for initial immunization - if (antibodies > person.getMaxAntibodies(strain2)) { - person.setMaxAntibodies(strain2, antibodies); - } + person.updateMaxAntibodies(strain2, antibodies); } @@ -139,9 +137,7 @@ private void handleImmunization(EpisimPerson person, ImmunityEvent immunityEvent person.setAntibodies(strain2, antibodies); // if antibodies against a strain2 are higher than previous maximum, replace maximum - if (antibodies > person.getMaxAntibodies(strain2)) { - person.setMaxAntibodies(strain2, antibodies); - } + person.updateMaxAntibodies(strain2, antibodies); } } } From b7c9bee980f8243b874a9ab75adca61cce28170e Mon Sep 17 00:00:00 2001 From: jakobrehmann Date: Wed, 26 Oct 2022 13:57:53 +0200 Subject: [PATCH 090/128] remove test --- .../model/DefaultAntibodyModelTest.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java index 17e351140..81c5874af 100644 --- a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java @@ -303,42 +303,6 @@ public void testImmunityResponseMultiplier() { } - @Test - public void testyTest(){ - - List people = new ArrayList<>(); - - for (int i = 0; i < 90_000; i++) { - people.add("boostered"); - } - - for (int i = 0; i < 10_000; i++) { - people.add("vaccinated"); - } - - Collections.shuffle(people); - - double cntVaccinated = 0; - double cntBoostered = 0; - for (int i = 0; i < 50_000; i++) { - if (people.get(i).equals("vaccinated")) { - cntVaccinated++; - }else { - cntBoostered++; - } - } - - System.out.println(cntVaccinated / 10_000); - System.out.println(cntBoostered / 90_000); - - - - - return; - - } - - @Test public void immunizationByBa1() { From 86fff8a033312a651f5ffd356818dd58c1967a2e Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 26 Oct 2022 14:17:46 +0200 Subject: [PATCH 091/128] fixed test: testImmunityResponseMultiplier in DefaultAntibodyModelTest. Previous expected behaviour was that for 2nd immunity event, the multiplier would depend on the agent's immuneResponse; now all agents have same multiplier. --- .../org/matsim/episim/model/DefaultAntibodyModelTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java index 17e351140..ebbbbace5 100644 --- a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java @@ -247,7 +247,7 @@ public void testMixOfVaccinesAndInfections() { * Tests the immuneResponseMultiplier of EpisimPerson; the agent w/ a higher immune response to vaccination/infection * will have a multiplier of 2 while the "normal" agent has a multiplier of 1. * a) 1st immunity event: high-response agent will gain 2x antibodies as regular-response agent - * b) 2nd immunity event: high-response agent will have their antibodies multiplied/refreshed by a factor 2x as high as the regular-response agent + * b) 2nd immunity event: high-response agent will have their antibodies multiplied/refreshed by a factor exactly the same as regular-response agent */ @Test public void testImmunityResponseMultiplier() { @@ -292,12 +292,12 @@ public void testImmunityResponseMultiplier() { } } - // antibody jump after 2nd infection will be 2x higher for high immunity agent. + // antibody jump after 2nd infection will be same for high immunity agent. for (VirusStrain strain : strainsToCheck) { double jumpNormal = antibodyLevelsNormal.get(secondImmunityEvent + 1).getDouble(strain) / antibodyLevelsNormal.get(secondImmunityEvent).getDouble(strain); double jumpHigh = antibodyLevelsHigh.get(secondImmunityEvent + 1).getDouble(strain) / antibodyLevelsHigh.get(secondImmunityEvent).getDouble(strain); - assertThat(jumpHigh).isCloseTo(2 * jumpNormal, OFFSET); + assertThat(jumpHigh).isCloseTo(jumpNormal, OFFSET); } From 5e1c77631614c4a1a35260d47ff1c58122b5fb19 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 26 Oct 2022 16:24:49 +0200 Subject: [PATCH 092/128] updates hospitalisation model --- .../analysis/HospitalNumbersFromEvents.java | 9 ++-- .../HospitalNumbersFromEventsPlotter.java | 43 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 364d0b68c..efdf7b299 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -59,7 +59,8 @@ ) public class HospitalNumbersFromEvents implements OutputAnalysis { - @CommandLine.Option(names = "--output", defaultValue = "./output/") +// @CommandLine.Option(names = "--output", defaultValue = "./output/") + @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-10-18/3-meas/analysis/") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -160,10 +161,10 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double factorDelta = 1.2 * factorWild;//1.6 * factorWild; // omicron: approx 0.3x (intrinsic) severity of delta - Comparative analysis of the risks of hospitalisation and death associated with SARS-CoV-2 omicron (B.1.1.529) and delta (B.1.617.2) variants in England: a cohort study -// private static final double factorOmicron = 0.3 * factorDelta; // reportedShareOmicron / reportedShareDelta - private static final double factorOmicron = 0.6 * factorDelta;// reportedShareOmicron / reportedShareDelta + private static final double factorOmicron = 0.45 * factorDelta; // reportedShareOmicron / reportedShareDelta +// private static final double factorOmicron = 0.6 * factorDelta;// reportedShareOmicron / reportedShareDelta - private static final double factorBA5 = 1.5 * factorOmicron; + private static final double factorBA5 = 1.0 * factorOmicron; // old: 1.5 private static final double factorScen2 = factorBA5;// reportedShareOmicron / reportedShareDelta private static final double factorScen3 = factorBA5 * 3;// reportedShareOmicron / reportedShareDelta diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java index 0f369f177..383c405a1 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEventsPlotter.java @@ -134,23 +134,30 @@ static void aggregateAndProducePlots(Path output, List pathList, String ou rkiHospIncidence.put(day, incidence); double incidenceAdj; - if (date.isBefore(LocalDate.of(2020, 12, 10))) { - incidenceAdj = incidence; - } else if (date.isBefore(LocalDate.of(2021, 1, 11))) { - incidenceAdj = 23. / 16. * incidence; - } else if (date.isBefore(LocalDate.of(2021, 3, 22))) { - incidenceAdj = 8. / 6. * incidence; - } else if (date.isBefore(LocalDate.of(2021, 5, 3))) { - incidenceAdj = 15./11. * incidence; - } else if (date.isBefore(LocalDate.of(2021, 11, 8))) { - incidenceAdj = incidence; - } else if (date.isBefore(LocalDate.of(2021, 12, 6))) { - incidenceAdj = 16. / 13. * incidence; - } else if (date.isBefore(LocalDate.of(2022, 1, 24))) { - incidenceAdj = incidence; - } else { - incidenceAdj = 11./14 * incidence; + if (date.isBefore(LocalDate.of(2022, 11, 1))) { + incidenceAdj = incidence * 2 / 3; + } else{ + incidenceAdj = incidence / 3; } + + +// if (date.isBefore(LocalDate.of(2020, 12, 10))) { +// incidenceAdj = incidence; +// } else if (date.isBefore(LocalDate.of(2021, 1, 11))) { +// incidenceAdj = 23. / 16. * incidence; +// } else if (date.isBefore(LocalDate.of(2021, 3, 22))) { +// incidenceAdj = 8. / 6. * incidence; +// } else if (date.isBefore(LocalDate.of(2021, 5, 3))) { +// incidenceAdj = 15./11. * incidence; +// } else if (date.isBefore(LocalDate.of(2021, 11, 8))) { +// incidenceAdj = incidence; +// } else if (date.isBefore(LocalDate.of(2021, 12, 6))) { +// incidenceAdj = 16. / 13. * incidence; +// } else if (date.isBefore(LocalDate.of(2022, 1, 24))) { +// incidenceAdj = incidence; +// } else { +// incidenceAdj = 11./14 * incidence; +// } rkiHospIncidenceAdj.put(day, incidenceAdj); } } @@ -404,7 +411,7 @@ static void aggregateAndProducePlots(Path output, List pathList, String ou } else { values.append(value); } - groupings.append("reported: intakeHosp (rki, nrw adjusted)"); + groupings.append("reported: intakeHosp (rki, nrw adjusted) WITH Covid"); } for (Int2DoubleMap.Entry entry : rkiHospIncidenceAdj.int2DoubleEntrySet()) { @@ -417,7 +424,7 @@ static void aggregateAndProducePlots(Path output, List pathList, String ou } else { values.append(value); } - groupings.append("reported: intakeHosp (rki, nrw adjusted, SARI)"); + groupings.append("reported: intakeHosp (rki, nrw adjusted) FROM Covid"); } for (Int2DoubleMap.Entry entry : hospIncidenceKoeln.int2DoubleEntrySet()) { From 043e260b019ab5e9bbb7683669de369c9064c615 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Wed, 26 Oct 2022 17:23:02 +0200 Subject: [PATCH 093/128] write immunization tsv --- .../org/matsim/episim/EpisimConfigGroup.java | 16 ++++++ .../java/org/matsim/episim/EpisimRunner.java | 50 +++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimConfigGroup.java b/src/main/java/org/matsim/episim/EpisimConfigGroup.java index 2badeb3b2..15dfeae7d 100644 --- a/src/main/java/org/matsim/episim/EpisimConfigGroup.java +++ b/src/main/java/org/matsim/episim/EpisimConfigGroup.java @@ -67,6 +67,7 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { private static final String SNAPSHOT_INTERVAL = "snapshotInterval"; private static final String START_FROM_SNAPSHOT = "startFromSnapshot"; private static final String SNAPSHOT_PREFIX = "snapshotPrefix"; + private static final String IMMUNIZATION_PREFIX = "immunizationPrefix"; private static final String SNAPSHOT_SEED = "snapshotSeed"; private static final String LEISUREOUTDOORFRACTION = "leisureOutdoorFraction"; private static final String INPUT_DAYS = "inputDays"; @@ -147,6 +148,11 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { */ private String snapshotPrefix = "episim-snapshot"; + /** + * Filename prefix for immunization. + */ + private String immunizationPrefix = "episim-immunization"; + /** * How the internal rng state should be handled. */ @@ -381,6 +387,16 @@ public void setSnapshotPrefix(String snapshotPrefix) { this.snapshotPrefix = snapshotPrefix; } + @StringGetter(IMMUNIZATION_PREFIX) + public String getImmunizationPrefix() { + return immunizationPrefix; + } + + @StringSetter(IMMUNIZATION_PREFIX) + public void setImmunizationPrefix(String immunizationPrefix) { + this.immunizationPrefix = immunizationPrefix; + } + @StringGetter(SNAPSHOT_SEED) public SnapshotSeed getSnapshotSeed() { return snapshotSeed; diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index 39aae36f1..ef3f07319 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -24,6 +24,9 @@ import com.google.inject.Provider; import org.apache.commons.compress.archivers.*; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.events.Event; @@ -35,10 +38,7 @@ import org.matsim.episim.model.AntibodyModel; import org.matsim.episim.model.ProgressionModel; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -131,8 +131,10 @@ public void run(int maxIterations) { for (; iteration <= maxIterations; iteration++) { - if (episimConfig.getSnapshotInterval() > 0 && iteration % episimConfig.getSnapshotInterval() == 0) + if (episimConfig.getSnapshotInterval() > 0 && iteration % episimConfig.getSnapshotInterval() == 0) { writeSnapshot(output, iteration); + writeImmunization(output, iteration); + } if (iteration % 10 == 0) Gbl.printMemoryUsage(); @@ -149,6 +151,7 @@ public void run(int maxIterations) { /** * Update events data and internal person data structure. + * * @param events */ public void updateEvents(Map> events) { @@ -247,6 +250,43 @@ private void writeSnapshot(Path output, int iteration) { } + /** + * Write immunization history. + * + * @param output output path + * @param iteration current iteration + */ + private void writeImmunization(Path output, int iteration) { + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + String date = episimConfig.getStartDate().plusDays(iteration - 1).toString(); + + Path path = output.resolve(episimConfig.getImmunizationPrefix() + String.format("-%03d-%s.tsv.gz", iteration, date)); + + log.info("Writing immunization history to {}", path); + + InfectionEventHandler handler = handlerProvider.get(); + + try (CSVPrinter out = new CSVPrinter(new OutputStreamWriter(new GzipCompressorOutputStream(Files.newOutputStream(path))), CSVFormat.TDF)) { + + out.printRecord("personId", "date", "virus_or_vaccine", "type"); + + for (EpisimPerson person : handler.getPersons()) { + for (int i = 0; i < person.getNumInfections(); i++) { + out.printRecord(person.getPersonId(), person.getInfectionDates().getDouble(i), "virus", person.getVirusStrain(i)); + } + + for (int i = 0; i < person.getNumVaccinations(); i++) { + out.printRecord(person.getPersonId(), person.getVaccinationDates().getInt(i), "vaccine", person.getVaccinationType(i)); + } + } + + } catch (IOException e) { + throw new UncheckedIOException("Could not write immunization history", e); + } + } + /** * Read snapshot from disk and initialize simulation state * From c8230c780fa1895d43cb47d1e095192956dd557f Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 26 Oct 2022 17:23:08 +0200 Subject: [PATCH 094/128] add new test batch --- .../analysis/HospitalNumbersFromEvents.java | 2 +- ...ccinationStrategyReoccurringCampaigns.java | 4 +- .../run/batch/StartFromImmunisations.java | 147 ++++++++++++++++++ 3 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/StartFromImmunisations.java diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index efdf7b299..e776423f6 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -268,7 +268,7 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t ConfigHolder holderDelta = configure(factorScen3, 1.0); //scenario 3 List handlers = List.of( - new Handler("Omicron", population, holderOmicron, 0.0), + new Handler("Omicron", population, holderOmicron, 0.0), new Handler("Delta", population, holderDelta, 0.0) // new Handler("Omicron-Paxlovid-0.25 ", population, holderOmicron, 0.25), // new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), diff --git a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java index bc17e2498..c2604d694 100644 --- a/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java +++ b/src/main/java/org/matsim/episim/model/vaccination/VaccinationStrategyReoccurringCampaigns.java @@ -84,7 +84,7 @@ public void handleVaccination(Map, EpisimPerson> persons, LocalDate d .filter(EpisimPerson::isVaccinable) .filter(p -> p.getDiseaseStatus() == EpisimPerson.DiseaseStatus.susceptible) .filter(p -> p.getNumVaccinations() >= config.vaccinationPool.vaxCnt) - .filter(p -> p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > config.minDaysAfterVaccination) // only people who've had their last vaccination more than 90 days ago + .filter(p -> p.getNumVaccinations() == 0 || p.daysSinceVaccination(p.getNumVaccinations() - 1, iteration) > config.minDaysAfterVaccination) // only people who've had their last vaccination more than 90 days ago .filter(p -> p.getNumInfections() == 0 || p.daysSinceInfection(p.getNumInfections() - 1, iteration) > minDaysAfterInfection) // only people who've had their last vaccination more than 90 days ago .filter(p -> date.isAfter(config.emergencyDate.minusDays(1)) ? boostBa5Emergency.contains(p.getPersonId()) : boostBa5Yes.contains(p.getPersonId())) .filter(p -> !p.hadVaccinationType(vaccinationType)) // todo remove in future @@ -135,6 +135,8 @@ public static class Config { public enum VaccinationPool { + unvaccinated(0), + vaccinated(1), boostered(2); diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunisations.java b/src/main/java/org/matsim/run/batch/StartFromImmunisations.java new file mode 100644 index 000000000..ad8a13a11 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/StartFromImmunisations.java @@ -0,0 +1,147 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class StartFromImmunisations implements BatchRun { + + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // VACCINATION MODEL + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + // fixed values + LocalDate start = LocalDate.parse("2020-03-01"); + VaccinationType vaccinationType = VaccinationType.mRNA; + int campaignDuration = 300000; + + // default values, to be changed if params != null + int minDaysAfterInfection = 180; + int minDaysAfterVaccination = 180; + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.unvaccinated; + LocalDate emergencyDate = LocalDate.MAX; + LocalDate dateToTurnDownMinDaysAfterInfection = LocalDate.MAX; + Map startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(start, vaccinationType); + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, dateToTurnDownMinDaysAfterInfection)); + + } + }); + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( +// new VaccinationEffectiveness().withArgs(), +// new RValuesFromEvents().withArgs(), +// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), +// new FilterEvents().withArgs("--output","./output/"), +// new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + //snapshot +// episimConfig.setSnapshotInterval(30); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + virusStrainConfigGroup.getOrAddParams(VirusStrain.SARS_CoV_2).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.SARS_CoV_2).getInfectiousness() * 10); + + + return config; + } + + public static final class Params { + // general + @GenerateSeeds(1) + public long seed; + + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, StartFromImmunisations.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + From 563dac36944fac0ef3e765373df4407d49a12243 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Wed, 26 Oct 2022 17:33:09 +0200 Subject: [PATCH 095/128] write out date instead of time as double --- .../java/org/matsim/episim/EpisimConfigGroup.java | 12 ++++++++++++ src/main/java/org/matsim/episim/EpisimRunner.java | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimConfigGroup.java b/src/main/java/org/matsim/episim/EpisimConfigGroup.java index 15dfeae7d..9883bf7d2 100644 --- a/src/main/java/org/matsim/episim/EpisimConfigGroup.java +++ b/src/main/java/org/matsim/episim/EpisimConfigGroup.java @@ -66,6 +66,7 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { private static final String START_DATE = "startDate"; private static final String SNAPSHOT_INTERVAL = "snapshotInterval"; private static final String START_FROM_SNAPSHOT = "startFromSnapshot"; + private static final String START_FROM_IMMUNIZATION = "startFromImmunization"; private static final String SNAPSHOT_PREFIX = "snapshotPrefix"; private static final String IMMUNIZATION_PREFIX = "immunizationPrefix"; private static final String SNAPSHOT_SEED = "snapshotSeed"; @@ -142,6 +143,7 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { * Path to snapshot file. */ private String startFromSnapshot = null; + private String startFromImmunization = null; /** * Filename prefix for snapshot. @@ -377,6 +379,16 @@ public void setStartFromSnapshot(String startFromSnapshot) { this.startFromSnapshot = startFromSnapshot; } + @StringGetter(START_FROM_IMMUNIZATION) + public String getStartFromImmunization() { + return startFromImmunization; + } + + @StringSetter(START_FROM_IMMUNIZATION) + public void setStartFromImmunization(String startFromImmunization) { + this.startFromImmunization = startFromImmunization; + } + @StringGetter(SNAPSHOT_PREFIX) public String getSnapshotPrefix() { return snapshotPrefix; diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index ef3f07319..ed2617c4b 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -274,11 +274,13 @@ private void writeImmunization(Path output, int iteration) { for (EpisimPerson person : handler.getPersons()) { for (int i = 0; i < person.getNumInfections(); i++) { - out.printRecord(person.getPersonId(), person.getInfectionDates().getDouble(i), "virus", person.getVirusStrain(i)); + String occurrence = episimConfig.getStartDate().plusDays((long) ((person.getInfectionDates().getDouble(i) / EpisimUtils.DAY) - 1)).toString(); + out.printRecord(person.getPersonId(), occurrence, "virus", person.getVirusStrain(i)); } for (int i = 0; i < person.getNumVaccinations(); i++) { - out.printRecord(person.getPersonId(), person.getVaccinationDates().getInt(i), "vaccine", person.getVaccinationType(i)); + String occurrence = episimConfig.getStartDate().plusDays(person.getVaccinationDates().getInt(i) - 1).toString(); + out.printRecord(person.getPersonId(), occurrence, "vaccine", person.getVaccinationType(i)); } } From bf17974b4da025f3b88b52a9980e268543bee370 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Wed, 26 Oct 2022 18:03:05 +0200 Subject: [PATCH 096/128] read immunization history --- .../java/org/matsim/episim/EpisimPerson.java | 17 ++++++++-- .../java/org/matsim/episim/EpisimRunner.java | 4 +++ .../matsim/episim/InfectionEventHandler.java | 33 ++++++++++++++++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index 0e6fb5f6e..d10f22d0a 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -49,8 +49,7 @@ import java.util.function.BiFunction; import java.util.stream.Collectors; -import static org.matsim.episim.EpisimUtils.readChars; -import static org.matsim.episim.EpisimUtils.writeChars; +import static org.matsim.episim.EpisimUtils.*; /** * Persons current state in the simulation. @@ -438,6 +437,20 @@ public void setInitialInfection(double now, VirusStrain strain) { } + /** + * Add an infection or vaccination from immunization history. + */ + void addImmunizationRecord(double time, boolean virus, String type) { + + if (virus) { + virusStrains.add(VirusStrain.valueOf(type)); + infectionDates.add(time * DAY); + } else { + vaccinations.add(VaccinationType.valueOf(type)); + vaccinationDates.add((int) time); + } + } + /** * Adds an infection possibility to this person. Will be executed in {@link #checkInfection()} */ diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index ed2617c4b..bea7705b4 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -117,6 +117,10 @@ public void run(int maxIterations) { handler.onSnapshotLoaded(iteration); } + if (episimConfig.getStartFromImmunization() != null) { + handler.initImmunization(Path.of(episimConfig.getStartFromImmunization())); + } + // recalculate antibodies for every agent if starting from snapshot. // The antibodies profile is generated using the immunity event history in the // snapshot; the antibody model config of the snapshot simulation will diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 5fd9ea8bc..5f8db04ae 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -26,8 +26,10 @@ import com.google.inject.util.Types; import com.typesafe.config.ConfigFactory; import it.unimi.dsi.fastutil.objects.*; +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVPrinter; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; @@ -50,14 +52,12 @@ import org.matsim.utils.objectattributes.attributable.Attributes; import org.matsim.vehicles.Vehicle; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; +import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -286,6 +286,7 @@ void init(Map> events) { /** * Update events data and internal person data structure. + * * @param events */ void updateEvents(Map> events) { @@ -997,6 +998,28 @@ void handleEvents(DayOfWeek day, List events) { } + /** + * Read immunization history and init persons. + */ + void initImmunization(Path history) { + + log.info("Reading immunization from {}", history); + try (CSVParser parser = new CSVParser(new InputStreamReader(new GzipCompressorInputStream(Files.newInputStream(history))), CSVFormat.TDF.withSkipHeaderRecord())) { + + for (CSVRecord record : parser) { + EpisimPerson person = personMap.get(Id.createPersonId(record.get(0))); + LocalDate occurrence = LocalDate.parse(record.get(1)); + + long time = ChronoUnit.DAYS.between(episimConfig.getStartDate(), occurrence); + person.addImmunizationRecord(time, record.get(2).equals("virus"), record.get(3)); + } + + } catch (IOException e) { + throw new UncheckedIOException("Could not read immunization history", e); + } + + } + /** * Container that is always a vehicle. */ From aed85c23f1f3e2ea91dbfefc6debbfadeff48f3a Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 27 Oct 2022 10:21:52 +0200 Subject: [PATCH 097/128] wip --- .../episim/model/DefaultAntibodyModel.java | 5 +- .../batch/CologneBMBF20221024_snapshot.java | 692 ++++++++++++++++++ .../run/batch/StartFromImmunisations.java | 7 +- 3 files changed, 700 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 819bf5402..f24a50c31 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -44,11 +44,12 @@ public void init(Collection persons, int iteration) { person.updateMaxAntibodies(strain, 0.0); } - if (iteration > 1) { + + // start from snapshot + if (iteration > 1 ) { for (int it = 1; it < iteration; it++) { updateAntibodies(person, it); } - } } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java new file mode 100644 index 000000000..ac54be48a --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java @@ -0,0 +1,692 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF20221024_snapshot implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + LocalDate restrictionDatePhase1 = LocalDate.parse("2022-12-01"); + LocalDate restrictionDatePhase2 = restrictionDatePhase1.plusDays(10); + + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // VACCINATION MODEL + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + // fixed values + LocalDate start = LocalDate.parse("2022-10-15"); + VaccinationType vaccinationType = VaccinationType.ba5Update; + int campaignDuration = 300000; + + // default values, to be changed if params != null + int minDaysAfterInfection = 180; + int minDaysAfterVaccination = 180; + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated; + LocalDate emergencyDate = LocalDate.MAX; + LocalDate dateToTurnDownMinDaysAfterInfection = LocalDate.MAX; + Map startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(start, vaccinationType); + + if (params != null) { + if (params.vacCamp.equals("base")) { // + + + } else if(params.vacCamp.equals("ph1_90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_180")){ // + + emergencyDate = restrictionDatePhase1; + } else if (params.vacCamp.equals("ph1_180_ph2_inf90vax180")) { + emergencyDate = restrictionDatePhase1; + dateToTurnDownMinDaysAfterInfection = restrictionDatePhase2; + // same as ifsg180 but after phase 2 date, minDaysAfterInfection = 90; + }else if(params.vacCamp.equals("ph2_90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_inf90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_180")) { + emergencyDate = restrictionDatePhase2; + }else { + throw new RuntimeException(); + } + } + + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, dateToTurnDownMinDaysAfterInfection)); + + + // ANTIBODY MODEL + // default values + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 5.0; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + + if (params != null) { +// mutEscBa1 = params.ba1Esc; +// mutEscBa5 = params.ba5Esc; + +// String StrainA = "6.0"; + String StrainB = "off"; + + + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(StrainB); + } + + } + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + + // HOUSEHOLD SUSCEPTIBILITY + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(0.35, 0.01) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + //snapshot + episimConfig.setSnapshotInterval(30); + episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); + } + +// STRAIN_B +// if (!params.StrainB.equals("off")) { +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); +// } + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + configureFutureDiseaseImport(params, episimConfig); + + // modify import: + LocalDate impModDate = LocalDate.parse("2022-01-31"); + double impRedBa1 = 0.0; + double impRedBa2 = 0.0; + if (impRedBa1 != 1.0) { + NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); + for (Map.Entry entry : impBa1.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); + } + } + } + + if (impRedBa2 != 1.0) { + NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); + for (Map.Entry entry : impBa2.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); + } + } + } + + + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + + + //ifsg + if ("base".equals(params.ifsg)) { + + } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { + double compliance = Double.parseDouble(params.ifsg) / 100.; + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, compliance)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way + } else { + throw new RuntimeException(); + } + + // EMERGENCY RESTRICTIONS + //work + builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); + double homeOfficeFactor = 0.5; + switch (params.work) { + case "base": + break; + case "half": + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "half&mask": + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure public + private + switch (params.leis) { + case "base": + break; + case "pub50": + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic"); + break; + case "pubPriv50": + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic", "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //school + switch (params.edu) { + case "base": + break; + case "mask": + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + case "half&mask": + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + + builder.restrict(restrictionDatePhase2, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); + Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); + LocalDate strADate = LocalDate.parse("2022-11-01"); + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB +// if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strBDate = LocalDate.parse("2022-11-01"); +// for (int i = 0; i < 7; i++) { +// infPerDayStrB.put(strBDate.plusDays(i), 4); +// } +// infPerDayStrB.put(strBDate.plusDays(7), 1); +// } + + + // add projected disease import for vacation waves after initial disease import + int facBa2 = 4; + int facBa5 = 4; + int facStrAB = 4; + + LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import + LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import + LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + +// String importSummer2022 = "off"; +// if (importSummer2022.equals("on")) { +// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); +// LocalDate date = null; +// for (Map.Entry entry : data.entrySet()) { +// date = entry.getKey(); +// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +//// +// double cases = factor * entry.getValue(); +// +// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { +// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// } +// else if (!params.StrainA.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else { +// throw new RuntimeException(); +// } +// infPerDayBa5.put(date, 1); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa5)) { +// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa2)) { +// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); +// } +// +// } +// } else if (importSummer2022.equals("off")) { +// } else { +// throw new RuntimeException(); +// } + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } +// if (!params.StrainB.equals("off")) { +// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); +// } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + //IFSG + @StringParameter({"base"}) + public String ifsg; + + // Vacciantion Campaign + @StringParameter({"base"}) + String vacCamp; + + // NEW RESTRICTIONS + @StringParameter({"base"}) + public String work; + + // leisure Public + @StringParameter({"base"}) + public String leis; + + //edu + @StringParameter({"base"}) + public String edu; + + @StringParameter({"6.0"}) + public String StrainA; + + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF20221024_snapshot.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunisations.java b/src/main/java/org/matsim/run/batch/StartFromImmunisations.java index ad8a13a11..f49c01b47 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunisations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunisations.java @@ -105,8 +105,11 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot -// episimConfig.setSnapshotInterval(30); -// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); + episimConfig.setSnapshotInterval(5); + + episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); + + // episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- From 9e0a83a25256ee33909c470d18837c0d21c4d6d4 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 1 Nov 2022 15:29:52 +0100 Subject: [PATCH 098/128] update startFromImmunisations and create batch for bq1 simulation --- .../matsim/episim/InfectionEventHandler.java | 6 +- .../episim/model/DefaultAntibodyModel.java | 8 +- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../matsim/run/batch/CologneBMBF202212XX.java | 697 ++++++++++++++++++ .../run/batch/StartFromImmunisations.java | 19 +- .../modules/SnzCologneProductionScenario.java | 2 +- .../model/DefaultAntibodyModelTest.java | 3 +- 7 files changed, 727 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 5f8db04ae..e1b8622b8 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -1006,7 +1006,11 @@ void initImmunization(Path history) { log.info("Reading immunization from {}", history); try (CSVParser parser = new CSVParser(new InputStreamReader(new GzipCompressorInputStream(Files.newInputStream(history))), CSVFormat.TDF.withSkipHeaderRecord())) { - for (CSVRecord record : parser) { + // initialize parser and skip header row TODO: this should be done automatically but fails + Iterator iterator = parser.iterator(); + iterator.next(); + while (iterator.hasNext()) { + CSVRecord record = iterator.next(); EpisimPerson person = personMap.get(Id.createPersonId(record.get(0))); LocalDate occurrence = LocalDate.parse(record.get(1)); diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index f24a50c31..3a0be548f 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -2,6 +2,7 @@ import com.google.inject.Inject; +import org.matsim.episim.EpisimConfigGroup; import org.matsim.episim.EpisimPerson; import org.matsim.episim.EpisimUtils; @@ -15,10 +16,13 @@ public class DefaultAntibodyModel implements AntibodyModel { private final AntibodyModel.Config antibodyConfig; private final SplittableRandom localRnd; + private final EpisimConfigGroup episimConfig; + @Inject - DefaultAntibodyModel(AntibodyModel.Config antibodyConfig) { + DefaultAntibodyModel(AntibodyModel.Config antibodyConfig, EpisimConfigGroup episimConfigGroup) { this.antibodyConfig = antibodyConfig; + this.episimConfig = episimConfigGroup; localRnd = new SplittableRandom(2938); // todo: should it be a fixed seed, i.e not change btwn snapshots @@ -46,7 +50,7 @@ public void init(Collection persons, int iteration) { // start from snapshot - if (iteration > 1 ) { + if (iteration > 1 || episimConfig.getStartFromImmunization() != null) { for (int it = 1; it < iteration; it++) { updateAntibodies(person, it); } diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 3efd951a1..0f3ed3168 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_measures") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202210XX_measures$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java new file mode 100644 index 000000000..55efe1de2 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java @@ -0,0 +1,697 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF202212XX implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + LocalDate restrictionDatePhase1 = LocalDate.parse("2022-12-01"); + LocalDate restrictionDatePhase2 = restrictionDatePhase1.plusDays(10); + + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // VACCINATION MODEL + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + // fixed values + LocalDate start = LocalDate.parse("2022-10-15"); + VaccinationType vaccinationType = VaccinationType.ba5Update; + int campaignDuration = 300000; + + // default values, to be changed if params != null + int minDaysAfterInfection = 180; + int minDaysAfterVaccination = 180; + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated; + LocalDate emergencyDate = LocalDate.MAX; + LocalDate dateToTurnDownMinDaysAfterInfection = LocalDate.MAX; + Map startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(start, vaccinationType); + + if (params != null) { + if (params.vacCamp.equals("base")) { // + + + } else if(params.vacCamp.equals("ph1_90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_180")){ // + + emergencyDate = restrictionDatePhase1; + } else if (params.vacCamp.equals("ph1_180_ph2_inf90vax180")) { + emergencyDate = restrictionDatePhase1; + dateToTurnDownMinDaysAfterInfection = restrictionDatePhase2; + // same as ifsg180 but after phase 2 date, minDaysAfterInfection = 90; + }else if(params.vacCamp.equals("ph2_90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_inf90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_180")) { + emergencyDate = restrictionDatePhase2; + }else { + throw new RuntimeException(); + } + } + + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, dateToTurnDownMinDaysAfterInfection)); + + + // ANTIBODY MODEL + // default values + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 5.0; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + + if (params != null) { +// mutEscBa1 = params.ba1Esc; +// mutEscBa5 = params.ba5Esc; + +// String StrainA = "6.0"; + String StrainB = "off"; + + + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(StrainB); + } + + } + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + + // HOUSEHOLD SUSCEPTIBILITY + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(0.35, 0.01) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + //snapshot +// episimConfig.setSnapshotInterval(30); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip "); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); + } + +// STRAIN_B +// if (!params.StrainB.equals("off")) { +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); +// } + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + configureFutureDiseaseImport(params, episimConfig); + + // modify import: + LocalDate impModDate = LocalDate.parse("2022-01-31"); + double impRedBa1 = 0.0; + double impRedBa2 = 0.0; + if (impRedBa1 != 1.0) { + NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); + for (Map.Entry entry : impBa1.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); + } + } + } + + if (impRedBa2 != 1.0) { + NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); + for (Map.Entry entry : impBa2.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); + } + } + } + + + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + + + //ifsg + if ("base".equals(params.ifsg)) { + + } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { + double compliance = Double.parseDouble(params.ifsg) / 100.; + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, compliance)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way + } else { + throw new RuntimeException(); + } + + // EMERGENCY RESTRICTIONS + //work + builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); + double homeOfficeFactor = 0.5; + switch (params.work) { + case "base": + break; + case "half": + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "half&mask": + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure public + private + switch (params.leis) { + case "base": + break; + case "pub50": + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic"); + break; + case "pubPriv50": + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic", "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //school + switch (params.edu) { + case "base": + break; + case "mask": + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + case "half&mask": + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + + builder.restrict(restrictionDatePhase2, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); +// Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strADate = LocalDate.parse("2022-11-01"); + LocalDate strADate = LocalDate.parse(params.strainADate); + + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB +// if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strBDate = LocalDate.parse("2022-11-01"); +// for (int i = 0; i < 7; i++) { +// infPerDayStrB.put(strBDate.plusDays(i), 4); +// } +// infPerDayStrB.put(strBDate.plusDays(7), 1); +// } + + + // add projected disease import for vacation waves after initial disease import +// int facBa2 = 4; +// int facBa5 = 4; +// int facStrAB = 4; +// +// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import +// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import +// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + +// String importSummer2022 = "off"; +// if (importSummer2022.equals("on")) { +// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); +// LocalDate date = null; +// for (Map.Entry entry : data.entrySet()) { +// date = entry.getKey(); +// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +//// +// double cases = factor * entry.getValue(); +// +// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { +// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// } +// else if (!params.StrainA.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else { +// throw new RuntimeException(); +// } +// infPerDayBa5.put(date, 1); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa5)) { +// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa2)) { +// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); +// } +// +// } +// } else if (importSummer2022.equals("off")) { +// } else { +// throw new RuntimeException(); +// } + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } +// if (!params.StrainB.equals("off")) { +// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); +// } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + //IFSG + @StringParameter({"base"}) + public String ifsg; + + // Vaccination Campaign + @StringParameter({"base"}) + String vacCamp; + + // NEW RESTRICTIONS + @StringParameter({"base"}) + public String work; + + // leisure Public + @StringParameter({"base"}) + public String leis; + + //edu + @StringParameter({"base"}) + public String edu; + + @StringParameter({"off","3.0","4.0","5.0","6.0"}) + public String StrainA; + + @StringParameter({"2022-08-15", "2022-08-22", "2022-08-29", "2022-09-05", "2022-09-12", "2022-09-19", "2022-09-26"}) + public String strainADate; + + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF202212XX.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunisations.java b/src/main/java/org/matsim/run/batch/StartFromImmunisations.java index f49c01b47..cb1175939 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunisations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunisations.java @@ -105,20 +105,29 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot - episimConfig.setSnapshotInterval(5); +// episimConfig.setSnapshotInterval(10); - episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); + LocalDate startDate = LocalDate.parse("2022-11-01"); + episimConfig.setStartDate(startDate); +// episimConfig.setImmunizationPrefix("imm-" + String.valueOf(params.seed)); +// episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/imm-" + String.valueOf(params.seed)+"-960-2022-10-11.tsv.gz"); + episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/imm-4711-210-2020-09-21.tsv.gz"); // episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + + episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA5).put(startDate, 144_380 / 4); + + //--------------------------------------- // S T R A I N S //--------------------------------------- - VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - - virusStrainConfigGroup.getOrAddParams(VirusStrain.SARS_CoV_2).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.SARS_CoV_2).getInfectiousness() * 10); +// VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.SARS_CoV_2).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.SARS_CoV_2).getInfectiousness() * 10); return config; diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index d855db9fa..1465902e8 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -382,7 +382,7 @@ public Config config() { CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); - activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20221003.csv")); + activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20221023.csv")); activityParticipation.setScale(this.scale); activityParticipation.setLeisureAsNightly(this.leisureNightly); diff --git a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java index 266e1d48b..186883c51 100644 --- a/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultAntibodyModelTest.java @@ -10,6 +10,7 @@ import org.apache.log4j.Logger; import org.assertj.core.data.Offset; import org.junit.*; +import org.matsim.episim.EpisimConfigGroup; import org.matsim.episim.EpisimPerson; import org.matsim.episim.EpisimTestUtils; import org.matsim.testcases.MatsimTestUtils; @@ -53,7 +54,7 @@ public class DefaultAntibodyModelTest { public void setup() { antibodyConfig = AntibodyModel.newConfig(); - model = new DefaultAntibodyModel(antibodyConfig); + model = new DefaultAntibodyModel(antibodyConfig,new EpisimConfigGroup()); } From 483fdac17edf4718572fd92095fe480060ccb3d3 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 3 Nov 2022 15:40:53 +0100 Subject: [PATCH 099/128] wip: snapshot lite - jakob --- .../java/org/matsim/episim/EpisimPerson.java | 2 +- .../java/org/matsim/episim/EpisimRunner.java | 4 - .../java/org/matsim/episim/EpisimUtils.java | 2 +- .../matsim/episim/InfectionEventHandler.java | 34 +++++- .../matsim/episim/analysis/FilterEvents.java | 4 +- .../analysis/HospitalNumbersFromEvents.java | 2 + .../episim/events/EpisimEventsReader.java | 20 +++- .../events/EpisimInitialInfectionEvent.java | 5 +- .../episim/events/EpisimStartEvent.java | 49 ++++++++ .../events/EpisimStartEventHandler.java | 27 +++++ .../events/InitialImmunizationHandler.java | 90 +++++++++++++++ .../episim/model/DefaultAntibodyModel.java | 8 +- .../matsim/run/batch/CologneBMBF202212XX.java | 2 +- ...tions.java => StartFromImmunizations.java} | 29 +++-- .../InitialImmunizationHandlerTest.java | 108 ++++++++++++++++++ 15 files changed, 348 insertions(+), 38 deletions(-) create mode 100644 src/main/java/org/matsim/episim/events/EpisimStartEvent.java create mode 100644 src/main/java/org/matsim/episim/events/EpisimStartEventHandler.java create mode 100644 src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java rename src/main/java/org/matsim/run/batch/{StartFromImmunisations.java => StartFromImmunizations.java} (83%) create mode 100644 src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index d10f22d0a..d44fbd63c 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -427,7 +427,7 @@ public void setDiseaseStatus(double now, DiseaseStatus status) { */ public void setInitialInfection(double now, VirusStrain strain) { - reporting.reportInfection(new EpisimInitialInfectionEvent(now, getPersonId(), strain, antibodies.getDouble(strain))); + reporting.reportInfection(new EpisimInitialInfectionEvent(now, getPersonId(), strain, antibodies.getDouble(strain), maxAntibodies.getDouble(strain))); virusStrains.add(strain); setDiseaseStatus(now, EpisimPerson.DiseaseStatus.infectedButNotContagious); diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index bea7705b4..ed2617c4b 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -117,10 +117,6 @@ public void run(int maxIterations) { handler.onSnapshotLoaded(iteration); } - if (episimConfig.getStartFromImmunization() != null) { - handler.initImmunization(Path.of(episimConfig.getStartFromImmunization())); - } - // recalculate antibodies for every agent if starting from snapshot. // The antibodies profile is generated using the immunity event history in the // snapshot; the antibody model config of the snapshot simulation will diff --git a/src/main/java/org/matsim/episim/EpisimUtils.java b/src/main/java/org/matsim/episim/EpisimUtils.java index 5972fa323..b73a6ce71 100644 --- a/src/main/java/org/matsim/episim/EpisimUtils.java +++ b/src/main/java/org/matsim/episim/EpisimUtils.java @@ -61,7 +61,7 @@ public final class EpisimUtils { /** * Seconds in one day. */ - static final double DAY = 24. * 3600; + public static final double DAY = 24. * 3600; private EpisimUtils() { } diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index e1b8622b8..b98d454e2 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -41,7 +41,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.utils.collections.Tuple; -import org.matsim.episim.events.EpisimInfectionEvent; +import org.matsim.episim.events.*; import org.matsim.episim.model.*; import org.matsim.episim.model.activity.ActivityParticipationModel; import org.matsim.episim.model.testing.TestingModel; @@ -49,6 +49,7 @@ import org.matsim.episim.policy.Restriction; import org.matsim.episim.policy.ShutdownPolicy; import org.matsim.facilities.ActivityFacility; +import org.matsim.run.AnalysisCommand; import org.matsim.utils.objectattributes.attributable.Attributes; import org.matsim.vehicles.Vehicle; @@ -63,8 +64,7 @@ import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutorService; -import static org.matsim.episim.EpisimUtils.readChars; -import static org.matsim.episim.EpisimUtils.writeChars; +import static org.matsim.episim.EpisimUtils.*; /** * Main event handler of episim. @@ -778,7 +778,7 @@ public void reset(int iteration) { } } - // uncomment if you want immunisation stats to be printed on a certain + // uncomment if you want immunization stats to be printed on a certain // date or e.g. every month. This produces a lot of large files so use // sparingly. // if (date.getDayOfMonth() == 1) { @@ -998,6 +998,7 @@ void handleEvents(DayOfWeek day, List events) { } + /** * Read immunization history and init persons. */ @@ -1024,6 +1025,31 @@ void initImmunization(Path history) { } + void initImmunization2(Path history) { + + InitialImmunizationHandler handler = new InitialImmunizationHandler(personMap,episimConfig, antibodyModel,progressionModel); + AnalysisCommand.forEachEvent(history, s -> {}, true, handler); + + } + + void restoreDiseaseState(LocalDate first) { + + for (LocalDate date = first; date.isBefore(episimConfig.getStartDate()); date = date.plusDays(1)) { + + //progressionModel.beforeStateUpdates(personMap, i, this.report); + + for (EpisimPerson person : personMap.values()) { + + + //progressionModel.updateState(person, i); + //antibodyModel.updateAntibodies(person, i); + } + + //progressionModel.afterStateUpdates(personMap, i); + + } + } + /** * Container that is always a vehicle. */ diff --git a/src/main/java/org/matsim/episim/analysis/FilterEvents.java b/src/main/java/org/matsim/episim/analysis/FilterEvents.java index 8cf0fb5b5..64e182980 100644 --- a/src/main/java/org/matsim/episim/analysis/FilterEvents.java +++ b/src/main/java/org/matsim/episim/analysis/FilterEvents.java @@ -9,6 +9,8 @@ import org.matsim.api.core.v01.events.Event; import org.matsim.core.events.handler.BasicEventHandler; import org.matsim.episim.events.EpisimInfectionEvent; +import org.matsim.episim.events.EpisimInitialInfectionEvent; +import org.matsim.episim.events.EpisimStartEvent; import org.matsim.episim.events.EpisimVaccinationEvent; import org.matsim.episim.reporting.EpisimWriter; import org.matsim.run.AnalysisCommand; @@ -35,7 +37,7 @@ public class FilterEvents implements OutputAnalysis { private Path output; @CommandLine.Parameters(paramLabel = "TYPE", arity = "0..*", description = "Names of event types to keep") - private Set filter = Set.of(EpisimInfectionEvent.EVENT_TYPE, EpisimVaccinationEvent.EVENT_TYPE); + private Set filter = Set.of(EpisimStartEvent.EVENT_TYPE, EpisimInitialInfectionEvent.EVENT_TYPE, EpisimInfectionEvent.EVENT_TYPE, EpisimVaccinationEvent.EVENT_TYPE); public static void main(String[] args) { System.exit(new CommandLine(new FilterEvents()).execute(args)); diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index e776423f6..d59a043e2 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -402,6 +402,8 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis // } } + + //TODO: add INITIAL INFECTION EVENT @Override public void handleEvent(EpisimInfectionEvent event) { diff --git a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java index 67a04bc02..fd8c19697 100644 --- a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java +++ b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java @@ -35,6 +35,7 @@ import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import java.time.LocalDate; import java.util.Map; import java.util.Stack; @@ -54,6 +55,7 @@ public EpisimEventsReader(EventsManager events) { delegate.addCustomEventMapper(EpisimPersonStatusEvent.EVENT_TYPE, getEpisimPersonStatusEventMapper()); delegate.addCustomEventMapper(EpisimContactEvent.EVENT_TYPE, getEpisimContactEventMapper()); delegate.addCustomEventMapper(EpisimVaccinationEvent.EVENT_TYPE, getEpisimVaccinationEventMapper()); + delegate.addCustomEventMapper(EpisimStartEvent.EVENT_TYPE, getEpisimStartEventMapper()); } public void characters(char[] ch, int start, int length) throws SAXException { @@ -142,7 +144,12 @@ private MatsimEventsReader.CustomEventMapper getEpisimInitialInfectionEventMappe antibodies = Double.parseDouble(attributes.get(EpisimInfectionEvent.ANTIBODIES)); } - return new EpisimInitialInfectionEvent(time, person,virusStrain, antibodies); + double maxAntibodies = -1; + if (attributes.containsKey(EpisimInfectionEvent.MAX_ANTIBODIES)) { + maxAntibodies = Double.parseDouble(attributes.get(EpisimInfectionEvent.MAX_ANTIBODIES)); + } + + return new EpisimInitialInfectionEvent(time, person,virusStrain, antibodies, maxAntibodies); }; } @@ -187,6 +194,17 @@ private MatsimEventsReader.CustomEventMapper getEpisimVaccinationEventMapper() { }; } + private MatsimEventsReader.CustomEventMapper getEpisimStartEventMapper() { + return event -> { + + Map attr = event.getAttributes(); + return new EpisimStartEvent( + LocalDate.parse(attr.get(EpisimStartEvent.START_DATE)), + attr.get(EpisimStartEvent.IMMUNIZATION) + ); + }; + } + @Override public void startTag(String name, Attributes atts, Stack context) { diff --git a/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java b/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java index 00fe8f89c..138d7b8d7 100644 --- a/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java +++ b/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java @@ -14,7 +14,7 @@ */ public class EpisimInitialInfectionEvent extends Event implements HasPersonId, Comparable { - static final String EVENT_TYPE = "episimInitialInfection"; + public static final String EVENT_TYPE = "episimInitialInfection"; private final Id personId; private final VirusStrain virusStrain; @@ -24,12 +24,13 @@ public class EpisimInitialInfectionEvent extends Event implements HasPersonId, C /** * Constructor. */ - public EpisimInitialInfectionEvent(double time, Id personId, VirusStrain strain, double antibodies) { + public EpisimInitialInfectionEvent(double time, Id personId, VirusStrain strain, double antibodies, double maxAntibodies) { super(time); this.personId = personId; this.virusStrain = strain; this.antibodies = antibodies; + this.maxAntibodies = maxAntibodies; } @Override diff --git a/src/main/java/org/matsim/episim/events/EpisimStartEvent.java b/src/main/java/org/matsim/episim/events/EpisimStartEvent.java new file mode 100644 index 000000000..ab9c3142c --- /dev/null +++ b/src/main/java/org/matsim/episim/events/EpisimStartEvent.java @@ -0,0 +1,49 @@ +package org.matsim.episim.events; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.population.Person; +import org.matsim.episim.model.VaccinationType; + +import java.time.LocalDate; +import java.util.Map; + +/** + * Notifies begin of episim simulation + */ +public class EpisimStartEvent extends Event { + + public static final String EVENT_TYPE = "episimStart"; + public static final String START_DATE = "startDate"; + public static final String IMMUNIZATION = "immunization"; + + private final LocalDate startDate; + private final String immunization; + + public EpisimStartEvent(LocalDate startDate, String immunization) { + super(0); + this.startDate = startDate; + this.immunization = immunization; + } + + public LocalDate getStartDate() { + return startDate; + } + + @Override + public String getEventType() { + return EVENT_TYPE; + } + + + + @Override + public Map getAttributes() { + Map attr = super.getAttributes(); + + attr.put(START_DATE, startDate.toString()); + attr.put(IMMUNIZATION, String.valueOf(immunization)); + + return attr; + } +} diff --git a/src/main/java/org/matsim/episim/events/EpisimStartEventHandler.java b/src/main/java/org/matsim/episim/events/EpisimStartEventHandler.java new file mode 100644 index 000000000..8f8aff7e5 --- /dev/null +++ b/src/main/java/org/matsim/episim/events/EpisimStartEventHandler.java @@ -0,0 +1,27 @@ +/* *********************************************************************** * + * project: org.matsim.* + * * + * *********************************************************************** * + * * + * copyright : (C) 2007 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.episim.events; + +import org.matsim.core.events.handler.EventHandler; + +public interface EpisimStartEventHandler extends EventHandler { + void handleEvent(EpisimStartEvent event); + +} diff --git a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java new file mode 100644 index 000000000..59f777743 --- /dev/null +++ b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java @@ -0,0 +1,90 @@ +package org.matsim.episim.events; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.Person; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.EpisimPerson; +import org.matsim.episim.EpisimUtils; +import org.matsim.episim.model.AntibodyModel; +import org.matsim.episim.model.ProgressionModel; + +import java.time.temporal.ChronoUnit; +import java.util.Map; + +import static org.matsim.episim.EpisimUtils.DAY; + +public final class InitialImmunizationHandler implements EpisimVaccinationEventHandler, EpisimInfectionEventHandler, EpisimInitialInfectionEventHandler, EpisimStartEventHandler { + + private final Map, EpisimPerson> personMap; + private final EpisimConfigGroup episimConfig; + private final AntibodyModel antibodyModel; + private final ProgressionModel progressionModel; + + private Double startTimeOffset = null; + + private int iterationOffset; + + int maxIterationReachedSoFar = 0; + + + // 0 1 2 3 4 + // 0 DAY 2Day 3Day 4Day + // startDate + // startDate2 + // -1 0 1 2 + // -86.. 0 86.. + public InitialImmunizationHandler(Map, EpisimPerson> personMap, EpisimConfigGroup episimConfig, AntibodyModel antibodyModel, ProgressionModel progressionModel) { + this.personMap = personMap; + this.episimConfig = episimConfig; + this.antibodyModel = antibodyModel; + this.progressionModel = progressionModel; + } + + @Override + public void handleEvent(EpisimStartEvent event) { + this.iterationOffset = (int) ChronoUnit.DAYS.between(event.getStartDate(), episimConfig.getStartDate()); + this.startTimeOffset = this.iterationOffset * DAY; + } + + + + @Override + public void handleEvent(EpisimInfectionEvent event) { + int currentIteration = (int) (event.getTime() / EpisimUtils.DAY); + if (currentIteration >= iterationOffset + 1) { + return; + } else if (maxIterationReachedSoFar < currentIteration) { + newDay(currentIteration); + } + + personMap.get(event.getPersonId()).setInitialInfection(event.getTime() - startTimeOffset, event.getVirusStrain()); + } + + @Override + public void handleEvent(EpisimInitialInfectionEvent event) { + handleEvent(event.asInfectionEvent()); + } + + @Override + public void handleEvent(EpisimVaccinationEvent event) { + int currentIteration = (int) (event.getTime() / EpisimUtils.DAY); + if (currentIteration >= iterationOffset + 1) { + + return; + } else if (maxIterationReachedSoFar < currentIteration) { + newDay(currentIteration); + } + + personMap.get(event.getPersonId()).setVaccinationStatus(EpisimPerson.VaccinationStatus.yes, event.getVaccinationType(), currentIteration - iterationOffset); + } + + public void newDay(int currentIteration) { + while (this.maxIterationReachedSoFar <= currentIteration) { + this.maxIterationReachedSoFar++; + for (EpisimPerson person : personMap.values()) { + antibodyModel.updateAntibodies(person, this.maxIterationReachedSoFar); + progressionModel.updateState(person, this.maxIterationReachedSoFar); + } + } + } +} diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 3a0be548f..6367d08da 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -43,14 +43,8 @@ public void init(Collection persons, int iteration) { person.setImmuneResponseMultiplier(immuneResponseMultiplier); - for (VirusStrain strain : VirusStrain.values()) { - person.setAntibodies(strain, 0.0); - person.updateMaxAntibodies(strain, 0.0); - } - - // start from snapshot - if (iteration > 1 || episimConfig.getStartFromImmunization() != null) { + if (iteration > 1 && episimConfig.getStartFromSnapshot() != null) { for (int it = 1; it < iteration; it++) { updateAntibodies(person, it); } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java index 55efe1de2..4ea1960f5 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java @@ -392,7 +392,7 @@ public Config prepareConfig(int id, Params params) { //snapshot // episimConfig.setSnapshotInterval(30); // episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip "); + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip"); episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- // S T R A I N S diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunisations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java similarity index 83% rename from src/main/java/org/matsim/run/batch/StartFromImmunisations.java rename to src/main/java/org/matsim/run/batch/StartFromImmunizations.java index cb1175939..cf4d0d659 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunisations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -12,11 +12,8 @@ import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; -import org.matsim.episim.model.listener.HouseholdSusceptibility; import org.matsim.episim.model.vaccination.VaccinationModel; import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; -import org.matsim.episim.policy.FixedPolicy; -import org.matsim.episim.policy.Restriction; import org.matsim.run.RunParallel; import org.matsim.run.modules.SnzCologneProductionScenario; @@ -28,7 +25,7 @@ /** * Batch for Bmbf runs */ -public class StartFromImmunisations implements BatchRun { +public class StartFromImmunizations implements BatchRun { @Nullable @@ -84,7 +81,7 @@ public Collection postProcessing() { // new VaccinationEffectiveness().withArgs(), // new RValuesFromEvents().withArgs(), // new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), -// new FilterEvents().withArgs("--output","./output/"), + new FilterEvents().withArgs("--output","./output/") // new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") // new SecondaryAttackRateFromEvents().withArgs() ); @@ -105,29 +102,29 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot -// episimConfig.setSnapshotInterval(10); -// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - LocalDate startDate = LocalDate.parse("2022-11-01"); - episimConfig.setStartDate(startDate); + episimConfig.setStartDate(LocalDate.parse("2020-03-20")); + episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-03"); // episimConfig.setImmunizationPrefix("imm-" + String.valueOf(params.seed)); // episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/imm-" + String.valueOf(params.seed)+"-960-2022-10-11.tsv.gz"); - episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/imm-4711-210-2020-09-21.tsv.gz"); +// episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/imm-4711-210-2020-09-21.tsv.gz"); // episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA5).put(startDate, 144_380 / 4); +// episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA5).put(startDate, 144_380 / 4); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setSnapshotInterval(10); //--------------------------------------- // S T R A I N S //--------------------------------------- -// VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); -// -// virusStrainConfigGroup.getOrAddParams(VirusStrain.SARS_CoV_2).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.SARS_CoV_2).getInfectiousness() * 10); + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + virusStrainConfigGroup.getOrAddParams(VirusStrain.SARS_CoV_2).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.SARS_CoV_2).getInfectiousness() * 10); return config; @@ -144,10 +141,10 @@ public static final class Params { public static void main(String[] args) { String[] args2 = { - RunParallel.OPTION_SETUP, StartFromImmunisations.class.getName(), + RunParallel.OPTION_SETUP, StartFromImmunizations.class.getName(), RunParallel.OPTION_PARAMS, Params.class.getName(), RunParallel.OPTION_TASKS, Integer.toString(1), - RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_ITERATIONS, Integer.toString(30), RunParallel.OPTION_METADATA }; diff --git a/src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java b/src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java new file mode 100644 index 000000000..0426ae68e --- /dev/null +++ b/src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java @@ -0,0 +1,108 @@ +package org.matsim.episim.events; + +import org.apache.commons.math.stat.inference.TestUtils; +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.Person; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.EventsUtils; +import org.matsim.episim.*; +import org.matsim.episim.model.AntibodyModel; +import org.matsim.episim.model.ProgressionModel; +import org.matsim.episim.model.VaccinationType; +import org.matsim.episim.model.VirusStrain; +import org.mockito.Mockito; + +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertTrue; + +public class InitialImmunizationHandlerTest { + + private EventsManager manager; + private InitialImmunizationHandler handler; + private Map, EpisimPerson> personMap; + + @Before + public void setUp() throws Exception { + + personMap = new HashMap<>(); + + EpisimConfigGroup episimConfig = new EpisimConfigGroup(); + episimConfig.setStartDate(LocalDate.parse("2022-01-05")); + + handler = new InitialImmunizationHandler(personMap, episimConfig, Mockito.mock(AntibodyModel.class), Mockito.mock(ProgressionModel.class)); + + manager = EventsUtils.createEventsManager(); + manager.addHandler(handler); + manager.initProcessing(); + } + + + // 1 2 3 4 5 6 7 8 9 <---- old count + //-3 -2 -1 0 1 2 3 4 5 <---- new count + + /** + * Tests functionality of InitialImmunizationHandler, which reads infection and vaccination events from an immunization + * history in order to initialize the EpisimPerson. + */ + @Test + public void person() { + + // create population of one + EpisimPerson patient0 = EpisimTestUtils.createPerson(); + personMap.put(patient0.getPersonId(), patient0); + + // start date on day 1 + LocalDate date1 = LocalDate.parse("2022-01-01"); // 1 DAY + manager.processEvent(new EpisimStartEvent(date1, "...")); + + // initial infection (from import) on day 2 + manager.processEvent(new EpisimInitialInfectionEvent(2 * EpisimUtils.DAY, patient0.getPersonId(), VirusStrain.SARS_CoV_2, -1, -1)); + + assertThat(patient0.getNumInfections()).isEqualTo(1); + assertThat(patient0.getNumVaccinations()).isEqualTo(0); + assertThat(patient0.getVirusStrain()).isEqualTo(VirusStrain.SARS_CoV_2); + assertThat(patient0.getDiseaseStatus()).isEqualTo(EpisimPerson.DiseaseStatus.infectedButNotContagious); + assertThat(patient0.daysSinceInfection(0, 5)).isEqualTo(7); + assertTrue(patient0.getInfectionDates().contains(-2 * EpisimUtils.DAY)); + + // infection on day 3 + manager.processEvent(new EpisimInfectionEvent(3 * EpisimUtils.DAY, patient0.getPersonId(), patient0.getPersonId(), null, "undefined", 1, VirusStrain.SARS_CoV_2, 1.0, -1,-1)); + + assertThat(patient0.getNumInfections()).isEqualTo(2); + assertThat(patient0.getNumVaccinations()).isEqualTo(0); + assertThat(patient0.getVirusStrain()).isEqualTo(VirusStrain.SARS_CoV_2); + assertThat(patient0.getDiseaseStatus()).isEqualTo(EpisimPerson.DiseaseStatus.infectedButNotContagious); + assertThat(patient0.daysSinceInfection(1, 5)).isEqualTo(6); + assertThat(patient0.getInfectionDates().size()).isEqualTo(2); + assertTrue(patient0.getInfectionDates().contains(-EpisimUtils.DAY)); + + // vaccination on day 4 + manager.processEvent(new EpisimVaccinationEvent(4 * EpisimUtils.DAY, patient0.getPersonId(), VaccinationType.mRNA,1 )); + + assertThat(patient0.getNumInfections()).isEqualTo(2); + assertThat(patient0.getNumVaccinations()).isEqualTo(1); + assertTrue(patient0.hadVaccinationType(VaccinationType.mRNA)); + assertThat(patient0.getVaccinationStatus()).isEqualTo(EpisimPerson.VaccinationStatus.yes); + assertThat(patient0.daysSince(EpisimPerson.VaccinationStatus.yes, 5)).isEqualTo(5); + assertThat(patient0.getVaccinationDates().size()).isEqualTo(1); + assertTrue(patient0.getVaccinationDates().contains(0)); + + // vaccination on day 5 and infection on day 6; neither should be registered because they occur on or after start date of new simulation + manager.processEvent(new EpisimVaccinationEvent(5 * EpisimUtils.DAY, patient0.getPersonId(), VaccinationType.mRNA,1 )); + manager.processEvent(new EpisimInfectionEvent(6 * EpisimUtils.DAY, patient0.getPersonId(), patient0.getPersonId(), null, "undefined", 1, VirusStrain.SARS_CoV_2, 1.0, -1,-1)); + + assertThat(patient0.getNumInfections()).isEqualTo(2); + assertThat(patient0.getInfectionDates().size()).isEqualTo(2); + assertThat(patient0.getNumVaccinations()).isEqualTo(1); + assertThat(patient0.getVaccinationDates().size()).isEqualTo(1); + + + } +} From 574496746fcb83b753ece3ba3476fe36c790a564 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 3 Nov 2022 15:41:11 +0100 Subject: [PATCH 100/128] Changes by chris --- .../java/org/matsim/episim/EpisimPerson.java | 1 + .../java/org/matsim/episim/EpisimReporting.java | 10 +++++++--- .../java/org/matsim/episim/EpisimRunner.java | 6 +++++- .../java/org/matsim/episim/EpisimUtils.java | 4 ++-- .../matsim/episim/InfectionEventHandler.java | 17 ++++++++++++----- .../events/EpisimInitialInfectionEvent.java | 10 ++++++++++ 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index d44fbd63c..e163a8d81 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -435,6 +435,7 @@ public void setInitialInfection(double now, VirusStrain strain) { antibodyLevelAtInfection = antibodies.getDouble(strain); + // TODO: add max antibodies } /** diff --git a/src/main/java/org/matsim/episim/EpisimReporting.java b/src/main/java/org/matsim/episim/EpisimReporting.java index 3830f1801..332fc6804 100644 --- a/src/main/java/org/matsim/episim/EpisimReporting.java +++ b/src/main/java/org/matsim/episim/EpisimReporting.java @@ -920,6 +920,10 @@ synchronized void reportCpuTime(int iteration, String where, String what, int ta String.valueOf(taskId)}); } + void reportStart(LocalDate startDate, String startFromImmunization) { + manager.processEvent(new EpisimStartEvent(startDate, startFromImmunization)); + } + @Override public void close() { @@ -956,11 +960,11 @@ public void close() { public void handleEvent(Event event) { // Events on 0th day are not needed - if (iteration == 0) return; + if (iteration == 0 && !(event instanceof EpisimStartEvent)) return; // Crucial episim events are always written, others only if enabled - if (event instanceof EpisimPersonStatusEvent || event instanceof EpisimInfectionEvent || event instanceof EpisimVaccinationEvent || event instanceof EpisimPotentialInfectionEvent || - event instanceof EpisimInitialInfectionEvent + if (event instanceof EpisimPersonStatusEvent || event instanceof EpisimInfectionEvent || event instanceof EpisimVaccinationEvent || event instanceof EpisimPotentialInfectionEvent + || event instanceof EpisimInitialInfectionEvent || event instanceof EpisimStartEvent || (writeEvents == EpisimConfigGroup.WriteEvents.tracing && event instanceof EpisimTracingEvent) || (writeEvents == EpisimConfigGroup.WriteEvents.tracing && event instanceof EpisimContactEvent)) { diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index ed2617c4b..655f0a108 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -35,6 +35,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.ControlerUtils; import org.matsim.core.gbl.Gbl; +import org.matsim.episim.events.EpisimStartEvent; import org.matsim.episim.model.AntibodyModel; import org.matsim.episim.model.ProgressionModel; @@ -67,7 +68,7 @@ public final class EpisimRunner { @Inject public EpisimRunner(Config config, EventsManager manager, Provider handlerProvider, Provider replay, - Provider reportingProvider, Provider progressionProvider, Provider antibodyModelProvider) { + Provider reportingProvider, Provider progressionProvider, Provider antibodyModelProvider) { this.config = config; this.handlerProvider = handlerProvider; this.manager = manager; @@ -115,6 +116,9 @@ public void run(int maxIterations) { } handler.onSnapshotLoaded(iteration); + } else if (episimConfig.getStartFromImmunization() != null) { + + handler.initImmunization2(Path.of(episimConfig.getStartFromImmunization())); } // recalculate antibodies for every agent if starting from snapshot. diff --git a/src/main/java/org/matsim/episim/EpisimUtils.java b/src/main/java/org/matsim/episim/EpisimUtils.java index b73a6ce71..78cd0cb8f 100644 --- a/src/main/java/org/matsim/episim/EpisimUtils.java +++ b/src/main/java/org/matsim/episim/EpisimUtils.java @@ -565,14 +565,14 @@ public static Map getOutDoorFractionFromDateAndTemp2(File wea double tMax = Double.parseDouble(record.get("tmax")); double prcp = Double.parseDouble(record.get("prcp")); - + if (date.isBefore(LocalDate.parse("2021-01-01"))) { outdoorFractions.put(date, maxOutdoorFraction * getOutDoorFractionFromDateAndTemp(date, TmidSpring2020, TmidFall2020, Trange, tMax, prcp, rainThreshold, alpha)); } else { outdoorFractions.put(date, maxOutdoorFraction * getOutDoorFractionFromDateAndTemp(date, TmidSpring, TmidFall, Trange, tMax, prcp, rainThreshold, alpha)); } - + lastDate = date; } diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index b98d454e2..0676f07aa 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -759,6 +759,9 @@ public void reset(int iteration) { if (paramsMap.size() > 1000) log.warn("Params map contains many entries. Activity types may not be .intern() Strings"); + if (iteration == 1) + reporting.reportStart(episimConfig.getStartDate(), episimConfig.getStartFromImmunization()); + double now = EpisimUtils.getCorrectedTime(episimConfig.getStartOffset(), 0, iteration); LocalDate date = episimConfig.getStartDate().plusDays(iteration - 1); @@ -1005,16 +1008,19 @@ void handleEvents(DayOfWeek day, List events) { void initImmunization(Path history) { log.info("Reading immunization from {}", history); - try (CSVParser parser = new CSVParser(new InputStreamReader(new GzipCompressorInputStream(Files.newInputStream(history))), CSVFormat.TDF.withSkipHeaderRecord())) { + LocalDate first = null; + + try (CSVParser parser = new CSVParser(new InputStreamReader(new GzipCompressorInputStream(Files.newInputStream(history))), CSVFormat.TDF.withFirstRecordAsHeader())) { // initialize parser and skip header row TODO: this should be done automatically but fails - Iterator iterator = parser.iterator(); - iterator.next(); - while (iterator.hasNext()) { - CSVRecord record = iterator.next(); + + for (CSVRecord record : parser) { EpisimPerson person = personMap.get(Id.createPersonId(record.get(0))); LocalDate occurrence = LocalDate.parse(record.get(1)); + if (first == null || occurrence.isBefore(first)) + first = occurrence; + long time = ChronoUnit.DAYS.between(episimConfig.getStartDate(), occurrence); person.addImmunizationRecord(time, record.get(2).equals("virus"), record.get(3)); } @@ -1023,6 +1029,7 @@ void initImmunization(Path history) { throw new UncheckedIOException("Could not read immunization history", e); } + restoreDiseaseState(first); } void initImmunization2(Path history) { diff --git a/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java b/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java index 138d7b8d7..a8d1c1b97 100644 --- a/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java +++ b/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java @@ -20,6 +20,8 @@ public class EpisimInitialInfectionEvent extends Event implements HasPersonId, C private final VirusStrain virusStrain; private final double antibodies; + private final double maxAntibodies; + /** * Constructor. @@ -33,6 +35,13 @@ public EpisimInitialInfectionEvent(double time, Id personId, VirusStrain this.maxAntibodies = maxAntibodies; } + /** + * Return initial infection as "normal" infection event. + */ + public EpisimInfectionEvent asInfectionEvent() { + return new EpisimInfectionEvent(getTime(), personId, null, null, null, -1, virusStrain, 0, antibodies, maxAntibodies); + } + @Override public String getEventType() { return EVENT_TYPE; @@ -52,6 +61,7 @@ public Map getAttributes() { Map attr = super.getAttributes(); attr.put(EpisimInfectionEvent.VIRUS_STRAIN, virusStrain.toString()); attr.put(EpisimInfectionEvent.ANTIBODIES, Double.toString(antibodies)); + attr.put(EpisimInfectionEvent.MAX_ANTIBODIES, Double.toString(maxAntibodies)); return attr; } From 10633fd3dddd3eda408fdce2813adac599cc45dc Mon Sep 17 00:00:00 2001 From: Sydpaltra <61940153+Sydpaltra@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:24:41 +0100 Subject: [PATCH 101/128] checking hospital post processing --- .../episim/analysis/HospitalNumbersFromEvents.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index d59a043e2..493dd3ecc 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -128,7 +128,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { Map.of(VirusStrain.SARS_CoV_2, 15, // Debeka & Ireland studies VirusStrain.ALPHA, 15, // Debeka & Ireland studies VirusStrain.DELTA, 15, // this and following values come from nrw analysis on Tabellenblatt 5 - VirusStrain.OMICRON_BA1, 10, + VirusStrain.OMICRON_BA1, 10, // TODO: Where does this number come from? VirusStrain.OMICRON_BA2, 10, VirusStrain.OMICRON_BA5,10, VirusStrain.STRAIN_A, 10, @@ -137,7 +137,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // ?? private static final Object2IntMap daysInHospitalGivenICU = new Object2IntAVLTreeMap<>( - Map.of(VirusStrain.SARS_CoV_2, 60, + Map.of(VirusStrain.SARS_CoV_2, 60, // TODO: Where does this number come from? VirusStrain.ALPHA, 60, VirusStrain.DELTA, 60, VirusStrain.OMICRON_BA1, 60, @@ -150,7 +150,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double beta = 1.2; - private static final double hospitalFactor = 0.3; + private static final double hospitalFactor = 0.3; // Based on "guess & check", accounts for unreported cases TODO: Potential follow-up // base private static final double factorWild = 1.0; @@ -158,7 +158,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double factorAlpha = 1.0 * factorWild; // delta: 2.3x more severe than alpha - Hospital admission and emergency care attendance risk for SARS-CoV-2 delta (B.1.617.2) compared with alpha (B.1.1.7) variants of concern: a cohort study - private static final double factorDelta = 1.2 * factorWild;//1.6 * factorWild; + private static final double factorDelta = 1.2 * factorWild; //1.6 * factorWild; // omicron: approx 0.3x (intrinsic) severity of delta - Comparative analysis of the risks of hospitalisation and death associated with SARS-CoV-2 omicron (B.1.1.529) and delta (B.1.617.2) variants in England: a cohort study private static final double factorOmicron = 0.45 * factorDelta; // reportedShareOmicron / reportedShareDelta @@ -175,7 +175,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { // ?? - private static final double factorWildAndAlphaICU = 1.; + private static final double factorWildAndAlphaICU = 1.; // TODO : Check literature for reasonable values private static final double factorDeltaICU = 1.; private static final double factorOmicronICU = 1.; private static final double factorBA5ICU = 1.; @@ -520,7 +520,7 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st int inHospital = infectionIteration + lagBetweenInfectionAndHospitalisation.getInt(strain); postProcessHospitalAdmissions.mergeInt(inHospital, 1, Integer::sum); - + // Currently not used TODO : Integrate into Covid-sim plots (i.e. hospitalizations unvaccinated vs vaccinated/boostered) if (person.getNumVaccinations() == 0) { hospNoImmunity.mergeInt(inHospital, 1, Integer::sum); } else if (person.getNumVaccinations() == 1) { From 0e2801f1b5f1fd45eab7cce9088d223d7730e314 Mon Sep 17 00:00:00 2001 From: Sydpaltra <61940153+Sydpaltra@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:25:00 +0100 Subject: [PATCH 102/128] Changes by jakob to hospital post processing --- .../analysis/HospitalNumbersFromEvents.java | 35 +- .../AntibodyDependentTransitionModel.java | 67 +-- .../HospitalNumbersFromEventsTest.java | 479 ++++++++---------- 3 files changed, 235 insertions(+), 346 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 493dd3ecc..b94e77c14 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -57,6 +57,7 @@ name = "hospitalNumbers", description = "Calculate hospital numbers from events" ) + public class HospitalNumbersFromEvents implements OutputAnalysis { // @CommandLine.Option(names = "--output", defaultValue = "./output/") @@ -88,6 +89,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private Population population; + // TODO: check age or strain based lags in literature // source: incidence wave vs. hospitalization wave in cologne/nrw (see https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit?usp=sharing) private static final Object2IntMap lagBetweenInfectionAndHospitalisation = new Object2IntAVLTreeMap<>( Map.of(VirusStrain.SARS_CoV_2, 14, @@ -148,11 +150,11 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { )); + private static final double beta = 1.2; private static final double hospitalFactor = 0.3; // Based on "guess & check", accounts for unreported cases TODO: Potential follow-up - // base private static final double factorWild = 1.0; private static final double factorAlpha = 1.0 * factorWild; @@ -166,7 +168,7 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { private static final double factorBA5 = 1.0 * factorOmicron; // old: 1.5 - private static final double factorScen2 = factorBA5;// reportedShareOmicron / reportedShareDelta + private static final double factorScen2 = factorBA5; // reportedShareOmicron / reportedShareDelta private static final double factorScen3 = factorBA5 * 3;// reportedShareOmicron / reportedShareDelta @@ -186,23 +188,22 @@ public static void main(String[] args) { @Override public Integer call() throws Exception { + // logger configuration Configurator.setLevel("org.matsim.core.config", Level.WARN); Configurator.setLevel("org.matsim.core.controler", Level.WARN); Configurator.setLevel("org.matsim.core.events", Level.WARN); Configurator.setLevel("org.matsim.core.utils", Level.WARN); + // check if events file exists if (!Files.exists(output)) { log.error("Output path {} does not exist.", output); return 2; } - + // read population population = PopulationUtils.readPopulation(input + populationFile); - // Here we define values factorSeriouslySickStrainA should have - - // Part 1: calculate hospitalizations for each seed and save as csv List pathList = new ArrayList<>(); AnalysisCommand.forEachScenario(output, pathToScenario -> { @@ -221,6 +222,7 @@ public Integer call() throws Exception { // Part 2: aggregate over multiple seeds & produce tsv output & plot // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); + //TODO: move to other class HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); @@ -377,6 +379,7 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis this.paxlovidCompliance = paxlovidCompliance; this.paxlovidDay = (int) LocalDate.of(2020, 2, 25).datesUntil(LocalDate.of(2022, 11, 1)).count(); + // key : iteration, value : admissions/filled beds this.postProcessHospitalAdmissions = new Int2IntAVLTreeMap(); this.postProcessICUAdmissions = new Int2IntAVLTreeMap(); this.postProcessHospitalFilledBeds = new Int2IntAVLTreeMap(); @@ -407,6 +410,7 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis @Override public void handleEvent(EpisimInfectionEvent event) { + ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); @@ -418,7 +422,7 @@ public void handleEvent(EpisimInfectionEvent event) { VirusStrain virusStrain = event.getVirusStrain(); person.addInfection(event.getTime()); - person.setAntibodyLevelAtInfection(event.getAntibodies()); +// person.setAntibodyLevelAtInfection(event.getAntibodies()); // commented out as we're only using the max antibody level from now on person.setVirusStrain(virusStrain); person.updateMaxAntibodies(virusStrain, event.getMaxAntibodies()); @@ -504,7 +508,7 @@ private int getAge(Id personId) { */ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain strain, int infectionIteration) { - + // check whether we entered all information for the strain if (!lagBetweenInfectionAndHospitalisation.containsKey(strain) || !lagBetweenHospitalizationAndICU.containsKey(strain) || !daysInHospitalGivenNoICU.containsKey(strain) @@ -514,6 +518,7 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st } + // check if go to hospital if (goToHospital(person, infectionIteration)) { // newly admitted to hospital @@ -573,15 +578,10 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st */ private boolean goToHospital(ImmunizablePerson person, int day) { - - double ageFactor = transitionModel.getProbaOfTransitioningToSeriouslySick(person); double strainFactor = holder.strainConfig.getParams(person.getVirusStrain()).getFactorSeriouslySick(); double immunityFactor = transitionModel.getSeriouslySickFactor(person, holder.vaccinationConfig, day); - - - double paxlovidFactor = 1.0; if (person.getAge() > 60 && day >= this.paxlovidDay) { if (rnd.nextDouble() < this.paxlovidCompliance) { @@ -752,7 +752,7 @@ public int getAge() { * necessary for post processing. * @param */ - private ConfigHolder configure(double facA, double facAICU) { + private static ConfigHolder configure(double facA, double facAICU) { Config config = ConfigUtils.createConfig(new EpisimConfigGroup()); @@ -783,9 +783,6 @@ private ConfigHolder configure(double facA, double facAICU) { strainConfig.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(facA); strainConfig.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(facAICU); - - - // configure vaccinationConfig: set beta factor VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); vaccinationConfig.setBeta(beta); @@ -793,13 +790,13 @@ private ConfigHolder configure(double facA, double facAICU) { return new ConfigHolder(episimConfig, vaccinationConfig, strainConfig); } - private static final class ConfigHolder { + static final class ConfigHolder { private final EpisimConfigGroup episimConfig; private final VaccinationConfigGroup vaccinationConfig; private final VirusStrainConfigGroup strainConfig; - private ConfigHolder(EpisimConfigGroup episimConfig, VaccinationConfigGroup vaccinationConfig, VirusStrainConfigGroup strainConfig) { + ConfigHolder(EpisimConfigGroup episimConfig, VaccinationConfigGroup vaccinationConfig, VirusStrainConfigGroup strainConfig) { this.episimConfig = episimConfig; this.vaccinationConfig = vaccinationConfig; this.strainConfig = strainConfig; diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 90843910e..32e1405c6 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -148,71 +148,20 @@ public double getCriticalFactor(Immunizable person, VaccinationConfigGroup vacci VirusStrain strain = person.getVirusStrain(); - int lastVaccination = 0; - - if (numVaccinations > 0) - lastVaccination = person.getVaccinationDates().getInt(numVaccinations - 1); - - int lastInfection = 0; - - if (numInfections > 0) - lastInfection = (int) (person.getInfectionDates().getDouble(numInfections - 1) / 86400.); - - int lastImmunityEvent = Math.max(lastVaccination, lastInfection); - int daysSinceLastImmunityEvent = day - lastImmunityEvent; - - double antibodiesAfterLastImmunityEvent = person.getAntibodyLevelAtInfection() * Math.pow(2., daysSinceLastImmunityEvent / 60.); + double abNoWaning = person.getMaxAntibodies(strain); // Two modifications to antibody level below: // a) we multiply the antibody level by 4 if the agent is boostered if (numVaccinations > 1) { - antibodiesAfterLastImmunityEvent *= 4; + abNoWaning *= 4; } // b) if strain is omicron, an additional factor of 3.7 is applied if (strain.equals(VirusStrain.OMICRON_BA1) || strain.equals(VirusStrain.OMICRON_BA2)) { - antibodiesAfterLastImmunityEvent *= 3.7; + abNoWaning *= 3.7; } - return 1. / (1. + Math.pow(antibodiesAfterLastImmunityEvent, vaccinationConfig.getBeta())); - -// -// double veSeriouslySick = 0.0; -// -// //vaccinated persons that are boostered either by infection or by 3rd shot -// if (numVaccinations > 1 || (numVaccinations > 0 && numInfections > 1)) { -// if (strain == VirusStrain.OMICRON_BA1 || strain == VirusStrain.OMICRON_BA2) -// veSeriouslySick = 0.9; -// else -// veSeriouslySick = 0.95; -// } -// -// //vaccinated persons or persons who have had a severe course of disease in the past -// // I think this does not work, because old states are removed when changing from recovered to susceptible. SM -// else if (numVaccinations == 1 || person.hadDiseaseStatus(DiseaseStatus.seriouslySick)) { -//// else if (numVaccinations == 1 || person.hadStrain(VirusStrain.SARS_CoV_2) || person.hadStrain(VirusStrain.ALPHA) || person.hadStrain(VirusStrain.DELTA)) -// -// if (strain == VirusStrain.OMICRON_BA1 || strain == VirusStrain.OMICRON_BA2) -// veSeriouslySick = 0.55; -// else -// veSeriouslySick = 0.9; -// } -// -// -// else { -// if (strain == VirusStrain.OMICRON_BA1 || strain == VirusStrain.OMICRON_BA2) -// veSeriouslySick = 0.55; -// else -// veSeriouslySick = 0.6; -// } -// -// double factorInf = person.getImmunityFactor(vaccinationConfig.getBeta()); -// -// double factorSeriouslySick = (1.0 - veSeriouslySick) / factorInf; -// -// factorSeriouslySick = Math.min(1.0, factorSeriouslySick); -// factorSeriouslySick = Math.max(0.0, factorSeriouslySick); -// -// return factorSeriouslySick; + return 1. / (1. + Math.pow(abNoWaning, vaccinationConfig.getBeta())); + } @@ -220,11 +169,5 @@ protected double getProbaOfTransitioningToDeceased(EpisimPerson person) { return 0.0; } -// @Override -// public double getCriticalFactor(Immunizable person, VaccinationConfigGroup vaccinationConfig, int day) { -// return 1.0; -// } -// - } diff --git a/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java b/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java index f7a27e735..6491e0a78 100644 --- a/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java +++ b/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java @@ -1,265 +1,214 @@ -//package org.matsim.episim.analysis; -// -//import org.assertj.core.data.Offset; -//import org.assertj.core.data.Percentage; -//import org.junit.Before; -//import org.junit.Ignore; -//import org.junit.Test; -//import org.matsim.api.core.v01.Id; -//import org.matsim.api.core.v01.IdMap; -//import org.matsim.api.core.v01.Scenario; -//import org.matsim.api.core.v01.population.Person; -//import org.matsim.api.core.v01.population.Population; -//import org.matsim.api.core.v01.population.PopulationFactory; -//import org.matsim.core.config.Config; -//import org.matsim.core.config.ConfigUtils; -//import org.matsim.core.population.PopulationUtils; -//import org.matsim.core.scenario.ScenarioUtils; -//import org.matsim.episim.EpisimConfigGroup; -//import org.matsim.episim.EpisimTestUtils; -//import org.matsim.episim.VaccinationConfigGroup; -//import org.matsim.episim.VirusStrainConfigGroup; -//import org.matsim.episim.events.EpisimInfectionEvent; -//import org.matsim.episim.events.EpisimVaccinationEvent; -//import org.matsim.episim.model.VaccinationType; -//import org.matsim.episim.model.VirusStrain; -//import org.matsim.facilities.Facility; -//import org.matsim.testcases.MatsimTestUtils; -// -//import java.util.HashMap; -//import java.util.Map; -// -//import static org.junit.Assert.*; -//import static org.assertj.core.api.Assertions.assertThat; -// -//public class HospitalNumbersFromEventsTest { -// -// -// private HospitalNumbersFromEvents.Handler handler; -// private Population population; -// private final int populationSize = 1_000_000; -// private VirusStrainConfigGroup strainConfig; -// -// @Before -// public void setUp() throws Exception { -// -// // instantiate configs -// Config config = ConfigUtils.createConfig(new EpisimConfigGroup()); -// EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); -// strainConfig = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); -// VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); -// -// -// // create population -// final Scenario scenario = ScenarioUtils.createScenario(config); -// PopulationFactory popFac = scenario.getPopulation().getFactory(); -// population = scenario.getPopulation(); -// -// -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// Person person = popFac.createPerson(personId); -// person.getAttributes().putAttribute("microm:modeled:age", 25); -// person.getAttributes().putAttribute("district", "Köln"); -// population.addPerson(person); -// } -// -// // instantiate event handler -// Map, HospitalNumbersFromEvents.Handler.ImmunizablePerson> data = new IdMap<>(Person.class, population.getPersons().size()); -// handler = new HospitalNumbersFromEvents.Handler(data, population, episimConfig, strainConfig, vaccinationConfig); -// -// } -// -// /** -// * check's that once a vaccination or infection event is logged, the person is entered into the "data" of the handler. -// */ -// @Test -// public void testHandlerData() { -// -// Id personId1 = Id.createPersonId(1); -// assertThat(handler.data.isEmpty()).isTrue(); -// handler.handleEvent(new EpisimVaccinationEvent(0., personId1, VaccinationType.mRNA, 1)); -// assertThat(handler.data.isEmpty()).isFalse(); -// assertThat(handler.data.containsKey(personId1)).isTrue(); -// -// handler.data.clear(); -// -// assertThat(handler.data.isEmpty()).isTrue(); -// handler.handleEvent(new EpisimInfectionEvent(0., personId1, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.)); -// assertThat(handler.data.isEmpty()).isFalse(); -// assertThat(handler.data.containsKey(personId1)).isTrue(); -// -// -// // strain config -// -// // immunity config -// -//// handler.handleEvent(); -// -// } -// -// /** -// * Age-dependent probability of being admitted to the hospital given infection matches configuration. -// * In addition, probability of transitioning to critical (ICU) given hospitalization is checked. -// * Test is applied to 25 year-olds and 75 year-olds. -// */ -// @Ignore -// @Test -// public void testAgeComponent() { -// -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.)); -// } -// -// int hospitalizations25 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icu25 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// assertThat((double) hospitalizations25 / populationSize).isCloseTo(0.024, Percentage.withPercentage(2)); -// assertThat((double) icu25 / hospitalizations25).isCloseTo(0.15, Percentage.withPercentage(2)); -// -// handler.data.clear(); -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// Person person = population.getPersons().get(personId); -// person.getAttributes().putAttribute("microm:modeled:age", 75); -// handler.handleEvent(new EpisimInfectionEvent(10 * 24 * 3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.)); -// } -// -// int hospitalizations75 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icu75 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// -// assertThat((double) hospitalizations75 / populationSize).isCloseTo(0.23, Percentage.withPercentage(2)); -// assertThat((double) icu75 / hospitalizations75).isCloseTo(0.41, Percentage.withPercentage(2)); -// -// assertThat(hospitalizations75).isGreaterThan(hospitalizations25); -// assertThat(icu75).isGreaterThan(icu25); -// } -// -// /** -// * Checks differences in strain configuration when age & immunity is constant. In this scenario, a lower chance of -// * hospitalization (0.6x) and lower chance of ICU (0.8x) is associated with Omicron BA.1 as compared to the wild type -// */ -// @Test -// public void testStrainComponent() { -// -// // set up strain configuration -// strainConfig.getParams(VirusStrain.SARS_CoV_2).setFactorSeriouslySick(1.); -// strainConfig.getParams(VirusStrain.SARS_CoV_2).setFactorCritical(1.); -// -// strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorSeriouslySick(0.6); -// strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorCritical(0.8); -// -// -// // calculate hospitalizations/ICU for wild type -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.)); -// } -// -// int hospitalizations100 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icu100 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// handler.data.clear(); -// -// -// // calculate hospitalizations/ICU for omicron -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// handler.handleEvent(new EpisimInfectionEvent(100*24*3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.OMICRON_BA1, 0., 0.)); -// } -// -// int hospitalizations60 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icu80 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// // omicron hospitalizations should be 0.6x wild type hospitalizations (see factorSeriouslySick above) -// assertThat(((double) hospitalizations60) / hospitalizations100).isCloseTo(0.6, Percentage.withPercentage(2)); -// -// // The chance to visit icu given hospitalization (factorCritical) for omicron should be 0.8x wild typ. -// // However, the chance of going to the hospital at all is also lower for omicron (see above assert). -// // Thus we need to multiply the two probabilities 0.8*0.6 -// assertThat(((double) icu80) / icu100).isCloseTo(0.8 * 0.6, Percentage.withPercentage(2)); -// -// } -// -// @Ignore -// @Test -// public void testImmunityComponent() { -// -// // calculate hospitalizations/ICU for people without any antibodies -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.)); -// } -// -// int hospitalizationsNoImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icuNoImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// // calculate hospitalizations/ICU for people with antibodies -// // this time we do not clear the the handler.data, because we need to know how long ago their last immunity event was. -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// handler.handleEvent(new EpisimInfectionEvent(10*24*3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 10.)); -// } -// -// int hospitalizationsWithImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icuWithImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// assertThat(hospitalizationsWithImmunity).isGreaterThan(hospitalizationsNoImmunity); -// assertThat(icuWithImmunity).isGreaterThan(icuNoImmunity); -// -// } -// -// @Test -// public void testImmunityComponent2() { -// -// // expected value (2 doses mRNA vs. DELTA) prob w/ respect to unvaccinated individual -// // p(hosp) of vaccinated person w/ respect to unvaccianted -//// double pHosp = 1. - 0.95; -//// // p(symptoms) -//// double pSym = 1. - 0.75; -//// // p(hosp|symptoms) -// -// strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1); -// double pHospGivenSym = 0.1; -// -// // calculate hospitalizations/ICU for people without any antibodies -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.OMICRON_BA1, 0., 0.)); -// } -// -// int hospitalizationsNoImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icuNoImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// // calculate hospitalizations/ICU for people with antibodies -// // this time we do not clear the the handler.data, because we need to know how long ago their last immunity event was. -// handler.postProcessICUAdmissions.clear(); -// handler.postProcessHospitalAdmissions.clear(); -// handler.data.clear(); -// -// for (int i = 0; i < populationSize; i++) { -// Id personId = Id.createPersonId(i); -// handler.handleEvent(new EpisimVaccinationEvent(0., personId, VaccinationType.mRNA, 1)); -// handler.handleEvent(new EpisimInfectionEvent(1.5 * 24 * 3600, personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.OMICRON_BA1, 0., 1.9)); -// } -// -// int hospitalizationsWithImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); -// int icuWithImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); -// -// -// double probHosp = ((double) hospitalizationsWithImmunity) / hospitalizationsNoImmunity; -// -// return; -// -//// assertThat(hospitalizationsWithImmunity).isGreaterThan(hospitalizationsNoImmunity); -//// assertThat(icuWithImmunity).isGreaterThan(icuNoImmunity); -// -// } -// -// -// -// -// -//} +package org.matsim.episim.analysis; + +import org.assertj.core.data.Percentage; +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.IdMap; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.population.Person; +import org.matsim.api.core.v01.population.Population; +import org.matsim.api.core.v01.population.PopulationFactory; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.EpisimUtils; +import org.matsim.episim.VaccinationConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.events.EpisimInfectionEvent; +import org.matsim.episim.events.EpisimVaccinationEvent; +import org.matsim.episim.model.VaccinationType; +import org.matsim.episim.model.VirusStrain; +import org.matsim.facilities.Facility; +import java.util.Map; + +import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.matsim.episim.analysis.HospitalNumbersFromEvents.*; + +public class HospitalNumbersFromEventsTest { + + + private Handler handler; + private Population population; + private final int populationSize = 1_000_000; + private VirusStrainConfigGroup strainConfig; + + @Before + public void setUp() throws Exception { + + // instantiate configs + Config config = ConfigUtils.createConfig(new EpisimConfigGroup()); + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + strainConfig = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + + + // create population + final Scenario scenario = ScenarioUtils.createScenario(config); + PopulationFactory popFac = scenario.getPopulation().getFactory(); + population = scenario.getPopulation(); + + + for (int i = 0; i < populationSize; i++) { + Id personId = Id.createPersonId(i); + Person person = popFac.createPerson(personId); + person.getAttributes().putAttribute("microm:modeled:age", 25); + person.getAttributes().putAttribute("district", "Köln"); + population.addPerson(person); + } + + // instantiate event handler + Map, Handler.ImmunizablePerson> data = new IdMap<>(Person.class, population.getPersons().size()); + ConfigHolder configHolder = new ConfigHolder(episimConfig,vaccinationConfig,strainConfig); + + handler = new Handler("xxx", population, configHolder, 0.); + + } + + /** + * check's that once a vaccination or infection event is logged, the person is entered into the "data" of the handler. + */ + @Test + public void testHandlerData() { + + + // before any events, data should be empty + Id personId1 = Id.createPersonId(1); + assertTrue(handler.data.isEmpty()); + + // add vaccination event - data should contain person1 + handler.handleEvent(new EpisimVaccinationEvent(0., personId1, VaccinationType.mRNA, 1)); + assertFalse(handler.data.isEmpty()); + assertTrue(handler.data.containsKey(personId1)); + + handler.data.clear(); + + // same thing for infection event + assertTrue(handler.data.isEmpty()); + handler.handleEvent(new EpisimInfectionEvent(0., personId1, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.,0.)); + assertFalse(handler.data.isEmpty()); + assertTrue(handler.data.containsKey(personId1)); + + } + + /** + * Age-dependent probability of being admitted to the hospital given infection matches configuration. + * In addition, probability of transitioning to critical (ICU) given hospitalization is checked. + * Test is applied to 25 year-olds and 75 year-olds. + */ + + @Test + public void testAgeComponent() { + + + // infect every person an infection + for (int i = 0; i < populationSize; i++) { + Id personId = Id.createPersonId(i); + handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + } + + // extract total number of hospitalisations + int hospitalizations25 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); + int icu25 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); + + assertThat((double) hospitalizations25 / populationSize).isCloseTo(0.024, Percentage.withPercentage(2)); + assertThat((double) icu25 / hospitalizations25).isCloseTo(0.15, Percentage.withPercentage(2)); + + + // Now, check for 75+ year olds + handler.data.clear(); + for (int i = 0; i < populationSize; i++) { + Id personId = Id.createPersonId(i); + Person person = population.getPersons().get(personId); + person.getAttributes().putAttribute("microm:modeled:age", 75); + handler.handleEvent(new EpisimInfectionEvent(10 * 24 * 3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + } + + int hospitalizations75 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); + int icu75 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); + + + assertThat((double) hospitalizations75 / populationSize).isCloseTo(0.23, Percentage.withPercentage(2)); + assertThat((double) icu75 / hospitalizations75).isCloseTo(0.41, Percentage.withPercentage(2)); + + assertThat(hospitalizations75).isGreaterThan(hospitalizations25); + assertThat(icu75).isGreaterThan(icu25); + } + + /** + * Checks differences in strain configuration when age & immunity is constant. In this scenario, a lower chance of + * hospitalization (0.6x) and lower chance of ICU (0.8x) is associated with Omicron BA.1 as compared to the wild type + */ + @Test + public void testStrainComponent() { + + // set up strain configuration + strainConfig.getParams(VirusStrain.SARS_CoV_2).setFactorSeriouslySick(1.); + strainConfig.getParams(VirusStrain.SARS_CoV_2).setFactorCritical(1.); + + strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorSeriouslySick(0.6); + strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorCritical(0.8); + + + // calculate hospitalizations/ICU for wild type + for (int i = 0; i < populationSize; i++) { + Id personId = Id.createPersonId(i); + handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + } + + int hospitalizations100 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); + int icu100 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); + + handler.data.clear(); + + + // calculate hospitalizations/ICU for omicron + for (int i = 0; i < populationSize; i++) { + Id personId = Id.createPersonId(i); + handler.handleEvent(new EpisimInfectionEvent(100 * 24 * 3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.OMICRON_BA1, 0., 0., 0.)); + } + + int hospitalizations60 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); + int icu80 = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); + + // omicron hospitalizations should be 0.6x wild type hospitalizations (see factorSeriouslySick above) + assertThat(((double) hospitalizations60) / hospitalizations100).isCloseTo(0.6, Percentage.withPercentage(2)); + + // The chance to visit icu given hospitalization (factorCritical) for omicron should be 0.8x wild type. + // However, the chance of going to the hospital at all is also lower for omicron (see above assert). + // Thus, we need to multiply the two probabilities 0.8*0.6. + assertThat(((double) icu80) / icu100).isCloseTo(0.8 * 0.6, Percentage.withPercentage(2)); + + } + + + @Test + public void testImmunityComponent() { + + // calculate hospitalizations/ICU for people without any antibodies + for (int i = 0; i < populationSize; i++) { + Id personId = Id.createPersonId(i); + handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + } + + int hospitalizationsNoImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); + int icuNoImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); + + handler.data.clear(); + + for (int i = 0; i < populationSize; i++) { + Id personId = Id.createPersonId(i); + handler.handleEvent(new EpisimInfectionEvent(10 * EpisimUtils.DAY, personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + handler.handleEvent(new EpisimInfectionEvent(15 * EpisimUtils.DAY, personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 50.)); + } + + int hospitalizationsWithImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); + int icuWithImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); + +// assertThat(hospitalizationsWithImmunity).isLessThan(hospitalizationsNoImmunity); +// assertThat(icuWithImmunity).isLessThan(icuNoImmunity); + return; + } +} From 17ed326ba2959210c3389fcb207deb7ab0d1c114 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 4 Nov 2022 09:38:49 +0100 Subject: [PATCH 103/128] wip: snapshot lite --- .../java/org/matsim/episim/EpisimRunner.java | 8 +-- .../matsim/episim/InfectionEventHandler.java | 49 ------------------- .../analysis/HospitalNumbersFromEvents.java | 10 ++-- .../events/InitialImmunizationHandler.java | 1 - .../matsim/run/CreateBatteryForCluster.java | 4 +- .../batch/CologneBMBF20221024_snapshot.java | 40 ++++++++++----- .../run/batch/StartFromImmunizations.java | 8 +-- 7 files changed, 44 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index 655f0a108..bae0b6d8d 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -35,7 +35,6 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.ControlerUtils; import org.matsim.core.gbl.Gbl; -import org.matsim.episim.events.EpisimStartEvent; import org.matsim.episim.model.AntibodyModel; import org.matsim.episim.model.ProgressionModel; @@ -46,7 +45,6 @@ import java.time.DayOfWeek; import java.util.List; import java.util.Map; -import java.util.Random; /** * Main entry point and runner of one epidemic simulation. @@ -105,7 +103,9 @@ public void run(int maxIterations) { Path output = Path.of(config.controler().getOutputDirectory()); int iteration = 1; - if (episimConfig.getStartFromSnapshot() != null) { + if (episimConfig.getStartFromSnapshot() != null && episimConfig.getStartFromImmunization() != null) { + throw new RuntimeException("Cannot start from snapshot and immunization history simultaneously. Choose one."); + } else if (episimConfig.getStartFromSnapshot() != null) { reporting.close(); iteration = readSnapshot(output, Path.of(episimConfig.getStartFromSnapshot())); try { @@ -118,7 +118,7 @@ public void run(int maxIterations) { handler.onSnapshotLoaded(iteration); } else if (episimConfig.getStartFromImmunization() != null) { - handler.initImmunization2(Path.of(episimConfig.getStartFromImmunization())); + handler.initImmunization(Path.of(episimConfig.getStartFromImmunization())); } // recalculate antibodies for every agent if starting from snapshot. diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 0676f07aa..d0527be9e 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -26,10 +26,6 @@ import com.google.inject.util.Types; import com.typesafe.config.ConfigFactory; import it.unimi.dsi.fastutil.objects.*; -import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVParser; -import org.apache.commons.csv.CSVRecord; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; @@ -54,11 +50,9 @@ import org.matsim.vehicles.Vehicle; import java.io.*; -import java.nio.file.Files; import java.nio.file.Path; import java.time.DayOfWeek; import java.time.LocalDate; -import java.time.temporal.ChronoUnit; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -1009,54 +1003,11 @@ void initImmunization(Path history) { log.info("Reading immunization from {}", history); - LocalDate first = null; - - try (CSVParser parser = new CSVParser(new InputStreamReader(new GzipCompressorInputStream(Files.newInputStream(history))), CSVFormat.TDF.withFirstRecordAsHeader())) { - // initialize parser and skip header row TODO: this should be done automatically but fails - - for (CSVRecord record : parser) { - EpisimPerson person = personMap.get(Id.createPersonId(record.get(0))); - LocalDate occurrence = LocalDate.parse(record.get(1)); - - if (first == null || occurrence.isBefore(first)) - first = occurrence; - - long time = ChronoUnit.DAYS.between(episimConfig.getStartDate(), occurrence); - person.addImmunizationRecord(time, record.get(2).equals("virus"), record.get(3)); - } - - } catch (IOException e) { - throw new UncheckedIOException("Could not read immunization history", e); - } - - restoreDiseaseState(first); - } - - void initImmunization2(Path history) { - InitialImmunizationHandler handler = new InitialImmunizationHandler(personMap,episimConfig, antibodyModel,progressionModel); AnalysisCommand.forEachEvent(history, s -> {}, true, handler); } - void restoreDiseaseState(LocalDate first) { - - for (LocalDate date = first; date.isBefore(episimConfig.getStartDate()); date = date.plusDays(1)) { - - //progressionModel.beforeStateUpdates(personMap, i, this.report); - - for (EpisimPerson person : personMap.values()) { - - - //progressionModel.updateState(person, i); - //antibodyModel.updateAntibodies(person, i); - } - - //progressionModel.afterStateUpdates(personMap, i); - - } - } - /** * Container that is always a vehicle. */ diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index d59a043e2..a6423acbe 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -332,7 +332,7 @@ static int getWeeklyHospitalizations(Int2IntMap hospMap, Integer today) { } - public static final class Handler implements EpisimVaccinationEventHandler, EpisimInfectionEventHandler { + public static final class Handler implements EpisimVaccinationEventHandler, EpisimInfectionEventHandler, EpisimInitialInfectionEventHandler{ final Map, ImmunizablePerson> data; private final String name; private final Population population; @@ -486,11 +486,15 @@ public void handleEvent(EpisimVaccinationEvent event) { person.addVaccination(day); } + @Override + public void handleEvent(EpisimInitialInfectionEvent event) { + handleEvent(event.asInfectionEvent()); + } + private int getAge(Id personId) { return (int) population.getPersons().get(personId).getAttributes().getAttribute("microm:modeled:age"); } - /* % infected who get paxlovid (for a certain age group): @@ -502,6 +506,7 @@ private int getAge(Id personId) { */ + private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain strain, int infectionIteration) { @@ -611,7 +616,6 @@ private boolean goToICU(ImmunizablePerson person, int day) { } - /** * Data holder for attributes */ diff --git a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java index 59f777743..ed09adbcc 100644 --- a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java +++ b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java @@ -69,7 +69,6 @@ public void handleEvent(EpisimInitialInfectionEvent event) { public void handleEvent(EpisimVaccinationEvent event) { int currentIteration = (int) (event.getTime() / EpisimUtils.DAY); if (currentIteration >= iterationOffset + 1) { - return; } else if (maxIterationReachedSoFar < currentIteration) { newDay(currentIteration); diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 0f3ed3168..b04f74800 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20221024_snapshot") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20221024_snapshot$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java index ac54be48a..5207efff8 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java @@ -389,9 +389,15 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + if (!params.startDate.equals("fromTheStart")) { + episimConfig.setStartDate(LocalDate.parse(params.startDate)); + episimConfig.setStartFromImmunization("");//TODO!!! + episimConfig.setImmunizationPrefix(String.valueOf(params.seed)); //TODO + } + //snapshot - episimConfig.setSnapshotInterval(30); - episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setSnapshotInterval(30); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); // episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- @@ -558,12 +564,14 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); - Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); +// Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); //StrainA if (!params.StrainA.equals("off")) { infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); - LocalDate strADate = LocalDate.parse("2022-11-01"); +// LocalDate strADate = LocalDate.parse("2022-11-01"); + LocalDate strADate = LocalDate.parse(params.strainADate); + for (int i = 0; i < 7; i++) { infPerDayStrA.put(strADate.plusDays(i), 4); } @@ -582,13 +590,13 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi // add projected disease import for vacation waves after initial disease import - int facBa2 = 4; - int facBa5 = 4; - int facStrAB = 4; - - LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import - LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import - LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import +// int facBa2 = 4; +// int facBa5 = 4; +// int facStrAB = 4; +// +// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import +// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import +// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import // String importSummer2022 = "off"; // if (importSummer2022.equals("on")) { @@ -648,11 +656,14 @@ public static final class Params { @GenerateSeeds(5) public long seed; + @StringParameter({"fromTheStart","2020-06-01", "2020-12-01", "2021-06-01", "2021-12-01", "2022-06-01", "2022-09-15"}) + public String startDate; + //IFSG @StringParameter({"base"}) public String ifsg; - // Vacciantion Campaign + // Vaccination Campaign @StringParameter({"base"}) String vacCamp; @@ -668,9 +679,12 @@ public static final class Params { @StringParameter({"base"}) public String edu; - @StringParameter({"6.0"}) + @StringParameter({"3.0"}) public String StrainA; + @StringParameter({"2022-09-19"}) + public String strainADate; + } diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java index cf4d0d659..d395936f5 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -103,7 +103,7 @@ public Config prepareConfig(int id, Params params) { //snapshot - episimConfig.setStartDate(LocalDate.parse("2020-03-20")); + episimConfig.setStartDate(LocalDate.parse("2020-02-29")); episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-03"); // episimConfig.setImmunizationPrefix("imm-" + String.valueOf(params.seed)); @@ -122,9 +122,9 @@ public Config prepareConfig(int id, Params params) { // S T R A I N S //--------------------------------------- - VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); - - virusStrainConfigGroup.getOrAddParams(VirusStrain.SARS_CoV_2).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.SARS_CoV_2).getInfectiousness() * 10); +// VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.SARS_CoV_2).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.SARS_CoV_2).getInfectiousness() * 10); return config; From 7a44b457ce6a4bc736a5f51cb9f42572d9f5662f Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 4 Nov 2022 14:46:18 +0100 Subject: [PATCH 104/128] wip: snapshot lite --- .../java/org/matsim/episim/EpisimPerson.java | 13 ++++++-- .../java/org/matsim/episim/EpisimRunner.java | 2 +- .../matsim/episim/InfectionEventHandler.java | 8 ++++- .../events/InitialImmunizationHandler.java | 30 ++++++++++++++++--- .../java/org/matsim/run/AnalysisCommand.java | 22 ++++++++++++-- .../batch/CologneBMBF20221024_snapshot.java | 4 +-- .../run/batch/StartFromImmunizations.java | 4 +-- 7 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index e163a8d81..a8b84cd21 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -155,7 +155,7 @@ public final class EpisimPerson implements Immunizable, Attributable { /** * Iteration when this person got into quarantine. Negative if person was never quarantined. */ - private int quarantineDate = -1; + private int quarantineDate = Integer.MIN_VALUE; /** * Iteration when this person was tested. Negative if person was never tested. @@ -707,15 +707,22 @@ public boolean hadStrain(VirusStrain strain) { /** * Days elapsed since person was put into quarantine. * + * Doesn't check if person has ever been in quarantine + * * @param currentDay current day (iteration) * @apiNote This is currently not used much and may change similar to {@link #daysSince(DiseaseStatus, int)}. */ @Beta public int daysSinceQuarantine(int currentDay) { - // yyyy since this API is so unstable, I would prefer to have the class non-public. kai, apr'20 // -> api now marked as unstable and containing an api note, because it is used by the models it has to be public. chr, apr'20 - if (quarantineDate < 0) throw new IllegalStateException("Person was never quarantined"); + + //check removed; when starting simulation with immunisation history, quarantine date can very well be negative. -jr, nov'22 + if (quarantineDate == Integer.MIN_VALUE) { + + throw new IllegalStateException("Person was never quarantined"); + + } return currentDay - quarantineDate; } diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index bae0b6d8d..44813edd9 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -127,7 +127,7 @@ public void run(int maxIterations) { // be superceded by the config of the current simulation. Thus, the antibody development // during the snapshot can be rewritten without modifying the immunity event history. - antibodyModel.init(handler.getPersons(), iteration); + antibodyModel.init(handler.getPersons(), iteration); reporting.reportCpuTime(0, "Init", "finished", -1); diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index d0527be9e..057001ce6 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -1004,7 +1004,13 @@ void initImmunization(Path history) { log.info("Reading immunization from {}", history); InitialImmunizationHandler handler = new InitialImmunizationHandler(personMap,episimConfig, antibodyModel,progressionModel); - AnalysisCommand.forEachEvent(history, s -> {}, true, handler); + //TODO: change history from folder -> file + List days = AnalysisCommand.forEachEvent(history, handler, true, handler); + + + if (handler.isContinueProcessingEvents()) { + throw new RuntimeException("Immunisation history is not long enough (only contains " + days.size() + "days)"); + } } diff --git a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java index ed09adbcc..f4f1e0127 100644 --- a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java +++ b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java @@ -7,6 +7,7 @@ import org.matsim.episim.EpisimUtils; import org.matsim.episim.model.AntibodyModel; import org.matsim.episim.model.ProgressionModel; +import org.matsim.episim.model.VirusStrain; import java.time.temporal.ChronoUnit; import java.util.Map; @@ -51,18 +52,22 @@ public void handleEvent(EpisimStartEvent event) { @Override public void handleEvent(EpisimInfectionEvent event) { int currentIteration = (int) (event.getTime() / EpisimUtils.DAY); - if (currentIteration >= iterationOffset + 1) { + if (currentIteration >= iterationOffset + 1) { // starts returning when current iteration = 5 + continueProcessingEvents = false; return; } else if (maxIterationReachedSoFar < currentIteration) { newDay(currentIteration); } + //TODO why should this be an initial infection? personMap.get(event.getPersonId()).setInitialInfection(event.getTime() - startTimeOffset, event.getVirusStrain()); } @Override public void handleEvent(EpisimInitialInfectionEvent event) { + handleEvent(event.asInfectionEvent()); + } @Override @@ -78,12 +83,29 @@ public void handleEvent(EpisimVaccinationEvent event) { } public void newDay(int currentIteration) { - while (this.maxIterationReachedSoFar <= currentIteration) { + while (this.maxIterationReachedSoFar < currentIteration) { this.maxIterationReachedSoFar++; for (EpisimPerson person : personMap.values()) { - antibodyModel.updateAntibodies(person, this.maxIterationReachedSoFar); - progressionModel.updateState(person, this.maxIterationReachedSoFar); + antibodyModel.updateAntibodies(person, this.maxIterationReachedSoFar - this.iterationOffset); + progressionModel.updateState(person, this.maxIterationReachedSoFar - this.iterationOffset); + +// if (person.getPersonId().toString().equals("1238c80")) { +// System.out.println("it " + currentIteration + ", " + person.getAntibodies(VirusStrain.SARS_CoV_2)); +// System.out.println(" " + person.getDiseaseStatus()); +// System.out.println(" " + person.getQuarantineStatus()); +// +// } } } } + + @Override + public Boolean apply(String s) { + return continueProcessingEvents; + } + + public boolean isContinueProcessingEvents() { + return continueProcessingEvents; + } } + diff --git a/src/main/java/org/matsim/run/AnalysisCommand.java b/src/main/java/org/matsim/run/AnalysisCommand.java index 09eaf9c72..e80f247ff 100644 --- a/src/main/java/org/matsim/run/AnalysisCommand.java +++ b/src/main/java/org/matsim/run/AnalysisCommand.java @@ -42,6 +42,7 @@ import java.nio.file.Path; import java.util.*; import java.util.function.Consumer; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; @@ -106,6 +107,16 @@ public static void forEachScenario(Path output, Consumer function) throws }); } + /** + * See {@link #forEachEvent(Path, Function, boolean, EventHandler...)}. Callback will always return true. + */ + public static List forEachEvent(Path scenario, Consumer callback, boolean preferReducedEvents, EventHandler... handler) { + return forEachEvent(scenario, s-> { + callback.accept(s); + return true; + }, preferReducedEvents, handler); + } + /** * Reads in all event file from a scenario. * @@ -115,7 +126,7 @@ public static void forEachScenario(Path output, Consumer function) throws * @param handler handler for the events * @return list of read event files */ - public static List forEachEvent(Path scenario, Consumer callback, boolean preferReducedEvents, EventHandler... handler) { + public static List forEachEvent(Path scenario, Function callback, boolean preferReducedEvents, EventHandler... handler) { Path events = getEvents(scenario, preferReducedEvents); if (events == null) { @@ -146,7 +157,9 @@ public static List forEachEvent(Path scenario, Consumer callback for (Path p : eventFiles) { try { String name = p.getFileName().toString(); - callback.accept(name); + if (!callback.apply(name)) { + break; + } new EpisimEventsReader(manager).readFile(p.toString()); read.add(name); @@ -160,7 +173,10 @@ public static List forEachEvent(Path scenario, Consumer callback ArchiveEntry entry; while ((entry = ar.getNextEntry()) != null) { - callback.accept(entry.getName()); + + if (!callback.apply(entry.getName())) { + break; + } new EpisimEventsReader(manager).parse(new NonClosingGZIPStream(ar)); diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java index 5207efff8..c39f68081 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java @@ -391,8 +391,8 @@ public Config prepareConfig(int id, Params params) { if (!params.startDate.equals("fromTheStart")) { episimConfig.setStartDate(LocalDate.parse(params.startDate)); - episimConfig.setStartFromImmunization("");//TODO!!! - episimConfig.setImmunizationPrefix(String.valueOf(params.seed)); //TODO + episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/2022-11-04/1-snap/immunisation-history/");//TODO!!! +// episimConfig.setImmunizationPrefix(String.valueOf(params.seed)); //TODO } //snapshot diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java index d395936f5..4d52a0fa5 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -103,8 +103,8 @@ public Config prepareConfig(int id, Params params) { //snapshot - episimConfig.setStartDate(LocalDate.parse("2020-02-29")); - episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-03"); + episimConfig.setStartDate(LocalDate.parse("2020-03-29")); + episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-03xsfdsadfasdfasdf"); // episimConfig.setImmunizationPrefix("imm-" + String.valueOf(params.seed)); From 82fdb094323daa75c744f00038710843122fdd87 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 4 Nov 2022 14:46:29 +0100 Subject: [PATCH 105/128] Changes by chris --- src/main/java/org/matsim/episim/InfectionEventHandler.java | 1 + .../matsim/episim/events/InitialImmunizationHandler.java | 7 ++++++- src/main/java/org/matsim/run/AnalysisCommand.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 057001ce6..cac1d0345 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -57,6 +57,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutorService; +import java.util.function.Function; import static org.matsim.episim.EpisimUtils.*; diff --git a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java index f4f1e0127..0d0961161 100644 --- a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java +++ b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java @@ -11,10 +11,13 @@ import java.time.temporal.ChronoUnit; import java.util.Map; +import java.util.function.Function; import static org.matsim.episim.EpisimUtils.DAY; -public final class InitialImmunizationHandler implements EpisimVaccinationEventHandler, EpisimInfectionEventHandler, EpisimInitialInfectionEventHandler, EpisimStartEventHandler { +public final class InitialImmunizationHandler implements Function, + EpisimVaccinationEventHandler, EpisimInfectionEventHandler, + EpisimInitialInfectionEventHandler, EpisimStartEventHandler { private final Map, EpisimPerson> personMap; private final EpisimConfigGroup episimConfig; @@ -24,6 +27,7 @@ public final class InitialImmunizationHandler implements EpisimVaccinationEventH private Double startTimeOffset = null; private int iterationOffset; + private boolean continueProcessingEvents = true; int maxIterationReachedSoFar = 0; @@ -74,6 +78,7 @@ public void handleEvent(EpisimInitialInfectionEvent event) { public void handleEvent(EpisimVaccinationEvent event) { int currentIteration = (int) (event.getTime() / EpisimUtils.DAY); if (currentIteration >= iterationOffset + 1) { + continueProcessingEvents = false; return; } else if (maxIterationReachedSoFar < currentIteration) { newDay(currentIteration); diff --git a/src/main/java/org/matsim/run/AnalysisCommand.java b/src/main/java/org/matsim/run/AnalysisCommand.java index e80f247ff..69457a09c 100644 --- a/src/main/java/org/matsim/run/AnalysisCommand.java +++ b/src/main/java/org/matsim/run/AnalysisCommand.java @@ -121,7 +121,7 @@ public static List forEachEvent(Path scenario, Consumer callback * Reads in all event file from a scenario. * * @param scenario path of the scenario, which contains the event folder - * @param callback will be executed before reading an event file and pass the path + * @param callback will be executed before reading an event file and pass the path. If false is returned, no more events will be read. * @param preferReducedEvents * @param handler handler for the events * @return list of read event files From e38dc4fb8e09154b28e0ea2bde4fcf36e489f69e Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Fri, 4 Nov 2022 15:21:51 +0100 Subject: [PATCH 106/128] count total contacts --- .../org/matsim/episim/EpisimReporting.java | 14 ++++++ .../matsim/episim/InfectionEventHandler.java | 5 ++ .../org/matsim/episim/TrajectoryHandler.java | 21 ++++++--- .../episim/model/AbstractContactModel.java | 10 ++++ .../org/matsim/episim/model/ContactModel.java | 8 ++++ .../episim/model/SymmetricContactModel.java | 3 ++ .../model/listener/WriteContactsPerDay.java | 46 +++++++++++++++++++ 7 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java diff --git a/src/main/java/org/matsim/episim/EpisimReporting.java b/src/main/java/org/matsim/episim/EpisimReporting.java index 332fc6804..633b25754 100644 --- a/src/main/java/org/matsim/episim/EpisimReporting.java +++ b/src/main/java/org/matsim/episim/EpisimReporting.java @@ -67,6 +67,7 @@ */ public final class EpisimReporting implements BasicEventHandler, Closeable, Externalizable { + /** * Age groups used for various outputs. AgeGroup -> minimum age of age group. * Important: age groups must be in descending order @@ -129,6 +130,8 @@ public enum AgeGroup { private final NumberFormat decimalFormat = DecimalFormat.getInstance(Locale.GERMAN); private final double sampleSize; + private int totalContacts; + /** * Whether all events are written into one file. */ @@ -719,6 +722,17 @@ public synchronized void reportContact(double now, EpisimPerson person, EpisimPe } + /** + * Set number of total contacts. + * @param totalContacts + */ + public void reportTotalContacts(int totalContacts) { + this.totalContacts = totalContacts; + } + + public int getTotalContacts() { + return totalContacts; + } /** * Report the successful tracing between two persons. diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index cac1d0345..1811fbd83 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -990,6 +990,11 @@ void handleEvents(DayOfWeek day, List events) { infections.stream().sorted() .forEach(reporting::reportInfection); + + int totalContacts = handlers.stream().mapToInt(TrajectoryHandler::getNumContacts).sum(); + + reporting.reportTotalContacts(totalContacts); + for (SimulationListener l : listener) { l.onIterationEnd(iteration, episimConfig.getStartDate().plusDays(iteration - 1)); } diff --git a/src/main/java/org/matsim/episim/TrajectoryHandler.java b/src/main/java/org/matsim/episim/TrajectoryHandler.java index 2326e9a7f..d15d55f92 100644 --- a/src/main/java/org/matsim/episim/TrajectoryHandler.java +++ b/src/main/java/org/matsim/episim/TrajectoryHandler.java @@ -46,9 +46,9 @@ final class TrajectoryHandler { @Inject public TrajectoryHandler(EpisimConfigGroup episimConfig, EpisimReporting reporting, ContactModel model, SplittableRandom rnd, - @Named("personMap") Map, EpisimPerson> personMap, - @Named("vehicleMap") Map, InfectionEventHandler.EpisimVehicle> vehicleMap, - @Named("pseudoFacilityMap") Map, InfectionEventHandler.EpisimFacility> pseudoFacilityMap) { + @Named("personMap") Map, EpisimPerson> personMap, + @Named("vehicleMap") Map, InfectionEventHandler.EpisimVehicle> vehicleMap, + @Named("pseudoFacilityMap") Map, InfectionEventHandler.EpisimFacility> pseudoFacilityMap) { this.rnd = rnd; this.episimConfig = episimConfig; this.reporting = reporting; @@ -68,6 +68,13 @@ void setRestrictionsForIteration(int iteration, ImmutableMap @@ -132,7 +139,7 @@ void checkAndHandleEndOfNonCircularTrajectory(EpisimPerson person, DayOfWeek day * @param responsible predicate for checking if the handler is responsible for a certain facility */ public void onStartDay(Predicate> responsibleFacility, - Predicate> responsibleVehicle) { + Predicate> responsibleVehicle) { double now = EpisimUtils.getCorrectedTime(episimConfig.getStartOffset(), 0, iteration); DayOfWeek day = EpisimUtils.getDayOfWeek(episimConfig, iteration); @@ -263,7 +270,7 @@ public void handleEvent(ActivityEndEvent activityEndEvent) { reporting.handleEvent(activityEndEvent); if (episimConfig.getContagiousOptimization() == EpisimConfigGroup.ContagiousOptimization.no || - episimFacility.containsContagious()) { + episimFacility.containsContagious()) { contactModel.infectionDynamicsFacility(episimPerson, episimFacility, now); } @@ -311,8 +318,8 @@ public void handleEvent(PersonLeavesVehicleEvent leavesVehicleEvent) { reporting.handleEvent(leavesVehicleEvent); - if (episimConfig.getContagiousOptimization() == EpisimConfigGroup.ContagiousOptimization.no || - episimVehicle.containsContagious()) { + if (episimConfig.getContagiousOptimization() == EpisimConfigGroup.ContagiousOptimization.no || + episimVehicle.containsContagious()) { contactModel.infectionDynamicsVehicle(episimPerson, episimVehicle, now); } diff --git a/src/main/java/org/matsim/episim/model/AbstractContactModel.java b/src/main/java/org/matsim/episim/model/AbstractContactModel.java index c7f6389f9..3226c2084 100644 --- a/src/main/java/org/matsim/episim/model/AbstractContactModel.java +++ b/src/main/java/org/matsim/episim/model/AbstractContactModel.java @@ -72,6 +72,11 @@ public abstract class AbstractContactModel implements ContactModel { protected DayOfWeek day; private Map restrictions; + /** + * Count number of contacts per day. + */ + protected int numContacts = 0; + /** * Curfew compliance valid for the day. */ @@ -355,6 +360,11 @@ public void setRestrictionsForIteration(int iteration, Map this.infectionModel.setIteration(iteration); this.curfewCompliance = EpisimUtils.findValidEntry(episimConfig.getCurfewCompliance(), 1.0, episimConfig.getStartDate().plusDays(iteration - 1)); + this.numContacts = 0; + } + + public int getNumContacts() { + return numContacts; } /** diff --git a/src/main/java/org/matsim/episim/model/ContactModel.java b/src/main/java/org/matsim/episim/model/ContactModel.java index 1cee7e9ca..bb56340c2 100644 --- a/src/main/java/org/matsim/episim/model/ContactModel.java +++ b/src/main/java/org/matsim/episim/model/ContactModel.java @@ -35,12 +35,14 @@ public interface ContactModel { * This method is called when a persons leave a vehicle at {@code now}. */ void infectionDynamicsVehicle(EpisimPerson personLeavingVehicle, InfectionEventHandler.EpisimVehicle vehicle, double now); + void notifyEnterVehicle(EpisimPerson personEnteringVehicle, InfectionEventHandler.EpisimVehicle vehicle, double now); /** * This method is called when a persons leaves a facility at {@code now}. */ void infectionDynamicsFacility(EpisimPerson personLeavingFacility, InfectionEventHandler.EpisimFacility facility, double now); + void notifyEnterFacility(EpisimPerson personEnteringFacility, InfectionEventHandler.EpisimFacility facility, double now); /** @@ -48,4 +50,10 @@ public interface ContactModel { */ void setRestrictionsForIteration(int iteration, Map restrictions); + /** + * Number of processed contacts for the day. + */ + int getNumContacts(); + + } diff --git a/src/main/java/org/matsim/episim/model/SymmetricContactModel.java b/src/main/java/org/matsim/episim/model/SymmetricContactModel.java index 0b51b8382..a1f456915 100644 --- a/src/main/java/org/matsim/episim/model/SymmetricContactModel.java +++ b/src/main/java/org/matsim/episim/model/SymmetricContactModel.java @@ -131,6 +131,9 @@ private void infectionDynamicsGeneralized(EpisimPerson personLeavingContainer, E continue; } + // counted as contact + numContacts++; + // we have thrown the random numbers, so we can bail out in some cases if we are not tracking: if (!trackingEnabled) { if (personLeavingContainer.getDiseaseStatus() == DiseaseStatus.infectedButNotContagious) { diff --git a/src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java b/src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java new file mode 100644 index 000000000..f9eafbb30 --- /dev/null +++ b/src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java @@ -0,0 +1,46 @@ +package org.matsim.episim.model.listener; + +import com.google.inject.Inject; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.Person; +import org.matsim.episim.EpisimPerson; +import org.matsim.episim.EpisimReporting; +import org.matsim.episim.InfectionEventHandler; +import org.matsim.episim.model.SimulationListener; +import org.matsim.episim.model.VirusStrain; +import org.matsim.facilities.ActivityFacility; +import org.matsim.vehicles.Vehicle; + +import java.io.BufferedWriter; +import java.time.LocalDate; +import java.util.Arrays; +import java.util.Map; +import java.util.SplittableRandom; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * Writes contacts for each day. + */ +public class WriteContactsPerDay implements SimulationListener { + + private Map, EpisimPerson> persons; + @Inject + private EpisimReporting reporting; + private BufferedWriter writer; + + @Override + public void init(SplittableRandom rnd, Map, EpisimPerson> persons, Map, InfectionEventHandler.EpisimFacility> facilities, Map, InfectionEventHandler.EpisimVehicle> vehicles) { + this.persons = persons; + this.writer = reporting.registerWriter("contactsPerDay.tsv"); + this.reporting.writeAsync(writer, "date\tavgContacts"); + this.persons = persons; + } + + @Override + public void onIterationEnd(int iteration, LocalDate date) { + + reporting.writeAsync(writer, date + "\t" + reporting.getTotalContacts() / (double) persons.size()); + + } +} From b3e3e16f281b593a848458b58c8e65457dfb67b4 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Fri, 4 Nov 2022 16:34:38 +0100 Subject: [PATCH 107/128] change how writer is initialized --- .../episim/model/listener/WriteContactsPerDay.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java b/src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java index f9eafbb30..0f37ea086 100644 --- a/src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java +++ b/src/main/java/org/matsim/episim/model/listener/WriteContactsPerDay.java @@ -32,15 +32,17 @@ public class WriteContactsPerDay implements SimulationListener { @Override public void init(SplittableRandom rnd, Map, EpisimPerson> persons, Map, InfectionEventHandler.EpisimFacility> facilities, Map, InfectionEventHandler.EpisimVehicle> vehicles) { this.persons = persons; - this.writer = reporting.registerWriter("contactsPerDay.tsv"); - this.reporting.writeAsync(writer, "date\tavgContacts"); - this.persons = persons; } @Override public void onIterationEnd(int iteration, LocalDate date) { - reporting.writeAsync(writer, date + "\t" + reporting.getTotalContacts() / (double) persons.size()); + if (writer == null) { + writer = reporting.registerWriter("contactsPerDay.tsv"); + reporting.writeAsync(writer, "date\tavgContacts\n"); + } + + reporting.writeAsync(writer, date + "\t" + reporting.getTotalContacts() / (double) persons.size() + "\n"); } } From feb61b608bc9fe8eeb0898ff5a001378730f4928 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Tue, 8 Nov 2022 17:53:29 +0100 Subject: [PATCH 108/128] set max line length --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index e7006ed3c..428584c7e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,6 +10,7 @@ charset = utf-8 indent_style = tab insert_final_newline = true trim_trailing_whitespace = true +max_line_length = 150 [Makefile] indent_style = tab \ No newline at end of file From 1ec186a133c5bbfd511bd36c14443e335081ca3b Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Wed, 9 Nov 2022 11:06:22 +0100 Subject: [PATCH 109/128] add viewer version 2 to metadata --- src/main/java/org/matsim/run/CreateBatteryForCluster.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index b04f74800..87caf2b4f 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -262,6 +262,7 @@ static void writeMetadata(Path dir, PreparedRun run) throws IOException { metadata.put("info", "_info.txt"); metadata.put("zipFolder", "summaries"); metadata.put("timestamp", LocalDate.now()); + metadata.put("viewerVersion", 2); metadata.putAll(run.getMetadata()); mapper.writeValue(yamlWriter, metadata); From 02431d0b198acc75045a9589df4e0b0b8aa126d9 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Wed, 9 Nov 2022 16:44:16 +0100 Subject: [PATCH 110/128] fix bug where multiple listener where created when loading from snapshot --- src/main/java/org/matsim/episim/InfectionEventHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 1811fbd83..f04276210 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -560,8 +560,7 @@ void updateEvents(Map> events) { */ void onSnapshotLoaded(int iteration) { - listener = (Set) injector.getInstance(Key.get(Types.setOf(SimulationListener.class))); - vaccinations = (Set) injector.getInstance(Key.get(Types.setOf(VaccinationModel.class))); + // Listener and vaccinations should already be present for (SimulationListener s : listener) { s.onSnapshotLoaded(iteration, localRnd, personMap, pseudoFacilityMap, vehicleMap); From 039420ac0fb0693ec3c09b13b5a4b069d400c282 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Thu, 10 Nov 2022 10:56:43 +0100 Subject: [PATCH 111/128] catch error with empty data --- src/main/python/analysis/utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/python/analysis/utils.py b/src/main/python/analysis/utils.py index 88cf77079..82075b6bf 100644 --- a/src/main/python/analysis/utils.py +++ b/src/main/python/analysis/utils.py @@ -217,9 +217,15 @@ def aggregate_batch_run(run): if idx not in idMap or f.endswith(".xml"): continue - with z.open(f) as zf: - df = pd.read_csv(zf, sep="\t") - runs[idMap[idx]][filename].append(df) + with z.open(f) as zf: + try: + df = pd.read_csv(zf, sep="\t") + runs[idMap[idx]][filename].append(df) + except pd.errors.EmptyDataError as e: + print("WARN: " + f + " is empty") + except: + print("Error reading " + f) + with zipfile.ZipFile(run.replace(".zip", "-aggr.zip"), mode="w", compresslevel=9, From aa6689936041d11f650e84902fa9dff11e35dcef Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Thu, 10 Nov 2022 15:41:13 +0100 Subject: [PATCH 112/128] first implementation of "variant soup" --- .../model/InfectionModelWithAntibodies.java | 5 +- .../org/matsim/episim/model/VirusStrain.java | 20 ++- .../AntibodyDependentTransitionModel.java | 4 +- .../model/testing/DefaultTestingModel.java | 11 +- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../matsim/run/batch/CologneBMBF202212XX.java | 150 ++++++++++++++++-- 6 files changed, 179 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java index 3b1f76e8c..7949eec38 100644 --- a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java +++ b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java @@ -109,7 +109,10 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto igaFactor = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); } else if (vaccinationConfig.getUseIgA()) { - List crossImmunityStrainsOmicron = List.of(VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A, VirusStrain.STRAIN_B); + List crossImmunityStrainsOmicron = List.of(VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A, VirusStrain.STRAIN_B, + VirusStrain.STRAIN_C, VirusStrain.STRAIN_D, VirusStrain.STRAIN_E, VirusStrain.STRAIN_F, VirusStrain.STRAIN_G, VirusStrain.STRAIN_H, VirusStrain.STRAIN_I, + VirusStrain.STRAIN_J, VirusStrain.STRAIN_K); + if(crossImmunityStrainsOmicron.contains(infector.getVirusStrain())){ int lastInfectionWithStrain = 0; diff --git a/src/main/java/org/matsim/episim/model/VirusStrain.java b/src/main/java/org/matsim/episim/model/VirusStrain.java index cb117106c..b58738bc9 100644 --- a/src/main/java/org/matsim/episim/model/VirusStrain.java +++ b/src/main/java/org/matsim/episim/model/VirusStrain.java @@ -40,6 +40,24 @@ public enum VirusStrain implements ImmunityEvent { STRAIN_A, - STRAIN_B + STRAIN_B, + + STRAIN_C, + + STRAIN_D, + + STRAIN_E, + + STRAIN_F, + + STRAIN_G, + + STRAIN_H, + + STRAIN_I, + + STRAIN_J, + + STRAIN_K } diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 32e1405c6..2a664d603 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -128,7 +128,9 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup abNoWaning *= 4; } // b) if strain is omicron, an additional factor of 3.7 is applied - if (strain.equals(VirusStrain.OMICRON_BA1) || strain.equals(VirusStrain.OMICRON_BA2) || strain.equals(VirusStrain.OMICRON_BA5) || strain.equals(VirusStrain.STRAIN_A) || strain.equals(VirusStrain.STRAIN_B)) { + if (strain.equals(VirusStrain.OMICRON_BA1) || strain.equals(VirusStrain.OMICRON_BA2) || strain.equals(VirusStrain.OMICRON_BA5) || strain.equals(VirusStrain.STRAIN_A) || strain.equals(VirusStrain.STRAIN_B) + || strain.equals(VirusStrain.STRAIN_C) || strain.equals(VirusStrain.STRAIN_D) || strain.equals(VirusStrain.STRAIN_E) || strain.equals(VirusStrain.STRAIN_F) || strain.equals(VirusStrain.STRAIN_G) + || strain.equals(VirusStrain.STRAIN_H) || strain.equals(VirusStrain.STRAIN_I) || strain.equals(VirusStrain.STRAIN_J) || strain.equals(VirusStrain.STRAIN_K)) { abNoWaning *= 3.7; } diff --git a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java index 09b447c84..b39678d8f 100644 --- a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java +++ b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java @@ -207,7 +207,16 @@ protected boolean testAndQuarantine(EpisimPerson person, int day, TestingConfigG person.getVirusStrain() == VirusStrain.OMICRON_BA2 || person.getVirusStrain() == VirusStrain.OMICRON_BA5 || person.getVirusStrain() == VirusStrain.STRAIN_A || - person.getVirusStrain() == VirusStrain.STRAIN_B)) { + person.getVirusStrain() == VirusStrain.STRAIN_B || + person.getVirusStrain() == VirusStrain.STRAIN_C || + person.getVirusStrain() == VirusStrain.STRAIN_D || + person.getVirusStrain() == VirusStrain.STRAIN_E || + person.getVirusStrain() == VirusStrain.STRAIN_F || + person.getVirusStrain() == VirusStrain.STRAIN_G || + person.getVirusStrain() == VirusStrain.STRAIN_H || + person.getVirusStrain() == VirusStrain.STRAIN_I || + person.getVirusStrain() == VirusStrain.STRAIN_J || + person.getVirusStrain() == VirusStrain.STRAIN_K)) { rate = 0.5; } diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 87caf2b4f..7c2b07d0d 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF20221024_snapshot") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF20221024_snapshot$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java index 4ea1960f5..55bb52b81 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java @@ -22,6 +22,7 @@ import javax.annotation.Nullable; import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.*; @@ -101,9 +102,12 @@ protected void configure() { double mutEscBa1 = 10.9 / 1.9; double mutEscBa5 = 5.0; - double mutEscStrainA = 0.; - double mutEscStrainB = 0.; - + double mutEscStrainA = 1.0; + double mutEscStrainB = 1.0; + + double escape = 12.; + int days = 30; + String strainSeed = "no"; if (params != null) { // mutEscBa1 = params.ba1Esc; @@ -119,13 +123,16 @@ protected void configure() { if (!StrainB.equals("off")) { mutEscStrainB = Double.parseDouble(StrainB); } + escape = params.escape; + days = params.days; + strainSeed = params.strainRnd; } //initial antibodies Map> initialAntibodies = new HashMap<>(); Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB, escape, days, strainSeed); AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); @@ -152,7 +159,7 @@ protected void configure() { private void configureAntibodies(Map> initialAntibodies, Map> antibodyRefreshFactors, - double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB, double escapePerYear, int days, String strainSeed) { for (VaccinationType immunityType : VaccinationType.values()) { initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -298,6 +305,58 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + { + + ArrayList strains = getNewStrains(); + + ArrayList dates = getDatesNewStrains(strains, days, strainSeed); + + for (int i = 0; i < strains.size(); i++) { + long daysSince = LocalDate.parse("2022-11-15").datesUntil(dates.get(i)).count(); + double escape = 1. + (escapePerYear - 1.0) * daysSince / 365.; //factor 6, if variant appears 6 months later + VirusStrain strain = strains.get(i); + + initialAntibodies.get(strain).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(strain).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(strain).put(VirusStrain.DELTA, 0.01); + + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA / escape); + initialAntibodies.get(strain).put(VirusStrain.STRAIN_A, 64.0 / 300. / escape); + + double mRNAStrain = mRNAStrainA / escape; + initialAntibodies.get(VaccinationType.mRNA).put(strain, mRNAStrain); + initialAntibodies.get(VaccinationType.vector).put(strain, mRNAStrain * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(strain, mRNAStrain * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(strain, mRNAStrain * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(strain, mRNAStrain * 8./20.); + + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(strain, 64.0 / 300. / mutEscBa5 /mutEscStrainA / escape); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(strain, 64.0 / 300./ mutEscBa5 /mutEscStrainA / escape); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(strain, 64.0 / 300. / mutEscStrainA / escape); + initialAntibodies.get(VirusStrain.STRAIN_A).put(strain, 64.0 / 300. / escape); + // initialAntibodies.get(VirusStrain.STRAIN_B).put(strain, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5 / escape); + initialAntibodies.get(VaccinationType.ba1Update).put(strain, mRNAAlpha / mutEscBa5 / mutEscStrainA / escape); + initialAntibodies.get(VaccinationType.ba5Update).put(strain, mRNAAlpha / mutEscStrainA / escape); + + + for (int j = 0; j < strains.size(); j++) { + LocalDate date1 = dates.get(i); + LocalDate date2 = dates.get(j); + long daysBetweenStrains = Math.abs(ChronoUnit.DAYS.between(date1, date2)); + double escapeBetweenStrains = 1. + (escapePerYear - 1.0) * daysBetweenStrains / 365.; //factor 6, if variant appears 6 months later + VirusStrain strain2 = strains.get(j); + initialAntibodies.get(strain).put(strain2, 64.0 / 300. / escapeBetweenStrains); + } + + } + + + } + for (VaccinationType immunityType : VaccinationType.values()) { @@ -392,8 +451,8 @@ public Config prepareConfig(int id, Params params) { //snapshot // episimConfig.setSnapshotInterval(30); // episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip"); - episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- // S T R A I N S //--------------------------------------- @@ -411,6 +470,13 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); } + + for (VirusStrain strain : getNewStrains()) { + virusStrainConfigGroup.getOrAddParams(strain).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(strain).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(strain).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(strain).setFactorCritical(ba5Hos); + } // STRAIN_B // if (!params.StrainB.equals("off")) { @@ -571,6 +637,20 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } + + + for (int i = 0; i < getNewStrains().size(); i++) { + LocalDate date = getDatesNewStrains(getNewStrains(), params.days, params.strainRnd).get(i); + VirusStrain strain = getNewStrains().get(i); + + Map infPerDayStrainX = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(strain, new TreeMap<>())); + infPerDayStrainX.put(LocalDate.parse("2020-01-01"), 0); + for (int j = 0; j < 7; j++) { + infPerDayStrainX.put(date.plusDays(j), 4); + } + infPerDayStrainX.put(date.plusDays(7), 1); + episimConfig.setInfections_pers_per_day(strain, infPerDayStrainX); + } //StrainB // if (!params.StrainB.equals("off")) { @@ -670,11 +750,22 @@ public static final class Params { @StringParameter({"base"}) public String edu; - @StringParameter({"off","3.0","4.0","5.0","6.0"}) +// @StringParameter({"off","3.0","4.0","5.0","6.0"}) + @StringParameter({"off", "1.7"}) public String StrainA; - @StringParameter({"2022-08-15", "2022-08-22", "2022-08-29", "2022-09-05", "2022-09-12", "2022-09-19", "2022-09-26"}) +// @StringParameter({"2022-08-15", "2022-08-22", "2022-08-29", "2022-09-05", "2022-09-12", "2022-09-19", "2022-09-26"}) + @StringParameter({"2022-09-12"}) public String strainADate; + + @Parameter({6., 12., 24.}) + public double escape; + + @IntParameter({30, 90, 180}) + public int days; + + @StringParameter({"1", "2", "3", "no"}) + public String strainRnd; } @@ -691,6 +782,47 @@ public static void main(String[] args) { RunParallel.main(args2); } + + private static ArrayList getNewStrains() { + ArrayList strains = new ArrayList(); + strains.add(VirusStrain.STRAIN_C); + strains.add(VirusStrain.STRAIN_D); + strains.add(VirusStrain.STRAIN_E); + strains.add(VirusStrain.STRAIN_F); + strains.add(VirusStrain.STRAIN_G); + strains.add(VirusStrain.STRAIN_H); + strains.add(VirusStrain.STRAIN_I); + strains.add(VirusStrain.STRAIN_J); + strains.add(VirusStrain.STRAIN_K); + return strains; + } + + private static ArrayList getDatesNewStrains(ArrayList strains, int days, String seed) { + ArrayList dates = new ArrayList(); + + if (seed.equals("no")) { + for (LocalDate date = LocalDate.parse("2022-11-15"); ; date = date.plusDays(1)) { + long daysBetween = ChronoUnit.DAYS.between(LocalDate.parse("2022-11-15"), date); + if (daysBetween % days == 0) + dates.add(date); + if (dates.size() == strains.size()) + break; + } + return dates; + } + + else { + Random rand = new Random(Integer.parseInt(seed)); + for (LocalDate date = LocalDate.parse("2022-11-15"); ; date = date.plusDays(1)) { + if (rand.nextDouble() < 1. / days) + dates.add(date); + if (dates.size() == strains.size()) + break; + } + return dates; + } + + } } From ffd4ab923ea1c43a9afa49a85c0900b5f3038eb7 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 15 Nov 2022 14:49:46 +0100 Subject: [PATCH 113/128] bug fix, fix start from snapshot (too high antibodies at beginning --- src/main/R/analyseCases.R | 79 +++++++++++++++++ .../java/org/matsim/episim/EpisimPerson.java | 26 +++--- .../java/org/matsim/episim/EpisimRunner.java | 85 ++++++++++--------- .../matsim/episim/InfectionEventHandler.java | 4 + .../events/InitialImmunizationHandler.java | 3 +- .../matsim/episim/model/AntibodyModel.java | 2 + .../episim/model/DefaultAntibodyModel.java | 38 ++++++--- .../batch/CologneBMBF20221024_snapshot.java | 49 +++++++---- .../run/batch/StartFromImmunizations.java | 20 ++--- .../modules/SnzCologneProductionScenario.java | 2 +- 10 files changed, 213 insertions(+), 95 deletions(-) create mode 100644 src/main/R/analyseCases.R diff --git a/src/main/R/analyseCases.R b/src/main/R/analyseCases.R new file mode 100644 index 000000000..ef1b7fd1c --- /dev/null +++ b/src/main/R/analyseCases.R @@ -0,0 +1,79 @@ +library(lubridate) +library(tidyverse) +library(readr) + + + +rm(list=ls()) +source("/Users/jakob/git/matsim-episim/src/main/R/masterJR-utils.R", encoding = 'utf-8') + +# directory_snap <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-05/2-imm-snap/" +directory_snap <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-15/1-imm-snap/" +directory_imm <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-05/2b-imm-hist/" +# file_root<- "antibodies.tsv" + +#infections +file_root_inf<- "infections.txt.csv" +snap_inf_raw <- read_combine_episim_output_zipped(directory_snap, file_root_inf ) +imm_inf_raw <- read_combine_episim_output_zipped(directory_imm, file_root_inf) + + +start_date <- ymd("2021-11-15") +end_date <- ymd("2029-07-05") +snap_inf <- snap_inf_raw %>% + filter(date >= start_date) %>% + filter(date <= end_date) %>% + filter(pHh == 0.0, immuneSigma == 0.0) + # mutate(vax = generic + mRNA + vector + ba1Update + ba5Update + natural) +imm_inf <- imm_inf_raw %>% + filter(date >= start_date) %>% + filter(date <= end_date) %>% + filter(pHh == 0.0, immuneSigma == 0.0) + # mutate(vax = generic + mRNA + vector + ba1Update + ba5Update + natural) +ggplot() + #nShowingSymptoms # SARS_CoV_2 + geom_line(imm_inf, mapping = aes(date, nShowingSymptoms , group = seed, col = "imm-hist")) + + geom_line(snap_inf, mapping = aes(date, nShowingSymptoms , group = seed, col = "snapshot")) + + scale_color_manual(name='Regression Model', + breaks=c('snapshot', 'imm-hist'), + values=c('snapshot'='red', 'imm-hist'='blue'))+ + ggtitle("Infections") + + +# antibodies +file_root_ab<- "antibodies.tsv" +snap_ab_raw <- read_combine_episim_output_zipped(directory_snap, file_root_ab ) +imm_ab_raw <- read_combine_episim_output_zipped(directory_imm, file_root_ab) + + +start_date <- ymd("2021-11-15") +end_date <- ymd("2021-11-30") +snap_ab <- snap_ab_raw %>% + filter(date >= start_date) %>% + filter(date <= end_date) %>% + filter(pHh == 0.0, immuneSigma == 0.0) +# mutate(vax = generic + mRNA + vector + ba1Update + ba5Update + natural) +imm_ab <- imm_ab_raw %>% + filter(date >= start_date) %>% + filter(date <= end_date) %>% + filter(pHh == 0.0, immuneSigma == 0.0) +# mutate(vax = generic + mRNA + vector + ba1Update + ba5Update + natural) +ggplot() + #nShowingSymptoms # SARS_CoV_2 + geom_line(imm_ab, mapping = aes(date, SARS_CoV_2 , group = seed, col = "imm-hist")) + + geom_line(snap_ab, mapping = aes(date, SARS_CoV_2 , group = seed, col = "snapshot")) + + scale_color_manual(name='Regression Model', + breaks=c('snapshot', 'imm-hist'), + values=c('snapshot'='red', 'imm-hist'='blue'))+ + ggtitle("Antibodies") + + + + + # scale_colour_manual(name = "scenario", values = c("red"="red", "blue"="blue"), labels = c("snapshot", "immune history")) + + # facet_wrap(pHh ~ immuneSigma) + +# antibodies are a bit lower for immune history people +# jump in snapshot on first day is a bit sus... (maybe there is something wrong there..., not with immune history)) +# what happens to Antibodies from June 30 to July 1?? Why do they jump? + +# infections: now imm-Hist (blue) run has lower case numbers... too many antibodies or whats going on? +# but blue also has slightly lower antibodies. How can this be? \ No newline at end of file diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index a8b84cd21..03144dfdb 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -438,19 +438,19 @@ public void setInitialInfection(double now, VirusStrain strain) { // TODO: add max antibodies } - /** - * Add an infection or vaccination from immunization history. - */ - void addImmunizationRecord(double time, boolean virus, String type) { - - if (virus) { - virusStrains.add(VirusStrain.valueOf(type)); - infectionDates.add(time * DAY); - } else { - vaccinations.add(VaccinationType.valueOf(type)); - vaccinationDates.add((int) time); - } - } +// /** +// * Add an infection or vaccination from immunization history. +// */ +// void addImmunizationRecord(double time, boolean virus, String type) { +// +// if (virus) { +// virusStrains.add(VirusStrain.valueOf(type)); +// infectionDates.add(time * DAY); +// } else { +// vaccinations.add(VaccinationType.valueOf(type)); +// vaccinationDates.add((int) time); +// } +// } /** * Adds an infection possibility to this person. Will be executed in {@link #checkInfection()} diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index 44813edd9..5aa9ea791 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -116,19 +116,22 @@ public void run(int maxIterations) { } handler.onSnapshotLoaded(iteration); + + // recalculate antibodies for every agent if starting from snapshot. + // The antibodies profile is generated using the immunity event history in the + // snapshot; the antibody model config of the snapshot simulation will + // be superceded by the config of the current simulation. Thus, the antibody development + // during the snapshot can be rewritten without modifying the immunity event history. + antibodyModel.recalculateAntibodiesAfterSnapshot(handler.getPersons(), iteration); + } else if (episimConfig.getStartFromImmunization() != null) { + antibodyModel.init(handler.getPersons(), iteration); handler.initImmunization(Path.of(episimConfig.getStartFromImmunization())); + } else { + antibodyModel.init(handler.getPersons(), iteration); } - // recalculate antibodies for every agent if starting from snapshot. - // The antibodies profile is generated using the immunity event history in the - // snapshot; the antibody model config of the snapshot simulation will - // be superceded by the config of the current simulation. Thus, the antibody development - // during the snapshot can be rewritten without modifying the immunity event history. - - antibodyModel.init(handler.getPersons(), iteration); - reporting.reportCpuTime(0, "Init", "finished", -1); log.info("Starting from iteration {}...", iteration); @@ -137,7 +140,7 @@ public void run(int maxIterations) { if (episimConfig.getSnapshotInterval() > 0 && iteration % episimConfig.getSnapshotInterval() == 0) { writeSnapshot(output, iteration); - writeImmunization(output, iteration); +// writeImmunization(output, iteration); } if (iteration % 10 == 0) @@ -260,38 +263,38 @@ private void writeSnapshot(Path output, int iteration) { * @param output output path * @param iteration current iteration */ - private void writeImmunization(Path output, int iteration) { - - EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - - String date = episimConfig.getStartDate().plusDays(iteration - 1).toString(); - - Path path = output.resolve(episimConfig.getImmunizationPrefix() + String.format("-%03d-%s.tsv.gz", iteration, date)); - - log.info("Writing immunization history to {}", path); - - InfectionEventHandler handler = handlerProvider.get(); - - try (CSVPrinter out = new CSVPrinter(new OutputStreamWriter(new GzipCompressorOutputStream(Files.newOutputStream(path))), CSVFormat.TDF)) { - - out.printRecord("personId", "date", "virus_or_vaccine", "type"); - - for (EpisimPerson person : handler.getPersons()) { - for (int i = 0; i < person.getNumInfections(); i++) { - String occurrence = episimConfig.getStartDate().plusDays((long) ((person.getInfectionDates().getDouble(i) / EpisimUtils.DAY) - 1)).toString(); - out.printRecord(person.getPersonId(), occurrence, "virus", person.getVirusStrain(i)); - } - - for (int i = 0; i < person.getNumVaccinations(); i++) { - String occurrence = episimConfig.getStartDate().plusDays(person.getVaccinationDates().getInt(i) - 1).toString(); - out.printRecord(person.getPersonId(), occurrence, "vaccine", person.getVaccinationType(i)); - } - } - - } catch (IOException e) { - throw new UncheckedIOException("Could not write immunization history", e); - } - } +// private void writeImmunization(Path output, int iteration) { +// +// EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); +// +// String date = episimConfig.getStartDate().plusDays(iteration - 1).toString(); +// +// Path path = output.resolve(episimConfig.getImmunizationPrefix() + String.format("-%03d-%s.tsv.gz", iteration, date)); +// +// log.info("Writing immunization history to {}", path); +// +// InfectionEventHandler handler = handlerProvider.get(); +// +// try (CSVPrinter out = new CSVPrinter(new OutputStreamWriter(new GzipCompressorOutputStream(Files.newOutputStream(path))), CSVFormat.TDF)) { +// +// out.printRecord("personId", "date", "virus_or_vaccine", "type"); +// +// for (EpisimPerson person : handler.getPersons()) { +// for (int i = 0; i < person.getNumInfections(); i++) { +// String occurrence = episimConfig.getStartDate().plusDays((long) ((person.getInfectionDates().getDouble(i) / EpisimUtils.DAY) - 1)).toString(); +// out.printRecord(person.getPersonId(), occurrence, "virus", person.getVirusStrain(i)); +// } +// +// for (int i = 0; i < person.getNumVaccinations(); i++) { +// String occurrence = episimConfig.getStartDate().plusDays(person.getVaccinationDates().getInt(i) - 1).toString(); +// out.printRecord(person.getPersonId(), occurrence, "vaccine", person.getVaccinationType(i)); +// } +// } +// +// } catch (IOException e) { +// throw new UncheckedIOException("Could not write immunization history", e); +// } +// } /** * Read snapshot from disk and initialize simulation state diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index cac1d0345..d27dfb431 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -771,6 +771,10 @@ public void reset(int iteration) { progressionModel.updateState(person, iteration); antibodyModel.updateAntibodies(person, iteration); +// if (person.getPersonId().toString().equals("1280b24")) { +// System.out.println("it " + iteration + ", " + person.getAntibodies(VirusStrain.SARS_CoV_2)); +// } + for (Object2DoubleMap.Entry kv : person.getAntibodies().object2DoubleEntrySet()) { antibodies.mergeDouble(kv.getKey(), kv.getDoubleValue(), Double::sum); } diff --git a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java index 0d0961161..7e8d4c7f1 100644 --- a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java +++ b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java @@ -94,8 +94,9 @@ public void newDay(int currentIteration) { antibodyModel.updateAntibodies(person, this.maxIterationReachedSoFar - this.iterationOffset); progressionModel.updateState(person, this.maxIterationReachedSoFar - this.iterationOffset); -// if (person.getPersonId().toString().equals("1238c80")) { +// if (person.getPersonId().toString().equals("1280b24")) { // System.out.println("it " + currentIteration + ", " + person.getAntibodies(VirusStrain.SARS_CoV_2)); +// } // System.out.println(" " + person.getDiseaseStatus()); // System.out.println(" " + person.getQuarantineStatus()); // diff --git a/src/main/java/org/matsim/episim/model/AntibodyModel.java b/src/main/java/org/matsim/episim/model/AntibodyModel.java index 39fc90af1..bbda67d6f 100644 --- a/src/main/java/org/matsim/episim/model/AntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/AntibodyModel.java @@ -41,6 +41,8 @@ static AntibodyModel.Config newConfig(Map persons, int iteration); + void recalculateAntibodiesAfterSnapshot(Collection persons, int iteration); + /** * Class for antibody model configurations. */ diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 6367d08da..0d8422358 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -35,6 +35,7 @@ public void init(Collection persons, int iteration) { // mu = log(median); log(1)=0 + // we assume immune response multiplier follows log-normal distribution, bounded by 0.01 and 10. double immuneResponseMultiplier = 0; while (immuneResponseMultiplier < 0.1 || immuneResponseMultiplier > 10) { @@ -43,17 +44,31 @@ public void init(Collection persons, int iteration) { person.setImmuneResponseMultiplier(immuneResponseMultiplier); - // start from snapshot - if (iteration > 1 && episimConfig.getStartFromSnapshot() != null) { - for (int it = 1; it < iteration; it++) { - updateAntibodies(person, it); - } - } } } + @Override + public void recalculateAntibodiesAfterSnapshot(Collection persons, int iteration) { + for (EpisimPerson person : persons) { + + // reset to 0.0 + for (VirusStrain strain : VirusStrain.values()) { + person.setAntibodies(strain, 0.0); + } + + // recalculate antibodies from immune history + for (int it = 1; it < iteration; it++) { + updateAntibodies(person, it); + +// if (person.getPersonId().toString().equals("1280b24")) { +// System.out.println("it " + it + ", " + person.getAntibodies(VirusStrain.SARS_CoV_2)); +// } + } + } + } + /** * Updates the antibody levels for person. If an immunity event occurs (vaccination or infection) on the previous * day, antibodies will increase. If not, they will decrease. This method was designed to also recalculate antibodies @@ -65,12 +80,11 @@ public void init(Collection persons, int iteration) { @Override public void updateAntibodies(EpisimPerson person, int day) { - // todo: is this needed, now that we have an init - if (day == 0) { - for (VirusStrain strain : VirusStrain.values()) { - person.setAntibodies(strain, 0.0); - } - } +// if (day == 0) { +// for (VirusStrain strain : VirusStrain.values()) { +// person.setAntibodies(strain, 0.0); +// } +// } //handle vaccination if (person.getVaccinationDates().contains(day - 1)) { diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java index c39f68081..17e260561 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java @@ -129,20 +129,25 @@ protected void configure() { AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); - double immuneSigma = 3.0; + + double immuneSigma = 0.0; if (params != null) { - antibodyConfig.setImmuneReponseSigma(immuneSigma); + immuneSigma = params.immuneSigma; } + antibodyConfig.setImmuneReponseSigma(immuneSigma); bind(AntibodyModel.Config.class).toInstance(antibodyConfig); if (params == null) return; + + // HOUSEHOLD SUSCEPTIBILITY // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + double pHouseholds = params.pHh; bind(HouseholdSusceptibility.Config.class).toInstance( HouseholdSusceptibility.newConfig() - .withSusceptibleHouseholds(0.35, 0.01) + .withSusceptibleHouseholds(pHouseholds, 0.01) // .withNonVaccinableHouseholds(params.nonVaccinableHh) // .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) // .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) @@ -359,11 +364,11 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( - new VaccinationEffectiveness().withArgs(), - new RValuesFromEvents().withArgs(), - new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new FilterEvents().withArgs("--output","./output/"), - new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new VaccinationEffectiveness().withArgs(), +// new RValuesFromEvents().withArgs(), +// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/") +// new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") // new SecondaryAttackRateFromEvents().withArgs() ); } @@ -389,14 +394,20 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); - if (!params.startDate.equals("fromTheStart")) { - episimConfig.setStartDate(LocalDate.parse(params.startDate)); - episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/2022-11-04/1-snap/immunisation-history/");//TODO!!! -// episimConfig.setImmunizationPrefix(String.valueOf(params.seed)); //TODO + + if (params.simStart.equals("createSnapshot")) { + episimConfig.setSnapshotInterval(630); + episimConfig.setSnapshotPrefix(params.immuneSigma + "-" + params.pHh); + } else if (params.simStart.equals("startFromSnapshot")) { + episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/runs/jakob/2022-11-05/1-snap/snapshot/" + params.immuneSigma + "-" + params.pHh + "-630-2021-11-15.zip"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); + } else { + episimConfig.setStartDate(LocalDate.parse(params.simStart)); + episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/2022-11-05/1-snap/imm-history-640/"+params.immuneSigma + "-" + params.pHh+"/"); } //snapshot -// episimConfig.setSnapshotInterval(30); +// episimConfig.setSnapshotInterval(90); // episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); // episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); @@ -653,11 +664,17 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi public static final class Params { // general - @GenerateSeeds(5) + @GenerateSeeds(20) public long seed; - @StringParameter({"fromTheStart","2020-06-01", "2020-12-01", "2021-06-01", "2021-12-01", "2022-06-01", "2022-09-15"}) - public String startDate; + @Parameter({0.0, 3.0}) + public double immuneSigma; + + @Parameter({0.0, 0.35}) + public double pHh; + + @StringParameter({"startFromSnapshot"})//"2021-11-15"}) //"startFromSnapshot"})//"createSnapshot","2020-06-01", "2020-12-01", "2021-06-01", "2021-12-01", "2022-06-01", "2022-09-15"}) + public String simStart; //IFSG @StringParameter({"base"}) diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java index 4d52a0fa5..2b8b002c6 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -55,6 +55,9 @@ protected void configure() { } }); + + //ANTIBODY Model + } private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { @@ -103,19 +106,14 @@ public Config prepareConfig(int id, Params params) { //snapshot - episimConfig.setStartDate(LocalDate.parse("2020-03-29")); - episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-03xsfdsadfasdfasdf"); - -// episimConfig.setImmunizationPrefix("imm-" + String.valueOf(params.seed)); +// episimConfig.setSnapshotInterval(15); +// +// episimConfig.setStartDate(LocalDate.parse("2020-03-10")); +// episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15"); -// episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/imm-" + String.valueOf(params.seed)+"-960-2022-10-11.tsv.gz"); -// episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/imm-4711-210-2020-09-21.tsv.gz"); -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); -// episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA5).put(startDate, 144_380 / 4); -// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); -// episimConfig.setSnapshotInterval(10); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); + episimConfig.setStartFromSnapshot("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15/episim-snapshot-015-2020-03-10.zip"); //--------------------------------------- diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 1465902e8..6f55f64b4 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -239,7 +239,7 @@ protected void configure() { // antibody model AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(); - antibodyConfig.setImmuneReponseSigma(3.0); + antibodyConfig.setImmuneReponseSigma(0.0); // todo revert to 3.0? bind(AntibodyModel.Config.class).toInstance(antibodyConfig); /* Bremen: From ca8da68b3576d17e11b3ae299f0810c409b42d46 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 15 Nov 2022 19:09:04 +0100 Subject: [PATCH 114/128] bug fixes for start from immunizations, as well as new batch for bq1 --- src/main/R/analyseCases.R | 9 +- .../org/matsim/episim/TracingConfigGroup.java | 7 +- .../model/ConfigurableProgressionModel.java | 8 +- .../org/matsim/episim/policy/FixedPolicy.java | 2 +- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../batch/CologneBMBF20221024_snapshot.java | 2 +- .../run/batch/CologneBMBF202212XX_bq1.java | 748 ++++++++++++++++++ ...2XX.java => CologneBMBF202212XX_soup.java} | 64 +- .../run/batch/StartFromImmunizations.java | 4 +- .../modules/SnzCologneProductionScenario.java | 4 +- 10 files changed, 806 insertions(+), 46 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java rename src/main/java/org/matsim/run/batch/{CologneBMBF202212XX.java => CologneBMBF202212XX_soup.java} (98%) diff --git a/src/main/R/analyseCases.R b/src/main/R/analyseCases.R index ef1b7fd1c..9012b45c8 100644 --- a/src/main/R/analyseCases.R +++ b/src/main/R/analyseCases.R @@ -7,14 +7,15 @@ library(readr) rm(list=ls()) source("/Users/jakob/git/matsim-episim/src/main/R/masterJR-utils.R", encoding = 'utf-8') -# directory_snap <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-05/2-imm-snap/" -directory_snap <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-15/1-imm-snap/" -directory_imm <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-05/2b-imm-hist/" +# directory_snap_old <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-05/2-imm-snap/" +directory_snap <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-15/2-imm-snap/" +directory_imm <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-15/3-imm-hist/" # file_root<- "antibodies.tsv" #infections file_root_inf<- "infections.txt.csv" snap_inf_raw <- read_combine_episim_output_zipped(directory_snap, file_root_inf ) +# snap_inf_raw_old <- read_combine_episim_output_zipped(directory_snap, file_root_inf ) imm_inf_raw <- read_combine_episim_output_zipped(directory_imm, file_root_inf) @@ -46,7 +47,7 @@ imm_ab_raw <- read_combine_episim_output_zipped(directory_imm, file_root_ab) start_date <- ymd("2021-11-15") -end_date <- ymd("2021-11-30") +end_date <- ymd("2029-11-30") snap_ab <- snap_ab_raw %>% filter(date >= start_date) %>% filter(date <= end_date) %>% diff --git a/src/main/java/org/matsim/episim/TracingConfigGroup.java b/src/main/java/org/matsim/episim/TracingConfigGroup.java index f58949c9b..d02479454 100644 --- a/src/main/java/org/matsim/episim/TracingConfigGroup.java +++ b/src/main/java/org/matsim/episim/TracingConfigGroup.java @@ -493,7 +493,12 @@ public enum QuarantineRelease { /** * Release persons without showing symptoms. */ - NON_SYMPTOMS + NON_SYMPTOMATIC, + + /** + * Release all people except those in hospital + */ + WITH_SYMPTOMS } diff --git a/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java b/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java index 6bb31850f..f3f06964e 100644 --- a/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java +++ b/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java @@ -227,10 +227,16 @@ private boolean releasePerson(EpisimPerson person) { if (release == TracingConfigGroup.QuarantineRelease.SUSCEPTIBLE && status == DiseaseStatus.susceptible) return true; - if (release == TracingConfigGroup.QuarantineRelease.NON_SYMPTOMS && + if (release == TracingConfigGroup.QuarantineRelease.NON_SYMPTOMATIC && (status == DiseaseStatus.susceptible || status == DiseaseStatus.contagious || status == DiseaseStatus.infectedButNotContagious)) return true; + if (release == TracingConfigGroup.QuarantineRelease.WITH_SYMPTOMS && + (status == DiseaseStatus.susceptible || status == DiseaseStatus.contagious || status == DiseaseStatus.infectedButNotContagious || status == DiseaseStatus.showingSymptoms)) { + return true; + } + + return false; } diff --git a/src/main/java/org/matsim/episim/policy/FixedPolicy.java b/src/main/java/org/matsim/episim/policy/FixedPolicy.java index d2a763906..39f4ef4ce 100644 --- a/src/main/java/org/matsim/episim/policy/FixedPolicy.java +++ b/src/main/java/org/matsim/episim/policy/FixedPolicy.java @@ -101,7 +101,7 @@ static void initRestrictions(LocalDate start, ImmutableMap if (days.getKey().startsWith("day")) continue; LocalDate date = LocalDate.parse(days.getKey()); - if (date.isBefore(start)) { + if (date.isBefore(start.plusDays(1))) { Restriction r = Restriction.fromConfig(actConfig.getConfig(days.getKey())); entry.getValue().update(r); diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 7c2b07d0d..0f59fc630 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX_bq1") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202212XX_bq1$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java index 17e260561..cccb69816 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF20221024_snapshot.java @@ -673,7 +673,7 @@ public static final class Params { @Parameter({0.0, 0.35}) public double pHh; - @StringParameter({"startFromSnapshot"})//"2021-11-15"}) //"startFromSnapshot"})//"createSnapshot","2020-06-01", "2020-12-01", "2021-06-01", "2021-12-01", "2022-06-01", "2022-09-15"}) + @StringParameter({"2021-11-15"})//"2021-11-15"}) //"startFromSnapshot"})//"createSnapshot","2020-06-01", "2020-12-01", "2021-06-01", "2021-12-01", "2022-06-01", "2022-09-15"}) public String simStart; //IFSG diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java new file mode 100644 index 000000000..b36e87e8f --- /dev/null +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java @@ -0,0 +1,748 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.TracingConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.*; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.time.LocalDate; +import java.util.*; + + +/** + * Batch for Bmbf runs + */ +public class CologneBMBF202212XX_bq1 implements BatchRun { + + boolean DEBUG_MODE = false; + int runCount = 0; + + LocalDate restrictionDatePhase1 = LocalDate.parse("2022-12-01"); + LocalDate restrictionDatePhase2 = restrictionDatePhase1.plusDays(10); + + + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return Modules.override(getBindings(0.0, params)).with(new AbstractModule() { + @Override + protected void configure() { + + // VACCINATION MODEL + Multibinder set = Multibinder.newSetBinder(binder(), VaccinationModel.class); + set.addBinding().to(VaccinationStrategyReoccurringCampaigns.class).in(Singleton.class); + // fixed values + LocalDate start = LocalDate.parse("2022-10-15"); + VaccinationType vaccinationType = VaccinationType.ba5Update; + int campaignDuration = 300000; + + // default values, to be changed if params != null + int minDaysAfterInfection = 180; + int minDaysAfterVaccination = 180; + VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool vaccinationPool = VaccinationStrategyReoccurringCampaigns.Config.VaccinationPool.vaccinated; + LocalDate emergencyDate = LocalDate.MAX; + LocalDate dateToTurnDownMinDaysAfterInfection = LocalDate.MAX; + Map startDateToVaccination = new HashMap<>(); + startDateToVaccination.put(start, vaccinationType); + + if (params != null) { + if (params.vacCamp.equals("base")) { // + + + } else if(params.vacCamp.equals("ph1_90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDatePhase1; + } else if(params.vacCamp.equals("ph1_180")){ // + + emergencyDate = restrictionDatePhase1; + } else if (params.vacCamp.equals("ph1_180_ph2_inf90vax180")) { + emergencyDate = restrictionDatePhase1; + dateToTurnDownMinDaysAfterInfection = restrictionDatePhase2; + // same as ifsg180 but after phase 2 date, minDaysAfterInfection = 90; + }else if(params.vacCamp.equals("ph2_90")){ + minDaysAfterInfection = 90; + minDaysAfterVaccination = 90; + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_inf90vax180")){ + minDaysAfterInfection = 90; + emergencyDate = restrictionDatePhase2; + } else if(params.vacCamp.equals("ph2_180")) { + emergencyDate = restrictionDatePhase2; + }else { + throw new RuntimeException(); + } + } + + bind(VaccinationStrategyReoccurringCampaigns.Config.class).toInstance(new VaccinationStrategyReoccurringCampaigns.Config(startDateToVaccination, campaignDuration, vaccinationPool, minDaysAfterInfection, minDaysAfterVaccination, emergencyDate, dateToTurnDownMinDaysAfterInfection)); + + + // ANTIBODY MODEL + // default values + double mutEscDelta = 29.2 / 10.9; + double mutEscBa1 = 10.9 / 1.9; + double mutEscBa5 = 5.0; + + double mutEscStrainA = 0.; + double mutEscStrainB = 0.; + + + if (params != null) { +// mutEscBa1 = params.ba1Esc; +// mutEscBa5 = params.ba5Esc; + +// String StrainA = "6.0"; + String StrainB = "off"; + + + if (!params.StrainA.equals("off")) { + mutEscStrainA = Double.parseDouble(params.StrainA); + } + if (!StrainB.equals("off")) { + mutEscStrainB = Double.parseDouble(StrainB); + } + + } + + //initial antibodies + Map> initialAntibodies = new HashMap<>(); + Map> antibodyRefreshFactors = new HashMap<>(); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB); + + AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); + + double immuneSigma = 3.0; + if (params != null) { + antibodyConfig.setImmuneReponseSigma(immuneSigma); + } + + bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + if (params == null) return; + + // HOUSEHOLD SUSCEPTIBILITY + // designates a 35% of households as super safe; the susceptibility of that subpopulation is reduced to 1% wrt to general population. + bind(HouseholdSusceptibility.Config.class).toInstance( + HouseholdSusceptibility.newConfig() + .withSusceptibleHouseholds(0.35, 0.01) +// .withNonVaccinableHouseholds(params.nonVaccinableHh) +// .withShape(SnzCologneProductionScenario.INPUT.resolve("CologneDistricts.zip")) +// .withFeature("STT_NAME", vingst, altstadtNord, bickendorf, weiden) + ); + + } + + private void configureAntibodies(Map> initialAntibodies, + Map> antibodyRefreshFactors, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB) { + for (VaccinationType immunityType : VaccinationType.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + initialAntibodies.get(immunityType).put(virusStrain, 29.2); //10.0 + } + else if (immunityType == VaccinationType.vector) { + initialAntibodies.get(immunityType).put(virusStrain, 6.8); //2.5 + } + else { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + initialAntibodies.get(immunityType).put(virusStrain, 5.0); + } + } + + //mRNAAlpha, mRNADelta, mRNABA1 comes from Sydney's calibration. + //The other values come from Rössler et al. + + //Wildtype + double mRNAAlpha = 29.2; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.SARS_CoV_2, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.SARS_CoV_2, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.SARS_CoV_2, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.SARS_CoV_2, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //Alpha + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.ALPHA, mRNAAlpha); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.ALPHA, mRNAAlpha * 300. / 700.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.ALPHA, mRNAAlpha * 210. / 700.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.ALPHA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.ALPHA, mRNAAlpha / mutEscDelta / mutEscBa1 / mutEscBa5); + + //DELTA + double mRNADelta = mRNAAlpha / mutEscDelta; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.DELTA, mRNADelta); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.DELTA, mRNADelta * 150./300.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.DELTA, mRNADelta * 64./300.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.DELTA, mRNADelta * 450./300.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.DELTA, 0.01); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.DELTA, mRNADelta / mutEscBa1 / mutEscBa5); + + //BA.1 + double mRNABA1 = mRNADelta / mutEscBa1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA1, mRNABA1); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA1, mRNABA1 * 4./20.); //??? + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA1, mRNABA1 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA1, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5); //todo: is 1.4 + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA1, mRNAAlpha / mutEscBa5); + + //BA.2 + double mRNABA2 = mRNABA1; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA2, mRNABA2); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA2, mRNABA2 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA2, mRNABA2 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / 1.4); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA2, 64.0 / 300.); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA2, mRNAAlpha / mutEscBa5); + + + //BA.5 + double mRNABa5 = mRNABA2 / mutEscBa5; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.OMICRON_BA5, mRNABa5); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.OMICRON_BA5, mRNABa5 * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.OMICRON_BA5, mRNABa5 * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5);// todo: do we need 1.4? + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscBa5); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.OMICRON_BA5, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA); //todo ??? + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.OMICRON_BA5, 64.0 / 300. / mutEscBa5 / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha / mutEscBa5); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.OMICRON_BA5, mRNAAlpha); + + //StrainA + double mRNAStrainA = mRNABa5 / mutEscStrainA; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_A, mRNAStrainA); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_A, mRNAStrainA * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_A, mRNAStrainA * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_A, mRNAStrainA * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_A, 64.0 / 300./ mutEscBa5 /mutEscStrainA); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_A, 64.0 / 300.); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_A, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscBa5 / mutEscStrainA); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_A, mRNAAlpha / mutEscStrainA); + + //StrainB + double mRNAStrainB = mRNABA2 / mutEscStrainB; + initialAntibodies.get(VaccinationType.mRNA).put(VirusStrain.STRAIN_B, mRNAStrainB); + initialAntibodies.get(VaccinationType.vector).put(VirusStrain.STRAIN_B, mRNAStrainB * 4./20.); + initialAntibodies.get(VirusStrain.SARS_CoV_2).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.ALPHA).put(VirusStrain.STRAIN_B, mRNAStrainB * 6./20.); + initialAntibodies.get(VirusStrain.DELTA).put(VirusStrain.STRAIN_B, mRNAStrainB * 8./20.); + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA2).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainB); + initialAntibodies.get(VirusStrain.OMICRON_BA5).put(VirusStrain.STRAIN_B, 64.0 / 300. / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_A).put(VirusStrain.STRAIN_B, 64.0 / 300./ mutEscStrainA / mutEscStrainB / mutEscBa5); + initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); + initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); + initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); + + + for (VaccinationType immunityType : VaccinationType.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + + if (immunityType == VaccinationType.mRNA) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.vector) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 5.0); + } + else if (immunityType == VaccinationType.ba1Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else if (immunityType == VaccinationType.ba5Update) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + else { + antibodyRefreshFactors.get(immunityType).put(virusStrain, Double.NaN); + } + + } + } + + for (VirusStrain immunityType : VirusStrain.values()) { + antibodyRefreshFactors.put(immunityType, new EnumMap<>( VirusStrain.class ) ); + for (VirusStrain virusStrain : VirusStrain.values()) { + antibodyRefreshFactors.get(immunityType).put(virusStrain, 15.0); + } + } + + +// UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + + } + }); + + } + + private SnzCologneProductionScenario getBindings(double pHousehold, Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(pHousehold) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) +// .setTestingModel(params != null ? FlexibleTestingModel.class : DefaultTestingModel.class) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + @Override + public Collection postProcessing() { + return List.of( + new VaccinationEffectiveness().withArgs(), + new RValuesFromEvents().withArgs(), + new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") +// new SecondaryAttackRateFromEvents().withArgs() + ); + } + + @Override + public Config prepareConfig(int id, Params params) { + + if (DEBUG_MODE) { + if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } + } + + SnzCologneProductionScenario module = getBindings(0.0, params); + + Config config = module.config(); + + config.global().setRandomSeed(params.seed); + + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + //snapshot +// episimConfig.setSnapshotInterval(30); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + //--------------------------------------- + // S T R A I N S + //--------------------------------------- + + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); + double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); + +// STRAIN_A + if (!params.StrainA.equals("off")) { + + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); + } + +// STRAIN_B +// if (!params.StrainB.equals("off")) { +// +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); +// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); +// } + + //--------------------------------------- + // I M P O R T + //--------------------------------------- + + configureFutureDiseaseImport(params, episimConfig); + + // modify import: + LocalDate impModDate = LocalDate.parse("2022-01-31"); + double impRedBa1 = 0.0; + double impRedBa2 = 0.0; + if (impRedBa1 != 1.0) { + NavigableMap impBa1 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA1); + for (Map.Entry entry : impBa1.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa1.put(entry.getKey(), (int) (entry.getValue() * impRedBa1)); + } + } + } + + if (impRedBa2 != 1.0) { + NavigableMap impBa2 = episimConfig.getInfections_pers_per_day().get(VirusStrain.OMICRON_BA2); + for (Map.Entry entry : impBa2.entrySet()) { + if (entry.getKey().isAfter(impModDate)) { + impBa2.put(entry.getKey(), (int) (entry.getValue() * impRedBa2)); + } + } + } + + + + //--------------------------------------- + // R E S T R I C T I O N S + //--------------------------------------- + + FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); + + + + //ifsg + if ("base".equals(params.ifsg)) { + + } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { + double compliance = Double.parseDouble(params.ifsg) / 100.; + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, compliance)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); + builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way + } else { + throw new RuntimeException(); + } + + // EMERGENCY RESTRICTIONS + //work + builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); + double homeOfficeFactor = 0.5; + switch (params.work) { + case "base": + break; + case "half": + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + break; + case "half&mask": + builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); + + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + // leisure public + private + switch (params.leis) { + case "base": + break; + case "pub50": + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic"); + break; + case "pubPriv50": + builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic", "leisPrivate"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + //school + switch (params.edu) { + case "base": + break; + case "mask": + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + case "half&mask": + builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.90)), + "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + + builder.restrict(restrictionDatePhase2, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + switch (params.maskPt) { + case "base": + break; + case "off": + builder.restrict(LocalDate.parse("2023-01-01"), + Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.0)), + "pt"); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + TracingConfigGroup tracingConfig = ConfigUtils.addOrGetModule(config, TracingConfigGroup.class); + LocalDate dateToRemoveQuarantine = LocalDate.parse("2022-12-01"); + switch (params.quarantine) { + case "base": + break; + case "nonSymptomatic0": + tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); + tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.NON_SYMPTOMATIC); + break; + case "withSymptoms0": + tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); + tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.WITH_SYMPTOMS); + break; + case "susceptible0": + tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); + tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.SUSCEPTIBLE); + break; + default: + throw new RuntimeException("invalid parameter"); + } + + + + // vary amount of "school" activity that takes place during vacation + builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); + + episimConfig.setPolicy(builder.build()); + + + //--------------------------------------- + // M I S C + //--------------------------------------- + + + if (DEBUG_MODE) { + UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); + } + + return config; + } + + private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episimConfig) { + Map infPerDayBa1 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA1, new TreeMap<>())); + Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); + Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); + Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); +// Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); + + //StrainA + if (!params.StrainA.equals("off")) { + infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strADate = LocalDate.parse("2022-11-01"); + LocalDate strADate = LocalDate.parse(params.strainADate); + + for (int i = 0; i < 7; i++) { + infPerDayStrA.put(strADate.plusDays(i), 4); + } + infPerDayStrA.put(strADate.plusDays(7), 1); + } + + //StrainB +// if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); +// LocalDate strBDate = LocalDate.parse("2022-11-01"); +// for (int i = 0; i < 7; i++) { +// infPerDayStrB.put(strBDate.plusDays(i), 4); +// } +// infPerDayStrB.put(strBDate.plusDays(7), 1); +// } + + + // add projected disease import for vacation waves after initial disease import +// int facBa2 = 4; +// int facBa5 = 4; +// int facStrAB = 4; +// +// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import +// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import +// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import + +// String importSummer2022 = "off"; +// if (importSummer2022.equals("on")) { +// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); +// LocalDate date = null; +// for (Map.Entry entry : data.entrySet()) { +// date = entry.getKey(); +// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model +//// +// double cases = factor * entry.getValue(); +// +// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { +// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); +// } +// else if (!params.StrainA.equals("off")) { +// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else if (!params.StrainB.equals("off")) { +// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); +// } +// else { +// throw new RuntimeException(); +// } +// infPerDayBa5.put(date, 1); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa5)) { +// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); +// infPerDayBa2.put(date, 1); +// } else if (date.isAfter(dateBa2)) { +// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); +// } +// +// } +// } else if (importSummer2022.equals("off")) { +// } else { +// throw new RuntimeException(); +// } + + + // save disease import + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); + episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA5, infPerDayBa5); + + if (!params.StrainA.equals("off")) { + episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); + } +// if (!params.StrainB.equals("off")) { +// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); +// } + } + + public static final class Params { + // general + @GenerateSeeds(5) + public long seed; + + + @StringParameter({"base", "off"}) + public String maskPt; + + + @StringParameter({"base", "nonSymptomatic0", "withSymptoms0", "susceptible0"}) + public String quarantine; + + + // BQ 1 + @StringParameter({"off","2.0", "2.25", "2.5", "2.75", "3.0"}) + public String StrainA; + + @StringParameter({"2022-08-24", "2022-08-29", "2022-09-04", "2022-09-09", "2022-09-14", "2022-09-19"}) + public String strainADate; + + + //IFSG + @StringParameter({"base"}) + public String ifsg; + + // Vaccination Campaign + @StringParameter({"base"}) + String vacCamp; + + // NEW RESTRICTIONS + @StringParameter({"base"}) + public String work; + + // leisure Public + @StringParameter({"base"}) + public String leis; + + //edu + @StringParameter({"base"}) + public String edu; + + + + } + + + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, CologneBMBF202212XX_soup.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(1), + RunParallel.OPTION_ITERATIONS, Integer.toString(1000), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + + +} + diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java similarity index 98% rename from src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java rename to src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java index 55bb52b81..4800383a5 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java @@ -29,7 +29,7 @@ /** * Batch for Bmbf runs */ -public class CologneBMBF202212XX implements BatchRun { +public class CologneBMBF202212XX_soup implements BatchRun { boolean DEBUG_MODE = false; int runCount = 0; @@ -104,7 +104,7 @@ protected void configure() { double mutEscStrainA = 1.0; double mutEscStrainB = 1.0; - + double escape = 12.; int days = 30; String strainSeed = "no"; @@ -305,35 +305,35 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); - - + + { - + ArrayList strains = getNewStrains(); - + ArrayList dates = getDatesNewStrains(strains, days, strainSeed); for (int i = 0; i < strains.size(); i++) { long daysSince = LocalDate.parse("2022-11-15").datesUntil(dates.get(i)).count(); double escape = 1. + (escapePerYear - 1.0) * daysSince / 365.; //factor 6, if variant appears 6 months later VirusStrain strain = strains.get(i); - + initialAntibodies.get(strain).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(strain).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(strain).put(VirusStrain.DELTA, 0.01); - + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); - initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA / escape); + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA / escape); initialAntibodies.get(strain).put(VirusStrain.STRAIN_A, 64.0 / 300. / escape); - + double mRNAStrain = mRNAStrainA / escape; initialAntibodies.get(VaccinationType.mRNA).put(strain, mRNAStrain); initialAntibodies.get(VaccinationType.vector).put(strain, mRNAStrain * 4./20.); initialAntibodies.get(VirusStrain.SARS_CoV_2).put(strain, mRNAStrain * 6./20.); initialAntibodies.get(VirusStrain.ALPHA).put(strain, mRNAStrain * 6./20.); initialAntibodies.get(VirusStrain.DELTA).put(strain, mRNAStrain * 8./20.); - + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(strain, 64.0 / 300. / mutEscBa5 /mutEscStrainA / escape); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(strain, 64.0 / 300./ mutEscBa5 /mutEscStrainA / escape); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(strain, 64.0 / 300. / mutEscStrainA / escape); @@ -341,8 +341,8 @@ else if (immunityType == VaccinationType.vector) { // initialAntibodies.get(VirusStrain.STRAIN_B).put(strain, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5 / escape); initialAntibodies.get(VaccinationType.ba1Update).put(strain, mRNAAlpha / mutEscBa5 / mutEscStrainA / escape); initialAntibodies.get(VaccinationType.ba5Update).put(strain, mRNAAlpha / mutEscStrainA / escape); - - + + for (int j = 0; j < strains.size(); j++) { LocalDate date1 = dates.get(i); LocalDate date2 = dates.get(j); @@ -351,12 +351,12 @@ else if (immunityType == VaccinationType.vector) { VirusStrain strain2 = strains.get(j); initialAntibodies.get(strain).put(strain2, 64.0 / 300. / escapeBetweenStrains); } - + } - - + + } - + for (VaccinationType immunityType : VaccinationType.values()) { @@ -470,7 +470,7 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); } - + for (VirusStrain strain : getNewStrains()) { virusStrainConfigGroup.getOrAddParams(strain).setInfectiousness(ba5Inf); virusStrainConfigGroup.getOrAddParams(strain).setFactorSeriouslySick(ba5Hos); @@ -637,8 +637,8 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } - - + + for (int i = 0; i < getNewStrains().size(); i++) { LocalDate date = getDatesNewStrains(getNewStrains(), params.days, params.strainRnd).get(i); VirusStrain strain = getNewStrains().get(i); @@ -757,13 +757,13 @@ public static final class Params { // @StringParameter({"2022-08-15", "2022-08-22", "2022-08-29", "2022-09-05", "2022-09-12", "2022-09-19", "2022-09-26"}) @StringParameter({"2022-09-12"}) public String strainADate; - + @Parameter({6., 12., 24.}) public double escape; - + @IntParameter({30, 90, 180}) public int days; - + @StringParameter({"1", "2", "3", "no"}) public String strainRnd; @@ -773,7 +773,7 @@ public static final class Params { public static void main(String[] args) { String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202212XX.class.getName(), + RunParallel.OPTION_SETUP, CologneBMBF202212XX_soup.class.getName(), RunParallel.OPTION_PARAMS, Params.class.getName(), RunParallel.OPTION_TASKS, Integer.toString(1), RunParallel.OPTION_ITERATIONS, Integer.toString(1000), @@ -782,7 +782,7 @@ public static void main(String[] args) { RunParallel.main(args2); } - + private static ArrayList getNewStrains() { ArrayList strains = new ArrayList(); strains.add(VirusStrain.STRAIN_C); @@ -796,32 +796,32 @@ private static ArrayList getNewStrains() { strains.add(VirusStrain.STRAIN_K); return strains; } - + private static ArrayList getDatesNewStrains(ArrayList strains, int days, String seed) { ArrayList dates = new ArrayList(); - + if (seed.equals("no")) { for (LocalDate date = LocalDate.parse("2022-11-15"); ; date = date.plusDays(1)) { long daysBetween = ChronoUnit.DAYS.between(LocalDate.parse("2022-11-15"), date); - if (daysBetween % days == 0) + if (daysBetween % days == 0) dates.add(date); if (dates.size() == strains.size()) break; } return dates; } - + else { - Random rand = new Random(Integer.parseInt(seed)); + Random rand = new Random(Integer.parseInt(seed)); for (LocalDate date = LocalDate.parse("2022-11-15"); ; date = date.plusDays(1)) { - if (rand.nextDouble() < 1. / days) + if (rand.nextDouble() < 1. / days) dates.add(date); if (dates.size() == strains.size()) break; } return dates; } - + } diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java index 2b8b002c6..e21e0ade6 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -112,8 +112,8 @@ public Config prepareConfig(int id, Params params) { // episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15"); - episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); - episimConfig.setStartFromSnapshot("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15/episim-snapshot-015-2020-03-10.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); +// episimConfig.setStartFromSnapshot("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15/episim-snapshot-015-2020-03-10.zip"); //--------------------------------------- diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 6f55f64b4..7bc893f0b 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -382,7 +382,7 @@ public Config config() { CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); - activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20221023.csv")); + activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20221102.csv")); activityParticipation.setScale(this.scale); activityParticipation.setLeisureAsNightly(this.leisureNightly); @@ -538,7 +538,7 @@ public Config config() { builder.restrict(LocalDate.parse("2021-12-02"), Restriction.ofMask(FaceMask.N95, 0.9 * schoolFac), "educ_primary", "educ_secondary", "educ_tertiary", "educ_other"); // mask mandate removed - builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(FaceMask.N95, 0.), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "leisure","leisPublic","leisPrivate","work", "business"); //todo: check + builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(FaceMask.N95, 0.), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher", "leisure","leisPublic","leisPrivate","work", "business"); builder.restrict(LocalDate.of(2022, 4, 4), Restriction.ofMask(Map.of( FaceMask.CLOTH, 0.0, From 8d6729a5dcbfa6da3a8651493f9badeaa80f5ef6 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 15 Nov 2022 19:09:17 +0100 Subject: [PATCH 115/128] Changes by chris --- .../java/org/matsim/episim/policy/FixedPolicy.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/episim/policy/FixedPolicy.java b/src/main/java/org/matsim/episim/policy/FixedPolicy.java index 39f4ef4ce..5d5bee740 100644 --- a/src/main/java/org/matsim/episim/policy/FixedPolicy.java +++ b/src/main/java/org/matsim/episim/policy/FixedPolicy.java @@ -33,12 +33,10 @@ import javax.inject.Named; import java.time.LocalDate; import java.time.temporal.ChronoUnit; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.function.BiConsumer; import java.util.function.BiFunction; +import java.util.stream.Collectors; /** * Set the restrictions based on fixed rules with day and {@link Restriction#getRemainingFraction()}. @@ -96,7 +94,11 @@ static void initRestrictions(LocalDate start, ImmutableMap Config actConfig = config.getConfig(entry.getKey()); - for (Map.Entry days : actConfig.root().entrySet()) { + List> entries = actConfig.root().entrySet().stream().filter(e -> !e.getKey().startsWith("day")) + .sorted(Comparator.comparing(e -> LocalDate.parse(e.getKey()))) + .collect(Collectors.toList()); + + for (Map.Entry days : entries) { if (days.getKey().startsWith("day")) continue; From 1f4591971d2664c4d3d787d8c02ffd5129055254 Mon Sep 17 00:00:00 2001 From: smuellervsp Date: Wed, 16 Nov 2022 15:18:23 +0100 Subject: [PATCH 116/128] updates to variant soup --- .../model/InfectionModelWithAntibodies.java | 77 +++- .../org/matsim/episim/model/VirusStrain.java | 81 +++- .../AntibodyDependentTransitionModel.java | 3 +- .../model/testing/DefaultTestingModel.java | 11 +- .../run/batch/CologneBMBF202212XX_soup.java | 357 +++++++----------- 5 files changed, 277 insertions(+), 252 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java index 7949eec38..d70712dfb 100644 --- a/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java +++ b/src/main/java/org/matsim/episim/model/InfectionModelWithAntibodies.java @@ -8,6 +8,7 @@ import org.matsim.episim.*; import org.matsim.episim.policy.Restriction; +import java.util.ArrayList; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -95,7 +96,6 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto { double igaFactor = 0.0; - double igaTimePeriod = vaccinationConfig.getTimePeriodIgA(); if (target.hadStrain(infector.getVirusStrain())) { @@ -108,17 +108,41 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto // igaFactor = Math.exp( - target.daysSinceInfection(lastInfectionWithStrain, iteration) / 120.0); igaFactor = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); - } else if (vaccinationConfig.getUseIgA()) { - List crossImmunityStrainsOmicron = List.of(VirusStrain.OMICRON_BA1, VirusStrain.OMICRON_BA2, VirusStrain.OMICRON_BA5, VirusStrain.STRAIN_A, VirusStrain.STRAIN_B, - VirusStrain.STRAIN_C, VirusStrain.STRAIN_D, VirusStrain.STRAIN_E, VirusStrain.STRAIN_F, VirusStrain.STRAIN_G, VirusStrain.STRAIN_H, VirusStrain.STRAIN_I, - VirusStrain.STRAIN_J, VirusStrain.STRAIN_K); + } + + ArrayList strainsLineA = new ArrayList(); + strainsLineA.add(VirusStrain.OMICRON_BA1); + strainsLineA.add(VirusStrain.OMICRON_BA2); + strainsLineA.add(VirusStrain.OMICRON_BA5); + strainsLineA.add(VirusStrain.STRAIN_A); + strainsLineA.add(VirusStrain.STRAIN_B); + + ArrayList strainsLineB = new ArrayList(); + strainsLineB.add(VirusStrain.OMICRON_BA1); + strainsLineB.add(VirusStrain.OMICRON_BA2); + strainsLineB.add(VirusStrain.OMICRON_BA5); + strainsLineB.add(VirusStrain.STRAIN_A); + strainsLineB.add(VirusStrain.STRAIN_B); + + if (vaccinationConfig.getUseIgA()) { + for (VirusStrain str : VirusStrain.values()) { + if (str.toString().startsWith("A_")) + strainsLineA.add(str); + } + for (VirusStrain str : VirusStrain.values()) { + if (str.toString().startsWith("B_")) + strainsLineB.add(str); + } + } + +// if (vaccinationConfig.getUseIgA()) { - if(crossImmunityStrainsOmicron.contains(infector.getVirusStrain())){ + if(strainsLineA.contains(infector.getVirusStrain())){ int lastInfectionWithStrain = 0; boolean targetHadStrain = false; for (int ii = 0; ii < target.getNumInfections(); ii++) { - if (crossImmunityStrainsOmicron.contains(target.getVirusStrain(ii))){ + if (strainsLineA.contains(target.getVirusStrain(ii))){ targetHadStrain = true; lastInfectionWithStrain = ii; } @@ -130,8 +154,43 @@ public double calcInfectionProbability(EpisimPerson target, EpisimPerson infecto igaFactor = Math.max(fac, igaFactor); } } - } - susceptibility = susceptibility * (1.0 - igaFactor); + + if(strainsLineB.contains(infector.getVirusStrain())){ + int lastInfectionWithStrain = 0; + boolean targetHadStrain = false; + for (int ii = 0; ii < target.getNumInfections(); ii++) { + if (strainsLineB.contains(target.getVirusStrain(ii))){ + targetHadStrain = true; + lastInfectionWithStrain = ii; + } + } + + if (targetHadStrain) { + double fac = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); + fac = fac / 1.4; + igaFactor = Math.max(fac, igaFactor); + } + } + +// if(strainsLineA.contains(infector.getVirusStrain()) || strainsLineB.contains(infector.getVirusStrain())){ +// int lastInfectionWithStrain = 0; +// boolean targetHadStrain = false; +// for (int ii = 0; ii < target.getNumInfections(); ii++) { +// if (strainsLineA.contains(target.getVirusStrain(ii)) || strainsLineB.contains(target.getVirusStrain(ii))){ +// targetHadStrain = true; +// lastInfectionWithStrain = ii; +// } +// } +// +// if (targetHadStrain) { +// double fac = 1.0 / (1.0 + Math.exp(-2.0 * (1.0 - target.daysSinceInfection(lastInfectionWithStrain, iteration) / igaTimePeriod))); +// fac = fac / 1.4 / 1.4; +// igaFactor = Math.max(fac, igaFactor); +// } +// } + + susceptibility = susceptibility * (1.0 - igaFactor); +// } } diff --git a/src/main/java/org/matsim/episim/model/VirusStrain.java b/src/main/java/org/matsim/episim/model/VirusStrain.java index b58738bc9..cc278b5c8 100644 --- a/src/main/java/org/matsim/episim/model/VirusStrain.java +++ b/src/main/java/org/matsim/episim/model/VirusStrain.java @@ -37,27 +37,88 @@ public enum VirusStrain implements ImmunityEvent { OMICRON_BA2, OMICRON_BA5, - + STRAIN_A, STRAIN_B, + + A_1, + + A_2, + + A_3, + + A_4, + + A_5, + + A_6, - STRAIN_C, + A_7, - STRAIN_D, + A_8, - STRAIN_E, + A_9, - STRAIN_F, + A_10, - STRAIN_G, + A_11, - STRAIN_H, + A_12, - STRAIN_I, + A_13, - STRAIN_J, + A_14, - STRAIN_K + A_15, + + A_16, + + A_17, + + A_18, + + A_19, + + A_20, + + B_1, + B_2, + + B_3, + + B_4, + + B_5, + + B_6, + + B_7, + + B_8, + + B_9, + + B_10, + + B_11, + + B_12, + + B_13, + + B_14, + + B_15, + + B_16, + + B_17, + + B_18, + + B_19, + + B_20 } diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 2a664d603..a6739c042 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -129,8 +129,7 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup } // b) if strain is omicron, an additional factor of 3.7 is applied if (strain.equals(VirusStrain.OMICRON_BA1) || strain.equals(VirusStrain.OMICRON_BA2) || strain.equals(VirusStrain.OMICRON_BA5) || strain.equals(VirusStrain.STRAIN_A) || strain.equals(VirusStrain.STRAIN_B) - || strain.equals(VirusStrain.STRAIN_C) || strain.equals(VirusStrain.STRAIN_D) || strain.equals(VirusStrain.STRAIN_E) || strain.equals(VirusStrain.STRAIN_F) || strain.equals(VirusStrain.STRAIN_G) - || strain.equals(VirusStrain.STRAIN_H) || strain.equals(VirusStrain.STRAIN_I) || strain.equals(VirusStrain.STRAIN_J) || strain.equals(VirusStrain.STRAIN_K)) { + || strain.toString().startsWith("A_") || strain.toString().startsWith("B_")) { abNoWaning *= 3.7; } diff --git a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java index b39678d8f..2036656dc 100644 --- a/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java +++ b/src/main/java/org/matsim/episim/model/testing/DefaultTestingModel.java @@ -208,15 +208,8 @@ protected boolean testAndQuarantine(EpisimPerson person, int day, TestingConfigG person.getVirusStrain() == VirusStrain.OMICRON_BA5 || person.getVirusStrain() == VirusStrain.STRAIN_A || person.getVirusStrain() == VirusStrain.STRAIN_B || - person.getVirusStrain() == VirusStrain.STRAIN_C || - person.getVirusStrain() == VirusStrain.STRAIN_D || - person.getVirusStrain() == VirusStrain.STRAIN_E || - person.getVirusStrain() == VirusStrain.STRAIN_F || - person.getVirusStrain() == VirusStrain.STRAIN_G || - person.getVirusStrain() == VirusStrain.STRAIN_H || - person.getVirusStrain() == VirusStrain.STRAIN_I || - person.getVirusStrain() == VirusStrain.STRAIN_J || - person.getVirusStrain() == VirusStrain.STRAIN_K)) { + person.getVirusStrain().toString().startsWith("A_") || + person.getVirusStrain().toString().startsWith("B_"))) { rate = 0.5; } diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java index 4800383a5..1d8370253 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java @@ -9,6 +9,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.episim.BatchRun; import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VaccinationConfigGroup; import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; @@ -24,6 +25,7 @@ import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.Map.Entry; /** @@ -104,10 +106,13 @@ protected void configure() { double mutEscStrainA = 1.0; double mutEscStrainB = 1.0; - + double escape = 12.; - int days = 30; + int days = 30; String strainSeed = "no"; + LocalDate strainADate = LocalDate.parse("2020-01-01"); + boolean lineB = true; + double escapeBetweenLines = 1.0; if (params != null) { // mutEscBa1 = params.ba1Esc; @@ -123,16 +128,19 @@ protected void configure() { if (!StrainB.equals("off")) { mutEscStrainB = Double.parseDouble(StrainB); } - escape = params.escape; + escape = params.esc; days = params.days; strainSeed = params.strainRnd; + strainADate = LocalDate.parse(params.strainADate); + lineB = Boolean.valueOf(params.lineB); + escapeBetweenLines = params.escL; } //initial antibodies Map> initialAntibodies = new HashMap<>(); Map> antibodyRefreshFactors = new HashMap<>(); - configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB, escape, days, strainSeed); + configureAntibodies(initialAntibodies, antibodyRefreshFactors, mutEscDelta, mutEscBa1, mutEscBa5, mutEscStrainA, mutEscStrainB, escape, days, strainSeed, strainADate, lineB, escapeBetweenLines); AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(initialAntibodies, antibodyRefreshFactors); @@ -159,7 +167,8 @@ protected void configure() { private void configureAntibodies(Map> initialAntibodies, Map> antibodyRefreshFactors, - double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB, double escapePerYear, int days, String strainSeed) { + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB, + double escapePerYear, int days, String strainSeed, LocalDate strainADate, boolean lineB, double escapeBetweenLines) { for (VaccinationType immunityType : VaccinationType.values()) { initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); for (VirusStrain virusStrain : VirusStrain.values()) { @@ -305,35 +314,35 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); - - + + { - - ArrayList strains = getNewStrains(); - - ArrayList dates = getDatesNewStrains(strains, days, strainSeed); + + ArrayList strains = getNewStrains(Boolean.valueOf(lineB)); + + ArrayList dates = getDatesNewStrains(strains, days, strainSeed, strainADate); for (int i = 0; i < strains.size(); i++) { - long daysSince = LocalDate.parse("2022-11-15").datesUntil(dates.get(i)).count(); + long daysSince = ChronoUnit.DAYS.between(strainADate, dates.get(i)); double escape = 1. + (escapePerYear - 1.0) * daysSince / 365.; //factor 6, if variant appears 6 months later VirusStrain strain = strains.get(i); - + initialAntibodies.get(strain).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(strain).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(strain).put(VirusStrain.DELTA, 0.01); - + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); - initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA / escape); + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA / escape); initialAntibodies.get(strain).put(VirusStrain.STRAIN_A, 64.0 / 300. / escape); - + double mRNAStrain = mRNAStrainA / escape; initialAntibodies.get(VaccinationType.mRNA).put(strain, mRNAStrain); initialAntibodies.get(VaccinationType.vector).put(strain, mRNAStrain * 4./20.); initialAntibodies.get(VirusStrain.SARS_CoV_2).put(strain, mRNAStrain * 6./20.); initialAntibodies.get(VirusStrain.ALPHA).put(strain, mRNAStrain * 6./20.); initialAntibodies.get(VirusStrain.DELTA).put(strain, mRNAStrain * 8./20.); - + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(strain, 64.0 / 300. / mutEscBa5 /mutEscStrainA / escape); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(strain, 64.0 / 300./ mutEscBa5 /mutEscStrainA / escape); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(strain, 64.0 / 300. / mutEscStrainA / escape); @@ -341,22 +350,26 @@ else if (immunityType == VaccinationType.vector) { // initialAntibodies.get(VirusStrain.STRAIN_B).put(strain, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5 / escape); initialAntibodies.get(VaccinationType.ba1Update).put(strain, mRNAAlpha / mutEscBa5 / mutEscStrainA / escape); initialAntibodies.get(VaccinationType.ba5Update).put(strain, mRNAAlpha / mutEscStrainA / escape); - - + + for (int j = 0; j < strains.size(); j++) { LocalDate date1 = dates.get(i); LocalDate date2 = dates.get(j); long daysBetweenStrains = Math.abs(ChronoUnit.DAYS.between(date1, date2)); double escapeBetweenStrains = 1. + (escapePerYear - 1.0) * daysBetweenStrains / 365.; //factor 6, if variant appears 6 months later VirusStrain strain2 = strains.get(j); + + if (strain.toString().charAt(0) != strain2.toString().charAt(0)) + escapeBetweenStrains = escapeBetweenStrains * escapeBetweenLines; + initialAntibodies.get(strain).put(strain2, 64.0 / 300. / escapeBetweenStrains); } - + } - - + + } - + for (VaccinationType immunityType : VaccinationType.values()) { @@ -470,23 +483,14 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); } - - for (VirusStrain strain : getNewStrains()) { + + for (VirusStrain strain : getNewStrains(Boolean.valueOf(params.lineB))) { virusStrainConfigGroup.getOrAddParams(strain).setInfectiousness(ba5Inf); virusStrainConfigGroup.getOrAddParams(strain).setFactorSeriouslySick(ba5Hos); virusStrainConfigGroup.getOrAddParams(strain).setFactorSeriouslySickVaccinated(ba5Hos); virusStrainConfigGroup.getOrAddParams(strain).setFactorCritical(ba5Hos); } -// STRAIN_B -// if (!params.StrainB.equals("off")) { -// -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); -// } - //--------------------------------------- // I M P O R T //--------------------------------------- @@ -524,83 +528,6 @@ public Config prepareConfig(int id, Params params) { FixedPolicy.ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy()); - - //ifsg - if ("base".equals(params.ifsg)) { - - } else if ("45".equals(params.ifsg) || "90".equals(params.ifsg)) { - double compliance = Double.parseDouble(params.ifsg) / 100.; - builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, compliance)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "leisPublic"); - builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, compliance)), "shop_daily", "shop_other", "errands"); - builder.restrict(restrictionDatePhase1, Restriction.ofMask(Map.of(FaceMask.N95, 0.9)), "pt"); // pt has 90 compliance either way - } else { - throw new RuntimeException(); - } - - // EMERGENCY RESTRICTIONS - //work - builder.restrict(LocalDate.parse("2022-10-15"), 0.88, "work", "business"); - double homeOfficeFactor = 0.5; - switch (params.work) { - case "base": - break; - case "half": - builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); - break; - case "half&mask": - builder.restrict(restrictionDatePhase2, 0.88 * homeOfficeFactor, "work"); // dont include business bc harder to do from home office - builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> rf * homeOfficeFactor, "work"); - - builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of(FaceMask.SURGICAL, 0.0, FaceMask.N95, 0.9)), "work", "business"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - // leisure public + private - switch (params.leis) { - case "base": - break; - case "pub50": - builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic"); - break; - case "pubPriv50": - builder.restrict(restrictionDatePhase2, 0.88 * 0.5, "leisPublic", "leisPrivate"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - - //school - switch (params.edu) { - case "base": - break; - case "mask": - builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, 0.0, - FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - break; - case "half&mask": - builder.restrict(restrictionDatePhase2, Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, 0.0, - FaceMask.N95, 0.90)), - "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - - builder.restrict(restrictionDatePhase2, 0.5, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - builder.applyToRf(restrictionDatePhase2.plusDays(1).toString(), restrictionDatePhase2.plusDays(1000).toString(), (d, rf) -> Math.min(0.5, rf), "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other", "educ_higher"); - break; - default: - throw new RuntimeException("invalid parameter"); - } - // vary amount of "school" activity that takes place during vacation builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); @@ -611,6 +538,22 @@ public Config prepareConfig(int id, Params params) { // M I S C //--------------------------------------- + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setUseIgA(Boolean.valueOf(params.iga)); + + if (!Boolean.valueOf(params.seasonal)) { + + Map fractionsOld = episimConfig.getLeisureOutdoorFraction(); + Map fractionsNew = new HashMap(); + + for (Entry e : fractionsOld.entrySet()) { + if (e.getKey().isBefore(LocalDate.parse("2022-12-01"))) + fractionsNew.put(e.getKey(), e.getValue()); + + } + episimConfig.setLeisureOutdoorFraction(fractionsNew); + } + if (DEBUG_MODE) { UtilsJR.produceDiseaseImportPlot(episimConfig.getInfections_pers_per_day()); @@ -637,11 +580,11 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } - - - for (int i = 0; i < getNewStrains().size(); i++) { - LocalDate date = getDatesNewStrains(getNewStrains(), params.days, params.strainRnd).get(i); - VirusStrain strain = getNewStrains().get(i); + + + for (int i = 0; i < getNewStrains(Boolean.valueOf(params.lineB)).size(); i++) { + LocalDate date = getDatesNewStrains(getNewStrains(Boolean.valueOf(params.lineB)), params.days, params.strainRnd, LocalDate.parse(params.strainADate)).get(i); + VirusStrain strain = getNewStrains(Boolean.valueOf(params.lineB)).get(i); Map infPerDayStrainX = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(strain, new TreeMap<>())); infPerDayStrainX.put(LocalDate.parse("2020-01-01"), 0); @@ -652,66 +595,6 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi episimConfig.setInfections_pers_per_day(strain, infPerDayStrainX); } - //StrainB -// if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); -// LocalDate strBDate = LocalDate.parse("2022-11-01"); -// for (int i = 0; i < 7; i++) { -// infPerDayStrB.put(strBDate.plusDays(i), 4); -// } -// infPerDayStrB.put(strBDate.plusDays(7), 1); -// } - - - // add projected disease import for vacation waves after initial disease import -// int facBa2 = 4; -// int facBa5 = 4; -// int facStrAB = 4; -// -// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import -// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import -// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import - -// String importSummer2022 = "off"; -// if (importSummer2022.equals("on")) { -// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); -// LocalDate date = null; -// for (Map.Entry entry : data.entrySet()) { -// date = entry.getKey(); -// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model -//// -// double cases = factor * entry.getValue(); -// -// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { -// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// } -// else if (!params.StrainA.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else { -// throw new RuntimeException(); -// } -// infPerDayBa5.put(date, 1); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa5)) { -// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa2)) { -// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); -// } -// -// } -// } else if (importSummer2022.equals("off")) { -// } else { -// throw new RuntimeException(); -// } - - // save disease import episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); @@ -730,43 +613,37 @@ public static final class Params { @GenerateSeeds(5) public long seed; - //IFSG - @StringParameter({"base"}) - public String ifsg; - // Vaccination Campaign @StringParameter({"base"}) String vacCamp; - // NEW RESTRICTIONS - @StringParameter({"base"}) - public String work; - - // leisure Public - @StringParameter({"base"}) - public String leis; - - //edu - @StringParameter({"base"}) - public String edu; - -// @StringParameter({"off","3.0","4.0","5.0","6.0"}) - @StringParameter({"off", "1.7"}) + @StringParameter({"1.7"}) public String StrainA; // @StringParameter({"2022-08-15", "2022-08-22", "2022-08-29", "2022-09-05", "2022-09-12", "2022-09-19", "2022-09-26"}) @StringParameter({"2022-09-12"}) public String strainADate; - + @Parameter({6., 12., 24.}) - public double escape; - - @IntParameter({30, 90, 180}) + public double esc; + + @Parameter({1., 6.}) + public double escL; + + @IntParameter({30}) public int days; - - @StringParameter({"1", "2", "3", "no"}) + + @StringParameter({"no"}) public String strainRnd; - + + @StringParameter({"true", "false"}) + public String lineB; + + @StringParameter({"true", "false"}) + public String iga; + + @StringParameter({"true", "false"}) + public String seasonal; } @@ -782,46 +659,82 @@ public static void main(String[] args) { RunParallel.main(args2); } - - private static ArrayList getNewStrains() { + + private static ArrayList getNewStrains(boolean lineB) { ArrayList strains = new ArrayList(); - strains.add(VirusStrain.STRAIN_C); - strains.add(VirusStrain.STRAIN_D); - strains.add(VirusStrain.STRAIN_E); - strains.add(VirusStrain.STRAIN_F); - strains.add(VirusStrain.STRAIN_G); - strains.add(VirusStrain.STRAIN_H); - strains.add(VirusStrain.STRAIN_I); - strains.add(VirusStrain.STRAIN_J); - strains.add(VirusStrain.STRAIN_K); + strains.add(VirusStrain.A_1); + strains.add(VirusStrain.A_2); + strains.add(VirusStrain.A_3); + strains.add(VirusStrain.A_4); + strains.add(VirusStrain.A_5); + strains.add(VirusStrain.A_6); + strains.add(VirusStrain.A_7); + strains.add(VirusStrain.A_8); + strains.add(VirusStrain.A_9); + strains.add(VirusStrain.A_10); + strains.add(VirusStrain.A_11); + strains.add(VirusStrain.A_12); + strains.add(VirusStrain.A_13); + strains.add(VirusStrain.A_14); + strains.add(VirusStrain.A_15); + strains.add(VirusStrain.A_16); + strains.add(VirusStrain.A_17); + strains.add(VirusStrain.A_18); + strains.add(VirusStrain.A_19); + strains.add(VirusStrain.A_20); + + + if (lineB) { + strains.add(1, VirusStrain.B_1); + strains.add(3, VirusStrain.B_2); + strains.add(5, VirusStrain.B_3); + strains.add(7, VirusStrain.B_4); + strains.add(9, VirusStrain.B_5); + strains.add(11, VirusStrain.B_6); + strains.add(13, VirusStrain.B_7); + strains.add(15, VirusStrain.B_8); + strains.add(17, VirusStrain.B_9); + strains.add(19, VirusStrain.B_10); + strains.add(21, VirusStrain.B_11); + strains.add(23, VirusStrain.B_12); + strains.add(25, VirusStrain.B_13); + strains.add(27, VirusStrain.B_14); + strains.add(29, VirusStrain.B_15); + strains.add(31, VirusStrain.B_16); + strains.add(33, VirusStrain.B_17); + strains.add(35, VirusStrain.B_18); + strains.add(37, VirusStrain.B_19); + strains.add(39, VirusStrain.B_20); + } + return strains; } - - private static ArrayList getDatesNewStrains(ArrayList strains, int days, String seed) { + + private static ArrayList getDatesNewStrains(ArrayList strains, int days, String seed, LocalDate start) { ArrayList dates = new ArrayList(); - + if (seed.equals("no")) { - for (LocalDate date = LocalDate.parse("2022-11-15"); ; date = date.plusDays(1)) { - long daysBetween = ChronoUnit.DAYS.between(LocalDate.parse("2022-11-15"), date); - if (daysBetween % days == 0) + for (LocalDate date = start; ; date = date.plusDays(1)) { + long daysBetween = ChronoUnit.DAYS.between(start, date); + if (daysBetween % days == 0) dates.add(date); if (dates.size() == strains.size()) break; } return dates; } - + else { - Random rand = new Random(Integer.parseInt(seed)); + Random rand = new Random(Integer.parseInt(seed)); for (LocalDate date = LocalDate.parse("2022-11-15"); ; date = date.plusDays(1)) { - if (rand.nextDouble() < 1. / days) + if (rand.nextDouble() < 1. / days) dates.add(date); if (dates.size() == strains.size()) break; } return dates; } - + } From 6ce096c7c05a8548904f8fb12091ea47edb3ae5e Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 16 Nov 2022 15:37:48 +0100 Subject: [PATCH 117/128] hacked a mod to probOfTransitioningToShowingSymptoms --- .../matsim/episim/VaccinationConfigGroup.java | 18 +++++ .../AntibodyDependentTransitionModel.java | 12 ++- .../run/batch/CologneBMBF202212XX_bq1.java | 77 +++++++++++-------- .../run/batch/CologneBMBF202212XX_soup.java | 13 ++-- .../modules/SnzCologneProductionScenario.java | 2 +- 5 files changed, 83 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java index 47a4f8ec8..679d3a734 100644 --- a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java +++ b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java @@ -36,6 +36,10 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { private static final String GROUPNAME = "episimVaccination"; + private static final String TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS = "TEMP_updatedShowingSymptomsFactor"; + + private static final String TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS_DATE = "TEMP_updatedShowingSymptomsDate"; + /** * Amount of vaccinations available per day. @@ -88,6 +92,9 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { */ private final Map params = new EnumMap<>(VaccinationType.class); + //TODO: temp, remove or modify + private double TEMP_updatedProbaOfTransitioningToShowingSymptoms = -1; + /** * Default constructor. @@ -180,6 +187,17 @@ String getComplianceString() { } + //TODO: temp, remove or modify + @StringGetter(TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS) + public double getTEMP_updatedProbaOfTransitioningToShowingSymptoms() { + return TEMP_updatedProbaOfTransitioningToShowingSymptoms; + } + + @StringSetter(TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS) + public void setTEMP_updatedProbaOfTransitioningToShowingSymptoms(double TEMP_updatedProbaOfTransitioningToShowingSymptoms) { + this.TEMP_updatedProbaOfTransitioningToShowingSymptoms = TEMP_updatedProbaOfTransitioningToShowingSymptoms; + } + /** * Sets the vaccination capacity for individual days. If a day has no entry the previous will be still valid. * If empty, default is 0. diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 2a664d603..81f80a298 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -30,9 +30,17 @@ public final EpisimPerson.DiseaseStatus decideNextState(EpisimPerson person, Epi switch (status) { case infectedButNotContagious: return EpisimPerson.DiseaseStatus.contagious; - case contagious: - if (rnd.nextDouble() < getProbaOfTransitioningToShowingSymptoms(person) * getShowingSymptomsFactor(person, vaccinationConfig, day)) + + double probaOfTransitioningToShowingSymptoms = getProbaOfTransitioningToShowingSymptoms(person); + + if (day >= 981 // hardcoded: 2022-11-01 + && vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms() >= 0.0 + && vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms() <= 1.0) { + probaOfTransitioningToShowingSymptoms = vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms(); + } + + if (rnd.nextDouble() < probaOfTransitioningToShowingSymptoms * getShowingSymptomsFactor(person, vaccinationConfig, day)) return EpisimPerson.DiseaseStatus.showingSymptoms; else return EpisimPerson.DiseaseStatus.recovered; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java index b36e87e8f..affc1aae8 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java @@ -7,10 +7,7 @@ import com.google.inject.util.Modules; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.episim.BatchRun; -import org.matsim.episim.EpisimConfigGroup; -import org.matsim.episim.TracingConfigGroup; -import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.*; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; import org.matsim.episim.model.listener.HouseholdSusceptibility; @@ -391,9 +388,18 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot -// episimConfig.setSnapshotInterval(30); -// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); + episimConfig.setSnapshotInterval(960); + episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); + + //idk // episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + + //newer snapshot modiefied slightly +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-960-2022-10-11.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + //from last bericht +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //--------------------------------------- // S T R A I N S @@ -551,26 +557,29 @@ public Config prepareConfig(int id, Params params) { throw new RuntimeException("invalid parameter"); } - TracingConfigGroup tracingConfig = ConfigUtils.addOrGetModule(config, TracingConfigGroup.class); - LocalDate dateToRemoveQuarantine = LocalDate.parse("2022-12-01"); - switch (params.quarantine) { - case "base": - break; - case "nonSymptomatic0": - tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); - tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.NON_SYMPTOMATIC); - break; - case "withSymptoms0": - tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); - tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.WITH_SYMPTOMS); - break; - case "susceptible0": - tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); - tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.SUSCEPTIBLE); - break; - default: - throw new RuntimeException("invalid parameter"); - } + VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); + vaccinationConfig.setTEMP_updatedProbaOfTransitioningToShowingSymptoms(params.probaShowSymptoms); + +// TracingConfigGroup tracingConfig = ConfigUtils.addOrGetModule(config, TracingConfigGroup.class); +// LocalDate dateToRemoveQuarantine = LocalDate.parse("2022-12-01"); +// switch (params.quarantine) { +// case "base": +// break; +// case "nonSymptomatic0": +// tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); +// tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.NON_SYMPTOMATIC); +// break; +// case "withSymptoms0": +// tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); +// tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.WITH_SYMPTOMS); +// break; +// case "susceptible0": +// tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); +// tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.SUSCEPTIBLE); +// break; +// default: +// throw new RuntimeException("invalid parameter"); +// } @@ -693,16 +702,22 @@ public static final class Params { @StringParameter({"base", "off"}) public String maskPt; + @Parameter({0.2, 0.4, 0.6, 0.8, 1.0}) + public double probaShowSymptoms; + + - @StringParameter({"base", "nonSymptomatic0", "withSymptoms0", "susceptible0"}) - public String quarantine; +// @StringParameter({"base", "nonSymptomatic0", "withSymptoms0", "susceptible0"}) +// public String quarantine; // BQ 1 - @StringParameter({"off","2.0", "2.25", "2.5", "2.75", "3.0"}) +// @StringParameter({"off", "2.0", "2.25", "2.5", "2.75", "3.0"}) + @StringParameter({"2.0"}) public String StrainA; - @StringParameter({"2022-08-24", "2022-08-29", "2022-09-04", "2022-09-09", "2022-09-14", "2022-09-19"}) +// @StringParameter({"2022-08-24", "2022-08-29", "2022-09-04", "2022-09-09", "2022-09-14", "2022-09-19"}) + @StringParameter({"2022-09-19"}) public String strainADate; @@ -733,7 +748,7 @@ public static final class Params { public static void main(String[] args) { String[] args2 = { - RunParallel.OPTION_SETUP, CologneBMBF202212XX_soup.class.getName(), + RunParallel.OPTION_SETUP, CologneBMBF202212XX_bq1.class.getName(), RunParallel.OPTION_PARAMS, Params.class.getName(), RunParallel.OPTION_TASKS, Integer.toString(1), RunParallel.OPTION_ITERATIONS, Integer.toString(1000), diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java index 4800383a5..f7f2e0e84 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java @@ -143,6 +143,9 @@ protected void configure() { bind(AntibodyModel.Config.class).toInstance(antibodyConfig); + + UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + if (params == null) return; // HOUSEHOLD SUSCEPTIBILITY @@ -431,11 +434,11 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { - runCount++; - } else { - return null; - } +// if (runCount == 0 && params.escape(12.)) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { +// runCount++; +// } else { +// return null; +// } } SnzCologneProductionScenario module = getBindings(0.0, params); diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 7bc893f0b..12aac1c2f 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -382,7 +382,7 @@ public Config config() { CreateRestrictionsFromCSV activityParticipation = new CreateRestrictionsFromCSV(episimConfig); - activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20221102.csv")); + activityParticipation.setInput(INPUT.resolve("CologneSnzData_daily_until20221111.csv")); activityParticipation.setScale(this.scale); activityParticipation.setLeisureAsNightly(this.leisureNightly); From a7e2daa22e35178043e01547365dc4c1e290bfe2 Mon Sep 17 00:00:00 2001 From: Christian Rakow Date: Thu, 17 Nov 2022 13:36:19 +0100 Subject: [PATCH 118/128] generate a per seed file while aggregating runs --- src/main/python/analysis/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/python/analysis/utils.py b/src/main/python/analysis/utils.py index 82075b6bf..0d162edff 100644 --- a/src/main/python/analysis/utils.py +++ b/src/main/python/analysis/utils.py @@ -287,6 +287,19 @@ def aggregate_batch_run(run): buf = io.TextIOWrapper(zf, encoding="utf8", newline="\n") means.to_csv(buf, sep="\t", columns=list(dfs[0].columns), mode="w", line_terminator="\n", index=False) buf.flush() + + if "infections.txt.csv" in filename: + + cols = [dfs[0].day, dfs[0].date] + [df.nShowingSymptomsCumulative for df in dfs] + columns = pd.concat(cols, axis=1) + + columns.columns = [columns.columns[0], columns.columns[1]] + ["%s_%d" % (name, i) for i, name in enumerate(columns.columns[2:])] + + with zInner.open(str(runId) + ".infectionsPerSeed.tsv", "w") as zf: + buf = io.TextIOWrapper(zf, encoding="utf8", newline="\n") + columns.to_csv(buf, sep="\t", mode="w", line_terminator="\n", index=False) + buf.flush() + with z.open("summaries/" + str(runId) + ".zip", "w") as f: f.write(zip_buffer.getvalue()) From e028af78abdfd24dcdebcf03f7e5f45704e4e39d Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Fri, 18 Nov 2022 10:07:24 +0100 Subject: [PATCH 119/128] work on batch runs --- .../AntibodyDependentTransitionModel.java | 2 +- .../run/batch/CologneBMBF202212XX_bq1.java | 31 +++--- .../run/batch/CologneBMBF202212XX_soup.java | 103 +++++++++--------- .../run/batch/StartFromImmunizations.java | 4 +- .../java/org/matsim/run/batch/UtilsJR.java | 46 ++++++-- 5 files changed, 105 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 7be6fcc9c..bbe6e8677 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -34,7 +34,7 @@ public final EpisimPerson.DiseaseStatus decideNextState(EpisimPerson person, Epi double probaOfTransitioningToShowingSymptoms = getProbaOfTransitioningToShowingSymptoms(person); - if (day >= 981 // hardcoded: 2022-11-01 + if (day >= 1011 // hardcoded: 2022-12-01 && vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms() >= 0.0 && vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms() <= 1.0) { probaOfTransitioningToShowingSymptoms = vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms(); diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java index affc1aae8..fcb0bd250 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java @@ -388,11 +388,11 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); //snapshot - episimConfig.setSnapshotInterval(960); - episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); +// episimConfig.setSnapshotInterval(960); +// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); //idk -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-900-2022-08-12.zip"); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-11-17/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //newer snapshot modiefied slightly @@ -542,19 +542,14 @@ public Config prepareConfig(int id, Params params) { throw new RuntimeException("invalid parameter"); } - switch (params.maskPt) { - case "base": - break; - case "off": - builder.restrict(LocalDate.parse("2023-01-01"), - Restriction.ofMask(Map.of( - FaceMask.CLOTH, 0.0, - FaceMask.SURGICAL, 0.0, - FaceMask.N95, 0.0)), - "pt"); - break; - default: - throw new RuntimeException("invalid parameter"); + if ("base".equals(params.maskPt)) { + } else { + builder.restrict(LocalDate.parse(params.maskPt), + Restriction.ofMask(Map.of( + FaceMask.CLOTH, 0.0, + FaceMask.SURGICAL, 0.0, + FaceMask.N95, 0.0)), + "pt"); } VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); @@ -699,10 +694,10 @@ public static final class Params { public long seed; - @StringParameter({"base", "off"}) + @StringParameter({"base", "2022-11-15", "2022-12-01", "2022-12-15", "2023-01-01"}) public String maskPt; - @Parameter({0.2, 0.4, 0.6, 0.8, 1.0}) + @Parameter({0.0, 0.2, 0.4, 0.6, 0.8, 1.0}) public double probaShowSymptoms; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java index 832dfb397..0ce1f29ec 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_soup.java @@ -17,7 +17,6 @@ import org.matsim.episim.model.vaccination.VaccinationModel; import org.matsim.episim.model.vaccination.VaccinationStrategyReoccurringCampaigns; import org.matsim.episim.policy.FixedPolicy; -import org.matsim.episim.policy.Restriction; import org.matsim.run.RunParallel; import org.matsim.run.modules.SnzCologneProductionScenario; @@ -33,7 +32,7 @@ */ public class CologneBMBF202212XX_soup implements BatchRun { - boolean DEBUG_MODE = false; + boolean DEBUG_MODE = true; int runCount = 0; LocalDate restrictionDatePhase1 = LocalDate.parse("2022-12-01"); @@ -106,9 +105,9 @@ protected void configure() { double mutEscStrainA = 1.0; double mutEscStrainB = 1.0; - + double escape = 12.; - int days = 30; + int days = 30; String strainSeed = "no"; LocalDate strainADate = LocalDate.parse("2020-01-01"); boolean lineB = true; @@ -152,7 +151,7 @@ protected void configure() { bind(AntibodyModel.Config.class).toInstance(antibodyConfig); - UtilsJR.printInitialAntibodiesToConsole(initialAntibodies); + UtilsJR.printInitialAntibodiesToConsole(initialAntibodies, true); if (params == null) return; @@ -170,7 +169,7 @@ protected void configure() { private void configureAntibodies(Map> initialAntibodies, Map> antibodyRefreshFactors, - double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB, + double mutEscDelta, double mutEscBa1, double mutEscBa5, double mutEscStrainA, double mutEscStrainB, double escapePerYear, int days, String strainSeed, LocalDate strainADate, boolean lineB, double escapeBetweenLines) { for (VaccinationType immunityType : VaccinationType.values()) { initialAntibodies.put(immunityType, new EnumMap<>( VirusStrain.class ) ); @@ -317,35 +316,35 @@ else if (immunityType == VaccinationType.vector) { initialAntibodies.get(VirusStrain.STRAIN_B).put(VirusStrain.STRAIN_B, 64.0 / 300.); initialAntibodies.get(VaccinationType.ba1Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB); initialAntibodies.get(VaccinationType.ba5Update).put(VirusStrain.STRAIN_B, mRNAAlpha / mutEscStrainB / mutEscBa5); - - + + { - + ArrayList strains = getNewStrains(Boolean.valueOf(lineB)); - + ArrayList dates = getDatesNewStrains(strains, days, strainSeed, strainADate); for (int i = 0; i < strains.size(); i++) { long daysSince = ChronoUnit.DAYS.between(strainADate, dates.get(i)); double escape = 1. + (escapePerYear - 1.0) * daysSince / 365.; //factor 6, if variant appears 6 months later VirusStrain strain = strains.get(i); - + initialAntibodies.get(strain).put(VirusStrain.SARS_CoV_2, 0.01); initialAntibodies.get(strain).put(VirusStrain.ALPHA, 0.01); initialAntibodies.get(strain).put(VirusStrain.DELTA, 0.01); - + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA1, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA2, 64.0 / 300. / mutEscBa5 / mutEscStrainA / escape); - initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA / escape); + initialAntibodies.get(strain).put(VirusStrain.OMICRON_BA5, 64.0 / 300./ mutEscStrainA / escape); initialAntibodies.get(strain).put(VirusStrain.STRAIN_A, 64.0 / 300. / escape); - + double mRNAStrain = mRNAStrainA / escape; initialAntibodies.get(VaccinationType.mRNA).put(strain, mRNAStrain); initialAntibodies.get(VaccinationType.vector).put(strain, mRNAStrain * 4./20.); initialAntibodies.get(VirusStrain.SARS_CoV_2).put(strain, mRNAStrain * 6./20.); initialAntibodies.get(VirusStrain.ALPHA).put(strain, mRNAStrain * 6./20.); initialAntibodies.get(VirusStrain.DELTA).put(strain, mRNAStrain * 8./20.); - + initialAntibodies.get(VirusStrain.OMICRON_BA1).put(strain, 64.0 / 300. / mutEscBa5 /mutEscStrainA / escape); initialAntibodies.get(VirusStrain.OMICRON_BA2).put(strain, 64.0 / 300./ mutEscBa5 /mutEscStrainA / escape); initialAntibodies.get(VirusStrain.OMICRON_BA5).put(strain, 64.0 / 300. / mutEscStrainA / escape); @@ -353,26 +352,26 @@ else if (immunityType == VaccinationType.vector) { // initialAntibodies.get(VirusStrain.STRAIN_B).put(strain, 64.0 / 300. / mutEscStrainA / mutEscStrainB / mutEscBa5 / escape); initialAntibodies.get(VaccinationType.ba1Update).put(strain, mRNAAlpha / mutEscBa5 / mutEscStrainA / escape); initialAntibodies.get(VaccinationType.ba5Update).put(strain, mRNAAlpha / mutEscStrainA / escape); - - + + for (int j = 0; j < strains.size(); j++) { LocalDate date1 = dates.get(i); LocalDate date2 = dates.get(j); long daysBetweenStrains = Math.abs(ChronoUnit.DAYS.between(date1, date2)); double escapeBetweenStrains = 1. + (escapePerYear - 1.0) * daysBetweenStrains / 365.; //factor 6, if variant appears 6 months later VirusStrain strain2 = strains.get(j); - + if (strain.toString().charAt(0) != strain2.toString().charAt(0)) escapeBetweenStrains = escapeBetweenStrains * escapeBetweenLines; - + initialAntibodies.get(strain).put(strain2, 64.0 / 300. / escapeBetweenStrains); } - + } - - + + } - + for (VaccinationType immunityType : VaccinationType.values()) { @@ -447,11 +446,11 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { -// if (runCount == 0 && params.escape(12.)) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { -// runCount++; -// } else { -// return null; -// } + if (runCount == 0 && Boolean.parseBoolean(params.lineB) && params.esc == 12. && params.escL == 6.0 ) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + runCount++; + } else { + return null; + } } SnzCologneProductionScenario module = getBindings(0.0, params); @@ -486,7 +485,7 @@ public Config prepareConfig(int id, Params params) { virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); } - + for (VirusStrain strain : getNewStrains(Boolean.valueOf(params.lineB))) { virusStrainConfigGroup.getOrAddParams(strain).setInfectiousness(ba5Inf); virusStrainConfigGroup.getOrAddParams(strain).setFactorSeriouslySick(ba5Hos); @@ -543,16 +542,16 @@ public Config prepareConfig(int id, Params params) { VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); vaccinationConfig.setUseIgA(Boolean.valueOf(params.iga)); - + if (!Boolean.valueOf(params.seasonal)) { - + Map fractionsOld = episimConfig.getLeisureOutdoorFraction(); Map fractionsNew = new HashMap(); - + for (Entry e : fractionsOld.entrySet()) { if (e.getKey().isBefore(LocalDate.parse("2022-12-01"))) fractionsNew.put(e.getKey(), e.getValue()); - + } episimConfig.setLeisureOutdoorFraction(fractionsNew); } @@ -583,8 +582,8 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } - - + + for (int i = 0; i < getNewStrains(Boolean.valueOf(params.lineB)).size(); i++) { LocalDate date = getDatesNewStrains(getNewStrains(Boolean.valueOf(params.lineB)), params.days, params.strainRnd, LocalDate.parse(params.strainADate)).get(i); VirusStrain strain = getNewStrains(Boolean.valueOf(params.lineB)).get(i); @@ -626,25 +625,25 @@ public static final class Params { // @StringParameter({"2022-08-15", "2022-08-22", "2022-08-29", "2022-09-05", "2022-09-12", "2022-09-19", "2022-09-26"}) @StringParameter({"2022-09-12"}) public String strainADate; - + @Parameter({6., 12., 24.}) public double esc; - + @Parameter({1., 6.}) public double escL; - + @IntParameter({30}) public int days; - + @StringParameter({"no"}) public String strainRnd; - + @StringParameter({"true", "false"}) public String lineB; - + @StringParameter({"true", "false"}) public String iga; - + @StringParameter({"true", "false"}) public String seasonal; @@ -662,7 +661,7 @@ public static void main(String[] args) { RunParallel.main(args2); } - + private static ArrayList getNewStrains(boolean lineB) { ArrayList strains = new ArrayList(); strains.add(VirusStrain.A_1); @@ -686,7 +685,7 @@ private static ArrayList getNewStrains(boolean lineB) { strains.add(VirusStrain.A_19); strains.add(VirusStrain.A_20); - + if (lineB) { strains.add(1, VirusStrain.B_1); strains.add(3, VirusStrain.B_2); @@ -709,35 +708,35 @@ private static ArrayList getNewStrains(boolean lineB) { strains.add(37, VirusStrain.B_19); strains.add(39, VirusStrain.B_20); } - + return strains; } - + private static ArrayList getDatesNewStrains(ArrayList strains, int days, String seed, LocalDate start) { ArrayList dates = new ArrayList(); - + if (seed.equals("no")) { for (LocalDate date = start; ; date = date.plusDays(1)) { long daysBetween = ChronoUnit.DAYS.between(start, date); - if (daysBetween % days == 0) + if (daysBetween % days == 0) dates.add(date); if (dates.size() == strains.size()) break; } return dates; } - + else { - Random rand = new Random(Integer.parseInt(seed)); + Random rand = new Random(Integer.parseInt(seed)); for (LocalDate date = LocalDate.parse("2022-11-15"); ; date = date.plusDays(1)) { - if (rand.nextDouble() < 1. / days) + if (rand.nextDouble() < 1. / days) dates.add(date); if (dates.size() == strains.size()) break; } return dates; } - + } diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java index e21e0ade6..2b8b002c6 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -112,8 +112,8 @@ public Config prepareConfig(int id, Params params) { // episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); -// episimConfig.setStartFromSnapshot("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15/episim-snapshot-015-2020-03-10.zip"); + episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); + episimConfig.setStartFromSnapshot("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15/episim-snapshot-015-2020-03-10.zip"); //--------------------------------------- diff --git a/src/main/java/org/matsim/run/batch/UtilsJR.java b/src/main/java/org/matsim/run/batch/UtilsJR.java index fc0a43d71..9883e471d 100644 --- a/src/main/java/org/matsim/run/batch/UtilsJR.java +++ b/src/main/java/org/matsim/run/batch/UtilsJR.java @@ -19,6 +19,7 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.NavigableMap; @@ -148,28 +149,57 @@ private static void producePlot(DateColumn records, DoubleColumn values, StringC } - protected static void printInitialAntibodiesToConsole(Map> initialAntibodies) { + protected static void printInitialAntibodiesToConsole(Map> initialAntibodies, boolean ignoreSuperfluous) { + + List ignoredEvents = new ArrayList<>(); + if (ignoreSuperfluous) { + ignoredEvents = List.of(VirusStrain.STRAIN_B, VirusStrain.B1351, VaccinationType.generic, VaccinationType.natural, VaccinationType.ba1Update, VaccinationType.ba5Update); + } System.out.print("immunityGiver"); for (VirusStrain immunityFrom : VirusStrain.values()) { - if (immunityFrom == VirusStrain.OMICRON_BA1) { - System.out.print( "," + "BA.1"); - } else if (immunityFrom == VirusStrain.OMICRON_BA2) { - System.out.print( "," + "BA.2"); - } else { - System.out.print( "," + immunityFrom); - } + if (ignoredEvents.contains(immunityFrom)) { + continue; + } + +// if (immunityFrom == VirusStrain.OMICRON_BA1) { +// System.out.print("," + "BA.1"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA2) { +// System.out.print("," + "BA.2"); +// } else if (immunityFrom == VirusStrain.OMICRON_BA5) { +// System.out.print("," + "BA.5"); +// } else { + System.out.print("," + immunityFrom); +// } + } for (ImmunityEvent immunityGiver : VaccinationType.values()) { + + if (ignoredEvents.contains(immunityGiver)) { + continue; + } + System.out.print("\n" + immunityGiver); for (VirusStrain immunityFrom : VirusStrain.values()) { + if (ignoredEvents.contains(immunityFrom)) { + continue; + } System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); } } for (ImmunityEvent immunityGiver : VirusStrain.values()) { + + if (ignoredEvents.contains(immunityGiver)) { + continue; + } System.out.print("\n" + immunityGiver); for (VirusStrain immunityFrom : VirusStrain.values()) { + + if (ignoredEvents.contains(immunityFrom)) { + continue; + } + System.out.print("," + String.format("%.3g", initialAntibodies.get(immunityGiver).get(immunityFrom))); } } From ba2ed07363ca699df174df00f0c749e9daec876c Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 23 Nov 2022 11:41:59 +0100 Subject: [PATCH 120/128] turned tests off --- .../org/matsim/run/modules/SnzCologneProductionScenario.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 12aac1c2f..53c44ded1 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -677,8 +677,6 @@ public Config config() { testingConfigGroup.setTestAllPersonsAfter(LocalDate.parse("2021-10-01")); - - testingConfigGroup.setStrategy(TestingConfigGroup.Strategy.ACTIVITIES); List actsList = new ArrayList(); @@ -750,8 +748,7 @@ public Config config() { // kigaPrimaryTests.put(LocalDate.of(2022, 4, 25), 0.0); eduTests.put(LocalDate.of(2022, 4, 25), 0.0); uniTests.put(LocalDate.of(2022, 4, 25), 0.0); - leisureTests.put(LocalDate.of(2022, 4, 25), 0.1); // no more regulation regarding test, we assume once every 2 weeks - + leisureTests.put(LocalDate.of(2022, 4, 25), 0.0); Map> testingRatePerAct = new HashMap<>(Map.of( "leisure", leisureTests, From ec9d69012383405de69caa7658a333360659808b Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 24 Nov 2022 10:48:21 +0100 Subject: [PATCH 121/128] added number of vaccinations to InfectionEvent --- .../java/org/matsim/episim/EpisimPerson.java | 2 +- .../analysis/HospitalNumbersFromEvents.java | 107 ++++++++++-------- .../episim/events/EpisimEventsReader.java | 14 ++- .../episim/events/EpisimInfectionEvent.java | 14 ++- .../events/EpisimInitialInfectionEvent.java | 9 +- .../episim/model/AbstractContactModel.java | 4 +- .../AntibodyDependentTransitionModel.java | 4 +- .../run/batch/CologneBMBF202212XX_bq1.java | 29 +++-- .../run/batch/StartFromImmunizations.java | 12 +- .../org/matsim/episim/EpisimTestUtils.java | 2 +- .../HospitalNumbersFromEventsTest.java | 73 ++++++------ .../InitialImmunizationHandlerTest.java | 6 +- .../model/DefaultInfectionModelTest.java | 2 +- 13 files changed, 162 insertions(+), 116 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index 03144dfdb..92b672657 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -427,7 +427,7 @@ public void setDiseaseStatus(double now, DiseaseStatus status) { */ public void setInitialInfection(double now, VirusStrain strain) { - reporting.reportInfection(new EpisimInitialInfectionEvent(now, getPersonId(), strain, antibodies.getDouble(strain), maxAntibodies.getDouble(strain))); + reporting.reportInfection(new EpisimInitialInfectionEvent(now, getPersonId(), strain, antibodies.getDouble(strain), maxAntibodies.getDouble(strain),getNumInfections())); virusStrains.add(strain); setDiseaseStatus(now, EpisimPerson.DiseaseStatus.infectedButNotContagious); diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index c6cbf3bd3..2551432fa 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -60,8 +60,9 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { -// @CommandLine.Option(names = "--output", defaultValue = "./output/") - @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-10-18/3-meas/analysis/") + @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/matsim-episim/A_originalImmHist") +// @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/matsim-episim/B_startedFromImmHist") +// @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-10-18/3-meas/analysis/") private Path output; // @CommandLine.Option(names = "--input", defaultValue = "/scratch/projects/bzz0020/episim-input") @@ -71,7 +72,8 @@ public class HospitalNumbersFromEvents implements OutputAnalysis { @CommandLine.Option(names = "--population-file", defaultValue = "/cologne_snz_entirePopulation_emptyPlans_withDistricts_25pt_split.xml.gz") private String populationFile; - @CommandLine.Option(names = "--start-date", defaultValue = "2020-02-24") +// @CommandLine.Option(names = "--start-date", defaultValue = "2022-04-01") + @CommandLine.Option(names = "--start-date", defaultValue = "2020-02-25") private LocalDate startDate; @CommandLine.Option(names = "--district", description = "District to filter for", defaultValue = "Köln") @@ -223,8 +225,8 @@ public Integer call() throws Exception { // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList); //TODO: move to other class - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); - HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); +// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); @@ -334,7 +336,7 @@ static int getWeeklyHospitalizations(Int2IntMap hospMap, Integer today) { } - public static final class Handler implements EpisimVaccinationEventHandler, EpisimInfectionEventHandler, EpisimInitialInfectionEventHandler{ + public static final class Handler implements EpisimInfectionEventHandler, EpisimInitialInfectionEventHandler{ final Map, ImmunizablePerson> data; private final String name; private final Population population; @@ -360,14 +362,8 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis private final Int2IntMap incBaseImmunity; private final Int2IntMap incBoostered; -// private final EpisimWriter episimWriter; - BufferedWriter hospCalibration; - -// private CSVPrinter printer; - private final AgeDependentDiseaseStatusTransitionModel transitionModel; - Handler(String name, Population population, ConfigHolder holder, double paxlovidCompliance) { // instantiate the custom event handler that calculates hospitalizations based on events @@ -406,7 +402,6 @@ public static final class Handler implements EpisimVaccinationEventHandler, Epis } - //TODO: add INITIAL INFECTION EVENT @Override public void handleEvent(EpisimInfectionEvent event) { @@ -424,6 +419,7 @@ public void handleEvent(EpisimInfectionEvent event) { person.addInfection(event.getTime()); // person.setAntibodyLevelAtInfection(event.getAntibodies()); // commented out as we're only using the max antibody level from now on person.setVirusStrain(virusStrain); + person.setNumVaccinations(event.getNumVaccinations()); person.updateMaxAntibodies(virusStrain, event.getMaxAntibodies()); @@ -460,41 +456,41 @@ public void handleEvent(EpisimInfectionEvent event) { } - - - @Override - public void handleEvent(EpisimVaccinationEvent event) { - -// if (!event.getPersonId().toString().equals("12102f5")) -// return; - - ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); - - String district = (String) population.getPersons().get(person.personId).getAttributes().getAttribute("district"); - - if (!district.equals("Köln")){ - return; - } - - int day = (int) (event.getTime() / 86_400); - - if (person.getNumVaccinations()==0) { - changeBaseImmunity.mergeInt(day, 1, Integer::sum); - changeNoImmunity.mergeInt(day, -1, Integer::sum); - } else if (person.getNumVaccinations() == 1) { - changeBoostered.mergeInt(day, 1, Integer::sum); - changeBaseImmunity.mergeInt(day, -1, Integer::sum); - } - - - person.addVaccination(day); - } - @Override public void handleEvent(EpisimInitialInfectionEvent event) { handleEvent(event.asInfectionEvent()); } + +// @Override +// public void handleEvent(EpisimVaccinationEvent event) { +// +//// if (!event.getPersonId().toString().equals("12102f5")) +//// return; +// +// ImmunizablePerson person = data.computeIfAbsent(event.getPersonId(), personId -> new ImmunizablePerson(personId, getAge(personId))); +// +// String district = (String) population.getPersons().get(person.personId).getAttributes().getAttribute("district"); +// +// if (!district.equals("Köln")){ +// return; +// } +// +// int day = (int) (event.getTime() / 86_400); +// +// if (person.getNumVaccinations()==0) { +// changeBaseImmunity.mergeInt(day, 1, Integer::sum); +// changeNoImmunity.mergeInt(day, -1, Integer::sum); +// } else if (person.getNumVaccinations() == 1) { +// changeBoostered.mergeInt(day, 1, Integer::sum); +// changeBaseImmunity.mergeInt(day, -1, Integer::sum); +// } +// +// +// person.addVaccination(day); + +// } + private int getAge(Id personId) { return (int) population.getPersons().get(personId).getAttributes().getAttribute("microm:modeled:age"); } @@ -583,10 +579,21 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st */ private boolean goToHospital(ImmunizablePerson person, int day) { + + if (List.of("12c304f").contains(person.personId.toString())) { + System.out.println(); + } + double ageFactor = transitionModel.getProbaOfTransitioningToSeriouslySick(person); double strainFactor = holder.strainConfig.getParams(person.getVirusStrain()).getFactorSeriouslySick(); double immunityFactor = transitionModel.getSeriouslySickFactor(person, holder.vaccinationConfig, day); + if (List.of("12c304f").contains(person.personId.toString())) { + System.out.println(person.getMaxAntibodies()); + System.out.println(person.getPersonId() + " ---- age " + ageFactor + ", strain " + strainFactor + ", immunity " + immunityFactor); + + } + double paxlovidFactor = 1.0; if (person.getAge() > 60 && day >= this.paxlovidDay) { if (rnd.nextDouble() < this.paxlovidCompliance) { @@ -654,6 +661,8 @@ static final class ImmunizablePerson implements Immunizable{ private int age; + private int numVaccinations; + ImmunizablePerson(Id personId, int age) { this.personId = personId; this.age = age; @@ -666,7 +675,11 @@ public Id getPersonId() { @Override public int getNumVaccinations() { - return vaccinationDates.size(); + return numVaccinations; + } + public void setNumVaccinations(int numVaccinations) { + this.numVaccinations = numVaccinations; + } @Override @@ -684,9 +697,9 @@ public VirusStrain getVirusStrain() { return strain; } - public void addVaccination(int day) { - vaccinationDates.add(day); - } +// public void addVaccination(int day) { +// vaccinationDates.add(day); +// } @Override public IntList getVaccinationDates() { diff --git a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java index fd8c19697..ba09a0948 100644 --- a/src/main/java/org/matsim/episim/events/EpisimEventsReader.java +++ b/src/main/java/org/matsim/episim/events/EpisimEventsReader.java @@ -99,7 +99,12 @@ private MatsimEventsReader.CustomEventMapper getEpisimInfectionEventMapper() { maxAntibodies = Double.parseDouble(attributes.get(EpisimInfectionEvent.MAX_ANTIBODIES)); } - return new EpisimInfectionEvent(time, person, infector, container, type, groupSize, virusStrain, probability, antibodies, maxAntibodies); + int vaccinationCnt = -1; + attr = attributes.get(EpisimInfectionEvent.NUM_VACCINATIONS); + if (attr != null) + vaccinationCnt = Integer.parseInt(attr); + + return new EpisimInfectionEvent(time, person, infector, container, type, groupSize, virusStrain, probability, antibodies, maxAntibodies, vaccinationCnt); }; } @@ -149,7 +154,12 @@ private MatsimEventsReader.CustomEventMapper getEpisimInitialInfectionEventMappe maxAntibodies = Double.parseDouble(attributes.get(EpisimInfectionEvent.MAX_ANTIBODIES)); } - return new EpisimInitialInfectionEvent(time, person,virusStrain, antibodies, maxAntibodies); + int vaccinationCnt = -1; + String attr = attributes.get(EpisimInfectionEvent.NUM_VACCINATIONS); + if (attr != null) + vaccinationCnt = Integer.parseInt(attr); + + return new EpisimInitialInfectionEvent(time, person,virusStrain, antibodies, maxAntibodies, vaccinationCnt); }; } diff --git a/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java b/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java index 19f805302..74007cbbf 100644 --- a/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java +++ b/src/main/java/org/matsim/episim/events/EpisimInfectionEvent.java @@ -26,6 +26,7 @@ public class EpisimInfectionEvent extends Event implements HasPersonId, Comparab static final String GROUP_SIZE = "groupSize"; static final String ANTIBODIES = "antibodies"; static final String MAX_ANTIBODIES = "maxAntibodies"; + static final String NUM_VACCINATIONS = "numVaccinations"; private final Id personId; private final Id infectorId; @@ -37,12 +38,14 @@ public class EpisimInfectionEvent extends Event implements HasPersonId, Comparab private final double antibodies; private final double maxAntibodies; + private final int numVaccinations; + /** * Constructor. */ public EpisimInfectionEvent(double time, Id personId, Id infectorId, Id containerId, String infectionType, - int groupSize, VirusStrain strain, double probability, double antibodies, double maxAntibodies) { + int groupSize, VirusStrain strain, double probability, double antibodies, double maxAntibodies, int numVaccinations) { super(time); this.personId = personId; @@ -54,6 +57,7 @@ public EpisimInfectionEvent(double time, Id personId, Id infecto this.probability = probability; this.antibodies = antibodies; this.maxAntibodies = maxAntibodies; + this.numVaccinations = numVaccinations; } @Override @@ -113,6 +117,13 @@ public double getMaxAntibodies() { return maxAntibodies; } + /** + * Number of vaccinations agent has received at time of infection + */ + public int getNumVaccinations(){ + return numVaccinations; + } + @Override public Map getAttributes() { Map attr = super.getAttributes(); @@ -125,6 +136,7 @@ public Map getAttributes() { attr.put(VIRUS_STRAIN, virusStrain.toString()); attr.put(ANTIBODIES, Double.toString(antibodies)); attr.put(MAX_ANTIBODIES, Double.toString(maxAntibodies)); + attr.put(NUM_VACCINATIONS, Integer.toString(numVaccinations)); return attr; } diff --git a/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java b/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java index a8d1c1b97..c05a6c2c9 100644 --- a/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java +++ b/src/main/java/org/matsim/episim/events/EpisimInitialInfectionEvent.java @@ -19,27 +19,29 @@ public class EpisimInitialInfectionEvent extends Event implements HasPersonId, C private final Id personId; private final VirusStrain virusStrain; private final double antibodies; - private final double maxAntibodies; + private final int numVaccinations; /** * Constructor. */ - public EpisimInitialInfectionEvent(double time, Id personId, VirusStrain strain, double antibodies, double maxAntibodies) { + public EpisimInitialInfectionEvent(double time, Id personId, VirusStrain strain, double antibodies, double maxAntibodies, int numVaccinations) { + super(time); this.personId = personId; this.virusStrain = strain; this.antibodies = antibodies; this.maxAntibodies = maxAntibodies; + this.numVaccinations = numVaccinations; } /** * Return initial infection as "normal" infection event. */ public EpisimInfectionEvent asInfectionEvent() { - return new EpisimInfectionEvent(getTime(), personId, null, null, null, -1, virusStrain, 0, antibodies, maxAntibodies); + return new EpisimInfectionEvent(getTime(), personId, null, null, null, -1, virusStrain, 0, antibodies, maxAntibodies, numVaccinations); } @Override @@ -62,6 +64,7 @@ public Map getAttributes() { attr.put(EpisimInfectionEvent.VIRUS_STRAIN, virusStrain.toString()); attr.put(EpisimInfectionEvent.ANTIBODIES, Double.toString(antibodies)); attr.put(EpisimInfectionEvent.MAX_ANTIBODIES, Double.toString(maxAntibodies)); + attr.put(EpisimInfectionEvent.NUM_VACCINATIONS, Integer.toString(numVaccinations)); return attr; } diff --git a/src/main/java/org/matsim/episim/model/AbstractContactModel.java b/src/main/java/org/matsim/episim/model/AbstractContactModel.java index 3226c2084..096f3bcaa 100644 --- a/src/main/java/org/matsim/episim/model/AbstractContactModel.java +++ b/src/main/java/org/matsim/episim/model/AbstractContactModel.java @@ -398,8 +398,8 @@ protected void infectPerson(EpisimPerson personWrapper, EpisimPerson infector, d personWrapper.possibleInfection( new EpisimInfectionEvent(now, personWrapper.getPersonId(), infector.getPersonId(), - container.getContainerId(), infectionType.toString(), container.getPersons().size(), infector.getVirusStrain(), prob, - personWrapper.getAntibodies(infector.getVirusStrain()),personWrapper.getMaxAntibodies(infector.getVirusStrain())) + container.getContainerId(), infectionType.toString(), container.getPersons().size(), infector.getVirusStrain(), prob, + personWrapper.getAntibodies(infector.getVirusStrain()), personWrapper.getMaxAntibodies(infector.getVirusStrain()), personWrapper.getNumVaccinations()) ); // check infection immediately if there is only one thread diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index bbe6e8677..02959e9c0 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -123,8 +123,8 @@ public double getSeriouslySickFactor(Immunizable person, VaccinationConfigGroup int numVaccinations = person.getNumVaccinations(); int numInfections = person.getNumInfections() - 1; - if (numVaccinations == 0 && numInfections == 0) - return 1.0; +// if (numVaccinations == 0 && numInfections == 0) +// return 1.0; VirusStrain strain = person.getVirusStrain(); diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java index fcb0bd250..ca8563c69 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java @@ -29,12 +29,13 @@ public class CologneBMBF202212XX_bq1 implements BatchRun { boolean DEBUG_MODE = false; + + String START_DATE = "2022-04-01"; int runCount = 0; LocalDate restrictionDatePhase1 = LocalDate.parse("2022-12-01"); LocalDate restrictionDatePhase2 = restrictionDatePhase1.plusDays(10); - @Nullable @Override public Module getBindings(int id, @Nullable Params params) { @@ -357,11 +358,11 @@ public Metadata getMetadata() { @Override public Collection postProcessing() { return List.of( - new VaccinationEffectiveness().withArgs(), - new RValuesFromEvents().withArgs(), - new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new FilterEvents().withArgs("--output","./output/"), - new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") + new VaccinationEffectiveness().withArgs("--start-date", START_DATE), + new RValuesFromEvents().withArgs("--start-date", START_DATE), +// new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), + new FilterEvents().withArgs("--output", "./output/"), + new HospitalNumbersFromEvents().withArgs("--output", "./output/", "--input", "/scratch/projects/bzz0020/episim-input", "--start-date", START_DATE) // new SecondaryAttackRateFromEvents().withArgs() ); } @@ -370,7 +371,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0 && params.vacCamp.equals("emergency180")) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { runCount++; } else { return null; @@ -387,12 +388,18 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); + + + episimConfig.setStartDate(LocalDate.parse(START_DATE)); + episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/imm-hist-970-2022-10-21/"); + + //snapshot // episimConfig.setSnapshotInterval(960); // episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); //idk -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-11-17/" + params.seed + "-960-2022-10-11.zip"); +// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-11-18/" + params.seed + "-960-2022-10-11.zip"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); //newer snapshot modiefied slightly @@ -694,10 +701,12 @@ public static final class Params { public long seed; - @StringParameter({"base", "2022-11-15", "2022-12-01", "2022-12-15", "2023-01-01"}) +// @StringParameter({"base", "2022-11-15", "2022-12-01", "2022-12-15", "2023-01-01"}) + @StringParameter({"base"}) public String maskPt; - @Parameter({0.0, 0.2, 0.4, 0.6, 0.8, 1.0}) + // @Parameter({0.0, 0.2, 0.4, 0.6, 0.8, 1.0}) + @Parameter({0.8, 1.0}) public double probaShowSymptoms; diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java index 2b8b002c6..065061ea9 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -84,8 +84,8 @@ public Collection postProcessing() { // new VaccinationEffectiveness().withArgs(), // new RValuesFromEvents().withArgs(), // new VaccinationEffectivenessFromPotentialInfections().withArgs("--remove-infected"), - new FilterEvents().withArgs("--output","./output/") -// new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/scratch/projects/bzz0020/episim-input") + new FilterEvents().withArgs("--output","./output/"), + new HospitalNumbersFromEvents().withArgs("--output","./output/","--input","/Users/jakob/git/shared-svn/projects/episim/matsim-files/snz/Cologne/episim-input") // new SecondaryAttackRateFromEvents().withArgs() ); } @@ -108,12 +108,12 @@ public Config prepareConfig(int id, Params params) { // episimConfig.setSnapshotInterval(15); // -// episimConfig.setStartDate(LocalDate.parse("2020-03-10")); -// episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15"); + episimConfig.setStartDate(LocalDate.parse("2022-04-01")); + episimConfig.setStartFromImmunization("/Users/jakob/imm-hist-970-2022-10-21"); - episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); - episimConfig.setStartFromSnapshot("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15/episim-snapshot-015-2020-03-10.zip"); +// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); +// episimConfig.setStartFromSnapshot("/Users/jakob/git/matsim-episim/output/seed_4711/2022-11-15/episim-snapshot-015-2020-03-10.zip"); //--------------------------------------- diff --git a/src/test/java/org/matsim/episim/EpisimTestUtils.java b/src/test/java/org/matsim/episim/EpisimTestUtils.java index 47831181c..c2e0c0894 100644 --- a/src/test/java/org/matsim/episim/EpisimTestUtils.java +++ b/src/test/java/org/matsim/episim/EpisimTestUtils.java @@ -190,7 +190,7 @@ public static EpisimPerson createPerson(boolean vaccinable, int age) { * Helper method to infect a person. */ public static EpisimPerson infectPerson(EpisimPerson p, VirusStrain strain, double now) { - p.possibleInfection(new EpisimInfectionEvent(now, p.getPersonId(), p.getPersonId(), null, "undefined", 1, strain, 1.0, -1,-1)); + p.possibleInfection(new EpisimInfectionEvent(now, p.getPersonId(), p.getPersonId(), null, "undefined", 1, strain, 1.0, -1, -1, p.getNumVaccinations())); p.checkInfection(); return p; } diff --git a/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java b/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java index 6491e0a78..055e49f23 100644 --- a/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java +++ b/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java @@ -79,15 +79,15 @@ public void testHandlerData() { assertTrue(handler.data.isEmpty()); // add vaccination event - data should contain person1 - handler.handleEvent(new EpisimVaccinationEvent(0., personId1, VaccinationType.mRNA, 1)); - assertFalse(handler.data.isEmpty()); - assertTrue(handler.data.containsKey(personId1)); - - handler.data.clear(); +// handler.handleEvent(new EpisimVaccinationEvent(0., personId1, VaccinationType.mRNA, 1)); +// assertFalse(handler.data.isEmpty()); +// assertTrue(handler.data.containsKey(personId1)); +// +// handler.data.clear(); // same thing for infection event assertTrue(handler.data.isEmpty()); - handler.handleEvent(new EpisimInfectionEvent(0., personId1, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.,0.)); + handler.handleEvent(new EpisimInfectionEvent(0., personId1, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0.,0.,-1)); assertFalse(handler.data.isEmpty()); assertTrue(handler.data.containsKey(personId1)); @@ -106,7 +106,7 @@ public void testAgeComponent() { // infect every person an infection for (int i = 0; i < populationSize; i++) { Id personId = Id.createPersonId(i); - handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.,0)); } // extract total number of hospitalisations @@ -123,7 +123,7 @@ public void testAgeComponent() { Id personId = Id.createPersonId(i); Person person = population.getPersons().get(personId); person.getAttributes().putAttribute("microm:modeled:age", 75); - handler.handleEvent(new EpisimInfectionEvent(10 * 24 * 3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + handler.handleEvent(new EpisimInfectionEvent(10 * 24 * 3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0., 0)); } int hospitalizations75 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); @@ -155,7 +155,7 @@ public void testStrainComponent() { // calculate hospitalizations/ICU for wild type for (int i = 0; i < populationSize; i++) { Id personId = Id.createPersonId(i); - handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); + handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.,0)); } int hospitalizations100 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); @@ -167,7 +167,7 @@ public void testStrainComponent() { // calculate hospitalizations/ICU for omicron for (int i = 0; i < populationSize; i++) { Id personId = Id.createPersonId(i); - handler.handleEvent(new EpisimInfectionEvent(100 * 24 * 3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.OMICRON_BA1, 0., 0., 0.)); + handler.handleEvent(new EpisimInfectionEvent(100 * 24 * 3600., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.OMICRON_BA1, 0., 0., 0.,0)); } int hospitalizations60 = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); @@ -184,31 +184,30 @@ public void testStrainComponent() { } - @Test - public void testImmunityComponent() { - - // calculate hospitalizations/ICU for people without any antibodies - for (int i = 0; i < populationSize; i++) { - Id personId = Id.createPersonId(i); - handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); - } - - int hospitalizationsNoImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); - int icuNoImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); - - handler.data.clear(); - - for (int i = 0; i < populationSize; i++) { - Id personId = Id.createPersonId(i); - handler.handleEvent(new EpisimInfectionEvent(10 * EpisimUtils.DAY, personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.)); - handler.handleEvent(new EpisimInfectionEvent(15 * EpisimUtils.DAY, personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 50.)); - } - - int hospitalizationsWithImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); - int icuWithImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); - -// assertThat(hospitalizationsWithImmunity).isLessThan(hospitalizationsNoImmunity); -// assertThat(icuWithImmunity).isLessThan(icuNoImmunity); - return; - } +// @Test +// public void testImmunityComponent() { +// +// // calculate hospitalizations/ICU for people without any antibodies +// for (int i = 0; i < populationSize; i++) { +// Id personId = Id.createPersonId(i); +// handler.handleEvent(new EpisimInfectionEvent(0., personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.,0)); +// } +// +// int hospitalizationsNoImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); +// int icuNoImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); +// +// handler.data.clear(); +// +// for (int i = 0; i < populationSize; i++) { +// Id personId = Id.createPersonId(i); +// handler.handleEvent(new EpisimInfectionEvent(10 * EpisimUtils.DAY, personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 0.,0)); +// handler.handleEvent(new EpisimInfectionEvent(15 * EpisimUtils.DAY, personId, Id.createPersonId("infector"), Id.create("facility", Facility.class), "", 2, VirusStrain.SARS_CoV_2, 0., 0., 50.,0)); +// } +// +// int hospitalizationsWithImmunity = handler.postProcessHospitalAdmissions.get(handler.postProcessHospitalAdmissions.lastIntKey()); +// int icuWithImmunity = handler.postProcessICUAdmissions.get(handler.postProcessICUAdmissions.lastIntKey()); +// +//// assertThat(hospitalizationsWithImmunity).isLessThan(hospitalizationsNoImmunity); +//// assertThat(icuWithImmunity).isLessThan(icuNoImmunity); +// } } diff --git a/src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java b/src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java index 0426ae68e..b3a4ee810 100644 --- a/src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java +++ b/src/test/java/org/matsim/episim/events/InitialImmunizationHandlerTest.java @@ -63,7 +63,7 @@ public void person() { manager.processEvent(new EpisimStartEvent(date1, "...")); // initial infection (from import) on day 2 - manager.processEvent(new EpisimInitialInfectionEvent(2 * EpisimUtils.DAY, patient0.getPersonId(), VirusStrain.SARS_CoV_2, -1, -1)); + manager.processEvent(new EpisimInitialInfectionEvent(2 * EpisimUtils.DAY, patient0.getPersonId(), VirusStrain.SARS_CoV_2, -1, -1, -1)); assertThat(patient0.getNumInfections()).isEqualTo(1); assertThat(patient0.getNumVaccinations()).isEqualTo(0); @@ -73,7 +73,7 @@ public void person() { assertTrue(patient0.getInfectionDates().contains(-2 * EpisimUtils.DAY)); // infection on day 3 - manager.processEvent(new EpisimInfectionEvent(3 * EpisimUtils.DAY, patient0.getPersonId(), patient0.getPersonId(), null, "undefined", 1, VirusStrain.SARS_CoV_2, 1.0, -1,-1)); + manager.processEvent(new EpisimInfectionEvent(3 * EpisimUtils.DAY, patient0.getPersonId(), patient0.getPersonId(), null, "undefined", 1, VirusStrain.SARS_CoV_2, 1.0, -1,-1,-1)); assertThat(patient0.getNumInfections()).isEqualTo(2); assertThat(patient0.getNumVaccinations()).isEqualTo(0); @@ -96,7 +96,7 @@ public void person() { // vaccination on day 5 and infection on day 6; neither should be registered because they occur on or after start date of new simulation manager.processEvent(new EpisimVaccinationEvent(5 * EpisimUtils.DAY, patient0.getPersonId(), VaccinationType.mRNA,1 )); - manager.processEvent(new EpisimInfectionEvent(6 * EpisimUtils.DAY, patient0.getPersonId(), patient0.getPersonId(), null, "undefined", 1, VirusStrain.SARS_CoV_2, 1.0, -1,-1)); + manager.processEvent(new EpisimInfectionEvent(6 * EpisimUtils.DAY, patient0.getPersonId(), patient0.getPersonId(), null, "undefined", 1, VirusStrain.SARS_CoV_2, 1.0, -1,-1,-1)); assertThat(patient0.getNumInfections()).isEqualTo(2); assertThat(patient0.getInfectionDates().size()).isEqualTo(2); diff --git a/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java b/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java index 1d3229fb2..090f00216 100644 --- a/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java +++ b/src/test/java/org/matsim/episim/model/DefaultInfectionModelTest.java @@ -123,7 +123,7 @@ public void immunityEffectiveness() { EpisimPerson p = EpisimTestUtils.createPerson(true, -1); - p.possibleInfection(new EpisimInfectionEvent(0, p.getPersonId(), p.getPersonId(), null, "somewhere", 1, VirusStrain.SARS_CoV_2, 1d, -1,-1)); + p.possibleInfection(new EpisimInfectionEvent(0, p.getPersonId(), p.getPersonId(), null, "somewhere", 1, VirusStrain.SARS_CoV_2, 1d, -1, -1, -1)); p.checkInfection(); p.setDiseaseStatus(1000, EpisimPerson.DiseaseStatus.recovered); p.setDiseaseStatus(2000, EpisimPerson.DiseaseStatus.susceptible); From 8cea4efa22e8bfb812c088e313eca779066a1cbc Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 24 Nov 2022 10:52:03 +0100 Subject: [PATCH 122/128] remove paxlovid from hospitalisation post processing --- .../analysis/HospitalNumbersFromEvents.java | 42 ++----------------- .../HospitalNumbersFromEventsTest.java | 5 +-- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 2551432fa..bea4897e7 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -227,8 +227,6 @@ public Integer call() throws Exception { //TODO: move to other class // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron"); // HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta"); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_OmicronPaxlovid", startDate, "Omicron-Paxlovid"); -// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_DeltaPaxlovid", startDate, "Delta-Paxlovid"); // } @@ -272,14 +270,8 @@ private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path t ConfigHolder holderDelta = configure(factorScen3, 1.0); //scenario 3 List handlers = List.of( - new Handler("Omicron", population, holderOmicron, 0.0), - new Handler("Delta", population, holderDelta, 0.0) -// new Handler("Omicron-Paxlovid-0.25 ", population, holderOmicron, 0.25), -// new Handler("Delta-Paxlovid-0.25", population, holderDelta, 0.25), -// new Handler("Omicron-Paxlovid-0.50", population, holderOmicron, 0.5), -// new Handler("Delta-Paxlovid-0.50", population, holderDelta, 0.5), -// new Handler("Omicron-Paxlovid-0.75", population, holderOmicron, 0.75), -// new Handler("Delta-Paxlovid-0.75", population, holderDelta, 0.75) + new Handler("Omicron", population, holderOmicron), + new Handler("Delta", population, holderDelta) ); // feed the output events file to the handler, so that the hospitalizations may be calculated @@ -343,10 +335,6 @@ public static final class Handler implements EpisimInfectionEventHandler, Episim private final Random rnd; private final ConfigHolder holder; - private final double paxlovidCompliance; - - private final int paxlovidDay; - final Int2IntSortedMap postProcessHospitalAdmissions; final Int2IntSortedMap postProcessICUAdmissions; final Int2IntSortedMap postProcessHospitalFilledBeds; @@ -364,7 +352,7 @@ public static final class Handler implements EpisimInfectionEventHandler, Episim private final AgeDependentDiseaseStatusTransitionModel transitionModel; - Handler(String name, Population population, ConfigHolder holder, double paxlovidCompliance) { + Handler(String name, Population population, ConfigHolder holder) { // instantiate the custom event handler that calculates hospitalizations based on events this.name = name; @@ -372,8 +360,6 @@ public static final class Handler implements EpisimInfectionEventHandler, Episim this.population = population; this.rnd = new Random(1234); this.holder = holder; - this.paxlovidCompliance = paxlovidCompliance; - this.paxlovidDay = (int) LocalDate.of(2020, 2, 25).datesUntil(LocalDate.of(2022, 11, 1)).count(); // key : iteration, value : admissions/filled beds this.postProcessHospitalAdmissions = new Int2IntAVLTreeMap(); @@ -495,18 +481,6 @@ private int getAge(Id personId) { return (int) population.getPersons().get(personId).getAttributes().getAttribute("microm:modeled:age"); } - /* - % infected who get paxlovid (for a certain age group): - - 75% of people over 60 get paxlovid - + - 75% of people with antibodyResponse below 0.3 - - effectivity: 66% reduction, chance of hospitalization * 0.33 - - - */ - private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain strain, int infectionIteration) { // check whether we entered all information for the strain @@ -594,17 +568,9 @@ private boolean goToHospital(ImmunizablePerson person, int day) { } - double paxlovidFactor = 1.0; - if (person.getAge() > 60 && day >= this.paxlovidDay) { - if (rnd.nextDouble() < this.paxlovidCompliance) { - paxlovidFactor = 0.33; // todo - } - } - return rnd.nextDouble() < ageFactor * strainFactor - * immunityFactor - * paxlovidFactor; + * immunityFactor; } /** diff --git a/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java b/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java index 055e49f23..edd5e2084 100644 --- a/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java +++ b/src/test/java/org/matsim/episim/analysis/HospitalNumbersFromEventsTest.java @@ -13,12 +13,9 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.episim.EpisimConfigGroup; -import org.matsim.episim.EpisimUtils; import org.matsim.episim.VaccinationConfigGroup; import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.events.EpisimInfectionEvent; -import org.matsim.episim.events.EpisimVaccinationEvent; -import org.matsim.episim.model.VaccinationType; import org.matsim.episim.model.VirusStrain; import org.matsim.facilities.Facility; import java.util.Map; @@ -63,7 +60,7 @@ public void setUp() throws Exception { Map, Handler.ImmunizablePerson> data = new IdMap<>(Person.class, population.getPersons().size()); ConfigHolder configHolder = new ConfigHolder(episimConfig,vaccinationConfig,strainConfig); - handler = new Handler("xxx", population, configHolder, 0.); + handler = new Handler("xxx", population, configHolder); } From 131aa36612bb0871ed2ee87e32ce76efc72feacd Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 24 Nov 2022 10:55:01 +0100 Subject: [PATCH 123/128] remove hosp stats per vaccination status --- .../analysis/HospitalNumbersFromEvents.java | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index bea4897e7..2ca7a6f67 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -340,16 +340,6 @@ public static final class Handler implements EpisimInfectionEventHandler, Episim final Int2IntSortedMap postProcessHospitalFilledBeds; final Int2IntSortedMap postProcessHospitalFilledBedsICU; - private final Int2IntSortedMap changeBaseImmunity; - private final Int2IntMap changeNoImmunity; - private final Int2IntMap changeBoostered; - private final Int2IntMap hospNoImmunity; - private final Int2IntMap hospBoostered; - private final Int2IntMap hospBaseImmunity; - private final Int2IntMap incNoImmunity; - private final Int2IntMap incBaseImmunity; - private final Int2IntMap incBoostered; - private final AgeDependentDiseaseStatusTransitionModel transitionModel; Handler(String name, Population population, ConfigHolder holder) { @@ -367,16 +357,6 @@ public static final class Handler implements EpisimInfectionEventHandler, Episim this.postProcessHospitalFilledBeds = new Int2IntAVLTreeMap(); this.postProcessHospitalFilledBedsICU = new Int2IntAVLTreeMap(); - this.changeNoImmunity = new Int2IntAVLTreeMap(); - this.changeBaseImmunity = new Int2IntAVLTreeMap(); - this.changeBoostered = new Int2IntAVLTreeMap(); - this.hospNoImmunity = new Int2IntAVLTreeMap(); - this.hospBoostered = new Int2IntAVLTreeMap(); - this.hospBaseImmunity = new Int2IntAVLTreeMap(); - this.incNoImmunity = new Int2IntAVLTreeMap(); - this.incBaseImmunity = new Int2IntAVLTreeMap(); - this.incBoostered = new Int2IntAVLTreeMap(); - this.transitionModel = new AgeDependentDiseaseStatusTransitionModel(new SplittableRandom(1234), holder.episimConfig, holder.vaccinationConfig, holder.strainConfig); // try { @@ -403,7 +383,6 @@ public void handleEvent(EpisimInfectionEvent event) { VirusStrain virusStrain = event.getVirusStrain(); person.addInfection(event.getTime()); -// person.setAntibodyLevelAtInfection(event.getAntibodies()); // commented out as we're only using the max antibody level from now on person.setVirusStrain(virusStrain); person.setNumVaccinations(event.getNumVaccinations()); @@ -415,14 +394,6 @@ public void handleEvent(EpisimInfectionEvent event) { updateHospitalizationsPost(person, virusStrain, day); - if (person.getNumVaccinations()==0) { - incNoImmunity.mergeInt(day, 1, Integer::sum); - } else if (person.getNumVaccinations()==1) { - incBaseImmunity.mergeInt(day, 1, Integer::sum); - } else { - incBoostered.mergeInt(day, 1, Integer::sum); - } - // print to csv // System.out.println(event.getVirusStrain().toString()); @@ -500,16 +471,6 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st int inHospital = infectionIteration + lagBetweenInfectionAndHospitalisation.getInt(strain); postProcessHospitalAdmissions.mergeInt(inHospital, 1, Integer::sum); - // Currently not used TODO : Integrate into Covid-sim plots (i.e. hospitalizations unvaccinated vs vaccinated/boostered) - if (person.getNumVaccinations() == 0) { - hospNoImmunity.mergeInt(inHospital, 1, Integer::sum); - } else if (person.getNumVaccinations() == 1) { - hospBaseImmunity.mergeInt(inHospital, 1, Integer::sum); - } else { - hospBoostered.mergeInt(inHospital, 1, Integer::sum); - } - - if (goToICU(person, inHospital)) { // newly admitted to ICU @@ -625,7 +586,7 @@ static final class ImmunizablePerson implements Immunizable{ */ private final Object2DoubleMap maxAntibodies = new Object2DoubleOpenHashMap<>(); - private int age; + private final int age; private int numVaccinations; From 7fbc2d34c28aaa1ce1cf8d4c380d5cc09a9a25f4 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 24 Nov 2022 11:47:42 +0100 Subject: [PATCH 124/128] cleaned up batch --- .../run/batch/CologneBMBF202212XX_bq1.java | 150 ++---------------- 1 file changed, 13 insertions(+), 137 deletions(-) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java index ca8563c69..d889d0c07 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java @@ -105,19 +105,8 @@ protected void configure() { if (params != null) { -// mutEscBa1 = params.ba1Esc; -// mutEscBa5 = params.ba5Esc; -// String StrainA = "6.0"; - String StrainB = "off"; - - - if (!params.StrainA.equals("off")) { - mutEscStrainA = Double.parseDouble(params.StrainA); - } - if (!StrainB.equals("off")) { - mutEscStrainB = Double.parseDouble(StrainB); - } + mutEscStrainA = Double.parseDouble(params.StrainA); } @@ -371,7 +360,7 @@ public Collection postProcessing() { public Config prepareConfig(int id, Params params) { if (DEBUG_MODE) { - if (runCount == 0) { //&& params.strAEsc != 0.0 && params.ba5Inf == 0. && params.eduTest.equals("true")) { + if (runCount == 0) { runCount++; } else { return null; @@ -389,25 +378,10 @@ public Config prepareConfig(int id, Params params) { episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7); - - episimConfig.setStartDate(LocalDate.parse(START_DATE)); - episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/imm-hist-970-2022-10-21/"); - - - //snapshot -// episimConfig.setSnapshotInterval(960); -// episimConfig.setSnapshotPrefix(String.valueOf(params.seed)); - - //idk -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-11-18/" + params.seed + "-960-2022-10-11.zip"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - - //newer snapshot modiefied slightly -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-27/" + params.seed + "-960-2022-10-11.zip"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); - //from last bericht -// episimConfig.setStartFromSnapshot("/scratch/projects/bzz0020/episim-input/snapshots-cologne-2022-10-18/" + params.seed + "-960-2022-10-11.zip"); -// episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.restore); + // start from immunization history +// episimConfig.setStartDate(LocalDate.parse(START_DATE)); +// episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/imm-hist-970-2022-10-21/"); + //--------------------------------------- // S T R A I N S //--------------------------------------- @@ -417,23 +391,11 @@ public Config prepareConfig(int id, Params params) { double ba5Inf = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getInfectiousness(); double ba5Hos = virusStrainConfigGroup.getOrAddParams(VirusStrain.OMICRON_BA5).getFactorSeriouslySick(); -// STRAIN_A - if (!params.StrainA.equals("off")) { - - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); - virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); - } -// STRAIN_B -// if (!params.StrainB.equals("off")) { -// -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setInfectiousness(virusStrainConfigGroup.getParams(VirusStrain.OMICRON_BA5).getInfectiousness() * ba5Inf); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySickVaccinated(ba5Hos); -// virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(ba5Hos); -// } + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setInfectiousness(ba5Inf); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySickVaccinated(ba5Hos); + virusStrainConfigGroup.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(ba5Hos); //--------------------------------------- // I M P O R T @@ -562,27 +524,6 @@ public Config prepareConfig(int id, Params params) { VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); vaccinationConfig.setTEMP_updatedProbaOfTransitioningToShowingSymptoms(params.probaShowSymptoms); -// TracingConfigGroup tracingConfig = ConfigUtils.addOrGetModule(config, TracingConfigGroup.class); -// LocalDate dateToRemoveQuarantine = LocalDate.parse("2022-12-01"); -// switch (params.quarantine) { -// case "base": -// break; -// case "nonSymptomatic0": -// tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); -// tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.NON_SYMPTOMATIC); -// break; -// case "withSymptoms0": -// tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); -// tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.WITH_SYMPTOMS); -// break; -// case "susceptible0": -// tracingConfig.getQuarantineDuration().put(dateToRemoveQuarantine, 0); -// tracingConfig.setQuarantineRelease(TracingConfigGroup.QuarantineRelease.SUSCEPTIBLE); -// break; -// default: -// throw new RuntimeException("invalid parameter"); -// } - // vary amount of "school" activity that takes place during vacation @@ -608,12 +549,10 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi Map infPerDayBa2 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA2, new TreeMap<>())); Map infPerDayBa5 = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.OMICRON_BA5, new TreeMap<>())); Map infPerDayStrA = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_A, new TreeMap<>())); -// Map infPerDayStrB = new HashMap<>(episimConfig.getInfections_pers_per_day().getOrDefault(VirusStrain.STRAIN_B, new TreeMap<>())); //StrainA if (!params.StrainA.equals("off")) { infPerDayStrA.put(LocalDate.parse("2020-01-01"), 0); -// LocalDate strADate = LocalDate.parse("2022-11-01"); LocalDate strADate = LocalDate.parse(params.strainADate); for (int i = 0; i < 7; i++) { @@ -621,67 +560,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } - - //StrainB -// if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(LocalDate.parse("2020-01-01"), 0); -// LocalDate strBDate = LocalDate.parse("2022-11-01"); -// for (int i = 0; i < 7; i++) { -// infPerDayStrB.put(strBDate.plusDays(i), 4); -// } -// infPerDayStrB.put(strBDate.plusDays(7), 1); -// } - - - // add projected disease import for vacation waves after initial disease import -// int facBa2 = 4; -// int facBa5 = 4; -// int facStrAB = 4; -// -// LocalDate dateBa2 = LocalDate.parse("2022-01-27"); // local min of disease import -// LocalDate dateBa5 = LocalDate.parse("2022-05-01"); // after vaca import -// LocalDate dateStrainAB = LocalDate.parse("2022-11-18"); // after vaca import - -// String importSummer2022 = "off"; -// if (importSummer2022.equals("on")) { -// NavigableMap data = DataUtils.readDiseaseImport(SnzCologneProductionScenario.INPUT.resolve("cologneDiseaseImport_Projected.csv")); -// LocalDate date = null; -// for (Map.Entry entry : data.entrySet()) { -// date = entry.getKey(); -// double factor = 0.25 * 2352476. / 919936.; //25% sample, data is given for Cologne City so we have to scale it to the whole model -//// -// double cases = factor * entry.getValue(); -// -// if (date.isAfter(dateStrainAB) && (!params.StrainA.equals("off") || !params.StrainB.equals("off"))) { -// if (!params.StrainA.equals("off") && !params.StrainB.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (0.5 * cases * facStrAB)); -// } -// else if (!params.StrainA.equals("off")) { -// infPerDayStrA.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else if (!params.StrainB.equals("off")) { -// infPerDayStrB.put(date, ((int) cases * facStrAB) == 0 ? 1 : (int) (cases * facStrAB)); -// } -// else { -// throw new RuntimeException(); -// } -// infPerDayBa5.put(date, 1); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa5)) { -// infPerDayBa5.put(date, ((int) cases * facBa5) == 0 ? 1 : (int) (cases * facBa5)); -// infPerDayBa2.put(date, 1); -// } else if (date.isAfter(dateBa2)) { -// infPerDayBa2.put(date, ((int) cases * facBa2) == 0 ? 1 : (int) (cases * facBa2)); -// } -// -// } -// } else if (importSummer2022.equals("off")) { -// } else { -// throw new RuntimeException(); -// } - - + // save disease import episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); @@ -690,14 +569,11 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi if (!params.StrainA.equals("off")) { episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_A, infPerDayStrA); } -// if (!params.StrainB.equals("off")) { -// episimConfig.setInfections_pers_per_day(VirusStrain.STRAIN_B, infPerDayStrB); -// } } public static final class Params { // general - @GenerateSeeds(5) + @GenerateSeeds(20) public long seed; @@ -706,7 +582,7 @@ public static final class Params { public String maskPt; // @Parameter({0.0, 0.2, 0.4, 0.6, 0.8, 1.0}) - @Parameter({0.8, 1.0}) + @Parameter({0.8}) public double probaShowSymptoms; From 2f2767899ba60639b4dd45af66faf0e0acacc04b Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 24 Nov 2022 12:22:58 +0100 Subject: [PATCH 125/128] modified AnalysisCommand to accept paths to events files themselves instead of just the directories holding them --- src/main/java/org/matsim/run/AnalysisCommand.java | 12 ++++++++++++ .../org/matsim/run/batch/StartFromImmunizations.java | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/matsim/run/AnalysisCommand.java b/src/main/java/org/matsim/run/AnalysisCommand.java index 69457a09c..df4261ccc 100644 --- a/src/main/java/org/matsim/run/AnalysisCommand.java +++ b/src/main/java/org/matsim/run/AnalysisCommand.java @@ -227,10 +227,22 @@ public static String getScenarioPrefix(Path scenario) throws IOException { @Nullable public static Path getEvents(Path scenario, boolean preferReducedEvents) { + + // if a path to an events file is entered, return that directly + if (Files.isRegularFile(scenario)) { + if (scenario.getFileName().toString().endsWith("events_reduced.tar") || scenario.getFileName().toString().endsWith("events.tar")) { + return scenario; + } else { + throw new RuntimeException("A file was specified; however, it doesn't follow the naming conventions for events files"); + } + } + + // if a path to a directory called "events is passed", return that directory if (Files.isDirectory(scenario.resolve("events")) && !isEmpty(scenario.resolve("events"))) { return scenario.resolve("events"); } + // otherwise, search directory for *events_reduced.tar or *events.tar try { Optional o; if (preferReducedEvents) { diff --git a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java index 065061ea9..901abbcec 100644 --- a/src/main/java/org/matsim/run/batch/StartFromImmunizations.java +++ b/src/main/java/org/matsim/run/batch/StartFromImmunizations.java @@ -9,7 +9,6 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.episim.BatchRun; import org.matsim.episim.EpisimConfigGroup; -import org.matsim.episim.VirusStrainConfigGroup; import org.matsim.episim.analysis.*; import org.matsim.episim.model.*; import org.matsim.episim.model.vaccination.VaccinationModel; @@ -108,8 +107,10 @@ public Config prepareConfig(int id, Params params) { // episimConfig.setSnapshotInterval(15); // - episimConfig.setStartDate(LocalDate.parse("2022-04-01")); - episimConfig.setStartFromImmunization("/Users/jakob/imm-hist-970-2022-10-21"); +// episimConfig.setStartDate(LocalDate.parse("2022-04-01")); +// episimConfig.setStartFromImmunization("/Users/jakob/imm-hist-970-2022-10-21"); + episimConfig.setStartDate(LocalDate.parse("2022-03-15")); + episimConfig.setStartFromImmunization("/Users/jakob/git/matsim-episim/seed_4711-1846/calibration1.events_reduced.tar"); // episimConfig.setSnapshotSeed(EpisimConfigGroup.SnapshotSeed.reseed); From 6a545c31e9208bd8e9b9457dec73519ee669fd3d Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Thu, 24 Nov 2022 13:25:47 +0100 Subject: [PATCH 126/128] clean up & remove outdated and unused code --- .../org/matsim/episim/EpisimConfigGroup.java | 16 -------- .../java/org/matsim/episim/EpisimPerson.java | 16 -------- .../java/org/matsim/episim/EpisimRunner.java | 40 ------------------- .../matsim/episim/InfectionEventHandler.java | 5 --- .../org/matsim/episim/TracingConfigGroup.java | 7 +--- .../matsim/episim/VaccinationConfigGroup.java | 19 --------- .../analysis/HospitalNumbersFromEvents.java | 11 ----- .../events/InitialImmunizationHandler.java | 17 -------- .../model/ConfigurableProgressionModel.java | 6 --- .../episim/model/DefaultAntibodyModel.java | 9 ----- .../AntibodyDependentTransitionModel.java | 10 +---- .../run/batch/CologneBMBF202212XX_bq1.java | 17 ++------ .../modules/SnzCologneProductionScenario.java | 2 +- 13 files changed, 7 insertions(+), 168 deletions(-) diff --git a/src/main/java/org/matsim/episim/EpisimConfigGroup.java b/src/main/java/org/matsim/episim/EpisimConfigGroup.java index 9883bf7d2..d0e5be474 100644 --- a/src/main/java/org/matsim/episim/EpisimConfigGroup.java +++ b/src/main/java/org/matsim/episim/EpisimConfigGroup.java @@ -68,7 +68,6 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { private static final String START_FROM_SNAPSHOT = "startFromSnapshot"; private static final String START_FROM_IMMUNIZATION = "startFromImmunization"; private static final String SNAPSHOT_PREFIX = "snapshotPrefix"; - private static final String IMMUNIZATION_PREFIX = "immunizationPrefix"; private static final String SNAPSHOT_SEED = "snapshotSeed"; private static final String LEISUREOUTDOORFRACTION = "leisureOutdoorFraction"; private static final String INPUT_DAYS = "inputDays"; @@ -150,11 +149,6 @@ public final class EpisimConfigGroup extends ReflectiveConfigGroup { */ private String snapshotPrefix = "episim-snapshot"; - /** - * Filename prefix for immunization. - */ - private String immunizationPrefix = "episim-immunization"; - /** * How the internal rng state should be handled. */ @@ -399,16 +393,6 @@ public void setSnapshotPrefix(String snapshotPrefix) { this.snapshotPrefix = snapshotPrefix; } - @StringGetter(IMMUNIZATION_PREFIX) - public String getImmunizationPrefix() { - return immunizationPrefix; - } - - @StringSetter(IMMUNIZATION_PREFIX) - public void setImmunizationPrefix(String immunizationPrefix) { - this.immunizationPrefix = immunizationPrefix; - } - @StringGetter(SNAPSHOT_SEED) public SnapshotSeed getSnapshotSeed() { return snapshotSeed; diff --git a/src/main/java/org/matsim/episim/EpisimPerson.java b/src/main/java/org/matsim/episim/EpisimPerson.java index 92b672657..197c1ebf4 100644 --- a/src/main/java/org/matsim/episim/EpisimPerson.java +++ b/src/main/java/org/matsim/episim/EpisimPerson.java @@ -438,20 +438,6 @@ public void setInitialInfection(double now, VirusStrain strain) { // TODO: add max antibodies } -// /** -// * Add an infection or vaccination from immunization history. -// */ -// void addImmunizationRecord(double time, boolean virus, String type) { -// -// if (virus) { -// virusStrains.add(VirusStrain.valueOf(type)); -// infectionDates.add(time * DAY); -// } else { -// vaccinations.add(VaccinationType.valueOf(type)); -// vaccinationDates.add((int) time); -// } -// } - /** * Adds an infection possibility to this person. Will be executed in {@link #checkInfection()} */ @@ -707,8 +693,6 @@ public boolean hadStrain(VirusStrain strain) { /** * Days elapsed since person was put into quarantine. * - * Doesn't check if person has ever been in quarantine - * * @param currentDay current day (iteration) * @apiNote This is currently not used much and may change similar to {@link #daysSince(DiseaseStatus, int)}. */ diff --git a/src/main/java/org/matsim/episim/EpisimRunner.java b/src/main/java/org/matsim/episim/EpisimRunner.java index 5aa9ea791..e091c3744 100644 --- a/src/main/java/org/matsim/episim/EpisimRunner.java +++ b/src/main/java/org/matsim/episim/EpisimRunner.java @@ -140,7 +140,6 @@ public void run(int maxIterations) { if (episimConfig.getSnapshotInterval() > 0 && iteration % episimConfig.getSnapshotInterval() == 0) { writeSnapshot(output, iteration); -// writeImmunization(output, iteration); } if (iteration % 10 == 0) @@ -257,45 +256,6 @@ private void writeSnapshot(Path output, int iteration) { } - /** - * Write immunization history. - * - * @param output output path - * @param iteration current iteration - */ -// private void writeImmunization(Path output, int iteration) { -// -// EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); -// -// String date = episimConfig.getStartDate().plusDays(iteration - 1).toString(); -// -// Path path = output.resolve(episimConfig.getImmunizationPrefix() + String.format("-%03d-%s.tsv.gz", iteration, date)); -// -// log.info("Writing immunization history to {}", path); -// -// InfectionEventHandler handler = handlerProvider.get(); -// -// try (CSVPrinter out = new CSVPrinter(new OutputStreamWriter(new GzipCompressorOutputStream(Files.newOutputStream(path))), CSVFormat.TDF)) { -// -// out.printRecord("personId", "date", "virus_or_vaccine", "type"); -// -// for (EpisimPerson person : handler.getPersons()) { -// for (int i = 0; i < person.getNumInfections(); i++) { -// String occurrence = episimConfig.getStartDate().plusDays((long) ((person.getInfectionDates().getDouble(i) / EpisimUtils.DAY) - 1)).toString(); -// out.printRecord(person.getPersonId(), occurrence, "virus", person.getVirusStrain(i)); -// } -// -// for (int i = 0; i < person.getNumVaccinations(); i++) { -// String occurrence = episimConfig.getStartDate().plusDays(person.getVaccinationDates().getInt(i) - 1).toString(); -// out.printRecord(person.getPersonId(), occurrence, "vaccine", person.getVaccinationType(i)); -// } -// } -// -// } catch (IOException e) { -// throw new UncheckedIOException("Could not write immunization history", e); -// } -// } - /** * Read snapshot from disk and initialize simulation state * diff --git a/src/main/java/org/matsim/episim/InfectionEventHandler.java b/src/main/java/org/matsim/episim/InfectionEventHandler.java index 5b91b2004..81f3641bd 100644 --- a/src/main/java/org/matsim/episim/InfectionEventHandler.java +++ b/src/main/java/org/matsim/episim/InfectionEventHandler.java @@ -770,10 +770,6 @@ public void reset(int iteration) { progressionModel.updateState(person, iteration); antibodyModel.updateAntibodies(person, iteration); -// if (person.getPersonId().toString().equals("1280b24")) { -// System.out.println("it " + iteration + ", " + person.getAntibodies(VirusStrain.SARS_CoV_2)); -// } - for (Object2DoubleMap.Entry kv : person.getAntibodies().object2DoubleEntrySet()) { antibodies.mergeDouble(kv.getKey(), kv.getDoubleValue(), Double::sum); } @@ -1013,7 +1009,6 @@ void initImmunization(Path history) { log.info("Reading immunization from {}", history); InitialImmunizationHandler handler = new InitialImmunizationHandler(personMap,episimConfig, antibodyModel,progressionModel); - //TODO: change history from folder -> file List days = AnalysisCommand.forEachEvent(history, handler, true, handler); diff --git a/src/main/java/org/matsim/episim/TracingConfigGroup.java b/src/main/java/org/matsim/episim/TracingConfigGroup.java index d02479454..8ca429b3c 100644 --- a/src/main/java/org/matsim/episim/TracingConfigGroup.java +++ b/src/main/java/org/matsim/episim/TracingConfigGroup.java @@ -493,12 +493,7 @@ public enum QuarantineRelease { /** * Release persons without showing symptoms. */ - NON_SYMPTOMATIC, - - /** - * Release all people except those in hospital - */ - WITH_SYMPTOMS + NON_SYMPTOMATIC } diff --git a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java index 679d3a734..8a2595ffb 100644 --- a/src/main/java/org/matsim/episim/VaccinationConfigGroup.java +++ b/src/main/java/org/matsim/episim/VaccinationConfigGroup.java @@ -36,11 +36,6 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { private static final String GROUPNAME = "episimVaccination"; - private static final String TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS = "TEMP_updatedShowingSymptomsFactor"; - - private static final String TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS_DATE = "TEMP_updatedShowingSymptomsDate"; - - /** * Amount of vaccinations available per day. */ @@ -92,9 +87,6 @@ public class VaccinationConfigGroup extends ReflectiveConfigGroup { */ private final Map params = new EnumMap<>(VaccinationType.class); - //TODO: temp, remove or modify - private double TEMP_updatedProbaOfTransitioningToShowingSymptoms = -1; - /** * Default constructor. @@ -187,17 +179,6 @@ String getComplianceString() { } - //TODO: temp, remove or modify - @StringGetter(TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS) - public double getTEMP_updatedProbaOfTransitioningToShowingSymptoms() { - return TEMP_updatedProbaOfTransitioningToShowingSymptoms; - } - - @StringSetter(TEMP_UPDATED_PROBA_OF_TRANSITIONING_TO_SHOWING_SYMPTOMS) - public void setTEMP_updatedProbaOfTransitioningToShowingSymptoms(double TEMP_updatedProbaOfTransitioningToShowingSymptoms) { - this.TEMP_updatedProbaOfTransitioningToShowingSymptoms = TEMP_updatedProbaOfTransitioningToShowingSymptoms; - } - /** * Sets the vaccination capacity for individual days. If a day has no entry the previous will be still valid. * If empty, default is 0. diff --git a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java index 2ca7a6f67..6dd17f5f1 100644 --- a/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java +++ b/src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java @@ -514,21 +514,10 @@ private void updateHospitalizationsPost(ImmunizablePerson person, VirusStrain st */ private boolean goToHospital(ImmunizablePerson person, int day) { - - if (List.of("12c304f").contains(person.personId.toString())) { - System.out.println(); - } - double ageFactor = transitionModel.getProbaOfTransitioningToSeriouslySick(person); double strainFactor = holder.strainConfig.getParams(person.getVirusStrain()).getFactorSeriouslySick(); double immunityFactor = transitionModel.getSeriouslySickFactor(person, holder.vaccinationConfig, day); - if (List.of("12c304f").contains(person.personId.toString())) { - System.out.println(person.getMaxAntibodies()); - System.out.println(person.getPersonId() + " ---- age " + ageFactor + ", strain " + strainFactor + ", immunity " + immunityFactor); - - } - return rnd.nextDouble() < ageFactor * strainFactor * immunityFactor; diff --git a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java index 7e8d4c7f1..056f90ee3 100644 --- a/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java +++ b/src/main/java/org/matsim/episim/events/InitialImmunizationHandler.java @@ -31,13 +31,6 @@ public final class InitialImmunizationHandler implements Function, EpisimPerson> personMap, EpisimConfigGroup episimConfig, AntibodyModel antibodyModel, ProgressionModel progressionModel) { this.personMap = personMap; this.episimConfig = episimConfig; @@ -51,8 +44,6 @@ public void handleEvent(EpisimStartEvent event) { this.startTimeOffset = this.iterationOffset * DAY; } - - @Override public void handleEvent(EpisimInfectionEvent event) { int currentIteration = (int) (event.getTime() / EpisimUtils.DAY); @@ -93,14 +84,6 @@ public void newDay(int currentIteration) { for (EpisimPerson person : personMap.values()) { antibodyModel.updateAntibodies(person, this.maxIterationReachedSoFar - this.iterationOffset); progressionModel.updateState(person, this.maxIterationReachedSoFar - this.iterationOffset); - -// if (person.getPersonId().toString().equals("1280b24")) { -// System.out.println("it " + currentIteration + ", " + person.getAntibodies(VirusStrain.SARS_CoV_2)); -// } -// System.out.println(" " + person.getDiseaseStatus()); -// System.out.println(" " + person.getQuarantineStatus()); -// -// } } } } diff --git a/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java b/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java index f3f06964e..a0e2e3a15 100644 --- a/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java +++ b/src/main/java/org/matsim/episim/model/ConfigurableProgressionModel.java @@ -231,12 +231,6 @@ private boolean releasePerson(EpisimPerson person) { (status == DiseaseStatus.susceptible || status == DiseaseStatus.contagious || status == DiseaseStatus.infectedButNotContagious)) return true; - if (release == TracingConfigGroup.QuarantineRelease.WITH_SYMPTOMS && - (status == DiseaseStatus.susceptible || status == DiseaseStatus.contagious || status == DiseaseStatus.infectedButNotContagious || status == DiseaseStatus.showingSymptoms)) { - return true; - } - - return false; } diff --git a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java index 0d8422358..b040e796f 100644 --- a/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java +++ b/src/main/java/org/matsim/episim/model/DefaultAntibodyModel.java @@ -62,9 +62,6 @@ public void recalculateAntibodiesAfterSnapshot(Collection persons, for (int it = 1; it < iteration; it++) { updateAntibodies(person, it); -// if (person.getPersonId().toString().equals("1280b24")) { -// System.out.println("it " + it + ", " + person.getAntibodies(VirusStrain.SARS_CoV_2)); -// } } } } @@ -80,12 +77,6 @@ public void recalculateAntibodiesAfterSnapshot(Collection persons, @Override public void updateAntibodies(EpisimPerson person, int day) { -// if (day == 0) { -// for (VirusStrain strain : VirusStrain.values()) { -// person.setAntibodies(strain, 0.0); -// } -// } - //handle vaccination if (person.getVaccinationDates().contains(day - 1)) { int vaccinationIndex = person.getVaccinationDates().indexOf(day - 1); diff --git a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java index 02959e9c0..63dc0dc36 100644 --- a/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java +++ b/src/main/java/org/matsim/episim/model/progression/AntibodyDependentTransitionModel.java @@ -32,15 +32,7 @@ public final EpisimPerson.DiseaseStatus decideNextState(EpisimPerson person, Epi return EpisimPerson.DiseaseStatus.contagious; case contagious: - double probaOfTransitioningToShowingSymptoms = getProbaOfTransitioningToShowingSymptoms(person); - - if (day >= 1011 // hardcoded: 2022-12-01 - && vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms() >= 0.0 - && vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms() <= 1.0) { - probaOfTransitioningToShowingSymptoms = vaccinationConfig.getTEMP_updatedProbaOfTransitioningToShowingSymptoms(); - } - - if (rnd.nextDouble() < probaOfTransitioningToShowingSymptoms * getShowingSymptomsFactor(person, vaccinationConfig, day)) + if (rnd.nextDouble() < getProbaOfTransitioningToShowingSymptoms(person) * getShowingSymptomsFactor(person, vaccinationConfig, day)) return EpisimPerson.DiseaseStatus.showingSymptoms; else return EpisimPerson.DiseaseStatus.recovered; diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java index d889d0c07..79d0a3d90 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java @@ -381,7 +381,7 @@ public Config prepareConfig(int id, Params params) { // start from immunization history // episimConfig.setStartDate(LocalDate.parse(START_DATE)); // episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/imm-hist-970-2022-10-21/"); - + //--------------------------------------- // S T R A I N S //--------------------------------------- @@ -521,10 +521,6 @@ public Config prepareConfig(int id, Params params) { "pt"); } - VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class); - vaccinationConfig.setTEMP_updatedProbaOfTransitioningToShowingSymptoms(params.probaShowSymptoms); - - // vary amount of "school" activity that takes place during vacation builder.restrict(LocalDate.parse("2022-06-27"), 0.8, "educ_primary", "educ_kiga", "educ_secondary", "educ_tertiary", "educ_other"); @@ -560,7 +556,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi } infPerDayStrA.put(strADate.plusDays(7), 1); } - + // save disease import episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA1, infPerDayBa1); episimConfig.setInfections_pers_per_day(VirusStrain.OMICRON_BA2, infPerDayBa2); @@ -573,7 +569,7 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi public static final class Params { // general - @GenerateSeeds(20) + @GenerateSeeds(5) public long seed; @@ -581,11 +577,6 @@ public static final class Params { @StringParameter({"base"}) public String maskPt; - // @Parameter({0.0, 0.2, 0.4, 0.6, 0.8, 1.0}) - @Parameter({0.8}) - public double probaShowSymptoms; - - // @StringParameter({"base", "nonSymptomatic0", "withSymptoms0", "susceptible0"}) // public String quarantine; @@ -593,7 +584,7 @@ public static final class Params { // BQ 1 // @StringParameter({"off", "2.0", "2.25", "2.5", "2.75", "3.0"}) - @StringParameter({"2.0"}) + @StringParameter({"1.0", "1.2", "1.4", "1.6", "1.8", "2.0"}) public String StrainA; // @StringParameter({"2022-08-24", "2022-08-29", "2022-09-04", "2022-09-09", "2022-09-14", "2022-09-19"}) diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 53c44ded1..313f09b73 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -239,7 +239,7 @@ protected void configure() { // antibody model AntibodyModel.Config antibodyConfig = new AntibodyModel.Config(); - antibodyConfig.setImmuneReponseSigma(0.0); // todo revert to 3.0? + antibodyConfig.setImmuneReponseSigma(3.0); bind(AntibodyModel.Config.class).toInstance(antibodyConfig); /* Bremen: From 91ff689f110c40fb381c948c55c1feffa52ac2e0 Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Tue, 6 Dec 2022 12:06:05 +0100 Subject: [PATCH 127/128] snapshot-lite --- src/main/R/analyseCases.R | 25 +++++++++++------ .../run/batch/CologneBMBF202212XX_bq1.java | 28 ++++++++++++------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/main/R/analyseCases.R b/src/main/R/analyseCases.R index 9012b45c8..e552fce58 100644 --- a/src/main/R/analyseCases.R +++ b/src/main/R/analyseCases.R @@ -8,28 +8,35 @@ rm(list=ls()) source("/Users/jakob/git/matsim-episim/src/main/R/masterJR-utils.R", encoding = 'utf-8') # directory_snap_old <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-05/2-imm-snap/" -directory_snap <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-15/2-imm-snap/" -directory_imm <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-15/3-imm-hist/" +directory_base <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-24/1-makeImmHist/" +directory_imm <- "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-11-24/3-imm-20seeds/" # file_root<- "antibodies.tsv" #infections file_root_inf<- "infections.txt.csv" -snap_inf_raw <- read_combine_episim_output_zipped(directory_snap, file_root_inf ) +snap_inf_raw <- read_combine_episim_output_zipped(directory_base, file_root_inf ) # snap_inf_raw_old <- read_combine_episim_output_zipped(directory_snap, file_root_inf ) imm_inf_raw <- read_combine_episim_output_zipped(directory_imm, file_root_inf) +unique(snap_inf_raw$seed) -start_date <- ymd("2021-11-15") -end_date <- ymd("2029-07-05") + +start_date <- ymd("2022-04-01") +end_date <- ymd("2022-09-01") snap_inf <- snap_inf_raw %>% filter(date >= start_date) %>% filter(date <= end_date) %>% - filter(pHh == 0.0, immuneSigma == 0.0) + filter(seed %in% unique(imm_inf_raw$seed)) + # filter(pHh == 0.0, immuneSigma == 0.0) # mutate(vax = generic + mRNA + vector + ba1Update + ba5Update + natural) + + imm_inf <- imm_inf_raw %>% filter(date >= start_date) %>% filter(date <= end_date) %>% - filter(pHh == 0.0, immuneSigma == 0.0) + filter(StrainA == 2.0 & startFromImm =="sepSeeds") + + # mutate(vax = generic + mRNA + vector + ba1Update + ba5Update + natural) ggplot() + #nShowingSymptoms # SARS_CoV_2 geom_line(imm_inf, mapping = aes(date, nShowingSymptoms , group = seed, col = "imm-hist")) + @@ -37,12 +44,14 @@ ggplot() + #nShowingSymptoms # SARS_CoV_2 scale_color_manual(name='Regression Model', breaks=c('snapshot', 'imm-hist'), values=c('snapshot'='red', 'imm-hist'='blue'))+ + labs(alt = "hello world") + ggtitle("Infections") + # antibodies file_root_ab<- "antibodies.tsv" -snap_ab_raw <- read_combine_episim_output_zipped(directory_snap, file_root_ab ) +snap_ab_raw <- read_combine_episim_output_zipped(directory_base, file_root_ab ) imm_ab_raw <- read_combine_episim_output_zipped(directory_imm, file_root_ab) diff --git a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java index 79d0a3d90..a29b25077 100644 --- a/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java +++ b/src/main/java/org/matsim/run/batch/CologneBMBF202212XX_bq1.java @@ -379,8 +379,15 @@ public Config prepareConfig(int id, Params params) { // start from immunization history -// episimConfig.setStartDate(LocalDate.parse(START_DATE)); -// episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/runs/jakob/imm-hist-970-2022-10-21/"); + episimConfig.setStartDate(LocalDate.parse(START_DATE)); + + if (params.startFromImm.equals("sepSeeds")) { + episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/episim-input/imm-cologne-2022-11-24/" + params.seed + "-events_reduced.tar"); + } else if (params.startFromImm.equals("4711")) { + episimConfig.setStartFromImmunization("/scratch/projects/bzz0020/episim-input/imm-cologne-2022-11-24/4711-events_reduced.tar"); + } else { + throw new RuntimeException("invalid param"); + } //--------------------------------------- // S T R A I N S @@ -569,23 +576,24 @@ private void configureFutureDiseaseImport(Params params, EpisimConfigGroup episi public static final class Params { // general - @GenerateSeeds(5) + @GenerateSeeds(20) public long seed; + @StringParameter({"sepSeeds", "4711"}) + public String startFromImm; + + // BQ 1 +// @StringParameter({"off", "2.0", "2.25", "2.5", "2.75", "3.0"}) +// @StringParameter({"1.0", "1.2", "1.4", "1.6", "1.8", "2.0"}) + @StringParameter({"2.0"}) + public String StrainA; // @StringParameter({"base", "2022-11-15", "2022-12-01", "2022-12-15", "2023-01-01"}) @StringParameter({"base"}) public String maskPt; -// @StringParameter({"base", "nonSymptomatic0", "withSymptoms0", "susceptible0"}) -// public String quarantine; - - // BQ 1 -// @StringParameter({"off", "2.0", "2.25", "2.5", "2.75", "3.0"}) - @StringParameter({"1.0", "1.2", "1.4", "1.6", "1.8", "2.0"}) - public String StrainA; // @StringParameter({"2022-08-24", "2022-08-29", "2022-09-04", "2022-09-09", "2022-09-14", "2022-09-19"}) @StringParameter({"2022-09-19"}) From ea97b4507f46655173e82a0a9745ad9b8d22458b Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Wed, 7 Dec 2022 13:04:28 +0100 Subject: [PATCH 128/128] removed setter that is overwritten a couple of lines later --- .../org/matsim/run/modules/SnzCologneProductionScenario.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java index 313f09b73..df5a084eb 100644 --- a/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java +++ b/src/main/java/org/matsim/run/modules/SnzCologneProductionScenario.java @@ -293,7 +293,7 @@ public Config config() { //episim config EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); - episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 0.96 * 1.06); +// episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 0.96 * 1.06); episimConfig.addInputEventsFile(inputForSample("cologne_snz_episim_events_wt_%dpt_split_withLeisureSplit.xml.gz", sample)) .addDays(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY);