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

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

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

Graph.createEdgeExplorer介绍

暂无

代码示例

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

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

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

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

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

void setFilter(IntHashSet set, boolean fwd, boolean bwd) {
  EdgeFilter ef = new BlockedEdgesFilter(flagEncoder, fwd, bwd, set);
  outEdgeExplorer = graph.createEdgeExplorer(ef);
  inEdgeExplorer = graph.createEdgeExplorer(ef);
}

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

public static void printInfo(final Graph g, int startNode, final int counts, final EdgeFilter filter) {
  new BreadthFirstSearch() {
    int counter = 0;
    @Override
    protected boolean goFurther(int nodeId) {
      System.out.println(getNodeInfo(g, nodeId, filter));
      return counter++ <= counts;
    }
  }.start(g.createEdgeExplorer(), startNode);
}

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

public Collection<TurnCostTableEntry> analyzeTurnRelation(FlagEncoder encoder, OSMTurnRelation turnRelation) {
  if (!encoder.supports(TurnWeighting.class))
    return Collections.emptyList();
  EdgeExplorer edgeOutExplorer = outExplorerMap.get(encoder);
  EdgeExplorer edgeInExplorer = inExplorerMap.get(encoder);
  if (edgeOutExplorer == null || edgeInExplorer == null) {
    edgeOutExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.outEdges(encoder));
    outExplorerMap.put(encoder, edgeOutExplorer);
    edgeInExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.inEdges(encoder));
    inExplorerMap.put(encoder, edgeInExplorer);
  }
  return turnRelation.getRestrictionAsEntries(encoder, edgeOutExplorer, edgeInExplorer, this);
}

代码示例来源: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 InstructionsFromEdges(int tmpNode, Graph graph, Weighting weighting, FlagEncoder encoder, NodeAccess nodeAccess, Translation tr, InstructionList ways) {
  this.weighting = weighting;
  this.encoder = encoder;
  this.nodeAccess = nodeAccess;
  this.tr = tr;
  this.ways = ways;
  prevLat = this.nodeAccess.getLatitude(tmpNode);
  prevLon = this.nodeAccess.getLongitude(tmpNode);
  prevNode = -1;
  prevInRoundabout = false;
  prevName = null;
  outEdgeExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.outEdges(encoder));
  crossingExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.allEdges(encoder));
}

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

/**
 * @return the <b>first</b> edge containing the specified nodes base and adj. Returns null if
 * not found.
 */
public static EdgeIteratorState getEdge(Graph graph, int base, int adj) {
  EdgeIterator iter = graph.createEdgeExplorer().setBaseNode(base);
  while (iter.next()) {
    if (iter.getAdjNode() == adj)
      return iter;
  }
  return null;
}

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

private static void warmUpNonCHSubNetwork(final GraphHopper graphHopper, int iterations) {
    GraphHopperStorage ghStorage = graphHopper.getGraphHopperStorage();
    Random rand = new Random(0);
    EdgeExplorer explorer = ghStorage.getBaseGraph().createEdgeExplorer();

    for (int i = 0; i < iterations; i++) {
      BreadthFirstSearch bfs = new BreadthFirstSearch() {
        int counter = 0;

        @Override
        public boolean goFurther(int nodeId) {
          counter++;
          return counter < graphHopper.getMaxVisitedNodes();
        }
      };
      int startNode = rand.nextInt(ghStorage.getBaseGraph().getNodes() + 1);
      bfs.start(explorer, startNode);
    }
  }
}

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

private int findPlatformNode(int stationNode, GtfsStorageI.PlatformDescriptor platformDescriptor, GtfsStorage.EdgeType edgeType) {
  DefaultEdgeFilter filter;
  if (edgeType == GtfsStorage.EdgeType.ENTER_PT) {
    filter = DefaultEdgeFilter.outEdges(encoder);
  } else if (edgeType == GtfsStorage.EdgeType.EXIT_PT) {
    filter = DefaultEdgeFilter.inEdges(encoder);
  } else {
    throw new RuntimeException();
  }
  EdgeIterator i = graph.getBaseGraph().createEdgeExplorer(filter).setBaseNode(stationNode);
  while (i.next()) {
    if (encoder.getEdgeType(i.getFlags()) == edgeType) {
      if (platformDescriptor.equals(gtfsStorage.getRoutes().get(i.getEdge()))) {
        return i.getAdjNode();
      }
    }
  }
  return -1;
}

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

