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

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

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

Graph.incomingEdgesOf介绍

[英]Returns a set of all edges incoming into 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> incomingEdgesOf(V vertex)
{
  return delegate.incomingEdgesOf(vertex);
}

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

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

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

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

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

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

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

/**
 * {@inheritDoc}
 */
@Override
public Set<E> incomingEdgesOf(V vertex)
{
  boolean inG1 = g1.containsVertex(vertex);
  boolean inG2 = g2.containsVertex(vertex);
  if (inG1 && inG2) {
    return new UnmodifiableUnionSet<>(
      g1.incomingEdgesOf(vertex), g2.incomingEdgesOf(vertex));
  } else if (inG1) {
    return Collections.unmodifiableSet(g1.incomingEdgesOf(vertex));
  } else if (inG2) {
    return Collections.unmodifiableSet(g2.incomingEdgesOf(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 predecessors 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#incomingEdgesOf(Object)} to traverse the graph.
 *
 * @param g the graph to look for predecessors in
 * @param vertex the vertex to get the predecessors of
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 *
 * @return a list of the vertices that are the direct predecessors of the specified vertex.
 */
public static <V, E> List<V> predecessorListOf(Graph<V, E> g, V vertex)
{
  List<V> predecessors = new ArrayList<>();
  Set<? extends E> edges = g.incomingEdgesOf(vertex);
  for (E e : edges) {
    predecessors.add(getOppositeVertex(g, e, vertex));
  }
  return predecessors;
}

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

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

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

/**
 * Find the immediate parents of every item in the given set, and return a set containing all
 * those parents
 *
 * @param vertexSet the set of vertex to find parents of
 *
 * @return a set of every parent of every vertex passed in
 */
private Set<V> allParents(Set<V> vertexSet)
{
  HashSet<V> result = new HashSet<>();
  for (V e : vertexSet) {
    for (E edge : graph.incomingEdgesOf(e)) {
      if (graph.getEdgeTarget(edge).equals(e)) {
        result.add(graph.getEdgeSource(edge));
      }
    }
  }
  return result;
}

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

/**
 * Find the immediate parents of every item in the given set, and return a set containing all
 * those parents
 *
 * @param vertexSet the set of vertex to find parents of
 *
 * @return a set of every parent of every vertex passed in
 */
private Set<V> allParents(Set<V> vertexSet)
{
  HashSet<V> result = new HashSet<>();
  for (V e : vertexSet) {
    for (E edge : graph.incomingEdgesOf(e)) {
      if (graph.getEdgeTarget(edge).equals(e)) {
        result.add(graph.getEdgeSource(edge));
      }
    }
  }
  return result;
}

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

for (E edge : graph.incomingEdgesOf(node)) {
  if (graph.getEdgeTarget(edge).equals(node)) {
    V source = graph.getEdgeSource(edge);

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

for (E edge : graph.incomingEdgesOf(node)) {
  if (graph.getEdgeTarget(edge).equals(node)) {
    V source = graph.getEdgeSource(edge);

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

/**
 * Returns the set of non-epsilon edges reachable via epsilon transitions from the given vertex
 *  // Check if a state is implicitly final if it has an epsilon transition to a final state
 */
public static <V, E> Set<E> resolveTransitions(Graph<V, E> graph, Predicate<E> isEpsilon, V vertex, boolean reverse) {
  Set<E> result = new HashSet<>();
  Set<E> visited = new HashSet<>();
  Set<E> open = new HashSet<>(reverse ? graph.incomingEdgesOf(vertex) : graph.outgoingEdgesOf(vertex));
  while(!open.isEmpty()) {
    Iterator<E> it = open.iterator();
    E edge = it.next();
    it.remove();
    boolean isVisited = visited.contains(edge);
    if(isVisited) {
      continue;
    }
    visited.add(edge);
    boolean isEps = isEpsilon.test(edge);
    V target = reverse ? graph.getEdgeSource(edge) : graph.getEdgeTarget(edge);
    if(isEps) {
      Set<E> nextEdges = reverse ? graph.incomingEdgesOf(vertex) : graph.outgoingEdgesOf(target);
      open.addAll(nextEdges);
    } else {
      result.add(edge);
    }
  }
  return result;
}

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

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

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

for (E edge : graph.incomingEdgesOf(node)) {
  if (graph.getEdgeTarget(edge).equals(node)) {
    V source = graph.getEdgeSource(edge);

代码示例来源: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
 *         incoming to $v$.
 */
public int[] getInEdges(int vertexNumber)
{
  if (cacheEdges && (incomingEdges[vertexNumber] != null)) {
    return incomingEdges[vertexNumber];
  }
  V v = getVertex(vertexNumber);
  Set<E> edgeSet = graph.incomingEdgesOf(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) {
    incomingEdges[vertexNumber] = vertexArray;
  }
  return vertexArray;
}

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

double contribution = 0d;
for (E e : g.incomingEdgesOf(v)) {
  V w = Graphs.getOppositeVertex(g, e, v);
  contribution += dampingFactor * scores.get(w) * g.getEdgeWeight(e);

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

public void destructiveTopologocialSort(final List<ATermAppl> nodesSorted)
  {
    final Queue<ATermAppl> nodesPending = createQueue();

    for (final ATermAppl node : _graph.vertexSet())
      if (_graph.outDegreeOf(node) == 0)
        nodesPending.add(node);

    while (!nodesPending.isEmpty())
    {
      final ATermAppl node = nodesPending.remove();

      assert _graph.outDegreeOf(node) == 0;

      nodesSorted.addAll(getAllEquivalents(node));

      for (final DefaultEdge edge : _graph.incomingEdgesOf(node))
      {
        final ATermAppl source = _graph.getEdgeSource(edge);
        if (_graph.outDegreeOf(source) == 1)
          nodesPending.add(source);
      }

      _graph.removeVertex(node);
    }

    assert _graph.vertexSet().isEmpty() : "Failed to sort elements: " + _graph.vertexSet();
  }
}

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

public void destructiveTopologocialSort(final List<ATermAppl> nodesSorted)
  {
    final Queue<ATermAppl> nodesPending = createQueue();

    for (final ATermAppl node : _graph.vertexSet())
      if (_graph.outDegreeOf(node) == 0)
        nodesPending.add(node);

    while (!nodesPending.isEmpty())
    {
      final ATermAppl node = nodesPending.remove();

      assert _graph.outDegreeOf(node) == 0;

      nodesSorted.addAll(getAllEquivalents(node));

      for (final DefaultEdge edge : _graph.incomingEdgesOf(node))
      {
        final ATermAppl source = _graph.getEdgeSource(edge);
        if (_graph.outDegreeOf(source) == 1)
          nodesPending.add(source);
      }

      _graph.removeVertex(node);
    }

    assert _graph.vertexSet().isEmpty() : "Failed to sort elements: " + _graph.vertexSet();
  }
}

相关文章