public String toDetailsString() { String str = ""; for (int i = 0; i < edgeIds.size(); i++) { if (i > 0) str += "->"; str += edgeIds.get(i); } return toString() + ", found:" + isFound() + ", " + str; }
/** * @return the list of instructions for this path. */ public InstructionList calcInstructions(final Translation tr) { final InstructionList ways = new InstructionList(edgeIds.size() / 4, tr); if (edgeIds.isEmpty()) { if (isFound()) { ways.add(new FinishInstruction(nodeAccess, endNode)); } return ways; } forEveryEdge(new InstructionsFromEdges(getFromNode(), graph, weighting, encoder, nodeAccess, tr, ways)); return ways; }
@Test public void testCalcDistanceDetails() { Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5); assertTrue(p.isFound()); Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[]{DISTANCE}), new PathDetailsBuilderFactory(), 0); assertTrue(details.size() == 1); List<PathDetail> distanceDetails = details.get(DISTANCE); assertEquals(5D, distanceDetails.get(0).getValue()); assertEquals(5D, distanceDetails.get(1).getValue()); assertEquals(10D, distanceDetails.get(2).getValue()); assertEquals(5D, distanceDetails.get(3).getValue()); }
@Test public void testMaxVisitedNodes() { GraphHopperStorage graph = createGHStorage(false); initBiGraph(graph); RoutingAlgorithm algo = createAlgo(graph); Path p = algo.calcPath(0, 4); assertTrue(p.isFound()); algo = createAlgo(graph); algo.setMaxVisitedNodes(3); p = algo.calcPath(0, 4); assertFalse(p.isFound()); }
@Test public void testCalcAverageSpeedDetails() { Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5); assertTrue(p.isFound()); Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[]{AVERAGE_SPEED}), new PathDetailsBuilderFactory(), 0); assertTrue(details.size() == 1); List<PathDetail> averageSpeedDetails = details.get(AVERAGE_SPEED); assertEquals(4, averageSpeedDetails.size()); assertEquals(45.0, averageSpeedDetails.get(0).getValue()); assertEquals(90.0, averageSpeedDetails.get(1).getValue()); assertEquals(10.0, averageSpeedDetails.get(2).getValue()); assertEquals(45.0, averageSpeedDetails.get(3).getValue()); assertEquals(0, averageSpeedDetails.get(0).getFirst()); assertEquals(1, averageSpeedDetails.get(1).getFirst()); assertEquals(2, averageSpeedDetails.get(2).getFirst()); assertEquals(3, averageSpeedDetails.get(3).getFirst()); assertEquals(4, averageSpeedDetails.get(3).getLast()); }
@Test public void testCalcTimeDetails() { Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5); assertTrue(p.isFound()); Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[]{TIME}), new PathDetailsBuilderFactory(), 0); assertTrue(details.size() == 1); List<PathDetail> timeDetails = details.get(TIME); assertEquals(4, timeDetails.size()); assertEquals(400L, timeDetails.get(0).getValue()); assertEquals(200L, timeDetails.get(1).getValue()); assertEquals(3600L, timeDetails.get(2).getValue()); assertEquals(400L, timeDetails.get(3).getValue()); assertEquals(0, timeDetails.get(0).getFirst()); assertEquals(1, timeDetails.get(1).getFirst()); assertEquals(2, timeDetails.get(2).getFirst()); assertEquals(3, timeDetails.get(3).getFirst()); assertEquals(4, timeDetails.get(3).getLast()); }
@Test public void testCalcStreetNameDetails() { Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5); assertTrue(p.isFound()); Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[]{STREET_NAME}), new PathDetailsBuilderFactory(), 0); assertTrue(details.size() == 1); List<PathDetail> streetNameDetails = details.get(STREET_NAME); assertTrue(details.size() == 1); assertEquals(4, streetNameDetails.size()); assertEquals("1-2", streetNameDetails.get(0).getValue()); assertEquals("2-3", streetNameDetails.get(1).getValue()); assertEquals("3-4", streetNameDetails.get(2).getValue()); assertEquals("4-5", streetNameDetails.get(3).getValue()); assertEquals(0, streetNameDetails.get(0).getFirst()); assertEquals(1, streetNameDetails.get(1).getFirst()); assertEquals(2, streetNameDetails.get(2).getFirst()); assertEquals(3, streetNameDetails.get(3).getFirst()); assertEquals(4, streetNameDetails.get(3).getLast()); }
@Test public void testCalcEdgeIdDetails() { Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5); assertTrue(p.isFound()); Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[]{EDGE_ID}), new PathDetailsBuilderFactory(), 0); assertTrue(details.size() == 1); List<PathDetail> edgeIdDetails = details.get(EDGE_ID); assertEquals(4, edgeIdDetails.size()); assertEquals(0, edgeIdDetails.get(0).getValue()); // This is out of order because we don't create the edges in order assertEquals(2, edgeIdDetails.get(1).getValue()); assertEquals(3, edgeIdDetails.get(2).getValue()); assertEquals(1, edgeIdDetails.get(3).getValue()); assertEquals(0, edgeIdDetails.get(0).getFirst()); assertEquals(1, edgeIdDetails.get(1).getFirst()); assertEquals(2, edgeIdDetails.get(2).getFirst()); assertEquals(3, edgeIdDetails.get(3).getFirst()); assertEquals(4, edgeIdDetails.get(3).getLast()); }
/** * case starting in Roundabout */ @Test public void testCalcInstructionsRoundaboutBegin() { Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(2, 8); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); List<String> tmpList = pick("text", wayList.createJson()); assertEquals(Arrays.asList("At roundabout, take exit 3 onto 5-8", "Arrive at destination"), tmpList); }
@Test public void testWeightLimit_issue380() { GraphHopperStorage graph = createGHStorage(false); initGraphWeightLimit(graph); DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(graph); algo.setWeightLimit(3); Path p = algo.calcPath(0, 4); assertTrue(p.isFound()); assertEquals(3.0, p.getWeight(), 1e-6); algo = (DijkstraOneToMany) createAlgo(graph); p = algo.calcPath(0, 3); assertTrue(p.isFound()); assertEquals(3.0, p.getWeight(), 1e-6); }
@Test public void testCalcInstructionsIgnoreContinue() { // Follow a couple of straight edges, including a name change Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(4, 11); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // Contain only start and finish instruction, no CONTINUE assertEquals(2, wayList.size()); }
@Test public void testCalcInstructionsIgnoreTurnIfNoAlternative() { // The street turns left, but there is not turn Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(10, 12); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // Contain only start and finish instruction assertEquals(2, wayList.size()); }
@Test public void testIgnoreInstructionsForSlightTurnWithOtherTurn() { // Test for a fork with one sligh turn and one actual turn. We are going along the slight turn. No turn instruction needed in this case Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(16, 19); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // Contain start, and finish instruction assertEquals(2, wayList.size()); }
@Test public void testDisconnectedAreas() { Graph g = createTestGraph(true, em); // one single disconnected node updateDistancesFor(g, 20, 0.00, -0.01); Weighting weighting = new FastestWeighting(carFE); AlternativeBidirSearch altDijkstra = new AlternativeBidirSearch(g, weighting, traversalMode, 1); Path path = altDijkstra.calcPath(1, 20); assertFalse(path.isFound()); // make sure not the full graph is traversed! assertEquals(3, altDijkstra.getVisitedNodes()); } }
/** * case with one node being containig already exit */ @Test public void testCalcInstructionsRoundaboutDirectExit() { roundaboutGraph.inverse3to9(); Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(6, 8); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); List<String> tmpList = pick("text", wayList.createJson()); assertEquals(Arrays.asList("Continue onto 3-6", "At roundabout, take exit 3 onto 5-8", "Arrive at destination"), tmpList); roundaboutGraph.inverse3to9(); }
@Test public void testCalcInstructionsForTurn() { // The street turns left, but there is not turn Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(11, 13); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // Contain start, turn, and finish instruction assertEquals(3, wayList.size()); // Assert turn right assertEquals(2, wayList.get(1).getSign()); }
@Test public void testCalcInstructionsForSlightTurnWithOtherSlightTurn() { // Test for a fork with two sligh turns. Since there are two sligh turns, show the turn instruction Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(12, 16); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // Contain start, turn, and finish instruction assertEquals(3, wayList.size()); // Assert turn right assertEquals(7, wayList.get(1).getSign()); }
/** * clockwise roundabout */ @Test public void testCalcInstructionsRoundaboutClockwise() { roundaboutGraph.setRoundabout(true); Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 8); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); List<String> tmpList = pick("text", wayList.createJson()); assertEquals(Arrays.asList("Continue onto MainStreet 1 2", "At roundabout, take exit 1 onto 5-8", "Arrive at destination"), tmpList); // Test Radian double delta = roundaboutGraph.getAngle(1, 2, 5, 8); RoundaboutInstruction instr = (RoundaboutInstruction) wayList.get(1); assertEquals(delta, instr.getTurnAngle(), 0.01); }
@Test public void testFound() { GraphHopperStorage g = new GraphBuilder(carManager).create(); Path p = new Path(g, new FastestWeighting(encoder)); assertFalse(p.isFound()); assertEquals(0, p.getDistance(), 1e-7); assertEquals(0, p.calcNodes().size()); g.close(); }
@Test public void testCalcInstructionsForDataFlagEncoder() { final Graph g = new GraphBuilder(dataFlagManager).create(); final NodeAccess na = g.getNodeAccess(); na.setNode(1, 48.982618, 13.122021); na.setNode(2, 48.982565, 13.121597); na.setNode(3, 48.982611, 13.121012); na.setNode(4, 48.982336, 13.121002); ReaderWay w = new ReaderWay(1); w.setTag("highway", "tertiary"); g.edge(1, 2, 5, true).setFlags(dataFlagEncoder.handleWayTags(w, 1, 0)); g.edge(2, 4, 5, true).setFlags(dataFlagEncoder.handleWayTags(w, 1, 0)); g.edge(2, 3, 5, true).setFlags(dataFlagEncoder.handleWayTags(w, 1, 0)); Path p = new Dijkstra(g, new GenericWeighting(dataFlagEncoder, new HintsMap()), TraversalMode.NODE_BASED).calcPath(1, 3); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); }