return s0.edit(this, narrative).makeState();
}
private State traverseReverse(State s0) {
State results = null;
long time = s0.getTime();
TraverseOptions options = s0.getOptions();
/**
* Look for arrivals in the previous X minutes
*/
long timeFrom = SupportLibrary.getPreviousTimeWindow(_context, time);
long timeTo = time;
List<ArrivalAndDepartureInstance> arrivals = getArrivalsInTimeRange(time,
timeFrom, timeTo, options);
for (ArrivalAndDepartureInstance instance : arrivals) {
long arrivalTime = instance.getBestArrivalTime();
// Prune anything that doesn't have an arrival time in the proper range,
// since the stopTimeService method will also return instances that depart
// in the target interval as well
if (arrivalTime < timeFrom || time <= arrivalTime)
continue;
Vertex fromVertex = new BlockArrivalVertex(_context, instance);
Vertex toVertex = new ArrivalVertex(_context, _stop, s0.getTime());
EdgeNarrative narrative = narrative(s0, fromVertex, toVertex);
OBAStateEditor edit = (OBAStateEditor) s0.edit(this, narrative);
int dwellTime = (int) ((time - arrivalTime) / 1000);
edit.setTime(arrivalTime);
edit.incrementNumBoardings();
edit.setEverBoarded(true);
if (s0.getNumBoardings() == 0)
edit.incrementInitialWaitTime(dwellTime * 1000);
double w = ItineraryWeightingLibrary.computeWeightForWait(s0, dwellTime);
edit.incrementWeight(w);
State r = edit.makeState();
results = r.addToExistingResultChain(results);
}
// In addition to all the departures, we can just remain waiting at the stop
int dwellTime = (int) ((time - timeFrom) / 1000);
double w = ItineraryWeightingLibrary.computeWeightForWait(s0, dwellTime);
Vertex fromVertex = new ArrivalVertex(_context, _stop, timeFrom);
Vertex toVertex = new ArrivalVertex(_context, _stop, s0.getTime());
EdgeNarrative narrative = narrative(s0, fromVertex, toVertex);
OBAStateEditor edit = (OBAStateEditor) s0.edit(this, narrative);
edit.incrementWeight(w);
edit.setTime(time);
if (s0.getNumBoardings() == 0)
edit.incrementInitialWaitTime(dwellTime * 1000);
State r = edit.makeState();
results = r.addToExistingResultChain(results);
return results;
}