org.jgrapht.Graph.outgoingEdgesOf()方法的使用及代码示例

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

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

Graph.outgoingEdgesOf介绍

[英]Returns a set of all edges outgoing from the specified vertex.

In the case of undirected graphs this method returns all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order.
[中]返回从指定顶点传出的所有边的集合。
在无向图的情况下,此方法返回与顶点接触的所有边,因此,某些返回边的源顶点和目标顶点的顺序可能相反。

代码示例

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public Set<E> outgoingEdgesOf(V vertex)
{
  return delegate.outgoingEdgesOf(vertex);
}

代码示例来源:origin: cwensel/cascading

public Set<Scope> outgoingEdgesOf( FlowElement vertex )
 {
 return graph.outgoingEdgesOf( vertex );
 }

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Check if a vertex has any direct successors.
 *
 * @param graph the graph to look for successors
 * @param vertex the vertex to look for successors
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 *
 * @return true if the vertex has any successors, false otherwise
 */
public static <V, E> boolean vertexHasSuccessors(Graph<V, E> graph, V vertex)
{
  return !graph.outgoingEdgesOf(vertex).isEmpty();
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public Set<E> outgoingEdgesOf(V vertex)
{
  assertVertexExist(vertex);
  return base.outgoingEdgesOf(vertex).stream().filter(edgeSet::contains).collect(
    Collectors.toCollection(LinkedHashSet::new));
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public Set<E> outgoingEdgesOf(V vertex)
{
  boolean inG1 = g1.containsVertex(vertex);
  boolean inG2 = g2.containsVertex(vertex);
  if (inG1 && inG2) {
    return new UnmodifiableUnionSet<>(
      g1.outgoingEdgesOf(vertex), g2.outgoingEdgesOf(vertex));
  } else if (inG1) {
    return Collections.unmodifiableSet(g1.outgoingEdgesOf(vertex));
  } else if (inG2) {
    return Collections.unmodifiableSet(g2.outgoingEdgesOf(vertex));
  } else {
    throw new IllegalArgumentException("no such vertex in graph: " + vertex.toString());
  }
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Returns a list of vertices that are the direct successors of a specified vertex. If the graph
 * is a multigraph vertices may appear more than once in the returned list.
 *
 * <p>
 * The method uses {@link Graph#outgoingEdgesOf(Object)} to traverse the graph.
 *
 * @param g the graph to look for successors in
 * @param vertex the vertex to get the successors of
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 *
 * @return a list of the vertices that are the direct successors of the specified vertex.
 */
public static <V, E> List<V> successorListOf(Graph<V, E> g, V vertex)
{
  List<V> successors = new ArrayList<>();
  Set<? extends E> edges = g.outgoingEdgesOf(vertex);
  for (E e : edges) {
    successors.add(getOppositeVertex(g, e, vertex));
  }
  return successors;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

private V advance()
{
  V result = queue.poll();
  if (result != null) {
    for (E e : graph.outgoingEdgesOf(result)) {
      V other = Graphs.getOppositeVertex(graph, e, result);
      ModifiableInteger inDegree = inDegreeMap.get(other);
      if (inDegree.value > 0) {
        inDegree.value--;
        if (inDegree.value == 0) {
          queue.offer(other);
        }
      }
    }
    --remainingVertices;
  } else {
    /*
     * Still expecting some vertices, but no vertex has zero degree.
     */
    if (remainingVertices > 0) {
      throw new IllegalArgumentException(GRAPH_IS_NOT_A_DAG);
    }
  }
  return result;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

private void dfs(int u, int parent)
{
  component[u] = numberComponent;
  timeIn[u] = ++clock;
  ancestors[0][u] = parent;
  for (int l = 1; l < maxLevel; l++) {
    if (ancestors[l - 1][u] != -1)
      ancestors[l][u] = ancestors[l - 1][ancestors[l - 1][u]];
  }
  V vertexU = indexList.get(u);
  for (E edge : graph.outgoingEdgesOf(vertexU)) {
    int v = vertexMap.get(Graphs.getOppositeVertex(graph, edge, vertexU));
    if (v != parent) {
      dfs(v, u);
    }
  }
  timeOut[u] = ++clock;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public Set<E> outgoingEdgesOf(V vertex)
{
  assertVertexExist(vertex);
  return new MaskEdgeSet<>(base, base.outgoingEdgesOf(vertex), vertexMask, edgeMask);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

@Override
public Set<E> getCutEdges()
{
  if (cutEdges != null)
    return cutEdges;
  cutEdges = new LinkedHashSet<>();
  Set<V> p1 = getSourcePartition();
  if (directedGraph) {
    for (V vertex : p1) {
      cutEdges.addAll(
        network
          .outgoingEdgesOf(vertex).stream()
          .filter(edge -> !p1.contains(network.getEdgeTarget(edge)))
          .collect(Collectors.toList()));
    }
  } else {
    cutEdges.addAll(
      network
        .edgeSet().stream()
        .filter(
          e -> p1.contains(network.getEdgeSource(e))
            ^ p1.contains(network.getEdgeTarget(e)))
        .collect(Collectors.toList()));
  }
  return cutEdges;
}

代码示例来源:origin: cwensel/cascading

public Set<Integer> getSuccessors( int vertex )
 {
 Set<Integer> results = successors.get( vertex );
 if( results != null )
  return results;
 results = new HashSet<>();
 Set<Edge> edges = getDelegate().outgoingEdgesOf( getVertex( vertex ) );
 for( Edge edge : edges )
  {
  Object result = getEdgeTarget( edge );
  Integer value = getIndex( result );
  if( value != null )
   results.add( value );
  }
 successors.put( vertex, results );
 return results;
 }

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * @param vertexNumber the number which identifies the vertex $v$ in this order.
 *
 * @return the identifying numbers of all vertices which are connected to $v$ by an edge
 *         outgoing from $v$.
 */
public int[] getOutEdges(int vertexNumber)
{
  if (cacheEdges && (outgoingEdges[vertexNumber] != null)) {
    return outgoingEdges[vertexNumber];
  }
  V v = getVertex(vertexNumber);
  Set<E> edgeSet = graph.outgoingEdgesOf(v);
  int[] vertexArray = new int[edgeSet.size()];
  int i = 0;
  for (E edge : edgeSet) {
    V source = graph.getEdgeSource(edge), target = graph.getEdgeTarget(edge);
    vertexArray[i++] = mapVertexToOrder.get(source.equals(v) ? target : source);
  }
  if (cacheEdges) {
    outgoingEdges[vertexNumber] = vertexArray;
  }
  return vertexArray;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

private void computeTarjanOLCA(V u, V p, Set<V> visited)
{
  visited.add(u);
  unionFind.addElement(u);
  ancestors.put(u, u);
  for (E edge : graph.outgoingEdgesOf(u)) {
    V v = Graphs.getOppositeVertex(graph, edge, u);
    if (!v.equals(p)) {
      computeTarjanOLCA(v, u, visited);
      unionFind.union(u, v);
      ancestors.put(unionFind.find(u), u);
    }
  }
  blackNodes.add(u);
  for (int index : queryOccurs.computeIfAbsent(u, x -> new HashSet<>())) {
    Pair<V, V> query = queries.get(index);
    V v;
    if (query.getFirst().equals(u))
      v = query.getSecond();
    else
      v = query.getFirst();
    if (blackNodes.contains(v)) {
      lowestCommonAncestors.set(index, ancestors.get(unionFind.find(v)));
    }
  }
}

代码示例来源:origin: Galigator/openllet

private void collapseCycle(final Set<ATermAppl> scc)
{
  final Iterator<ATermAppl> i = scc.iterator();
  final ATermAppl rep = i.next();
  while (i.hasNext())
  {
    final ATermAppl node = i.next();
    addEquivalent(rep, node);
    for (final DefaultEdge edge : _graph.incomingEdgesOf(node))
    {
      final ATermAppl incoming = _graph.getEdgeSource(edge);
      if (!incoming.equals(rep))
        _graph.addEdge(incoming, rep);
    }
    for (final DefaultEdge edge : _graph.outgoingEdgesOf(node))
    {
      final ATermAppl outgoing = _graph.getEdgeTarget(edge);
      if (!outgoing.equals(rep))
        _graph.addEdge(rep, outgoing);
    }
    _graph.removeVertex(node);
  }
}

代码示例来源:origin: org.jgrapht/jgrapht-io

private void exportAsAdjacencyList(Graph<V, E> g, PrintWriter out)
{
  boolean exportEdgeWeights = parameters.contains(CSVFormat.Parameter.EDGE_WEIGHTS);
  for (V v : g.vertexSet()) {
    exportEscapedField(out, vertexIDProvider.getName(v));
    for (E e : g.outgoingEdgesOf(v)) {
      V w = Graphs.getOppositeVertex(g, e, v);
      out.print(delimiter);
      exportEscapedField(out, vertexIDProvider.getName(w));
      if (exportEdgeWeights) {
        out.print(delimiter);
        exportEscapedField(out, String.valueOf(g.getEdgeWeight(e)));
      }
    }
    out.println();
  }
}

代码示例来源:origin: Galigator/openllet

private void collapseCycle(final Set<ATermAppl> scc)
{
  final Iterator<ATermAppl> i = scc.iterator();
  final ATermAppl rep = i.next();
  while (i.hasNext())
  {
    final ATermAppl node = i.next();
    addEquivalent(rep, node);
    for (final DefaultEdge edge : _graph.incomingEdgesOf(node))
    {
      final ATermAppl incoming = _graph.getEdgeSource(edge);
      if (!incoming.equals(rep))
        _graph.addEdge(incoming, rep);
    }
    for (final DefaultEdge edge : _graph.outgoingEdgesOf(node))
    {
      final ATermAppl outgoing = _graph.getEdgeTarget(edge);
      if (!outgoing.equals(rep))
        _graph.addEdge(rep, outgoing);
    }
    _graph.removeVertex(node);
  }
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public V next()
{
  if (!hasNext()) {
    throw new NoSuchElementException();
  }
  // settle next node
  FibonacciHeapNode<QueueEntry> vNode = heap.removeMin();
  V v = vNode.getData().v;
  double vDistance = vNode.getKey();
  // relax edges
  for (E e : graph.outgoingEdgesOf(v)) {
    V u = Graphs.getOppositeVertex(graph, e, v);
    double eWeight = graph.getEdgeWeight(e);
    if (eWeight < 0.0) {
      throw new IllegalArgumentException("Negative edge weight not allowed");
    }
    updateDistance(u, e, vDistance + eWeight);
  }
  return v;
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static <V, E> List<NestedPath<V, E>> advanceFrontier(Graph<V, E> graph, Collection<NestedPath<V, E>> paths) {
  List<NestedPath<V, E>> result = new ArrayList<>();
  for(NestedPath<V, E> path : paths) {
    V current = path.getCurrent();
    Set<E> edges = graph.outgoingEdgesOf(current);
    for(E edge : edges) {
      boolean isCycle = path.containsEdge(edge, false);
      V v = graph.getEdgeTarget(edge);
      if(!isCycle) {
        NestedPath<V, E> nextPath = new NestedPath<>(new ParentLink<>(path, new Directed<>(edge, false)), v);
        result.add(nextPath);
      }
    }
  }
  return result;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

private void addUnseenChildrenOf(V vertex)
{
  for (E edge : graph.outgoingEdgesOf(vertex)) {
    if (nListeners != 0) {
      fireEdgeTraversed(createEdgeTraversalEvent(edge));
    }
    V oppositeV = Graphs.getOppositeVertex(graph, edge, vertex);
    if (isSeenVertex(oppositeV)) {
      encounterVertexAgain(oppositeV, edge);
    } else {
      encounterVertex(oppositeV, edge);
    }
  }
}

代码示例来源:origin: org.jgrapht/jgrapht-core

@Override
public V next()
{
  if (!hasNext()) {
    throw new NoSuchElementException();
  }
  Set<? extends E> potentialEdges = graph.outgoingEdgesOf(currentVertex);
  // randomly select an edge from the set of potential edges.
  E nextEdge = drawEdge(potentialEdges);
  if (nextEdge != null) {
    V nextVertex;
    nextVertex = Graphs.getOppositeVertex(graph, nextEdge, currentVertex);
    encounterVertex(nextVertex, nextEdge);
    fireEdgeTraversed(createEdgeTraversalEvent(nextEdge));
    fireVertexTraversed(createVertexTraversalEvent(nextVertex));
    currentVertex = nextVertex;
    return nextVertex;
  } else {
    sinkReached = true;
    return currentVertex;
  }
}

相关文章