pgr_stoerWagner  Experimental¶
pgr_stoerWagner
— The mincut of graph using stoerWagner algorithm.
Warning
Possible server crash
These functions might create a server crash
Warning
Experimental functions
They are not officially of the current release.
They likely will not be officially be part of the next release:
The functions might not make use of ANYINTEGER and ANYNUMERICAL
Name might change.
Signature might change.
Functionality might change.
pgTap tests might be missing.
Might need c/c++ coding.
May lack documentation.
Documentation if any might need to be rewritten.
Documentation examples might need to be automatically generated.
Might need a lot of feedback from the comunity.
Might depend on a proposed function of pgRouting
Might depend on a deprecated function of pgRouting
Availability
Version 2.3.0
New Experimental function
Description¶
In graph theory, the Stoer–Wagner algorithm is a recursive algorithm to solve the minimum cut problem in undirected weighted graphs with nonnegative weights. The essential idea of this algorithm is to shrink the graph by merging the most intensive vertices, until the graph only contains two combined vertex sets. At each phase, the algorithm finds the minimum st cut for two vertices s and t chosen as its will. Then the algorithm shrinks the edge between s and t to search for non st cuts. The minimum cut found in all phases will be the minimum weighted cut of the graph.
A cut is a partition of the vertices of a graph into two disjoint subsets. A minimum cut is a cut for which the size or weight of the cut is not larger than the size of any other cut. For an unweighted graph, the minimum cut would simply be the cut with the least edges. For a weighted graph, the sum of all edges’ weight on the cut determines whether it is a minimum cut.
The main characteristics are:
Process is done only on edges with positive costs.
It’s implementation is only on undirected graph.
Sum of the weights of all edges between the two sets is mincut.
A mincut is a cut having the least weight.
Values are returned when graph is connected.
When there is no edge in graph then EMPTY SET is return.
When the graph is unconnected then EMPTY SET is return.
Sometimes a graph has multiple mincuts, but all have the same weight. The this function determines exactly one of the mincuts as well as its weight.
Running time: \(O(V*E + V^2*log V)\).
Signatures¶
pgr_stoerWagner(Edges SQL) RETURNS SET OF (seq, edge, cost, mincut) OR EMPTY SET
 Example:
min cut of the main subgraph
SELECT * FROM pgr_stoerWagner(
'SELECT id, source, target, cost, reverse_cost
FROM edges WHERE id < 17');
seq  edge  cost  mincut
+++
1  6  1  1
(1 row)
Parameters¶
Parameter 
Type 
Description 


Edges SQL as described below. 
Inner Queries¶
Edges SQL¶
Column 
Type 
Default 
Description 


ANYINTEGER 
Identifier of the edge. 


ANYINTEGER 
Identifier of the first end point vertex of the edge. 


ANYINTEGER 
Identifier of the second end point vertex of the edge. 


ANYNUMERICAL 
Weight of the edge ( 


ANYNUMERICAL 
1 
Weight of the edge (

Where:
 ANYINTEGER:
SMALLINT
,INTEGER
,BIGINT
 ANYNUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Result Columns¶
Returns set of (seq, edge, cost, mincut)
Column 
Type 
Description 

seq 

Sequential value starting from 1. 
edge 

Edges which divides the set of vertices into two. 
cost 

Cost to traverse of edge. 
mincut 

Mincut weight of a undirected graph. 
Additional Example:¶
 Example:
min cut of an edge
SELECT * FROM pgr_stoerWagner(
'SELECT id, source, target, cost, reverse_cost
FROM edges WHERE id = 18');
seq  edge  cost  mincut
+++
1  18  1  1
(1 row)
 Example:
Using pgr_connectedComponents
SELECT * FROM pgr_stoerWagner(
$$
SELECT id, source, target, cost, reverse_cost FROM edges
WHERE source IN (
SELECT node FROM pgr_connectedComponents(
'SELECT id, source, target, cost, reverse_cost FROM edges ')
WHERE component = 2)
$$
);
seq  edge  cost  mincut
+++
1  17  1  1
(1 row)
See Also¶
Indices and tables