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

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

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

Graph.getAllEdges介绍

暂无

代码示例

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

@Override
public int length() {
  return IntStream.concat(
      IntStream.of(baseGraph.getAllEdges().length() - 1),
      extraEdges.stream().mapToInt(VirtualEdgeIteratorState::getEdge))
      .max().getAsInt()+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 QueryGraph(Graph graph) {
  mainGraph = graph;
  mainNodeAccess = graph.getNodeAccess();
  mainNodes = graph.getNodes();
  mainEdges = graph.getAllEdges().length();
  if (mainGraph.getExtension() instanceof TurnCostExtension)
    wrappedExtension = new QueryGraphTurnExt();
  else
    wrappedExtension = mainGraph.getExtension();
  // create very lightweight QueryGraph which uses variables from this QueryGraph (same virtual edges)
  baseGraph = new QueryGraph(graph.getBaseGraph(), this) {
    // override method to avoid stackoverflow
    @Override
    public QueryGraph setUseEdgeExplorerCache(boolean useEECache) {
      baseGraph.useEdgeExplorerCache = useEECache;
      return baseGraph;
    }
  };
}

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

AllEdgesIterator edge = graph.getAllEdges();
while (edge.next()) {
  if (fastPaint && rand.nextInt(30) > 1)

代码示例来源: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

void prepare() {
  final EdgeIterator allIter = graph.getAllEdges();
  try {
    while (allIter.next()) {
      int nodeA = allIter.getBaseNode();
      int nodeB = allIter.getAdjNode();
      double lat1 = nodeAccess.getLatitude(nodeA);
      double lon1 = nodeAccess.getLongitude(nodeA);
      double lat2;
      double lon2;
      PointList points = allIter.fetchWayGeometry(0);
      int len = points.getSize();
      for (int i = 0; i < len; i++) {
        lat2 = points.getLatitude(i);
        lon2 = points.getLongitude(i);
        addNode(nodeA, nodeB, lat1, lon1, lat2, lon2);
        lat1 = lat2;
        lon1 = lon2;
      }
      lat2 = nodeAccess.getLatitude(nodeB);
      lon2 = nodeAccess.getLongitude(nodeB);
      addNode(nodeA, nodeB, lat1, lon1, lat2, lon2);
    }
  } catch (Exception ex) {
    logger.error("Problem! base:" + allIter.getBaseNode() + ", adj:" + allIter.getAdjNode()
        + ", edge:" + allIter.getEdge(), ex);
  }
}

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

AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
  if (!edgeFilter.accept(iter))

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

/**
 * @return the specified toGraph which is now filled with data from fromGraph
 */
// TODO very similar to createSortedGraph -> use a 'int map(int)' interface
public static Graph copyTo(Graph fromGraph, Graph toGraph) {
  AllEdgesIterator eIter = fromGraph.getAllEdges();
  while (eIter.next()) {
    int base = eIter.getBaseNode();
    int adj = eIter.getAdjNode();
    eIter.copyPropertiesTo(toGraph.edge(base, adj));
  }
  NodeAccess fna = fromGraph.getNodeAccess();
  NodeAccess tna = toGraph.getNodeAccess();
  int nodes = fromGraph.getNodes();
  for (int node = 0; node < nodes; node++) {
    if (tna.is3D())
      tna.setNode(node, fna.getLatitude(node), fna.getLongitude(node), fna.getElevation(node));
    else
      tna.setNode(node, fna.getLatitude(node), fna.getLongitude(node));
  }
  return toGraph;
}

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

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

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

static Graph createSortedGraph(Graph fromGraph, Graph toSortedGraph, final IntIndexedContainer oldToNewNodeList) {
  AllEdgesIterator eIter = fromGraph.getAllEdges();
  while (eIter.next()) {
    int base = eIter.getBaseNode();
    int newBaseIndex = oldToNewNodeList.get(base);
    int adj = eIter.getAdjNode();
    int newAdjIndex = oldToNewNodeList.get(adj);
    // ignore empty entries
    if (newBaseIndex < 0 || newAdjIndex < 0)
      continue;
    eIter.copyPropertiesTo(toSortedGraph.edge(newBaseIndex, newAdjIndex));
  }
  int nodes = fromGraph.getNodes();
  NodeAccess na = fromGraph.getNodeAccess();
  NodeAccess sna = toSortedGraph.getNodeAccess();
  for (int old = 0; old < nodes; old++) {
    int newIndex = oldToNewNodeList.get(old);
    if (sna.is3D())
      sna.setNode(newIndex, na.getLatitude(old), na.getLongitude(old), na.getElevation(old));
    else
      sna.setNode(newIndex, na.getLatitude(old), na.getLongitude(old));
  }
  return toSortedGraph;
}

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

print("unit_tests" + description + ".all_edge_state_next", miniPerf);
final int maxEdgesId = graph.getAllEdges().length();
miniPerf = new MiniPerfTest() {
  @Override

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

AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
  if (!filter.accept(iter)) {

代码示例来源: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());
}

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

AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
  iter.setFlags(bikeEncoder.setAccess(iter.getFlags(), false, false));

代码示例来源:origin: com.rgi-corp/graphhopper

public static void printEdgeInfo(final Graph g, FlagEncoder encoder) {
  System.out.println("-- Graph n:" + g.getNodes() + " e:" + g.getAllEdges().getMaxId() + " ---");
  AllEdgesIterator iter = g.getAllEdges();
  while (iter.next()) {
    String sc = "";
    if (iter instanceof AllCHEdgesIterator) {
      AllCHEdgesIterator aeSkip = (AllCHEdgesIterator) iter;
      sc = aeSkip.isShortcut() ? "sc" : "  ";
    }
    String fwdStr = iter.isForward(encoder) ? "fwd" : "   ";
    String bckStr = iter.isBackward(encoder) ? "bckwd" : "";
    System.out.println(sc + " " + iter + " " + fwdStr + " " + bckStr);
  }
}

代码示例来源:origin: com.graphhopper/graphhopper-core

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: com.graphhopper/graphhopper

public QueryGraph( Graph graph )
{
  mainGraph = graph;
  mainNodeAccess = graph.getNodeAccess();
  mainNodes = graph.getNodes();
  mainEdges = graph.getAllEdges().getMaxId();
  if (mainGraph.getExtension() instanceof TurnCostExtension)
    wrappedExtension = new QueryGraphTurnExt();
  else
    wrappedExtension = mainGraph.getExtension();
  // create very lightweight QueryGraph which uses variables from this QueryGraph (same virtual edges)
  baseGraph = new QueryGraph(graph.getBaseGraph(), this);
}

代码示例来源:origin: com.graphhopper/graphhopper-core

public QueryGraph(Graph graph) {
  mainGraph = graph;
  mainNodeAccess = graph.getNodeAccess();
  mainNodes = graph.getNodes();
  mainEdges = graph.getAllEdges().length();
  if (mainGraph.getExtension() instanceof TurnCostExtension)
    wrappedExtension = new QueryGraphTurnExt();
  else
    wrappedExtension = mainGraph.getExtension();
  // create very lightweight QueryGraph which uses variables from this QueryGraph (same virtual edges)
  baseGraph = new QueryGraph(graph.getBaseGraph(), this) {
    // override method to avoid stackoverflow
    @Override
    public QueryGraph setUseEdgeExplorerCache(boolean useEECache) {
      baseGraph.useEdgeExplorerCache = useEECache;
      return baseGraph;
    }
  };
}

代码示例来源:origin: com.graphhopper/graphhopper-core

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: com.graphhopper/graphhopper-core

/**
 * @return the specified toGraph which is now filled with data from fromGraph
 */
// TODO very similar to createSortedGraph -> use a 'int map(int)' interface
public static Graph copyTo(Graph fromGraph, Graph toGraph) {
  AllEdgesIterator eIter = fromGraph.getAllEdges();
  while (eIter.next()) {
    int base = eIter.getBaseNode();
    int adj = eIter.getAdjNode();
    eIter.copyPropertiesTo(toGraph.edge(base, adj));
  }
  NodeAccess fna = fromGraph.getNodeAccess();
  NodeAccess tna = toGraph.getNodeAccess();
  int nodes = fromGraph.getNodes();
  for (int node = 0; node < nodes; node++) {
    if (tna.is3D())
      tna.setNode(node, fna.getLatitude(node), fna.getLongitude(node), fna.getElevation(node));
    else
      tna.setNode(node, fna.getLatitude(node), fna.getLongitude(node));
  }
  return toGraph;
}

相关文章