Push–relabel maximum flow algorithm

In mathematical optimization, the push–relabel algorithm (alternatively, preflow–push algorithm) is an algorithm for computing maximum flows in a flow network. The name "push–relabel" comes from the two basic operations used in the algorithm. Throughout its execution, the algorithm maintains a "preflow" and gradually converts it into a maximum flow by moving flow locally between neighboring nodes using push operations under the guidance of an admissible network maintained by relabel operations. In comparison, the Ford–Fulkerson algorithm performs global augmentations that send flow following paths from the source all the way to the sink.

The push–relabel algorithm is considered one of the most efficient maximum flow algorithms. The generic algorithm has a strongly polynomial $O(V^{ 2}E)$ time complexity, which is asymptotically more efficient than the $O(VE^{ 2})$ Edmonds–Karp algorithm. Specific variants of the algorithms achieve even lower time complexities. The variant based on the highest label node selection rule has $O(V^{ 2}√E)$ time complexity and is generally regarded as the benchmark for maximum flow algorithms. Subcubic $O(VElog(V^{ 2}/E))$ time complexity can be achieved using dynamic trees, although in practice it is less efficient.

The push–relabel algorithm has been extended to compute minimum cost flows. The idea of distance labels has led to a more efficient augmenting path algorithm, which in turn can be incorporated back into the push–relabel algorithm to create a variant with even higher empirical performance.

History
The concept of a preflow was originally designed by Alexander V. Karzanov and was published in 1974 in Soviet Mathematical Dokladi 15. This pre-flow algorithm also used a push operation; however, it used distances in the auxiliary network to determine where to push the flow instead of a labeling system.

The push-relabel algorithm was designed by Andrew V. Goldberg and Robert Tarjan. The algorithm was initially presented in November 1986 in STOC '86: Proceedings of the eighteenth annual ACM symposium on Theory of computing, and then officially in October 1988 as an article in the Journal of the ACM. Both papers detail a generic form of the algorithm terminating in $O(V^{ 2}E)$ along with a $O(V^{ 3})$ sequential implementation, a $O(VE log(V^{ 2}/E))$ implementation using dynamic trees, and parallel/distributed implementation. As explained in, Goldberg-Tarjan introduced distance labels by incorporating them into the parallel maximum flow algorithm of Yossi Shiloach and Uzi Vishkin.

Definitions and notations
Let: and
 * $G = (V, E)$ be a network with capacity function $c: V × V → $\mathbb{R}$_{∞}$,
 * $F = (G, c, s, t)$ a flow network, where $s ∈ V$ and $t ∈ V$ are chosen source and sink vertices respectively,
 * $f : V × V → $\mathbb{R}$$ denote a pre-flow in $F$,
 * $x_{f} : V → $\mathbb{R}$$ denote the excess function with respect to the flow $f$, defined by $x_{f} (u) = Σ_{v ∈ V} f (v, u) − Σ_{v ∈ V} f (u, v)$,
 * $c_{f} : V × V → $\mathbb{R}$_{∞}$ denote the residual capacity function with respect to the flow $f$, defined by $c_{f} (e) = c(e) − f (e)$,
 * $E_{f} ⊂ E$ being the edges where $f < c$,
 * $G_{f} (V, E_{f })$ denote the residual network of $G$ with respect to the flow $f$.

The push–relabel algorithm uses a nonnegative integer valid labeling function which makes use of distance labels, or heights, on nodes to determine which arcs should be selected for the push operation. This labeling function is denoted by $𝓁 : V → $\mathbb{N}$$. This function must satisfy the following conditions in order to be considered valid:


 * Valid labeling:
 * $𝓁(u) ≤ 𝓁(v) + 1$ for all $(u, v) ∈ E_{f}$
 * Source condition:
 * Sink conservation:
 * Sink conservation:

In the algorithm, the label values of $s$ and $t$ are fixed. $𝓁(s) = | V |$ is a lower bound of the unweighted distance from $u$ to $t$ in $𝓁(t) = 0$ if $t$ is reachable from $u$. If $u$ has been disconnected from $t$, then $𝓁(u)$ is a lower bound of the unweighted distance from $u$ to $s$. As a result, if a valid labeling function exists, there are no $G_{f}$ paths in $𝓁(u) − | V |$ because no such paths can be longer than $s-t$.

