int calcChecksum() { // do not include the edges as we could get problem with CHGraph due to shortcuts // ^ graph.getAllEdges().count(); return graph.getNodes(); }
public DijkstraOneToMany(Graph graph, Weighting weighting, TraversalMode tMode) { super(graph, weighting, tMode); parents = new int[graph.getNodes()]; Arrays.fill(parents, EMPTY_PARENT); edgeIds = new int[graph.getNodes()]; Arrays.fill(edgeIds, EdgeIterator.NO_EDGE); weights = new double[graph.getNodes()]; Arrays.fill(weights, Double.MAX_VALUE); heap = new IntDoubleBinaryHeap(1000); changedNodes = new IntArrayListWithCap(); }
public Dijkstra(Graph graph, Weighting weighting, TraversalMode tMode) { super(graph, weighting, tMode); int size = Math.min(Math.max(200, graph.getNodes() / 10), 2000); initCollections(size); }
@Override public int getNodes() { return IntStream.concat( IntStream.of(baseGraph.getNodes()-1), extraEdges.stream().flatMapToInt(edge -> IntStream.of(edge.getBaseNode(), edge.getAdjNode()))) .max().getAsInt()+1; }
Stream<EdgeIteratorState> exploreEdgesAround(Label label) { final List<VirtualEdgeIteratorState> extraEdges = reverse ? extraEdgesByDestination.get(label.adjNode) : extraEdgesBySource.get(label.adjNode); return Stream.concat( label.adjNode < graph.getNodes() ? mainEdgesAround(label) : Stream.empty(), extraEdges.stream()).filter(new EdgeIteratorStatePredicate(label)); }
public AStar(Graph graph, Weighting weighting, TraversalMode tMode) { super(graph, weighting, tMode); int size = Math.min(Math.max(200, graph.getNodes() / 10), 2000); initCollections(size); BeelineWeightApproximator defaultApprox = new BeelineWeightApproximator(nodeAccess, weighting); defaultApprox.setDistanceCalc(Helper.DIST_PLANE); setApproximation(defaultApprox); }
GtfsReader(String id, Graph graph, GtfsStorageI gtfsStorage, PtFlagEncoder encoder, LocationIndex walkNetworkIndex) { this.id = id; this.graph = graph; this.gtfsStorage = gtfsStorage; this.nodeAccess = graph.getNodeAccess(); this.walkNetworkIndex = walkNetworkIndex; this.encoder = encoder; this.feed = this.gtfsStorage.getGtfsFeeds().get(id); this.transfers = this.gtfsStorage.getTransfers().get(id); this.i = graph.getNodes(); this.startDate = feed.getStartDate(); this.endDate = feed.getEndDate(); }
public static Graph shuffle(Graph g, Graph sortedGraph) { int nodes = g.getNodes(); GHIntArrayList list = new GHIntArrayList(nodes); list.fill(nodes, -1); for (int i = 0; i < nodes; i++) { list.set(i, i); } list.shuffle(new Random()); return createSortedGraph(g, sortedGraph, list); }
public static int getIdOf(Graph g, double latitude) { int s = g.getNodes(); NodeAccess na = g.getNodeAccess(); for (int i = 0; i < s; i++) { if (Math.abs(na.getLatitude(i) - latitude) < 1e-4) { return i; } } return -1; }
public static void printEdgeInfo(final Graph g, FlagEncoder encoder) { System.out.println("-- Graph nodes:" + g.getNodes() + " edges:" + g.getAllEdges().length() + " ---"); AllEdgesIterator iter = g.getAllEdges(); while (iter.next()) { String prefix = (iter instanceof AllCHEdgesIterator && ((AllCHEdgesIterator) iter).isShortcut()) ? "sc" : " "; String fwdStr = iter.isForward(encoder) ? "fwd" : " "; String bwdStr = iter.isBackward(encoder) ? "bwd" : " "; System.out.println(prefix + " " + iter + " " + fwdStr + " " + bwdStr + " " + iter.getDistance()); } }
public static int getIdOf(Graph g, double latitude, double longitude) { int s = g.getNodes(); NodeAccess na = g.getNodeAccess(); for (int i = 0; i < s; i++) { if (Math.abs(na.getLatitude(i) - latitude) < 1e-4 && Math.abs(na.getLongitude(i) - longitude) < 1e-4) { return i; } } throw new IllegalArgumentException("did not find node with location " + (float) latitude + "," + (float) longitude); }
@Override public void flush() { index.setHeader(0, MAGIC_INT); index.setHeader(1 * 4, latSize); index.setHeader(2 * 4, lonSize); index.setHeader(3 * 4, graph.getNodes()); index.flush(); }
private void printInfo(String str) { LOGGER.info("finished " + str + " processing." + " nodes: " + graph.getNodes() + ", osmIdMap.size:" + getNodeMap().getSize() + ", osmIdMap:" + getNodeMap().getMemoryUsage() + "MB" + ", nodeFlagsMap.size:" + getNodeFlagsMap().size() + ", relFlagsMap.size:" + getRelFlagsMap().size() + ", zeroCounter:" + zeroCounter + " " + Helper.getMemInfo()); }
@Override public void doSpecificWork() { StopWatch sw = new StopWatch().start(); LOGGER.info("Start calculating " + lms.getLandmarkCount() + " landmarks, default active lms:" + defaultActiveLandmarks + ", weighting:" + lms.getLmSelectionWeighting() + ", " + Helper.getMemInfo()); lms.createLandmarks(); lms.flush(); LOGGER.info("Calculated landmarks for " + (lms.getSubnetworksWithLandmarks() - 1) + " subnetworks, took:" + sw.stop().getSeconds() + " => " + lms.getLandmarksAsGeoJSON() + ", stored weights:" + lms.getLandmarkCount() + ", nodes:" + graph.getNodes() + ", " + Helper.getMemInfo()); }
public static void printGraphForUnitTest(Graph g, FlagEncoder encoder, BBox bBox) { NodeAccess na = g.getNodeAccess(); for (int node = 0; node < g.getNodes(); ++node) { if (bBox.contains(na.getLat(node), na.getLon(node))) { System.out.printf(Locale.ROOT, "na.setNode(%d, %f, %f);\n", node, na.getLat(node), na.getLon(node)); } } AllEdgesIterator iter = g.getAllEdges(); while (iter.next()) { if (bBox.contains(na.getLat(iter.getBaseNode()), na.getLon(iter.getBaseNode())) && bBox.contains(na.getLat(iter.getAdjNode()), na.getLon(iter.getAdjNode()))) { printUnitTestEdge(encoder, iter); } } }
@Test public void testMediumRead() throws IOException { Graph graph = new GraphBuilder(encodingManager).create(); new PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.class.getResourceAsStream("mediumEWD.txt.gz"))).read(); assertEquals(250, graph.getNodes()); EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges); assertEquals(13, count(explorer.setBaseNode(244))); assertEquals(11, count(explorer.setBaseNode(16))); } }
@Test public void testSort2() { Graph g = initUnsorted(createGraph()); Graph newG = GHUtility.sortDFS(g, createGraph()); assertEquals(g.getNodes(), newG.getNodes()); NodeAccess na = newG.getNodeAccess(); assertEquals(0, na.getLatitude(0), 1e-4); // 0 assertEquals(2.5, na.getLatitude(1), 1e-4); // 1 assertEquals(4.5, na.getLatitude(2), 1e-4); // 2 assertEquals(4.6, na.getLatitude(3), 1e-4); // 8 }
@Test public void testRead() { Graph graph = new GraphBuilder(encodingManager).create(); new PrincetonReader(graph).setStream(PrincetonReader.class.getResourceAsStream("tinyEWD.txt")).read(); assertEquals(8, graph.getNodes()); EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges); assertEquals(2, count(explorer.setBaseNode(0))); assertEquals(3, count(explorer.setBaseNode(6))); }
@Test public void testSort() { Graph g = initUnsorted(createGraph()); Graph newG = GHUtility.sortDFS(g, createGraph()); assertEquals(g.getNodes(), newG.getNodes()); NodeAccess na = newG.getNodeAccess(); assertEquals(0, na.getLatitude(0), 1e-4); // 0 assertEquals(2.5, na.getLatitude(1), 1e-4); // 1 assertEquals(4.5, na.getLatitude(2), 1e-4); // 2 assertEquals(4.6, na.getLatitude(3), 1e-4); // 8 assertEquals(3.0, na.getLatitude(4), 1e-4); // 3 assertEquals(5.0, na.getLatitude(5), 1e-4); // 7 assertEquals(4.2, na.getLatitude(6), 1e-4); // 5 }
@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()); }