/** * Default graph is a {@link GraphHopperStorage} with an in memory directory and disabled storing on flush. */ public GraphHopperStorage create() { return build().create(byteCapacity); }
@Override public GraphHopperStorage createGHStorage(String location, boolean enabled3D) { // reduce segment size in order to test the case where multiple segments come into the game GraphHopperStorage gs = newGHStorage(new RAMDirectory(location), enabled3D); gs.setSegmentSize(defaultSize / 2); gs.create(defaultSize); return gs; }
GraphHopperStorage createGHStorage(Directory dir, EncodingManager encodingManager, boolean is3D) { return new GraphHopperStorage(dir, encodingManager, is3D, new GraphExtension.NoOpExtension()).create(100); }
/** * 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()); }
@Override GraphHopperStorage createGHStorage(Directory dir, EncodingManager encodingManager, boolean is3D) { return new GraphHopperStorage(Arrays.asList(new FastestWeighting(encodingManager.getEncoder("car"))), dir, encodingManager, is3D, new GraphExtension.NoOpExtension()). create(100); }
@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); }
@Override public GraphHopperStorage createGHStorage(String location, boolean is3D) { GraphHopperStorage gs = new GraphBuilder(encodingManager).set3D(is3D).setLocation(location).setMmap(true).build(); gs.setSegmentSize(defaultSize / 2); gs.create(defaultSize); return gs; } }
@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(); }
@Test public void testEnsureSize() { Directory dir = new RAMDirectory(); graph = newGHStorage(dir, false).create(defaultSize); int roughEdgeRowLength = 4 * 8; int testIndex = dir.find("edges", DAType.RAM_INT).getSegmentSize() * 3 / roughEdgeRowLength; // we need a big node index to trigger multiple segments, but low enough to avoid OOM graph.edge(0, testIndex, 10, true); // test if optimize works without error graph.optimize(); }
@Test(expected = IllegalStateException.class) public void testLoadingWithExtraWeighting_throws() { // we start with one weighting GraphHopperStorage ghStorage = newGHStorage(new GHDirectory(defaultGraphLoc, DAType.RAM_STORE), false); ghStorage.create(defaultSize); ghStorage.flush(); // but then add an additional weighting and try to load the graph from disk -> error GraphHopperStorage newGHStorage = createStorageWithWeightings( new FastestWeighting(carEncoder), new ShortestWeighting(carEncoder)); newGHStorage.loadExisting(); }
@Before public void setUp() { carEncoder = new CarFlagEncoder(); encodingManager = new EncodingManager(carEncoder); g = new GraphHopperStorage(new RAMDirectory(), encodingManager, false, new GraphExtension.NoOpExtension()).create(100); }
@Before public void setUp() { encoder = new CarFlagEncoder(); tm = TraversalMode.NODE_BASED; GraphHopperStorage tmp = new GraphHopperStorage(new RAMDirectory(), new EncodingManager(encoder), false, new GraphExtension.NoOpExtension()); tmp.create(1000); graph = tmp; }
@Before public void setUp() { encoder = new CarFlagEncoder(); ghStorage = new GraphHopperStorage(new RAMDirectory(), new EncodingManager(encoder), false, new GraphExtension.NoOpExtension()); ghStorage.create(1000); }
@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 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(); }
@SuppressWarnings("resource") @Before public void setUp() { dataFlagEncoder = new DataFlagEncoder(); graph = new GraphHopperStorage(new RAMDirectory(), new EncodingManager(Arrays.asList(dataFlagEncoder, new FootFlagEncoder()), 8), true, new GraphExtension.NoOpExtension()).create(100); edgeElevationInterpolator = createEdgeElevationInterpolator(); interpolatableWay = createInterpolatableWay(); normalWay = new ReaderWay(0); normalWay.setTag("highway", "primary"); }
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; }
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 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()); }
@Test public void testRoutingFailsWithInvalidGraph_issue665() { GraphHopperStorage graph = new GraphHopperStorage( new RAMDirectory(), em, true, new GraphExtension.NoOpExtension()); graph.create(100); ReaderWay way = new ReaderWay(0); way.setTag("route", "ferry"); long includeWay = em.acceptWay(way); long relationFlags = 0; long wayFlags = em.handleWayTags(way, includeWay, relationFlags); graph.edge(0, 1).setDistance(247).setFlags(wayFlags); assertTrue(isGraphValid(graph, encoder)); }