diff --git a/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/BicycleScoreEventsCreator.java b/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/BicycleScoreEventsCreator.java index e82f524c711..43e44b8bc93 100644 --- a/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/BicycleScoreEventsCreator.java +++ b/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/BicycleScoreEventsCreator.java @@ -132,7 +132,6 @@ class BicycleScoreEventsCreator implements } @Override public void handleEvent( VehicleLeavesTrafficEvent event ){ - vehicle2driver.handleEvent( event ); if ( this.bicycleConfig.isMotorizedInteraction() ){ // dec count by one: String mode = this.modeFromVehicle.get( event.getVehicleId() ); @@ -155,6 +154,8 @@ class BicycleScoreEventsCreator implements } else { log.warn( "no driver found for vehicleId=" + event.getVehicleId() + "; not clear why this could happen" ); } + // Needs to be called last, because it will remove driver information + vehicle2driver.handleEvent( event ); // --- } diff --git a/contribs/bicycle/src/test/java/org/matsim/contrib/bicycle/run/BicycleTest.java b/contribs/bicycle/src/test/java/org/matsim/contrib/bicycle/run/BicycleTest.java index 222834c746b..6c53356fb13 100644 --- a/contribs/bicycle/src/test/java/org/matsim/contrib/bicycle/run/BicycleTest.java +++ b/contribs/bicycle/src/test/java/org/matsim/contrib/bicycle/run/BicycleTest.java @@ -48,6 +48,7 @@ import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.population.PopulationUtils; import org.matsim.core.population.io.PopulationReader; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.core.router.TripStructureUtils; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.utils.collections.CollectionUtils; @@ -204,7 +205,8 @@ void testLane() { Scenario scenarioCurrent = ScenarioUtils.createScenario(ConfigUtils.createConfig()); new PopulationReader(scenarioReference).readFile(utils.getInputDirectory() + "output_plans.xml.gz"); new PopulationReader(scenarioCurrent).readFile(utils.getOutputDirectory() + "output_plans.xml.gz"); - assertTrue(PopulationUtils.equalPopulation(scenarioReference.getPopulation(), scenarioCurrent.getPopulation()), "Populations are different"); + + assertEquals(PopulationComparison.Result.equal, PopulationComparison.compare(scenarioReference.getPopulation(), scenarioCurrent.getPopulation()), "Populations are different"); } @Test diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_events.xml.gz index 9cb0d3cf237..df938db8693 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_plans.xml.gz index 17c8452fd78..9cd6def1cce 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testCobblestone/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_events.xml.gz index 97f24034206..fd77527354e 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_plans.xml.gz index 59e2f55ae6f..99ee5c39f20 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradient/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_events.xml.gz index a49a018f3d0..0fc24545326 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_plans.xml.gz index 69788484cf9..4af157ab83e 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/testGradient/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/testGradient/output_events.xml.gz deleted file mode 100644 index 97f24034206..00000000000 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/testGradient/output_events.xml.gz and /dev/null differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/testGradient/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/testGradient/output_plans.xml.gz deleted file mode 100644 index 59e2f55ae6f..00000000000 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testGradientLane/testGradient/output_plans.xml.gz and /dev/null differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_events.xml.gz index 955cde9e707..07129f0a0a9 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_plans.xml.gz index f41e975b460..22ce253ffda 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLane/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_events.xml.gz index 3478209daf4..ff9247df740 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_plans.xml.gz index 31eeebd5ab5..52f95856f96 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkBasedScoring/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_events.xml.gz index e6f996e514c..763f7214df7 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_plans.xml.gz index 6a99b6e8af4..29a33e2aa48 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testLinkVsLegMotorizedScoring/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_events.xml.gz index c45233d6432..67b34e49d71 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_plans.xml.gz index 31eeebd5ab5..52f95856f96 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_events.xml.gz index f0c50645e9b..dde3baab5cd 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_plans.xml.gz index 3c5b6caa023..9dedc2b2558 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testNormal10It/output_plans.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_events.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_events.xml.gz index f5b8f36e29d..94e4cbee126 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_events.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_events.xml.gz differ diff --git a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_plans.xml.gz b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_plans.xml.gz index b09a281270f..6e4970d1379 100644 Binary files a/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_plans.xml.gz and b/contribs/bicycle/test/input/org/matsim/contrib/bicycle/run/BicycleTest/testPedestrian/output_plans.xml.gz differ diff --git a/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/examples/RunJointDemandDRTExample.java b/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/examples/RunJointDemandDRTExample.java index 4379075dc79..7e8b84afaba 100644 --- a/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/examples/RunJointDemandDRTExample.java +++ b/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/examples/RunJointDemandDRTExample.java @@ -30,6 +30,7 @@ import org.matsim.contrib.commercialTrafficApplications.jointDemand.JointDemandConfigGroup; import org.matsim.contrib.commercialTrafficApplications.jointDemand.JointDemandModule; import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.run.DrtConfigs; @@ -141,9 +142,10 @@ private static void loadConfigGroups(Config config) { MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); DrtConfigGroup drtCfg = new DrtConfigGroup(); - drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime = 2 * 3600; - drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 5; - drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 15 * 60; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = 2 * 3600; + defaultConstraintsSet.maxTravelTimeAlpha = 5; + defaultConstraintsSet.maxTravelTimeBeta = 15 * 60; drtCfg.stopDuration = 60; drtCfg.vehiclesFile = "jointDemand_vehicles.xml"; multiModeDrtConfigGroup.addParameterSet(drtCfg); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java index 5333231bd6a..546f5b90cc2 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java @@ -28,13 +28,7 @@ import org.matsim.contrib.drt.extension.edrt.schedule.EDrtStayTaskEndTimeCalculator; import org.matsim.contrib.drt.extension.edrt.schedule.EDrtTaskFactoryImpl; import org.matsim.contrib.drt.extension.edrt.scheduler.EmptyVehicleChargingScheduler; -import org.matsim.contrib.drt.optimizer.DefaultDrtOptimizer; -import org.matsim.contrib.drt.optimizer.DrtModeOptimizerQSimModule; -import org.matsim.contrib.drt.optimizer.DrtOptimizer; -import org.matsim.contrib.drt.optimizer.DrtRequestInsertionRetryParams; -import org.matsim.contrib.drt.optimizer.DrtRequestInsertionRetryQueue; -import org.matsim.contrib.drt.optimizer.QSimScopeForkJoinPoolHolder; -import org.matsim.contrib.drt.optimizer.VehicleEntry; +import org.matsim.contrib.drt.optimizer.*; import org.matsim.contrib.drt.optimizer.depot.DepotFinder; import org.matsim.contrib.drt.optimizer.insertion.CostCalculationStrategy; import org.matsim.contrib.drt.optimizer.insertion.DefaultInsertionCostCalculator; @@ -147,7 +141,10 @@ public EmptyVehicleChargingScheduler get() { bindModal(VehicleEntry.EntryFactory.class).toProvider( EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider.class).asEagerSingleton(); - bindModal(CostCalculationStrategy.class).to(drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated ? + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + bindModal(CostCalculationStrategy.class) + .to(defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated + ? CostCalculationStrategy.RejectSoftConstraintViolations.class : CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton(); @@ -179,7 +176,8 @@ public EmptyVehicleRelocator get() { getter.getModal(StopTimeCalculator.class), scheduleWaitBeforeDrive))) .asEagerSingleton(); - bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor(drtCfg.getDrtOptimizationConstraintsParam().maxAllowedPickupDelay))); + bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor( + defaultConstraintsSet.maxAllowedPickupDelay))); bindModal(DrtOfferAcceptor.class).to(modalKey(DefaultOfferAcceptor.class)); bindModal(ScheduleTimingUpdater.class).toProvider(modalProvider( diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java index 29f2a9b006d..97f515ca57c 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java @@ -12,6 +12,7 @@ import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; @@ -53,16 +54,17 @@ void test() { DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.; drtConfigGroup.stopDuration = 30.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = 600.; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = true; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.5; + defaultConstraintsSet.maxTravelTimeBeta = 10. * 60.; + defaultConstraintsSet.maxWaitTime = 600.; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true; + defaultConstraintsSet.maxWalkDistance = 1000.; drtConfigGroup.useModeFilteredSubnetwork = false; drtConfigGroup.vehiclesFile = fleetFile; drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; drtConfigGroup.plotDetailedCustomerStats = true; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWalkDistance = 1000.; drtConfigGroup.idleVehiclesReturnToDepots = false; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java index 6f4e8ceb392..06fd5ea4eaf 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java @@ -9,11 +9,11 @@ import org.matsim.contrib.drt.extension.operations.EDrtOperationsControlerCreator; import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.ev.EvConfigGroup; @@ -57,17 +57,17 @@ void test() { DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; drtConfigGroup.mode = TransportMode.drt; - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); - constraintsParam.maxTravelTimeAlpha = 1.5; - constraintsParam.maxTravelTimeBeta = 10. * 60.; + DrtOptimizationConstraintsSet constraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + constraintsSet.maxTravelTimeAlpha = 1.5; + constraintsSet.maxTravelTimeBeta = 10. * 60.; drtConfigGroup.stopDuration = 30.; - constraintsParam.maxWaitTime = 600.; - constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated = true; + constraintsSet.maxWaitTime = 600.; + constraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true; drtConfigGroup.useModeFilteredSubnetwork = false; drtConfigGroup.vehiclesFile = fleetFile; drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; drtConfigGroup.plotDetailedCustomerStats = true; - constraintsParam.maxWalkDistance = 1000.; + constraintsSet.maxWalkDistance = 1000.; drtConfigGroup.idleVehiclesReturnToDepots = false; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java index 49033927906..bc9243a24fa 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java @@ -9,11 +9,11 @@ import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams; @@ -46,17 +46,17 @@ void test() { DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; drtConfigGroup.mode = TransportMode.drt; - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); - constraintsParam.maxTravelTimeAlpha = 1.5; - constraintsParam.maxTravelTimeBeta = 10. * 60.; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); drtConfigGroup.stopDuration = 30.; - constraintsParam.maxWaitTime = 600.; - constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated = true; + defaultConstraintsSet.maxTravelTimeAlpha = 1.5; + defaultConstraintsSet.maxTravelTimeBeta = 10. * 60.; + defaultConstraintsSet.maxWaitTime = 600.; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true; + defaultConstraintsSet.maxWalkDistance = 1000.; drtConfigGroup.useModeFilteredSubnetwork = false; drtConfigGroup.vehiclesFile = fleetFile; drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; drtConfigGroup.plotDetailedCustomerStats = true; - constraintsParam.maxWalkDistance = 1000.; drtConfigGroup.idleVehiclesReturnToDepots = false; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java index f794e546c51..c2b671c90e7 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java @@ -9,11 +9,11 @@ import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams; @@ -45,39 +45,38 @@ void test() { DrtWithOperationsConfigGroup drtWithShiftsConfigGroup = (DrtWithOperationsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt"); - DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; - drtConfigGroup.mode = TransportMode.drt; - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); - constraintsParam.maxTravelTimeAlpha = 1.5; - constraintsParam.maxTravelTimeBeta = 10. * 60.; - drtConfigGroup.stopDuration = 30.; - constraintsParam.maxWaitTime = 600.; - constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated = true; - drtConfigGroup.useModeFilteredSubnetwork = false; - drtConfigGroup.vehiclesFile = fleetFile; - drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtConfigGroup.plotDetailedCustomerStats = true; - constraintsParam.maxWalkDistance = 1000.; - drtConfigGroup.idleVehiclesReturnToDepots = false; - - drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); - - ConfigGroup rebalancing = drtConfigGroup.createParameterSet("rebalancing"); - drtConfigGroup.addParameterSet(rebalancing); + drtWithShiftsConfigGroup.mode = TransportMode.drt; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtWithShiftsConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + drtWithShiftsConfigGroup.stopDuration = 30.; + defaultConstraintsSet.maxTravelTimeAlpha = 1.5; + defaultConstraintsSet.maxTravelTimeBeta = 10. * 60.; + defaultConstraintsSet.maxWaitTime = 600.; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true; + defaultConstraintsSet.maxWalkDistance = 1000.; + drtWithShiftsConfigGroup.useModeFilteredSubnetwork = false; + drtWithShiftsConfigGroup.vehiclesFile = fleetFile; + drtWithShiftsConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; + drtWithShiftsConfigGroup.plotDetailedCustomerStats = true; + drtWithShiftsConfigGroup.idleVehiclesReturnToDepots = false; + + drtWithShiftsConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); + + ConfigGroup rebalancing = drtWithShiftsConfigGroup.createParameterSet("rebalancing"); + drtWithShiftsConfigGroup.addParameterSet(rebalancing); ((RebalancingParams) rebalancing).interval = 600; MinCostFlowRebalancingStrategyParams strategyParams = new MinCostFlowRebalancingStrategyParams(); strategyParams.targetAlpha = 0.3; strategyParams.targetBeta = 0.3; - drtConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams); + drtWithShiftsConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams); DrtZoneSystemParams drtZoneSystemParams = new DrtZoneSystemParams(); SquareGridZoneSystemParams zoneParams = (SquareGridZoneSystemParams) drtZoneSystemParams.createParameterSet(SquareGridZoneSystemParams.SET_NAME); zoneParams.cellSize = 500.; drtZoneSystemParams.addParameterSet(zoneParams); drtZoneSystemParams.targetLinkSelection = DrtZoneSystemParams.TargetLinkSelection.mostCentral; - drtConfigGroup.addParameterSet(drtZoneSystemParams); + drtWithShiftsConfigGroup.addParameterSet(drtZoneSystemParams); multiModeDrtConfigGroup.addParameterSet(drtWithShiftsConfigGroup); diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java index 3cc19b7a938..67ee1973686 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java @@ -44,6 +44,7 @@ import org.matsim.contrib.common.timeprofile.TimeProfileCharts; import org.matsim.contrib.common.util.ChartSaveUtils; import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector.EventSequence; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.passenger.events.DrtRequestSubmittedEvent; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.schedule.DrtStayTask; @@ -400,7 +401,7 @@ private void writeAndPlotWaitTimeEstimateComparison(Collection pe if (createChart) { final JFreeChart chart2 = DensityScatterPlots.createPlot("Wait times", "Actual wait time [s]", "Initially planned wait time [s]", - times, Pair.of(0., drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime)); + times, Pair.of(0., drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().maxWaitTime)); // xAxis.setLowerBound(0); // yAxis.setLowerBound(0); ChartUtils.writeChartAsPNG(new FileOutputStream(plotFileName), chart2, 1500, 1500); @@ -663,12 +664,15 @@ private static void analyseDetours(Network network, List legs, Map new DefaultOfferAcceptor(drtCfg.getDrtOptimizationConstraintsParam().maxAllowedPickupDelay))); + bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor( + defaultOptimizationConstraintsSet.maxAllowedPickupDelay))); bindModal(DrtOfferAcceptor.class).to(modalKey(DefaultOfferAcceptor.class)); bindModal(ScheduleTimingUpdater.class).toProvider(modalProvider( diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsParams.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsParams.java new file mode 100644 index 00000000000..9f517b8b862 --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsParams.java @@ -0,0 +1,80 @@ +package org.matsim.contrib.drt.optimizer; + +import com.google.common.base.Verify; +import org.matsim.core.config.Config; +import org.matsim.core.config.ReflectiveConfigGroup; + +import java.util.List; +import java.util.Optional; + +/** + * @author nkuehnel / MOIA + */ +public class DrtOptimizationConstraintsParams extends ReflectiveConfigGroup { + + public static final String SET_NAME = "drtOptimizationConstraints"; + + public static String defaultConstraintSet = DrtOptimizationConstraintsSet.DEFAULT_PARAMS_NAME; + + + public DrtOptimizationConstraintsParams() { + super(SET_NAME); + } + + @Override + protected void checkConsistency(Config config) { + super.checkConsistency(config); + List drtOptimizationConstraintsSets = getDrtOptimizationConstraintsSets(); + + Verify.verify(!drtOptimizationConstraintsSets.isEmpty(), + "At least one DrtOptimizationConstraintsParams is required."); + Verify.verify(drtOptimizationConstraintsSets.stream() + .anyMatch(params -> params.name.equals(defaultConstraintSet)), + "Default DrtOptimizationConstraintsParams is required."); + Verify.verify(drtOptimizationConstraintsSets.stream() + .map(params -> params.name) + .distinct() + .count() == drtOptimizationConstraintsSets.size(), + "Cannot have DrtOptimizationConstraintsParams with identical names."); + } + + public List getDrtOptimizationConstraintsSets() { + return getParameterSets(DrtOptimizationConstraintsSet.SET_NAME).stream() + .filter(DrtOptimizationConstraintsSet.class::isInstance) + .map(DrtOptimizationConstraintsSet.class::cast) + .toList(); + } + + public DrtOptimizationConstraintsSet addOrGetDefaultDrtOptimizationConstraintsSet() { + Optional drtOptParams = getDrtOptimizationConstraintsSets().stream() + .filter(params -> params.name.equals(defaultConstraintSet)) + .findAny(); + if (drtOptParams.isEmpty()) { + addParameterSet(new DrtOptimizationConstraintsSet()); + } + return getDrtOptimizationConstraintsSets().stream() + .filter(params -> params.name.equals(defaultConstraintSet)) + .findAny().orElseThrow(); + } + + /** + * for backwards compatibility with old drt config groups + */ + public void handleAddUnknownParam(final String paramName, final String value) { + switch (paramName) { + case "maxWaitTime": + case "maxTravelTimeAlpha": + case "maxTravelTimeBeta": + case "maxAbsoluteDetour": + case "maxDetourAlpha": + case "maxDetourBeta": + case "maxAllowedPickupDelay": + case "rejectRequestIfMaxWaitOrTravelTimeViolated": + case "maxWalkDistance": + addOrGetDefaultDrtOptimizationConstraintsSet().addParam(paramName, value); + break; + default: + super.handleAddUnknownParam(paramName, value); + } + } +} \ No newline at end of file diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtOptimizationConstraintsParams.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsSet.java similarity index 91% rename from contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtOptimizationConstraintsParams.java rename to contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsSet.java index f3f1e1ed5f2..d80bc047b4e 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtOptimizationConstraintsParams.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsSet.java @@ -1,18 +1,25 @@ -package org.matsim.contrib.drt.run; +package org.matsim.contrib.drt.optimizer; import com.google.common.base.Verify; import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.PositiveOrZero; import org.matsim.core.config.Config; import org.matsim.core.config.ReflectiveConfigGroup; -/** - * @author nkuehnel / MOIA - */ -public class DrtOptimizationConstraintsParams extends ReflectiveConfigGroup { +public class DrtOptimizationConstraintsSet extends ReflectiveConfigGroup { - public final static String SET_NAME = "drtOptimizationConstraints"; + public static final String SET_NAME = "drtOptimizationConstraintsSet"; + public static final String DEFAULT_PARAMS_NAME = "default"; + public DrtOptimizationConstraintsSet() { + super(SET_NAME); + } + + @Parameter + @Comment("name of optimization params") + @NotBlank + public String name = DEFAULT_PARAMS_NAME; @Parameter @Comment("Max wait time for the bus to come (optimisation constraint).") @@ -81,10 +88,6 @@ public class DrtOptimizationConstraintsParams extends ReflectiveConfigGroup { @PositiveOrZero // used only for stopbased DRT scheme public double maxWalkDistance = Double.MAX_VALUE;// [m]; - public DrtOptimizationConstraintsParams() { - super(SET_NAME); - } - @Override protected void checkConsistency(Config config) { super.checkConsistency(config); @@ -93,4 +96,4 @@ protected void checkConsistency(Config config) { "maxAllowedPickupDelay must be specified! A value between 0 and 240 seconds can be a good choice for maxAllowedPickupDelay."); } } -} \ No newline at end of file +} diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingStopActivity.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingStopActivity.java index 268521d4ada..1e1965d11a6 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingStopActivity.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingStopActivity.java @@ -131,19 +131,19 @@ private boolean updatePickupRequests(double now) { var enterIterator = enterTimes.entrySet().iterator(); while (enterIterator.hasNext()) { - if (onboard >= vehicle.getCapacity()) { - // only let people enter if there is currently free capacity - break; - } - var entry = enterIterator.next(); + int availableCapacity = vehicle.getCapacity() - onboard; if (entry.getValue() <= now) { - // let agent enter now - Verify.verify(passengerHandler.tryPickUpPassengers(this, driver, entry.getKey(), now)); - enteredRequests.add(entry.getKey()); - onboard += pickupRequests.get(entry.getKey()).getPassengerCount(); - enterIterator.remove(); + int requiredCapacity = pickupRequests.get(entry.getKey()).getPassengerCount(); + + if (requiredCapacity <= availableCapacity) { + // let agent enter now + Verify.verify(passengerHandler.tryPickUpPassengers(this, driver, entry.getKey(), now)); + enteredRequests.add(entry.getKey()); + onboard += requiredCapacity; + enterIterator.remove(); + } } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java index c19a631ac44..9cb031a9ebf 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java @@ -23,6 +23,7 @@ import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Route; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.dvrp.path.VrpPathWithTravelData; import org.matsim.contrib.dvrp.path.VrpPaths; @@ -61,7 +62,9 @@ public DrtRouteCreator(DrtConfigGroup drtCfg, Network modalNetwork, * @return maximum travel time */ static double getMaxTravelTime(DrtConfigGroup drtCfg, double unsharedRideTime) { - return drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha * unsharedRideTime + drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeBeta; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + return defaultConstraintsSet.maxTravelTimeAlpha * unsharedRideTime + + defaultConstraintsSet.maxTravelTimeBeta; } /** @@ -72,7 +75,10 @@ static double getMaxTravelTime(DrtConfigGroup drtCfg, double unsharedRideTime) { * @return maximum ride time */ static double getMaxRideTime(DrtConfigGroup drtCfg, double unsharedRideTime) { - return Math.min(unsharedRideTime + drtCfg.getDrtOptimizationConstraintsParam().maxAbsoluteDetour, drtCfg.getDrtOptimizationConstraintsParam().maxDetourAlpha * unsharedRideTime + drtCfg.getDrtOptimizationConstraintsParam().maxDetourBeta); + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + return Math.min(unsharedRideTime + defaultConstraintsSet.maxAbsoluteDetour, + defaultConstraintsSet.maxDetourAlpha * unsharedRideTime + + defaultConstraintsSet.maxDetourBeta); } public Route createRoute(double departureTime, Link accessActLink, Link egressActLink, Person person, @@ -89,7 +95,7 @@ public Route createRoute(double departureTime, Link accessActLink, Link egressAc route.setTravelTime(maxTravelTime); route.setMaxRideTime(maxRideDuration); route.setDirectRideTime(unsharedRideTime); - route.setMaxWaitTime(drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime); + route.setMaxWaitTime(drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().maxWaitTime); if (this.drtCfg.storeUnsharedPath) { route.setUnsharedPath(unsharedPath); diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java index 687b48b16fc..b271a8690e8 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java @@ -19,11 +19,12 @@ package org.matsim.contrib.drt.run; -import com.google.common.base.Preconditions; -import com.google.common.base.Verify; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Positive; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +import javax.annotation.Nullable; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.TransportMode; @@ -31,6 +32,8 @@ import org.matsim.contrib.drt.analysis.zonal.DrtZoneSystemParams; import org.matsim.contrib.drt.estimator.DrtEstimatorParams; import org.matsim.contrib.drt.fare.DrtFareParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.DrtRequestInsertionRetryParams; import org.matsim.contrib.drt.optimizer.insertion.DrtInsertionSearchParams; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; @@ -43,14 +46,16 @@ import org.matsim.contrib.dvrp.router.DvrpModeRoutingNetworkModule; import org.matsim.contrib.dvrp.run.Modal; import org.matsim.core.config.Config; +import org.matsim.core.config.groups.QSimConfigGroup.EndtimeInterpretation; import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup; -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Optional; +import com.google.common.base.Preconditions; +import com.google.common.base.Verify; -import static org.matsim.core.config.groups.QSimConfigGroup.EndtimeInterpretation; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; public class DrtConfigGroup extends ReflectiveConfigGroupWithConfigurableParameterSets implements Modal { private static final Logger log = LogManager.getLogger(DrtConfigGroup.class); @@ -64,9 +69,6 @@ public static DrtConfigGroup getSingleModeDrtConfig(Config config) { return drtConfigGroups.iterator().next(); } - @NotNull - private DrtOptimizationConstraintsParams drtOptimizationConstraintsParams; - @Parameter @Comment("Mode which will be handled by PassengerEngine and VrpOptimizer (passengers'/customers' perspective)") @NotBlank @@ -159,6 +161,9 @@ public enum SimulationType { @NotNull private DrtInsertionSearchParams drtInsertionSearchParams; + @NotNull + private DrtOptimizationConstraintsParams drtOptimizationConstraintsParams; + @Nullable private DrtZoneSystemParams zonalSystemParams; @@ -186,9 +191,11 @@ public DrtConfigGroup() { } private void initSingletonParameterSets() { - //drt optimization constraints + + //optimization constraints (mandatory) addDefinition(DrtOptimizationConstraintsParams.SET_NAME, DrtOptimizationConstraintsParams::new, - () -> drtOptimizationConstraintsParams, params -> drtOptimizationConstraintsParams = (DrtOptimizationConstraintsParams) params); + () -> drtOptimizationConstraintsParams, + params -> drtOptimizationConstraintsParams = (DrtOptimizationConstraintsParams) params); //rebalancing (optional) addDefinition(RebalancingParams.SET_NAME, RebalancingParams::new, () -> rebalancingParams, @@ -231,7 +238,6 @@ private void initSingletonParameterSets() { addDefinition(DrtEstimatorParams.SET_NAME, DrtEstimatorParams::new, () -> drtEstimatorParams, params -> drtEstimatorParams = (DrtEstimatorParams) params); - } /** @@ -248,7 +254,7 @@ public void handleAddUnknownParam(final String paramName, final String value) { case "maxAllowedPickupDelay": case "rejectRequestIfMaxWaitOrTravelTimeViolated": case "maxWalkDistance": - getDrtOptimizationConstraintsParam().addParam(paramName, value); + addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().addParam(paramName, value); break; default: super.handleAddUnknownParam(paramName, value); @@ -269,7 +275,11 @@ protected void checkConsistency(Config config) { + "attempting to travel without vehicles being available."); } - Verify.verify(drtOptimizationConstraintsParams.maxWaitTime >= stopDuration, "maxWaitTime must not be smaller than stopDuration"); + List drtOptimizationConstraintsSets = addOrGetDrtOptimizationConstraintsParams().getDrtOptimizationConstraintsSets(); + for (DrtOptimizationConstraintsSet constraintsSet : drtOptimizationConstraintsSets) { + Verify.verify(constraintsSet.maxWaitTime >= stopDuration, + "maxWaitTime must not be smaller than stopDuration"); + } Verify.verify(operationalScheme != OperationalScheme.stopbased || transitStopFile != null, "transitStopFile must not be null when operationalScheme is " + OperationalScheme.stopbased); @@ -309,17 +319,19 @@ public String getMode() { return mode; } - public DrtOptimizationConstraintsParams getDrtOptimizationConstraintsParam() { - if (drtOptimizationConstraintsParams == null) { - addParameterSet(new DrtOptimizationConstraintsParams()); - } - return drtOptimizationConstraintsParams; - } + public DrtInsertionSearchParams getDrtInsertionSearchParams() { return drtInsertionSearchParams; } + public DrtOptimizationConstraintsParams addOrGetDrtOptimizationConstraintsParams() { + if(drtOptimizationConstraintsParams == null) { + drtOptimizationConstraintsParams = new DrtOptimizationConstraintsParams(); + } + return drtOptimizationConstraintsParams; + } + public Optional getZonalSystemParams() { return Optional.ofNullable(zonalSystemParams); } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java index af5916d028a..95c23eeaf17 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java @@ -104,7 +104,8 @@ public void install() { .asEagerSingleton(); case stopbased, serviceAreaBased -> { bindModal( AccessEgressFacilityFinder.class ).toProvider( modalProvider( - getter -> new ClosestAccessEgressFacilityFinder( drtCfg.getDrtOptimizationConstraintsParam().maxWalkDistance, + getter -> new ClosestAccessEgressFacilityFinder( + drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().maxWalkDistance, getter.get( Network.class ), QuadTrees.createQuadTree( getter.getModal( DrtStopNetwork.class ).getDrtStops().values() ) ) ) ) .asEagerSingleton(); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/MaxDetourConstraintTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/MaxDetourConstraintTest.java index 8722cc9e657..d15ae3dab03 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/MaxDetourConstraintTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/MaxDetourConstraintTest.java @@ -36,17 +36,18 @@ public void testMaxDetourConstraint() { DrtConfigGroup drtConfigGroup = DrtConfigGroup.getSingleModeDrtConfig(config); // Max wait time - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = 300; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = 300; // Turn on the max detour constraint - drtConfigGroup.getDrtOptimizationConstraintsParam().maxDetourAlpha = 1.5; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxDetourBeta = 300; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxAllowedPickupDelay = 180; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxAbsoluteDetour = 1200; + defaultConstraintsSet.maxDetourAlpha = 1.5; + defaultConstraintsSet.maxDetourBeta = 300; + defaultConstraintsSet.maxAllowedPickupDelay = 180; + defaultConstraintsSet.maxAbsoluteDetour = 1200; // Make the max total travel time constraints very loose (i.e., make it not active) - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 10; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 7200; + defaultConstraintsSet.maxTravelTimeAlpha = 10; + defaultConstraintsSet.maxTravelTimeBeta = 7200; config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setOutputDirectory(utils.getOutputDirectory()); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DrtPoolingParameterTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DrtPoolingParameterTest.java index dfff04e67da..96836e36303 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DrtPoolingParameterTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DrtPoolingParameterTest.java @@ -10,6 +10,7 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.population.*; import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.run.DrtControlerCreator; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.fleet.DvrpVehicle; @@ -225,9 +226,10 @@ private PersonEnterDrtVehicleEventHandler setupAndRunScenario(double maxWaitTime MultiModeDrtConfigGroup mm = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); mm.getModalElements().forEach(x -> { - x.getDrtOptimizationConstraintsParam().maxWaitTime = maxWaitTime; - x.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = maxTravelTimeAlpha; - x.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = maxTravelTimeBeta; + DrtOptimizationConstraintsSet defaultConstraintsSet = x.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = maxWaitTime; + defaultConstraintsSet.maxTravelTimeAlpha = maxTravelTimeAlpha; + defaultConstraintsSet.maxTravelTimeBeta = maxTravelTimeBeta; x.stopDuration = 1.; }); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java index 9f6b424da09..b0d3e37c42f 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java @@ -626,7 +626,7 @@ private class Fixture { DrtConfigGroup drtConfig = new DrtConfigGroup(); drtConfig.stopDuration = 30.0; - drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime = 600.0; + drtConfig.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().maxWaitTime = 600.0; this.entryFactory = new VehicleDataEntryFactoryImpl(); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/PrebookingTestEnvironment.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/PrebookingTestEnvironment.java index e4cece58765..f161c3ad9a1 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/PrebookingTestEnvironment.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/PrebookingTestEnvironment.java @@ -10,6 +10,7 @@ import org.matsim.api.core.v01.network.Node; import org.matsim.api.core.v01.population.*; import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.insertion.DrtInsertionSearchParams; import org.matsim.contrib.drt.optimizer.insertion.selective.SelectiveInsertionSearchParams; import org.matsim.contrib.drt.passenger.events.DrtRequestSubmittedEvent; @@ -226,9 +227,10 @@ private void buildConfig(Config config) { DrtConfigGroup modeConfig = new DrtConfigGroup(); drtConfig.addParameterSet(modeConfig); modeConfig.mode = "drt"; - modeConfig.getDrtOptimizationConstraintsParam().maxWaitTime = maximumWaitTime; - modeConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = detourRelative; - modeConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = detourAbsolute; + DrtOptimizationConstraintsSet defaultConstraintsSet = modeConfig.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = maximumWaitTime; + defaultConstraintsSet.maxTravelTimeAlpha = detourRelative; + defaultConstraintsSet.maxTravelTimeBeta = detourAbsolute; modeConfig.stopDuration = stopDuration; modeConfig.idleVehiclesReturnToDepots = false; modeConfig.vehiclesFile = null; diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java index f86bbeb7215..459c3bf8965 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java @@ -36,6 +36,7 @@ import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.PlanElement; import org.matsim.api.core.v01.population.PopulationFactory; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.run.DrtControlerCreator; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; @@ -80,9 +81,10 @@ void testCottbusClosestAccessEgressStopFinder() { DrtConfigGroup drtCfg = DrtConfigGroup.getSingleModeDrtConfig(scenario.getConfig()); String drtMode = "DrtX"; drtCfg.mode = drtMode; - drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5; - drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5 * 60; - drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime = 5 * 60; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.5; + defaultConstraintsSet.maxTravelTimeBeta = 5 * 60; + defaultConstraintsSet.maxWaitTime = 5 * 60; ImmutableMap, DrtStopFacility> drtStops = scenario.getTransitSchedule() .getFacilities() @@ -91,7 +93,8 @@ void testCottbusClosestAccessEgressStopFinder() { .map(DrtStopFacilityImpl::createFromFacility) .collect(ImmutableMap.toImmutableMap(DrtStopFacility::getId, f -> f)); - AccessEgressFacilityFinder stopFinder = new ClosestAccessEgressFacilityFinder(drtCfg.getDrtOptimizationConstraintsParam().maxWalkDistance, + AccessEgressFacilityFinder stopFinder = new ClosestAccessEgressFacilityFinder( + defaultConstraintsSet.maxWalkDistance, scenario.getNetwork(), QuadTrees.createQuadTree(drtStops.values())); DrtRouteCreator drtRouteCreator = new DrtRouteCreator(drtCfg, scenario.getNetwork(), new SpeedyDijkstraFactory(), new FreeSpeedTravelTime(), TimeAsTravelDisutility::new); @@ -259,7 +262,7 @@ void testRouteDescriptionHandling() { private Scenario createTestScenario() { Config config = ConfigUtils.createConfig(); DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWalkDistance = 200; + drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().maxWalkDistance = 200; drtConfigGroup.transitStopFile = utils.getClassInputDirectory() + "testCottbus/drtstops.xml.gz"; MultiModeDrtConfigGroup multiModeDrtConfigGroup = new MultiModeDrtConfigGroup(); multiModeDrtConfigGroup.addParameterSet(drtConfigGroup); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/run/DrtConfigGroupTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/DrtConfigGroupTest.java new file mode 100644 index 00000000000..ae9cd5c3f21 --- /dev/null +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/DrtConfigGroupTest.java @@ -0,0 +1,73 @@ +package org.matsim.contrib.drt.run; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; + +import com.google.common.base.VerifyException; + +class DrtConfigGroupTest { + + @Test + void testHasDefaultDrtOptimizationConstraintsParam() { + Config config = ConfigUtils.createConfig(); + DrtConfigGroup drtConfig = new DrtConfigGroup(); + config.addModule(drtConfig); + + // get DrtOptimizationConstraintsParams + DrtOptimizationConstraintsSet params = drtConfig.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + + Assertions.assertEquals(DrtOptimizationConstraintsParams.defaultConstraintSet, params.name); + Assertions.assertThrows(VerifyException.class, () -> drtConfig.checkConsistency(config)); + drtConfig.stopDuration = 0; + params.maxWaitTime = drtConfig.stopDuration; + Assertions.assertDoesNotThrow(() -> drtConfig.checkConsistency(config)); + } + + @Test + void testMultipleDrtOptimizationConstraintsParams() { + Config config = ConfigUtils.createConfig(); + DrtConfigGroup drtConfig = new DrtConfigGroup(); + config.addModule(drtConfig); + + // add second DrtOptimizationConstraintsParams + DrtOptimizationConstraintsSet params = new DrtOptimizationConstraintsSet(); + params.name = "test"; + + DrtOptimizationConstraintsParams optimizationConstraintsParams = drtConfig.addOrGetDrtOptimizationConstraintsParams(); + optimizationConstraintsParams.addParameterSet(params); + + //default not yet present + Assertions.assertEquals(1, optimizationConstraintsParams.getDrtOptimizationConstraintsSets().size()); + + DrtOptimizationConstraintsSet defaultConstraints = optimizationConstraintsParams.addOrGetDefaultDrtOptimizationConstraintsSet(); + Assertions.assertEquals(2, optimizationConstraintsParams.getDrtOptimizationConstraintsSets().size()); + + drtConfig.stopDuration = 0; + params.maxWaitTime = drtConfig.stopDuration; + defaultConstraints.maxWaitTime = drtConfig.stopDuration; + + Assertions.assertDoesNotThrow(() -> drtConfig.checkConsistency(config)); + } + + @Test + void testNoDuplicateDrtDrtOptimizationConstraintsParams() { + Config config = ConfigUtils.createConfig(); + DrtConfigGroup drtConfig = new DrtConfigGroup(); + config.addModule(drtConfig); + + // add second DrtOptimizationConstraintsParams with same name + DrtOptimizationConstraintsSet params = new DrtOptimizationConstraintsSet(); + params.name = DrtOptimizationConstraintsSet.DEFAULT_PARAMS_NAME; + + DrtOptimizationConstraintsParams optimizationConstraintsParams = drtConfig.addOrGetDrtOptimizationConstraintsParams(); + optimizationConstraintsParams.addOrGetDefaultDrtOptimizationConstraintsSet(); + optimizationConstraintsParams.addParameterSet(params); + + Assertions.assertEquals(2, optimizationConstraintsParams.getDrtOptimizationConstraintsSets().size()); + Assertions.assertThrows(VerifyException.class, () -> drtConfig.checkConsistency(config)); + } +} diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunDrtExampleIT.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunDrtExampleIT.java index 6b15ba1bc9e..0b2adb16db2 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunDrtExampleIT.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunDrtExampleIT.java @@ -90,7 +90,9 @@ void testRunDrtExampleWithNoRejections_ExtensiveSearch() { for (var drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.addOrGetDrtOptimizationConstraintsParams() + .addOrGetDefaultDrtOptimizationConstraintsSet() + .rejectRequestIfMaxWaitOrTravelTimeViolated = false; } config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); @@ -129,7 +131,9 @@ void testRunDrtExampleWithNoRejections_SelectiveSearch() { drtCfg.addParameterSet(selectiveInsertionSearchParams); //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.addOrGetDrtOptimizationConstraintsParams() + .addOrGetDefaultDrtOptimizationConstraintsSet() + .rejectRequestIfMaxWaitOrTravelTimeViolated = false; } config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); @@ -168,7 +172,9 @@ void testRunDrtExampleWithNoRejections_RepeatedSelectiveSearch() { drtCfg.addParameterSet(repeatedSelectiveInsertionSearchParams); //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.addOrGetDrtOptimizationConstraintsParams() + .addOrGetDefaultDrtOptimizationConstraintsSet() + .rejectRequestIfMaxWaitOrTravelTimeViolated = false; } config.controller().setLastIteration(3); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunOldDrtConfigCompatibilityIT.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunOldDrtConfigCompatibilityIT.java index 506bb7503c2..60dc9c1bf7e 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunOldDrtConfigCompatibilityIT.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunOldDrtConfigCompatibilityIT.java @@ -41,7 +41,9 @@ void testRunDrtExampleWithNoRejections_ExtensiveSearch() { for (var drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.addOrGetDrtOptimizationConstraintsParams() + .addOrGetDefaultDrtOptimizationConstraintsSet() + .rejectRequestIfMaxWaitOrTravelTimeViolated = false; } config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/teleportation/DrtTeleportationTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/teleportation/DrtTeleportationTest.java index 27dfd190989..47ede4e4e89 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/teleportation/DrtTeleportationTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/teleportation/DrtTeleportationTest.java @@ -10,9 +10,9 @@ import org.matsim.contrib.drt.estimator.DrtEstimatorModule; import org.matsim.contrib.drt.estimator.impl.PessimisticDrtEstimator; import org.matsim.contrib.drt.fare.DrtFareParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.run.DrtControlerCreator; -import org.matsim.contrib.drt.run.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.core.config.Config; @@ -46,10 +46,10 @@ void testTeleportationEngine() throws IOException { Controler controler = DrtControlerCreator.createControler(config, false); DrtConfigGroup drtConfigGroup = DrtConfigGroup.getSingleModeDrtConfig(config); - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); - constraintsParam.maxTravelTimeAlpha = 1.2; - constraintsParam.maxTravelTimeBeta = 600; - constraintsParam.maxWaitTime = 300; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.2; + defaultConstraintsSet.maxTravelTimeBeta = 600; + defaultConstraintsSet.maxWaitTime = 300; DrtFareParams fareParams = new DrtFareParams(); fareParams.baseFare = 1.0; fareParams.distanceFare_m = 0.001; @@ -77,12 +77,12 @@ public void install() { double waitAvg = Double.parseDouble(row.get("wait_average")); - assertThat(waitAvg).isEqualTo(constraintsParam.maxWaitTime); + assertThat(waitAvg).isEqualTo(defaultConstraintsSet.maxWaitTime); double distMean = Double.parseDouble(row.get("distance_m_mean")); double directDistMean = Double.parseDouble(row.get("directDistance_m_mean")); - assertThat(distMean / directDistMean).isCloseTo(constraintsParam.maxTravelTimeAlpha, Offset.offset(0.0001)); + assertThat(distMean / directDistMean).isCloseTo(defaultConstraintsSet.maxTravelTimeAlpha, Offset.offset(0.0001)); } diff --git a/contribs/hybridsim/pom.xml b/contribs/hybridsim/pom.xml index 496f3b1b96a..fa6c86d2f52 100644 --- a/contribs/hybridsim/pom.xml +++ b/contribs/hybridsim/pom.xml @@ -10,7 +10,7 @@ hybridsim - 4.26.1 + 4.27.0 1.64.0 diff --git a/contribs/protobuf/pom.xml b/contribs/protobuf/pom.xml index 8b2b9121993..a824085d737 100644 --- a/contribs/protobuf/pom.xml +++ b/contribs/protobuf/pom.xml @@ -11,7 +11,7 @@ protobuf - 4.26.1 + 4.27.0 diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java index b4aa67762e0..4c577fed4a8 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java @@ -21,6 +21,7 @@ package org.matsim.contrib.taxi.run; import org.matsim.contrib.drt.fare.DrtFareParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.run.DrtModeModule; import org.matsim.contrib.drt.run.DrtModeQSimModule; @@ -66,16 +67,17 @@ public static DrtConfigGroup convertTaxiToDrtCfg(TaxiConfigGroup taxiCfg) { // Taxi optimisers do not reject, so time constraints are only used for routing plans (DrtRouteCreator). // Using some (relatively high) values as we do not know what values should be there. They can be adjusted // manually after the TaxiAsDrtConfigGroup config is created. - drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime = 3600; - drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 2; - drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 3600; - drtCfg.getDrtOptimizationConstraintsParam().maxAbsoluteDetour = Double.MAX_VALUE; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = 3600; + defaultConstraintsSet.maxTravelTimeAlpha = 2; + defaultConstraintsSet.maxTravelTimeBeta = 3600; + defaultConstraintsSet.maxAbsoluteDetour = Double.MAX_VALUE; - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtCfg.changeStartLinkToLastLinkInSchedule = taxiCfg.changeStartLinkToLastLinkInSchedule; drtCfg.idleVehiclesReturnToDepots = false; drtCfg.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtCfg.getDrtOptimizationConstraintsParam().maxWalkDistance = Double.MAX_VALUE; + defaultConstraintsSet.maxWalkDistance = Double.MAX_VALUE; drtCfg.vehiclesFile = taxiCfg.taxisFile; drtCfg.transitStopFile = null; drtCfg.drtServiceAreaShapeFile = null; diff --git a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java index f99512782ef..0c2e2fbd58e 100644 --- a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java +++ b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java @@ -24,6 +24,7 @@ import org.matsim.api.core.v01.population.Population; import org.matsim.api.core.v01.population.PopulationFactory; import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.routing.DrtRouteFactory; @@ -229,11 +230,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 2.0; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 2.0; + defaultConstraintsSet.maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + defaultConstraintsSet.maxWaitTime = Double.MAX_VALUE; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); @@ -243,11 +245,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { if (drt2) { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = "drt2"; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.3; + defaultConstraintsSet.maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + defaultConstraintsSet.maxWaitTime = Double.MAX_VALUE; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); @@ -256,11 +259,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { if (drt3) { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = "drt3"; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.3; + defaultConstraintsSet.maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + defaultConstraintsSet.maxWaitTime = Double.MAX_VALUE; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); diff --git a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALineTest.java b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALineTest.java index fd92aafff84..e771f174dd7 100644 --- a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALineTest.java +++ b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALineTest.java @@ -11,6 +11,7 @@ import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.routing.DrtRouteFactory; import org.matsim.contrib.drt.run.DrtConfigGroup; @@ -110,10 +111,12 @@ void testDrtAlongALine() { DrtConfigGroup drtConfig = new DrtConfigGroup(); drtConfig.mode = "drt_A"; drtConfig.stopDuration = 60.; - drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime = 900.; - drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.; - drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + DrtOptimizationConstraintsSet defaultConstraintsSet = + drtConfig.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = 900.; + defaultConstraintsSet.maxTravelTimeAlpha = 1.3; + defaultConstraintsSet.maxTravelTimeBeta = 10. * 60.; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfig.changeStartLinkToLastLinkInSchedule = true; multiModeDrtCfg.addParameterSet(drtConfig); } @@ -247,11 +250,12 @@ void testPtAlongALineWithRaptorAndDrtStopFilterAttribute() { MultiModeDrtConfigGroup mm = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); { DrtConfigGroup drtConfig = new DrtConfigGroup(); - drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; drtConfig.stopDuration = 60.; - drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfig.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.3; + defaultConstraintsSet.maxTravelTimeBeta = 5. * 60.; + defaultConstraintsSet.maxWaitTime = Double.MAX_VALUE; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfig.mode = TransportMode.drt; mm.addParameterSet(drtConfig); } diff --git a/pom.xml b/pom.xml index 4e29f5f1b0b..f81cb43ab6d 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ org.apache.commons commons-compress - 1.26.1 + 1.26.2 commons-logging