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

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

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

Graph.getEdgeIteratorState介绍

[英]Returns a wrapper over the specified edgeId.
[中]返回指定edgeId上的包装。

代码示例

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

@Override
public EdgeIteratorState edge(int a, int b) {
  return baseGraph.getEdgeIteratorState(a, b);
}

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

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

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

@Override
public EdgeIteratorState getEdgeIteratorState(int edgeId, int adjNode) {
  return baseGraph.getEdgeIteratorState(edgeId, adjNode);
}

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

static List<String> getAltNames(Graph graph, SPTEntry ee) {
  if (ee == null || !EdgeIterator.Edge.isValid(ee.edge))
    return Collections.emptyList();
  EdgeIteratorState iter = graph.getEdgeIteratorState(ee.edge, Integer.MIN_VALUE);
  if (iter == null)
    return Collections.emptyList();
  String str = iter.getName();
  if (str.isEmpty())
    return Collections.emptyList();
  return Collections.singletonList(str);
}

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

@Override
  public int doCalc(boolean warmup, int run) {
    while (true) {
      int edgeId = rand.nextInt(maxEdgesId);
      if (allowedEdges.contains(edgeId))
        return graph.getEdgeIteratorState(edgeId, Integer.MIN_VALUE).getEdge();
    }
  }
}.setIterations(count).start();

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

/**
 * Yields the final edge of the path
 */
public EdgeIteratorState getFinalEdge() {
  return graph.getEdgeIteratorState(edgeIds.get(edgeIds.size() - 1), endNode);
}

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

public static int getAdjNode(Graph g, int edge, int adjNode) {
  if (EdgeIterator.Edge.isValid(edge)) {
    EdgeIteratorState iterTo = g.getEdgeIteratorState(edge, adjNode);
    return iterTo.getAdjNode();
  }
  return adjNode;
}

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

EdgeIteratorState getEdgeIteratorState(int edgeId, int adjNode) {
  if (edgeId == -1) {
    throw new RuntimeException();
  }
  for (EdgeIteratorState extraEdge : extraEdges) {
    if (extraEdge.getEdge() == edgeId) {
      if (extraEdge.getAdjNode() != adjNode) {
        throw new IllegalStateException();
      }
      return extraEdge;
    }
  }
  EdgeIteratorState edge = graph.getEdgeIteratorState(edgeId, adjNode);
  if (edge.getAdjNode() != adjNode) {
    throw new IllegalStateException();
  }
  return edge;
}

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

@Override
public EdgeIteratorState getEdgeIteratorState(int origEdgeId, int adjNode) {
  if (!isVirtualEdge(origEdgeId))
    return mainGraph.getEdgeIteratorState(origEdgeId, adjNode);
  int edgeId = origEdgeId - mainEdges;
  EdgeIteratorState eis = virtualEdges.get(edgeId);
  if (eis.getAdjNode() == adjNode || adjNode == Integer.MIN_VALUE)
    return eis;
  edgeId = getPosOfReverseEdge(edgeId);
  EdgeIteratorState eis2 = virtualEdges.get(edgeId);
  if (eis2.getAdjNode() == adjNode)
    return eis2;
  throw new IllegalStateException("Edge " + origEdgeId + " not found with adjNode:" + adjNode
      + ". found edges were:" + eis + ", " + eis2);
}

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

/**
 * Calculates the distance and time of the specified edgeId. Also it adds the edgeId to the path list.
 *
 * @param prevEdgeId here the edge that comes before edgeId is necessary. I.e. for the reverse search we need the
 *                   next edge.
 */
protected void processEdge(int edgeId, int adjNode, int prevEdgeId) {
  EdgeIteratorState iter = graph.getEdgeIteratorState(edgeId, adjNode);
  distance += iter.getDistance();
  time += weighting.calcMillis(iter, false, prevEdgeId);
  addEdge(edgeId);
}

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

/**
 * Iterates over all edges in this path sorted from start to end and calls the visitor callback
 * for every edge.
 * <p>
 *
 * @param visitor callback to handle every edge. The edge is decoupled from the iterator and can
 *                be stored.
 */
