public void testRoutingOverMidnight() throws Exception { // this route only runs on weekdays Vertex stop_g = graph.getVertex("agency:G_depart"); Vertex stop_h = graph.getVertex("agency:H_arrive"); ShortestPathTree spt; GraphPath path; RoutingRequest options = new RoutingRequest(); // Friday evening options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 23, 20, 0); options.setRoutingContext(graph, stop_g, stop_h); spt = aStar.getShortestPathTree(options); path = spt.getPath(stop_h, false); assertNotNull(path); assertEquals(4, path.states.size()); // Saturday morning long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 0, 5, 0); options.dateTime = startTime; options.setRoutingContext(graph, stop_g.getLabel(), stop_h.getLabel()); spt = aStar.getShortestPathTree(options); path = spt.getPath(stop_h, false); assertNotNull(path); assertEquals(4, path.states.size()); long endTime = path.getEndTime(); assertTrue(endTime < startTime + 60 * 60); }
/** Generates a TripPlan from a set of paths */ public TripPlan generatePlan(List<GraphPath> paths, RoutingRequest request) { GraphPath exemplar = paths.get(0); Vertex tripStartVertex = exemplar.getStartVertex(); Vertex tripEndVertex = exemplar.getEndVertex(); String startName = tripStartVertex.getName(); String endName = tripEndVertex.getName(); // Use vertex labels if they don't have names if (startName == null) { startName = tripStartVertex.getLabel(); } if (endName == null) { endName = tripEndVertex.getLabel(); } Place from = new Place(tripStartVertex.getX(), tripStartVertex.getY(), startName); Place to = new Place(tripEndVertex.getX(), tripEndVertex.getY(), endName); TripPlan plan = new TripPlan(from, to, request.getDateTime()); for (GraphPath path : paths) { Itinerary itinerary = generateItinerary(path, request.getShowIntermediateStops()); plan.addItinerary(itinerary); } return plan; }
public void testIntermediate() throws Exception { Vertex v1 = getVertexByCrossStreets("NW 10TH AVE", "W BURNSIDE ST"); Vertex v2 = getVertexByCrossStreets("SE 82ND AVE", "SE ASH ST") .getOutgoing() .iterator() .next() .getToVertex(); Vertex v3 = getVertexByCrossStreets("NE 21ST AVE", "NE MASON ST") .getOutgoing() .iterator() .next() .getToVertex(); Vertex v4 = getVertexByCrossStreets("SE 92ND AVE", "SE FLAVEL ST"); Vertex[] vertices = {v1, v3, v2, v4}; assertNotNull(v1); assertNotNull(v2); assertNotNull(v3); assertNotNull(v4); TestPlanner planner = new TestPlanner( "portland", v1.getLabel(), v4.getLabel(), Arrays.asList(v2.getLabel(), v3.getLabel())); List<GraphPath> paths = planner.getPaths(); assertTrue(paths.size() > 0); GraphPath path = paths.get(0); int curVertex = 0; for (State s : path.states) { if (s.getVertex().equals(vertices[curVertex])) { curVertex += 1; } } assertEquals(4, curVertex); // found all four, in the correct order (1, 3, 2, 4) }
public void testRunForTrain() { /** * This is the notorious Byrd bug: we're going from Q to T at 8:30. There's a trip from S to T * at 8:50 and a second one at 9:50. To get to S by 8:50, we need to take trip 12.1 from Q to R, * and 13.1 from R to S. If we take the direct-but-slower 11.1, we'll miss the 8:50 and have to * catch the 9:50. */ Vertex destination = graph.getVertex("agency:T"); RoutingRequest options = new RoutingRequest(); // test is designed such that transfers must be instantaneous options.transferSlack = (0); GregorianCalendar startTime = new GregorianCalendar(2009, 11, 2, 8, 30, 0); startTime.setTimeZone(TimeZone.getTimeZone("America/New_York")); options.dateTime = TestUtils.toSeconds(startTime); options.setRoutingContext(graph, "agency:Q", destination.getLabel()); ShortestPathTree spt = aStar.getShortestPathTree(options); GraphPath path = spt.getPath(destination, false); long endTime = path.getEndTime(); Calendar c = new GregorianCalendar(); c.setTimeInMillis(endTime * 1000L); assertTrue(endTime - TestUtils.toSeconds(startTime) < 7200); }
public void testAddVertex() throws Exception { Graph g = new Graph(); Vertex a = new IntersectionVertex(g, "A", 5, 5); assertEquals(a.getLabel(), "A"); }