The maximum s-t flow has a value of 6
Suppose that we have a communication network, in which certain pairs of nodes are linked by connections; each connection has a limit to the rate at which data can be sent. Given two nodes on the network, what is the maximum rate at which one can send data to the other, assuming no other pair of nodes are attempting to communicate? (source)
This is a typical instance of a maximum flow problem: given an underlying network, where the edge weights denote the maximum possible capacity per edge, one wants to find out how much can be transerred over the edges from the source node s to the target node t.
maxflow-graph-editor.svg
Legende
|
Graph G
maxflow-graph-algorithm-graph.svg
Legende
|
Residual Graph G' with axis:
maxflow-graph-algorithm-height.svg
Legende
|
Click on a node to select it as the source/starting node s
Click on a node to select it as the target/sink node t. If you want to change the source node, go back with prev.
Source and target node have been selected and are filled with green. Per default, these are the nodes with lowest and hightest id. If you want to change the target node, go back with prev.
Edges are annotated with preflow/capacity, where the latter corresponds to the thickness of the gray line.
Now the algorithm can begin. Click on next to start it
Set the preflow f(e) (light blue) to the maximum capacity c(e) for all edges emanating s and set f(e) = 0 for all other edges. Add all nodes v ≠ t having (s,v) ∈ E to the queue Q of active nodes (yellow).
The edges in G are labeled with f(e)/c(e) denoting the current preflow along the edge and its maximum capacity. The nodes in G' are labeled with height/excess, where the latter one is also shown as a bar next to the node.
For each node v ≠ s set h(v) to the shortest directed path from v to t in the network G where the length of a path is the number of edges of the path. (In particular, set h(t) = 0). This can be done in time O(|V| + |E|) by a breadth first search starting at t and using all edges in the opposite direction. The source s isn’t reached by this BFS. We initialize h(s) by setting h(s) = |V|.
We mapped the height of a node to the y axis in G'.
As long as the queue Q containing the active nodes (in yellow) isn’t empty pop the first node v from the front of the queue. We call v the current node and fill it with red.
In the following, we will try to apply push or relabel operations to v to get rid of its excess flow e(v). These operate on the residual edges E' in G' leaving the active node and are displayed with dashed lines and labeled with their residual capacities c'.
While the current node has excess e(v)>0 and the residual network G'=(V,E') contains an edge that is eligible or legal with respect to the current height function, i.e. there is an edge e'=(v,w) having h(v)==h(w)+1, we can apply a push operation.
All residual edges which are not legal are grayed out. If there is a legal residual edge e' it is displayed in orange.
Push δ = min{e(v), c'(e')} amount of flow from v to w. More precisely, if e' ∈ E' is a forward edge (-->) with respect to an edge e of G, increase the preflow f(e) of e by δ, and if e' is a backward edge (<--), then decrease the preflow f(e) of e by δ.
By doing so, e(v) is decreased by δ, and e(w) is increased by δ. If w ≠ s,t, and if w wasn't active before, w becomes active, and is added at the end of the queue Q containing the active nodes.
If the current node still has excess e(v)>0 and if there is no legal edge emanating from v in the residual network, then apply a relabel operation.
Increase the height h(v) of the current node so that it is exactly one level above the minimum height of its adjacent nodes in the residual Graph G'. The residual edge e* to the adjacent node of minimum height is displayed in purple.
Since the current node still has excess, re-add it to the end of the queue Q of active nodes after that.
The algorithm terminated with a maximum flow value of:
v | Q | e' | e* |
---|---|---|---|
- | ∅ | - | - |
s ← pick(v)
t ← pick(v)
BEGIN
(* Initialize the preflow *)
FORALL e=(u,w) ∈ E
f(e) ← (u == s) ? c(e) : 0
IF u == s AND w ≠ t THEN Q.add(w)
(* Initialize the height function *)
h(s) ← |V|
FORALL v ∈ V\{s}
h(v) ← #arcs on shortest v-t path
(* Main Loop *)
WHILE Q ≠ ∅
v ← Q.pop()
WHILE e(v)>0 AND ∃ e'=(v,w)∈E'|h(v)==h(w)+1
(* PUSH *)
push min(e(v),c'(e')) flow from v to w
IF w ≠ s,t AND w ∉ Q THEN Q.add(w)
IF e(v)>0
(* RELABEL *)
h(v) ← 1+min({h(w)|e*=(v,w)∈E'})
Q.add(v)
END