pgr_stoerWagner
— Returns the weight of the mincut of graph using stoerWagner algorithm.
Function determines a mincut and the mincut weight of a connected, undirected graph implemented by Boost.Graph.
Warning
Experimental functions
Availability
Version 2.3.0
 New Experimental function
Support
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:
pgr_stoerWagner(edges_sql)
RETURNS SET OF (seq, edge, cost, mincut)
OR EMPTY SET
Example: 


pgr_stoerWagner(TEXT edges_sql);
RETURNS SET OF (seq, edge, cost, mincut)
OR EMPTY SET
SELECT * FROM pgr_stoerWagner(
'SELECT id, source, target, cost, reverse_cost
FROM edge_table
WHERE id < 17'
);
seq  edge  cost  mincut
+++
1  1  1  1
(1 row)
Parameter  Type  Default  Description 

edges_sql  TEXT 
SQL query as described above. 
edges_sql:  an SQL query, which should return a set of rows with the following columns: 

Column  Type  Default  Description 

id  ANYINTEGER 
Identifier of the edge.  
source  ANYINTEGER 
Identifier of the first end point vertex of the edge.  
target  ANYINTEGER 
Identifier of the second end point vertex of the edge.  
cost  ANYNUMERICAL 
Weight of the edge (source, target)


reverse_cost  ANYNUMERICAL 
1  Weight of the edge (target, source),

Where:
ANYINTEGER:  SMALLINT, INTEGER, BIGINT 

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

seq  INT 
Sequential value starting from 1. 
edge  BIGINT 
Edges which divides the set of vertices into two. 
cost  FLOAT 
Cost to traverse of edge. 
mincut  FLOAT 
Mincut weight of a undirected graph. 
SELECT * FROM pgr_stoerWagner(
'SELECT id, source, target, cost, reverse_cost
FROM edge_table
WHERE id = 18'
);
seq  edge  cost  mincut
+++
1  18  1  1
(1 row)
Use pgr_connectedComponents( ) function in query:
SELECT * FROM pgr_stoerWagner(
$$
SELECT id, source, target, cost, reverse_cost FROM edge_table
where source = any (ARRAY(SELECT node FROM pgr_connectedComponents(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ')
WHERE component = 14)
)
OR
target = any (ARRAY(SELECT node FROM pgr_connectedComponents(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ')
WHERE component = 14)
)
$$
);
seq  edge  cost  mincut
+++
1  17  1  1
(1 row)
Indices and tables