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

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

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

Graph.edgesOf介绍

[英]Returns a set of all edges touching the specified vertex. If no edges are touching the specified vertex returns an empty set.
[中]返回一组与指定顶点接触的所有边。如果没有边与指定顶点接触,则返回一个空集。

代码示例

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

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

代码示例来源:origin: sc.fiji/TrackMate_

@Override
  public Set< EE > edgesOf( final VV vertex )
  {
    return graph.edgesOf( vertex );
  }
}

代码示例来源:origin: fiji/TrackMate

@Override
  public Set< EE > edgesOf( final VV vertex )
  {
    return graph.edgesOf( vertex );
  }
}

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

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

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

@Override
  public int compare(V2 v1, V2 v2)
  {
    return graph.edgesOf(v1).size() - graph.edgesOf(v2).size();
  }
}

代码示例来源:origin: org.orbisgis/java-network-analyzer

public static Set outgoingEdgesOf(Graph g, Object node) {
  if (g instanceof DirectedGraph) {
    return ((DirectedGraph) g).outgoingEdgesOf(node);
  } else {
    return g.edgesOf(node);
  }
}

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

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

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

/**
 * Compute the sum of the weights entering a vertex
 * 
 * @param v the vertex
 * @return the sum of the weights entering a vertex
 */
public double vertexWeight(Set<V> v)
{
  double wsum = 0.0;
  for (DefaultWeightedEdge e : workingGraph.edgesOf(v)) {
    wsum += workingGraph.getEdgeWeight(e);
  }
  return wsum;
}

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

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

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

/**
 * Returns a set of vertices that are neighbors of a specified vertex.
 *
 * @param g the graph to look for neighbors in
 * @param vertex the vertex to get the neighbors of
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 * @return a set of the vertices that are neighbors of the specified vertex
 */
public static <V, E> Set<V> neighborSetOf(Graph<V, E> g, V vertex)
{
  Set<V> neighbors = new LinkedHashSet<>();
  for (E e : g.edgesOf(vertex)) {
    neighbors.add(Graphs.getOppositeVertex(g, e, vertex));
  }
  return neighbors;
}

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

/**
 * Returns true if vertex v is incident to an edge in this matching.
 * 
 * @param v vertex
 * @return true if vertex v is incident to an edge in this matching.
 */
default boolean isMatched(V v)
{
  Set<E> edges = getEdges();
  return getGraph().edgesOf(v).stream().anyMatch(edges::contains);
}

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

/**
 * Returns a list of vertices that are the neighbors 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#edgesOf(Object)} to traverse the graph.
 *
 * @param g the graph to look for neighbors in
 * @param vertex the vertex to get the neighbors of
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 *
 * @return a list of the vertices that are the neighbors of the specified vertex.
 */
public static <V, E> List<V> neighborListOf(Graph<V, E> g, V vertex)
{
  List<V> neighbors = new ArrayList<>();
  for (E e : g.edgesOf(vertex)) {
    neighbors.add(getOppositeVertex(g, e, vertex));
  }
  return neighbors;
}

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

/**
 * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More
 * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then
 * the index of {@code vertex}.
 *
 * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in
 *        order.
 * @param vertex the vertex whose predecessors in order are to be returned.
 * @return the predecessors of {@code vertex} in order defines by {@code map}.
 */
private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex)
{
  Set<V> predecessors = new HashSet<>();
  Integer vertexPosition = vertexInOrder.get(vertex);
  Set<E> edges = graph.edgesOf(vertex);
  for (E edge : edges) {
    V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex);
    Integer destPosition = vertexInOrder.get(oppositeVertex);
    if (destPosition < vertexPosition)
      predecessors.add(oppositeVertex);
  }
  return predecessors;
}

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

/**
 * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More
 * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then
 * the index of {@code vertex}.
 *
 * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in
 *        order.
 * @param vertex the vertex whose predecessors in order are to be returned.
 * @return the predecessors of {@code vertex} in order defines by {@code map}.
 */
