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

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

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

Graph.vertexSet介绍

[英]Returns a set of the vertices 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.orbisgis/java-network-analyzer

/**
 * Initializes a new instance of a graph analyzer with the given
 * {@link ProgressMonitor}.
 *
 * @param graph The graph to be analyzed.
 */
public GeneralizedGraphAnalyzer(Graph<V, E> graph) {
  this.graph = graph;
  this.nodeSet = graph.vertexSet();
  this.nodeCount = this.nodeSet.size();
}

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

/**
 * {@inheritDoc}
 */
@Override
protected Iterable<V> getVertexOrdering()
{
  List<V> order = new ArrayList<V>(graph.vertexSet());
  Collections.shuffle(order, rng);
  return order;
}

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

/**
 * Returns partition $V-W$ of the cut obtained after the last invocation of
 * {@link #calculateMinCut(Set, boolean)}
 *
 * @return partition $V-W$
 */
public Set<V> getSinkPartition()
{
  Set<V> sinkPartition = new LinkedHashSet<>(network.vertexSet());
  sinkPartition.removeAll(sourcePartitionMinimumCut);
  return sinkPartition;
}

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

private void createVertexData()
{
  vertexToVertexData = new HashMap<V, VertexData<V>>(graph.vertexSet().size());
  for (V vertex : graph.vertexSet()) {
    vertexToVertexData.put(vertex, new VertexData2<V>(vertex, false, false));
  }
}

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

private void createVertexNumber()
{
  c = graph.vertexSet().size();
  vertexToVertexNumber = new HashMap<>(c);
  for (V vertex : graph.vertexSet()) {
    vertexToVertexNumber.put(vertex, new VertexNumber<>(vertex, 0));
  }
  stack = new ArrayDeque<>(c);
  B = new ArrayDeque<>(c);
}

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

/**
 * Constructs a new GreedyVCImpl instance
 * 
 * @param graph input graph
 */
public RecursiveExactVCImpl(Graph<V, E> graph)
{
  this.graph = GraphTests.requireUndirected(graph);
  this.vertexWeightMap = graph
    .vertexSet().stream().collect(Collectors.toMap(Function.identity(), vertex -> 1.0));
  weighted = false;
}

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

@Override
public Set<V> getSinkPartition()
{
  Set<V> sinkPartition = new LinkedHashSet<>(network.vertexSet());
  sinkPartition.removeAll(this.getSourcePartition());
  return sinkPartition;
}

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

/**
 * Tests if the inspected graph is biconnected. A biconnected graph is a connected graph on two
 * or more vertices having no cutpoints.
 *
 * @return true if the graph is biconnected, false otherwise
 */
public boolean isBiconnected()
{
  performLazyInspection();
  return graph.vertexSet().size() >= 2 && blocks.size() == 1;
}

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

/**
 * Constructs a new ClarksonTwoApproxVCImpl instance where all vertices have uniform weights.
 * 
 * @param graph input graph
 */
public ClarksonTwoApproxVCImpl(Graph<V, E> graph)
{
  this.graph = GraphTests.requireUndirected(graph);
  this.vertexWeightMap = graph
    .vertexSet().stream().collect(Collectors.toMap(Function.identity(), vertex -> 1.0));
}

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

@Override
public Set<V> getSinkPartition()
{
  if (sinkPartition == null) {
    sinkPartition = new LinkedHashSet<>(network.vertexSet());
    sinkPartition.removeAll(this.getSourcePartition());
  }
  return sinkPartition;
}

代码示例来源: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: org.jgrapht/jgrapht-core

/**
 * Constructs a new GreedyVCImpl instance where all vertices have uniform weights.
 * 
 * @param graph input graph
 */
public GreedyVCImpl(Graph<V, E> graph)
{
  this.graph = GraphTests.requireUndirected(graph);
  this.vertexWeightMap = graph
    .vertexSet().stream().collect(Collectors.toMap(Function.identity(), vertex -> 1.0));
}

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

/**
 * Constructs a new BarYehudaEvenTwoApproxVCImpl instance where all vertices have uniform
 * weights.
 * 
 * @param graph input graph
 */
public BarYehudaEvenTwoApproxVCImpl(Graph<V, E> graph)
{
  this.graph = GraphTests.requireUndirected(graph);
  this.vertexWeightMap = graph
    .vertexSet().stream().collect(Collectors.toMap(Function.identity(), vertex -> 1.0));
}

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

/**
 * Construct a new coloring algorithm.
 *
 * @param graph the input graph
 */
public ColorRefinementAlgorithm(Graph<V, E> graph)
{
  this(graph, getDefaultAlpha(graph.vertexSet()));
}

代码示例来源: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 true if the matching is a perfect matching. A matching is perfect if every vertex
 * in the graph is incident to an edge in the matching.
 * 
 * @return true if the matching is perfect. By definition, a perfect matching consists of
 *         exactly $\frac{1}{2|V|}$ edges, and the number of vertices in the graph must be
 *         even.
 */
default boolean isPerfect()
{
  return getEdges().size() == getGraph().vertexSet().size() / 2.0;
}

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

@Override
public MultiObjectiveSingleSourcePaths<V, E> getPaths(V source)
{
  if (!graph.containsVertex(source)) {
    throw new IllegalArgumentException(GRAPH_MUST_CONTAIN_THE_SOURCE_VERTEX);
  }
  Map<V, List<GraphPath<V, E>>> paths = new HashMap<>();
  for (V v : graph.vertexSet()) {
    paths.put(v, getPaths(source, v));
  }
  return new ListMultiObjectiveSingleSourcePathsImpl<>(graph, source, paths);
}

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

/**
 * Creates new lexicographical breadth-first iterator for {@code graph}.
 *
 * @param graph the graph to be iterated.
 */
public LexBreadthFirstIterator(Graph<V, E> graph)
{
  super(graph);
  GraphTests.requireUndirected(graph);
  bucketList = new BucketList(graph.vertexSet());
}

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

@Override
protected void init(V startNode) {
  super.init(startNode);
  for (V node : graph.vertexSet()) {
    node.reset();
  }
  startNode.setSource();
  queue.clear();
  queue.add(startNode);
}

代码示例来源: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.");
    }
  }
}

相关文章