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); }