An arc $G_{f}$ is called admissible if $| V | − 1$. The admissible network $(u, v) ∈ E_{f}$ is composed of the set of arcs $𝓁(u) = 𝓁(v) + 1$  that are admissible. The admissible network is acyclic.

For a fixed flow $G̃_{f} (V, Ẽ_{f} )$, a vertex $e ∈ E_{f}$ is called active if it has positive excess with respect to $f$, i.e., $v ∉ {s, t}$.

Initialization
The algorithm starts by creating a residual graph, initializing the preflow values to zero and performing a set of saturating push operations on residual arcs $f$ exiting the source, where $x_{f} (u) > 0$. Similarly, the labels are initialized such that the label at the source is the number of nodes in the graph, $(s, v)$, and all other nodes are given a label of zero. Once the initialization is complete the algorithm repeatedly performs either the push or relabel operations against active nodes until no applicable operation can be performed.

Push
The push operation applies on an admissible out-arc $v ∈ V \ (s)$ of an active node $u$ in $𝓁(s) = | V |$. It moves $(u, v)$ units of flow from $u$ to $v$.

push(u, v): assert xf[u] > 0 and 𝓁[u] == 𝓁[v] + 1 Δ = min(xf[u], c[u][v] - f[u][v]) f[u][v] += Δ f[v][u] -= Δ xf[u] -= Δ xf[v] += Δ

A push operation that causes $G_{f}$ to reach $min(x_{f} (u), c_{f} (u,v))$ is called a saturating push since it uses up all the available capacity of the residual arc. Otherwise, all of the excess at the node is pushed across the residual arc. This is called an unsaturating or non-saturating push.

Relabel
The relabel operation applies on an active node $u$ which is neither the source nor the sink without any admissible out-arcs in $f (u, v)$. It modifies $c(u, v)$ to be the minimum value such that an admissible out-arc is created. Note that this always increases $G_{f}$ and never creates a steep arc, which is an arc $𝓁(u)$ such that $𝓁(u)$, and $(u, v)$.

relabel(u): assert xf[u] > 0 and 𝓁[u] <= 𝓁[v] for all v such that cf[u][v] > 0 𝓁[u] = 1 + min(𝓁[v] for all v such that cf[u][v] > 0)

Effects of push and relabel
After a push or relabel operation, $c_{f} (u, v) > 0$ remains a valid labeling function with respect to $f$.

For a push operation on an admissible arc $𝓁(u) > 𝓁(v) + 1$, it may add an arc $𝓁$ to $(u, v)$, where $(v, u)$; it may also remove the arc $E_{f}$ from $𝓁(v) = 𝓁(u) − 1 ≤ 𝓁(u) + 1$, where it effectively removes the constraint $(u, v)$.

To see that a relabel operation on node $u$ preserves the validity of $E_{f}$, notice that this is trivially guaranteed by definition for the out-arcs of u in $𝓁(u) ≤ 𝓁(v) + 1$. For the in-arcs of $u$ in $𝓁(u)$, the increased $G_{f}$ can only satisfy the constraints less tightly, not violate them.

The generic push–relabel algorithm
The generic push–relabel algorithm is used as a proof of concept only and does not contain implementation details on how to select an active node for the push and relabel operations. This generic version of the algorithm will terminate in $G_{f}$.

Since $𝓁(u)$, $O(V^{2}E)$, and there are no paths longer than $𝓁(s) = | V |$ in $𝓁(t) = 0$, in order for $| V | − 1$ to satisfy the valid labeling condition $s$ must be disconnected from $t$. At initialisation, the algorithm fulfills this requirement by creating a pre-flow $f$ that saturates all out-arcs of $s$, after which $G_{f}$ is trivially valid for all $𝓁(s)$. After initialisation, the algorithm repeatedly executes an applicable push or relabel operation until no such operations apply, at which point the pre-flow has been converted into a maximum flow.

generic-push-relabel(G, c, s, t): create a pre-flow f that saturates all out-arcs of s    let 𝓁[s] = |V| let 𝓁[v] = 0 for all v ∈ V \ {s} while there is an applicable push or relabel operation do execute the operation

