Search in sources :

Example 21 with Trip

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

the class TripTimesTest method testBikesAllowed.

@Test
public void testBikesAllowed() {
    Graph graph = new Graph();
    Trip trip = new Trip();
    Route route = new Route();
    trip.setRoute(route);
    List<StopTime> stopTimes = Arrays.asList(new StopTime(), new StopTime());
    TripTimes s = new TripTimes(trip, stopTimes, new Deduplicator());
    RoutingRequest request = new RoutingRequest(TraverseMode.BICYCLE);
    Vertex v = new SimpleConcreteVertex(graph, "", 0.0, 0.0);
    request.setRoutingContext(graph, v, v);
    State s0 = new State(request);
    assertFalse(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.ALLOWED);
    assertTrue(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.NOT_ALLOWED);
    assertFalse(s.tripAcceptable(s0, 0));
}
Also used : SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 22 with Trip

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

the class TestTransfers method testStopToStopTransfer.

public void testStopToStopTransfer() 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 + ":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 transfer to table, transfer time was 27600 seconds
    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, 27601);
    // 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 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 23 with Trip

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

the class TestTransfers method testStopToStopTransferInReverse.

public void testStopToStopTransferInReverse() 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 + ":N");
    Vertex destination = graph.getVertex(feedId + ":H");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.setArriveBy(true);
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 12, 1, 0, 0);
    options.setRoutingContext(graph, origin, destination);
    // Plan journey
    GraphPath path;
    List<Trip> trips;
    path = planJourney(options, true);
    trips = extractTrips(path);
    // Validate result
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Add transfer to table, transfer time was 27600 seconds
    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, 27601);
    // Plan journey
    path = planJourney(options, true);
    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 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 24 with Trip

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

the class TestTransfers method testForbiddenStopToStopTransfer.

public void testForbiddenStopToStopTransfer() 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 + ":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 forbidden 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.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 25 with Trip

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

the class TimetableTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    patternIndex = new HashMap<AgencyAndId, TripPattern>();
    for (TransitStopDepart tsd : Iterables.filter(graph.getVertices(), TransitStopDepart.class)) {
        for (TransitBoardAlight tba : Iterables.filter(tsd.getOutgoing(), TransitBoardAlight.class)) {
            if (!tba.boarding)
                continue;
            TripPattern pattern = tba.getPattern();
            for (Trip trip : pattern.getTrips()) {
                patternIndex.put(trip.getId(), pattern);
            }
        }
    }
    pattern = patternIndex.get(new AgencyAndId("agency", "1.1"));
    timetable = pattern.scheduledTimetable;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File) TransitStopDepart(org.opentripplanner.routing.vertextype.TransitStopDepart) BeforeClass(org.junit.BeforeClass)

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