|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Stoer-Wagner deterministic minimum cut algorithm. More...
#include <Stoer_Wagner.H>
Classes | |
| struct | PQEntry |
| struct | SWNode |
Public Types | |
| using | Node = typename GT::Node |
| using | Arc = typename GT::Arc |
| using | Weight = typename Distance::Distance_Type |
Public Member Functions | |
| Stoer_Wagner_Min_Cut ()=default | |
| Default constructor. | |
| Stoer_Wagner_Min_Cut (Distance _distance) | |
| Constructor with custom distance functor. | |
| Weight | operator() (GT &g, DynList< Node * > &vs, DynList< Node * > &vt, DynList< Arc * > &cut) |
| Find minimum cut in graph. | |
| Weight | min_cut_weight (GT &g) |
| Find only the minimum cut weight (faster, no partition info). | |
Private Member Functions | |
| void | init_from_graph (GT &g) |
| std::tuple< size_t, size_t, Weight > | minimum_cut_phase () |
| void | merge_nodes (size_t s, size_t t) |
Private Attributes | |
| Distance | distance |
| SA | sa |
| std::vector< std::vector< Weight > > | adj |
| std::vector< SWNode > | nodes |
| size_t | active_count |
Stoer-Wagner deterministic minimum cut algorithm.
This class implements the Stoer-Wagner algorithm for finding the global minimum cut in an undirected weighted graph. Unlike randomized algorithms (Karger, Karger-Stein), Stoer-Wagner is deterministic and always finds the exact minimum cut.
The algorithm is based on the observation that for any two vertices s and t, the global minimum cut is either:
It uses Maximum Adjacency Search to efficiently find minimum s-t cuts.
Weight operator()(Arc*). Defaults to extracting arc->get_info() as the weight.The algorithm works with any numeric weight type that supports:
Definition at line 203 of file Stoer_Wagner.H.
Definition at line 207 of file Stoer_Wagner.H.
Definition at line 206 of file Stoer_Wagner.H.
| using Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::Weight = typename Distance::Distance_Type |
Definition at line 208 of file Stoer_Wagner.H.
|
default |
Default constructor.
|
inlineexplicit |
Constructor with custom distance functor.
| _distance | Functor to extract edge weights |
Definition at line 399 of file Stoer_Wagner.H.
Definition at line 240 of file Stoer_Wagner.H.
References Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::active_count, Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::adj, Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::distance, GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::maps(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), NODE_COUNTER, Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::nodes, Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::sa, and w.
Referenced by Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::min_cut_weight(), and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()().
|
inlineprivate |
Definition at line 364 of file Stoer_Wagner.H.
References Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::active_count, Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::adj, and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::nodes.
Referenced by Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::min_cut_weight(), and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()().
Find only the minimum cut weight (faster, no partition info).
If you only need the cut weight and not the actual partition, this method is slightly more efficient.
| [in] | g | Input graph |
Definition at line 509 of file Stoer_Wagner.H.
References Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::active_count, GraphCommon< GT, Node, Arc >::get_num_nodes(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::init_from_graph(), Aleph::maps(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::merge_nodes(), and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::minimum_cut_phase().
|
inlineprivate |
Definition at line 273 of file Stoer_Wagner.H.
References Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::active_count, Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::adj, Aleph::count(), Aleph::DynList< T >::empty(), Aleph::maps(), Aleph::next(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::nodes, Aleph::DynList< T >::pop(), Aleph::DynList< T >::push(), and Aleph::DynList< T >::top().
Referenced by Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::min_cut_weight(), and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()().
|
inline |
Find minimum cut in graph.
Executes the Stoer-Wagner algorithm to find the exact minimum cut. For weighted graphs, returns the minimum total weight of cut edges. For unweighted graphs (weight=1), returns the minimum number of edges.
| [in] | g | Input graph (must have at least 2 nodes) |
| [out] | vs | First partition of vertices |
| [out] | vt | Second partition of vertices |
| [out] | cut | Arcs crossing the cut |
| std::domain_error | if graph has fewer than 2 nodes |
Definition at line 420 of file Stoer_Wagner.H.
References Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::active_count, ah_domain_error_if, Aleph::DynList< T >::append(), Aleph::DynList< T >::empty(), FunctionalMethods< Container, T >::exists(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::init_from_graph(), Aleph::HTList::is_empty(), Aleph::maps(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::merge_nodes(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::minimum_cut_phase(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::nodes, and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::sa.
|
private |
Definition at line 237 of file Stoer_Wagner.H.
Referenced by Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::init_from_graph(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::merge_nodes(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::min_cut_weight(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::minimum_cut_phase(), and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()().
|
private |
|
private |
Definition at line 211 of file Stoer_Wagner.H.
Referenced by Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::init_from_graph().
|
private |
Definition at line 236 of file Stoer_Wagner.H.
Referenced by Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::init_from_graph(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::merge_nodes(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::minimum_cut_phase(), and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()().
|
private |
Definition at line 212 of file Stoer_Wagner.H.
Referenced by Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::init_from_graph(), and Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()().