Search in sources :

Example 86 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class TestTransfers method testForbiddenStopToStopTransferWithFrequencyInReverse.

public void testForbiddenStopToStopTransferWithFrequencyInReverse() throws Exception {
    // 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 + ":U");
    Vertex destination = graph.getVertex(feedId + ":J");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.setArriveBy(true);
    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("15.1", trips.get(0).getId().getId());
    assertEquals("5.1", trips.get(1).getId().getId());
    // Add forbidden transfer to table
    Stop stopV = new Stop();
    stopV.setId(new AgencyAndId(feedId, "V"));
    Stop stopI = new Stop();
    stopI.setId(new AgencyAndId(feedId, "I"));
    table.addTransferTime(stopV, stopI, null, null, null, null, StopTransfer.FORBIDDEN_TRANSFER);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check that no trip was returned
    assertEquals(0, trips.size());
    // Revert the graph, thus using the original transfer table again
    reset(graph);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath)

Example 87 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class TestTransfers method testStopToStopTransferWithFrequency.

public void testStopToStopTransferWithFrequency() throws Exception {
    // 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 + ":O");
    Vertex destination = graph.getVertex(feedId + ":V");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 11, 13, 11, 0);
    options.setRoutingContext(graph, origin, destination);
    // Plan journey
    GraphPath path;
    List<Trip> trips;
    path = planJourney(options);
    trips = extractTrips(path);
    // Validate result
    assertEquals("10.5", trips.get(0).getId().getId());
    assertEquals("15.1", trips.get(1).getId().getId());
    // Find state with FrequencyBoard back edge and save time of that state
    long time = -1;
    for (State s : path.states) {
        if (s.getBackEdge() instanceof TransitBoardAlight && ((TransitBoardAlight) s.getBackEdge()).boarding) {
            // find the final board edge, don't break
            time = s.getTimeSeconds();
        }
    }
    assertTrue(time >= 0);
    // Add transfer to table such that the next trip will be chosen
    // (there are 3600 seconds between trips), transfer time was 75 seconds
    Stop stopP = new Stop();
    stopP.setId(new AgencyAndId(feedId, "P"));
    Stop stopU = new Stop();
    stopU.setId(new AgencyAndId(feedId, "U"));
    table.addTransferTime(stopP, stopU, null, null, null, null, 3675);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether a later second trip was taken
    assertEquals("10.5", trips.get(0).getId().getId());
    assertEquals("15.1", trips.get(1).getId().getId());
    // Find state with FrequencyBoard back edge and save time of that state
    long newTime = -1;
    for (State s : path.states) {
        if (s.getBackEdge() instanceof TransitBoardAlight && ((TransitBoardAlight) s.getBackEdge()).boarding) {
            // find the final board edge, don't break
            newTime = s.getTimeSeconds();
        }
    }
    assertTrue(newTime >= 0);
    assertTrue(newTime > time);
    assertEquals(3600, newTime - time);
    // Revert the graph, thus using the original transfer table again
    reset(graph);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath)

Example 88 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class TestTransfers method testStopToStopTransferWithFrequencyInReverse.

public void testStopToStopTransferWithFrequencyInReverse() throws Exception {
    // 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 + ":U");
    Vertex destination = graph.getVertex(feedId + ":J");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.setArriveBy(true);
    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("15.1", trips.get(0).getId().getId());
    assertEquals("5.1", trips.get(1).getId().getId());
    // Find state with FrequencyBoard back edge and save time of that state
    long time = -1;
    for (State s : path.states) {
        if (s.getBackEdge() instanceof TransitBoardAlight && s.getBackState() != null) {
            time = s.getBackState().getTimeSeconds();
            break;
        }
    }
    assertTrue(time >= 0);
    // Add transfer to table such that the next trip will be chosen
    // (there are 3600 seconds between trips), transfer time was 75 seconds
    Stop stopV = new Stop();
    stopV.setId(new AgencyAndId(feedId, "V"));
    Stop stopI = new Stop();
    stopI.setId(new AgencyAndId(feedId, "I"));
    table.addTransferTime(stopV, stopI, null, null, null, null, 3675);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether a later second trip was taken
    assertEquals("15.1", trips.get(0).getId().getId());
    assertEquals("5.1", trips.get(1).getId().getId());
    // Find state with FrequencyBoard back edge and save time of that state
    long newTime = -1;
    for (State s : path.states) {
        if (s.getBackEdge() instanceof TransitBoardAlight && s.getBackState() != null) {
            newTime = s.getBackState().getTimeSeconds();
            break;
        }
    }
    assertTrue(newTime >= 0);
    assertTrue(newTime < time);
    assertEquals(3600, time - newTime);
    // Revert the graph, thus using the original transfer table again
    reset(graph);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath)

