public CHAlgoFactoryDecorator addPreparation(PrepareContractionHierarchies pch) { preparations.add(pch); int lastIndex = preparations.size() - 1; if (lastIndex >= weightings.size()) throw new IllegalStateException("Cannot access weighting for PrepareContractionHierarchies with " + pch.getWeighting() + ". Call add(Weighting) before"); if (preparations.get(lastIndex).getWeighting() != weightings.get(lastIndex)) throw new IllegalArgumentException("Weighting of PrepareContractionHierarchies " + preparations.get(lastIndex).getWeighting() + " needs to be identical to previously added " + weightings.get(lastIndex)); return this; }
private RoutingAlgorithm createCHAlgo(GraphHopperStorage graph, CHGraph chGraph, boolean withSOD, AlgorithmOptions algorithmOptions) { PrepareContractionHierarchies ch = new PrepareContractionHierarchies( chGraph, algorithmOptions.getWeighting(), TraversalMode.NODE_BASED); if (!withSOD) { algorithmOptions.getHints().put("stall_on_demand", false); } return ch.createAlgo(chGraph, algorithmOptions); } }
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()); }
protected void runGraphContraction() { if (!prepareNodes()) return; contractNodes(); }
@Override public RoutingAlgorithmFactory createFactory(GraphHopperStorage ghStorage, AlgorithmOptions opts) { ghStorage.freeze(); PrepareContractionHierarchies ch = PrepareContractionHierarchies.fromGraphHopperStorage( ghStorage, opts.getWeighting(), TraversalMode.NODE_BASED); ch.doWork(); return ch; }
int priority = oldPriorities[node] = calculatePriority(node); sortedNodes.insert(node, priority); + ", shortcuts:" + Helper.nf(newShortcuts) + ", dijkstras:" + Helper.nf(dijkstraCount) + ", " + getTimesAsString() + ", meanDegree:" + (long) meanDegree + ", algo:" + prepareAlgo.getMemoryUsageAsString() int priority = oldPriorities[polledNode] = calculatePriority(polledNode); if (priority > sortedNodes.peekValue()) { findShortcuts(addScHandler.setNode(polledNode)); newShortcuts += addShortcuts(shortcuts.keySet()); prepareGraph.setLevel(polledNode, level); level++; neighborSW.start(); int oldPrio = oldPriorities[nn]; int priority = oldPriorities[nn] = calculatePriority(nn); if (priority != oldPrio) sortedNodes.update(nn, oldPrio, priority); close(); + ", " + prepareWeighting + ", dijkstras:" + dijkstraCount + ", " + getTimesAsString() + ", meanDegree:" + (long) meanDegree
public void createPreparations(GraphHopperStorage ghStorage, TraversalMode traversalMode) { if (!isEnabled() || !preparations.isEmpty()) return; if (weightings.isEmpty()) throw new IllegalStateException("No CH weightings found"); traversalMode = getNodeBase(); for (Weighting weighting : getWeightings()) { if (weighting instanceof GenericWeighting) { ((GenericWeighting) weighting).setGraph(ghStorage); } PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies( new GHDirectory("", DAType.RAM_INT), ghStorage, ghStorage.getGraph(CHGraph.class, weighting), weighting, traversalMode); tmpPrepareCH.setPeriodicUpdates(preparationPeriodicUpdates). setLazyUpdates(preparationLazyUpdates). setNeighborUpdates(preparationNeighborUpdates). setLogMessages(preparationLogMessages); addPreparation(tmpPrepareCH); } }
@Override public void doWork() { if (prepareWeighting == null) throw new IllegalStateException("No weight calculation set."); allSW.start(); super.doWork(); initFromGraph(); if (!prepareNodes()) return; contractNodes(); }
@Override public void doSpecificWork() { allSW.start(); initFromGraph(); runGraphContraction(); logger.info("took:" + (int) allSW.stop().getSeconds() + "s " + ", new shortcuts: " + nf(nodeContractor.getAddedShortcutsCount()) + ", initSize:" + nf(initSize) + ", " + prepareWeighting + ", periodic:" + params.getPeriodicUpdatesPercentage() + ", lazy:" + params.getLastNodesLazyUpdatePercentage() + ", neighbor:" + params.getNeighborUpdatePercentage() + ", " + getTimesAsString() + ", lazy-overhead: " + (int) (100 * ((checkCounter / (double) initSize) - 1)) + "%" + ", " + Helper.getMemInfo()); int edgeCount = prepareGraph.getOriginalEdges(); logger.info("graph now - num edges: {}, num nodes: {}, num shortcuts: {}", nf(edgeCount), nf(prepareGraph.getNodes()), nf(prepareGraph.getEdges() - edgeCount)); }
continue; float priority = oldPriorities[node] = calculatePriority(node); sortedNodes.insert(node, priority); logStats(updateCounter); float priority = oldPriorities[polledNode] = calculatePriority(polledNode); if (priority > sortedNodes.peekValue()) { neighborUpdateSW.start(); float oldPrio = oldPriorities[nn]; float priority = oldPriorities[nn] = calculatePriority(nn); if (priority != oldPrio) sortedNodes.update(nn, oldPrio, priority); logStats(updateCounter); close();
@Override public void run() { // toString is not taken into account so we need to cheat, see http://stackoverflow.com/q/6113746/194609 for other options Thread.currentThread().setName(name); prepare.doWork(); properties.put(CH.PREPARE + "date." + name, createFormatter().format(new Date())); } }, name);
@Test public void testCircleBug() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); // /--1 // -0--/ // | g.edge(0, 1, 10, true); g.edge(0, 1, 4, true); g.edge(0, 2, 10, true); g.edge(0, 3, 10, true); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(0, prepare.getShortcuts()); }
private boolean prepareNodes() { int nodes = prepareGraph.getNodes(); for (int node = 0; node < nodes; node++) { prepareGraph.setLevel(node, maxLevel); } periodicUpdateSW.start(); for (int node = 0; node < nodes; node++) { float priority = oldPriorities[node] = calculatePriority(node); sortedNodes.insert(node, priority); } periodicUpdateSW.stop(); return !sortedNodes.isEmpty(); }
public static PrepareContractionHierarchies fromGraphHopperStorage(GraphHopperStorage ghStorage, Weighting weighting, TraversalMode traversalMode) { return new PrepareContractionHierarchies(ghStorage.getGraph(CHGraph.class, weighting), weighting, traversalMode); }
@Test public void testRoundaboutUnpacking() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initRoundaboutGraph(g); int oldCount = g.getAllEdges().length(); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(oldCount, g.getEdges()); assertEquals(oldCount + 23, lg.getEdges()); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(4, 7); assertEquals(IntArrayList.from(4, 5, 6, 7), p.calcNodes()); }
public void createPreparations(GraphHopperStorage ghStorage, TraversalMode traversalMode) { if (!isEnabled() || !preparations.isEmpty()) return; if (weightings.isEmpty()) throw new IllegalStateException("No CH weightings found"); traversalMode = getNodeBase(); for (Weighting weighting : getWeightings()) { PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies( new GHDirectory("", DAType.RAM_INT), ghStorage, ghStorage.getGraph(CHGraph.class, weighting), traversalMode); tmpPrepareCH.setParams(pMap); addPreparation(tmpPrepareCH); } }
private void logStats(int updateCounter) { logger.info(String.format(Locale.ROOT, "nodes: %10s, shortcuts: %10s, updates: %2d, checked-nodes: %10s, %s, %s, %s", nf(sortedNodes.getSize()), nf(nodeContractor.getAddedShortcutsCount()), updateCounter, nf(checkCounter), getTimesAsString(), nodeContractor.getStatisticsString(), Helper.getMemInfo())); }
int priority = oldPriorities[node] = calculatePriority(node); sortedNodes.insert(node, priority); + ", shortcuts:" + Helper.nf(newShortcuts) + ", dijkstras:" + Helper.nf(dijkstraCount) + ", " + getTimesAsString() + ", meanDegree:" + (long) meanDegree + ", algo:" + prepareAlgo.getMemoryUsageAsString() int priority = oldPriorities[polledNode] = calculatePriority(polledNode); if (priority > sortedNodes.peekValue()) newShortcuts += addShortcuts(polledNode); prepareGraph.setLevel(polledNode, level); level++; int priority = oldPriorities[nn] = calculatePriority(nn); if (priority != oldPrio) sortedNodes.update(nn, oldPrio, priority); close(); + ", " + prepareFlagEncoder + ", dijkstras:" + dijkstraCount + ", " + getTimesAsString() + ", meanDegree:" + (long) meanDegree + ", initSize:" + initSize
public void createPreparations( GraphHopperStorage ghStorage, TraversalMode traversalMode ) { if (!isEnabled() || !preparations.isEmpty()) return; if (weightings.isEmpty()) throw new IllegalStateException("No CH weightings found"); traversalMode = getNodeBase(); for (Weighting weighting : getWeightings()) { PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies( new GHDirectory("", DAType.RAM_INT), ghStorage, ghStorage.getGraph(CHGraph.class, weighting), weighting.getFlagEncoder(), weighting, traversalMode); tmpPrepareCH.setPeriodicUpdates(preparationPeriodicUpdates). setLazyUpdates(preparationLazyUpdates). setNeighborUpdates(preparationNeighborUpdates). setLogMessages(preparationLogMessages); addPreparation(tmpPrepareCH); } }
@Override public void doWork() { if (prepareFlagEncoder == null) throw new IllegalStateException("No vehicle encoder set."); if (prepareWeighting == null) throw new IllegalStateException("No weight calculation set."); allSW.start(); super.doWork(); initFromGraph(); if (!prepareNodes()) return; contractNodes(); }