From 1fdb144ef26a0c25f3533c0103cc389c4c5a4369 Mon Sep 17 00:00:00 2001 From: schlenther Date: Mon, 23 Sep 2024 17:12:40 +0200 Subject: [PATCH 1/3] include AV speed limit --- src/main/java/org/matsim/run/DrtFleetSizing.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/matsim/run/DrtFleetSizing.java b/src/main/java/org/matsim/run/DrtFleetSizing.java index 6d17936..01e4524 100644 --- a/src/main/java/org/matsim/run/DrtFleetSizing.java +++ b/src/main/java/org/matsim/run/DrtFleetSizing.java @@ -19,6 +19,7 @@ import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; +import org.matsim.contrib.dvrp.trafficmonitoring.DvrpModeLimitedMaxSpeedTravelTimeModule; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; @@ -29,6 +30,7 @@ import org.matsim.core.router.TripStructureUtils; import org.matsim.core.utils.io.IOUtils; import org.matsim.rebalancing.WaitingPointsBasedRebalancingModule; +import org.matsim.vehicles.VehicleType; import picocli.CommandLine; import java.nio.file.Files; @@ -147,6 +149,16 @@ public Integer call() throws Exception { MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config); Controler controler = DrtControlerCreator.createControler(config, false); + // Add speed limit to av vehicle + double maxSpeed = controler.getScenario() + .getVehicles() + .getVehicleTypes() + .get(Id.create("autonomous_vehicle", VehicleType.class)) + .getMaximumVelocity(); + controler.addOverridingModule( + new DvrpModeLimitedMaxSpeedTravelTimeModule("av", config.qsim().getTimeStepSize(), + maxSpeed)); + for (DrtConfigGroup drtCfg : multiModeDrtConfig.getModalElements()) { if (drtCfg.getMode().equals("av")) { drtCfg.transitStopFile = transitStopFilePath; From a632f755d53bd66b1c7da0a0cd7f934de446ddbf Mon Sep 17 00:00:00 2001 From: schlenther Date: Mon, 23 Sep 2024 17:30:04 +0200 Subject: [PATCH 2/3] refactoring --- .../java/org/matsim/run/DrtFleetSizing.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/matsim/run/DrtFleetSizing.java b/src/main/java/org/matsim/run/DrtFleetSizing.java index 01e4524..48e3e13 100644 --- a/src/main/java/org/matsim/run/DrtFleetSizing.java +++ b/src/main/java/org/matsim/run/DrtFleetSizing.java @@ -4,6 +4,7 @@ import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; +import org.jetbrains.annotations.NotNull; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.TransportMode; @@ -33,6 +34,7 @@ import org.matsim.vehicles.VehicleType; import picocli.CommandLine; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -84,8 +86,21 @@ public Integer call() throws Exception { Files.createDirectories(Path.of(outputFolderPath)); } - // read DRT trips and generate plans + //input paths for the simulations String drtNetworkPath = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/kelheim/kelheim-v3.1/input/av-fleet-sizing/kelheim-v3.0-drt-network.xml.gz"; + String extractedAVPlansPath = outputFolderPath + "/av-plans.xml.gz"; + + // read DRT trips and generate plans + extractAVDemandFromExistingOutput(drtNetworkPath, extractedAVPlansPath); + + // run DRT simulations + runDRTSimulations(drtNetworkPath, extractedAVPlansPath); + + return 0; + } + + private @NotNull String extractAVDemandFromExistingOutput(String drtNetworkPath, String extractedAVPlansPath) { + Network drtNetwork = NetworkUtils.readNetwork(drtNetworkPath); Path outputPopulationPath = globFile(Path.of(matsimRunFolderPath), "*output_plans.xml.gz*"); MainModeIdentifier modeIdentifier = new DefaultAnalysisMainModeIdentifier(); @@ -129,9 +144,11 @@ public Integer call() throws Exception { } } } - new PopulationWriter(avPlans).write(outputFolderPath + "/av-plans.xml.gz"); + new PopulationWriter(avPlans).write(extractedAVPlansPath); + return drtNetworkPath; + } - // run DRT simulations + private void runDRTSimulations(String drtNetworkPath, String extractedAVPlansPath) throws IOException { Preconditions.checkArgument(fleetSizing.size() == 3); int fleetFrom = fleetSizing.get(0); int fleetMax = fleetSizing.get(1); @@ -141,7 +158,7 @@ public Integer call() throws Exception { // setup DRT run Config config = ConfigUtils.loadConfig(drtConfigPath, new MultiModeDrtConfigGroup(DrtWithExtensionsConfigGroup::new), new DvrpConfigGroup()); config.network().setInputFile(drtNetworkPath); - config.plans().setInputFile(outputFolderPath + "/av-plans.xml.gz"); + config.plans().setInputFile(extractedAVPlansPath); config.controller().setLastIteration(1); config.controller().setOutputDirectory(outputFolderPath + "/" + fleetSize + "-veh"); config.vehicles().setVehiclesFile(vehiclesFolderPath + "/" + fleetSize + "-veh.xml"); @@ -193,7 +210,5 @@ public void install() { break; } } - - return 0; } } From 82fc278812fc0f3ef3791ba38e08a53db069cbaa Mon Sep 17 00:00:00 2001 From: schlenther Date: Mon, 23 Sep 2024 17:38:11 +0200 Subject: [PATCH 3/3] logging --- src/main/java/org/matsim/run/DrtFleetSizing.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/matsim/run/DrtFleetSizing.java b/src/main/java/org/matsim/run/DrtFleetSizing.java index 48e3e13..1aee826 100644 --- a/src/main/java/org/matsim/run/DrtFleetSizing.java +++ b/src/main/java/org/matsim/run/DrtFleetSizing.java @@ -4,6 +4,8 @@ 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.jetbrains.annotations.NotNull; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; @@ -74,6 +76,7 @@ public class DrtFleetSizing implements MATSimAppCommand { @CommandLine.Option(names = "--fleet-sizing", description = "a triplet: [from max interval]. ", arity = "1..*", defaultValue = "10 50 5") private List fleetSizing; + private Logger logger = LogManager.getLogger(DrtFleetSizing.class); public static void main(String[] args) { new DrtFleetSizing().execute(args); @@ -83,6 +86,7 @@ public static void main(String[] args) { public Integer call() throws Exception { // write output root folder if (!Files.exists(Path.of(outputFolderPath))) { + logger.info("creating outputFolderPath"); Files.createDirectories(Path.of(outputFolderPath)); } @@ -101,8 +105,10 @@ public Integer call() throws Exception { private @NotNull String extractAVDemandFromExistingOutput(String drtNetworkPath, String extractedAVPlansPath) { + Network drtNetwork = NetworkUtils.readNetwork(drtNetworkPath); Path outputPopulationPath = globFile(Path.of(matsimRunFolderPath), "*output_plans.xml.gz*"); + logger.info("retrieving single-leg av plans from " + outputPopulationPath); MainModeIdentifier modeIdentifier = new DefaultAnalysisMainModeIdentifier(); Population outputPlans = PopulationUtils.readPopulation(outputPopulationPath.toString()); Population avPlans = PopulationUtils.createPopulation(ConfigUtils.createConfig()); @@ -155,12 +161,14 @@ private void runDRTSimulations(String drtNetworkPath, String extractedAVPlansPat int fleetInterval = fleetSizing.get(2); for (int fleetSize = fleetFrom; fleetSize <= fleetMax; fleetSize += fleetInterval) { + logger.info("set up run with fleet size = " + fleetSize); // setup DRT run Config config = ConfigUtils.loadConfig(drtConfigPath, new MultiModeDrtConfigGroup(DrtWithExtensionsConfigGroup::new), new DvrpConfigGroup()); config.network().setInputFile(drtNetworkPath); config.plans().setInputFile(extractedAVPlansPath); config.controller().setLastIteration(1); config.controller().setOutputDirectory(outputFolderPath + "/" + fleetSize + "-veh"); + logger.info("output will be written to " + outputFolderPath + "/" + fleetSize + "-veh"); config.vehicles().setVehiclesFile(vehiclesFolderPath + "/" + fleetSize + "-veh.xml"); String singleDrtRunOutputDirectory = config.controller().getOutputDirectory(); MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config); @@ -206,7 +214,10 @@ public void install() { } } + logger.info("the obtained waiting time is " + waitingTime); + if (waitingTime < meanWaitTime) { + logger.info("will stop to conduct simulations, as the target waiting time of " + waitingTime + " is higher than the yielded waiting time."); break; } }