private void forEveryEdge(EdgeVisitor visitor) {
  int tmpNode = getFromNode();
  int len = edgeIds.size();
  int prevEdgeId = EdgeIterator.NO_EDGE;
  for (int i = 0; i < len; i++) {
    EdgeIteratorState edgeBase = graph.getEdgeIteratorState(edgeIds.get(i), tmpNode);
    if (edgeBase == null)
      throw new IllegalStateException("Edge " + edgeIds.get(i) + " was empty when requested with node " + tmpNode
          + ", array index:" + i + ", edges:" + edgeIds.size());
    tmpNode = edgeBase.getBaseNode();
    // more efficient swap, currently not implemented for virtual edges: visitor.next(edgeBase.detach(true), i);
    edgeBase = graph.getEdgeIteratorState(edgeBase.getEdge(), tmpNode);
    visitor.next(edgeBase, i, prevEdgeId);
    prevEdgeId = edgeBase.getEdge();
  }
  visitor.finish();
}

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

while (iter.hasNext()) {
  int edgeId = iter.next().value;
  EdgeIteratorState edge = graph.getEdgeIteratorState(edgeId, Integer.MIN_VALUE);
  if (props.containsKey("access")) {
    boolean value = (boolean) props.get("access");

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

@Test
public void testCalcTime() {
  GenericWeighting weighting = new GenericWeighting(encoder, new HintsMap());
  EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
  assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1);
}

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

@Before
public void setUp() {
  ReaderWay way = new ReaderWay(27l);
  way.setTag("highway", "primary");
  way.setTag("maxspeed", "10");
  way.setTag("maxheight", "4.4");
  graph = new GraphBuilder(em).create();
  // 0-1
  graph.edge(0, 1, 1, true);
  AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
  AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
  graph.getEdgeIteratorState(0, 1).setFlags(encoder.handleWayTags(way, 1, 0));
}

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

@Test
  public void testDisabledRoadAttributes() {
    DataFlagEncoder simpleEncoder = new DataFlagEncoder();
    EncodingManager simpleEncodingManager = new EncodingManager(simpleEncoder);
    Graph simpleGraph = new GraphBuilder(simpleEncodingManager).create();

    ReaderWay way = new ReaderWay(27l);
    way.setTag("highway", "primary");
    way.setTag("maxspeed", "10");
    way.setTag("maxheight", "4.4");

    // 0-1
    simpleGraph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 1, 0.01, 0.01);
    simpleGraph.getEdgeIteratorState(0, 1).setFlags(simpleEncoder.handleWayTags(way, 1, 0));

    Weighting instance = new GenericWeighting(simpleEncoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
    EdgeIteratorState edge = simpleGraph.getEdgeIteratorState(0, 1);
    assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
  }
}

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

@Test
public void testRoadAttributeRestriction() {
  EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
  Weighting instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 4.0));
  assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
  instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
  assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}

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

@Test
public void testBlockedById() {
  GraphEdgeIdFinder.BlockArea bArea = new GraphEdgeIdFinder.BlockArea(graph);
  EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
  BlockAreaWeighting instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
  assertEquals(94.35, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), .01);
  bArea.add(0);
  instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
  assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), .01);
}

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

@Test
public void testBlockedByShape() {
  EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
  GraphEdgeIdFinder.BlockArea bArea = new GraphEdgeIdFinder.BlockArea(graph);
  BlockAreaWeighting instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
  assertEquals(94.35, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 0.01);
  bArea.add(new Circle(0.01, 0.01, 100));
  assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), .01);
  bArea = new GraphEdgeIdFinder.BlockArea(graph);
  instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
  // Do not match 1,1 of edge
  bArea.add(new Circle(0.1, 0.1, 100));
  assertEquals(94.35, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), .01);
}

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

public static int getAdjNode(Graph g, int edge, int adjNode) {
  if (EdgeIterator.Edge.isValid(edge)) {
    EdgeIteratorState iterTo = g.getEdgeIteratorState(edge, adjNode);
    return iterTo.getAdjNode();
  }
  return adjNode;
}

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

/**
 * Calls getDistance and adds the edgeId.
 */
protected void processEdge( int edgeId, int adjNode )
{
  EdgeIteratorState iter = graph.getEdgeIteratorState(edgeId, adjNode);
  double dist = iter.getDistance();
  distance += dist;
  time += calcMillis(dist, iter.getFlags(), false);
  addEdge(edgeId);
}

相关文章