Search in sources :

Example 1 with TimedTransferEdge

use of org.opentripplanner.routing.edgetype.TimedTransferEdge in project OpenTripPlanner by opentripplanner.

the class GTFSPatternHopFactory method loadTransfers.

private void loadTransfers(Graph graph) {
    Collection<Transfer> transfers = _dao.getAllTransfers();
    TransferTable transferTable = graph.getTransferTable();
    for (Transfer sourceTransfer : transfers) {
        // we thus expand transfers that use parent stations to all the member stops.
        for (Transfer t : expandTransfer(sourceTransfer)) {
            Stop fromStop = t.getFromStop();
            Stop toStop = t.getToStop();
            Route fromRoute = t.getFromRoute();
            Route toRoute = t.getToRoute();
            Trip fromTrip = t.getFromTrip();
            Trip toTrip = t.getToTrip();
            Vertex fromVertex = context.stopArriveNodes.get(fromStop);
            Vertex toVertex = context.stopDepartNodes.get(toStop);
            switch(t.getTransferType()) {
                case 1:
                    // timed (synchronized) transfer
                    // Handle with edges that bypass the street network.
                    // from and to vertex here are stop_arrive and stop_depart vertices
                    // only add edge when it doesn't exist already
                    boolean hasTimedTransferEdge = false;
                    for (Edge outgoingEdge : fromVertex.getOutgoing()) {
                        if (outgoingEdge instanceof TimedTransferEdge) {
                            if (outgoingEdge.getToVertex() == toVertex) {
                                hasTimedTransferEdge = true;
                                break;
                            }
                        }
                    }
                    if (!hasTimedTransferEdge) {
                        new TimedTransferEdge(fromVertex, toVertex);
                    }
                    // add to transfer table to handle specificity
                    transferTable.addTransferTime(fromStop, toStop, fromRoute, toRoute, fromTrip, toTrip, StopTransfer.TIMED_TRANSFER);
                    break;
                case 2:
                    // min transfer time
                    transferTable.addTransferTime(fromStop, toStop, fromRoute, toRoute, fromTrip, toTrip, t.getMinTransferTime());
                    break;
                case 3:
                    // forbidden transfer
                    transferTable.addTransferTime(fromStop, toStop, fromRoute, toRoute, fromTrip, toTrip, StopTransfer.FORBIDDEN_TRANSFER);
                    break;
                case 0:
                default:
                    // preferred transfer
                    transferTable.addTransferTime(fromStop, toStop, fromRoute, toRoute, fromTrip, toTrip, StopTransfer.PREFERRED_TRANSFER);
                    break;
            }
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) TimedTransferEdge(org.opentripplanner.routing.edgetype.TimedTransferEdge) TransferTable(org.opentripplanner.routing.core.TransferTable) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TransitStationStop(org.opentripplanner.routing.vertextype.TransitStationStop) StopTransfer(org.opentripplanner.routing.core.StopTransfer) Transfer(org.onebusaway.gtfs.model.Transfer) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) TransferEdge(org.opentripplanner.routing.edgetype.TransferEdge) PreBoardEdge(org.opentripplanner.routing.edgetype.PreBoardEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) PreAlightEdge(org.opentripplanner.routing.edgetype.PreAlightEdge) TimedTransferEdge(org.opentripplanner.routing.edgetype.TimedTransferEdge) Edge(org.opentripplanner.routing.graph.Edge) StationStopEdge(org.opentripplanner.routing.edgetype.StationStopEdge) Route(org.onebusaway.gtfs.model.Route)

Example 2 with TimedTransferEdge

use of org.opentripplanner.routing.edgetype.TimedTransferEdge in project OpenTripPlanner by opentripplanner.

the class TestTransfers method testTimedStopToStopTransfer.

public void testTimedStopToStopTransfer() throws Exception {
    ServiceDate serviceDate = new ServiceDate(2009, 07, 11);
    // Replace the transfer table with an empty table
    TransferTable table = new TransferTable();
    when(graph.getTransferTable()).thenReturn(table);
    // Compute a normal path between two stops
    Vertex origin = graph.getVertex(feedId + ":N");
    Vertex destination = graph.getVertex(feedId + ":H");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 11, 11, 11, 0);
    options.setRoutingContext(graph, origin, destination);
    // Plan journey
    GraphPath path;
    List<Trip> trips;
    path = planJourney(options);
    trips = extractTrips(path);
    // Validate result
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Add timed transfer to table
    Stop stopK = new Stop();
    stopK.setId(new AgencyAndId(feedId, "K"));
    Stop stopF = new Stop();
    stopF.setId(new AgencyAndId(feedId, "F"));
    table.addTransferTime(stopK, stopF, null, null, null, null, StopTransfer.TIMED_TRANSFER);
    // Don't forget to also add a TimedTransferEdge
    Vertex fromVertex = graph.getVertex(feedId + ":K_arrive");
    Vertex toVertex = graph.getVertex(feedId + ":F_depart");
    TimedTransferEdge timedTransferEdge = new TimedTransferEdge(fromVertex, toVertex);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether the trips are still the same
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Now apply a real-time update: let the to-trip be early by 27600 seconds,
    // resulting in a transfer time of 0 seconds
    Trip trip = graph.index.tripForId.get(new AgencyAndId("agency", "4.2"));
    TripPattern pattern = graph.index.patternForTrip.get(trip);
    applyUpdateToTripPattern(pattern, "4.2", "F", 1, 55200, 55200, ScheduleRelationship.SCHEDULED, 0, serviceDate);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether the trips are still the same
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Now apply a real-time update: let the to-trip be early by 27601 seconds,
    // resulting in a transfer time of -1 seconds
    applyUpdateToTripPattern(pattern, "4.2", "F", 1, 55199, 55199, ScheduleRelationship.SCHEDULED, 0, serviceDate);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether a later second trip was taken
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.3", trips.get(1).getId().getId());
    // "Revert" the real-time update
    applyUpdateToTripPattern(pattern, "4.2", "F", 1, 82800, 82800, ScheduleRelationship.SCHEDULED, 0, serviceDate);
    // Remove the timed transfer from the graph
    graph.removeEdge(timedTransferEdge);
    // Revert the graph, thus using the original transfer table again
    reset(graph);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Trip(org.onebusaway.gtfs.model.Trip) TimedTransferEdge(org.opentripplanner.routing.edgetype.TimedTransferEdge) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath) TripPattern(org.opentripplanner.routing.edgetype.TripPattern)

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)2 Trip (org.onebusaway.gtfs.model.Trip)2 TimedTransferEdge (org.opentripplanner.routing.edgetype.TimedTransferEdge)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Route (org.onebusaway.gtfs.model.Route)1 Transfer (org.onebusaway.gtfs.model.Transfer)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 StopTransfer (org.opentripplanner.routing.core.StopTransfer)1 TransferTable (org.opentripplanner.routing.core.TransferTable)1 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)1 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)1 PreAlightEdge (org.opentripplanner.routing.edgetype.PreAlightEdge)1 PreBoardEdge (org.opentripplanner.routing.edgetype.PreBoardEdge)1 StationStopEdge (org.opentripplanner.routing.edgetype.StationStopEdge)1 TransferEdge (org.opentripplanner.routing.edgetype.TransferEdge)1 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)1 Edge (org.opentripplanner.routing.graph.Edge)1 GraphPath (org.opentripplanner.routing.spt.GraphPath)1