Example 89 with Trip

use of org.onebusaway.gtfs.model.Trip 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)

Example 90 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class TestTransferTable method testTransferTable.

/**
 * Test transfer table
 */
public void testTransferTable() {
    // Setup from stop
    Stop fromStop = new Stop();
    fromStop.setId(new AgencyAndId("A1", "S1"));
    // Setup to stop
    Stop toStop = new Stop();
    toStop.setId(new AgencyAndId("A1", "S2"));
    // Setup to stop parent
    Stop toStopParent = new Stop();
    toStopParent.setId(new AgencyAndId("A1", "S3"));
    toStop.setParentStation("S3");
    // Setup from trip with route
    Route fromRoute = new Route();
    fromRoute.setId(new AgencyAndId("A1", "R1"));
    Trip fromTrip = new Trip();
    fromTrip.setId(new AgencyAndId("A1", "T1"));
    fromTrip.setRoute(fromRoute);
    // Setup to trip with route
    Route toRoute = new Route();
    toRoute.setId(new AgencyAndId("A1", "R2"));
    Trip toTrip = new Trip();
    toTrip.setId(new AgencyAndId("A1", "T2"));
    toTrip.setRoute(toRoute);
    // Setup second to trip with route
    Route toRoute2 = new Route();
    toRoute2.setId(new AgencyAndId("A1", "R3"));
    Trip toTrip2 = new Trip();
    toTrip2.setId(new AgencyAndId("A1", "T3"));
    toTrip2.setRoute(toRoute2);
    // Create transfer table
    TransferTable table = new TransferTable();
    // Check transfer times
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip2, true));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip, true));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip2, true));
    // Add transfer to parent stop, specificity 0
    table.addTransferTime(fromStop, toStopParent, null, null, null, null, StopTransfer.PREFERRED_TRANSFER);
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip2, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip2, true));
    // Check going forward and backwards in time
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, false));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, table.getTransferTime(toStop, fromStop, toTrip, fromTrip, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(toStop, fromStop, toTrip, fromTrip, false));
    // Add transfer to child stop, specificity 1
    table.addTransferTime(fromStop, toStop, null, toRoute, null, null, StopTransfer.FORBIDDEN_TRANSFER);
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip2, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip2, true));
    // Add transfer to parent stop, specificity 1
    table.addTransferTime(fromStop, toStopParent, null, toRoute2, null, null, StopTransfer.TIMED_TRANSFER);
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(StopTransfer.TIMED_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip2, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip, true));
    assertEquals(StopTransfer.TIMED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip2, true));
    // Add transfer to child stop, specificity 2
    table.addTransferTime(fromStop, toStop, null, toRoute2, null, toTrip2, 4);
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(4, table.getTransferTime(fromStop, toStop, fromTrip, toTrip2, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip, true));
    assertEquals(StopTransfer.TIMED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip2, true));
    // Add transfer to parent stop and unknown to child stop, specificity 3
    // WARNING: don't add transfers with StopTransfer.UNKNOWN_TRANSFER in non-testing code
    table.addTransferTime(fromStop, toStop, fromRoute, null, null, toTrip, StopTransfer.UNKNOWN_TRANSFER);
    table.addTransferTime(fromStop, toStopParent, fromRoute, null, null, toTrip, 5);
    assertEquals(5, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(4, table.getTransferTime(fromStop, toStop, fromTrip, toTrip2, true));
    assertEquals(5, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip, true));
    assertEquals(StopTransfer.TIMED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip2, true));
    // Add transfer to child stop, specificity 4
    table.addTransferTime(fromStop, toStop, null, null, fromTrip, toTrip2, 6);
    assertEquals(5, table.getTransferTime(fromStop, toStop, fromTrip, toTrip, true));
    assertEquals(6, table.getTransferTime(fromStop, toStop, fromTrip, toTrip2, true));
    assertEquals(5, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip, true));
    assertEquals(StopTransfer.TIMED_TRANSFER, table.getTransferTime(fromStop, toStopParent, fromTrip, toTrip2, true));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10