public final boolean isDisablingAllowed() { return disablingAllowed || !isEnabled(); }
@Test public void addWeighting() { LMAlgoFactoryDecorator dec = new LMAlgoFactoryDecorator().setEnabled(true); dec.addWeighting("fastest"); assertEquals(Arrays.asList("fastest"), dec.getWeightingsAsStrings()); // special parameters like the maximum weight dec = new LMAlgoFactoryDecorator().setEnabled(true); dec.addWeighting("fastest|maximum=65000"); dec.addWeighting("shortest|maximum=20000"); assertEquals(Arrays.asList("fastest", "shortest"), dec.getWeightingsAsStrings()); FlagEncoder car = new CarFlagEncoder(); EncodingManager em = new EncodingManager(car); dec.addWeighting(new FastestWeighting(car)).addWeighting(new ShortestWeighting(car)); dec.createPreparations(new GraphHopperStorage(new RAMDirectory(), em, false, new GraphExtension.NoOpExtension()), null); assertEquals(1, dec.getPreparations().get(0).getLandmarkStorage().getFactor(), .1); assertEquals(0.3, dec.getPreparations().get(1).getLandmarkStorage().getFactor(), .1); }
@Override public void init(CmdArgs args) { setPreparationThreads(args.getInt(Parameters.Landmark.PREPARE + "threads", getPreparationThreads())); landmarkCount = args.getInt(Parameters.Landmark.COUNT, landmarkCount); activeLandmarkCount = args.getInt(Landmark.ACTIVE_COUNT_DEFAULT, Math.min(8, landmarkCount)); logDetails = args.getBool(Landmark.PREPARE + "log_details", false); minNodes = args.getInt(Landmark.PREPARE + "min_network_size", -1); for (String loc : args.get(Landmark.PREPARE + "suggestions_location", "").split(",")) { if (!loc.trim().isEmpty()) lmSuggestionsLocations.add(loc.trim()); } String lmWeightingsStr = args.get(Landmark.PREPARE + "weightings", ""); if (!lmWeightingsStr.isEmpty() && !lmWeightingsStr.equalsIgnoreCase("no")) { List<String> tmpLMWeightingList = Arrays.asList(lmWeightingsStr.split(",")); setWeightingsAsStrings(tmpLMWeightingList); } boolean enableThis = !weightingsAsStrings.isEmpty(); setEnabled(enableThis); if (enableThis) setDisablingAllowed(args.getBool(Landmark.INIT_DISABLING_ALLOWED, isDisablingAllowed())); }
private void initLMAlgoFactoryDecorator() { if (lmFactoryDecorator.hasWeightings()) return; for (FlagEncoder encoder : encodingManager.fetchEdgeEncoders()) { for (String lmWeightingStr : lmFactoryDecorator.getWeightingsAsStrings()) { Weighting weighting = createWeighting(new HintsMap(lmWeightingStr), encoder, null); lmFactoryDecorator.addWeighting(weighting); } } }
/** * For landmarks it is required to always call this method: either it creates the landmark data or it loads it. */ protected void loadOrPrepareLM() { boolean tmpPrepare = lmFactoryDecorator.isEnabled() && !lmFactoryDecorator.getPreparations().isEmpty(); if (tmpPrepare) { ensureWriteAccess(); ghStorage.freeze(); if (lmFactoryDecorator.loadOrDoWork(ghStorage.getProperties())) ghStorage.getProperties().put(Landmark.PREPARE + "done", true); } }
if (!isEnabled() || !preparations.isEmpty()) return; if (weightings.isEmpty()) for (Weighting weighting : getWeightings()) { Double maximumWeight = maximumWeights.get(weighting.getName()); if (maximumWeight == null) if (minNodes > 1) tmpPrepareLM.setMinimumNodes(minNodes); addPreparation(tmpPrepareLM);
/** * 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(); }
@Override protected void loadOrPrepareLM() { if (!getLMFactoryDecorator().isEnabled() || getLMFactoryDecorator().getPreparations().isEmpty()) return; if (landmarkSplittingFeatureCollection != null && !landmarkSplittingFeatureCollection.getFeatures().isEmpty()) { SpatialRuleLookup ruleLookup = SpatialRuleLookupBuilder.buildIndex(landmarkSplittingFeatureCollection, "area", new SpatialRuleLookupBuilder.SpatialRuleFactory() { @Override public SpatialRule createSpatialRule(final String id, List<Polygon> polygons) { return new DefaultSpatialRule() { @Override public String getId() { return id; } }.setBorders(polygons); } }); for (PrepareLandmarks prep : getLMFactoryDecorator().getPreparations()) { // the ruleLookup splits certain areas from each other but avoids making this a permanent change so that other algorithms still can route through these regions. if (ruleLookup != null && ruleLookup.size() > 0) { prep.setSpatialRuleLookup(ruleLookup); } } } super.loadOrPrepareLM(); } }
@Test public void testPrepareWeightingNo() { CmdArgs args = new CmdArgs(); args.put(Parameters.Landmark.PREPARE + "weightings", "fastest"); LMAlgoFactoryDecorator dec = new LMAlgoFactoryDecorator(); dec.init(args); assertTrue(dec.isEnabled()); // See #1076 args.put(Parameters.Landmark.PREPARE + "weightings", "no"); dec = new LMAlgoFactoryDecorator(); dec.init(args); assertFalse(dec.isEnabled()); } }
hopper.getLMFactoryDecorator().setDisablingAllowed(true); hopper.importOrLoad(); printTimeOfRouteQuery(hopper, isCH, isLM, count / 20, "routing", vehicleStr, true, -1, true); if (hopper.getLMFactoryDecorator().isEnabled()) { System.gc(); isLM = true; isCH = true; if (hopper.getLMFactoryDecorator().isEnabled()) { isLM = true; System.gc();
hopper.getLMFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest")); assertNotNull(em); assertEquals(1, em.fetchEdgeEncoders().size()); assertEquals(16, hopper.getLMFactoryDecorator().getLandmarks()); hopper.getLMFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest")); assertEquals(16, hopper.getLMFactoryDecorator().getLandmarks());
/** * For landmarks it is required to always call this method: either it creates the landmark data or it loads it. */ protected void loadOrPrepareLM() { boolean tmpPrepare = lmFactoryDecorator.isEnabled(); if (tmpPrepare) { ensureWriteAccess(); ghStorage.freeze(); if (lmFactoryDecorator.loadOrDoWork(ghStorage.getProperties())) ghStorage.getProperties().put(Landmark.PREPARE + "done", true); } }
@Override public void run() { if (plm.loadExisting()) return; LOGGER.info(tmpCounter + "/" + getPreparations().size() + " calling LM prepare.doWork for " + plm.getWeighting() + " ... (" + getMemInfo() + ")"); prepared.set(true); Thread.currentThread().setName(name); plm.doWork(); properties.put(Landmark.PREPARE + "date." + name, createFormatter().format(new Date())); } }, name);
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); }
/** * 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 LMAlgoFactoryDecorator 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 (!isEnabled() || !preparations.isEmpty()) return; if (weightings.isEmpty()) for (Weighting weighting : getWeightings()) { Double maximumWeight = maximumWeights.get(weighting.getName()); if (maximumWeight == null) setMaximumWeight(maximumWeight); addPreparation(tmpPrepareLM);
/** * For landmarks it is required to always call this method: either it creates the landmark data or it loads it. */ protected void loadOrPrepareLM() { boolean tmpPrepare = lmFactoryDecorator.isEnabled() && !lmFactoryDecorator.getPreparations().isEmpty(); if (tmpPrepare) { ensureWriteAccess(); ghStorage.freeze(); if (lmFactoryDecorator.loadOrDoWork(ghStorage.getProperties())) ghStorage.getProperties().put(Landmark.PREPARE + "done", true); } }
private void initLMAlgoFactoryDecorator() { if (lmFactoryDecorator.hasWeightings()) return; for (FlagEncoder encoder : encodingManager.fetchEdgeEncoders()) { for (String lmWeightingStr : lmFactoryDecorator.getWeightingsAsStrings()) { Weighting weighting = createWeighting(new HintsMap(lmWeightingStr), encoder, null); lmFactoryDecorator.addWeighting(weighting); } } }
/** * 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 (" + Helper.getMemInfo() + ")"); ghStorage = newGraph; } if (hasElevation()) { interpolateBridgesAndOrTunnels(); } initLocationIndex(); if (chFactoryDecorator.isEnabled()) chFactoryDecorator.createPreparations(ghStorage, traversalMode); if (!isCHPrepared()) prepareCH(); if (lmFactoryDecorator.isEnabled()) lmFactoryDecorator.createPreparations(ghStorage, traversalMode, locationIndex); loadOrPrepareLM(); }
@Override public void run() { if (plm.loadExisting()) return; LOGGER.info(tmpCounter + "/" + getPreparations().size() + " calling LM prepare.doWork for " + plm.getWeighting() + " ... (" + getMemInfo() + ")"); prepared.set(true); Thread.currentThread().setName(name); plm.doWork(); properties.put(Landmark.PREPARE + "date." + name, createFormatter().format(new Date())); } }, name);