Skip to content

Commit

Permalink
don't egress from transfers to the street network.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwigway committed Apr 27, 2015
1 parent 4df8943 commit 7e7f55d
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/main/java/org/opentripplanner/profile/RaptorWorker.java
Expand Up @@ -30,6 +30,9 @@ public class RaptorWorker {
List<int[]> timesPerStopPerRound; List<int[]> timesPerStopPerRound;
int[] timesPerStop; int[] timesPerStop;
int[] bestTimes; int[] bestTimes;

/** The best times for reaching stops via transit rather than via a transfer from another stop */
int[] bestNonTransferTimes;
int[] transferResults; int[] transferResults;
RaptorWorkerData data; RaptorWorkerData data;


Expand All @@ -41,10 +44,12 @@ public class RaptorWorker {
public RaptorWorker(RaptorWorkerData data, ProfileRequest req) { public RaptorWorker(RaptorWorkerData data, ProfileRequest req) {
this.data = data; this.data = data;
this.bestTimes = new int[data.nStops]; this.bestTimes = new int[data.nStops];
this.bestNonTransferTimes = new int[data.nStops];
stopsTouched = new BitSet(data.nStops); stopsTouched = new BitSet(data.nStops);
patternsTouched = new BitSet(data.nPatterns); patternsTouched = new BitSet(data.nPatterns);
this.req = req; this.req = req;
Arrays.fill(bestTimes, UNREACHED); // initialize once here and reuse on subsequent iterations. Arrays.fill(bestTimes, UNREACHED); // initialize once here and reuse on subsequent iterations.
Arrays.fill(bestNonTransferTimes, UNREACHED);
} }


public void advance () { public void advance () {
Expand Down Expand Up @@ -91,8 +96,9 @@ public PropagatedTimesStore runRaptor (Graph graph, TObjectIntMap<TransitStop> a
for (int s = 0; s < data.nStops; s++) { for (int s = 0; s < data.nStops; s++) {
// it's safe to use the best time at this stop for any number of transfers, even in range-raptor, // it's safe to use the best time at this stop for any number of transfers, even in range-raptor,
// because we allow unlimited transfers. this is slightly different from the original RAPTOR implementation: // because we allow unlimited transfers. this is slightly different from the original RAPTOR implementation:
// we do not necessarily compute all pareto-optimal paths on (journey time, number of transfers) // we do not necessarily compute all pareto-optimal paths on (journey time, number of transfers).
int baseTimeSeconds = bestTimes[s]; // TODO this allows egressing from transfers.
int baseTimeSeconds = bestNonTransferTimes[s];
if (baseTimeSeconds != UNREACHED) { if (baseTimeSeconds != UNREACHED) {
baseTimeSeconds -= departureTime; // convert to travel time rather than clock time baseTimeSeconds -= departureTime; // convert to travel time rather than clock time
int[] targets = data.targetsForStop.get(s); int[] targets = data.targetsForStop.get(s);
Expand Down Expand Up @@ -150,6 +156,7 @@ public void runRaptor (TIntIntMap initialStops, int departureTime) {
iterator.advance(); iterator.advance();
int stopIndex = iterator.key(); int stopIndex = iterator.key();
int time = iterator.value() + departureTime; int time = iterator.value() + departureTime;
// note not setting bestNonTransferTimes here because the initial walk is effectively a "transfer"
bestTimes[stopIndex] = Math.min(time, bestTimes[stopIndex]); bestTimes[stopIndex] = Math.min(time, bestTimes[stopIndex]);
markPatternsForStop(stopIndex); markPatternsForStop(stopIndex);
} }
Expand Down Expand Up @@ -181,15 +188,19 @@ public boolean doOneRound () {
} else { } else {
// We're on board a trip. // We're on board a trip.
int arrivalTime = timetable.getArrival(onTrip, stopPositionInPattern); int arrivalTime = timetable.getArrival(onTrip, stopPositionInPattern);
if (arrivalTime < max_time && arrivalTime < bestTimes[stopIndex]) { if (arrivalTime < max_time && arrivalTime < bestNonTransferTimes[stopIndex]) {
bestTimes[stopIndex] = arrivalTime; bestNonTransferTimes[stopIndex] = arrivalTime;

if (arrivalTime < bestTimes[stopIndex])
bestTimes[stopIndex] = arrivalTime;

stopsTouched.set(stopIndex); stopsTouched.set(stopIndex);
} }
// Check whether we can back up to an earlier trip. This could be due to an overtaking trip, // Check whether we can back up to an earlier trip. This could be due to an overtaking trip,
// or (more likely) because there was a faster way to get to a stop further down the line. // or (more likely) because there was a faster way to get to a stop further down the line.
while (onTrip > 0) { while (onTrip > 0) {
int departureOnPreviousTrip = timetable.getDeparture(onTrip - 1, stopPositionInPattern); int departureOnPreviousTrip = timetable.getDeparture(onTrip - 1, stopPositionInPattern);
if (departureOnPreviousTrip > bestTimes[stopIndex]) { if (departureOnPreviousTrip > bestNonTransferTimes[stopIndex]) {
onTrip--; onTrip--;
} else { } else {
break; break;
Expand All @@ -207,29 +218,21 @@ public boolean doOneRound () {
* Mark all the patterns passing through these stops and any stops transferred to. * Mark all the patterns passing through these stops and any stops transferred to.
*/ */
private void doTransfers() { private void doTransfers() {
// copy and update bestTimes, because if the best way to get to a stop is a transfer but that
// stop was also touched in the last round, we don't want to transfer from the transfer.
// This doesn't matter in the transit phase, because, since we don't limit transfers, it's fine
// if a particular round explores multiple connected transit rides.
int[] newBestTimes = bestTimes.clone();

patternsTouched.clear(); patternsTouched.clear();
for (int stop = stopsTouched.nextSetBit(0); stop >= 0; stop = stopsTouched.nextSetBit(stop + 1)) { for (int stop = stopsTouched.nextSetBit(0); stop >= 0; stop = stopsTouched.nextSetBit(stop + 1)) {
// TODO this is reboarding every trip at every stop. // TODO this is reboarding every trip at every stop.
markPatternsForStop(stop); markPatternsForStop(stop);
int fromTime = bestTimes[stop]; int fromTime = bestNonTransferTimes[stop];
int[] transfers = data.transfersForStop.get(stop); int[] transfers = data.transfersForStop.get(stop);
for (int i = 0; i < transfers.length; i++) { for (int i = 0; i < transfers.length; i++) {
int toStop = transfers[i++]; // increment i int toStop = transfers[i++]; // increment i
int distance = transfers[i]; // i will be incremented at the end of the loop int distance = transfers[i]; // i will be incremented at the end of the loop
int toTime = fromTime + (int) (distance / req.walkSpeed); int toTime = fromTime + (int) (distance / req.walkSpeed);
if (toTime < max_time && toTime < newBestTimes[toStop]) { if (toTime < max_time && toTime < bestTimes[toStop]) {
newBestTimes[toStop] = toTime; bestTimes[toStop] = toTime;
markPatternsForStop(toStop); markPatternsForStop(toStop);
} }
} }

bestTimes = newBestTimes;
} }
} }


Expand Down

0 comments on commit 7e7f55d

Please sign in to comment.