From 48bda59fc768c761bd7cc53cac3523e7c5e3e56e Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Thu, 16 May 2024 16:55:44 +0200 Subject: [PATCH 1/4] Allow for storing multiple DrtOptimizationConstraintsParams --- .../examples/RunJointDemandDRTExample.java | 6 +- .../edrt/run/EDrtModeOptimizerQSimModule.java | 7 +- .../extension/fiss/RunFissDrtScenarioIT.java | 10 +-- .../eshifts/run/RunEShiftDrtScenarioIT.java | 2 +- .../run/RunMultiHubShiftDrtScenarioIT.java | 2 +- .../shifts/run/RunShiftDrtScenarioIT.java | 2 +- .../DrtAnalysisControlerListener.java | 8 ++- .../impl/PessimisticDrtEstimator.java | 2 +- .../optimizer/DrtModeOptimizerQSimModule.java | 7 +- .../contrib/drt/routing/DrtRouteCreator.java | 9 ++- .../contrib/drt/run/DrtConfigGroup.java | 64 +++++++++++++------ .../contrib/drt/run/DrtModeRoutingModule.java | 3 +- .../run/DrtOptimizationConstraintsParams.java | 8 ++- .../optimizer/MaxDetourConstraintTest.java | 14 ++-- .../insertion/DrtPoolingParameterTest.java | 6 +- .../prebooking/ComplexUnschedulerTest.java | 2 +- .../prebooking/PrebookingTestEnvironment.java | 6 +- .../drt/routing/DrtRoutingModuleTest.java | 11 ++-- .../drt/run/examples/RunDrtExampleIT.java | 6 +- .../RunOldDrtConfigCompatibilityIT.java | 2 +- .../teleportation/DrtTeleportationTest.java | 2 +- .../contrib/taxi/run/MultiModeTaxiModule.java | 12 ++-- .../drtAndPt/PtAlongALine2Test.java | 27 ++++---- .../drtAndPt/PtAlongALineTest.java | 16 ++--- 24 files changed, 141 insertions(+), 93 deletions(-) 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..4888f4fc1c7 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 @@ -141,9 +141,9 @@ 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; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 2 * 3600; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 5; + drtCfg.getDefaultDrtOptimizationConstraintsParam().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..2ddc571d467 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 @@ -147,7 +147,9 @@ public EmptyVehicleChargingScheduler get() { bindModal(VehicleEntry.EntryFactory.class).toProvider( EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider.class).asEagerSingleton(); - bindModal(CostCalculationStrategy.class).to(drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated ? + bindModal(CostCalculationStrategy.class) + .to(drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated + ? CostCalculationStrategy.RejectSoftConstraintViolations.class : CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton(); @@ -179,7 +181,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( + drtCfg.getDefaultDrtOptimizationConstraintsParam().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..2e464f161a7 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 @@ -53,16 +53,16 @@ void test() { DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.; drtConfigGroup.stopDuration = 30.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = 600.; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = true; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 600.; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = true; drtConfigGroup.useModeFilteredSubnetwork = false; drtConfigGroup.vehiclesFile = fleetFile; drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; drtConfigGroup.plotDetailedCustomerStats = true; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWalkDistance = 1000.; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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..b4648770172 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 @@ -57,7 +57,7 @@ void test() { DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; drtConfigGroup.mode = TransportMode.drt; - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); + DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDefaultDrtOptimizationConstraintsParam(); constraintsParam.maxTravelTimeAlpha = 1.5; constraintsParam.maxTravelTimeBeta = 10. * 60.; drtConfigGroup.stopDuration = 30.; 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..053211ec458 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 @@ -46,7 +46,7 @@ void test() { DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; drtConfigGroup.mode = TransportMode.drt; - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); + DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDefaultDrtOptimizationConstraintsParam(); constraintsParam.maxTravelTimeAlpha = 1.5; constraintsParam.maxTravelTimeBeta = 10. * 60.; drtConfigGroup.stopDuration = 30.; 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..e9674eb0d29 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 @@ -47,7 +47,7 @@ void test() { DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; drtConfigGroup.mode = TransportMode.drt; - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); + DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDefaultDrtOptimizationConstraintsParam(); constraintsParam.maxTravelTimeAlpha = 1.5; constraintsParam.maxTravelTimeBeta = 10. * 60.; drtConfigGroup.stopDuration = 30.; 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..8cb77352196 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 @@ -400,7 +400,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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime)); // xAxis.setLowerBound(0); // yAxis.setLowerBound(0); ChartUtils.writeChartAsPNG(new FileOutputStream(plotFileName), chart2, 1500, 1500); @@ -664,11 +664,13 @@ private static void analyseDetours(Network network, List legs, Map new DefaultOfferAcceptor(drtCfg.getDrtOptimizationConstraintsParam().maxAllowedPickupDelay))); + bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor( + drtCfg.getDefaultDrtOptimizationConstraintsParam().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/routing/DrtRouteCreator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java index c19a631ac44..12c757f1ea0 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 @@ -61,7 +61,8 @@ 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; + return drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha * unsharedRideTime + + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta; } /** @@ -72,7 +73,9 @@ 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); + return Math.min(unsharedRideTime + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxAbsoluteDetour, + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxDetourAlpha * unsharedRideTime + + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxDetourBeta); } public Route createRoute(double departureTime, Link accessActLink, Link egressActLink, Person person, @@ -89,7 +92,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.getDefaultDrtOptimizationConstraintsParam().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..f8fa7690a0b 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; @@ -43,14 +44,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 +67,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 @@ -187,8 +187,7 @@ public DrtConfigGroup() { private void initSingletonParameterSets() { //drt optimization constraints - addDefinition(DrtOptimizationConstraintsParams.SET_NAME, DrtOptimizationConstraintsParams::new, - () -> drtOptimizationConstraintsParams, params -> drtOptimizationConstraintsParams = (DrtOptimizationConstraintsParams) params); + getDefaultDrtOptimizationConstraintsParam(); //rebalancing (optional) addDefinition(RebalancingParams.SET_NAME, RebalancingParams::new, () -> rebalancingParams, @@ -248,7 +247,7 @@ public void handleAddUnknownParam(final String paramName, final String value) { case "maxAllowedPickupDelay": case "rejectRequestIfMaxWaitOrTravelTimeViolated": case "maxWalkDistance": - getDrtOptimizationConstraintsParam().addParam(paramName, value); + getDefaultDrtOptimizationConstraintsParam().addParam(paramName, value); break; default: super.handleAddUnknownParam(paramName, value); @@ -269,7 +268,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 drtOptimizationConstraintsParams = getDrtOptimizationConstraintsParams(); + for (DrtOptimizationConstraintsParams params : drtOptimizationConstraintsParams) { + Verify.verify(params.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); @@ -302,6 +305,17 @@ protected void checkConsistency(Config config) { Verify.verify(drtSpeedUpParams == null, "Simulation type is estimateAndTeleport, but drtSpeedUpParams is set. " + "Please remove drtSpeedUpParams from the config, as these two functionalities are not compatible."); } + + Verify.verify(!drtOptimizationConstraintsParams.isEmpty(), + "At least one DrtOptimizationConstraintsParams is required."); + Verify.verify(drtOptimizationConstraintsParams.stream() + .anyMatch(params -> DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME.equals(params.name)), + "Default DrtOptimizationConstraintsParams is required."); + Verify.verify(drtOptimizationConstraintsParams.stream() + .map(params -> params.name) + .distinct() + .count() == drtOptimizationConstraintsParams.size(), + "Cannot have DrtOptimizationConstraintsParams with identical names."); } @Override @@ -309,11 +323,23 @@ public String getMode() { return mode; } - public DrtOptimizationConstraintsParams getDrtOptimizationConstraintsParam() { - if (drtOptimizationConstraintsParams == null) { + public List getDrtOptimizationConstraintsParams() { + return getParameterSets(DrtOptimizationConstraintsParams.SET_NAME).stream() + .filter(DrtOptimizationConstraintsParams.class::isInstance) + .map(DrtOptimizationConstraintsParams.class::cast) + .toList(); + } + + public DrtOptimizationConstraintsParams getDefaultDrtOptimizationConstraintsParam() { + Optional drtOptParams = getDrtOptimizationConstraintsParams().stream() + .filter(params -> DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME.equals(params.name)) + .findAny(); + if (drtOptParams.isEmpty()) { addParameterSet(new DrtOptimizationConstraintsParams()); } - return drtOptimizationConstraintsParams; + return getDrtOptimizationConstraintsParams().stream() + .filter(params -> DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME.equals(params.name)) + .findAny().orElseThrow(); } public DrtInsertionSearchParams getDrtInsertionSearchParams() { 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..c57ae9c9eda 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.getDefaultDrtOptimizationConstraintsParam().maxWalkDistance, getter.get( Network.class ), QuadTrees.createQuadTree( getter.getModal( DrtStopNetwork.class ).getDrtStops().values() ) ) ) ) .asEagerSingleton(); 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/run/DrtOptimizationConstraintsParams.java index f3f1e1ed5f2..5b1393bd7fb 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtOptimizationConstraintsParams.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtOptimizationConstraintsParams.java @@ -2,6 +2,7 @@ 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; @@ -11,8 +12,13 @@ */ public class DrtOptimizationConstraintsParams extends ReflectiveConfigGroup { - public final static String SET_NAME = "drtOptimizationConstraints"; + public static final String SET_NAME = "drtOptimizationConstraints"; + public static final String DEFAULT_PARAMS_NAME = "default"; + @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).") 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..78777108bd2 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,17 @@ public void testMaxDetourConstraint() { DrtConfigGroup drtConfigGroup = DrtConfigGroup.getSingleModeDrtConfig(config); // Max wait time - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = 300; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxDetourAlpha = 1.5; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxDetourBeta = 300; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxAllowedPickupDelay = 180; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 10; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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..00f14a225ee 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 @@ -225,9 +225,9 @@ 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; + x.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = maxWaitTime; + x.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = maxTravelTimeAlpha; + x.getDefaultDrtOptimizationConstraintsParam().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..a15ccbbdc2b 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.getDefaultDrtOptimizationConstraintsParam().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..3ae97d93604 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 @@ -226,9 +226,9 @@ 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; + modeConfig.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = maximumWaitTime; + modeConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = detourRelative; + modeConfig.getDefaultDrtOptimizationConstraintsParam().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..79baf22f08b 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 @@ -80,9 +80,9 @@ 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; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5 * 60; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 5 * 60; ImmutableMap, DrtStopFacility> drtStops = scenario.getTransitSchedule() .getFacilities() @@ -91,7 +91,8 @@ void testCottbusClosestAccessEgressStopFinder() { .map(DrtStopFacilityImpl::createFromFacility) .collect(ImmutableMap.toImmutableMap(DrtStopFacility::getId, f -> f)); - AccessEgressFacilityFinder stopFinder = new ClosestAccessEgressFacilityFinder(drtCfg.getDrtOptimizationConstraintsParam().maxWalkDistance, + AccessEgressFacilityFinder stopFinder = new ClosestAccessEgressFacilityFinder( + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWalkDistance, scenario.getNetwork(), QuadTrees.createQuadTree(drtStops.values())); DrtRouteCreator drtRouteCreator = new DrtRouteCreator(drtCfg, scenario.getNetwork(), new SpeedyDijkstraFactory(), new FreeSpeedTravelTime(), TimeAsTravelDisutility::new); @@ -259,7 +260,7 @@ void testRouteDescriptionHandling() { private Scenario createTestScenario() { Config config = ConfigUtils.createConfig(); DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWalkDistance = 200; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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/examples/RunDrtExampleIT.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/examples/RunDrtExampleIT.java index 6b15ba1bc9e..75f0556d2be 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,7 @@ void testRunDrtExampleWithNoRejections_ExtensiveSearch() { for (var drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; } config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); @@ -129,7 +129,7 @@ void testRunDrtExampleWithNoRejections_SelectiveSearch() { drtCfg.addParameterSet(selectiveInsertionSearchParams); //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; } config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); @@ -168,7 +168,7 @@ void testRunDrtExampleWithNoRejections_RepeatedSelectiveSearch() { drtCfg.addParameterSet(repeatedSelectiveInsertionSearchParams); //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.getDefaultDrtOptimizationConstraintsParam().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..bdf57656729 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,7 @@ void testRunDrtExampleWithNoRejections_ExtensiveSearch() { for (var drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { //disable rejections - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.getDefaultDrtOptimizationConstraintsParam().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..716135d2c76 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 @@ -46,7 +46,7 @@ void testTeleportationEngine() throws IOException { Controler controler = DrtControlerCreator.createControler(config, false); DrtConfigGroup drtConfigGroup = DrtConfigGroup.getSingleModeDrtConfig(config); - DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDrtOptimizationConstraintsParam(); + DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDefaultDrtOptimizationConstraintsParam(); constraintsParam.maxTravelTimeAlpha = 1.2; constraintsParam.maxTravelTimeBeta = 600; constraintsParam.maxWaitTime = 300; 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..d2330013b48 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 @@ -66,16 +66,16 @@ 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; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 3600; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 2; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 3600; + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxAbsoluteDetour = Double.MAX_VALUE; - drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtCfg.changeStartLinkToLastLinkInSchedule = taxiCfg.changeStartLinkToLastLinkInSchedule; drtCfg.idleVehiclesReturnToDepots = false; drtCfg.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtCfg.getDrtOptimizationConstraintsParam().maxWalkDistance = Double.MAX_VALUE; + drtCfg.getDefaultDrtOptimizationConstraintsParam().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..e6f7e5d08ba 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 @@ -229,11 +229,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 2.0; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 2.0; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; + drtConfigGroup + .getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); @@ -243,11 +244,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { if (drt2) { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = "drt2"; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; + drtConfigGroup + .getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); @@ -256,11 +258,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { if (drt3) { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = "drt3"; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; + drtConfigGroup + .getDefaultDrtOptimizationConstraintsParam().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..0a57b27bcde 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 @@ -110,10 +110,10 @@ 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; + drtConfig.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 900.; + drtConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; + drtConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.; + drtConfig.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfig.changeStartLinkToLastLinkInSchedule = true; multiModeDrtCfg.addParameterSet(drtConfig); } @@ -247,11 +247,11 @@ void testPtAlongALineWithRaptorAndDrtStopFilterAttribute() { MultiModeDrtConfigGroup mm = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); { DrtConfigGroup drtConfig = new DrtConfigGroup(); - drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + drtConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; + drtConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; drtConfig.stopDuration = 60.; - drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + drtConfig.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; + drtConfig.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfig.mode = TransportMode.drt; mm.addParameterSet(drtConfig); } From 07ba389d033dac2eb5b750f4fcfd0cf344d4fa1e Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Fri, 17 May 2024 09:19:22 +0200 Subject: [PATCH 2/4] Add test --- .../contrib/drt/run/DrtConfigGroupTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 contribs/drt/src/test/java/org/matsim/contrib/drt/run/DrtConfigGroupTest.java 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..66187a54683 --- /dev/null +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/run/DrtConfigGroupTest.java @@ -0,0 +1,54 @@ +package org.matsim.contrib.drt.run; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 + DrtOptimizationConstraintsParams params = drtConfig.getDefaultDrtOptimizationConstraintsParam(); + + Assertions.assertEquals(DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME, params.name); + Assertions.assertDoesNotThrow(() -> drtConfig.checkConsistency(config)); + } + + @Test + void testMultipleDrtOptimizationConstraintsParams() { + Config config = ConfigUtils.createConfig(); + DrtConfigGroup drtConfig = new DrtConfigGroup(); + config.addModule(drtConfig); + + // add second DrtOptimizationConstraintsParams + DrtOptimizationConstraintsParams params = new DrtOptimizationConstraintsParams(); + params.name = "test"; + drtConfig.addParameterSet(params); + + Assertions.assertEquals(2, drtConfig.getDrtOptimizationConstraintsParams().size()); + 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 + DrtOptimizationConstraintsParams params = new DrtOptimizationConstraintsParams(); + params.name = DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME; + drtConfig.addParameterSet(params); + + Assertions.assertEquals(2, drtConfig.getDrtOptimizationConstraintsParams().size()); + Assertions.assertThrows(VerifyException.class, () -> drtConfig.checkConsistency(config)); + } +} From 70eec346547414e021643f4741916f19e2138bfa Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Tue, 21 May 2024 11:14:44 +0200 Subject: [PATCH 3/4] Move optimization constraints params to optimizer package --- .../operations/eshifts/run/RunEShiftDrtScenarioIT.java | 2 +- .../operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java | 2 +- .../extension/operations/shifts/run/RunShiftDrtScenarioIT.java | 2 +- .../contrib/drt/estimator/impl/PessimisticDrtEstimator.java | 2 +- .../{run => optimizer}/DrtOptimizationConstraintsParams.java | 2 +- .../main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java | 1 + .../java/org/matsim/contrib/drt/run/DrtConfigGroupTest.java | 1 + .../matsim/contrib/drt/teleportation/DrtTeleportationTest.java | 2 +- 8 files changed, 8 insertions(+), 6 deletions(-) rename contribs/drt/src/main/java/org/matsim/contrib/drt/{run => optimizer}/DrtOptimizationConstraintsParams.java (99%) 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 b4648770172..65ba25204ac 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 @@ -13,7 +13,7 @@ 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.optimizer.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.ev.EvConfigGroup; 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 053211ec458..52267ba2d30 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 @@ -13,7 +13,7 @@ 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.optimizer.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams; 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 e9674eb0d29..1e10ce13f85 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 @@ -13,7 +13,7 @@ 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.optimizer.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams; diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/estimator/impl/PessimisticDrtEstimator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/estimator/impl/PessimisticDrtEstimator.java index 14642217c00..d720d2f7fef 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/estimator/impl/PessimisticDrtEstimator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/estimator/impl/PessimisticDrtEstimator.java @@ -3,7 +3,7 @@ import org.matsim.contrib.drt.estimator.DrtEstimator; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.DrtOptimizationConstraintsParams; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams; import org.matsim.core.utils.misc.OptionalTime; /** 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/DrtOptimizationConstraintsParams.java similarity index 99% 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/DrtOptimizationConstraintsParams.java index 5b1393bd7fb..b570931915f 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/DrtOptimizationConstraintsParams.java @@ -1,4 +1,4 @@ -package org.matsim.contrib.drt.run; +package org.matsim.contrib.drt.optimizer; import com.google.common.base.Verify; import jakarta.validation.constraints.DecimalMin; 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 f8fa7690a0b..bcef924dac0 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 @@ -32,6 +32,7 @@ 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.DrtRequestInsertionRetryParams; import org.matsim.contrib.drt.optimizer.insertion.DrtInsertionSearchParams; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; 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 index 66187a54683..626d6314f8e 100644 --- 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 @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; 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 716135d2c76..db4551d0564 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 @@ -12,7 +12,7 @@ import org.matsim.contrib.drt.fare.DrtFareParams; 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.optimizer.DrtOptimizationConstraintsParams; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.core.config.Config; From 12ca6a51decd0ba654cd8d3697a6cff5327daaa3 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Tue, 21 May 2024 15:45:17 +0200 Subject: [PATCH 4/4] add middleman for drt optimization constraints --- .../examples/RunJointDemandDRTExample.java | 8 +- .../edrt/run/EDrtModeOptimizerQSimModule.java | 13 +- .../extension/fiss/RunFissDrtScenarioIT.java | 12 +- .../eshifts/run/RunEShiftDrtScenarioIT.java | 14 +- .../run/RunMultiHubShiftDrtScenarioIT.java | 14 +- .../shifts/run/RunShiftDrtScenarioIT.java | 43 +++--- .../DrtAnalysisControlerListener.java | 12 +- .../impl/PessimisticDrtEstimator.java | 4 +- .../optimizer/DrtModeOptimizerQSimModule.java | 5 +- .../DrtOptimizationConstraintsParams.java | 132 ++++++++---------- .../DrtOptimizationConstraintsSet.java | 99 +++++++++++++ .../contrib/drt/routing/DrtRouteCreator.java | 15 +- .../contrib/drt/run/DrtConfigGroup.java | 55 +++----- .../contrib/drt/run/DrtModeRoutingModule.java | 2 +- .../optimizer/MaxDetourConstraintTest.java | 15 +- .../insertion/DrtPoolingParameterTest.java | 8 +- .../prebooking/ComplexUnschedulerTest.java | 2 +- .../prebooking/PrebookingTestEnvironment.java | 8 +- .../drt/routing/DrtRoutingModuleTest.java | 12 +- .../contrib/drt/run/DrtConfigGroupTest.java | 36 +++-- .../drt/run/examples/RunDrtExampleIT.java | 12 +- .../RunOldDrtConfigCompatibilityIT.java | 4 +- .../teleportation/DrtTeleportationTest.java | 14 +- .../contrib/taxi/run/MultiModeTaxiModule.java | 14 +- .../drtAndPt/PtAlongALine2Test.java | 31 ++-- .../drtAndPt/PtAlongALineTest.java | 20 +-- 26 files changed, 355 insertions(+), 249 deletions(-) create mode 100644 contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsSet.java 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 4888f4fc1c7..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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 2 * 3600; - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 5; - drtCfg.getDefaultDrtOptimizationConstraintsParam().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 2ddc571d467..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,8 +141,9 @@ public EmptyVehicleChargingScheduler get() { bindModal(VehicleEntry.EntryFactory.class).toProvider( EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider.class).asEagerSingleton(); + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); bindModal(CostCalculationStrategy.class) - .to(drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated + .to(defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated ? CostCalculationStrategy.RejectSoftConstraintViolations.class : CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton(); @@ -182,7 +177,7 @@ public EmptyVehicleRelocator get() { .asEagerSingleton(); bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor( - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxAllowedPickupDelay))); + 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 2e464f161a7..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.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.; drtConfigGroup.stopDuration = 30.; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 600.; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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.getDefaultDrtOptimizationConstraintsParam().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 65ba25204ac..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.optimizer.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.getDefaultDrtOptimizationConstraintsParam(); - 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 52267ba2d30..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.optimizer.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.getDefaultDrtOptimizationConstraintsParam(); - 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 1e10ce13f85..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.optimizer.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.getDefaultDrtOptimizationConstraintsParam(); - 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 8cb77352196..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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime)); + times, Pair.of(0., drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().maxWaitTime)); // xAxis.setLowerBound(0); // yAxis.setLowerBound(0); ChartUtils.writeChartAsPNG(new FileOutputStream(plotFileName), chart2, 1500, 1500); @@ -663,14 +664,15 @@ private static void analyseDetours(Network network, List legs, Map new DefaultOfferAcceptor( - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxAllowedPickupDelay))); + 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 index b570931915f..9f517b8b862 100644 --- 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 @@ -1,91 +1,21 @@ 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; +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 final String DEFAULT_PARAMS_NAME = "default"; - - @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).") - @PositiveOrZero - public double maxWaitTime = Double.NaN;// seconds - - @Parameter - @Comment("Defines the slope of the maxTravelTime estimation function (optimisation constraint), i.e. " - + "min(unsharedRideTime + maxAbsoluteDetour, maxTravelTimeAlpha * unsharedRideTime + maxTravelTimeBeta). " - + "Alpha should not be smaller than 1.") - @DecimalMin("1.0") - public double maxTravelTimeAlpha = Double.NaN;// [-] - - @Parameter - @Comment("Defines the shift of the maxTravelTime estimation function (optimisation constraint), i.e. " - + "min(unsharedRideTime + maxAbsoluteDetour, maxTravelTimeAlpha * unsharedRideTime + maxTravelTimeBeta). " - + "Beta should not be smaller than 0.") - @PositiveOrZero - public double maxTravelTimeBeta = Double.NaN;// [s] - - @Parameter - @Comment( - "Defines the maximum allowed absolute detour in seconds. Note that the detour is computed from the latest promised pickup time. " + - "To enable the max detour constraint, maxAllowedPickupDelay has to be specified. maxAbsoluteDetour should not be smaller than 0, " - + "and should be higher than the offset maxDetourBeta. By default, this limit is disabled (i.e. set to Inf)") - @PositiveOrZero - public double maxAbsoluteDetour = Double.POSITIVE_INFINITY;// [s] - - @Parameter - @Comment( - "Defines the maximum allowed absolute detour based on the unsharedRideTime. Note that the detour is computed from the latest promised " - + "pickup time. To enable the max detour constraint, maxAllowedPickupDelay has to be specified. A linear combination similar to travel " - + "time constrain is used. This is the ratio part. By default, this limit is disabled (i.e. set to Inf, together with maxDetourBeta).") - @DecimalMin("1.0") - public double maxDetourAlpha = Double.POSITIVE_INFINITY; - - @Parameter - @Comment( - "Defines the maximum allowed absolute detour based on the unsharedRideTime. Note that the detour is computed from the latest promised " - + "pickup time. To enable the max detour constraint, maxAllowedPickupDelay has to be specified. A linear combination similar to travel " - + "time constrain is used. This is the constant part. By default, this limit is disabled (i.e. set to Inf, together with maxDetourAlpha).") - @PositiveOrZero - public double maxDetourBeta = Double.POSITIVE_INFINITY;// [s] - - @Parameter - @Comment( - "Defines the maximum delay allowed from the initial scheduled pick up time. Once the initial pickup time is offered, the latest promised" - + "pickup time is calculated based on initial scheduled pickup time + maxAllowedPickupDelay. " - + "By default, this limit is disabled. If enabled, a value between 0 and 240 is a good choice.") - @PositiveOrZero - public double maxAllowedPickupDelay = Double.POSITIVE_INFINITY;// [s] - @Parameter - @Comment("If true, the max travel and wait times of a submitted request" - + " are considered hard constraints (the request gets rejected if one of the constraints is violated)." - + " If false, the max travel and wait times are considered soft constraints (insertion of a request that" - + " violates one of the constraints is allowed, but its cost is increased by additional penalty to make" - + " it relatively less attractive). Penalisation of insertions can be customised by injecting a customised" - + " InsertionCostCalculator.PenaltyCalculator") - public boolean rejectRequestIfMaxWaitOrTravelTimeViolated = true;//TODO consider renaming maxWalkDistance to max access/egress distance (or even have 2 separate params) + public static String defaultConstraintSet = DrtOptimizationConstraintsSet.DEFAULT_PARAMS_NAME; - @Parameter - @Comment( - "Maximum beeline distance (in meters) to next stop location in stopbased system for access/egress walk leg to/from drt." - + " If no stop can be found within this maximum distance will return null (in most cases caught by fallback routing module).") - @PositiveOrZero // used only for stopbased DRT scheme - public double maxWalkDistance = Double.MAX_VALUE;// [m]; public DrtOptimizationConstraintsParams() { super(SET_NAME); @@ -94,9 +24,57 @@ public DrtOptimizationConstraintsParams() { @Override protected void checkConsistency(Config config) { super.checkConsistency(config); - if ((maxDetourAlpha != Double.POSITIVE_INFINITY && maxDetourBeta != Double.POSITIVE_INFINITY) || maxAbsoluteDetour != Double.POSITIVE_INFINITY) { - Verify.verify(maxAllowedPickupDelay != Double.POSITIVE_INFINITY, "Detour constraints are activated, " + - "maxAllowedPickupDelay must be specified! A value between 0 and 240 seconds can be a good choice for maxAllowedPickupDelay."); + 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/optimizer/DrtOptimizationConstraintsSet.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsSet.java new file mode 100644 index 00000000000..d80bc047b4e --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtOptimizationConstraintsSet.java @@ -0,0 +1,99 @@ +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; + +public class DrtOptimizationConstraintsSet extends ReflectiveConfigGroup { + + 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).") + @PositiveOrZero + public double maxWaitTime = Double.NaN;// seconds + + @Parameter + @Comment("Defines the slope of the maxTravelTime estimation function (optimisation constraint), i.e. " + + "min(unsharedRideTime + maxAbsoluteDetour, maxTravelTimeAlpha * unsharedRideTime + maxTravelTimeBeta). " + + "Alpha should not be smaller than 1.") + @DecimalMin("1.0") + public double maxTravelTimeAlpha = Double.NaN;// [-] + + @Parameter + @Comment("Defines the shift of the maxTravelTime estimation function (optimisation constraint), i.e. " + + "min(unsharedRideTime + maxAbsoluteDetour, maxTravelTimeAlpha * unsharedRideTime + maxTravelTimeBeta). " + + "Beta should not be smaller than 0.") + @PositiveOrZero + public double maxTravelTimeBeta = Double.NaN;// [s] + + @Parameter + @Comment( + "Defines the maximum allowed absolute detour in seconds. Note that the detour is computed from the latest promised pickup time. " + + "To enable the max detour constraint, maxAllowedPickupDelay has to be specified. maxAbsoluteDetour should not be smaller than 0, " + + "and should be higher than the offset maxDetourBeta. By default, this limit is disabled (i.e. set to Inf)") + @PositiveOrZero + public double maxAbsoluteDetour = Double.POSITIVE_INFINITY;// [s] + + @Parameter + @Comment( + "Defines the maximum allowed absolute detour based on the unsharedRideTime. Note that the detour is computed from the latest promised " + + "pickup time. To enable the max detour constraint, maxAllowedPickupDelay has to be specified. A linear combination similar to travel " + + "time constrain is used. This is the ratio part. By default, this limit is disabled (i.e. set to Inf, together with maxDetourBeta).") + @DecimalMin("1.0") + public double maxDetourAlpha = Double.POSITIVE_INFINITY; + + @Parameter + @Comment( + "Defines the maximum allowed absolute detour based on the unsharedRideTime. Note that the detour is computed from the latest promised " + + "pickup time. To enable the max detour constraint, maxAllowedPickupDelay has to be specified. A linear combination similar to travel " + + "time constrain is used. This is the constant part. By default, this limit is disabled (i.e. set to Inf, together with maxDetourAlpha).") + @PositiveOrZero + public double maxDetourBeta = Double.POSITIVE_INFINITY;// [s] + + @Parameter + @Comment( + "Defines the maximum delay allowed from the initial scheduled pick up time. Once the initial pickup time is offered, the latest promised" + + "pickup time is calculated based on initial scheduled pickup time + maxAllowedPickupDelay. " + + "By default, this limit is disabled. If enabled, a value between 0 and 240 is a good choice.") + @PositiveOrZero + public double maxAllowedPickupDelay = Double.POSITIVE_INFINITY;// [s] + + @Parameter + @Comment("If true, the max travel and wait times of a submitted request" + + " are considered hard constraints (the request gets rejected if one of the constraints is violated)." + + " If false, the max travel and wait times are considered soft constraints (insertion of a request that" + + " violates one of the constraints is allowed, but its cost is increased by additional penalty to make" + + " it relatively less attractive). Penalisation of insertions can be customised by injecting a customised" + + " InsertionCostCalculator.PenaltyCalculator") + public boolean rejectRequestIfMaxWaitOrTravelTimeViolated = true;//TODO consider renaming maxWalkDistance to max access/egress distance (or even have 2 separate params) + + @Parameter + @Comment( + "Maximum beeline distance (in meters) to next stop location in stopbased system for access/egress walk leg to/from drt." + + " If no stop can be found within this maximum distance will return null (in most cases caught by fallback routing module).") + @PositiveOrZero // used only for stopbased DRT scheme + public double maxWalkDistance = Double.MAX_VALUE;// [m]; + + @Override + protected void checkConsistency(Config config) { + super.checkConsistency(config); + if ((maxDetourAlpha != Double.POSITIVE_INFINITY && maxDetourBeta != Double.POSITIVE_INFINITY) || maxAbsoluteDetour != Double.POSITIVE_INFINITY) { + Verify.verify(maxAllowedPickupDelay != Double.POSITIVE_INFINITY, "Detour constraints are activated, " + + "maxAllowedPickupDelay must be specified! A value between 0 and 240 seconds can be a good choice for maxAllowedPickupDelay."); + } + } +} 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 12c757f1ea0..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,8 +62,9 @@ public DrtRouteCreator(DrtConfigGroup drtCfg, Network modalNetwork, * @return maximum travel time */ static double getMaxTravelTime(DrtConfigGroup drtCfg, double unsharedRideTime) { - return drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha * unsharedRideTime - + drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + return defaultConstraintsSet.maxTravelTimeAlpha * unsharedRideTime + + defaultConstraintsSet.maxTravelTimeBeta; } /** @@ -73,9 +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.getDefaultDrtOptimizationConstraintsParam().maxAbsoluteDetour, - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxDetourAlpha * unsharedRideTime - + drtCfg.getDefaultDrtOptimizationConstraintsParam().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, @@ -92,7 +95,7 @@ public Route createRoute(double departureTime, Link accessActLink, Link egressAc route.setTravelTime(maxTravelTime); route.setMaxRideTime(maxRideDuration); route.setDirectRideTime(unsharedRideTime); - route.setMaxWaitTime(drtCfg.getDefaultDrtOptimizationConstraintsParam().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 bcef924dac0..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 @@ -33,6 +33,7 @@ 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; @@ -160,6 +161,9 @@ public enum SimulationType { @NotNull private DrtInsertionSearchParams drtInsertionSearchParams; + @NotNull + private DrtOptimizationConstraintsParams drtOptimizationConstraintsParams; + @Nullable private DrtZoneSystemParams zonalSystemParams; @@ -187,8 +191,11 @@ public DrtConfigGroup() { } private void initSingletonParameterSets() { - //drt optimization constraints - getDefaultDrtOptimizationConstraintsParam(); + + //optimization constraints (mandatory) + addDefinition(DrtOptimizationConstraintsParams.SET_NAME, DrtOptimizationConstraintsParams::new, + () -> 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": - getDefaultDrtOptimizationConstraintsParam().addParam(paramName, value); + addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().addParam(paramName, value); break; default: super.handleAddUnknownParam(paramName, value); @@ -269,9 +275,9 @@ protected void checkConsistency(Config config) { + "attempting to travel without vehicles being available."); } - List drtOptimizationConstraintsParams = getDrtOptimizationConstraintsParams(); - for (DrtOptimizationConstraintsParams params : drtOptimizationConstraintsParams) { - Verify.verify(params.maxWaitTime >= stopDuration, + List drtOptimizationConstraintsSets = addOrGetDrtOptimizationConstraintsParams().getDrtOptimizationConstraintsSets(); + for (DrtOptimizationConstraintsSet constraintsSet : drtOptimizationConstraintsSets) { + Verify.verify(constraintsSet.maxWaitTime >= stopDuration, "maxWaitTime must not be smaller than stopDuration"); } @@ -306,17 +312,6 @@ protected void checkConsistency(Config config) { Verify.verify(drtSpeedUpParams == null, "Simulation type is estimateAndTeleport, but drtSpeedUpParams is set. " + "Please remove drtSpeedUpParams from the config, as these two functionalities are not compatible."); } - - Verify.verify(!drtOptimizationConstraintsParams.isEmpty(), - "At least one DrtOptimizationConstraintsParams is required."); - Verify.verify(drtOptimizationConstraintsParams.stream() - .anyMatch(params -> DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME.equals(params.name)), - "Default DrtOptimizationConstraintsParams is required."); - Verify.verify(drtOptimizationConstraintsParams.stream() - .map(params -> params.name) - .distinct() - .count() == drtOptimizationConstraintsParams.size(), - "Cannot have DrtOptimizationConstraintsParams with identical names."); } @Override @@ -324,29 +319,19 @@ public String getMode() { return mode; } - public List getDrtOptimizationConstraintsParams() { - return getParameterSets(DrtOptimizationConstraintsParams.SET_NAME).stream() - .filter(DrtOptimizationConstraintsParams.class::isInstance) - .map(DrtOptimizationConstraintsParams.class::cast) - .toList(); - } - public DrtOptimizationConstraintsParams getDefaultDrtOptimizationConstraintsParam() { - Optional drtOptParams = getDrtOptimizationConstraintsParams().stream() - .filter(params -> DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME.equals(params.name)) - .findAny(); - if (drtOptParams.isEmpty()) { - addParameterSet(new DrtOptimizationConstraintsParams()); - } - return getDrtOptimizationConstraintsParams().stream() - .filter(params -> DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME.equals(params.name)) - .findAny().orElseThrow(); - } 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 c57ae9c9eda..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 @@ -105,7 +105,7 @@ public void install() { case stopbased, serviceAreaBased -> { bindModal( AccessEgressFacilityFinder.class ).toProvider( modalProvider( getter -> new ClosestAccessEgressFacilityFinder( - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWalkDistance, + 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 78777108bd2..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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 300; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = 300; // Turn on the max detour constraint - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxDetourAlpha = 1.5; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxDetourBeta = 300; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxAllowedPickupDelay = 180; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 10; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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 00f14a225ee..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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = maxWaitTime; - x.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = maxTravelTimeAlpha; - x.getDefaultDrtOptimizationConstraintsParam().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 a15ccbbdc2b..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.getDefaultDrtOptimizationConstraintsParam().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 3ae97d93604..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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = maximumWaitTime; - modeConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = detourRelative; - modeConfig.getDefaultDrtOptimizationConstraintsParam().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 79baf22f08b..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.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5; - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5 * 60; - drtCfg.getDefaultDrtOptimizationConstraintsParam().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() @@ -92,7 +94,7 @@ void testCottbusClosestAccessEgressStopFinder() { .collect(ImmutableMap.toImmutableMap(DrtStopFacility::getId, f -> f)); AccessEgressFacilityFinder stopFinder = new ClosestAccessEgressFacilityFinder( - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWalkDistance, + defaultConstraintsSet.maxWalkDistance, scenario.getNetwork(), QuadTrees.createQuadTree(drtStops.values())); DrtRouteCreator drtRouteCreator = new DrtRouteCreator(drtCfg, scenario.getNetwork(), new SpeedyDijkstraFactory(), new FreeSpeedTravelTime(), TimeAsTravelDisutility::new); @@ -260,7 +262,7 @@ void testRouteDescriptionHandling() { private Scenario createTestScenario() { Config config = ConfigUtils.createConfig(); DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().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 index 626d6314f8e..ae9cd5c3f21 100644 --- 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 @@ -3,6 +3,7 @@ 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; @@ -17,9 +18,12 @@ void testHasDefaultDrtOptimizationConstraintsParam() { config.addModule(drtConfig); // get DrtOptimizationConstraintsParams - DrtOptimizationConstraintsParams params = drtConfig.getDefaultDrtOptimizationConstraintsParam(); + DrtOptimizationConstraintsSet params = drtConfig.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); - Assertions.assertEquals(DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME, params.name); + 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)); } @@ -30,11 +34,22 @@ void testMultipleDrtOptimizationConstraintsParams() { config.addModule(drtConfig); // add second DrtOptimizationConstraintsParams - DrtOptimizationConstraintsParams params = new DrtOptimizationConstraintsParams(); + DrtOptimizationConstraintsSet params = new DrtOptimizationConstraintsSet(); params.name = "test"; - drtConfig.addParameterSet(params); - Assertions.assertEquals(2, drtConfig.getDrtOptimizationConstraintsParams().size()); + 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)); } @@ -45,11 +60,14 @@ void testNoDuplicateDrtDrtOptimizationConstraintsParams() { config.addModule(drtConfig); // add second DrtOptimizationConstraintsParams with same name - DrtOptimizationConstraintsParams params = new DrtOptimizationConstraintsParams(); - params.name = DrtOptimizationConstraintsParams.DEFAULT_PARAMS_NAME; - drtConfig.addParameterSet(params); + DrtOptimizationConstraintsSet params = new DrtOptimizationConstraintsSet(); + params.name = DrtOptimizationConstraintsSet.DEFAULT_PARAMS_NAME; + + DrtOptimizationConstraintsParams optimizationConstraintsParams = drtConfig.addOrGetDrtOptimizationConstraintsParams(); + optimizationConstraintsParams.addOrGetDefaultDrtOptimizationConstraintsSet(); + optimizationConstraintsParams.addParameterSet(params); - Assertions.assertEquals(2, drtConfig.getDrtOptimizationConstraintsParams().size()); + 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 75f0556d2be..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.getDefaultDrtOptimizationConstraintsParam().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.getDefaultDrtOptimizationConstraintsParam().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.getDefaultDrtOptimizationConstraintsParam().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 bdf57656729..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.getDefaultDrtOptimizationConstraintsParam().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 db4551d0564..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.optimizer.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.getDefaultDrtOptimizationConstraintsParam(); - 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/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 d2330013b48..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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 3600; - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 2; - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 3600; - drtCfg.getDefaultDrtOptimizationConstraintsParam().maxAbsoluteDetour = Double.MAX_VALUE; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxWaitTime = 3600; + defaultConstraintsSet.maxTravelTimeAlpha = 2; + defaultConstraintsSet.maxTravelTimeBeta = 3600; + defaultConstraintsSet.maxAbsoluteDetour = Double.MAX_VALUE; - drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtCfg.changeStartLinkToLastLinkInSchedule = taxiCfg.changeStartLinkToLastLinkInSchedule; drtCfg.idleVehiclesReturnToDepots = false; drtCfg.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtCfg.getDefaultDrtOptimizationConstraintsParam().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 e6f7e5d08ba..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,12 +230,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 2.0; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 2.0; + defaultConstraintsSet.maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup - .getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + defaultConstraintsSet.maxWaitTime = Double.MAX_VALUE; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); @@ -244,12 +245,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { if (drt2) { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = "drt2"; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.3; + defaultConstraintsSet.maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup - .getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = false; + defaultConstraintsSet.maxWaitTime = Double.MAX_VALUE; + defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); @@ -258,12 +259,12 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { if (drt3) { DrtConfigGroup drtConfigGroup = new DrtConfigGroup(); drtConfigGroup.mode = "drt3"; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; + DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); + defaultConstraintsSet.maxTravelTimeAlpha = 1.3; + defaultConstraintsSet.maxTravelTimeBeta = 5. * 60.; drtConfigGroup.stopDuration = 60.; - drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfigGroup - .getDefaultDrtOptimizationConstraintsParam().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 0a57b27bcde..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.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 900.; - drtConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.; - drtConfig.getDefaultDrtOptimizationConstraintsParam().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.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; - drtConfig.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 5. * 60.; drtConfig.stopDuration = 60.; - drtConfig.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = Double.MAX_VALUE; - drtConfig.getDefaultDrtOptimizationConstraintsParam().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); }