@Override public void init(CmdArgs args) { // throw explicit error for deprecated configs if (!args.get("prepare.threads", "").isEmpty()) throw new IllegalStateException("Use " + CH.PREPARE + "threads instead of prepare.threads"); if (!args.get("prepare.chWeighting", "").isEmpty() || !args.get("prepare.chWeightings", "").isEmpty()) throw new IllegalStateException("Use " + CH.PREPARE + "weightings and a comma separated list instead of prepare.chWeighting or prepare.chWeightings"); setPreparationThreads(args.getInt(CH.PREPARE + "threads", getPreparationThreads())); // default is enabled & fastest String chWeightingsStr = args.get(CH.PREPARE + "weightings", ""); if ("no".equals(chWeightingsStr) || "false".equals(chWeightingsStr)) { // default is fastest and we need to clear this explicitly weightingsAsStrings.clear(); } else if (!chWeightingsStr.isEmpty()) { List<String> tmpCHWeightingList = Arrays.asList(chWeightingsStr.split(",")); setWeightingsAsStrings(tmpCHWeightingList); } boolean enableThis = !weightingsAsStrings.isEmpty(); setEnabled(enableThis); if (enableThis) setDisablingAllowed(args.getBool(CH.INIT_DISABLING_ALLOWED, isDisablingAllowed())); pMap = args; }
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 = PrepareContractionHierarchies.fromGraphHopperStorage( ghStorage, weighting, traversalMode); tmpPrepareCH.setParams(pMap); addPreparation(tmpPrepareCH); } }
private void initCHAlgoFactoryDecorator() { if (!chFactoryDecorator.hasWeightings()) { for (FlagEncoder encoder : encodingManager.fetchEdgeEncoders()) { for (String chWeightingStr : chFactoryDecorator.getWeightingsAsStrings()) { // ghStorage is null at this point Weighting weighting = createWeighting(new HintsMap(chWeightingStr), encoder, null); chFactoryDecorator.addWeighting(weighting); } } } }
public CHAlgoFactoryDecorator() { setPreparationThreads(1); setWeightingsAsStrings(Arrays.asList(getDefaultWeighting())); }
public void init( CmdArgs args ) { setPreparationThreads(args.getInt("prepare.threads", getPreparationThreads())); String deprecatedWeightingConfig = args.get("prepare.chWeighting", ""); if (!deprecatedWeightingConfig.isEmpty()) throw new IllegalStateException("Use prepare.ch.weightings and a comma separated list instead of prepare.chWeighting"); // default is enabled & fastest String chWeightingsStr = args.get("prepare.ch.weightings", ""); // backward compatibility if (chWeightingsStr.isEmpty()) chWeightingsStr = args.get("prepare.chWeightings", ""); if ("no".equals(chWeightingsStr)) { // default is fastest and we need to clear this explicitely weightingsAsStrings.clear(); } else if (!chWeightingsStr.isEmpty()) { List<String> tmpCHWeightingList = Arrays.asList(chWeightingsStr.split(",")); setWeightingsAsStrings(tmpCHWeightingList); } boolean enableThis = !weightingsAsStrings.isEmpty(); setEnabled(enableThis); if (enableThis) setDisablingAllowed(args.getBool(CH.INIT_DISABLING_ALLOWED, isDisablingAllowed())); setPreparationPeriodicUpdates(args.getInt("prepare.updates.periodic", getPreparationPeriodicUpdates())); setPreparationLazyUpdates(args.getInt("prepare.updates.lazy", getPreparationLazyUpdates())); setPreparationNeighborUpdates(args.getInt("prepare.updates.neighbor", getPreparationNeighborUpdates())); setPreparationContractedNodes(args.getInt("prepare.contracted_nodes", getPreparationContractedNodes())); setPreparationLogMessages(args.getDouble("prepare.log_messages", getPreparationLogMessages())); }
if (!chFactoryDecorator.isDisablingAllowed() && disableCH) throw new IllegalArgumentException("Disabling CH not allowed on the server-side"); algoStr = chFactoryDecorator.isEnabled() && !disableCH ? DIJKSTRA_BI : ASTAR_BI; QueryGraph queryGraph; if (chFactoryDecorator.isEnabled() && !disableCH) { boolean forceCHHeading = hints.getBool(CH.FORCE_HEADING, false); if (!forceCHHeading && request.hasFavoredHeading(0)) throw new IllegalStateException("Although CH was enabled a non-CH algorithm factory was returned " + tmpAlgoFactory); tMode = getCHFactoryDecorator().getNodeBase(); queryGraph = new QueryGraph(ghStorage.getGraph(CHGraph.class, weighting)); queryGraph.lookup(qResults);
initLMAlgoFactoryDecorator(); if (chFactoryDecorator.isEnabled()) { initCHAlgoFactoryDecorator(); ghStorage = new GraphHopperStorage(chFactoryDecorator.getWeightings(), dir, encodingManager, hasElevation(), ext); } else { ghStorage = new GraphHopperStorage(dir, encodingManager, hasElevation(), ext);
public GraphHopper() { chFactoryDecorator.setEnabled(true); lmFactoryDecorator.setEnabled(false); // order is important to use CH as base algo and set the approximation in the followed lm factory decorator algoDecorators.add(chFactoryDecorator); algoDecorators.add(lmFactoryDecorator); }
public final boolean isDisablingAllowed() { return disablingAllowed || !isEnabled(); }
@Test public void testCreatePreparations() { CHAlgoFactoryDecorator instance = new CHAlgoFactoryDecorator(); assertFalse(instance.isDisablingAllowed()); instance.setEnabled(false); assertTrue(instance.isDisablingAllowed()); } }
hopper.getCHFactoryDecorator().setDisablingAllowed(true); hopper.getLMFactoryDecorator().setDisablingAllowed(true); hopper.importOrLoad(); if (hopper.getCHFactoryDecorator().isEnabled()) { isCH = true; Weighting weighting = hopper.getCHFactoryDecorator().getWeightings().get(0); CHGraph lg = g.getGraph(CHGraph.class, weighting); fillAllowedEdges(lg.getAllEdges(), allowedEdges);
@Override public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory defaultAlgoFactory, HintsMap map) { boolean disableCH = map.getBool(DISABLE, false); if (!isEnabled() || disablingAllowed && disableCH) return defaultAlgoFactory; if (preparations.isEmpty()) throw new IllegalStateException("No preparations added to this decorator"); if (map.getWeighting().isEmpty()) map.setWeighting(getDefaultWeighting()); String entriesStr = ""; for (PrepareContractionHierarchies p : preparations) { if (p.getWeighting().matches(map)) return p; entriesStr += p.getWeighting() + ", "; } throw new IllegalArgumentException("Cannot find CH RoutingAlgorithmFactory for weighting map " + map + " in entries " + entriesStr); }
protected void prepareCH() { boolean tmpPrepare = chFactoryDecorator.isEnabled(); if (tmpPrepare) { ensureWriteAccess(); if (chFactoryDecorator.getPreparationThreads() > 1 && dataAccessType.isMMap() && !dataAccessType.isSynched()) throw new IllegalStateException("You cannot execute CH preparation in parallel for MMAP without synching! Specify MMAP_SYNC or use 1 thread only"); ghStorage.freeze(); chFactoryDecorator.prepare(ghStorage.getProperties()); ghStorage.getProperties().put(CH.PREPARE + "done", true); } }
/** * Does the preparation and creates the location index */ public void postProcessing() { // Later: move this into the GraphStorage.optimize method // Or: Doing it after preparation to optimize shortcuts too. But not possible yet #12 if (sortGraph) { if (ghStorage.isCHPossible() && isCHPrepared()) throw new IllegalArgumentException("Sorting a prepared CHGraph is not possible yet. See #12"); GraphHopperStorage newGraph = GHUtility.newStorage(ghStorage); GHUtility.sortDFS(ghStorage, newGraph); logger.info("graph sorted (" + getMemInfo() + ")"); ghStorage = newGraph; } if (hasElevation()) { interpolateBridgesAndOrTunnels(); } initLocationIndex(); if (chFactoryDecorator.isEnabled()) chFactoryDecorator.createPreparations(ghStorage, traversalMode); if (!isCHPrepared()) prepareCH(); if (lmFactoryDecorator.isEnabled()) lmFactoryDecorator.createPreparations(ghStorage, locationIndex); loadOrPrepareLM(); }
graphHopper.getCHFactoryDecorator().setEnabled(false); graphHopper.getCHFactoryDecorator().setDisablingAllowed(true); graphHopper.importOrLoad();
@Override protected void prepareCH() { StopWatch sw = new StopWatch().start(); super.prepareCH(); put(Parameters.CH.PREPARE + "time", sw.stop().getMillis()); int edges = getGraphHopperStorage().getAllEdges().length(); if (getCHFactoryDecorator().hasWeightings()) { Weighting weighting = getCHFactoryDecorator().getWeightings().get(0); int edgesAndShortcuts = getGraphHopperStorage().getGraph(CHGraph.class, weighting).getEdges(); put(Parameters.CH.PREPARE + "shortcuts", edgesAndShortcuts - edges); } }
hints.put(Parameters.CH.DISABLE, true); if (!graphHopper.getCHFactoryDecorator().isDisablingAllowed()) throw new IllegalArgumentException("Cannot disable CH. Not allowed on server side");
/** * Enables the use of contraction hierarchies to reduce query times. Enabled by default. * * @param weightingList A list containing multiple weightings like: "fastest", "shortest" or * your own weight-calculation type. */ public CHAlgoFactoryDecorator setWeightingsAsStrings(List<String> weightingList) { if (weightingList.isEmpty()) throw new IllegalArgumentException("It is not allowed to pass an emtpy weightingList"); weightingsAsStrings.clear(); for (String strWeighting : weightingList) { strWeighting = toLowerCase(strWeighting); strWeighting = strWeighting.trim(); addWeighting(strWeighting); } return this; }
if (ch) { map.put(Parameters.Landmark.DISABLE, true); weighting = hopper.getCHFactoryDecorator().getWeightings().get(0); routingGraph = hopper.getGraphHopperStorage().getGraph(CHGraph.class, weighting);