use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testTransfers.
public void testTransfers() throws Exception {
TransferTable transferTable = graph.getTransferTable();
// create dummy routes and trips
// In tests we don't patch entities with the feed id, only default agency id is used.
Route fromRoute = new Route();
fromRoute.setId(new AgencyAndId("agency", "1"));
Trip fromTrip = new Trip();
fromTrip.setId(new AgencyAndId("agency", "1.1"));
fromTrip.setRoute(fromRoute);
Route toRoute = new Route();
toRoute.setId(new AgencyAndId("agency", "2"));
Trip toTrip = new Trip();
toTrip.setId(new AgencyAndId("agency", "2.1"));
toTrip.setRoute(toRoute);
Trip toTrip2 = new Trip();
toTrip2.setId(new AgencyAndId("agency", "2.2"));
toTrip2.setRoute(toRoute);
// find stops
Stop stopK = ((TransitStopArrive) graph.getVertex(feedId + ":K_arrive")).getStop();
Stop stopN = ((TransitStopDepart) graph.getVertex(feedId + ":N_depart")).getStop();
Stop stopM = ((TransitStopDepart) graph.getVertex(feedId + ":M_depart")).getStop();
assertTrue(transferTable.hasPreferredTransfers());
assertEquals(StopTransfer.UNKNOWN_TRANSFER, transferTable.getTransferTime(stopN, stopM, fromTrip, toTrip, true));
assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transferTable.getTransferTime(stopK, stopM, fromTrip, toTrip, true));
assertEquals(StopTransfer.PREFERRED_TRANSFER, transferTable.getTransferTime(stopN, stopK, toTrip, toTrip2, true));
assertEquals(StopTransfer.TIMED_TRANSFER, transferTable.getTransferTime(stopN, stopK, fromTrip, toTrip, true));
assertEquals(15, transferTable.getTransferTime(stopN, stopK, fromTrip, toTrip2, true));
TransitStop e_arrive = (TransitStop) graph.getVertex(feedId + ":E");
TransitStop f_depart = (TransitStop) graph.getVertex(feedId + ":F");
Edge edge = new TransferEdge(e_arrive, f_depart, 10000, 10000);
long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 0, 50, 0);
Vertex stop_b = graph.getVertex(feedId + ":B_depart");
Vertex stop_g = graph.getVertex(feedId + ":G_arrive");
RoutingRequest options = new RoutingRequest();
options.dateTime = startTime;
options.setRoutingContext(graph, stop_b, stop_g);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(stop_g, false);
assertNotNull(path);
assertTrue("expected to use much later trip due to min transfer time", path.getEndTime() - startTime > 4.5 * 60 * 60);
/* cleanup */
e_arrive.removeOutgoing(edge);
f_depart.removeIncoming(edge);
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class OnBoardDepartServiceImplTest method testOnBoardAtStation.
@Test
public final void testOnBoardAtStation() {
TransitStop station0 = mock(TransitStop.class);
TransitStop station1 = mock(TransitStop.class);
TransitStop station2 = mock(TransitStop.class);
PatternDepartVertex depart = mock(PatternDepartVertex.class);
PatternArriveVertex dwell = mock(PatternArriveVertex.class);
PatternArriveVertex arrive = mock(PatternArriveVertex.class);
Graph graph = mock(Graph.class);
RoutingRequest routingRequest = mock(RoutingRequest.class);
ServiceDay serviceDay = mock(ServiceDay.class);
// You're probably not supposed to do this to mocks (access their fields directly)
// But I know of no other way to do this since the mock object has only action-free stub methods.
routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
ArrayList<Edge> hops = new ArrayList<Edge>(2);
RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
Agency agency = new Agency();
AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
Route route = new Route();
ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
StopTime stopDepartTime = new StopTime();
StopTime stopDwellTime = new StopTime();
StopTime stopArriveTime = new StopTime();
Stop stopDepart = new Stop();
Stop stopDwell = new Stop();
Stop stopArrive = new Stop();
Trip trip = new Trip();
routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
agency.setId(agencyAndId.getAgencyId());
route.setId(agencyAndId);
route.setAgency(agency);
stopDepart.setId(new AgencyAndId("Station", "0"));
stopDwell.setId(new AgencyAndId("Station", "1"));
stopArrive.setId(new AgencyAndId("Station", "2"));
stopDepartTime.setStop(stopDepart);
stopDepartTime.setDepartureTime(0);
stopDwellTime.setArrivalTime(20);
stopDwellTime.setStop(stopDwell);
stopDwellTime.setDepartureTime(40);
stopArriveTime.setArrivalTime(60);
stopArriveTime.setStop(stopArrive);
stopTimes.add(stopDepartTime);
stopTimes.add(stopDwellTime);
stopTimes.add(stopArriveTime);
trip.setId(agencyAndId);
trip.setRoute(route);
TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
StopPattern stopPattern = new StopPattern(stopTimes);
TripPattern tripPattern = new TripPattern(route, stopPattern);
TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
when(depart.getTripPattern()).thenReturn(tripPattern);
when(dwell.getTripPattern()).thenReturn(tripPattern);
PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);
hops.add(patternHop0);
hops.add(patternHop1);
when(graph.getEdges()).thenReturn(hops);
when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
routingRequest.from = new GenericLocation();
routingRequest.startingTransitTripId = agencyAndId;
when(graph.getVertex("Station_0")).thenReturn(station0);
when(graph.getVertex("Station_1")).thenReturn(station1);
when(graph.getVertex("Station_2")).thenReturn(station2);
tripPattern.add(tripTimes);
graph.index = new GraphIndex(graph);
when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(0);
assertEquals(station0, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(20);
assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(30);
assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(40);
assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(60);
assertEquals(station2, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class OnBoardDepartServiceImplTest method testOnBoardDepartureAtArrivalTime.
@Test
public final void testOnBoardDepartureAtArrivalTime() {
Coordinate[] coordinates = new Coordinate[2];
coordinates[0] = new Coordinate(0.0, 0.0);
coordinates[1] = new Coordinate(0.0, 1.0);
TransitStop station0 = mock(TransitStop.class);
TransitStop station1 = mock(TransitStop.class);
PatternDepartVertex depart = mock(PatternDepartVertex.class);
PatternArriveVertex arrive = mock(PatternArriveVertex.class);
Graph graph = mock(Graph.class);
RoutingRequest routingRequest = mock(RoutingRequest.class);
ServiceDay serviceDay = mock(ServiceDay.class);
// You're probably not supposed to do this to mocks (access their fields directly)
// But I know of no other way to do this since the mock object has only action-free stub methods.
routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
when(station0.getX()).thenReturn(coordinates[0].x);
when(station0.getY()).thenReturn(coordinates[0].y);
when(station1.getX()).thenReturn(coordinates[1].x);
when(station1.getY()).thenReturn(coordinates[1].y);
RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
Agency agency = new Agency();
Route route = new Route();
ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
StopTime stopDepartTime = new StopTime();
StopTime stopArriveTime = new StopTime();
Stop stopDepart = new Stop();
Stop stopArrive = new Stop();
Trip trip = new Trip();
routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
agency.setId(agencyAndId.getAgencyId());
route.setId(agencyAndId);
route.setAgency(agency);
stopDepart.setId(new AgencyAndId("Station", "0"));
stopArrive.setId(new AgencyAndId("Station", "1"));
stopDepartTime.setStop(stopDepart);
stopDepartTime.setDepartureTime(0);
stopArriveTime.setArrivalTime(10);
stopArriveTime.setStop(stopArrive);
stopTimes.add(stopDepartTime);
stopTimes.add(stopArriveTime);
trip.setId(agencyAndId);
trip.setRoute(route);
TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
StopPattern stopPattern = new StopPattern(stopTimes);
TripPattern tripPattern = new TripPattern(route, stopPattern);
TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
when(depart.getTripPattern()).thenReturn(tripPattern);
PatternHop patternHop = new PatternHop(depart, arrive, stopDepart, stopArrive, 0);
when(graph.getEdges()).thenReturn(Collections.<Edge>singletonList(patternHop));
when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
routingRequest.from = new GenericLocation();
routingRequest.startingTransitTripId = agencyAndId;
when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(10);
when(graph.getVertex("Station_0")).thenReturn(station0);
when(graph.getVertex("Station_1")).thenReturn(station1);
tripPattern.add(tripTimes);
graph.index = new GraphIndex(graph);
Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
assertEquals(coordinates[1].x, vertex.getX(), 0.0);
assertEquals(coordinates[1].y, vertex.getY(), 0.0);
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class AlertPatch method remove.
public void remove(Graph graph) {
Agency agency = null;
if (feedId != null) {
Map<String, Agency> agencies = graph.index.agenciesForFeedId.get(feedId);
agency = this.agency != null ? agencies.get(this.agency) : null;
}
Route route = this.route != null ? graph.index.routeForId.get(this.route) : null;
Stop stop = this.stop != null ? graph.index.stopForId.get(this.stop) : null;
Trip trip = this.trip != null ? graph.index.tripForId.get(this.trip) : null;
if (route != null || trip != null || agency != null) {
Collection<TripPattern> tripPatterns = null;
if (trip != null) {
tripPatterns = new LinkedList<TripPattern>();
TripPattern tripPattern = graph.index.patternForTrip.get(trip);
if (tripPattern != null) {
tripPatterns.add(tripPattern);
}
} else if (route != null) {
tripPatterns = graph.index.patternsForRoute.get(route);
} else {
// Find patterns for the feed.
tripPatterns = graph.index.patternsForFeedId.get(feedId);
}
if (tripPatterns != null) {
for (TripPattern tripPattern : tripPatterns) {
if (direction != null && !direction.equals(tripPattern.getDirection())) {
continue;
}
if (directionId != -1 && directionId != tripPattern.directionId) {
continue;
}
for (int i = 0; i < tripPattern.stopPattern.stops.length; i++) {
if (stop == null || stop.equals(tripPattern.stopPattern.stops[i])) {
graph.removeAlertPatch(tripPattern.boardEdges[i], this);
graph.removeAlertPatch(tripPattern.alightEdges[i], this);
}
}
}
}
} else if (stop != null) {
TransitStop transitStop = graph.index.stopVertexForStop.get(stop);
for (Edge edge : transitStop.getOutgoing()) {
if (edge instanceof PreBoardEdge) {
graph.removeAlertPatch(edge, this);
break;
}
}
for (Edge edge : transitStop.getIncoming()) {
if (edge instanceof PreAlightEdge) {
graph.removeAlertPatch(edge, this);
break;
}
}
}
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class BikeAccessTest method testBikesAllowed.
@Test
public void testBikesAllowed() {
Trip trip = new Trip();
Route route = new Route();
trip.setRoute(route);
assertEquals(BikeAccess.UNKNOWN, BikeAccess.fromTrip(trip));
trip.setBikesAllowed(1);
assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(trip));
trip.setBikesAllowed(2);
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccess.fromTrip(trip));
route.setBikesAllowed(1);
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccess.fromTrip(trip));
trip.setBikesAllowed(0);
assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(trip));
route.setBikesAllowed(2);
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccess.fromTrip(trip));
}
Aggregations