protected final RoutingAlgorithm createAlgo(GraphHopperStorage g) { return createAlgo(g, defaultOpts); }
@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()); }
public void testCorrectWeight(GraphHopperStorage g) { Path p = createAlgo(g).calcPath(45, 72); assertEquals(IntArrayList.from(new int[]{45, 44, 54, 64, 74, 73, 72}), p.calcNodes()); assertEquals(38f, p.getDistance(), 1e-3); }
@Test public void test0SpeedButUnblocked_Issue242() { GraphHopperStorage graph = createGHStorage(false); long flags = carEncoder.setAccess(carEncoder.setSpeed(0, 0), true, true); graph.edge(0, 1).setFlags(flags).setDistance(10); graph.edge(1, 2).setFlags(flags).setDistance(10); RoutingAlgorithm algo = createAlgo(graph); try { Path p = algo.calcPath(0, 2); assertTrue(false); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Speed cannot be 0")); } }
@Test public void testCalcIfEmptyWay() { Path p = createAlgo(createTestStorage()).calcPath(0, 0); assertEquals(p.calcNodes().toString(), 1, p.calcNodes().size()); assertEquals(p.toString(), 0, p.getDistance(), 1e-4); }
public void testBug1(GraphHopperStorage g) { Path p = createAlgo(g).calcPath(34, 36); assertEquals(IntArrayList.from(new int[]{34, 35, 36}), p.calcNodes()); assertEquals(3, p.calcNodes().size()); assertEquals(17, p.getDistance(), 1e-5); }
@Test public void testCalcIf1EdgeAway() { Path p = createAlgo(createTestStorage()).calcPath(1, 2); assertEquals(IntArrayList.from(new int[]{1, 2}), p.calcNodes()); assertEquals(p.toString(), 35.1, p.getDistance(), .1); }
@Test public void testCannotCalculateSP() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, false); graph.edge(1, 2, 1, false); Path p = createAlgo(graph).calcPath(0, 2); assertEquals(p.toString(), 3, p.calcNodes().size()); }
@Test public void testWikipediaShortestPath() { GraphHopperStorage ghStorage = createWikipediaTestGraph(); Path p = createAlgo(ghStorage).calcPath(0, 4); assertEquals(p.toString(), IntArrayList.from(new int[]{0, 2, 5, 4}), p.calcNodes()); assertEquals(p.toString(), 20, p.getDistance(), 1e-4); }
@Test public void testDirectedGraphBug2() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, false); graph.edge(1, 2, 1, false); graph.edge(2, 3, 1, false); graph.edge(3, 1, 4, true); Path p = createAlgo(graph).calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 1, 2, 3}), p.calcNodes()); }
@Test public void testBidirectional() { GraphHopperStorage graph = createGHStorage(false); initBiGraph(graph); // PrepareTowerNodesShortcutsTest.printEdges((CHGraph) graph); Path p = createAlgo(graph).calcPath(0, 4); // PrepareTowerNodesShortcutsTest.printEdges((CHGraph) graph); assertEquals(p.toString(), IntArrayList.from(new int[]{0, 7, 6, 8, 3, 4}), p.calcNodes()); assertEquals(p.toString(), 335.8, p.getDistance(), .1); p = createAlgo(graph).calcPath(1, 2); // the other way around is even larger as 0-1 is already 11008.452 assertEquals(p.toString(), IntArrayList.from(new int[]{1, 2}), p.calcNodes()); assertEquals(p.toString(), 10007.7, p.getDistance(), .1); }
@Test public void testCalcShortestPath() { GraphHopperStorage ghStorage = createTestStorage(); RoutingAlgorithm algo = createAlgo(ghStorage); Path p = algo.calcPath(0, 7); assertEquals(p.toString(), IntArrayList.from(new int[]{0, 4, 5, 7}), p.calcNodes()); assertEquals(p.toString(), 62.1, p.getDistance(), .1); }
@Test public void testCreateAlgoTwice() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, true); graph.edge(1, 2, 1, true); graph.edge(2, 3, 1, true); graph.edge(3, 4, 1, true); graph.edge(4, 5, 1, true); graph.edge(5, 6, 1, true); graph.edge(6, 7, 1, true); graph.edge(7, 0, 1, true); graph.edge(3, 8, 1, true); graph.edge(8, 6, 1, true); // run the same query twice, this can be interesting because in the second call algorithms that pre-process // the graph might depend on the state of the graph after the first call Path p1 = createAlgo(graph).calcPath(0, 4); Path p2 = createAlgo(graph).calcPath(0, 4); assertEquals(p1.calcNodes(), p2.calcNodes()); }
@Test public void testCalcFootPath() { AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new ShortestWeighting(footEncoder)).build(); GraphHopperStorage ghStorage = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), false); initFootVsCar(ghStorage); Path p1 = createAlgo(ghStorage, opts). calcPath(0, 7); assertEquals(p1.toString(), 17000, p1.getDistance(), 1e-6); assertEquals(p1.toString(), 12240 * 1000, p1.getTime()); assertEquals(IntArrayList.from(new int[]{0, 4, 5, 7}), p1.calcNodes()); }
@Test public void testRekeyBugOfIntBinHeap() { // using Dijkstra + IntBinHeap then rekey loops endlessly GraphHopperStorage matrixGraph = createMatrixGraph(); Path p = createAlgo(matrixGraph).calcPath(36, 91); assertEquals(12, p.calcNodes().size()); IntIndexedContainer list = p.calcNodes(); if (!IntArrayList.from(new int[]{36, 46, 56, 66, 76, 86, 85, 84, 94, 93, 92, 91}).equals(list) && !IntArrayList.from(new int[]{36, 46, 56, 66, 76, 86, 85, 84, 83, 82, 92, 91}).equals(list)) { assertTrue("wrong locations: " + list.toString(), false); } assertEquals(66f, p.getDistance(), 1e-3); testBug1(matrixGraph); testCorrectWeight(matrixGraph); }
@Test public void testCalcShortestPath_sourceEqualsTarget() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, true); graph.edge(1, 2, 2, true); RoutingAlgorithm algo = createAlgo(graph); Path p = algo.calcPath(0, 0); assertEquals(p.toString(), IntArrayList.from(new int[]{0}), p.calcNodes()); assertEquals(p.toString(), 0, p.getDistance(), 1.e-6); }
@Test public void testBidirectionalLinear() { //3--2--1--4--5 GraphHopperStorage graph = createGHStorage(false); graph.edge(2, 1, 2, true); graph.edge(2, 3, 11, true); graph.edge(5, 4, 6, true); graph.edge(4, 1, 9, true); Path p = createAlgo(graph).calcPath(3, 5); assertEquals(p.toString(), 28, p.getDistance(), 1e-4); assertEquals(IntArrayList.from(new int[]{3, 2, 1, 4, 5}), p.calcNodes()); }
@Test public void testCalcFastestPath() { GraphHopperStorage graphShortest = createGHStorage(false); initDirectedAndDiffSpeed(graphShortest, carEncoder); Path p1 = createAlgo(graphShortest, defaultOpts). calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 1, 5, 2, 3}), p1.calcNodes()); assertEquals(p1.toString(), 402.3, p1.getDistance(), .1); assertEquals(p1.toString(), 144823, p1.getTime()); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new FastestWeighting(carEncoder)).build(); GraphHopperStorage graphFastest = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), false); initDirectedAndDiffSpeed(graphFastest, carEncoder); Path p2 = createAlgo(graphFastest, opts). calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 4, 6, 7, 5, 3}), p2.calcNodes()); assertEquals(p2.toString(), 1261.7, p2.getDistance(), 0.1); assertEquals(p2.toString(), 111442, p2.getTime()); }
@Test public void testSimpleAlternative() { // 0--2--1 // | | // 3--4 GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 2, 9, true); graph.edge(2, 1, 2, true); graph.edge(2, 3, 11, true); graph.edge(3, 4, 6, true); graph.edge(4, 1, 9, true); Path p = createAlgo(graph).calcPath(0, 4); assertEquals(p.toString(), 20, p.getDistance(), 1e-4); assertEquals(IntArrayList.from(new int[]{0, 2, 1, 4}), p.calcNodes()); }
@Test public void testDirectedGraphBug1() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 3, false); graph.edge(1, 2, 2.99, false); graph.edge(0, 3, 2, false); graph.edge(3, 4, 3, false); graph.edge(4, 2, 1, false); Path p = createAlgo(graph).calcPath(0, 2); assertEquals(IntArrayList.from(new int[]{0, 1, 2}), p.calcNodes()); assertEquals(p.toString(), 5.99, p.getDistance(), 1e-4); assertEquals(p.toString(), 3, p.calcNodes().size()); }