com.graphhopper.storage.Graph类的使用及代码示例

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

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

Graph介绍

[英]An interface to represent a (geo) graph - suited for efficient storage as it can be requested via indices called node IDs. To get the lat,lon point you need to set up a LocationIndex instance.
[中]

代码示例

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

/**
 * @param graph         specifies the graph where this algorithm will run on
 * @param weighting     set the used weight calculation (e.g. fastest, shortest).
 * @param traversalMode how the graph is traversed e.g. if via nodes or edges.
 */
public AbstractRoutingAlgorithm(Graph graph, Weighting weighting, TraversalMode traversalMode) {
  this.weighting = weighting;
  this.flagEncoder = weighting.getFlagEncoder();
  this.traversalMode = traversalMode;
  this.graph = graph;
  this.nodeAccess = graph.getNodeAccess();
  outEdgeExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.outEdges(flagEncoder));
  inEdgeExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.inEdges(flagEncoder));
}

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

public static void initGraph(Graph g) {
  g.edge(0, 1, 3, true);
  g.edge(0, 2, 1, true);
  g.edge(1, 3, 1, true);
  g.edge(2, 3, 1, true);
  g.edge(3, 4, 1, true);
  g.edge(2, 5, .5, true);
  g.edge(3, 6, 1, true);
  g.edge(4, 7, 1, true);
  g.edge(5, 6, 1, true);
  g.edge(6, 7, 1, true);
}

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

public GraphicsWrapper(Graph g) {
  this.na = g.getNodeAccess();
  BBox b = g.getBounds();
  scaleX = scaleY = 0.002 * (b.maxLat - b.minLat);
  offsetY = b.maxLat - 90;
  offsetX = -b.minLon;
}

代码示例来源: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 testClone() {
  graph = createGHStorage();
  graph.edge(1, 2, 10, true);
  NodeAccess na = graph.getNodeAccess();
  na.setNode(0, 12, 23);
  na.setNode(1, 8, 13);
  na.setNode(2, 2, 10);
  na.setNode(3, 5, 9);
  graph.edge(1, 3, 10, true);
  Graph cloneGraph = graph.copyTo(AbstractGraphStorageTester.this.createGHStorage(locationParent + "/clone", false));
  assertEquals(graph.getNodes(), cloneGraph.getNodes());
  assertEquals(count(carOutExplorer.setBaseNode(1)), count(cloneGraph.createEdgeExplorer(carOutFilter).setBaseNode(1)));
  cloneGraph.edge(1, 4, 10, true);
  assertEquals(3, count(cloneGraph.createEdgeExplorer(carOutFilter).setBaseNode(1)));
  assertEquals(graph.getBounds(), cloneGraph.getBounds());
  Helper.close((Closeable) cloneGraph);
}

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

void initGraph(Graph g) {
  //
  //  /*-*\
  // 0     1
  // |
  // 2
  NodeAccess na = g.getNodeAccess();
  na.setNode(0, 1, 0);
  na.setNode(1, 1, 2.5);
  na.setNode(2, 0, 0);
  g.edge(0, 2, 10, true);
  g.edge(0, 1, 10, true).setWayGeometry(Helper.createPointList(1.5, 1, 1.5, 1.5));
}

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

@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

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

protected void checkGraph(Graph g) {
  NodeAccess na = g.getNodeAccess();
  assertTrue(na.is3D());
  assertTrue(g.getBounds().isValid());
  assertEquals(new BBox(10, 20, 10, 12, 0, 1), g.getBounds());
  assertEquals(10, na.getLatitude(0), 1e-2);
  assertEquals(10, na.getLongitude(0), 1e-2);
  EdgeExplorer explorer = g.createEdgeExplorer(carOutFilter);
  assertEquals(2, GHUtility.count(explorer.setBaseNode(0)));
  assertEquals(GHUtility.asSet(2, 1), GHUtility.getNeighbors(explorer.setBaseNode(0)));

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

@Override
public EdgeExplorer createEdgeExplorer(EdgeFilter filter) {
  return baseGraph.createEdgeExplorer(filter);
}

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

private void insertOutboundTransfers(String toStopId, String toRouteId, int minimumTransferTime, NavigableMap<Integer, Integer> fromStopTimelineNodes) {
  int stationNode = gtfsStorage.getStationNodes().get(toStopId);
  EdgeIterator i = graph.getBaseGraph().createEdgeExplorer().setBaseNode(stationNode);
  while (i.next()) {
    GtfsStorage.EdgeType edgeType = encoder.getEdgeType(i.getFlags());
    if (edgeType == GtfsStorage.EdgeType.ENTER_PT) {
      GtfsStorageI.PlatformDescriptor routeId = gtfsStorage.getRoutes().get(i.getEdge());
      if (toRouteId == null || routeId instanceof GtfsStorageI.RouteTypePlatform || GtfsStorageI.PlatformDescriptor.route(toRouteId).equals(routeId)) {
        fromStopTimelineNodes.forEach((time, e) -> {
          EdgeIterator j = graph.getBaseGraph().createEdgeExplorer().setBaseNode(i.getAdjNode());
          while (j.next()) {
            GtfsStorage.EdgeType edgeType2 = encoder.getEdgeType(j.getFlags());
            if (edgeType2 == GtfsStorage.EdgeType.ENTER_TIME_EXPANDED_NETWORK) {
              int departureTime = (int) encoder.getTime(j.getFlags());
              if (departureTime < time + minimumTransferTime) {
                continue;
              }
              EdgeIteratorState edge = graph.edge(e, j.getAdjNode());
              edge.setFlags(encoder.setAccess(edge.getFlags(), true, false));
              setEdgeTypeAndClearDistance(edge, GtfsStorage.EdgeType.TRANSFER);
              edge.setFlags(encoder.setTime(edge.getFlags(), departureTime - time));
              break;
            }
          }
        });
      }
    }
  }
}

代码示例来源: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 DebugAStar(Graph graph, Weighting type, TraversalMode tMode, GraphicsWrapper mg) {
  super(graph, type, tMode);
  this.mg = mg;
  na = graph.getNodeAccess();
}

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

NodeAccess na = graph.getNodeAccess();
    na.setNode(index, 0.01 * latIdx, 0.01 * lonIdx);
    if (latIdx < MAX - 1)
      graph.edge(index, index + 1, 1000, true);
      graph.edge(index, index + 10, 1000, true);
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
  iter.setFlags(bikeEncoder.setAccess(iter.getFlags(), false, false));

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

private NavigableMap<Integer, Integer> findDepartureTimelineForPlatform(int platformEnterNode) {
  TreeMap<Integer, Integer> result = new TreeMap<>();
  if (platformEnterNode == -1) {
    return result;
  }
  EdgeIterator edge = graph.getBaseGraph().createEdgeExplorer(DefaultEdgeFilter.outEdges(encoder)).setBaseNode(platformEnterNode);
  while (edge.next()) {
    if (encoder.getEdgeType(edge.getFlags()) == GtfsStorage.EdgeType.ENTER_TIME_EXPANDED_NETWORK) {
      result.put((int) encoder.getTime(edge.getFlags()), edge.getAdjNode());
    }
  }
  return result;
}

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

@Override
public BBox getBounds() {
  return mainGraph.getBounds();
}

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

private CHEdgeIteratorState getEdge(int edgeId, int adjNode) {
    return (CHEdgeIteratorState) routingGraph.getEdgeIteratorState(edgeId, adjNode);
  }
}

相关文章