Skip to content

Commit

Permalink
Consolidate two classes
Browse files Browse the repository at this point in the history
PromisedPickupTimeWindowDrtOfferAcceptor -> MaxDetourOfferAcceptor

MaxDetourInsertionCostCalculator -> DefaultInsertionCostCalculator
  • Loading branch information
luchengqi7 committed Dec 30, 2023
1 parent da6308b commit fe2a429
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,31 @@ 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
// insertion that may reduce the effective pickup delay that remains that the
// 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;
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
});
Expand Down

0 comments on commit fe2a429

Please sign in to comment.