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

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

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

Graph.edgeSet介绍

[英]Returns a set of the edges contained in this graph. The set is backed by the graph, so changes to the graph are reflected in the set. If the graph is modified while an iteration over the set is in progress, the results of the iteration are undefined.

The graph implementation may maintain a particular set ordering (e.g. via java.util.LinkedHashSet) for deterministic iteration, but this is not required. It is the responsibility of callers who rely on this behavior to only use graph implementations which support it.
[中]返回此图中包含的一组边。集合由图形支持,因此对图形的更改将反映在集合中。如果在对集合进行迭代时修改了图形,则迭代的结果是未定义的。
图形实现可以为确定性迭代维护特定的集合顺序(例如,通过java.util.LinkedHashSet),但这不是必需的。依赖此行为的调用方有责任只使用支持此行为的图形实现。

代码示例

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

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

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

public Set<Scope> edgeSet()
 {
 return graph.edgeSet();
 }

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

/**
 * {@inheritDoc}
 */
@Override
public Set<E> edgeSet()
{
  return new UnmodifiableUnionSet<>(g1.edgeSet(), g2.edgeSet());
}

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

/**
 * Test whether a graph is empty. An empty graph on n nodes consists of n isolated vertices with
 * no edges.
 * 
 * @param graph the input graph
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 * @return true if the graph is empty, false otherwise
 */
public static <V, E> boolean isEmpty(Graph<V, E> graph)
{
  Objects.requireNonNull(graph, GRAPH_CANNOT_BE_NULL);
  return graph.edgeSet().isEmpty();
}

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

/**
 * Check if the graph is chordal.
 *
 * @return true if the graph is chordal, false otherwise.
 */
public boolean isChordal()
{
  if (chordalGraph == null) {
    computeMinimalTriangulation();
  }
  return (chordalGraph.edgeSet().size() == graph.edgeSet().size());
}

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

private void init()
{
  blocks = new LinkedHashSet<>();
  cutpoints = new LinkedHashSet<>();
  bridges = new LinkedHashSet<>();
  connectedSets = new LinkedHashSet<>();
  stack = new ArrayDeque<>(graph.edgeSet().size());
  for (V v : graph.vertexSet())
    discTime.put(v, -1);
}

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

/**
 * Calculate the density of the graph as the
 * number of edges divided by the number of vertices
 * @param g the graph
 * @return the density
 */
public static double calculateDensity(Graph<?,?> g) {
  return (double)g.edgeSet().size() / (double)g.vertexSet().size();
}

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

/**
 * Returns the set of edges which run from the source partition to the sink partition, in the
 * $s-t$ cut obtained after the last invocation of {@link #calculateMinCut(Set, boolean)}
 *
 * @return set of edges which have one endpoint in the source partition and one endpoint in the
 *         sink partition.
 */
public Set<E> getCutEdges()
{
  Predicate<E> predicate = e -> sourcePartitionMinimumCut.contains(network.getEdgeSource(e))
    ^ sourcePartitionMinimumCut.contains(network.getEdgeTarget(e));
  return network.edgeSet().stream().filter(predicate).collect(
    Collectors.toCollection(LinkedHashSet::new));
}

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

/**
 * Test whether a graph is <a href="https://en.wikipedia.org/wiki/Overfull_graph">overfull</a>.
 * A graph is overfull if $|E|&gt;\Delta(G)\lfloor |V|/2 \rfloor$, where $\Delta(G)$ is the
 * maximum degree of the graph.
 *
 * @param graph the input graph
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 * @return true if the graph is overfull, false otherwise
 */
public static <V, E> boolean isOverfull(Graph<V, E> graph)
{
  int maxDegree = graph.vertexSet().stream().mapToInt(graph::degreeOf).max().getAsInt();
  return graph.edgeSet().size() > maxDegree * Math.floor(graph.vertexSet().size() / 2.0);
}

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

@Override
  public Set<E> getCutEdges()
  {
    Set<E> cutEdges = new LinkedHashSet<>();
    Set<V> sourcePartion = this.getSourcePartition();
    for (E e : network.edgeSet()) {
      V source = network.getEdgeSource(e);
      V sink = network.getEdgeTarget(e);
      if (sourcePartion.contains(source) ^ sourcePartion.contains(sink))
        cutEdges.add(e);
    }
    return cutEdges;
  }
}

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

/**
 * Test whether an undirected graph is a tree.
 *
 * @param graph the input graph
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 * @return true if the graph is tree, false otherwise
 */
public static <V, E> boolean isTree(Graph<V, E> graph)
{
  if (!graph.getType().isUndirected()) {
    throw new IllegalArgumentException(GRAPH_MUST_BE_UNDIRECTED);
  }
  return (graph.edgeSet().size() == (graph.vertexSet().size() - 1)) && isConnected(graph);
}

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

