com.graphhopper.storage.Graph.getNodes()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中com.graphhopper.storage.Graph.getNodes()方法的一些代码示例,展示了Graph.getNodes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.getNodes()方法的具体详情如下:
包路径:com.graphhopper.storage.Graph
类名称:Graph
方法名:getNodes

Graph.getNodes介绍

暂无

代码示例

代码示例来源:origin: graphhopper/graphhopper

int calcChecksum() {
  // do not include the edges as we could get problem with CHGraph due to shortcuts
  // ^ graph.getAllEdges().count();
  return graph.getNodes();
}

代码示例来源:origin: graphhopper/graphhopper

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();
}

代码示例来源:origin: graphhopper/graphhopper

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);
}

代码示例来源:origin: graphhopper/graphhopper

@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;
}

代码示例来源:origin: graphhopper/graphhopper

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));
}

代码示例来源:origin: graphhopper/graphhopper

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);
}

代码示例来源:origin: graphhopper/graphhopper

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();
}

代码示例来源:origin: graphhopper/graphhopper

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);
}

代码示例来源:origin: graphhopper/graphhopper

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;
}

代码示例来源:origin: graphhopper/graphhopper

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());
  }
}

代码示例来源:origin: graphhopper/graphhopper

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);
}

代码示例来源:origin: graphhopper/graphhopper

@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();
}

代码示例来源:origin: graphhopper/graphhopper

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());
}

代码示例来源:origin: graphhopper/graphhopper

@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());
}

代码示例来源:origin: graphhopper/graphhopper

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);
    }
  }
}

代码示例来源:origin: graphhopper/graphhopper

@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)));
  }
}

代码示例来源:origin: graphhopper/graphhopper

@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        
}

代码示例来源:origin: graphhopper/graphhopper

@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)));
}

代码示例来源:origin: graphhopper/graphhopper

@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
}

代码示例来源:origin: graphhopper/graphhopper

@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());
}

相关文章