"Couldn't find " + weighting.getName() + " in " + maximumWeights); PrepareLandmarks tmpPrepareLM = new PrepareLandmarks(ghStorage.getDirectory(), ghStorage, weighting, landmarkCount, activeLandmarkCount). setLandmarkSuggestions(lmSuggestions). setMaximumWeight(maximumWeight). setLogDetails(logDetails); if (minNodes > 1) tmpPrepareLM.setMinimumNodes(minNodes); addPreparation(tmpPrepareLM);
@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);
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { RoutingAlgorithm algo = defaultAlgoFactory.createAlgo(g, opts); return p.getDecoratedAlgorithm(g, algo, opts); } }
build(); PrepareLandmarks prepare = new PrepareLandmarks(new RAMDirectory(), graph, weighting, 4, 2); prepare.setMinimumNodes(2); prepare.doWork(); RoutingAlgorithm oneDirAlgoWithLandmarks = prepare.getDecoratedAlgorithm(graph, new AStar(graph, weighting, tm), opts); Path path = oneDirAlgoWithLandmarks.calcPath(41, 183); RoutingAlgorithm biDirAlgoWithLandmarks = prepare.getDecoratedAlgorithm(graph, new AStarBidirection(graph, weighting, tm), opts); path = biDirAlgoWithLandmarks.calcPath(41, 183); QueryResult toQR = index.findClosest(-0.2401, 0.0601, EdgeFilter.ALL_EDGES); qGraph.lookup(fromQR, toQR); RoutingAlgorithm qGraphOneDirAlgo = prepare.getDecoratedAlgorithm(qGraph, new AStar(qGraph, weighting, tm), opts); path = qGraphOneDirAlgo.calcPath(fromQR.getClosestNode(), toQR.getClosestNode());
throw new IllegalStateException("maximumWeight cannot be null. Default should be just negative"); PrepareLandmarks tmpPrepareLM = new PrepareLandmarks(ghStorage.getDirectory(), ghStorage, weighting, traversalMode, landmarkCount, activeLandmarkCount). setLandmarkSuggestions(lmSuggestions). setMaximumWeight(maximumWeight);
public LMAlgoFactoryDecorator addPreparation(PrepareLandmarks pch) { preparations.add(pch); int lastIndex = preparations.size() - 1; if (lastIndex >= weightings.size()) throw new IllegalStateException("Cannot access weighting for PrepareLandmarks 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; }
for (final PrepareLandmarks plm : preparations) { counter++; if (plm.loadExisting()) continue; LOGGER.info(counter + "/" + getPreparations().size() + " calling LM prepare.doWork for " + plm.getWeighting() + " ... (" + Helper.getMemInfo() + ")"); final String name = AbstractWeighting.weightingToFileName(plm.getWeighting()); threadPool.execute(new Runnable() { @Override
@Override public void run() { String errorKey = Landmark.PREPARE + "error." + name; try { Thread.currentThread().setName(name); properties.put(errorKey, "LM preparation incomplete"); plm.doWork(); properties.remove(errorKey); properties.put(Landmark.PREPARE + "date." + name, Helper.createFormatter().format(new Date())); } catch (Exception ex) { LOGGER.error("Problem while LM preparation " + name, ex); properties.put(errorKey, ex.getMessage()); } } });
@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); }
counter++; final int tmpCounter = counter; final String name = AbstractWeighting.weightingToFileName(plm.getWeighting()); completionService.submit(new Runnable() { @Override
"Couldn't find " + weighting.getName() + " in " + maximumWeights); PrepareLandmarks tmpPrepareLM = new PrepareLandmarks(ghStorage.getDirectory(), ghStorage, weighting, landmarkCount, activeLandmarkCount). setLandmarkSuggestions(lmSuggestions). setMaximumWeight(maximumWeight). setLogDetails(logDetails); if (minNodes > 1) tmpPrepareLM.setMinimumNodes(minNodes); addPreparation(tmpPrepareLM);
@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);
@Override public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory defaultAlgoFactory, HintsMap map) { // for now do not allow mixing CH&LM #1082 boolean disableCH = map.getBool(Parameters.CH.DISABLE, false); boolean disableLM = map.getBool(Parameters.Landmark.DISABLE, false); if (!isEnabled() || disablingAllowed && disableLM || !disableCH) return defaultAlgoFactory; if (preparations.isEmpty()) throw new IllegalStateException("No preparations added to this decorator"); for (final PrepareLandmarks p : preparations) { if (p.getWeighting().matches(map)) return new LMRAFactory(p, defaultAlgoFactory); } // if the initial encoder&weighting has certain properties we could cross query it but for now avoid this return defaultAlgoFactory; }
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { RoutingAlgorithm algo = defaultAlgoFactory.createAlgo(g, opts); return p.getDecoratedAlgorithm(g, algo, opts); } }
public LMAlgoFactoryDecorator addPreparation(PrepareLandmarks pch) { preparations.add(pch); int lastIndex = preparations.size() - 1; if (lastIndex >= weightings.size()) throw new IllegalStateException("Cannot access weighting for PrepareLandmarks 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; }
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { RoutingAlgorithm algo = defaultAlgoFactory.createAlgo(g, opts); return p.getDecoratedAlgorithm(g, algo, opts); } }
public LMAlgoFactoryDecorator addPreparation(PrepareLandmarks pch) { preparations.add(pch); int lastIndex = preparations.size() - 1; if (lastIndex >= weightings.size()) throw new IllegalStateException("Cannot access weighting for PrepareLandmarks 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; }
@Override public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory defaultAlgoFactory, HintsMap map) { boolean forceFlexMode = map.getBool(DISABLE, false); if (!isEnabled() || disablingAllowed && forceFlexMode) return defaultAlgoFactory; if (preparations.isEmpty()) throw new IllegalStateException("No preparations added to this decorator"); for (final PrepareLandmarks p : preparations) { if (p.getWeighting().matches(map)) return new LMRAFactory(p, defaultAlgoFactory); } // if the initial encoder&weighting has certain properies we could cross query it but for now avoid this return defaultAlgoFactory; }
counter++; final int tmpCounter = counter; final String name = AbstractWeighting.weightingToFileName(plm.getWeighting()); completionService.submit(new Runnable() { @Override
@Override public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory defaultAlgoFactory, HintsMap map) { // for now do not allow mixing CH&LM #1082 boolean disableCH = map.getBool(Parameters.CH.DISABLE, false); boolean disableLM = map.getBool(Parameters.Landmark.DISABLE, false); if (!isEnabled() || disablingAllowed && disableLM || !disableCH) return defaultAlgoFactory; if (preparations.isEmpty()) throw new IllegalStateException("No preparations added to this decorator"); for (final PrepareLandmarks p : preparations) { if (p.getWeighting().matches(map)) return new LMRAFactory(p, defaultAlgoFactory); } // if the initial encoder&weighting has certain properties we could cross query it but for now avoid this return defaultAlgoFactory; }