protected GraphHopperStorage createMatrixGraph() { return createMatrixAlikeGraph(createGHStorage(false)); } }
protected GraphHopperStorage createGHStorage(boolean is3D) { return createGHStorage(encodingManager, Arrays.asList(defaultOpts.getWeighting()), is3D); }
@Test public void testQueryGraphAndFastest() { Weighting weighting = new FastestWeighting(carEncoder); GraphHopperStorage graph = createGHStorage(encodingManager, Arrays.asList(weighting), false); initDirectedAndDiffSpeed(graph, carEncoder); Path p = calcPathViaQuery(weighting, graph, 0.002, 0.0005, 0.0017, 0.0031); assertEquals(IntArrayList.from(new int[]{8, 1, 5, 3, 9}), p.calcNodes()); assertEquals(602.98, p.getDistance(), 1e-1); }
@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 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()); }
protected GraphHopperStorage createWikipediaTestGraph() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 7, true); graph.edge(0, 2, 9, true); graph.edge(0, 5, 14, true); graph.edge(1, 2, 10, true); graph.edge(1, 3, 15, true); graph.edge(2, 5, 2, true); graph.edge(2, 3, 11, true); graph.edge(3, 4, 6, true); graph.edge(4, 5, 9, true); return graph; }
@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 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 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 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 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 testTwoWeightsPerEdge() { FlagEncoder encoder = new Bike2WeightFlagEncoder(); EncodingManager em = new EncodingManager(encoder); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new FastestWeighting(encoder)).build(); GraphHopperStorage graph = createGHStorage(em, Arrays.asList(opts.getWeighting()), true); initEleGraph(graph); // force the other path GHUtility.getEdge(graph, 0, 3).setFlags(encoder.setProperties(10, false, true)); // for two weights per edge it happened that Path (and also the Weighting) read the wrong side // of the speed and read 0 => infinity weight => overflow of millis => negative millis! Path p = createAlgo(graph, opts). calcPath(0, 10); assertEquals(85124371, p.getTime()); assertEquals(425622, p.getDistance(), 1); assertEquals(85124.4, p.getWeight(), 1); }
@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()); }
@Test public void testViaEdges_BiGraph() { GraphHopperStorage graph = createGHStorage(false); initBiGraph(graph); // 0-7 to 4-3 Path p = calcPathViaQuery(graph, 0.0009, 0, 0.001, 0.001105); assertEquals(p.toString(), IntArrayList.from(new int[]{10, 7, 6, 8, 3, 9}), p.calcNodes()); assertEquals(p.toString(), 324.11, p.getDistance(), 0.01); // 0-1 to 2-3 p = calcPathViaQuery(graph, 0.001, 0.0001, 0.010, 0.0011); assertEquals(p.toString(), IntArrayList.from(new int[]{0, 7, 6, 8, 3, 9}), p.calcNodes()); assertEquals(p.toString(), 1335.35, p.getDistance(), 0.01); }
@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 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 testMultipleVehicles_issue548() { FastestWeighting footWeighting = new FastestWeighting(footEncoder); AlgorithmOptions footOptions = AlgorithmOptions.start(). weighting(footWeighting).build(); FastestWeighting carWeighting = new FastestWeighting(carEncoder); AlgorithmOptions carOptions = AlgorithmOptions.start(). weighting(carWeighting).build(); GraphHopperStorage ghStorage = createGHStorage(encodingManager, Arrays.asList(footOptions.getWeighting(), carOptions.getWeighting()), false); initFootVsCar(ghStorage); // normal path would be 0-4-6-7 but block 4-6 GHUtility.getEdge(ghStorage, 4, 6).setFlags(carEncoder.setProperties(20, false, false)); RoutingAlgorithm algoFoot = createFactory(ghStorage, footOptions). createAlgo(getGraph(ghStorage, footWeighting), footOptions); RoutingAlgorithm algoCar = createFactory(ghStorage, carOptions). createAlgo(getGraph(ghStorage, carWeighting), carOptions); Path p1 = algoCar.calcPath(0, 7); assertEquals(IntArrayList.from(new int[]{0, 1, 5, 6, 7}), p1.calcNodes()); assertEquals(p1.toString(), 26000, p1.getDistance(), 1e-6); }
@Test public void testBidirectional2() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 100, true); graph.edge(1, 2, 1, true); graph.edge(2, 3, 1, true); graph.edge(3, 4, 1, true); graph.edge(4, 5, 20, true); graph.edge(5, 6, 10, true); graph.edge(6, 7, 5, true); graph.edge(7, 0, 5, true); graph.edge(3, 8, 20, true); graph.edge(8, 6, 20, true); Path p = createAlgo(graph).calcPath(0, 4); assertEquals(p.toString(), 40, p.getDistance(), 1e-4); assertEquals(p.toString(), 5, p.calcNodes().size()); assertEquals(IntArrayList.from(new int[]{0, 7, 6, 5, 4}), p.calcNodes()); }