-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DRT detour constraints (based on PR #2834) #2997
Changes from 1 commit
1b402e1
091e97e
da6308b
fe2a429
5c9a46e
529acd9
2e48c44
550a85c
4107e7e
144d77a
d69429b
dc0fe55
9f252bf
2f66229
65d6b46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.matsim.contrib.drt.optimizer.insertion; | ||
|
||
import org.matsim.contrib.drt.passenger.DrtRequest; | ||
|
||
/** | ||
* 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) | ||
* */ | ||
public class MaxDetourInsertionCostCalculator implements InsertionCostCalculator { | ||
private final InsertionCostCalculator delegate; | ||
|
||
public MaxDetourInsertionCostCalculator(InsertionCostCalculator delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public double calculate(DrtRequest drtRequest, InsertionGenerator.Insertion insertion, InsertionDetourTimeCalculator.DetourTimeInfo detourTimeInfo) { | ||
if (violatesDetour(drtRequest, detourTimeInfo)) { | ||
return INFEASIBLE_SOLUTION_COST; | ||
} | ||
return delegate.calculate(drtRequest, insertion, detourTimeInfo); | ||
} | ||
|
||
private boolean violatesDetour(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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.matsim.contrib.drt.passenger; | ||
|
||
import java.util.Optional; | ||
|
||
public class MaxDetourOfferAcceptor implements DrtOfferAcceptor{ | ||
private final double promisedPickupTimeWindow; | ||
|
||
public MaxDetourOfferAcceptor(double promisedPickupTimeWindow) { | ||
this.promisedPickupTimeWindow = promisedPickupTimeWindow; | ||
} | ||
|
||
@Override | ||
public Optional<AcceptedDrtRequest> acceptDrtOffer(DrtRequest request, double departureTime, double arrivalTime) { | ||
double updatedPickupTimeWindow = Math.min(departureTime | ||
+ promisedPickupTimeWindow, request.getLatestStartTime()); | ||
return Optional.of(AcceptedDrtRequest | ||
.newBuilder() | ||
.request(request) | ||
.earliestStartTime(request.getEarliestStartTime()) | ||
.latestArrivalTime(Math.min(updatedPickupTimeWindow + request.getMaxRideDuration(), request.getLatestArrivalTime())) | ||
.latestStartTime(updatedPickupTimeWindow).build()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,17 +65,30 @@ static double getMaxTravelTime(DrtConfigGroup drtCfg, double unsharedRideTime) { | |
drtCfg.maxTravelTimeAlpha * unsharedRideTime + drtCfg.maxTravelTimeBeta); | ||
} | ||
|
||
/** | ||
* Calculates the maximum ride time defined as: drtCfg.maxDetourAlpha * unsharedRideTime + drtCfg.maxDetourBeta | ||
* | ||
* @param drtCfg | ||
* @param unsharedRideTime ride time of the direct (shortest-time) route | ||
* @return maximum ride time | ||
*/ | ||
static double getMaxRideTime(DrtConfigGroup drtCfg, double unsharedRideTime) { | ||
return Math.min(unsharedRideTime + drtCfg.maxAbsoluteDetour, drtCfg.maxDetourAlpha * unsharedRideTime + drtCfg.maxDetourBeta); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if we should use Imposing this constraint on |
||
} | ||
|
||
public Route createRoute(double departureTime, Link accessActLink, Link egressActLink, Person person, | ||
Attributes tripAttributes, RouteFactories routeFactories) { | ||
VrpPathWithTravelData unsharedPath = VrpPaths.calcAndCreatePath(accessActLink, egressActLink, departureTime, | ||
router, travelTime); | ||
double unsharedRideTime = unsharedPath.getTravelTime();//includes first & last link | ||
double maxTravelTime = getMaxTravelTime(drtCfg, unsharedRideTime); | ||
double maxRideDuration = getMaxRideTime(drtCfg, unsharedRideTime); | ||
double unsharedDistance = VrpPaths.calcDistance(unsharedPath);//includes last link | ||
|
||
DrtRoute route = routeFactories.createRoute(DrtRoute.class, accessActLink.getId(), egressActLink.getId()); | ||
route.setDistance(unsharedDistance); | ||
route.setTravelTime(maxTravelTime); | ||
route.setMaxRideTime(maxRideDuration); | ||
route.setDirectRideTime(unsharedRideTime); | ||
route.setMaxWaitTime(drtCfg.maxWaitTime); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,27 @@ public static DrtConfigGroup getSingleModeDrtConfig(Config config) { | |
@PositiveOrZero | ||
public double maxAbsoluteDetour = Double.POSITIVE_INFINITY;// [s] | ||
|
||
@Parameter | ||
@Comment( | ||
"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") | ||
@DecimalMin("1.0") | ||
public double maxDetourAlpha = Double.POSITIVE_INFINITY; | ||
|
||
@Parameter | ||
@Comment( | ||
"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") | ||
@PositiveOrZero | ||
public double maxDetourBeta = Double.POSITIVE_INFINITY;// [s] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two comments should mention that the detour is computed from the latest promised pickup time and not from the actual pickup time. I think we should also mention the following somewhere (maybe in BTW. In a simulation setup without congestion, the actual pickup time is always less than or equal to the promised time. With congestion there is no such a guarantee. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, @michalmac! I will update the descriptions and comments based on the comments. |
||
|
||
@Parameter | ||
@Comment( | ||
"Defines the maximum delay allowed from the initial scheduled pick up time. Once a estimated pick up time is determined, the DRT optimizer" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rewrite the second sentence in this way? |
||
+ "should try to keep this promise. By default, this limit is disabled. If enabled, a value between 120 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)." | ||
|
@@ -250,7 +271,7 @@ private void initSingletonParameterSets() { | |
addDefinition(DrtRequestInsertionRetryParams.SET_NAME, DrtRequestInsertionRetryParams::new, | ||
() -> drtRequestInsertionRetryParams, | ||
params -> drtRequestInsertionRetryParams = (DrtRequestInsertionRetryParams)params); | ||
|
||
//prebooking (optional) | ||
addDefinition(PrebookingParams.SET_NAME, PrebookingParams::new, | ||
() -> prebookingParams, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider a different name than
promisedPickupTimeWindow
. We usually think of a time window as a[a,b)
period, wherea
andb
are time stamps. Here,promisedPickupTimeWindow
is a duration and represents a time buffer.In the drt config group, we use
maxAllowedPickupDelay
instetad ofpromisedPickupTimeWindow
. I think we should also use this name in this class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also
updatedPickupTimeWindow
should be renamed. MaybeupdatedLatestStartTime
?