@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 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 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()); }
@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()); }
/** * 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 testEmptyList() { Graph g = new GraphBuilder(carManager).create(); Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(0, 1); InstructionList il = p.calcInstructions(usTR); assertEquals(0, il.size()); assertEquals(0, il.createStartPoints().size()); }
@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()); }
/** * 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(); }
/** * 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 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()); }
/** * case with one edge being not an exit */ @Test public void testCalcInstructionsRoundabout2() { roundaboutGraph.inverse3to6(); 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 2 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); roundaboutGraph.inverse3to6(); }
@Test public void testShortestPathSkipNode2() { createExampleGraph(); final double normalDist = new Dijkstra(graph, weighting, traversalMode).calcPath(4, 2).getDistance(); assertEquals(3, normalDist, 1e-5); DijkstraOneToMany algo = new DijkstraOneToMany(graph, weighting, traversalMode); setMaxLevelOnAllNodes(); algo.setEdgeFilter(createIgnoreNodeFilter(3)); algo.setWeightLimit(10); int nodeEntry = algo.findEndNode(4, 2); assertEquals(4, algo.getWeight(nodeEntry), 1e-5); nodeEntry = algo.findEndNode(4, 1); assertEquals(4, algo.getWeight(nodeEntry), 1e-5); }
@Test public void testShortestPathSkipNode() { createExampleGraph(); final double normalDist = new Dijkstra(graph, weighting, traversalMode).calcPath(4, 2).getDistance(); DijkstraOneToMany algo = new DijkstraOneToMany(graph, weighting, traversalMode); CHGraph lg = graph.getGraph(CHGraph.class); setMaxLevelOnAllNodes(); algo.setEdgeFilter(createIgnoreNodeFilter(3)); algo.setWeightLimit(100); int nodeEntry = algo.findEndNode(4, 2); assertTrue(algo.getWeight(nodeEntry) > normalDist); algo.clear(); algo.setMaxVisitedNodes(1); nodeEntry = algo.findEndNode(4, 2); assertEquals(-1, nodeEntry); }
@Test public void testCalcInstructionContinueLeavingStreet() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // When leaving the current street via a Continue, we should show it // 3 // \ // 4 - 2 -- 1 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.982565, 13.121002); g.edge(1, 2, 5, true).setName("Regener Weg"); g.edge(2, 4, 5, true); g.edge(2, 3, 5, true).setName("Regener Weg"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 4); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(-7, wayList.get(1).getSign()); }
@Test public void testCalcInstructionsOntoOneway() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Actual example: point=-33.824566%2C151.187834&point=-33.82441%2C151.188231 // 1 -2 -3 is a oneway // 1 ->- 2 ->- 3 // | // 4 na.setNode(1, -33.824245, 151.187866); na.setNode(2, -33.824335, 151.188017); na.setNode(3, -33.824415, 151.188177); na.setNode(4, -33.824437, 151.187925); g.edge(1, 2, 5, false).setName("Pacific Highway"); g.edge(2, 3, 5, false).setName("Pacific Highway"); g.edge(4, 2, 5, true).setName("Greenwich Road"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(4, 3); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(2, wayList.get(1).getSign()); }
@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()); }