@Override public int getEdges() { return getAllEdges().length(); }
@Override public AllEdgesIterator getAllEdges() { final AllEdgesIterator edge = baseGraph.getAllEdges(); return new AllEdgesIterator() { @Override
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; }
if (allRemoved > ghStorage.getAllEdges().length() / 2) throw new IllegalStateException("Too many total edges were removed: " + allRemoved + ", all edges:" + ghStorage.getAllEdges().length()); return allRemoved;
final LinkedList<VirtualEdgeIteratorState> additionalEdges = new LinkedList<>(); final Graph overlayGraph = new Graph() { int firstEdge = graphHopperStorage.getAllEdges().length(); final NodeAccess nodeAccess = new NodeAccess() { IntIntHashMap additionalNodeFields = new IntIntHashMap();
private void interpolateElevationsOfTowerNodes() { final AllEdgesIterator edge = storage.getAllEdges(); final GHBitSet visitedEdgeIds = new GHBitSetImpl(edge.length()); final EdgeExplorer edgeExplorer = storage.createEdgeExplorer(); while (edge.next()) { final int edgeId = edge.getEdge(); if (isInterpolatableEdge(edge)) { if (!visitedEdgeIds.contains(edgeId)) { interpolateEdge(edge, visitedEdgeIds, edgeExplorer); } } visitedEdgeIds.add(edgeId); } }
/** * Internal method to clean up the graph. */ protected void cleanUp() { int prevNodeCount = ghStorage.getNodes(); PrepareRoutingSubnetworks preparation = new PrepareRoutingSubnetworks(ghStorage, encodingManager.fetchEdgeEncoders()); preparation.setMinNetworkSize(minNetworkSize); preparation.setMinOneWayNetworkSize(minOneWayNetworkSize); preparation.doWork(); int currNodeCount = ghStorage.getNodes(); logger.info("edges: " + Helper.nf(ghStorage.getAllEdges().length()) + ", nodes " + Helper.nf(currNodeCount) + ", there were " + Helper.nf(preparation.getMaxSubnetworks()) + " subnetworks. removed them => " + Helper.nf(prevNodeCount - currNodeCount) + " less nodes"); }
@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); } }
/** * This method makes edges crossing the specified border inaccessible to split a bigger area into smaller subnetworks. * This is important for the world wide use case to limit the maximum distance and also to detect unreasonable routes faster. */ protected IntHashSet findBorderEdgeIds(SpatialRuleLookup ruleLookup) { AllEdgesIterator allEdgesIterator = graph.getAllEdges(); NodeAccess nodeAccess = graph.getNodeAccess(); IntHashSet inaccessible = new IntHashSet(); while (allEdgesIterator.next()) { int adjNode = allEdgesIterator.getAdjNode(); SpatialRule ruleAdj = ruleLookup.lookupRule(nodeAccess.getLatitude(adjNode), nodeAccess.getLongitude(adjNode)); int baseNode = allEdgesIterator.getBaseNode(); SpatialRule ruleBase = ruleLookup.lookupRule(nodeAccess.getLatitude(baseNode), nodeAccess.getLongitude(baseNode)); if (ruleAdj != ruleBase) { inaccessible.add(allEdgesIterator.getEdge()); } } return inaccessible; }
@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()); }
@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(); }
private void interpolateElevationsOfPillarNodes() { final EdgeIterator edge = storage.getAllEdges(); final NodeAccess nodeAccess = storage.getNodeAccess(); while (edge.next()) { if (isInterpolatableEdge(edge)) { int firstNodeId = edge.getBaseNode(); int secondNodeId = edge.getAdjNode(); double lat0 = nodeAccess.getLat(firstNodeId); double lon0 = nodeAccess.getLon(firstNodeId); double ele0 = nodeAccess.getEle(firstNodeId); double lat1 = nodeAccess.getLat(secondNodeId); double lon1 = nodeAccess.getLon(secondNodeId); double ele1 = nodeAccess.getEle(secondNodeId); final PointList pointList = edge.fetchWayGeometry(0); final int count = pointList.size(); for (int index = 0; index < count; index++) { double lat = pointList.getLat(index); double lon = pointList.getLon(index); double ele = elevationInterpolator.calculateElevationBasedOnTwoPoints(lat, lon, lat0, lon0, ele0, lat1, lon1, ele1); pointList.set(index, lat, lon, ele); } edge.setWayGeometry(pointList); } } } }
@Test public void testDirectedGraph2() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initDirected2(g); int oldCount = GHUtility.count(g.getAllEdges()); assertEquals(19, oldCount); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); // PrepareTowerNodesShortcutsTest.printEdges(g); assertEquals(oldCount, g.getAllEdges().length()); assertEquals(oldCount, GHUtility.count(g.getAllEdges())); long numShortcuts = 9; assertEquals(numShortcuts, prepare.getShortcuts()); assertEquals(oldCount + numShortcuts, lg.getEdges()); assertEquals(oldCount + numShortcuts, GHUtility.count(lg.getAllEdges())); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(0, 10); assertEquals(10, p.getDistance(), 1e-6); assertEquals(IntArrayList.from(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), p.calcNodes()); }
graph.edge(1, 2, 1, true); graph.edge(2, 3, 1, true); AllEdgesIterator iter = graph.getAllEdges(); assertEquals(4, GHUtility.count(iter)); assertEquals(4, iter.length()); iter = graph.getAllEdges(); assertEquals(2, GHUtility.count(iter)); assertEquals(4, iter.length()); iter = graph.getAllEdges(); assertTrue(iter.next()); EdgeIteratorState eState = iter.detach(false);
@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()); }
@Test public void testRoundaboutUnpacking() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initRoundaboutGraph(g); int oldCount = g.getAllEdges().length(); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(oldCount, g.getEdges()); assertEquals(oldCount + 23, lg.getEdges()); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(4, 7); assertEquals(IntArrayList.from(4, 5, 6, 7), p.calcNodes()); }
AllEdgesIterator iter = graph.getAllEdges(); while (iter.next()) { long flags = GHUtility.getEdge(graph, 0, 1).getFlags();
@Test public void testGetAllEdges() { graph = createGHStorage(); graph.edge(0, 1, 2, true); graph.edge(3, 1, 1, false); graph.edge(3, 2, 1, false); EdgeIterator iter = graph.getAllEdges(); assertTrue(iter.next()); int edgeId = iter.getEdge(); assertEquals(0, iter.getBaseNode()); assertEquals(1, iter.getAdjNode()); assertEquals(2, iter.getDistance(), 1e-6); assertTrue(iter.next()); int edgeId2 = iter.getEdge(); assertEquals(1, edgeId2 - edgeId); assertEquals(1, iter.getBaseNode()); assertEquals(3, iter.getAdjNode()); assertTrue(iter.next()); assertEquals(2, iter.getBaseNode()); assertEquals(3, iter.getAdjNode()); assertFalse(iter.next()); }
private void setOrigEdgeCount( int edgeId, int value ) { edgeId -= maxEdgesCount; if (edgeId < 0) { // ignore setting as every normal edge has original edge count of 1 if (value != 1) throw new IllegalStateException("Trying to set original edge count for normal edge to a value = " + value + ", edge:" + (edgeId + maxEdgesCount) + ", max:" + maxEdgesCount + ", graph.max:" + ghStorage.getAllEdges().getMaxId()); return; } long tmp = (long) edgeId * 4; originalEdges.ensureCapacity(tmp + 4); originalEdges.setInt(tmp, value); }
@Override public void initFromGraph() { inEdgeExplorer = prepareGraph.createEdgeExplorer(DefaultEdgeFilter.inEdges(encoder)); outEdgeExplorer = prepareGraph.createEdgeExplorer(DefaultEdgeFilter.outEdges(encoder)); maxLevel = prepareGraph.getNodes(); maxEdgesCount = ghStorage.getAllEdges().length(); }