Skip to content

Commit

Permalink
update analysis (to new matsim-r)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschlenther committed Jul 3, 2024
1 parent 90775b4 commit 63e8692
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 139 deletions.
13 changes: 8 additions & 5 deletions src/main/R/differences_airPollution.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ policy_runId <- args[2]
baseCaseDirectory <- args[3]
base_runId <- args[4]

# baseCaseDirectory <- "C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/output/baseCaseContinued-10pct/analysis/airPollution/"
# base_runId <- "berlin-v5.5-10pct"
# policyCaseDirectory <- "C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/output/runs-2023-09-01/10pct/roadtypesAllowed-motorway/analysis/airPollution/"
# policy_runId <- "noDRT"

base_runId <- "berlin-v5.5-10pct"
policy_runId <- "roadTypesAllowed_all"
baseCaseDirectory <- "D:/Projekte/berlin-noprivate-cars/lorenz/baseCaseContinued-10pct/"
policyCaseDirectory <- "D:/Projekte/berlin-noprivate-cars/lorenz/runs-2023-09-01/10pct/roadtypesAllowed-all"

baseAirPollution <- read.table(file = file.path(baseCaseDirectory, paste0("analysis/airPollution/", base_runId,".emissionsPerLink.csv")), sep = ";", header = TRUE)
policyAirPollution <- read.table(file = file.path(policyCaseDirectory, paste0("analysis/airPollution/", policy_runId,".emissionsPerLink.csv")), sep = ";", header = TRUE)
policyAirPollution <- read.table(file = "D:/Projekte/berlin-noprivate-cars/lorenz/runs-2023-09-01/10pct/roadtypesAllowed-all/analysis/airPollution/roadtypesAllowed-all.emissionsPerLink.csv", sep = ";", header = TRUE)


#####################################
# CO2 - Emissions & Costs (wait for Tilmanns answer to do it for the rest)
Expand All @@ -34,7 +37,7 @@ CO2_rel <- (sum(policyAirPollution$CO2_TOTAL) - sum(baseAirPollution$CO2_TOTAL))

## Veränderung Kosten absolut [€ / Tag]
# 139€/t (Werte für 2030)
CO2_euro <- (sum(policyAirPollution$CO2_TOTAL) - sum(baseAirPollution$CO2_TOTAL)) / (1000 * 1000) * 139
CO2_euro <- (sum(policyAirPollution$CO2_TOTAL) - sum(baseAirPollution$CO2_TOTAL)) / (1000 * 1000) * 6000

#####################################
# NOx - Emissions & Costs
Expand Down
37 changes: 18 additions & 19 deletions src/main/R/scoreComparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ library(matsim)
baseCaseDirectory <- args[3]
shp <- st_read(args[5])

#10pct
#baseCaseDirectory <- "C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/output/baseCaseContinued-10pct/"
#policyCaseDirectory <- "C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/output/runs-2023-09-01/10pct/noDRT/"

#1pct
# baseCaseDirectory <- "C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/output/baseCaseContinued/"
# #policyCaseDirectory <- "C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/output/runs-2023-06-02/extraPtPlan-true/drtStopBased-true/massConservation-true/"
# policyCaseDirectory <- "C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/output/runs-2023-09-01/1pct/optimum-flowCapacity/"

#shp <- st_read("C:/Users/loren/Documents/TU_Berlin/Semester_6/Masterarbeit/scenarios/berlin/replaceCarByDRT/noModeChoice/shp/hundekopf-carBanArea.shp")
##### for berlin v5
shp <- st_read("D:/git/playground-schlenther/scenarios/berlin/replaceCarByDRT/noModeChoice/shp/hundekopf-carBanArea.shp")
#shp_berlin <- st_read("D:/public-svn/matsim/scenarios/countries/de/berlin/berlin-v5.5-10pct/input/berlin-shp/berlin.shp")
crs = 31468

baseCaseDirectory <- "D:/Projekte/berlin-noprivate-cars/lorenz/baseCaseContinued-10pct/"
policyCaseDirectory <- "D:/Projekte/berlin-noprivate-cars/lorenz/runs-2023-09-01/10pct/roadtypesAllowed-all/"

basePersons <- read.table(file = file.path(baseCaseDirectory, "output_plans_selectedPlanScores.tsv"), sep = '\t', header = TRUE)
policyPersons <- read.table(file = file.path(policyCaseDirectory, "output_plans_selectedPlanScores.tsv"), sep = '\t', header = TRUE)
Expand All @@ -47,8 +44,8 @@ dir.create(paste0(policyCaseDirectory,"/analysis/score"))
########################################
# Prepare basic trips

