public RaptorBoardSpec getTripIndexReverse(RoutingRequest request, int arrivalTime, int stopNo) { RaptorBoardSpec spec = new RaptorBoardSpec(); spec.departureTime = 0; spec.tripTimes = null; spec.patternIndex = -1; for (int i = 0; i < alights[stopNo - 1].length; ++i) { TransitBoardAlight alight = alights[stopNo - 1][i]; State state = new State(alight.getToVertex(), arrivalTime, request); State result = alight.traverse(state); if (result == null) continue; int time = (int) result.getTime(); if (time > spec.departureTime) { spec.departureTime = time; spec.tripTimes = result.getTripTimes(); spec.patternIndex = i; spec.serviceDay = result.getServiceDay(); spec.tripId = result.getTripId(); } } if (spec.patternIndex == -1) return null; return spec; }
public RaptorBoardSpec getTripIndex(RoutingRequest request, int arrivalTime, int stopNo) { RaptorBoardSpec spec = new RaptorBoardSpec(); spec.departureTime = Integer.MAX_VALUE; spec.tripTimes = null; spec.patternIndex = -1; for (int i = 0; i < boards[stopNo].length; ++i) { TransitBoardAlight board = boards[stopNo][i]; State state = new State(board.getFromVertex(), arrivalTime, request); State result = board.traverse(state); if (result == null) continue; int time = (int) result.getTime(); if (time < spec.departureTime) { spec.departureTime = time; spec.tripTimes = result.getTripTimes(); spec.patternIndex = i; spec.serviceDay = result.getServiceDay(); spec.tripId = result.getTripId(); } } if (spec.patternIndex == -1) return null; return spec; }
private State getStateArriveBy(RaptorData data, ArrayList<RaptorState> states) { RoutingRequest options = states.get(0).getRequest(); State state = new State(options.rctx.origin, options); for (int i = states.size() - 1; i >= 0; --i) { RaptorState cur = states.get(i); if (cur.walkPath != null) { GraphPath path = new GraphPath(cur.walkPath, false); for (ListIterator<Edge> it = path.edges.listIterator(path.edges.size()); it.hasPrevious(); ) { Edge e = it.previous(); State oldState = state; state = e.traverse(state); if (state == null) { e.traverse(oldState); } } } else { // so, cur is at this point at a transit stop; we have a route to alight from if (cur.getParent() == null || !cur.getParent().interlining) { for (Edge e : state.getVertex().getIncoming()) { if (e instanceof PreAlightEdge) { state = e.traverse(state); } } TransitBoardAlight alight = cur.getRoute().alights[cur.boardStopSequence - 1][cur.patternIndex]; State oldState = state; state = alight.traverse(state); if (state == null) { state = alight.traverse(oldState); } } // now traverse the hops and dwells until we find the board we're looking for HOP: while (true) { for (Edge e : state.getVertex().getIncoming()) { if (e instanceof PatternDwell) { state = e.traverse(state); } else if (e instanceof PatternHop) { state = e.traverse(state); if (cur.interlining) { for (Edge e2 : state.getVertex().getIncoming()) { RaptorState next = states.get(i - 1); if (e2 instanceof PatternInterlineDwell) { Stop fromStop = ((TransitVertex) e2.getFromVertex()).getStop(); Stop expectedStop = next.boardStop.stopVertex.getStop(); if (fromStop.equals(expectedStop)) { State newState = e2.traverse(state); if (newState == null) continue; if (newState.getTripId() != next.tripId) continue; state = newState; break HOP; } } } } else { for (Edge e2 : state.getVertex().getIncoming()) { if (e2 instanceof TransitBoardAlight) { for (Edge e3 : e2.getFromVertex().getIncoming()) { if (e3 instanceof PreBoardEdge) { if (data.raptorStopsForStopId.get( ((TransitStop) e3.getFromVertex()).getStopId()) == cur.stop) { state = e2.traverse(state); state = e3.traverse(state); break HOP; } } } } } } } } } } } return state; }
private State getStateDepartAt(RaptorData data, ArrayList<RaptorState> states) { State state = new State(states.get(0).getRequest()); for (int i = states.size() - 1; i >= 0; --i) { RaptorState cur = states.get(i); if (cur.walkPath != null) { // a walking step GraphPath path = new GraphPath(cur.walkPath, false); for (Edge e : path.edges) { State oldState = state; state = e.traverse(state); if (state == null) { e.traverse(oldState); } } } else { // so, cur is at this point at a transit stop; we have a route to board if (cur.getParent() == null || !cur.getParent().interlining) { for (Edge e : state.getVertex().getOutgoing()) { if (e instanceof PreBoardEdge) { state = e.traverse(state); break; } } TransitBoardAlight board = cur.getRoute().boards[cur.boardStopSequence][cur.patternIndex]; state = board.traverse(state); } // now traverse the hops and dwells until we find the alight we're looking for HOP: while (true) { for (Edge e : state.getVertex().getOutgoing()) { if (e instanceof PatternDwell) { state = e.traverse(state); } else if (e instanceof PatternHop) { state = e.traverse(state); if (cur.interlining) { for (Edge e2 : state.getVertex().getOutgoing()) { RaptorState next = states.get(i - 1); if (e2 instanceof PatternInterlineDwell) { Stop toStop = ((TransitVertex) e2.getToVertex()).getStop(); Stop expectedStop = next.boardStop.stopVertex.getStop(); if (toStop.equals(expectedStop)) { State newState = e2.traverse(state); if (newState == null) continue; if (newState.getTripId() != next.tripId) continue; state = newState; break HOP; } } } } else { for (Edge e2 : state.getVertex().getOutgoing()) { if (e2 instanceof TransitBoardAlight) { for (Edge e3 : e2.getToVertex().getOutgoing()) { if (e3 instanceof PreAlightEdge) { if (data.raptorStopsForStopId.get( ((TransitStop) e3.getToVertex()).getStopId()) == cur.stop) { state = e2.traverse(state); state = e3.traverse(state); break HOP; } } } } } } } } } } } return state; }