From b739ee890cf833fecae596ab5c898a04e4885706 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Mon, 18 Mar 2024 12:01:34 +0100 Subject: [PATCH 1/2] install drt zonalsystem module independently of the rebalancing module --- .../contrib/drt/optimizer/rebalancing/RebalancingModule.java | 1 - .../src/main/java/org/matsim/contrib/drt/run/DrtModeModule.java | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/rebalancing/RebalancingModule.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/rebalancing/RebalancingModule.java index b9c008bc3a1..ef148776efd 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/rebalancing/RebalancingModule.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/rebalancing/RebalancingModule.java @@ -46,7 +46,6 @@ public RebalancingModule(DrtConfigGroup drtCfg) { public void install() { if (drtCfg.getRebalancingParams().isPresent()) { RebalancingParams rebalancingParams = drtCfg.getRebalancingParams().get(); - install(new DrtModeZonalSystemModule(drtCfg)); if (rebalancingParams.getRebalancingStrategyParams() instanceof MinCostFlowRebalancingStrategyParams) { install(new DrtModeMinCostFlowRebalancingModule(drtCfg)); diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeModule.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeModule.java index a0cb1fc007c..f667841b104 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeModule.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeModule.java @@ -25,6 +25,7 @@ import com.google.inject.name.Names; import org.matsim.api.core.v01.network.Network; import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector; +import org.matsim.contrib.drt.analysis.zonal.DrtModeZonalSystemModule; import org.matsim.contrib.drt.fare.DrtFareHandler; import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingModule; import org.matsim.contrib.drt.prebooking.analysis.PrebookingModeAnalysisModule; @@ -65,6 +66,7 @@ public void install() { null : ConfigGroup.getInputFileURL(getConfig().getContext(), drtCfg.vehiclesFile), drtCfg.changeStartLinkToLastLinkInSchedule)); + install(new DrtModeZonalSystemModule(drtCfg)); install(new RebalancingModule(drtCfg)); install(new DrtModeRoutingModule(drtCfg)); From 4258f24f15a85523a9cf9e9d7b5136ab9682d1f7 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Mon, 18 Mar 2024 12:31:46 +0100 Subject: [PATCH 2/2] ensure zonal params are present --- .../zonal/DrtModeZonalSystemModule.java | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java index 8d81ba21749..986f75177a5 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java @@ -53,53 +53,55 @@ public DrtModeZonalSystemModule(DrtConfigGroup drtCfg) { @Override public void install() { - DrtZonalSystemParams params = drtCfg.getZonalSystemParams().orElseThrow(); - - bindModal(DrtZonalSystem.class).toProvider(modalProvider(getter -> { - Network network = getter.getModal(Network.class); - switch (params.zonesGeneration) { - case ShapeFile: - final List preparedGeometries = loadPreparedGeometries( + if (drtCfg.getZonalSystemParams().isPresent()) { + DrtZonalSystemParams params = drtCfg.getZonalSystemParams().get(); + + bindModal(DrtZonalSystem.class).toProvider(modalProvider(getter -> { + Network network = getter.getModal(Network.class); + switch (params.zonesGeneration) { + case ShapeFile: + final List preparedGeometries = loadPreparedGeometries( ConfigGroup.getInputFileURL(getConfig().getContext(), params.zonesShapeFile)); - return DrtZonalSystem.createFromPreparedGeometries(network, + return DrtZonalSystem.createFromPreparedGeometries(network, EntryStream.of(preparedGeometries).mapKeys(i -> (i + 1) + "").toMap()); - case GridFromNetwork: - Preconditions.checkNotNull(params.cellSize); - var gridZones = drtCfg.operationalScheme == OperationalScheme.serviceAreaBased ? + case GridFromNetwork: + Preconditions.checkNotNull(params.cellSize); + var gridZones = drtCfg.operationalScheme == OperationalScheme.serviceAreaBased ? createGridFromNetworkWithinServiceArea(network, params.cellSize, - loadPreparedGeometries(ConfigGroup.getInputFileURL(getConfig().getContext(), - drtCfg.drtServiceAreaShapeFile))) : + loadPreparedGeometries(ConfigGroup.getInputFileURL(getConfig().getContext(), + drtCfg.drtServiceAreaShapeFile))) : createGridFromNetwork(network, params.cellSize); - return DrtZonalSystem.createFromPreparedGeometries(network, gridZones); - - default: - throw new RuntimeException("Unsupported zone generation"); - } - })).asEagerSingleton(); - - bindModal(DrtZoneTargetLinkSelector.class).toProvider(modalProvider(getter -> { - switch (params.targetLinkSelection) { - case mostCentral: - return new MostCentralDrtZoneTargetLinkSelector(getter.getModal(DrtZonalSystem.class)); - case random: - return new RandomDrtZoneTargetLinkSelector(); - default: - throw new RuntimeException( + return DrtZonalSystem.createFromPreparedGeometries(network, gridZones); + + default: + throw new RuntimeException("Unsupported zone generation"); + } + })).asEagerSingleton(); + + bindModal(DrtZoneTargetLinkSelector.class).toProvider(modalProvider(getter -> { + switch (params.targetLinkSelection) { + case mostCentral: + return new MostCentralDrtZoneTargetLinkSelector(getter.getModal(DrtZonalSystem.class)); + case random: + return new RandomDrtZoneTargetLinkSelector(); + default: + throw new RuntimeException( "Unsupported target link selection = " + params.targetLinkSelection); - } - })).asEagerSingleton(); + } + })).asEagerSingleton(); - //zonal analysis - bindModal(ZonalIdleVehicleXYVisualiser.class).toProvider(modalProvider( + //zonal analysis + bindModal(ZonalIdleVehicleXYVisualiser.class).toProvider(modalProvider( getter -> new ZonalIdleVehicleXYVisualiser(getter.get(MatsimServices.class), drtCfg.getMode(), - getter.getModal(DrtZonalSystem.class)))).asEagerSingleton(); - addControlerListenerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class)); - addEventHandlerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class)); + getter.getModal(DrtZonalSystem.class)))).asEagerSingleton(); + addControlerListenerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class)); + addEventHandlerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class)); - bindModal(DrtZonalWaitTimesAnalyzer.class).toProvider(modalProvider( + bindModal(DrtZonalWaitTimesAnalyzer.class).toProvider(modalProvider( getter -> new DrtZonalWaitTimesAnalyzer(drtCfg, getter.getModal(DrtEventSequenceCollector.class), - getter.getModal(DrtZonalSystem.class)))).asEagerSingleton(); - addControlerListenerBinding().to(modalKey(DrtZonalWaitTimesAnalyzer.class)); + getter.getModal(DrtZonalSystem.class)))).asEagerSingleton(); + addControlerListenerBinding().to(modalKey(DrtZonalWaitTimesAnalyzer.class)); + } } }