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; }
@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 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 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_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 testCalcIfEmptyWay() { Path p = createAlgo(createTestStorage()).calcPath(0, 0); assertEquals(p.calcNodes().toString(), 1, p.calcNodes().size()); assertEquals(p.toString(), 0, p.getDistance(), 1e-4); }
@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 testViaEdges_WithCoordinates() { GraphHopperStorage ghStorage = createTestStorage(); Path p = calcPath(ghStorage, 0, 1, 2, 3); assertEquals(IntArrayList.from(new int[]{8, 1, 2, 9}), p.calcNodes()); assertEquals(p.toString(), 56.7, p.getDistance(), .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 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 testViaEdges_FromEqualsTo() { GraphHopperStorage ghStorage = createTestStorage(); // identical tower nodes Path p = calcPathViaQuery(ghStorage, 0.001, 0.000, 0.001, 0.000); assertTrue(p.isFound()); assertEquals(IntArrayList.from(new int[]{0}), p.calcNodes()); // assertEquals(1, p.calcPoints().size()); assertEquals(p.toString(), 0, p.getDistance(), 1e-4); // identical query points on edge p = calcPath(ghStorage, 0, 1, 0, 1); assertTrue(p.isFound()); assertEquals(IntArrayList.from(new int[]{8}), p.calcNodes()); // assertEquals(1, p.calcPoints().size()); assertEquals(p.toString(), 0, p.getDistance(), 1e-4); // very close p = calcPathViaQuery(ghStorage, 0.00092, 0, 0.00091, 0); assertEquals(IntArrayList.from(new int[]{8, 9}), p.calcNodes()); assertEquals(p.toString(), 1.11, p.getDistance(), .1); }
@Test public void testBaseGraph() { CarFlagEncoder carFE = new CarFlagEncoder(); EncodingManager em = new EncodingManager(carFE); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new ShortestWeighting(carFE)).build(); GraphHopperStorage ghStorage = createGHStorage(em, Arrays.asList(opts.getWeighting()), false); initDirectedAndDiffSpeed(ghStorage, carFE); // do CH preparation for car createFactory(ghStorage, opts); // use base graph for solving normal Dijkstra Path p1 = new RoutingAlgorithmFactorySimple().createAlgo(ghStorage, defaultOpts).calcPath(0, 3); assertEquals(IntArrayList.from(0, 1, 5, 2, 3), p1.calcNodes()); assertEquals(p1.toString(), 402.29, p1.getDistance(), 1e-2); assertEquals(p1.toString(), 144823, p1.getTime()); }
@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 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()); }
@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()); }
private void runTestWithDirectionDependentEdgeSpeed( int speed, int revSpeed, int from, int to, IntArrayList expectedPath, FlagEncoder encoder) { EncodingManager encodingManager = new EncodingManager(encoder); FastestWeighting weighting = new FastestWeighting(encoder); AlgorithmOptions algoOpts = AlgorithmOptions.start().weighting(weighting).build(); GraphHopperStorage graph = createGHStorage(encodingManager, Arrays.asList(weighting), false); EdgeIteratorState edge = graph.edge(0, 1, 2, true); long flags = edge.getFlags(); flags = encoder.setSpeed(flags, speed); flags = encoder.setReverseSpeed(flags, revSpeed); edge.setFlags(flags); graph.edge(1, 2, 1, true); CHGraph chGraph = graph.getGraph(CHGraph.class); for (int i = 0; i < 3; ++i) { chGraph.setLevel(i, i); } graph.freeze(); RoutingAlgorithm algo = createCHAlgo(graph, chGraph, true, algoOpts); Path p = algo.calcPath(from, to); assertEquals(3, p.getDistance(), 1.e-3); assertEquals(p.toString(), expectedPath, p.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); }