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; }
@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); }
public void prepare(final StorableProperties properties) { ExecutorCompletionService completionService = new ExecutorCompletionService<>(threadPool); int counter = 0; for (final PrepareContractionHierarchies prepare : getPreparations()) { LOGGER.info((++counter) + "/" + getPreparations().size() + " calling CH prepare.doWork for " + prepare.getWeighting() + " ... (" + getMemInfo() + ")"); final String name = AbstractWeighting.weightingToFileName(prepare.getWeighting()); completionService.submit(new Runnable() { @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); } threadPool.shutdown(); try { for (int i = 0; i < getPreparations().size(); i++) { completionService.take().get(); } } catch (Exception e) { threadPool.shutdownNow(); throw new RuntimeException(e); } }
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { // doable but ugly Weighting w = ((PrepareContractionHierarchies) tmpFactory).getWeighting(); return new TmpAlgo(g, new PreparationWeighting(w), TraversalMode.NODE_BASED, mg). setEdgeFilter(new LevelEdgeFilter((CHGraph) routingGraph)); } };
@Test public void testReturnsCorrectWeighting() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); assertSame(weighting, prepare.getWeighting()); }
weighting = ((PrepareContractionHierarchies) chAlgoFactory).getWeighting(); else throw new IllegalStateException("Although CH was enabled a non-CH algorithm factory was returned " + tmpAlgoFactory);
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; }
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; }
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; }
public void prepare(final StorableProperties properties) { int counter = 0; for (final PrepareContractionHierarchies prepare : getPreparations()) { LOGGER.info((++counter) + "/" + getPreparations().size() + " calling CH prepare.doWork for " + prepare.getWeighting() + " ... (" + Helper.getMemInfo() + ")"); final String name = AbstractWeighting.weightingToFileName(prepare.getWeighting()); threadPool.execute(new Runnable() { @Override
@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); }
@Override public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory defaultAlgoFactory, HintsMap map) { boolean forceFlexMode = map.getBool(DISABLE, false); if (!isEnabled() || forceFlexMode) 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); }
for (final PrepareContractionHierarchies prepare : getPreparations()) logger.info((++counter) + "/" + getPreparations().size() + " calling prepare.doWork for " + prepare.getWeighting() + " ... (" + Helper.getMemInfo() + ")"); final String name = AbstractWeighting.weightingToFileName(prepare.getWeighting()); chPreparePool.execute(new Runnable()
public void prepare(final StorableProperties properties) { ExecutorCompletionService completionService = new ExecutorCompletionService<>(threadPool); int counter = 0; for (final PrepareContractionHierarchies prepare : getPreparations()) { LOGGER.info((++counter) + "/" + getPreparations().size() + " calling CH prepare.doWork for " + prepare.getWeighting() + " ... (" + getMemInfo() + ")"); final String name = AbstractWeighting.weightingToFileName(prepare.getWeighting()); completionService.submit(new Runnable() { @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); } threadPool.shutdown(); try { for (int i = 0; i < getPreparations().size(); i++) { completionService.take().get(); } } catch (Exception e) { threadPool.shutdownNow(); throw new RuntimeException(e); } }
@Override public RoutingAlgorithmFactory getDecoratedAlgorithmFactory( RoutingAlgorithmFactory defaultAlgoFactory, HintsMap map ) { boolean forceFlexMode = map.getBool(DISABLE, false); if (!isEnabled() || forceFlexMode) return defaultAlgoFactory; if (preparations.isEmpty()) throw new IllegalStateException("No preparations added to this decorator"); if (map.getWeighting().isEmpty()) map.setWeighting(getDefaultWeighting()); for (PrepareContractionHierarchies p : preparations) { if (p.getWeighting().matches(map)) return p; } throw new IllegalArgumentException("Cannot find RoutingAlgorithmFactory for weighting map " + map); }
routingGraph = graphHopper.getGraphHopperStorage().getGraph(CHGraph.class, ((PrepareContractionHierarchies) routingAlgorithmFactory).getWeighting()); } else { ch = false;
routingGraph = graphHopper.getGraphHopperStorage().getGraph(CHGraph.class, ((PrepareContractionHierarchies) routingAlgorithmFactory).getWeighting()); } else { ch = false;
weighting = ((PrepareContractionHierarchies) chAlgoFactory).getWeighting(); else throw new IllegalStateException("Although CH was enabled a non-CH algorithm factory was returned " + tmpAlgoFactory);
weighting = ((PrepareContractionHierarchies) chAlgoFactory).getWeighting(); else throw new IllegalStateException("Although CH was enabled a non-CH algorithm factory was returned " + tmpAlgoFactory);
weighting = ((PrepareContractionHierarchies) tmpAlgoFactory).getWeighting(); routingGraph = ghStorage.getGraph(CHGraph.class, weighting);