generated from matsim-scenarios/matsim-scenario-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into drt-implementation
- Loading branch information
Showing
17 changed files
with
461 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
output/ | ||
scenarios/output | ||
test/output | ||
runs/ | ||
|
||
*.gz | ||
*.pbf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
library(tidyverse) | ||
library(lubridate) | ||
|
||
ptPersons <- read.csv(file="C:/Users/Simon/Desktop/wd/2024-09-23/pt-persons.csv") | ||
|
||
ptCaseTrips <- read.csv2(file="Y:/net/ils/matsim-lausitz/caseStudies/v1.1/pt-case-study/output/lausitz-pt-case/lausitz-10ct.output_trips.csv.gz") | ||
drtCaseTrips <- read.csv2(file="Y:/net/ils/matsim-lausitz/caseStudies/v1.1/drt-case-study/output-1km-ptRadius/lausitz-drt-case-study.output_trips.csv.gz") | ||
|
||
ptPersons <- ptPersons %>% | ||
mutate(person=as.character(person), | ||
time = as.double(time)) | ||
|
||
filteredPtCase <- ptCaseTrips %>% | ||
filter(person %in% ptPersons$person) %>% | ||
left_join(ptPersons, by="person") %>% | ||
mutate(dep_s = as.numeric(hms(dep_time)), | ||
trav_s = as.numeric(hms(trav_time))) %>% | ||
filter(time >= dep_s & time <= dep_s + trav_s) | ||
|
||
meanTravTimePtCase <- mean(filteredPtCase$trav_s) | ||
meanTravDistPtCase <- mean(filteredPtCase$traveled_distance) | ||
|
||
filteredDrtCase <- drtCaseTrips %>% | ||
filter(person %in% ptPersons$person) %>% | ||
left_join(ptPersons, by="person") %>% | ||
mutate(dep_s = as.numeric(hms(dep_time)), | ||
trav_s = as.numeric(hms(trav_time))) %>% | ||
filter(time >= dep_s & time <= dep_s + trav_s) | ||
|
||
meanTravTimeDrtCase <- mean(filteredDrtCase$trav_s) | ||
meanTravDistDrtCase <- mean(filteredDrtCase$traveled_distance) | ||
|
||
comparison <- inner_join(filteredPtCase, filteredDrtCase, by="person", suffix = c(".ptCase", ".drtCase")) %>% | ||
select(person, trip_id.ptCase, trav_s.ptCase, traveled_distance.ptCase, main_mode.ptCase, | ||
trip_id.drtCase, trav_s.drtCase, traveled_distance.drtCase, main_mode.drtCase) %>% | ||
mutate(delta_trav_s = trav_s.ptCase - trav_s.drtCase, | ||
delta_trav_dist = traveled_distance.ptCase - traveled_distance.drtCase) | ||
|
||
summary <- comparison %>% | ||
summarize(mean_trav_s_ptCase=mean(trav_s.ptCase), | ||
mean_trav_s_drtCase=mean(trav_s.drtCase), | ||
mean_trav_dist_ptCase=mean(traveled_distance.ptCase), | ||
mean_trav_dist_drtCase=mean(traveled_distance.drtCase), | ||
mean_trav_s_delta=mean(delta_trav_s), | ||
mean_trav_dist_delta=mean(delta_trav_dist)) %>% | ||
mutate(mean_trav_min_ptCase=mean_trav_s_ptCase / 60, | ||
mean_trav_min_drtCase=mean_trav_s_drtCase / 60) | ||
|
||
write.csv(summary, file="C:/Users/Simon/Desktop/wd/2024-09-23/lausitz_ptCase_drtCase_summary.csv", quote = FALSE, row.names = FALSE) | ||
|
||
# Reshape the data to a long format for easy plotting | ||
df_long <- summary %>% | ||
pivot_longer( | ||
cols = c(mean_trav_min_ptCase, mean_trav_min_drtCase, | ||
mean_trav_dist_ptCase, mean_trav_dist_drtCase), | ||
names_to = c("metric", "Case"), | ||
names_pattern = "(mean_trav_[^_]+)_(ptCase|drtCase)" | ||
) | ||
|
||
# Create the barplot for mean_trav_min and mean_trav_dist | ||
ggplot(df_long, aes(x = Case, y = value, fill = Case)) + | ||
geom_bar(stat = "identity", position = "dodge") + | ||
facet_wrap(~ metric, scales = "free_y") + | ||
labs(title = "Comparison of mean_trav_min and mean_trav_dist by Case", | ||
x = "Case", y = "Value") + | ||
theme_minimal() | ||
|
||
|
||
|
||
|
||
|
||
|
1 change: 0 additions & 1 deletion
1
src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.matsim.run; | ||
|
||
import org.matsim.application.MATSimApplication; | ||
import org.matsim.run.scenarios.LausitzSingleModeScenario; | ||
|
||
/** | ||
* Run the Lausitz single mode scenario policy case. | ||
*/ | ||
public final class RunLausitzSingleModeScenario { | ||
|
||
private RunLausitzSingleModeScenario() { | ||
} | ||
|
||
public static void main(String[] args) { | ||
MATSimApplication.execute(LausitzSingleModeScenario.class, args); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.matsim.run; | ||
|
||
import org.matsim.application.MATSimApplication; | ||
import org.matsim.run.scenarios.LausitzSpeedReductionScenario; | ||
|
||
/** | ||
* Run the Lausitz speed reduction scenario policy case. | ||
*/ | ||
public final class RunLausitzSpeedReductionScenario { | ||
|
||
private RunLausitzSpeedReductionScenario() { | ||
} | ||
|
||
public static void main(String[] args) { | ||
MATSimApplication.execute(LausitzSpeedReductionScenario.class, args); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/org/matsim/run/scenarios/LausitzSingleModeScenario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.matsim.run.scenarios; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.matsim.api.core.v01.Scenario; | ||
import org.matsim.api.core.v01.TransportMode; | ||
import org.matsim.api.core.v01.population.*; | ||
import org.matsim.application.prepare.population.CleanPopulation; | ||
import org.matsim.core.config.Config; | ||
import org.matsim.core.config.groups.ReplanningConfigGroup; | ||
import org.matsim.core.controler.Controler; | ||
import org.matsim.core.population.algorithms.TripsToLegsAlgorithm; | ||
import org.matsim.core.router.RoutingModeMainModeIdentifier; | ||
import picocli.CommandLine; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Lausitz scenario including the simulation of 1 single transport mode. | ||
* All legs are changed to --transport-mode and mode choice is switched off. | ||
* All necessary configs will be made in this class. | ||
*/ | ||
public class LausitzSingleModeScenario extends LausitzScenario { | ||
Logger log = LogManager.getLogger(LausitzSingleModeScenario.class); | ||
|
||
private final LausitzScenario baseScenario = new LausitzScenario(sample, emissions); | ||
|
||
@CommandLine.Option(names = "--transport-mode", description = "Transport mode to which all legs should be changed.", defaultValue = TransportMode.car) | ||
private String mode; | ||
|
||
public LausitzSingleModeScenario(@Nullable Config config) { | ||
super(config); | ||
} | ||
|
||
public LausitzSingleModeScenario(@Nullable String args) { | ||
super(args); | ||
} | ||
|
||
public LausitzSingleModeScenario() { | ||
super(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Config prepareConfig(Config config) { | ||
// apply all config changes from base scenario class | ||
baseScenario.prepareConfig(config); | ||
|
||
config.subtourModeChoice().setModes(new String[0]); | ||
|
||
// remove smc strategy, only one mode for this scenario | ||
Collection<ReplanningConfigGroup.StrategySettings> settings = config.replanning().getStrategySettings(); | ||
config.replanning().clearStrategySettings(); | ||
|
||
settings.stream() | ||
.filter(setting -> !setting.getStrategyName().equals("SubtourModeChoice")) | ||
.forEach(setting -> config.replanning().addStrategySettings(setting)); | ||
|
||
return config; | ||
} | ||
|
||
@Override | ||
public void prepareScenario(Scenario scenario) { | ||
// apply all scenario changes from base scenario class | ||
baseScenario.prepareScenario(scenario); | ||
|
||
TripsToLegsAlgorithm trips2Legs = new TripsToLegsAlgorithm(new RoutingModeMainModeIdentifier()); | ||
|
||
for (Person person : scenario.getPopulation().getPersons().values()) { | ||
if (!person.getAttributes().getAttribute("subpopulation").equals("person")) { | ||
continue; | ||
} | ||
|
||
CleanPopulation.removeUnselectedPlans(person); | ||
|
||
for (Plan plan : person.getPlans()) { | ||
trips2Legs.run(plan); | ||
|
||
for (PlanElement el : plan.getPlanElements()) { | ||
if (el instanceof Leg leg) { | ||
CleanPopulation.removeRouteFromLeg(el); | ||
leg.setMode(mode); | ||
} | ||
} | ||
} | ||
} | ||
log.info("For all non-freight agents: Unselected plans have been removed. Trips were converted to legs. Routes have been removed." + | ||
" For every leg, the mode was changed to {}", mode); | ||
} | ||
|
||
@Override | ||
public void prepareControler(Controler controler) { | ||
// apply all controller changes from base scenario class | ||
baseScenario.prepareControler(controler); | ||
} | ||
} |
Oops, something went wrong.