/** * 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(); }
/** * {@inheritDoc} */ @Override protected Iterable<V> getVertexOrdering() { List<V> order = new ArrayList<V>(graph.vertexSet()); Collections.shuffle(order, rng); return order; }
/** * 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; }
/** * 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; }
@Override public Set<V> getSinkPartition() { Set<V> sinkPartition = new LinkedHashSet<>(network.vertexSet()); sinkPartition.removeAll(this.getSourcePartition()); return sinkPartition; }
/** * 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; }
/** * 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)); }
@Override public Set<V> getSinkPartition() { if (sinkPartition == null) { sinkPartition = new LinkedHashSet<>(network.vertexSet()); sinkPartition.removeAll(this.getSourcePartition()); } return sinkPartition; }
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); }
/** * 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)); }
/** * 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)); }
/** * Construct a new coloring algorithm. * * @param graph the input graph */ public ColorRefinementAlgorithm(Graph<V, E> graph) { this(graph, getDefaultAlpha(graph.vertexSet())); }
/** * 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(); }
/** * 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; }
@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); }
/** * 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()); }
@Override protected void init(V startNode) { super.init(startNode); for (V node : graph.vertexSet()) { node.reset(); } startNode.setSource(); queue.clear(); queue.add(startNode); }
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."); } } }