Skip to content

Commit

Permalink
fix(pickup-delay): apply delay in caller, not at origin
Browse files Browse the repository at this point in the history
Still todo: apply delay for trips including transit
  • Loading branch information
ansoncfit committed Apr 13, 2019
1 parent 251205f commit 41cfd07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
25 changes: 19 additions & 6 deletions src/main/java/com/conveyal/r5/analyst/TravelTimeComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,20 @@ public OneOriginResult computeTravelTimes() {
StreetRouter sr = new StreetRouter(network.streetLayer);
sr.profileRequest = request;
sr.streetMode = accessMode;
int delayAtOrigin = 0;
if (request.accessModes.contains(LegMode.CAR)) {
delayAtOrigin = network.streetLayer.getWaitTime(request.fromLat, request.fromLon);
}
boolean foundOriginPoint = sr.setOrigin(request.fromLat, request.fromLon, delayAtOrigin);
boolean foundOriginPoint = sr.setOrigin(request.fromLat, request.fromLon);
if (!foundOriginPoint) {
// Short circuit around routing and propagation. Calling finish() before streaming in any travel times to
// destinations is designed to produce the right result.
LOG.info("Origin point was outside the transport network. Skipping routing and propagation, and returning default result.");
return travelTimeReducer.finish();
}

// Delay specified by a modification. For PickupDelay modifications, negative values imply no car service.
int delaySeconds = 0;
if (request.accessModes.contains(LegMode.CAR)) {
delaySeconds = network.streetLayer.getWaitTime(request.fromLat, request.fromLon);
}

// First we will find travel times to all destinations reachable without using transit.
// Simultaneously we will find stations that allow access to the transit network.
if (request.transitModes.isEmpty()) {
Expand All @@ -106,6 +108,12 @@ public OneOriginResult computeTravelTimes() {
// searches which use distance as the quantity to minimize (because they are precalculated and stored as distance,
// and then converted to times by dividing by speed without regard to weights/penalties for things like stairs).
// This does mean that walk-only results will not match the walking portion of walk+transit results.

// If there's no pickup service, give up (don't even try walking)
if (delaySeconds < 0) {
return travelTimeReducer.finish();
}

sr.timeLimitSeconds = request.maxTripDurationMinutes * 60;
sr.streetMode = directMode;
sr.quantityToMinimize = StreetRouter.State.RoutingVariable.DURATION_SECONDS;
Expand All @@ -119,10 +127,15 @@ public OneOriginResult computeTravelTimes() {

// Iterate over all destinations ("targets") and at each destination, save the same travel time for all percentiles.
for (int d = 0; d < travelTimesToTargets.length; d++) {
final int travelTimeSeconds = travelTimesToTargets[d];
final int travelTimeSeconds = travelTimesToTargets[d] + delaySeconds;
travelTimeReducer.recordTravelTimesForTarget(d, new int[] { travelTimeSeconds });
}

// TODO if we allow multiple directModes, check the next fastest mode. Walking or biking might be faster,
// especially if there are congestion or pickup delay modifications.

return travelTimeReducer.finish();

} else {
// This search will include transit.
//
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/com/conveyal/r5/streets/StreetRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,15 @@ public StreetRouter (StreetLayer streetLayer, TravelTimeCalculator travelTimeCal
*
* @param lat Latitude in floating point (not fixed int) degrees.
* @param lon Longitude in floating point (not fixed int) degrees.
* @param delay additional time spent at origin before traversing street network (e.g. TNC pickup delay)
* @return true if an edge was found near the specified coordinate
*/
public boolean setOrigin (double lat, double lon, int delay) {
public boolean setOrigin (double lat, double lon) {
Split split = streetLayer.findSplit(lat, lon, StreetLayer.LINK_RADIUS_METERS, streetMode);
if (split == null) {
LOG.info("No street was found near the specified origin point of {}, {}.", lat, lon);
return false;
}

if (delay <0 ) {
// Modifications like PickupDelay return negative values when service is not provided for a given origin.
return false;
}

originSplit = split;
bestStatesAtEdge.clear();
queue.clear();
Expand All @@ -335,13 +329,13 @@ public boolean setOrigin (double lat, double lon, int delay) {
// Uses weight based on distance from end vertices, and speed on edge which depends on transport mode
float speedMetersPerSecond = edge.calculateSpeed(profileRequest, streetMode);
startState1.weight = (int) ((split.distance1_mm / 1000) / speedMetersPerSecond);
startState1.durationSeconds = startState1.weight + delay;
startState1.durationSeconds = startState1.weight;
startState1.distance = split.distance1_mm;
edge.advance();
// Speed can be different on opposite sides of the same street
speedMetersPerSecond = edge.calculateSpeed(profileRequest, streetMode);
startState0.weight = (int) ((split.distance0_mm / 1000) / speedMetersPerSecond);
startState0.durationSeconds = startState0.weight + delay;
startState0.durationSeconds = startState0.weight;
startState0.distance = split.distance0_mm;

// FIXME Below is reversing the vertices, but then aren't the weights, times, distances wrong? Why are we even doing this?
Expand All @@ -366,10 +360,6 @@ public boolean setOrigin (double lat, double lon, int delay) {
return true;
}

public boolean setOrigin (double lat, double lon){
return setOrigin(lat, lon, 0);
}

public void setOrigin (int fromVertex) {
bestStatesAtEdge.clear();
queue.clear();
Expand Down

0 comments on commit 41cfd07

Please sign in to comment.