public static String getNodeInfo(Graph g, int nodeId, EdgeFilter filter) {
  EdgeIterator iter = g.createEdgeExplorer(filter).setBaseNode(nodeId);
  NodeAccess na = g.getNodeAccess();
  String str = nodeId + ":" + na.getLatitude(nodeId) + "," + na.getLongitude(nodeId) + "\n";
  while (iter.next()) {
    str += "  ->" + iter.getAdjNode() + " (" + iter.getDistance() + ") pillars:"
        + iter.fetchWayGeometry(0).getSize() + ", edgeId:" + iter.getEdge()
        + "\t" + BitUtil.BIG.toBitString(iter.getFlags(), 8) + "\n";
  }
  return str;
}

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

public static void updateDistancesFor(Graph g, int node, double lat, double lon) {
  NodeAccess na = g.getNodeAccess();
  na.setNode(node, lat, lon);
  EdgeIterator iter = g.createEdgeExplorer().setBaseNode(node);
  while (iter.next()) {
    iter.setDistance(iter.fetchWayGeometry(3).calcDistance(distCalc));
    // System.out.println(node + "->" + adj + ": " + iter.getDistance());
  }
}

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

private boolean isGraphValid(Graph graph, FlagEncoder encoder) {
    EdgeExplorer explorer = graph.createEdgeExplorer();

    // iterator at node 0 considers the edge 0-1 to be undirected
    EdgeIterator iter0 = explorer.setBaseNode(0);
    iter0.next();
    boolean iter0flag
        = iter0.getBaseNode() == 0 && iter0.getAdjNode() == 1
        && iter0.isForward(encoder) && iter0.isBackward(encoder);

    // iterator at node 1 considers the edge 1-0 to be directed
    EdgeIterator iter1 = explorer.setBaseNode(1);
    iter1.next();
    boolean iter1flag
        = iter1.getBaseNode() == 1 && iter1.getAdjNode() == 0
        && iter1.isForward(encoder) && iter1.isBackward(encoder);

    return iter0flag && iter1flag;
  }
}

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

@Test
public void testExtract() {
  Graph g = createGraph();
  g.edge(1, 2, 10, true);
  PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
  EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
  EdgeIterator iter = explorer.setBaseNode(1);
  iter.next();
  pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 0);
  pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 10);
  pw.edgeTo = new SPTEntry(EdgeIterator.NO_EDGE, 2, 0);
  Path p = pw.extract();
  assertEquals(IntArrayList.from(new int[]{1, 2}), p.calcNodes());
  assertEquals(10, p.getDistance(), 1e-4);
}

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

@Test
  public void testDifferentVehicles() {
    final EncodingManager encodingManager = new EncodingManager("car,foot");
    Graph g = AbstractLocationIndexTester.this.createGHStorage(encodingManager);
    initSimpleGraph(g);
    idx = createIndex(g, -1);
    assertEquals(1, findID(idx, 1, -1));

    // now make all edges from node 1 accessible for CAR only
    EdgeIterator iter = g.createEdgeExplorer().setBaseNode(1);
    CarFlagEncoder carEncoder = (CarFlagEncoder) encodingManager.getEncoder("car");
    while (iter.next()) {
      iter.setFlags(carEncoder.setProperties(50, true, true));
    }
    idx.close();

    idx = createIndex(g, -1);
    FootFlagEncoder footEncoder = (FootFlagEncoder) encodingManager.getEncoder("foot");
    assertEquals(2, idx.findClosest(1, -1, DefaultEdgeFilter.allEdges(footEncoder)).getClosestNode());
    Helper.close((Closeable) g);
  }
}

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

@Test
public void testGraph() {
  Graph g = new GraphBuilder(encodingManager).create();
  g.edge(0, 1).setDistance(10).setFlags(footEncoder.setProperties(10, true, true));
  g.edge(0, 2).setDistance(10).setFlags(footEncoder.setProperties(5, true, true));
  g.edge(1, 3).setDistance(10).setFlags(footEncoder.setProperties(10, true, true));
  EdgeExplorer out = g.createEdgeExplorer(DefaultEdgeFilter.outEdges(footEncoder));
  assertEquals(GHUtility.asSet(1, 2), GHUtility.getNeighbors(out.setBaseNode(0)));
  assertEquals(GHUtility.asSet(0, 3), GHUtility.getNeighbors(out.setBaseNode(1)));
  assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(out.setBaseNode(2)));
}

相关文章