stoer_wagner_min_cut
Determines a min-cut and the min-cut weight of a connected, undirected graph.
Complexity: O(V * E + V2 log V)
Defined in: <boost/graph/stoer_wagner_min_cut.hpp>
Example
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/stoer_wagner_min_cut.hpp>
#include <boost/property_map/property_map.hpp>
#include <iostream>
struct EdgeProps { int weight; };
using namespace boost;
using Graph = adjacency_list<vecS, vecS, undirectedS,
no_property, EdgeProps>;
int main() {
Graph g{4};
add_edge(0, 1, EdgeProps{2}, g);
add_edge(0, 2, EdgeProps{3}, g);
add_edge(1, 2, EdgeProps{3}, g);
add_edge(1, 3, EdgeProps{2}, g);
add_edge(2, 3, EdgeProps{4}, g);
auto weight_map = get(&EdgeProps::weight, g);
int cut = stoer_wagner_min_cut(g, weight_map);
std::cout << "Stoer-Wagner min cut: " << cut << "\n";
}
Stoer-Wagner min cut: 5
(1) Named parameter version
template <class UndirectedGraph, class WeightMap,
class P, class T, class R>
weight_type stoer_wagner_min_cut(
const UndirectedGraph& g,
WeightMap weights,
const bgl_named_params<P, T, R>& params = all defaults);
| Direction | Parameter | Description |
|---|---|---|
IN |
|
A connected, undirected graph. The graph type must be a model of Vertex List Graph and Incidence Graph. |
IN |
|
The weight or length of each edge in the graph. The |
| Direction | Named Parameter | Description / Default |
|---|---|---|
OUT |
|
The algorithm computes a min-cut, which divides the set of vertices into
two, non-empty sets. The |
IN |
|
This maps each vertex to an integer in the range [0, |
UTIL |
|
|
UTIL |
|
|
UTIL |
|
This parameter only has an effect when the default max-priority queue is
used. |
UTIL |
|
This parameter only has an effect when the default max-priority queue is
used. |
(2) Positional version (explicit index map)
template <class UndirectedGraph, class WeightMap, class ParityMap,
class VertexAssignmentMap, class KeyedUpdatablePriorityQueue,
class IndexMap>
typename property_traits<WeightMap>::value_type
stoer_wagner_min_cut(
const UndirectedGraph& g, WeightMap weights,
ParityMap parities, VertexAssignmentMap assignments,
KeyedUpdatablePriorityQueue& pq, IndexMap index_map);
Explicit positional form with every working map supplied by the caller. Prefer overload (1) unless you have a reason to pre-allocate the work maps and priority queue.
(3) Positional version (default index map)
template <class UndirectedGraph, class WeightMap, class ParityMap,
class VertexAssignmentMap, class KeyedUpdatablePriorityQueue>
typename property_traits<WeightMap>::value_type
stoer_wagner_min_cut(
const UndirectedGraph& g, WeightMap weights,
ParityMap parities, VertexAssignmentMap assignments,
KeyedUpdatablePriorityQueue& pq);
Lives in namespace boost::graph. Same as (2) with index_map = get(vertex_index, g); requires the graph to have an interior vertex_index_t property.
Description
A cut of a graph G is a partition of the vertices into two, non-empty sets. The weight of such a partition is the number of edges between the two sets if G is unweighted, or the sum of the weights of all edges between the two sets if G is weighted. A min-cut is a cut having the least weight.
Sometimes a graph has multiple min-cuts, but all have the same weight. The stoer_wagner_min_cut function implements the
Stoer-Wagner algorithm and determines exactly one of the min-cuts as well as its weight.
Throws
bad_graph-
If
num_vertices(g)is less than 2. std::invalid_argument-
If a max-priority queue is given as an argument and it is not empty.
Example
The file examples/stoer_wagner.cpp contains an example of calculating a min-cut of a weighted, undirected graph and its min-cut weight.