@Override public String toString() { return "distance:" + getDistance() + ", edges:" + edgeIds.size(); }
void checkPath(GraphHopperStorage g, Weighting w, int expShortcuts, double expDistance, IntIndexedContainer expNodes) { CHGraph lg = g.getGraph(CHGraph.class, w); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg, w); prepare.doWork(); assertEquals(w.toString(), expShortcuts, prepare.getShortcuts()); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, w, tMode)); Path p = algo.calcPath(3, 12); assertEquals(w.toString(), expDistance, p.getDistance(), 1e-5); assertEquals(w.toString(), expNodes, p.calcNodes()); }
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 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 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 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); }
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 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 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 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 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 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 testUnpackingOrder() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initUnpackingGraph(g, lg, weighting); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(10, 6); assertEquals(7, p.getDistance(), 1e-5); assertEquals(IntArrayList.from(10, 0, 1, 2, 3, 4, 5, 6), p.calcNodes()); }
@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 testUnpackingOrder_Fastest() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); Weighting w = new FastestWeighting(carEncoder); initUnpackingGraph(g, lg, w); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(10, 6); assertEquals(7, p.getDistance(), 1e-1); assertEquals(IntArrayList.from(10, 0, 1, 2, 3, 4, 5, 6), p.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 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 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 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()); }