/** * @throws IllegalStateException if not loadable. */ public GraphHopperStorage load() { GraphHopperStorage gs = build(); if (!gs.loadExisting()) { throw new IllegalStateException("Cannot load graph " + location); } return gs; } }
Graph createGraph() { return new GraphBuilder(encodingManager).create(); }
GraphHopperStorage createGHStorage() { return new GraphBuilder(encodingManager).setCHGraph(weighting).create(); }
/** * Creates a CHGraph */ public CHGraph chGraphCreate(Weighting singleCHWeighting) { return setCHGraph(singleCHWeighting).create().getGraph(CHGraph.class, singleCHWeighting); }
@Test public void testCannotBeLoadedWithNormalGraphHopperStorageClass() { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false).create(defaultSize); graph.flush(); graph.close(); graph = new GraphBuilder(encodingManager).setLocation(defaultGraphLoc).setMmap(false).setStore(true).create(); try { graph.loadExisting(); fail(); } catch (Exception ex) { } graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false); assertTrue(graph.loadExisting()); // empty graph still has invalid bounds assertEquals(graph.getBounds(), BBox.createInverse(false)); }
@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; } }
protected GraphHopperStorage createGHStorage(EncodingManager em, List<? extends Weighting> weightings, boolean is3D) { return new GraphBuilder(em).set3D(is3D).create(); }
@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 testCopyWithSelfRef() { Graph g = initUnsorted(createGraph()); g.edge(0, 0, 11, true); CHGraph lg = new GraphBuilder(encodingManager).chGraphCreate(new FastestWeighting(carEncoder)); GHUtility.copyTo(g, lg); assertEquals(g.getAllEdges().length(), lg.getEdges()); }
/** * Creates a CHGraph */ public CHGraph chGraphCreate(Weighting singleCHWeighting) { return setCHGraph(singleCHWeighting).create().getGraph(CHGraph.class, singleCHWeighting); }
CarFlagEncoder carFlagEncoder = new CarFlagEncoder(); EncodingManager encodingManager = new EncodingManager(carFlagEncoder); GraphHopperStorage graph = new GraphBuilder(encodingManager).setStore(true). setLocation(defaultGraphLoc).create();
Graph createGraph() { return new GraphBuilder(encodingManager).create(); }
@Test public void testDifferentEdgeFilter() { GraphHopperStorage g = new GraphBuilder(encodingManager).setCHGraph(new FastestWeighting(carEncoder)).create(); g.edge(4, 3, 10, true); g.edge(3, 6, 10, true); g.edge(4, 5, 10, true); g.edge(5, 6, 10, true); DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(g); algo.setEdgeFilter(new EdgeFilter() { @Override public boolean accept(EdgeIteratorState iter) { return iter.getAdjNode() != 5; } }); Path p = algo.calcPath(4, 6); assertEquals(IntArrayList.from(new int[]{4, 3, 6}), p.calcNodes()); // important call! algo.clear(); algo.setEdgeFilter(new EdgeFilter() { @Override public boolean accept(EdgeIteratorState iter) { return iter.getAdjNode() != 3; } }); p = algo.calcPath(4, 6); assertEquals(IntArrayList.from(new int[]{4, 5, 6}), p.calcNodes()); }
/** * Creates a CHGraph */ public CHGraph chGraphCreate(Weighting singleCHWeighting) { return setCHGraph(singleCHWeighting).create().getGraph(CHGraph.class, singleCHWeighting); }
@Test public void testStorageProperties() { graph = new GraphBuilder(encodingManager).setStore(true).setLocation(defaultGraphLoc).create();
/** * Default graph is a {@link GraphHopperStorage} with an in memory directory and disabled storing on flush. */ public GraphHopperStorage create() { return build().create(byteCapacity); }
GraphHopperStorage createStorage(EncodingManager eman) { return new GraphBuilder(eman).create(); }
@Test public void testGetWeightIfAdvancedEncoder() { FlagEncoder customEncoder = new Bike2WeightFlagEncoder(); EncodingManager em = new EncodingManager(customEncoder); FastestWeighting weighting = new FastestWeighting(customEncoder); GraphHopperStorage ghStorage = new GraphBuilder(em).setCHGraph(weighting).create(); ghStorage.edge(0, 2); ghStorage.freeze(); CHGraphImpl lg = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting); CHEdgeIteratorState sc1 = lg.shortcut(0, 1); long flags = customEncoder.setProperties(10, false, true); sc1.setFlags(flags); sc1.setWeight(100.123); assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getAdjNode()).getWeight(), 1e-3); assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getBaseNode()).getWeight(), 1e-3); assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getBaseNode(), sc1.getAdjNode())).getWeight(), 1e-3); assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getAdjNode(), sc1.getBaseNode())).getWeight(), 1e-3); sc1 = lg.shortcut(1, 0); assertTrue(sc1.isShortcut()); sc1.setFlags(PrepareEncoder.getScDirMask()); sc1.setWeight(1.011011); assertEquals(1.011011, sc1.getWeight(), 1e-3); }
/** * Creates a CHGraph */ public CHGraph chGraphCreate( Weighting singleCHWeighting ) { return setCHGraph(singleCHWeighting).create().getGraph(CHGraph.class, singleCHWeighting); }
/** * Default graph is a GraphStorage with an in memory directory and disabled storing on flush. */ public GraphHopperStorage create() { return build().create(byteCapacity); }