105# ifndef STOER_WAGNER_H
106# define STOER_WAGNER_H
111# include <functional>
235 std::vector<std::vector<Weight>>
adj;
243 adj.assign(n, std::vector<Weight>(n,
Weight(0)));
249 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne())
251 auto p = it.get_curr();
253 nodes[id].members.append(p);
255 nodes[id].merged =
false;
262 auto a = it.get_curr();
275 const size_t n =
nodes.size();
279 while (start < n &&
nodes[start].merged)
286 std::vector<Weight> key(n,
Weight(0));
287 std::vector<bool>
in_A(n,
false);
290 std::priority_queue<PQEntry>
pq;
298 for (
size_t j = 0; j < n; ++j)
302 key[j] =
adj[start][j];
317 if (!
in_A[top.node_id] && !
nodes[top.node_id].merged &&
318 top.priority == key[top.node_id])
328 for (
size_t j = 0; j < n; ++j)
347 for (
size_t j = 0; j < n; ++j)
366 const size_t n =
nodes.size();
370 nodes[t].merged =
true;
373 for (
size_t j = 0; j < n; ++j)
375 if (j != s && j != t && !
nodes[j].merged)
383 for (
size_t j = 0; j < n; ++j)
466 for (
auto p :
nodes[t].members)
477 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne())
479 auto p = it.get_curr();
487 auto a = it.get_curr();
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Default distance accessor for arc weights.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
void empty() noexcept
empty the list
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
constexpr bool is_empty() const noexcept
Return true if list is empty.
Graph_Node< int > Node
The graph type.
Graph_Arc< int > Arc
The node class type.
Stoer-Wagner deterministic minimum cut algorithm.
std::vector< std::vector< Weight > > adj
Weight operator()(GT &g, DynList< Node * > &vs, DynList< Node * > &vt, DynList< Arc * > &cut)
Find minimum cut in graph.
void merge_nodes(size_t s, size_t t)
std::tuple< size_t, size_t, Weight > minimum_cut_phase()
std::vector< SWNode > nodes
Stoer_Wagner_Min_Cut()=default
Default constructor.
Stoer_Wagner_Min_Cut(Distance _distance)
Constructor with custom distance functor.
typename Distance::Distance_Type Weight
Weight min_cut_weight(GT &g)
Find only the minimum cut weight (faster, no partition info).
void init_from_graph(GT &g)
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criteria.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
#define NODE_COUNTER(p)
Get the counter of a node.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
void next()
Advance all underlying iterators (bounds-checked).
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Filtered iterator on all the arcs of a graph.
Default filter for filtered iterators on arcs.
Arc of graph implemented with double-linked adjacency lists.
bool operator<(const PQEntry &other) const
DynList< Node * > members
Unit weight functor for unweighted graphs.
size_t operator()(typename GT::Arc *) const
Lazy and scalable dynamic array implementation.
Utility algorithms and operations for graphs.
Simple graph implementation with adjacency lists.