/** * Create a new storage from the specified one without copying the data. */ public static GraphHopperStorage newStorage(GraphHopperStorage store) { Directory outdir = guessDirectory(store); boolean is3D = store.getNodeAccess().is3D(); return new GraphHopperStorage(store.getCHWeightings(), outdir, store.getEncodingManager(), is3D, store.getExtension()). create(store.getNodes()); }
@Test public void testBigDataEdge() { Directory dir = new RAMDirectory(); GraphHopperStorage graph = new GraphHopperStorage(dir, encodingManager, false, new GraphExtension.NoOpExtension()); graph.create(defaultSize); ((BaseGraph) graph.getGraph(Graph.class)).setEdgeCount(Integer.MAX_VALUE / 2); assertTrue(graph.getAllEdges().next()); graph.close(); }
@GET public Info getInfo() { final Info info = new Info(); // use bbox always without elevation (for backward compatibility) info.bbox = new BBox(storage.getBounds().minLon, storage.getBounds().maxLon, storage.getBounds().minLat, storage.getBounds().maxLat); info.supported_vehicles = storage.getEncodingManager().toString().split(","); for (String v : info.supported_vehicles) { Info.PerVehicle perVehicleJson = new Info.PerVehicle(); perVehicleJson.elevation = hasElevation; info.features.put(v, perVehicleJson); } info.import_date = storage.getProperties().get("datareader.import.date"); info.data_date = storage.getProperties().get("datareader.data.date"); info.prepare_ch_date = storage.getProperties().get("prepare.ch.date"); info.prepare_date = storage.getProperties().get("prepare.ch.date"); return info; } }
/** * Removes nodes if all edges are not accessible. I.e. removes zero degree nodes. */ void markNodesRemovedIfUnreachable() { EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer(); for (int nodeIndex = 0; nodeIndex < ghStorage.getNodes(); nodeIndex++) { if (detectNodeRemovedForAllEncoders(edgeExplorer, nodeIndex)) ghStorage.markNodeRemoved(nodeIndex); } }
@Override public String toString() { return (isCHPossible() ? "CH|" : "") + encodingManager + "|" + getDirectory().getDefaultType() + "|" + baseGraph.nodeAccess.getDimension() + "D" + "|" + baseGraph.extStorage + "|" + getProperties().versionsToString(); }
@Test public void testSave_and_Freeze() throws IOException { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true).create(defaultSize); graph.edge(1, 0); graph.freeze(); graph.flush(); graph.close(); graph = newGHStorage(new MMapDirectory(defaultGraphLoc), true); assertTrue(graph.loadExisting()); assertEquals(2, graph.getNodes()); assertTrue(graph.isFrozen()); }
private Graph initExampleGraph() { GraphHopperStorage gs = new GraphHopperStorage(new RAMDirectory(), em, true, new GraphExtension.NoOpExtension()).create(1000); NodeAccess na = gs.getNodeAccess(); // 50--(0.0001)-->49--(0.0004)-->55--(0.0005)-->60 na.setNode(0, 51.1, 12.001, 50); na.setNode(1, 51.1, 12.002, 60); EdgeIteratorState edge = gs.edge(0, 1). setWayGeometry(Helper.createPointList3D(51.1, 12.0011, 49, 51.1, 12.0015, 55)); edge.setDistance(100); edge.setFlags(encoder.setReverseSpeed(encoder.setProperties(10, true, true), 15)); return gs; }
@Test public void testDoThrowExceptionIfDimDoesNotMatch() { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false); graph.create(1000); graph.flush(); graph.close(); graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true); try { graph.loadExisting(); assertTrue(false); } catch (Exception ex) { } }
@Test public void testIdentical() { GraphHopperStorage store = new GraphHopperStorage(new RAMDirectory(), encodingManager, true, new GraphExtension.NoOpExtension()); assertEquals(store.getNodes(), store.getGraph(Graph.class).getNodes()); assertEquals(store.getAllEdges().length(), store.getGraph(Graph.class).getAllEdges().length()); }
@Override protected GraphHopperStorage createGHStorage(EncodingManager em, List<? extends Weighting> weightings, boolean is3D) { return new GraphHopperStorage(weightings, new RAMDirectory(), em, is3D, new GraphExtension.NoOpExtension()). create(1000); }
@Test public void testClone() { graph = createGHStorage(); graph.edge(1, 2, 10, true); NodeAccess na = graph.getNodeAccess(); na.setNode(0, 12, 23); na.setNode(1, 8, 13); na.setNode(2, 2, 10); na.setNode(3, 5, 9); graph.edge(1, 3, 10, true); Graph cloneGraph = graph.copyTo(AbstractGraphStorageTester.this.createGHStorage(locationParent + "/clone", false)); assertEquals(graph.getNodes(), cloneGraph.getNodes()); assertEquals(count(carOutExplorer.setBaseNode(1)), count(cloneGraph.createEdgeExplorer(carOutFilter).setBaseNode(1))); cloneGraph.edge(1, 4, 10, true); assertEquals(3, count(cloneGraph.createEdgeExplorer(carOutFilter).setBaseNode(1))); assertEquals(graph.getBounds(), cloneGraph.getBounds()); Helper.close((Closeable) cloneGraph); }
ghStorage = new GraphHopperStorage(chFactoryDecorator.getWeightings(), dir, encodingManager, hasElevation(), ext); } else { ghStorage = new GraphHopperStorage(dir, encodingManager, hasElevation(), ext); ghStorage.setSegmentSize(defaultSegmentSize); if (ghStorage.getDirectory().getDefaultType().isStoring() && isAllowWrites()) { lockFactory.setLockDir(new File(ghLocation)); lock = lockFactory.create(fileLockName, false); if (!ghStorage.loadExisting()) return false;
@Test public void testMoreComplexGraph() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initShortcutsGraph(lg); int oldCount = g.getAllEdges().length(); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(oldCount, g.getEdges()); assertEquals(oldCount + 7, lg.getEdges()); }
public GraphHopperGtfs(PtFlagEncoder flagEncoder, TranslationMap translationMap, GraphHopperStorage graphHopperStorage, LocationIndex locationIndex, GtfsStorage gtfsStorage, RealtimeFeed realtimeFeed) { this.flagEncoder = flagEncoder; this.accessEgressWeighting = new FastestWeighting(graphHopperStorage.getEncodingManager().getEncoder("foot")); this.translationMap = translationMap; this.graphHopperStorage = graphHopperStorage; this.locationIndex = locationIndex; this.gtfsStorage = gtfsStorage; this.realtimeFeed = realtimeFeed; this.tripFromLabel = new TripFromLabel(this.gtfsStorage, this.realtimeFeed); }
@Override protected CHGraph getGraph(GraphHopperStorage ghStorage, Weighting weighting) { return ghStorage.getGraph(CHGraph.class, weighting); }
@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); } }
@Test public void testNoCreateCalled() throws IOException { GraphHopperStorage gs = new GraphBuilder(encodingManager).build(); try { ((BaseGraph) gs.getGraph(Graph.class)).ensureNodeIndex(123); assertFalse("AssertionError should be raised", true); } catch (AssertionError err) { assertTrue(true); } catch (Exception ex) { assertFalse("AssertionError should be raised, but was " + ex.toString(), true); } finally { gs.close(); } }
@Test public void testRemoveSubnetworkIfOnlyOneVehicle() { GraphHopperStorage g = createSubnetworkTestStorage2(em); PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, em.fetchEdgeEncoders()); instance.setMinNetworkSize(4); instance.doWork(); g.optimize(); assertEquals(6, g.getNodes()); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(g)); EdgeExplorer explorer = g.createEdgeExplorer(); assertEquals(GHUtility.asSet(2, 1, 5), GHUtility.getNeighbors(explorer.setBaseNode(3))); // do not remove because small network is big enough g = createSubnetworkTestStorage2(em); instance = new PrepareRoutingSubnetworks(g, em.fetchEdgeEncoders()); instance.setMinNetworkSize(3); instance.doWork(); g.optimize(); assertEquals(9, g.getNodes()); }
@Test(expected = IllegalStateException.class) public void testLoadingWithWrongWeighting_throws() { // we start with one weighting GraphHopperStorage ghStorage = newGHStorage(new GHDirectory(defaultGraphLoc, DAType.RAM_STORE), false); ghStorage.create(defaultSize); ghStorage.flush(); // but then configure another weighting and try to load the graph from disk -> error GraphHopperStorage newGHStorage = createStorageWithWeightings(new ShortestWeighting(carEncoder)); newGHStorage.loadExisting(); }
private GHBitSet printGraphDetails(GraphHopperStorage g, String vehicleStr) { // graph size (edge, node and storage size) put("graph.nodes", g.getNodes()); put("graph.edges", g.getAllEdges().length()); put("graph.size_in_MB", g.getCapacity() / MB); put("graph.encoder", vehicleStr); AllEdgesIterator iter = g.getAllEdges(); final int maxEdgesId = g.getAllEdges().length(); final GHBitSet allowedEdges = new GHBitSetImpl(maxEdgesId); fillAllowedEdges(iter, allowedEdges); put("graph.valid_edges", allowedEdges.getCardinality()); return allowedEdges; }