From 883ad57756edde2b0232df4d7c480993aa52c367 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Mon, 2 Dec 2024 21:47:12 +0100 Subject: [PATCH 1/2] DRT: add minimum allowed detour, remove misleading consistency check/comments --- .../DefaultDrtOptimizationConstraintsSet.java | 24 +++++++------------ .../DefaultDrtRouteConstraintsCalculator.java | 13 ++++++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java index 3ba0a7ce169..6748210fe39 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java @@ -1,9 +1,7 @@ package org.matsim.contrib.drt.optimizer.constraints; -import com.google.common.base.Verify; import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.PositiveOrZero; -import org.matsim.core.config.Config; public class DefaultDrtOptimizationConstraintsSet extends DrtOptimizationConstraintsSet { @@ -23,34 +21,28 @@ public class DefaultDrtOptimizationConstraintsSet extends DrtOptimizationConstra @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, " + "Defines the maximum allowed absolute detour in seconds. 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 " + "Defines the maximum allowed absolute detour based on the unsharedRideTime. 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 " + "Defines the maximum allowed absolute detour based on the unsharedRideTime. 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] - @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."); - } - } + @Parameter + @Comment( + "Defines the minimum allowed absolute detour in seconds. By default, this bound is disabled (i.e. set to 0.)") + @PositiveOrZero + public double minimumAllowedDetour = 0; } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java index f8e1f9b36eb..cfcaaa3e5c8 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java @@ -25,9 +25,12 @@ public DefaultDrtRouteConstraintsCalculator(DrtConfigGroup drtCfg, ConstraintSet /** * Calculates the maximum travel time defined as: drtCfg.getMaxTravelTimeAlpha() * unsharedRideTime + drtCfg.getMaxTravelTimeBeta() - * - * Calculates the maximum ride time defined as: drtCfg.maxDetourAlpha * - * unsharedRideTime + drtCfg.maxDetourBeta + * + * Calculates the maximum ride time defined as: + * unsharedRideTime + min( + * maxAbsoluteDetour, + * max(minimumAllowedDetour, unsharedRideTime * (1-drtCfg.maxDetourAlpha) + drtCfg.maxDetourBeta) + * ) * * @return DrtRouteConstraints constraints */ @@ -40,8 +43,8 @@ public DrtRouteConstraints calculateRouteConstraints(double departureTime, Link if (constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) { double maxTravelTime = defaultSet.maxTravelTimeAlpha * unsharedRideTime + defaultSet.maxTravelTimeBeta; - double maxRideTime = Math.min(unsharedRideTime + defaultSet.maxAbsoluteDetour, - defaultSet.maxDetourAlpha * unsharedRideTime + defaultSet.maxDetourBeta); + double maxDetour = Math.max(defaultSet.minimumAllowedDetour, unsharedRideTime * (defaultSet.maxDetourAlpha -1) + defaultSet.maxDetourBeta); + double maxRideTime = unsharedRideTime + Math.min(defaultSet.maxAbsoluteDetour, maxDetour); double maxWaitTime = constraintsSet.maxWaitTime; return new DrtRouteConstraints(maxTravelTime, maxRideTime, maxWaitTime); From 8aa7e7f7581c3efe54f75b767b53d38a657c5640 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Mon, 2 Dec 2024 22:31:38 +0100 Subject: [PATCH 2/2] add consistency check for minimum/maximum allowed detour --- .../DefaultDrtOptimizationConstraintsSet.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java index 6748210fe39..fd26a90256a 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DefaultDrtOptimizationConstraintsSet.java @@ -1,7 +1,9 @@ package org.matsim.contrib.drt.optimizer.constraints; +import com.google.common.base.Verify; import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.PositiveOrZero; +import org.matsim.core.config.Config; public class DefaultDrtOptimizationConstraintsSet extends DrtOptimizationConstraintsSet { @@ -45,4 +47,11 @@ public class DefaultDrtOptimizationConstraintsSet extends DrtOptimizationConstra "Defines the minimum allowed absolute detour in seconds. By default, this bound is disabled (i.e. set to 0.)") @PositiveOrZero public double minimumAllowedDetour = 0; + + @Override + protected void checkConsistency(Config config) { + super.checkConsistency(config); + Verify.verify(maxAbsoluteDetour > minimumAllowedDetour, "The minimum allowed detour must" + + "be lower than the maximum allowed detour."); + } }