@Override public void start() { graphHopper.importOrLoad(); logger.info("loaded graph at:" + graphHopper.getGraphHopperLocation() + ", data_reader_file:" + graphHopper.getDataReaderFile() + ", flag_encoders:" + graphHopper.getEncodingManager() + ", " + graphHopper.getGraphHopperStorage().toDetailsString()); }
/** * This method applies the changes to the graph specified as feature collection. It does so by locking the routing * to avoid concurrent changes which could result in incorrect routing (like when done while a Dijkstra search) or * also while just reading one edge row (inconsistent edge properties). */ public ChangeGraphResponse changeGraph(Collection<JsonFeature> collection) { // TODO allow calling this method if called before CH preparation if (getCHFactoryDecorator().isEnabled()) throw new IllegalArgumentException("To use the changeGraph API you need to turn off CH"); Lock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { ChangeGraphHelper overlay = createChangeGraphHelper(ghStorage, locationIndex); long updateCount = overlay.applyChanges(encodingManager, collection); return new ChangeGraphResponse(updateCount); } finally { writeLock.unlock(); } }
LocationIndex locationIndex = graphHopper.getLocationIndex(); QueryResult qr = locationIndex.findClosest(point.lat, point.lon, edgeFilter); if (!qr.isValid()) throw new IllegalArgumentException("Point not found:" + point); Graph graph = graphHopper.getGraphHopperStorage(); QueryGraph queryGraph = new QueryGraph(graph); queryGraph.lookup(Collections.singletonList(qr)); RouteResource.initHints(hintsMap, uriInfo.getQueryParameters()); Weighting weighting = graphHopper.createWeighting(hintsMap, encoder, graph); Isochrone isochrone = new Isochrone(queryGraph, weighting, reverseFlow); if (isochrone.getVisitedNodes() > graphHopper.getMaxVisitedNodes() / 5) { throw new IllegalArgumentException("Server side reset: too many junction nodes would have to explored (" + isochrone.getVisitedNodes() + "). Let us know if you need this increased.");
/** * Imports provided data from disc and creates graph. Depending on the settings the resulting * graph will be stored to disc so on a second call this method will only load the graph from * disc which is usually a lot faster. */ public GraphHopper importOrLoad() { if (!load(ghLocation)) { printInfo(); process(ghLocation); } else { printInfo(); } return this; }
protected Path saveDoInBackground(Void... v) throws Exception { GraphHopper tmpHopp = new GraphHopper().forMobile(); tmpHopp.load(new File(mapsFolder, currentArea).getAbsolutePath() + "-gh"); log("found graph " + tmpHopp.getGraphHopperStorage().toString() + ", nodes:" + tmpHopp.getGraphHopperStorage().getNodes()); hopper = tmpHopp; return null; }
public MiniGraphUI(GraphHopper hopper, boolean debug) { final Graph graph = hopper.getGraphHopperStorage(); this.na = graph.getNodeAccess(); encoder = hopper.getEncodingManager().getEncoder("car"); HintsMap map = new HintsMap("fastest"). setVehicle("car"); if (ch) { map.put(Parameters.Landmark.DISABLE, true); weighting = hopper.getCHFactoryDecorator().getWeightings().get(0); routingGraph = hopper.getGraphHopperStorage().getGraph(CHGraph.class, weighting); final RoutingAlgorithmFactory tmpFactory = hopper.getAlgorithmFactory(map); algoFactory = new RoutingAlgorithmFactory() { weighting = hopper.createWeighting(map, encoder, graph); final RoutingAlgorithmFactory tmpFactory = hopper.getAlgorithmFactory(map); algoFactory = new RoutingAlgorithmFactory() { this.index = (LocationIndexTree) hopper.getLocationIndex();
vehicle = getDefaultVehicle().toString(); request.setVehicle(vehicle); checkIfPointsAreInBounds(points); return Collections.emptyList(); RoutingAlgorithmFactory tmpAlgoFactory = getAlgorithmFactory(hints); Weighting weighting; QueryGraph queryGraph; 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); } else { checkNonChMaxWaypointDistance(points); queryGraph = new QueryGraph(ghStorage); queryGraph.lookup(qResults); weighting = createWeighting(hints, encoder, queryGraph); ghRsp.addDebugInfo("tmode:" + tMode.toString()); throw new IllegalArgumentException("The max_visited_nodes parameter has to be below or equal to:" + maxVisitedNodes); weighting = createTurnWeighting(queryGraph, weighting, tMode);
setGraphHopperLocation(graphHopperFolder); setEncodingManager(EncodingManager.create(flagEncoderFactory, ghLocation)); initLMAlgoFactoryDecorator(); initCHAlgoFactoryDecorator(); ghStorage = new GraphHopperStorage(chFactoryDecorator.getWeightings(), dir, encodingManager, hasElevation(), ext); } else { ghStorage = new GraphHopperStorage(dir, encodingManager, hasElevation(), ext); if (ghStorage.getDirectory().getDefaultType().isStoring() && isAllowWrites()) { lockFactory.setLockDir(new File(ghLocation)); lock = lockFactory.create(fileLockName, false); return false; postProcessing(); fullyLoaded = true; return true;
GraphHopper hopper = new GraphHopper().init(args); hopper.getCHFactoryDecorator().setEnabled(false); hopper.importOrLoad(); GraphHopper hopper = new GraphHopper().init(args); hopper.getCHFactoryDecorator().setEnabled(false); logger.info("loading graph from cache"); hopper.load("./graph-cache"); FlagEncoder firstEncoder = hopper.getEncodingManager().fetchEdgeEncoders().get(0); GraphHopperStorage graph = hopper.getGraphHopperStorage(); logger.info("Setup lookup index. Accuracy filter is at " + gpxAccuracy + "m"); LocationIndexMatch locationIndex = new LocationIndexMatch(graph, (LocationIndexTree) hopper.getLocationIndex(), gpxAccuracy); MapMatching mapMatching = new MapMatching(graph, locationIndex, firstEncoder); mapMatching.setSeparatedSearchDistance(args.getInt("separated_search_distance", 500));
hopper.init(args). forDesktop(); if (cleanGraph) { hopper.clean(); hopper.getCHFactoryDecorator().setDisablingAllowed(true); hopper.getLMFactoryDecorator().setDisablingAllowed(true); hopper.importOrLoad(); GraphHopperStorage g = hopper.getGraphHopperStorage(); String vehicleStr = args.get("graph.flag_encoders", "car"); FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicleStr); GHBitSet allowedEdges = printGraphDetails(g, vehicleStr); printMiscUnitPerfTests(g, isCH, encoder, count * 100, allowedEdges); printLocationIndexQuery(g, hopper.getLocationIndex(), count); printTimeOfRouteQuery(hopper, isCH, isLM, count / 20, "routing", vehicleStr, true, -1, true); if (hopper.getLMFactoryDecorator().isEnabled()) { System.gc(); isLM = true; if (hopper.getCHFactoryDecorator().isEnabled()) { isCH = true; if (hopper.getLMFactoryDecorator().isEnabled()) { isLM = true; System.gc();
graph.close(); GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false); hopper.getLMFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest")); hopper.importOrLoad(); EncodingManager em = hopper.getEncodingManager(); assertNotNull(em); assertEquals(1, em.fetchEdgeEncoders().size()); assertEquals(16, hopper.getLMFactoryDecorator().getLandmarks()); hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false); hopper.getLMFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest")); hopper.importOrLoad(); assertEquals(1, em.fetchEdgeEncoders().size()); assertEquals(16, hopper.getLMFactoryDecorator().getLandmarks());
public static List<AlgoHelperEntry> createAlgos(final GraphHopper hopper, final HintsMap hints, TraversalMode tMode) { GraphHopperStorage ghStorage = hopper.getGraphHopperStorage(); LocationIndex idx = hopper.getLocationIndex(); addStr = "turn|"; FlagEncoder encoder = hopper.getEncodingManager().getEncoder(hints.getVehicle()); Weighting weighting = hopper.createWeighting(hints, encoder, hopper.getGraphHopperStorage()); if (hopper.getLMFactoryDecorator().isEnabled()) { final HintsMap lmHints = new HintsMap(defaultHints).put(Parameters.Landmark.DISABLE, false); prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(astarbiOpts).hints(lmHints).build(), idx, "astarbi|landmarks|" + weighting) { if (hopper.getCHFactoryDecorator().isEnabled()) { final HintsMap chHints = new HintsMap(defaultHints).put(Parameters.CH.DISABLE, false); Weighting pickedWeighting = null; for (Weighting tmpWeighting : hopper.getCHFactoryDecorator().getWeightings()) { if (tmpWeighting.equals(weighting)) { pickedWeighting = tmpWeighting; throw new IllegalStateException("Didn't find weighting " + hints.getWeighting() + " in " + hopper.getCHFactoryDecorator().getWeightings());
@Test public void testDisconnected179() { GraphHopperStorage graph = new GraphBuilder(encodingManager).create(); initGraph(graph); GraphHopper instance = new GraphHopper(). setStoreOnFlush(false). setEncodingManager(encodingManager).setCHEnabled(false). loadGraph(graph); GHResponse rsp = instance.route(new GHRequest(42, 10, 42, 10.4)); assertTrue(rsp.hasErrors()); try { rsp.getBest().getPoints(); assertTrue(false); } catch (Exception ex) { } instance.close(); }
graphHopper.init(graphHopperConfiguration).forDesktop(); graphHopper.getCHFactoryDecorator().setEnabled(false); graphHopper.getCHFactoryDecorator().setDisablingAllowed(true); graphHopper.importOrLoad(); GraphHopperStorage graph = graphHopper.getGraphHopperStorage(); bbox = graph.getBounds(); LocationIndexTree locationIndex = (LocationIndexTree) graphHopper.getLocationIndex(); AlgorithmOptions algoOpts = AlgorithmOptions.start() .maxVisitedNodes((int) 1e20)
if (vehicle.isEmpty()) vehicle = getDefaultVehicle().toString(); request.setVehicle(vehicle); + "Supported are: " + getEncodingManager()); return Collections.emptyList(); RoutingAlgorithmFactory tmpAlgoFactory = getAlgorithmFactory(hints); Weighting weighting = null; Graph routingGraph = ghStorage; throw new IllegalStateException("Although CH was enabled a non-CH algorithm factory was returned " + tmpAlgoFactory); tMode = getCHFactoryDecorator().getNodeBase(); weighting = ((PrepareContractionHierarchies) tmpAlgoFactory).getWeighting(); routingGraph = ghStorage.getGraph(CHGraph.class, weighting); weighting = createWeighting(hints, encoder); weighting = createTurnWeighting(queryGraph, encoder, weighting, tMode);
public static GraphHopper createHopper(boolean memoryMapped, String graphFolder) { GraphHopper ret = null; ret = new GraphHopper().forDesktop(); // initialise the encoders ourselves as we can use multiple // encoders for same vehicle type corresponding to different // times of day (i.e. rush hours) ret.setEncodingManager(createEncodingManager(graphFolder)); // don't need to write so disable the lock file (allows us to run out of program files) ret.setAllowWrites(false); if (memoryMapped) { ret.setMemoryMapped(); } ret.setGraphHopperLocation(graphFolder); ret.importOrLoad(); return ret; }
@Override public GraphHopperStorage provide() { return graphHopper.getGraphHopperStorage(); }
setGraphHopperLocation(graphHopperFolder); defaultSegmentSize = args.getInt("graph.dataaccess.segment_size", defaultSegmentSize); String flagEncodersStr = args.get("graph.flag_encoders", ""); if (!flagEncodersStr.isEmpty()) setEncodingManager(new EncodingManager(flagEncoderFactory, flagEncodersStr, bytesForFlags)); tmpProvider.setBaseURL(baseURL); tmpProvider.setDAType(elevationDAType); setElevationProvider(tmpProvider);
return; hopper.close(); setOSMFile(file.getAbsolutePath()). forDesktop(). setEncodingManager(new EncodingManager(getAvailableTravelModeNames(), BYTES_FOR_EDGE_FLAGS)). setCHEnabled(false). setEnableInstructions(false). setGraphHopperLocation(path.getAbsolutePath()). importOrLoad(); } catch (IllegalStateException e) { log.warning("Could not initialize GraphHopper: " + e);
graphHopperConfiguration.put("graph.location", "graph-cache"); GraphHopper hopper = new GraphHopperOSM().init(graphHopperConfiguration); hopper.getCHFactoryDecorator().setEnabled(false); System.out.println("loading graph from cache"); hopper.load(graphHopperConfiguration.get("graph.location", "graph-cache")); FlagEncoder firstEncoder = hopper.getEncodingManager().fetchEdgeEncoders().get(0); AlgorithmOptions opts = AlgorithmOptions.start(). algorithm(Parameters.Algorithms.DIJKSTRA_BI).traversalMode(hopper.getTraversalMode()). weighting(new FastestWeighting(firstEncoder)). maxVisitedNodes(args.getInt("max_visited_nodes")). time = measurements.get(0).getTime(); writer.append(pathWrapper.getInstructions().createGPX(gpx.trk.get(0).name != null ? gpx.trk.get(0).name : "", time, hopper.hasElevation(), withRoute, true, false, Constants.VERSION));