public PrepareContractionHierarchies(FlagEncoder encoder, Weighting weighting) { prepareEncoder = encoder; scOneDir = encoder.setAccess(0, true, false); scBothDir = encoder.setAccess(0, true, true); prepareWeighting = weighting; originalEdges = new GHDirectory("", DAType.RAM_INT).find("originalEdges"); originalEdges.create(1000); }
@Test public void testPathRecursiveUnpacking() { // use an encoder where it is possible to store 2 weights per edge FlagEncoder encoder = new Bike2WeightFlagEncoder(); ShortestWeighting weighting = new ShortestWeighting(encoder); EncodingManager em = new EncodingManager(encoder); GraphHopperStorage ghStorage = createGHStorage(em, Collections.<Weighting>singleton(weighting), false); CHGraphImpl g2 = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting); g2.edge(0, 1, 1, true); EdgeIteratorState iter1_1 = g2.edge(0, 2, 1.4, false); EdgeIteratorState iter1_2 = g2.edge(2, 5, 1.4, false); g2.edge(1, 2, 1, true); g2.edge(1, 3, 3, true); g2.edge(2, 3, 1, true); g2.edge(4, 3, 1, true); g2.edge(2, 5, 1.4, true); g2.edge(3, 5, 1, true); g2.edge(5, 6, 1, true); g2.edge(4, 6, 1, true); g2.edge(6, 7, 1, true); EdgeIteratorState iter2_2 = g2.edge(5, 7); iter2_2.setDistance(1.4).setFlags(encoder.setProperties(10, true, false)); ghStorage.freeze(); // simulate preparation CHEdgeIteratorState iter2_1 = g2.shortcut(0, 5); iter2_1.setDistance(2.8).setFlags(encoder.setProperties(10, true, false)); iter2_1.setSkippedEdges(iter1_1.getEdge(), iter1_2.getEdge()); CHEdgeIteratorState tmp = g2.shortcut(0, 7); tmp.setDistance(4.2).setFlags(encoder.setProperties(10, true, false)); tmp.setSkippedEdges(iter2_1.getEdge(), iter2_2.getEdge()); g2.setLevel(1, 0); g2.setLevel(3, 1); g2.setLevel(4, 2); g2.setLevel(6, 3); g2.setLevel(2, 4); g2.setLevel(5, 5); g2.setLevel(7, 6); g2.setLevel(0, 7); AlgorithmOptions opts = new AlgorithmOptions(AlgorithmOptions.DIJKSTRA_BI, encoder, weighting); Path p = new PrepareContractionHierarchies( new GHDirectory("", DAType.RAM_INT), ghStorage, g2, encoder, weighting, TraversalMode.NODE_BASED) .createAlgo(g2, opts) .calcPath(0, 7); assertEquals(Helper.createTList(0, 2, 5, 7), p.calcNodes()); assertEquals(1064, p.getTime()); assertEquals(4.2, p.getDistance(), 1e-5); }
public CurvatureWeighting(FlagEncoder flagEncoder, PMap pMap) { super(flagEncoder, pMap); double minBendiness = 1; // see correctErrors double maxPriority = 1; // BEST / BEST minFactor = minBendiness / Math.log(flagEncoder.getMaxSpeed()) / (0.5 + maxPriority); }
/** Introduces the necessary shortcuts for endNode v in the graph. */ int addShortcuts(int v) { shortcuts.clear(); findShortcuts(addScHandler.setNode(v)); int tmpNewShortcuts = 0; for (Shortcut sc : shortcuts.keySet()) { boolean updatedInGraph = false; // check if we need to update some existing shortcut in the graph EdgeSkipIterator iter = vehicleOutExplorer.setBaseNode(sc.from); while (iter.next()) { if (iter.isShortcut() && iter.getAdjNode() == sc.to && prepareEncoder.canBeOverwritten(iter.getFlags(), sc.flags) && iter.getDistance() > sc.weight) { iter.setFlags(sc.flags); iter.setSkippedEdges(sc.skippedEdge1, sc.skippedEdge2); iter.setDistance(sc.weight); setOrigEdgeCount(iter.getEdge(), sc.originalEdges); updatedInGraph = true; break; } } if (!updatedInGraph) { EdgeSkipIterState edgeState = g.shortcut(sc.from, sc.to); edgeState.setDistance(sc.weight).setFlags(sc.flags); edgeState.setSkippedEdges(sc.skippedEdge1, sc.skippedEdge2); setOrigEdgeCount(edgeState.getEdge(), sc.originalEdges); tmpNewShortcuts++; } } return tmpNewShortcuts; }
@Test public void testPathRecursiveUnpacking() { // use an encoder where it is possible to store 2 weights per edge FlagEncoder encoder = new Bike2WeightFlagEncoder(); EncodingManager em = new EncodingManager(encoder); LevelGraphStorage g2 = (LevelGraphStorage) createGraph(em, false); g2.edge(0, 1, 1, true); EdgeIteratorState iter1_1 = g2.edge(0, 2, 1.4, false); EdgeIteratorState iter1_2 = g2.edge(2, 5, 1.4, false); g2.edge(1, 2, 1, true); g2.edge(1, 3, 3, true); g2.edge(2, 3, 1, true); g2.edge(4, 3, 1, true); g2.edge(2, 5, 1.4, true); g2.edge(3, 5, 1, true); g2.edge(5, 6, 1, true); g2.edge(4, 6, 1, true); g2.edge(6, 7, 1, true); EdgeIteratorState iter2_2 = g2.edge(5, 7); iter2_2.setDistance(1.4).setFlags(encoder.setProperties(10, true, false)); // simulate preparation EdgeSkipIterState iter2_1 = g2.shortcut(0, 5); iter2_1.setDistance(2.8).setFlags(encoder.setProperties(10, true, false)); iter2_1.setSkippedEdges(iter1_1.getEdge(), iter1_2.getEdge()); EdgeSkipIterState tmp = g2.shortcut(0, 7); tmp.setDistance(4.2).setFlags(encoder.setProperties(10, true, false)); tmp.setSkippedEdges(iter2_1.getEdge(), iter2_2.getEdge()); g2.setLevel(1, 0); g2.setLevel(3, 1); g2.setLevel(4, 2); g2.setLevel(6, 3); g2.setLevel(2, 4); g2.setLevel(5, 5); g2.setLevel(7, 6); g2.setLevel(0, 7); Path p = new PrepareContractionHierarchies(encoder, new ShortestWeighting()) .setGraph(g2) .createAlgo() .calcPath(0, 7); assertEquals(Helper.createTList(0, 2, 5, 7), p.calcNodes()); assertEquals(1064, p.getMillis()); assertEquals(4.2, p.getDistance(), 1e-5); }