baseTrips <- readTripsTable(baseCaseDirectory)
policy_trips_filename <- "output_trips_prepared.tsv"
baseTrips <- read_output_trips(baseCaseDirectory)
policy_trips_filename <- "output_trips_prepared_debugged.tsv"
policy_inputfile <- file.path(policyCaseDirectory, policy_trips_filename)

policyTrips <- read.table(file = policy_inputfile, sep ='\t', header = TRUE)
Expand Down Expand Up @@ -82,18 +79,20 @@ autonutzerBaseBrandenburg <- autonutzerBase %>% filter(home.activity.zone_base =
autonutzerPolicyBrandenburg <- autonutzerPolicy %>% filter(home.activity.zone_policy == "Brandenburg")

results_carUsers <- data.frame(key = character(), value = numeric()) %>%
add_row(key = "Änderung Autonutzer (%)", value = (nrow(autonutzerBase) - nrow(autonutzerPolicy)) / nrow(autonutzerBase)) %>%
add_row(key = "Änderung Autonutzer Verbotszone (%)", value = (nrow(autonutzerBaseZone) - nrow(autonutzerPolicyZone)) / nrow(autonutzerBaseZone)) %>%
add_row(key = "Änderung Autonutzer restl. Berlin (%)", value = (nrow(autonutzerBaseOuterBerlin) - nrow(autonutzerPolicyOuterBerlin)) / nrow(autonutzerBaseOuterBerlin)) %>%
add_row(key = "Änderung Autonutzer Brandenburg (%)", value = (nrow(autonutzerBaseBrandenburg) - nrow(autonutzerPolicyBrandenburg)) / nrow(autonutzerBaseBrandenburg))
add_row(key = "Änderung Autonutzer (%)", value = (nrow(autonutzerPolicy) - nrow(autonutzerBase)) / nrow(autonutzerBase)) %>%
add_row(key = "Änderung Autonutzer Verbotszone (%)", value = (nrow(autonutzerPolicyZone) - nrow(autonutzerBaseZone)) / nrow(autonutzerBaseZone)) %>%
add_row(key = "Änderung Autonutzer restl. Berlin (%)", value = (nrow(autonutzerPolicyOuterBerlin) - nrow(autonutzerBaseOuterBerlin)) / nrow(autonutzerBaseOuterBerlin)) %>%
add_row(key = "Änderung Autonutzer Berlin (%)", value = (nrow(autonutzerPolicyOuterBerlin) + nrow(autonutzerPolicyZone)
- (nrow(autonutzerBaseOuterBerlin) + nrow(autonutzerBaseZone) ) ) / (nrow(autonutzerBaseOuterBerlin) + nrow(autonutzerBaseZone) ) ) %>%
add_row(key = "Änderung Autonutzer Brandenburg (%)", value = (nrow(autonutzerPolicyBrandenburg) - nrow(autonutzerBaseBrandenburg)) / nrow(autonutzerBaseBrandenburg))

########################################
# Prepare impacted trips (for the next cases)

"Impacted Grenztrips"
autoBase <- baseTrips %>% filter(main_mode == "car" | main_mode == "ride")
impQuell_trips_base <- autoBase %>% filterByRegion(., shp, crs = 31468, TRUE, FALSE)
impZiel_trips_base <- autoBase %>% filterByRegion(., shp, crs = 31468, FALSE, TRUE)
impQuell_trips_base <- autoBase %>% process_filter_by_shape(., shp, crs = crs, spatial_type = "originating")
impZiel_trips_base <- autoBase %>% process_filter_by_shape(., shp, crs = crs, spatial_type = "destinating")
impGrenz_trips_base <- rbind(impQuell_trips_base, impZiel_trips_base)
impGrenz_trips_policy <- policyTrips %>% filter(trip_id %in% impGrenz_trips_base$trip_id)

Expand All @@ -105,7 +104,7 @@ impGrenz_trips <- impGrenz_trips %>%
add_column(euclideanDistance_diff = impGrenz_trips$euclidean_distance_policy - impGrenz_trips$euclidean_distance_base)

"Impacted Binnentrips"
impBinnen_trips_base <- autoBase %>% filterByRegion(., shp, crs = 31468, TRUE, TRUE)
impBinnen_trips_base <- autoBase %>% process_filter_by_shape(., shp, crs = crs, spatial_type = "inside")
impBinnen_trips_policy <- policyTrips %>% filter(trip_id %in% impBinnen_trips_base$trip_id)

impBinnen_trips <- merge(impBinnen_trips_policy, impBinnen_trips_base, by = "trip_id", suffixes = c("_policy","_base"))
Expand Down
Loading

0 comments on commit 63e8692

Please sign in to comment.