From 4fb3e6e6d6514afa2cd0b2ee7c83803d748d2c21 Mon Sep 17 00:00:00 2001 From: tschlenther Date: Fri, 2 Feb 2024 20:25:28 +0100 Subject: [PATCH 1/3] fix: drt stops creation for every mode --- .../java/org/matsim/run/prepare/DrtCaseSetup.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java b/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java index d188a42..6ecc0b1 100644 --- a/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java +++ b/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java @@ -189,9 +189,6 @@ public static void prepareScenario(Scenario scenario, DrtCase drtCase, ShpOption throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtArea.getShapeFile().toString()); } Integer noVehicles = (Integer) feature.getAttribute("noVehicles"); - if (noVehicles.equals(null)){ - throw new IllegalArgumentException("could not find 'noVehicles' attribute in the given shape file at " + drtArea.getShapeFile().toString()); - } log.info("attempting to create " + noVehicles + " drt vehicles for mode " + drtMode); @@ -201,7 +198,12 @@ public static void prepareScenario(Scenario scenario, DrtCase drtCase, ShpOption //normally the following code would be set in prepareConfig, but.. //.. the stops creator relies on a network with drt modes. Drt modes are added in RunLeipzigScenario.prepareScenario().. //.. so stops are created after that step -sme0823 - multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { + + String finalDrtMode = drtMode; + DrtConfigGroup drtConfigGroup = multiModeDrtConfigGroup.getModalElements().stream(). + filter(cfg -> cfg.getMode().equals(finalDrtMode)) + .findFirst().orElseThrow(); +// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { //path, tho which stops.xml is saved URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml"); @@ -221,8 +223,8 @@ public static void prepareScenario(Scenario scenario, DrtCase drtCase, ShpOption //naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523 drtConfigGroup.transitStopFile = stopsFile.toString(); - configureNecessaryConfigGroups(scenario.getConfig(), drtConfigGroup.getMode()); - }); +// configureNecessaryConfigGroups(scenario.getConfig(), drtConfigGroup.getMode()); +// }); } } From 592da6995fbf3378bbad5e50dcd8d485423e7115 Mon Sep 17 00:00:00 2001 From: tschlenther Date: Fri, 2 Feb 2024 20:42:27 +0100 Subject: [PATCH 2/3] remove command line option --drt-modes, as those are read from shape file now --- src/main/java/org/matsim/run/prepare/NetworkOptions.java | 7 ++++--- src/main/java/org/matsim/run/prepare/PrepareNetwork.java | 2 +- .../java/org/matsim/run/RunLeipzigIntegrationTest.java | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/matsim/run/prepare/NetworkOptions.java b/src/main/java/org/matsim/run/prepare/NetworkOptions.java index 9b15bee..d195803 100644 --- a/src/main/java/org/matsim/run/prepare/NetworkOptions.java +++ b/src/main/java/org/matsim/run/prepare/NetworkOptions.java @@ -18,8 +18,9 @@ public class NetworkOptions { @CommandLine.Option(names = "--drt-area", description = "Path to SHP file specifying where DRT mode is allowed") private Path drtArea; - @CommandLine.Option(names = "--drt-modes", description = "List of modes to add. Use comma as delimiter", defaultValue = TransportMode.drt) - private String drtModes; + //modes now have to be provided in the drt-area shape file, per 'mode' attribute with +// @CommandLine.Option(names = "--drt-modes", description = "List of modes to add. Use comma as delimiter", defaultValue = TransportMode.drt) +// private String drtModes; @CommandLine.Option(names = "--car-free-area", description = "Path to SHP file specifying car-free area") private Path carFreeArea; @CommandLine.Option(names = "--car-free-modes", description = "List of modes to remove. Use comma as delimiter", defaultValue = TransportMode.car) @@ -65,7 +66,7 @@ public void prepare(Network network) { if (!Files.exists(drtArea)) { throw new IllegalArgumentException("Path to drt area not found: " + drtArea); } else { - PrepareNetwork.prepareDRT(network, new ShpOptions(drtArea, null, null), drtModes); + PrepareNetwork.prepareDRT(network, new ShpOptions(drtArea, null, null)); } } diff --git a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java index a1441a3..5a483e8 100644 --- a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java +++ b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java @@ -57,7 +57,7 @@ public Integer call() throws Exception { * Adapt network to one or more drt service areas. Therefore, a shape file of the wished service area + a list * of drt modes are needed. */ - static void prepareDRT(Network network, ShpOptions shp, String modes) { + static void prepareDRT(Network network, ShpOptions shp) { List features = shp.readFeatures(); Map modeGeoms = new HashMap<>(); diff --git a/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java b/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java index 299d6d5..08abc84 100644 --- a/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java @@ -90,6 +90,8 @@ public final void runOptDrtExamplePopulationTest() { ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; + //modes now have to be provided in the drt-area shape file, per 'mode' attribute with + //TODO: fix test by providing service area shape file MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--drt-area", exampleShp, "--drt-modes", "drtNorth,drtSoutheast", "--waiting-time-threshold-optDrt", "600", "--post-processing", "disabled"); From 95803b9ec46339c3bbdca8f7ebaf415e6473fc83 Mon Sep 17 00:00:00 2001 From: GregorRyb Date: Sat, 3 Feb 2024 18:23:58 +0100 Subject: [PATCH 3/3] try to satisfy check style --- src/main/java/org/matsim/run/prepare/PrepareNetwork.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java index 5a483e8..2330f4f 100644 --- a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java +++ b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java @@ -67,7 +67,7 @@ static void prepareDRT(Network network, ShpOptions shp) { if (mode.equals("null")) { throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + shp.getShapeFile().toString()); } - modeGeoms.compute(mode, (m,geom) -> geom == null ? ((Geometry) feature.getDefaultGeometry()) : geom.union((Geometry) feature.getDefaultGeometry())); + modeGeoms.compute(mode, (m, geom) -> geom == null ? ((Geometry) feature.getDefaultGeometry()) : geom.union((Geometry) feature.getDefaultGeometry())); } @@ -77,7 +77,7 @@ static void prepareDRT(Network network, ShpOptions shp) { } for (Map.Entry modeGeometryEntry : modeGeoms.entrySet()) { - if(MGC.coord2Point(link.getFromNode().getCoord()).within(modeGeometryEntry.getValue()) && + if (MGC.coord2Point(link.getFromNode().getCoord()).within(modeGeometryEntry.getValue()) && MGC.coord2Point(link.getToNode().getCoord()).within(modeGeometryEntry.getValue())){ Set allowedModes = new HashSet<>(link.getAllowedModes()); allowedModes.add(modeGeometryEntry.getKey());