Correctness
The algorithm maintains the condition that $𝓁(v) = 0$ is a valid labeling during its execution. This can be proven true by examining the effects of the push and relabel operations on the label function $v ∈ V \ (s, t)$. The relabel operation increases the label value by the associated minimum plus one which will always satisfy the $𝓁$ constraint. The push operation can send flow from $u$ to $v$ if $𝓁$. This may add $𝓁(u) ≤ 𝓁(v) + 1$ to $𝓁(u) = 𝓁(v) + 1$ and may delete $(v, u)$ from $G_{f}$. The addition of $(u, v)$ to $G_{f}$ will not affect the valid labeling since $(v, u)$. The deletion of $G_{f}$ from $𝓁(v) = 𝓁(u) − 1$ removes the corresponding constraint since the valid labeling property $(u, v)$ only applies to residual arcs in $G_{f}$.

If a preflow $f$ and a valid labeling $𝓁(u) ≤ 𝓁(v) + 1$ for $f$ exists then there is no augmenting path from $s$ to $t$ in the residual graph $G_{f}$. This can be proven by contradiction based on inequalities which arise in the labeling function when supposing that an augmenting path does exist. If the algorithm terminates, then all nodes in $𝓁$ are not active. This means all $G_{f}$ have no excess flow, and with no excess the preflow $f$ obeys the flow conservation constraint and can be considered a normal flow. This flow is the maximum flow according to the max-flow min-cut theorem since there is no augmenting path from $s$ to $t$.

Therefore, the algorithm will return the maximum flow upon termination.

Time complexity
In order to bound the time complexity of the algorithm, we must analyze the number of push and relabel operations which occur within the main loop. The numbers of relabel, saturating push and nonsaturating push operations are analyzed separately.

In the algorithm, the relabel operation can be performed at most $V \ (s, t)$ times. This is because the labeling $v ∈ V \ (s, t)$ value for any node u can never decrease, and the maximum label value is at most $(2| V | − 1)(| V | − 2) < 2| V |^{2}$ for all nodes. This means the relabel operation could potentially be performed $𝓁(u)$ times for all nodes $2| V | − 1$ (i.e. $2| V | − 1$). This results in a bound of $V \ (s, t)$ for the relabel operation.

Each saturating push on an admissible arc $| V | − 2$ removes the arc from $O(V^{ 2})$. For the arc to be reinserted into $(u, v)$ for another saturating push, $v$ must first be relabeled, followed by a push on the arc $G_{f}$, then $u$ must be relabeled. In the process, $G_{f}$ increases by at least two. Therefore, there are $(v, u)$ saturating pushes on $𝓁(u)$, and the total number of saturating pushes is at most $O(V)$. This results in a time bound of $(u, v)$ for the saturating push operations.

Bounding the number of nonsaturating pushes can be achieved via a potential argument. We use the potential function $2| V || E |$ (i.e. $O(VE)$ is the sum of the labels of all active nodes). It is obvious that $Φ = Σ_{[u ∈ V ∧ x_{f} (u) > 0]} 𝓁(u)$ is $Φ$ initially and stays nonnegative throughout the execution of the algorithm. Both relabels and saturating pushes can increase $Φ$. However, the value of $0$ must be equal to 0 at termination since there cannot be any remaining active nodes at the end of the algorithm's execution. This means that over the execution of the algorithm, the nonsaturating pushes must make up the difference of the relabel and saturating push operations in order for $Φ$ to terminate with a value of 0. The relabel operation can increase $Φ$ by at most $Φ$. A saturating push on $Φ$ activates $v$ if it was inactive before the push, increasing $(2| V | − 1)(| V | − 2)$ by at most $(u, v)$. Hence, the total contribution of all saturating pushes operations to $Φ$ is at most $2| V | − 1$. A nonsaturating push on $Φ$ always deactivates $u$, but it can also activate $v$ as in a saturating push. As a result, it decreases $(2| V | − 1)(2| V || E |)$ by at least $(u, v)$. Since relabels and saturating pushes increase $Φ$, the total number of nonsaturating pushes must make up the difference of $𝓁(u) − 𝓁(v) = 1$. This results in a time bound of $Φ$ for the nonsaturating push operations.

In sum, the algorithm executes $(2| V | − 1)(| V | − 2) + (2| V | − 1)(2| V || E |) ≤ 4| V |^{2}| E |$ relabels, $O(V^{ 2}E)$ saturating pushes and $O(V^{ 2})$ nonsaturating pushes. Data structures can be designed to pick and execute an applicable operation in $O(VE)$ time. Therefore, the time complexity of the algorithm is $O(V^{ 2}E)$.

Example
The following is a sample execution of the generic push-relabel algorithm, as defined above, on the following simple network flow graph diagram.

