From 9f17787964027254d1951d77eb0056ee0112cb5f Mon Sep 17 00:00:00 2001 From: tschlenther Date: Fri, 2 Feb 2024 19:57:58 +0100 Subject: [PATCH 1/7] remove drt-case. attempt to make code easier to read. todo: remove comments --- .../org/matsim/run/RunLeipzigScenario.java | 14 +- .../org/matsim/run/prepare/DrtCaseSetup.java | 378 +++++++++++------- .../run/prepare/LeipzigDrtVehicleCreator.java | 8 +- 3 files changed, 229 insertions(+), 171 deletions(-) diff --git a/src/main/java/org/matsim/run/RunLeipzigScenario.java b/src/main/java/org/matsim/run/RunLeipzigScenario.java index 6b7f9085..f24fc8e8 100644 --- a/src/main/java/org/matsim/run/RunLeipzigScenario.java +++ b/src/main/java/org/matsim/run/RunLeipzigScenario.java @@ -99,13 +99,9 @@ public class RunLeipzigScenario extends MATSimApplication { @CommandLine.Option(names = "--intermodality", defaultValue = "drtAndPtSeparateFromEachOther", description = "Define if drt should be used as access and egress mode for pt.") private DrtCaseSetup.PtDrtIntermodality ptDrtIntermodality; - public RunLeipzigScenario(@Nullable Config config) { - super(config); - } + public RunLeipzigScenario(@Nullable Config config) { super(config); } - public RunLeipzigScenario() { - super(String.format("input/v%s/leipzig-v%s-10pct.config.xml", VERSION, VERSION)); - } + public RunLeipzigScenario() { super(String.format("input/v%s/leipzig-v%s-10pct.config.xml", VERSION, VERSION)); } public static void main(String[] args) { MATSimApplication.run(RunLeipzigScenario.class, args); @@ -191,7 +187,7 @@ protected Config prepareConfig(Config config) { if (networkOpt.hasDrtArea()) { //drt try { - DrtCaseSetup.prepareConfig(config, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null)); + DrtCaseSetup.prepareConfig(config, /* drtCase, */ new ShpOptions(networkOpt.getDrtArea(), null, null)); } catch (URISyntaxException e) { log.fatal(e); } @@ -280,7 +276,7 @@ protected void prepareScenario(Scenario scenario) { // (passt das Netz an aus den mitgegebenen shape files, z.B. parking area, car-free area, ...) if (networkOpt.hasDrtArea()) { - DrtCaseSetup.prepareScenario(scenario, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION); + DrtCaseSetup.prepareScenario(scenario, /*drtCase, */ new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION); } } @@ -328,7 +324,7 @@ public void install() { }); if (networkOpt.hasDrtArea()) { - DrtCaseSetup.prepareControler(controler, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null), ptDrtIntermodality); + DrtCaseSetup.prepareControler(controler,/* drtCase,*/ new ShpOptions(networkOpt.getDrtArea(), null, null), ptDrtIntermodality); } if (bike == BicycleHandling.onNetworkWithBicycleContrib) { diff --git a/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java b/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java index d188a42a..5fd19025 100644 --- a/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java +++ b/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java @@ -1,13 +1,16 @@ package org.matsim.run.prepare; +import cadyts.utilities.misc.DynamicData; import ch.sbb.matsim.config.SwissRailRaptorConfigGroup; import ch.sbb.matsim.routing.pt.raptor.RaptorIntermodalAccessEgress; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.locationtech.jts.geom.Geometry; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; +import org.matsim.api.core.v01.network.Network; import org.matsim.application.options.ShpOptions; import org.matsim.contrib.drt.analysis.zonal.DrtZonalSystemParams; import org.matsim.contrib.drt.fare.DrtFareParams; @@ -32,6 +35,8 @@ import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.controler.events.StartupEvent; import org.matsim.core.controler.listener.StartupListener; +import org.matsim.core.network.NetworkUtils; +import org.matsim.core.network.algorithms.TransportModeNetworkFilter; import org.matsim.core.utils.io.IOUtils; import org.matsim.extensions.pt.fare.intermodalTripFareCompensator.IntermodalTripFareCompensatorConfigGroup; import org.matsim.extensions.pt.fare.intermodalTripFareCompensator.IntermodalTripFareCompensatorsConfigGroup; @@ -62,25 +67,27 @@ public final class DrtCaseSetup { private static final String errorMessage = "Unexpected value: "; + //this is not nice because the static set is only filled in prepareConfig static Set drtModes = new HashSet<>(); /** * Defines if drt is modelled at all (none), with 2 separate modes (twoSeparateServiceAreas) or with 1 single drt mode (oneServiceArea). * As this class is only triggered if a shp of the drt service area was provided, none is inactive for now + *
tschlenther, feb' 02, 2024: all the necessary information (nrOfServices, nrOfVehicles, modes etc.) shall be provided by the shape file, so this enum is strictly not needed. */ - public enum DrtCase {/*none,*/ twoSeparateServiceAreas, oneServiceArea} + public enum DrtCase {/*none,*/ twoSeparateServiceAreas /*, oneServiceArea*/} /** * Defines if intermodality between drt and pt is modelled or not. */ public enum PtDrtIntermodality {drtAndPtSeparateFromEachOther, drtAsAccessEgressForPt} - private DrtCaseSetup(){} + public DrtCaseSetup(){ } /** * prepare config for drt simulation. */ - public static void prepareConfig(Config config, DrtCase drtCase, ShpOptions drtArea) throws URISyntaxException { + public static void prepareConfig(Config config,/* DrtCase drtCase,*/ ShpOptions drtAreas) throws URISyntaxException { MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); DvrpConfigGroup dvrpConfigGroup = ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class); @@ -97,66 +104,107 @@ public static void prepareConfig(Config config, DrtCase drtCase, ShpOptions drtA drtFareParams.timeFare_h = 0.; drtFareParams.dailySubscriptionFee = 0.; - switch (drtCase) { - case twoSeparateServiceAreas -> { - //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes - if (multiModeDrtConfigGroup.getModalElements().isEmpty()) { - createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString()); - createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString()); - } - - multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { - drtConfigGroup.addParameterSet(drtFareParams); - DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); - drtModes.add(drtConfigGroup.getMode()); - - - configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); - DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); - drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0; - drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0; - drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000; - // update to real world data - drtSpeedUpParams.initialWaitingTime = 345.6; - // update to real world data - drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6; - drtSpeedUpParams.intervalDetailedIteration = 10000; - drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled; - drtConfigGroup.addParameterSet(drtSpeedUpParams); - }); - + log.info("reading " + drtAreas.getShapeFile().toString()); + for (SimpleFeature feature : drtAreas.readFeatures()) { +// String name = (String) feature.getAttribute("Name"); + String drtMode = String.valueOf(feature.getAttribute("mode")); + if (drtMode.equals("null")) { + throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtAreas.getShapeFile().toString()); + } else { + drtModes.add(drtMode); } + } - case oneServiceArea -> { - //"normal" drt, modelled as one single drt mode - if (multiModeDrtConfigGroup.getModalElements().isEmpty()) { - createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt, drtArea.getShapeFile().toString()); - } - multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { - drtConfigGroup.addParameterSet(drtFareParams); - DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); - drtModes.add(drtConfigGroup.getMode()); - - configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); - DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); - drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0; - drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0; - drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000; - // update to real world data - drtSpeedUpParams.initialWaitingTime = 345.6; - // update to real world data - drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6; - drtSpeedUpParams.intervalDetailedIteration = 10000; - drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled; - drtConfigGroup.addParameterSet(drtSpeedUpParams); - }); + if (multiModeDrtConfigGroup.getModalElements().isEmpty()) { + for (String mode : drtModes){ + createDrtModeConfigGroup(multiModeDrtConfigGroup, mode); } - default -> throw new IllegalStateException(errorMessage + (drtCase)); +// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString()); +// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString()); } + multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { + drtConfigGroup.addParameterSet(drtFareParams); + DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); +// drtModes.add(drtConfigGroup.getMode()); + + configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); + DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); + drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0; + drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0; + drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000; + // update to real world data + drtSpeedUpParams.initialWaitingTime = 345.6; + // update to real world data + drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6; + drtSpeedUpParams.intervalDetailedIteration = 10000; + drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled; + drtConfigGroup.addParameterSet(drtSpeedUpParams); + }); + +// switch (drtCase) { +// case twoSeparateServiceAreas -> { +// if (multiModeDrtConfigGroup.getModalElements().isEmpty()) { +// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString()); +// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString()); +// } +// //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes +// +// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { +// drtConfigGroup.addParameterSet(drtFareParams); +// DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); +// drtModes.add(drtConfigGroup.getMode()); +// +// +// configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); +// DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); +// drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0; +// drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0; +// drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000; +// // update to real world data +// drtSpeedUpParams.initialWaitingTime = 345.6; +// // update to real world data +// drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6; +// drtSpeedUpParams.intervalDetailedIteration = 10000; +// drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled; +// drtConfigGroup.addParameterSet(drtSpeedUpParams); +// }); +// +// +// } +// +// case oneServiceArea -> { +// //"normal" drt, modelled as one single drt mode +// if (multiModeDrtConfigGroup.getModalElements().isEmpty()) { +// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt, drtArea.getShapeFile().toString()); +// } +// +// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { +// drtConfigGroup.addParameterSet(drtFareParams); +// DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); +// drtModes.add(drtConfigGroup.getMode()); +// +// configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); +// DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); +// drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0; +// drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0; +// drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000; +// // update to real world data +// drtSpeedUpParams.initialWaitingTime = 345.6; +// // update to real world data +// drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6; +// drtSpeedUpParams.intervalDetailedIteration = 10000; +// drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled; +// drtConfigGroup.addParameterSet(drtSpeedUpParams); +// +// }); +// } +// default -> throw new IllegalStateException(errorMessage + (drtCase)); +// } + //drt modes have to be set as network modes in dvrp CfgGroup dvrpConfigGroup.networkModes = drtModes; //after adding mode specific multiModeDrtParams -> adjust @@ -166,7 +214,7 @@ public static void prepareConfig(Config config, DrtCase drtCase, ShpOptions drtA * prepare scenario for drt simulation. more specifically, create input vehicles and stops files. * this method does not (!?) change the network. For this, please refer to NetworkOptions.prepareDRT */ - public static void prepareScenario(Scenario scenario, DrtCase drtCase, ShpOptions drtArea, String version) { + public static void prepareScenario(Scenario scenario,/* DrtCase drtCase, */ ShpOptions drtAreas, String version) { scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(DrtRoute.class, new DrtRouteFactory()); // (matsim core does not know about DRT routes. This makes it possible to read them before the controler is there.) @@ -176,98 +224,114 @@ public static void prepareScenario(Scenario scenario, DrtCase drtCase, ShpOption CreateDrtStopsFromNetwork drtStopsCreator = new CreateDrtStopsFromNetwork(); MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(scenario.getConfig(), MultiModeDrtConfigGroup.class); - String drtMode; - switch (drtCase) { - case twoSeparateServiceAreas -> { +// String drtMode; +// switch (drtCase) { +// case twoSeparateServiceAreas -> { //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes - log.info("reading " + drtArea.getShapeFile().toString()); - for (SimpleFeature feature : drtArea.readFeatures()) { + log.info("reading " + drtAreas.getShapeFile().toString()); + for (SimpleFeature feature : drtAreas.readFeatures()) { +// for (String drtMode : this.drtModes2Feature.keySet()) { // String name = (String) feature.getAttribute("Name"); - drtMode = String.valueOf(feature.getAttribute("mode")); + String drtMode = String.valueOf(feature.getAttribute("mode")); if (drtMode.equals("null")) { - throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtArea.getShapeFile().toString()); + throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtAreas.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()); + throw new IllegalArgumentException("could not find 'noVehicles' attribute in the given shape file at " + drtAreas.getShapeFile().toString()); } - log.info("attempting to create " + noVehicles + " drt vehicles for mode " + drtMode); + log.info("filtering network for mode " + drtMode + ". Before, the number of links equals " + scenario.getNetwork().getLinks().size()); + Network filteredNetwork = NetworkUtils.createNetwork(); + TransportModeNetworkFilter filter = new TransportModeNetworkFilter(scenario.getNetwork()); + filter.filter(filteredNetwork, Sets.newHashSet(drtMode)); + log.info("filtered network contains " + filteredNetwork.getLinks().size() + " links"); - new LeipzigDrtVehicleCreator().createDrtVehiclesForSingleArea(scenario.getVehicles(), scenario.getNetwork(), + log.info("attempting to create " + noVehicles + " drt vehicles for mode " + drtMode); + new LeipzigDrtVehicleCreator().createDrtVehiclesForSingleArea(scenario.getVehicles(), filteredNetwork, feature, noVehicles, drtMode); //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 -> { - - //path, tho which stops.xml is saved - URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml"); - File stopsFile = null; - try { - stopsFile = new File(path.toURI()); - } catch (URISyntaxException e) { - log.fatal(e); +// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { + DrtConfigGroup drtConfigGroup = multiModeDrtConfigGroup.getModalElements().stream(). + filter(cfg -> cfg.getMode().equals(drtMode)) + .findFirst().orElseThrow(); + { + //path, tho which stops.xml is saved + URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtMode + "-stops.xml"); + // URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-area.shp"); + File file = null; + try { + file = new File(path.toURI()); + } catch (URISyntaxException e) { + log.fatal(e); + } + + + //create drt stops and save them next to config -> put it as input stops file. + //unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723 + drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, (Geometry) feature.getDefaultGeometry(), + drtAreas.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(), + file.toString(), drtAreas); + + //naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523 + drtConfigGroup.transitStopFile = file.toString(); + + // new ShapeFileWriter().writeGeometries(List.of(feature), file.toString()); + // drtConfigGroup.drtServiceAreaShapeFile = file.toString(); + // drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.serviceAreaBased; //TODO move this to prepareConfig + +// configureNecessaryConfigGroups(scenario.getConfig(), drtConfigGroup.getMode()); } - - //create drt stops and save them next to config -> put it as input stops file. - //unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723 - drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, (Geometry) feature.getDefaultGeometry(), - drtArea.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(), - stopsFile.toString(), drtArea); - - //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()); - }); +// }); } - } - - case oneServiceArea -> { - //"normal" drt, modelled as one single drt mode - drtMode = TransportMode.drt; - - //make the 400 configurable??? -sme0723 - new LeipzigDrtVehicleCreator().createDrtVehicles(scenario.getVehicles(), scenario.getNetwork(), - drtArea, 400, drtMode); - - //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 -> { - - //path, tho which stops.xml is saved - URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml"); - File stopsFile = null; - try { - stopsFile = new File(path.toURI()); - } catch (URISyntaxException e) { - log.fatal(e); - } - - //create drt stops and save them next to config -> put it as input stops file. - //unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723 - drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, drtArea.getGeometry(), - drtArea.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(), - stopsFile.toString(), drtArea); - - //naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523 - drtConfigGroup.transitStopFile = stopsFile.toString(); - - }); - - } - default -> throw new IllegalStateException(errorMessage + (drtCase)); - } +// } + +// case oneServiceArea -> { +// //"normal" drt, modelled as one single drt mode +// drtMode = TransportMode.drt; +// +// //make the 400 configurable??? -sme0723 +// new LeipzigDrtVehicleCreator().createDrtVehicles(scenario.getVehicles(), scenario.getNetwork(), +// drtArea, 400, drtMode); +// +// //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 -> { +// +// //path, tho which stops.xml is saved +// URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml"); +// File stopsFile = null; +// try { +// stopsFile = new File(path.toURI()); +// } catch (URISyntaxException e) { +// log.fatal(e); +// } +// +// //create drt stops and save them next to config -> put it as input stops file. +// //unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723 +// drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, drtArea.getGeometry(), +// drtArea.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(), +// stopsFile.toString(), drtArea); +// +// //naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523 +// drtConfigGroup.transitStopFile = stopsFile.toString(); +// +// }); +// +// } +// default -> throw new IllegalStateException(errorMessage + (drtCase)); +// } } /** * prepare controler for drt simulation. */ - public static void prepareControler(Controler controler, DrtCase drtCase, ShpOptions drtArea, PtDrtIntermodality ptDrtIntermodality) { + public static void prepareControler(Controler controler,/* DrtCase drtCase,*/ ShpOptions drtAreas, PtDrtIntermodality ptDrtIntermodality) { MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(controler.getConfig(), MultiModeDrtConfigGroup.class); controler.addOverridingModule(new DvrpModule()); @@ -290,31 +354,31 @@ public void install() { } } - switch (drtCase) { - case twoSeparateServiceAreas -> { +// switch (drtCase) { +// case twoSeparateServiceAreas -> { //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes //if intermodality between pt and drt -> only railways are tagged as intermodal stations (this is how it is handled in reality) -sme0723 if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) { - preparePtDrtIntermodality(controler, drtArea, true); - } - } - - case oneServiceArea -> { - //"normal" drt, modelled as one single drt mode - - if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) { - preparePtDrtIntermodality(controler, drtArea, false); + preparePtDrtIntermodality(controler, drtAreas, true); } - } - default -> throw new IllegalStateException(errorMessage + (drtCase)); - } +// } +// +// case oneServiceArea -> { +// //"normal" drt, modelled as one single drt mode +// +// if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) { +// preparePtDrtIntermodality(controler, drtArea, false); +// } +// } +// default -> throw new IllegalStateException(errorMessage + (drtCase)); +// } } /** * if no modal params existing, we have to create them. */ - private static void createDrtModeConfigGroup(MultiModeDrtConfigGroup multiModeDrtConfigGroup, String mode, String pathToShp) { + private static void createDrtModeConfigGroup(MultiModeDrtConfigGroup multiModeDrtConfigGroup, String mode/*, String pathToShp*/) { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = mode; drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.stopbased; @@ -330,19 +394,23 @@ private static void createDrtModeConfigGroup(MultiModeDrtConfigGroup multiModeDr ExtensiveInsertionSearchParams insertionSearchParams = new ExtensiveInsertionSearchParams(); drtConfigGroup.addParameterSet(insertionSearchParams); - //add rebalancing params and configure standard values - RebalancingParams rebalancingParams = new RebalancingParams(); - - MinCostFlowRebalancingStrategyParams rebalancingStrategyParams = new MinCostFlowRebalancingStrategyParams(); - rebalancingStrategyParams.targetAlpha = 0.5; - rebalancingStrategyParams.targetBeta = 0.5; - rebalancingParams.addParameterSet(rebalancingStrategyParams); - drtConfigGroup.addParameterSet(rebalancingParams); - - DrtZonalSystemParams zonalSystemParams = new DrtZonalSystemParams(); - zonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.ShapeFile; - zonalSystemParams.zonesShapeFile = new File(pathToShp).getAbsolutePath(); - drtConfigGroup.addParameterSet(zonalSystemParams); + //we do not simulate drt explicitly anymore, so rebalancing is commented out. tschlenther feb' 24 + { +// //add rebalancing params and configure standard values +// RebalancingParams rebalancingParams = new RebalancingParams(); +// +// MinCostFlowRebalancingStrategyParams rebalancingStrategyParams = new MinCostFlowRebalancingStrategyParams(); +// rebalancingStrategyParams.targetAlpha = 0.5; +// rebalancingStrategyParams.targetBeta = 0.5; +// rebalancingParams.addParameterSet(rebalancingStrategyParams); +// drtConfigGroup.addParameterSet(rebalancingParams); +// +// DrtZonalSystemParams zonalSystemParams = new DrtZonalSystemParams(); +// zonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.ShapeFile; +// zonalSystemParams.zonesShapeFile = new File(pathToShp).getAbsolutePath(); //this needs to be adjusted: should only be the one corresponding feature and not the whole shape file!! +// drtConfigGroup.addParameterSet(zonalSystemParams); +// + } multiModeDrtConfigGroup.addParameterSet(drtConfigGroup); } @@ -387,7 +455,7 @@ private static void preparePtDrtIntermodality(Controler controler, ShpOptions sh ConfigUtils.addOrGetModule(controler.getConfig(), MultiModeDrtConfigGroup.class).getModalElements().stream().findFirst().ifPresent(drtConfigGroup -> drtConfigGroup.getDrtFareParams().ifPresent(drtFareParams -> - prepareDrtFareCompensation(controler, drtModes, drtFareParams.baseFare))); + prepareDrtFareCompensation(controler, drtModes, drtFareParams.baseFare))); //this only works if prepareConfig was called with the same ShpOptions } private static void prepareDrtFareCompensation(Controler controler, Set nonPtModes, Double ptBaseFare) { diff --git a/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java b/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java index 0798845c..07d0c08b 100644 --- a/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java +++ b/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java @@ -151,13 +151,7 @@ public void createDrtVehiclesForSingleArea(Vehicles vehicles, Network network, S } } - log.info("filtering network for mode " + drtMode + ". Before, the number of links equals " + network.getLinks().size()); - Network filteredNetwork = NetworkUtils.createNetwork(); - TransportModeNetworkFilter filter = new TransportModeNetworkFilter(network); - filter.filter(filteredNetwork, Sets.newHashSet(drtMode)); - log.info("filtered network contains " + filteredNetwork.getLinks().size() + " links"); - - createVehiclesByRandomPointInShape(feature, filteredNetwork, noVehiclesPerArea, serviceStartTime, + createVehiclesByRandomPointInShape(feature, network, noVehiclesPerArea, serviceStartTime, serviceEndTime, 1, drtType, drtMode, vehicles); } From d12b0ada790e72843510cab542d5044867aa9a06 Mon Sep 17 00:00:00 2001 From: tschlenther Date: Wed, 7 Feb 2024 14:18:54 +0100 Subject: [PATCH 2/7] clean code --- .../org/matsim/run/RunLeipzigScenario.java | 7 +- .../org/matsim/run/prepare/DrtCaseSetup.java | 146 +----------------- 2 files changed, 5 insertions(+), 148 deletions(-) diff --git a/src/main/java/org/matsim/run/RunLeipzigScenario.java b/src/main/java/org/matsim/run/RunLeipzigScenario.java index f24fc8e8..ec77748a 100644 --- a/src/main/java/org/matsim/run/RunLeipzigScenario.java +++ b/src/main/java/org/matsim/run/RunLeipzigScenario.java @@ -93,9 +93,6 @@ public class RunLeipzigScenario extends MATSimApplication { @CommandLine.Option(names = "--parking-cost-time-period-end", defaultValue = "0", description = "End of time period for which parking cost will be charged.") private Double parkingCostTimePeriodEnd; - @CommandLine.Option(names = "--drt-case", defaultValue = "oneServiceArea", description = "Defines how drt is modelled. For a more detailed description see class DrtCaseSetup.") - private DrtCaseSetup.DrtCase drtCase; - @CommandLine.Option(names = "--intermodality", defaultValue = "drtAndPtSeparateFromEachOther", description = "Define if drt should be used as access and egress mode for pt.") private DrtCaseSetup.PtDrtIntermodality ptDrtIntermodality; @@ -276,7 +273,7 @@ protected void prepareScenario(Scenario scenario) { // (passt das Netz an aus den mitgegebenen shape files, z.B. parking area, car-free area, ...) if (networkOpt.hasDrtArea()) { - DrtCaseSetup.prepareScenario(scenario, /*drtCase, */ new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION); + DrtCaseSetup.prepareScenario(scenario, new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION); } } @@ -324,7 +321,7 @@ public void install() { }); if (networkOpt.hasDrtArea()) { - DrtCaseSetup.prepareControler(controler,/* drtCase,*/ new ShpOptions(networkOpt.getDrtArea(), null, null), ptDrtIntermodality); + DrtCaseSetup.prepareControler(controler, new ShpOptions(networkOpt.getDrtArea(), null, null), ptDrtIntermodality); } if (bike == BicycleHandling.onNetworkWithBicycleContrib) { diff --git a/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java b/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java index 2a83e6e4..55770193 100644 --- a/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java +++ b/src/main/java/org/matsim/run/prepare/DrtCaseSetup.java @@ -66,13 +66,6 @@ public final class DrtCaseSetup { //this is not nice because the static set is only filled in prepareConfig static Set drtModes = new HashSet<>(); - /** - * Defines if drt is modelled at all (none), with 2 separate modes (twoSeparateServiceAreas) or with 1 single drt mode (oneServiceArea). - * As this class is only triggered if a shp of the drt service area was provided, none is inactive for now - *
tschlenther, feb' 02, 2024: all the necessary information (nrOfServices, nrOfVehicles, modes etc.) shall be provided by the shape file, so this enum is strictly not needed. - */ - public enum DrtCase {/*none,*/ twoSeparateServiceAreas /*, oneServiceArea*/} - /** * Defines if intermodality between drt and pt is modelled or not. */ @@ -83,7 +76,7 @@ public DrtCaseSetup(){ } /** * prepare config for drt simulation. */ - public static void prepareConfig(Config config,/* DrtCase drtCase,*/ ShpOptions drtAreas) throws URISyntaxException { + public static void prepareConfig(Config config, ShpOptions drtAreas) throws URISyntaxException { MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); DvrpConfigGroup dvrpConfigGroup = ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class); @@ -118,14 +111,11 @@ public static void prepareConfig(Config config,/* DrtCase drtCase,*/ ShpOptions for (String mode : drtModes){ createDrtModeConfigGroup(multiModeDrtConfigGroup, mode); } -// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString()); -// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString()); } multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { drtConfigGroup.addParameterSet(drtFareParams); DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); -// drtModes.add(drtConfigGroup.getMode()); configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); @@ -141,66 +131,6 @@ public static void prepareConfig(Config config,/* DrtCase drtCase,*/ ShpOptions drtConfigGroup.addParameterSet(drtSpeedUpParams); }); -// switch (drtCase) { -// case twoSeparateServiceAreas -> { -// if (multiModeDrtConfigGroup.getModalElements().isEmpty()) { -// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString()); -// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString()); -// } -// //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes -// -// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { -// drtConfigGroup.addParameterSet(drtFareParams); -// DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); -// drtModes.add(drtConfigGroup.getMode()); -// -// -// configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); -// DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); -// drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0; -// drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0; -// drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000; -// // update to real world data -// drtSpeedUpParams.initialWaitingTime = 345.6; -// // update to real world data -// drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6; -// drtSpeedUpParams.intervalDetailedIteration = 10000; -// drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled; -// drtConfigGroup.addParameterSet(drtSpeedUpParams); -// }); -// -// -// } -// -// case oneServiceArea -> { -// //"normal" drt, modelled as one single drt mode -// if (multiModeDrtConfigGroup.getModalElements().isEmpty()) { -// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt, drtArea.getShapeFile().toString()); -// } -// -// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> { -// drtConfigGroup.addParameterSet(drtFareParams); -// DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute()); -// drtModes.add(drtConfigGroup.getMode()); -// -// configureNecessaryConfigGroups(config, drtConfigGroup.getMode()); -// DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams(); -// drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0; -// drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0; -// drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000; -// // update to real world data -// drtSpeedUpParams.initialWaitingTime = 345.6; -// // update to real world data -// drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6; -// drtSpeedUpParams.intervalDetailedIteration = 10000; -// drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled; -// drtConfigGroup.addParameterSet(drtSpeedUpParams); -// -// }); -// } -// default -> throw new IllegalStateException(errorMessage + (drtCase)); -// } - //drt modes have to be set as network modes in dvrp CfgGroup dvrpConfigGroup.networkModes = drtModes; //after adding mode specific multiModeDrtParams -> adjust @@ -210,25 +140,16 @@ public static void prepareConfig(Config config,/* DrtCase drtCase,*/ ShpOptions * prepare scenario for drt simulation. more specifically, create input vehicles and stops files. * this method does not (!?) change the network. For this, please refer to NetworkOptions.prepareDRT */ - public static void prepareScenario(Scenario scenario,/* DrtCase drtCase, */ ShpOptions drtAreas, String version) { + public static void prepareScenario(Scenario scenario, ShpOptions drtAreas, String version) { scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(DrtRoute.class, new DrtRouteFactory()); // (matsim core does not know about DRT routes. This makes it possible to read them before the controler is there.) - - CreateDrtStopsFromNetwork drtStopsCreator = new CreateDrtStopsFromNetwork(); MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(scenario.getConfig(), MultiModeDrtConfigGroup.class); -// String drtMode; -// switch (drtCase) { -// case twoSeparateServiceAreas -> { - //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes - log.info("reading " + drtAreas.getShapeFile().toString()); for (SimpleFeature feature : drtAreas.readFeatures()) { -// for (String drtMode : this.drtModes2Feature.keySet()) { -// String name = (String) feature.getAttribute("Name"); String drtMode = String.valueOf(feature.getAttribute("mode")); if (drtMode.equals("null")) { throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtAreas.getShapeFile().toString()); @@ -251,14 +172,12 @@ public static void prepareScenario(Scenario scenario,/* DrtCase drtCase, */ ShpO //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 -> { DrtConfigGroup drtConfigGroup = multiModeDrtConfigGroup.getModalElements().stream(). filter(cfg -> cfg.getMode().equals(drtMode)) .findFirst().orElseThrow(); { //path, tho which stops.xml is saved URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtMode + "-stops.xml"); - // URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-area.shp"); File file = null; try { file = new File(path.toURI()); @@ -276,58 +195,14 @@ public static void prepareScenario(Scenario scenario,/* DrtCase drtCase, */ ShpO //naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523 drtConfigGroup.transitStopFile = file.toString(); - // new ShapeFileWriter().writeGeometries(List.of(feature), file.toString()); - // drtConfigGroup.drtServiceAreaShapeFile = file.toString(); - // drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.serviceAreaBased; //TODO move this to prepareConfig - -// configureNecessaryConfigGroups(scenario.getConfig(), drtConfigGroup.getMode()); } -// }); } -// } - -// case oneServiceArea -> { -// //"normal" drt, modelled as one single drt mode -// drtMode = TransportMode.drt; -// -// //make the 400 configurable??? -sme0723 -// new LeipzigDrtVehicleCreator().createDrtVehicles(scenario.getVehicles(), scenario.getNetwork(), -// drtArea, 400, drtMode); -// -// //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 -> { -// -// //path, tho which stops.xml is saved -// URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml"); -// File stopsFile = null; -// try { -// stopsFile = new File(path.toURI()); -// } catch (URISyntaxException e) { -// log.fatal(e); -// } -// -// //create drt stops and save them next to config -> put it as input stops file. -// //unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723 -// drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, drtArea.getGeometry(), -// drtArea.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(), -// stopsFile.toString(), drtArea); -// -// //naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523 -// drtConfigGroup.transitStopFile = stopsFile.toString(); -// -// }); -// -// } -// default -> throw new IllegalStateException(errorMessage + (drtCase)); -// } } /** * prepare controler for drt simulation. */ - public static void prepareControler(Controler controler,/* DrtCase drtCase,*/ ShpOptions drtAreas, PtDrtIntermodality ptDrtIntermodality) { + public static void prepareControler(Controler controler, ShpOptions drtAreas, PtDrtIntermodality ptDrtIntermodality) { MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(controler.getConfig(), MultiModeDrtConfigGroup.class); controler.addOverridingModule(new DvrpModule()); @@ -350,25 +225,10 @@ public void install() { } } -// switch (drtCase) { -// case twoSeparateServiceAreas -> { - //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes - //if intermodality between pt and drt -> only railways are tagged as intermodal stations (this is how it is handled in reality) -sme0723 if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) { preparePtDrtIntermodality(controler, drtAreas, true); } -// } -// -// case oneServiceArea -> { -// //"normal" drt, modelled as one single drt mode -// -// if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) { -// preparePtDrtIntermodality(controler, drtArea, false); -// } -// } -// default -> throw new IllegalStateException(errorMessage + (drtCase)); -// } } /** From c24f487ad0e83756635514bda7420b9abd9fa6ed Mon Sep 17 00:00:00 2001 From: tschlenther Date: Wed, 7 Feb 2024 14:53:35 +0100 Subject: [PATCH 3/7] update drt area shp + fix tests --- .../leipzig_flexa_service_area_2021.dbf | Bin 788 -> 1314 bytes .../matsim/run/RunLeipzigIntegrationTest.java | 50 +++++++++++------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/input/v1.3/drtServiceArea/leipzig_flexa_service_area_2021.dbf b/input/v1.3/drtServiceArea/leipzig_flexa_service_area_2021.dbf index 20e713024528dab7d1b030268d3fb97b5fef5c40..102373481699bcf1cee1f4407cf5b4086c28482d 100644 GIT binary patch delta 132 zcmbQjwup;|xrT|6iGhLPA%g!8q{)$K*SVd|W9-CBgZnB^jxS6EA*aG}`=%krO7z0hII0FDl8H%*ga< K;s-V+V<`ZP@gq6_ delta 117 zcmZ3)HHD3bxtfESiGhLPAcH33M4k}A-29YOAQuFjK?K*tK>v*oxEK{uib@nvfsvj8 SOu#_Ta5Ez_C!-=ERZ;-tpcFU& diff --git a/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java b/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java index 08abc846..098485b5 100644 --- a/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java @@ -1,12 +1,11 @@ package org.matsim.run; -import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.matsim.analysis.ParkingLocation; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Network; import org.matsim.application.MATSimApplication; +import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.OutputDirectoryHierarchy; @@ -21,7 +20,9 @@ public class RunLeipzigIntegrationTest { private static final String URL = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/leipzig/leipzig-v1.2/input/"; - private static final String exampleShp = "input/v1.3/drtServiceArea/Leipzig_stadt.shp"; + private static final String stadtShp = "input/v1.3/drtServiceArea/Leipzig_stadt.shp"; + private static final String flexaShp = "input/v1.3/drtServiceArea/leipzig_flexa_service_area_2021.shp"; + @Test public final void runPoint1pctIntegrationTest() { @@ -38,8 +39,8 @@ public final void runPoint1pctIntegrationTest() { ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; - MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--slow-speed-area", exampleShp, - "--slow-speed-relative-change", "0.5","--drt-area", exampleShp, "--post-processing", "disabled" + MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--slow-speed-area", stadtShp, + "--slow-speed-relative-change", "0.5","--drt-area", stadtShp, "--post-processing", "disabled" ); assertThat(output) @@ -63,7 +64,7 @@ public final void runPoint1pctParkingIntegrationTest() { ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; config.plans().setInputFile(URL + "leipzig-v1.2-0.1pct.plans-initial.xml.gz"); - MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--drt-area", exampleShp, "--post-processing", "disabled", + MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--drt-area", flexaShp, "--post-processing", "disabled", "--parking-cost-area", "input/v" + RunLeipzigScenario.VERSION + "/parkingCostArea/Bewohnerparken_2020.shp", "--parking", "--intermodality", "drtAsAccessEgressForPt"); @@ -73,29 +74,38 @@ public final void runPoint1pctParkingIntegrationTest() { new ParkingLocation().execute("--directory", output.toString()); } + //drt is included in the parking test, as well... @Test - @Ignore("Opt Drt is not used right now.") - public final void runOptDrtExamplePopulationTest() { - Config config = ConfigUtils.loadConfig("input/v1.2/leipzig-test.with-drt.config.xml"); + public final void runDrtTest() { + Config config = ConfigUtils.loadConfig("input/v1.3/leipzig-v1.3-10pct.config.xml"); + Path output = Path.of("output-drt-test/it-1pct"); + config.global().setNumberOfThreads(1); config.qsim().setNumberOfThreads(1); config.controler().setLastIteration(1); config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); - config.network().setInputFile(URL + "drt-base-case/leipzig-v1.1-network-with-pt-drt.xml.gz"); - config.plans().setInputFile(URL + "leipzig-v1.1-0.1pct.plans.xml.gz"); - config.transit().setTransitScheduleFile(URL + "leipzig-v1.1-transitSchedule.xml.gz"); - config.transit().setVehiclesFile(URL + "leipzig-v1.1-transitVehicles.xml.gz"); - config.vehicles().setVehiclesFile(URL + "drt-base-case/leipzig-v1.1-vehicle-types-with-drt-scaledFleet.xml"); + config.controler().setOutputDirectory(output.toString()); + +// config.network().setInputFile(URL + "drt-base-case/leipzig-v1.1-network-with-pt-drt.xml.gz"); + config.plans().setInputFile(URL + "leipzig-v1.2-0.1pct.plans-initial.xml.gz"); +// config.transit().setTransitScheduleFile(URL + "leipzig-v1.1-transitSchedule.xml.gz"); +// config.transit().setVehiclesFile(URL + "leipzig-v1.1-transitVehicles.xml.gz"); +// config.vehicles().setVehiclesFile(URL + "drt-base-case/leipzig-v1.1-vehicle-types-with-drt-scaledFleet.xml"); 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"); + MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--drt-area", flexaShp + , "--post-processing", "disabled"); + + Network network = NetworkUtils.readNetwork(output + "/" + config.controler().getRunId() + ".output_network.xml.gz"); + assertTrue(! network.getLinks().get(Id.createLinkId("24232899")).getAllowedModes().contains("drtNorth")); + assertTrue(! network.getLinks().get(Id.createLinkId("24232899")).getAllowedModes().contains("drtSoutheast")); + assertTrue(network.getLinks().get(Id.createLinkId("307899688#1")).getAllowedModes().contains("drtNorth")); + assertTrue(network.getLinks().get(Id.createLinkId("26588307#0")).getAllowedModes().contains("drtSoutheast")); + + assertTrue(MultiModeDrtConfigGroup.get(config)!= null); - Assert.assertNotNull(config.getModules().get("multiModeOptDrt")); - Assert.assertNotNull(config.getModules().get("multiModeOptDrt").getParameterSets()); + //TODO add more tests, drt trips, etc. } } From 7480023592a1e8b08ca3cb007e884655494d38db Mon Sep 17 00:00:00 2001 From: tschlenther Date: Wed, 7 Feb 2024 15:06:33 +0100 Subject: [PATCH 4/7] fix: clean each drt network individually --- src/main/java/org/matsim/run/prepare/PrepareNetwork.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java index 2330f4fe..0fa372a5 100644 --- a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java +++ b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java @@ -12,6 +12,7 @@ import org.matsim.application.options.ShpOptions; import org.matsim.core.network.NetworkUtils; import org.matsim.core.network.algorithms.MultimodalNetworkCleaner; +import org.matsim.core.network.algorithms.NetworkCleaner; import org.matsim.core.utils.geometry.geotools.MGC; import org.matsim.core.utils.gis.ShapeFileReader; import org.matsim.run.LeipzigUtils; @@ -86,6 +87,12 @@ static void prepareDRT(Network network, ShpOptions shp) { } } + //we have to call the MultiModalNetworkCleaner for each mode individually, because otherwise the individual subnetworks might not get cleaned + MultimodalNetworkCleaner multimodalNetworkCleaner = new MultimodalNetworkCleaner(network); + for (String mode : modeGeoms.keySet()) { + multimodalNetworkCleaner.run(Set.of(mode)); + } + log.log(Level.INFO, "The following modes have been added to the network: {}", modeGeoms.keySet()); } From 9243c253c8a1574ec82da6785a354056e594bd04 Mon Sep 17 00:00:00 2001 From: tschlenther Date: Wed, 7 Feb 2024 15:40:52 +0100 Subject: [PATCH 5/7] fix path. TODO: stops files are (over)written next to input config. this does not work for CI --- src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java b/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java index 098485b5..b943ee06 100644 --- a/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java @@ -40,7 +40,7 @@ public final void runPoint1pctIntegrationTest() { ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--slow-speed-area", stadtShp, - "--slow-speed-relative-change", "0.5","--drt-area", stadtShp, "--post-processing", "disabled" + "--slow-speed-relative-change", "0.5","--drt-area", flexaShp, "--post-processing", "disabled" ); assertThat(output) From 5a4babccd97dd7be1f2f39fe160d6a77de13c61d Mon Sep 17 00:00:00 2001 From: tschlenther Date: Tue, 13 Feb 2024 16:43:18 +0100 Subject: [PATCH 6/7] fix: default service start and end ties --- .../org/matsim/run/prepare/LeipzigDrtVehicleCreator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java b/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java index 07d0c08b..0b81e29d 100644 --- a/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java +++ b/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java @@ -58,11 +58,11 @@ public final class LeipzigDrtVehicleCreator implements MATSimAppCommand { @CommandLine.Option(names = "--no-vehicles", description = "no of vehicles per service area to create", required = true) private int noVehiclesPerArea; - @CommandLine.Option(names = "--service-start-time", description = "start of vehicle service time in seconds", defaultValue = "18000") - private double serviceStartTime; + @CommandLine.Option(names = "--service-start-time", description = "start of vehicle service time in seconds. default is 18000.") + private double serviceStartTime = 18000; - @CommandLine.Option(names = "--service-end-time", description = "end of vehicle service time in seconds", defaultValue = "86400") - private double serviceEndTime; + @CommandLine.Option(names = "--service-end-time", description = "end of vehicle service time in seconds. default is 864000.") + private double serviceEndTime = 864000; public static void main(String[] args) throws IOException { new LeipzigDrtVehicleCreator().execute(args); From 5fd4e954e6bf42de5d9ed531dfbd796f43bdc46c Mon Sep 17 00:00:00 2001 From: tschlenther Date: Tue, 13 Feb 2024 16:52:07 +0100 Subject: [PATCH 7/7] fix: default service start end time --- .../java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java b/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java index 0b81e29d..59a5196d 100644 --- a/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java +++ b/src/main/java/org/matsim/run/prepare/LeipzigDrtVehicleCreator.java @@ -62,7 +62,7 @@ public final class LeipzigDrtVehicleCreator implements MATSimAppCommand { private double serviceStartTime = 18000; @CommandLine.Option(names = "--service-end-time", description = "end of vehicle service time in seconds. default is 864000.") - private double serviceEndTime = 864000; + private double serviceEndTime = 86400; public static void main(String[] args) throws IOException { new LeipzigDrtVehicleCreator().execute(args);