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
Graph G=(V,E) with capacities c(e)≥0∀e∈E
In many applications one wants to know how much flow of a certain resource can simultaneously be transferred over a network from a to b. Depending on the context, flow can mean different things: The amount of water in a water pipe system in your city or the bandwidth of a computer network. However, the links in the network on paths from a to b can only handle flow up to their maximum capacity. One now seeks an assignemt of flow values to edges that fulfills all the capacity constraints of the edges and the flow conservation property on all the inner nodes, meaning we don't want leaks in our pipe system.
In general we speak of a flow. Therefore one assigns a flow value to each edge in our network, the graph
The Push-Relabel Algorithm of Goldberg and Tarjan computes the maximum s-t flow on a graph
digraph G=(V,E)
create the residual network
Input: a directed graph G=(V,E) with source node s, target node t.
edge capacities c(e)>=0 for all edges
Output: A feasible maximum s-t flow f(e) satisfying:
capacity constraints : 0<=f(e)<=c(e) for all edges
flow conservation : f(u,v) == f(v,u) for all nodes except s,t
The flow value of f(e) is maximized along all feasible flows
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
This is the same asymptotical performance as that of Dinic's algorithm (1970), itself a tuned version of Edmonds–Karp algorithm O(|V||E|2). These two classical maximum flow algorithms, emerging from the Ford-Fulkerson method (1956) are based on augmenting s-t paths and preserve the flow conservation property at inner nodes (e.g no excess) even during the course of the algorithm.
So why did we even need another method if it is not asymptotically faster than the existing ones and adds additional complexity? It turns out that we can further tune the generic algorithm by specifiing the order in which we choose the active nodes which we apply push and relabel operations to.
In particular, the variant implemented in this applet chooses the FIFO rule when selecting active nodes from the queue Q, which has a running time of O(|V|3), which is better than the previous bound, especially on dense graphs (it is actually independend on the number of edges).
Certain modifications of the generic algorithm are among the fastest algorithms known today to solve maximum flow problems. For a comparison, please refer to this table.
Efficient Maximum Flow Algorithms from CACM on Vimeo.
source: [GT2014]