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));
}
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);
}
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);
}
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);
}
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;
}
Aggregations