In the example, the h and e values denote the label $O(1)$ and excess $O(V^{ 2}E)$, respectively, of the node during the execution of the algorithm. Each residual graph in the example only contains the residual arcs with a capacity larger than zero. Each residual graph may contain multiple iterations of the perform operation loop.

The example (but with initial flow of 0) can be run here interactively.

Practical implementations
While the generic push–relabel algorithm has $𝓁$ time complexity, efficient implementations achieve $x_{f}$ or lower time complexity by enforcing appropriate rules in selecting applicable push and relabel operations. The empirical performance can be further improved by heuristics.

"Current-arc" data structure and discharge operation
The "current-arc" data structure is a mechanism for visiting the in- and out-neighbors of a node in the flow network in a static circular order. If a singly linked list of neighbors is created for a node, the data structure can be as simple as a pointer into the list that steps through the list and rewinds to the head when it runs off the end.

Based on the "current-arc" data structure, the discharge operation can be defined. A discharge operation applies on an active node and repeatedly pushes flow from the node until it becomes inactive, relabeling it as necessary to create admissible arcs in the process.

discharge(u): while xf[u] > 0 do if current-arc[u] has run off the end of neighbors[u] then relabel(u) rewind current-arc[u] else let (u, v) = current-arc[u] if (u, v) is admissible then push(u, v)            let current-arc[u] point to the next neighbor of u Finding the next admissible edge to push on has $$O(1)$$ amortized complexity. The current-arc pointer only moves to the next neighbor when the edge to the current neighbor is saturated or non-admissible, and neither of these two properties can change until the active node $$u$$ is relabelled. Therefore, when the pointer runs off, there are no admissible unsaturated edges and we have to relabel the active node $$u$$, so having moved the pointer $$O(V)$$ times is paid for by the $$O(V)$$ relabel operation.

Active node selection rules
Definition of the discharge operation reduces the push–relabel algorithm to repeatedly selecting an active node to discharge. Depending on the selection rule, the algorithm exhibits different time complexities. For the sake of brevity, we ignore $s$ and $a$ when referring to the nodes in the following discussion.

FIFO selection rule
The FIFO push–relabel algorithm organizes the active nodes into a queue. The initial active nodes can be inserted in arbitrary order. The algorithm always removes the node at the front of the queue for discharging. Whenever an inactive node becomes active, it is appended to the back of the queue.

The algorithm has $O(V^{ 2}E)$ time complexity.

Relabel-to-front selection rule
The relabel-to-front push–relabel algorithm organizes all nodes into a linked list and maintains the invariant that the list is topologically sorted with respect to the admissible network. The algorithm scans the list from front to back and performs a discharge operation on the current node if it is active. If the node is relabeled, it is moved to the front of the list, and the scan is restarted from the front.

The algorithm also has $O(V^{ 3})$ time complexity.

Highest label selection rule
The highest-label push–relabel algorithm organizes all nodes into buckets indexed by their labels. The algorithm always selects an active node with the largest label to discharge.

The algorithm has $O(V^{ 3})$ time complexity. If the lowest-label selection rule is used instead, the time complexity becomes $O(V^{ 3})$.

Implementation techniques
Although in the description of the generic push–relabel algorithm above, $O(V^{ 2}√E)$ is set to zero for each node u other than $t$ and $a$ at the beginning, it is preferable to perform a backward breadth-first search from $b$ to compute exact labels.

The algorithm is typically separated into two phases. Phase one computes a maximum pre-flow by discharging only active nodes whose labels are below $d$. Phase two converts the maximum preflow into a maximum flow by returning excess flow that cannot reach $a$ to $a$. It can be shown that phase two has $O(V^{ 2}E)$ time complexity regardless of the order of push and relabel operations and is therefore dominated by phase one. Alternatively, it can be implemented using flow decomposition.

Heuristics are crucial to improving the empirical performance of the algorithm. Two commonly used heuristics are the gap heuristic and the global relabeling heuristic. The gap heuristic detects gaps in the labeling function. If there is a label 0 < 𝓁' < for which there is no node $s$ such that $𝓁(u)$, then any node $a$ with $O(VE)$ has been disconnected from $b$ and can be relabeled to $𝓁(u) = 𝓁'$ immediately. The global relabeling heuristic periodically performs backward breadth-first search from $t$ in $𝓁' < 𝓁(u) < | V |$ to compute the exact labels of the nodes. Both heuristics skip unhelpful relabel operations, which are a bottleneck of the algorithm and contribute to the ineffectiveness of dynamic trees.