public void testBoardAlight() throws Exception { Vertex stop_a_depart = graph.getVertex("agency:A_depart"); Vertex stop_b_depart = graph.getVertex("agency:B_depart"); assertEquals(1, stop_a_depart.getDegreeOut()); assertEquals(3, stop_b_depart.getDegreeOut()); for (Edge e : stop_a_depart.getOutgoing()) { assertEquals(TransitBoardAlight.class, e.getClass()); assertTrue(((TransitBoardAlight) e).boarding); } TransitBoardAlight pb = (TransitBoardAlight) stop_a_depart.getOutgoing().iterator().next(); Vertex journey_a_1 = pb.getToVertex(); assertEquals(1, journey_a_1.getDegreeIn()); for (Edge e : journey_a_1.getOutgoing()) { if (e.getToVertex() instanceof TransitStop) { assertEquals(TransitBoardAlight.class, e.getClass()); } else { assertEquals(PatternHop.class, e.getClass()); } } }
@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 : filter(graph.getVertices(), TransitStopDepart.class)) { for (TransitBoardAlight tba : filter(tsd.getOutgoing(), TransitBoardAlight.class)) { if (!tba.isBoarding()) 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; }
/* Somewhat hackish convenience method to grab a hop edge on a particular route leaving a particular stop. */ private PatternHop getHopEdge(String stopId, String routeId) { Vertex stopDepartVertex = graph.getVertex("agency:" + stopId + "_depart"); for (Edge edge : stopDepartVertex.getOutgoing()) { if (edge instanceof TransitBoardAlight) { TransitBoardAlight tba = ((TransitBoardAlight) edge); if (tba.boarding && tba.getPattern().route.getId().getId().equals(routeId)) { for (Edge edge2 : tba.getToVertex().getOutgoing()) { if (edge2 instanceof PatternHop) { return (PatternHop) edge2; } } } } } return null; }
public void testBoardAlightStopIndex() { Vertex stop_b_arrive = graph.getVertex("agency:C_arrive"); Vertex stop_b_depart = graph.getVertex("agency:C_depart"); Map<TripPattern, Integer> stopIndex = new HashMap<TripPattern, Integer>(); for (Edge edge : stop_b_depart.getOutgoing()) { TransitBoardAlight tba = (TransitBoardAlight) edge; stopIndex.put(tba.getPattern(), tba.getStopIndex()); } for (Edge edge : stop_b_arrive.getIncoming()) { TransitBoardAlight tba = (TransitBoardAlight) edge; if (stopIndex.containsKey(tba.getPattern())) assertEquals((Integer) stopIndex.get(tba.getPattern()), new Integer(tba.getStopIndex())); } }