public static <V, E> int hashCodeIgnoreAnnotations( Graph<V, E> graph )
 {
 int hash = graph.vertexSet().hashCode();
 for( E e : graph.edgeSet() )
  {
  int part = e.hashCode();
  int source = graph.getEdgeSource( e ).hashCode();
  int target = graph.getEdgeTarget( e ).hashCode();
  int pairing = pair( source, target );
  part = ( 27 * part ) + pairing;
  long weight = (long) graph.getEdgeWeight( e );
  part = ( 27 * part ) + (int) ( weight ^ ( weight >>> 32 ) );
  hash += part;
  }
 return hash;
 }

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

/**
 * Creates a weak chordality inspector for the {@code graph}
 *
 * @param graph the inspected {@code graph}
 */
public WeakChordalityInspector(Graph<V, E> graph)
{
  this.graph = Objects.requireNonNull(graph);
  if (graph.getType().isDirected()) {
    this.graph = new AsUndirectedGraph<>(graph);
  }
  n = graph.vertexSet().size();
  m = graph.edgeSet().size();
  initMappings();
}

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

private void exportAsEdgeList(Graph<V, E> g, PrintWriter out)
{
  boolean exportEdgeWeights = parameters.contains(CSVFormat.Parameter.EDGE_WEIGHTS);
  for (E e : g.edgeSet()) {
    exportEscapedField(out, vertexIDProvider.getName(g.getEdgeSource(e)));
    out.print(delimiter);
    exportEscapedField(out, vertexIDProvider.getName(g.getEdgeTarget(e)));
    if (exportEdgeWeights) {
      out.print(delimiter);
      exportEscapedField(out, String.valueOf(g.getEdgeWeight(e)));
    }
    out.println();
  }
}

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

private static <V, E> Graph<V, E> disconnectExtentsAndExclude( Graph<V, E> full, Set<E> withoutEdges )
 {
 IdentityMultiGraphGraph<V, E> copy = (IdentityMultiGraphGraph<V, E>) new IdentityMultiGraphGraph<>( Object.class );
 Graphs.addAllVertices( copy, full.vertexSet() );
 copy.removeVertex( (V) Extent.head );
 copy.removeVertex( (V) Extent.tail );
 Set<E> edges = full.edgeSet();
 if( !withoutEdges.isEmpty() )
  {
  edges = new HashSet<>( edges );
  edges.removeAll( withoutEdges );
  }
 Graphs.addAllEdges( copy, full, edges );
 return copy;
 }

代码示例来源:origin: com.io7m.jgrapht/jgrapht-ext

/**
   * Draws a given graph with all its vertices and edges.
   *
   * @param graph the graph to be added to the existing graph.
   */
  private void insertJGraphT(Graph<V, E> graph)
  {
    for (V vertex : graph.vertexSet()) {
      addJGraphTVertex(vertex);
    }

    for (E edge : graph.edgeSet()) {
      addJGraphTEdge(edge);
    }
  }
}

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

/**
   * Draws a given graph with all its vertices and edges.
   *
   * @param graph the graph to be added to the existing graph.
   */
  private void insertJGraphT(Graph<V, E> graph)
  {
    for (V vertex : graph.vertexSet()) {
      addJGraphTVertex(vertex);
    }

    for (E edge : graph.edgeSet()) {
      addJGraphTEdge(edge);
    }
  }
}

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

/**
 * {@inheritDoc}
 */
@Override
public MinimumCostFlow<E> getMinimumCostFlow(
  final MinimumCostFlowProblem<V, E> minimumCostFlowProblem)
{
  this.problem = Objects.requireNonNull(minimumCostFlowProblem);
  if (problem.getGraph().getType().isUndirected()) {
    throw new IllegalArgumentException(
      "The algorithm doesn't support undirected flow networks");
  }
  n = problem.getGraph().vertexSet().size();
  m = problem.getGraph().edgeSet().size();
  calculateMinimumCostFlow();
  return minimumCostFlow;
}

代码示例来源:origin: io.github.oliviercailloux.jmcda/utils

static public <V, E> void copyTo(Graph<V, E> source, Graph<V, E> target) {
  for (V vertex : source.vertexSet()) {
    target.addVertex(vertex);
  }
  for (E edge : source.edgeSet()) {
    final boolean added = target.addEdge(source.getEdgeSource(edge), source.getEdgeTarget(edge), edge);
    if (!added) {
      throw new IllegalArgumentException("Target graph does not support addition of (some) source edges.");
    }
  }
}

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

public DirectedMultiGraph( Graph<FlowElement, Scope> parent )
 {
 this();
 // safe to assume there are no unconnected vertices
 for( Scope edge : parent.edgeSet() )
  {
  FlowElement s = parent.getEdgeSource( edge );
  FlowElement t = parent.getEdgeTarget( edge );
  addVertex( s );
  addVertex( t );
  addEdge( s, t, edge );
  }
 }

相关文章