private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex)
{
  Set<V> predecessors = new HashSet<>();
  Integer vertexPosition = vertexInOrder.get(vertex);
  Set<E> edges = graph.edgesOf(vertex);
  for (E edge : edges) {
    V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex);
    Integer destPosition = vertexInOrder.get(oppositeVertex);
    if (destPosition < vertexPosition)
      predecessors.add(oppositeVertex);
  }
  return predecessors;
}

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

/**
 * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More
 * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then
 * the index of {@code vertex}.
 *
 * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in
 *        order.
 * @param vertex the vertex whose predecessors in order are to be returned.
 * @return the predecessors of {@code vertex} in order defines by {@code map}.
 */
private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex)
{
  Set<V> predecessors = new HashSet<>();
  Integer vertexPosition = vertexInOrder.get(vertex);
  Set<E> edges = graph.edgesOf(vertex);
  for (E edge : edges) {
    V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex);
    Integer destPosition = vertexInOrder.get(oppositeVertex);
    if (destPosition < vertexPosition) {
      predecessors.add(oppositeVertex);
    }
  }
  return predecessors;
}

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

/**
   * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More
   * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then
   * the index of {@code vertex}.
   *
   * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in
   *        order.
   * @param vertex the vertex whose predecessors in order are to be returned.
   * @return the predecessors of {@code vertex} in order defines by {@code map}.
   */
  private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex)
  {
    Set<V> predecessors = new HashSet<>();
    Integer vertexPosition = vertexInOrder.get(vertex);
    Set<E> edges = graph.edgesOf(vertex);
    for (E edge : edges) {
      V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex);
      Integer destPosition = vertexInOrder.get(oppositeVertex);
      if (destPosition < vertexPosition)
        predecessors.add(oppositeVertex);
    }
    return predecessors;
  }
}

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

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

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

private void simpleHeuristic()
  {
    for (V v : partition1) {
      E maxEdge = null;
      BigDecimal maxWeight = BigDecimal.ZERO;

      for (E e : graph.edgesOf(v)) {
        BigDecimal w = BigDecimal.valueOf(graph.getEdgeWeight(e));
        if (comparator.compare(w, maxWeight) > 0) {
          maxWeight = w;
          maxEdge = e;
        }
      }

      pot.put(v, maxWeight);
      if (maxEdge != null) {
        V u = Graphs.getOppositeVertex(graph, maxEdge, v);
        if (!matchedEdge.containsKey(u)) {
          matching.add(maxEdge);
          matchingWeight = matchingWeight.add(maxWeight);
          matchedEdge.put(v, maxEdge);
          matchedEdge.put(u, maxEdge);
        }
      }
    }
  }
}

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

/**
 * Computes and returns neighbours of {@code vertex} which haven't been visited by this
 * iterator.
 *
 * @param vertex the vertex, whose neighbours are being explored.
 * @return neighbours of {@code vertex} which have yet to be visited by this iterator.
 */
private Set<V> getUnvisitedNeighbours(V vertex)
{
  Set<V> unmapped = new HashSet<>();
  Set<E> edges = graph.edgesOf(vertex);
  for (E edge : edges) {
    V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex);
    if (bucketList.containsBucketWith(oppositeVertex)) {
      unmapped.add(oppositeVertex);
    }
  }
  return unmapped;
}

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

/**
   * Increments the cardinalities of the neighbours of the {@code vertex} by 1. If the maximum
   * cardinality increases, increments {@code maxCardinality} by 1.
   *
   * @param vertex the vertex whose neighbours are to be updated.
   */
  private void updateNeighbours(V vertex)
  {
    Set<V> processed = new HashSet<>();
    for (E edge : graph.edgesOf(vertex)) {
      V opposite = Graphs.getOppositeVertex(graph, edge, vertex);
      if (cardinalityMap.containsKey(opposite) && !processed.contains(opposite)) {
        processed.add(opposite);
        addToBucket(opposite, removeFromBucket(opposite) + 1);
      }
    }
    if (maxCardinality < graph.vertexSet().size() && maxCardinality >= 0
      && buckets.get(maxCardinality + 1) != null)
    {
      ++maxCardinality;
    }
  }
}

相关文章