From fe2a42919ea2631b7e5bb6807eee7136f626d6e3 Mon Sep 17 00:00:00 2001 From: Chengqi Lu <43133404+luchengqi7@users.noreply.github.com> Date: Sat, 30 Dec 2023 10:27:29 +0800 Subject: [PATCH] Consolidate two classes PromisedPickupTimeWindowDrtOfferAcceptor -> MaxDetourOfferAcceptor MaxDetourInsertionCostCalculator -> DefaultInsertionCostCalculator --- .../insertion/DefaultInsertionCostCalculator.java | 14 +++++++++++++- .../MaxDetourInsertionCostCalculator.java | 3 +++ .../PromisedPickupTimeWindowDrtOfferAcceptor.java | 2 ++ .../drt/optimizer/MaxDetourConstraintTest.java | 4 ++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/DefaultInsertionCostCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/DefaultInsertionCostCalculator.java index 1b16c140d50..139d5262b12 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/DefaultInsertionCostCalculator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/DefaultInsertionCostCalculator.java @@ -48,6 +48,12 @@ public DefaultInsertionCostCalculator(CostCalculationStrategy costCalculationStr */ @Override public double calculate(DrtRequest drtRequest, Insertion insertion, DetourTimeInfo detourTimeInfo) { + // check if the max riding time constraints is violated (with default config, the max ride duration + // is infinity) + if (violatesMaxRideDuration(drtRequest, detourTimeInfo)) { + return INFEASIBLE_SOLUTION_COST; + } + var vEntry = insertion.vehicleEntry; // in case of prebooking, we may have intermediate stay times after pickup @@ -55,7 +61,7 @@ public double calculate(DrtRequest drtRequest, Insertion insertion, DetourTimeIn // dropoff insertion point double effectiveDropoffTimeLoss = InsertionDetourTimeCalculator.calculateRemainingPickupTimeLossAtDropoff( insertion, detourTimeInfo.pickupDetourInfo) + detourTimeInfo.dropoffDetourInfo.dropoffTimeLoss; - + if (vEntry.getSlackTime(insertion.pickup.index) < detourTimeInfo.pickupDetourInfo.pickupTimeLoss || vEntry.getSlackTime(insertion.dropoff.index) < effectiveDropoffTimeLoss) { return INFEASIBLE_SOLUTION_COST; @@ -63,4 +69,10 @@ public double calculate(DrtRequest drtRequest, Insertion insertion, DetourTimeIn return costCalculationStrategy.calcCost(drtRequest, insertion, detourTimeInfo); } + + private boolean violatesMaxRideDuration(DrtRequest drtRequest, InsertionDetourTimeCalculator.DetourTimeInfo detourTimeInfo) { + // Check if the max travel time constraint for the newly inserted request is violated + double rideDuration = detourTimeInfo.dropoffDetourInfo.arrivalTime - detourTimeInfo.pickupDetourInfo.departureTime; + return drtRequest.getMaxRideDuration() < rideDuration; + } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/MaxDetourInsertionCostCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/MaxDetourInsertionCostCalculator.java index 5d2dc57e189..e8bedc9282d 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/MaxDetourInsertionCostCalculator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/MaxDetourInsertionCostCalculator.java @@ -5,7 +5,10 @@ /** * This insertion cost calculator performs additional check on the maximum ride duration, on top of the original InsertionCostCalculator * @author: Nico Kühnel (nkuehnel), Chengqi Lu (luchengqi7) + * + * The function is now implemented in the DefaultInsertionCostCalculator * */ +@Deprecated public class MaxDetourInsertionCostCalculator implements InsertionCostCalculator { private final InsertionCostCalculator delegate; diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/PromisedPickupTimeWindowDrtOfferAcceptor.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/PromisedPickupTimeWindowDrtOfferAcceptor.java index 78e8e34bfe1..90732eb0b74 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/PromisedPickupTimeWindowDrtOfferAcceptor.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/PromisedPickupTimeWindowDrtOfferAcceptor.java @@ -4,7 +4,9 @@ /** * @author nkuehnel / MOIA + * The function is now realized by the MaxDetourOfferAcceptor -Chengqi (luchengqi7) */ +@Deprecated public final class PromisedPickupTimeWindowDrtOfferAcceptor implements DrtOfferAcceptor { private final double promisedPickupTimeWindow; 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 6648bf65466..58251c6af0e 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 @@ -56,8 +56,8 @@ public void testMaxDetourConstraint() { controler.addOverridingQSimModule(new AbstractDvrpModeQSimModule(drtCfg.mode) { @Override protected void configureQSim() { - bindModal(InsertionCostCalculator.class).toProvider(modalProvider( - getter -> new MaxDetourInsertionCostCalculator((new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class)))))); +// bindModal(InsertionCostCalculator.class).toProvider(modalProvider( +// getter -> new MaxDetourInsertionCostCalculator((new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class)))))); bindModal(DrtOfferAcceptor.class).toProvider(modalProvider(getter -> new MaxDetourOfferAcceptor(drtCfg.maxAllowedPickupDelay))); } });