private Path calcPath(RoutingAlgorithm algo) { // int from = index.findID(50.042, 10.19); // int to = index.findID(50.049, 10.23); // //// System.out.println("path " + from + "->" + to); // return algo.calcPath(from, to); // System.out.println(GraphUtility.getNodeInfo(graph, 60139, DefaultEdgeFilter.allEdges(new CarFlagEncoder()).direction(false, true))); // System.out.println(((GraphStorage) graph).debug(202947, 10)); // GraphUtility.printInfo(graph, 106511, 10); return algo.calcPath(162810, 35120); }
@Override public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, AlgorithmOptions algoOpts) { pathList = new ArrayList<>(queryResults.size() - 1); AvoidEdgesWeighting avoidPathWeighting = new AvoidEdgesWeighting(algoOpts.getWeighting()); avoidPathWeighting.setEdgePenaltyFactor(5); algoOpts = AlgorithmOptions.start(algoOpts). algorithm(Parameters.Algorithms.ASTAR_BI). weighting(avoidPathWeighting).build(); algoOpts.getHints().put(Algorithms.AStarBi.EPSILON, 2); long visitedNodesSum = 0L; QueryResult start = queryResults.get(0); for (int qrIndex = 1; qrIndex < queryResults.size(); qrIndex++) { RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, algoOpts); // instead getClosestNode (which might be a virtual one and introducing unnecessary tails of the route) // use next tower node -> getBaseNode or getAdjNode // Later: remove potential route tail QueryResult startQR = queryResults.get(qrIndex - 1); int startNode = (startQR == start) ? startQR.getClosestNode() : startQR.getClosestEdge().getBaseNode(); QueryResult endQR = queryResults.get(qrIndex); int endNode = (endQR == start) ? endQR.getClosestNode() : endQR.getClosestEdge().getBaseNode(); Path path = algo.calcPath(startNode, endNode); visitedNodesSum += algo.getVisitedNodes(); pathList.add(path); // it is important to avoid previously visited nodes for future paths avoidPathWeighting.addEdges(path.calcEdges()); } ghResponse.getHints().put("visited_nodes.sum", visitedNodesSum); ghResponse.getHints().put("visited_nodes.average", (float) visitedNodesSum / (queryResults.size() - 1)); return pathList; }
@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()); }
List<Path> tmpPathList = algo.calcPaths(fromQResult.getClosestNode(), toQResult.getClosestNode()); debug += ", " + algo.getName() + "-routing:" + sw.stop().getSeconds() + "s"; if (tmpPathList.isEmpty()) throw new IllegalStateException("At least one path has to be returned for " + fromQResult + " -> " + toQResult); if (algo.getVisitedNodes() >= algoOpts.getMaxVisitedNodes()) throw new IllegalArgumentException("No path found due to maximum nodes exceeded " + algoOpts.getMaxVisitedNodes()); visitedNodesSum += algo.getVisitedNodes(); altResponse.addDebugInfo("visited nodes sum: " + visitedNodesSum); fromQResult = toQResult;
ra.setMaxVisitedNodes(opts.getMaxVisitedNodes()); return ra;
List<Path> tmpPathList = algo.calcPaths(fromQResult.getClosestNode(), toQResult.getClosestNode()); debug += ", " + algo.getName() + "-routing:" + sw.stop().getSeconds() + "s"; if (tmpPathList.isEmpty()) throw new IllegalStateException("At least one path has to be returned for " + fromQResult + " -> " + toQResult); if (algo.getVisitedNodes() >= algoOpts.getMaxVisitedNodes()) throw new IllegalArgumentException("No path found due to maximum nodes exceeded " + algoOpts.getMaxVisitedNodes()); visitedNodesSum += algo.getVisitedNodes(); fromQResult = toQResult;
ra.setMaxVisitedNodes(opts.getMaxVisitedNodes()); return ra;
@Test public void testUseCacheZeroPath_issue707() { RoutingAlgorithm algo = createAlgo(createTestStorage()); Path p = algo.calcPath(0, 0); assertEquals(0, p.distance, 0.00000); p = algo.calcPath(0, 4); assertEquals(IntArrayList.from(new int[]{0, 4}), p.calcNodes()); // expand SPT p = algo.calcPath(0, 7); assertEquals(IntArrayList.from(new int[]{0, 4, 5, 7}), p.calcNodes()); // use SPT p = algo.calcPath(0, 2); assertEquals(IntArrayList.from(new int[]{0, 1, 2}), p.calcNodes()); }
path = algo.calcPath(fromRes.getClosestNode(), toRes.getClosestNode()); sw.stop(); + ", visited nodes:" + algo.getVisitedNodes()); g2.setColor(red); plotPath(path, g2, 4);
List<Path> tmpPathList = algo.calcPaths(fromQResult.getClosestNode(), toQResult.getClosestNode()); debug += ", " + algo.getName() + "-routing:" + sw.stop().getSeconds() + "s"; if (tmpPathList.isEmpty()) throw new IllegalStateException("At least one path has to be returned for " + fromQResult + " -> " + toQResult); if (algo.getVisitedNodes() >= algoOpts.getMaxVisitedNodes()) throw new IllegalArgumentException("No path found due to maximum nodes exceeded " + algoOpts.getMaxVisitedNodes()); visitedNodesSum += algo.getVisitedNodes(); fromQResult = toQResult;
router.setMaxVisitedNodes(maxVisitedNodes); } else { router = new DijkstraBidirectionRef(queryGraph, weighting, TraversalMode.NODE_BASED) { router.setMaxVisitedNodes(maxVisitedNodes); final Path path = router.calcPath(from.getQueryResult().getClosestNode(), to.getQueryResult().getClosestNode());
ra.setMaxVisitedNodes(opts.getMaxVisitedNodes()); return ra;
@Test public void testUseCache() { RoutingAlgorithm algo = createAlgo(createTestStorage()); Path p = algo.calcPath(0, 4); assertEquals(IntArrayList.from(new int[]{0, 4}), p.calcNodes()); // expand SPT p = algo.calcPath(0, 7); assertEquals(IntArrayList.from(new int[]{0, 4, 5, 7}), p.calcNodes()); // use SPT p = algo.calcPath(0, 2); assertEquals(IntArrayList.from(new int[]{0, 1, 2}), p.calcNodes()); }
Path p = algo.calcPath(1, 0); assertEquals(7, algo.getVisitedNodes()); assertEquals(102, p.getDistance(), 1.e-3); assertEquals(p.toString(), IntArrayList.from(1, 8, 9, 0), p.calcNodes()); Path pNoSod = algoNoSod.calcPath(1, 0); assertEquals(11, algoNoSod.getVisitedNodes()); assertEquals(102, pNoSod.getDistance(), 1.e-3); assertEquals(pNoSod.toString(), IntArrayList.from(1, 8, 9, 0), pNoSod.calcNodes());
List<Path> tmpPathList = algo.calcPaths(fromQResult.getClosestNode(), toQResult.getClosestNode()); debug += ", " + algo.getName() + "-routing:" + sw.stop().getSeconds() + "s"; if (tmpPathList.isEmpty()) throw new IllegalStateException("At least one path has to be returned for " + fromQResult + " -> " + toQResult); if (algo.getVisitedNodes() >= algoOpts.getMaxVisitedNodes()) throw new IllegalArgumentException("No path found due to maximum nodes exceeded " + algoOpts.getMaxVisitedNodes()); visitedNodesSum += algo.getVisitedNodes(); altResponse.addDebugInfo("visited nodes sum: " + visitedNodesSum); fromQResult = toQResult;
router.setMaxVisitedNodes(maxVisitedNodes); } else { router = new DijkstraBidirectionRef(queryGraph, weighting, TraversalMode.NODE_BASED) { router.setMaxVisitedNodes(maxVisitedNodes); final Path path = router.calcPath(from.getQueryResult().getClosestNode(), to.getQueryResult().getClosestNode());
ra.setMaxVisitedNodes(opts.getMaxVisitedNodes()); return ra;
@Test public void testIssue182() { GraphHopperStorage storage = createGHStorage(false); initGraph(storage); RoutingAlgorithm algo = createAlgo(storage); Path p = algo.calcPath(0, 8); assertEquals(IntArrayList.from(new int[]{0, 7, 8}), p.calcNodes()); // expand SPT p = algo.calcPath(0, 10); assertEquals(IntArrayList.from(new int[]{0, 1, 2, 3, 4, 10}), p.calcNodes()); }
Path path = oneDirAlgoWithLandmarks.calcPath(41, 183); assertEquals(expectedAlgo.getVisitedNodes(), oneDirAlgoWithLandmarks.getVisitedNodes() + 142); RoutingAlgorithm biDirAlgoWithLandmarks = prepare.getDecoratedAlgorithm(graph, new AStarBidirection(graph, weighting, tm), opts); path = biDirAlgoWithLandmarks.calcPath(41, 183); assertEquals(expectedPath.getWeight(), path.getWeight(), .1); assertEquals(expectedPath.calcNodes(), path.calcNodes()); assertEquals(expectedAlgo.getVisitedNodes(), biDirAlgoWithLandmarks.getVisitedNodes() + 164); RoutingAlgorithm qGraphOneDirAlgo = prepare.getDecoratedAlgorithm(qGraph, new AStar(qGraph, weighting, tm), opts); path = qGraphOneDirAlgo.calcPath(fromQR.getClosestNode(), toQR.getClosestNode()); assertEquals(expectedPath.getWeight(), path.getWeight(), .1); assertEquals(expectedPath.calcNodes(), path.calcNodes()); assertEquals(expectedAlgo.getVisitedNodes(), qGraphOneDirAlgo.getVisitedNodes() + 133);
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()); }