Open In App

Introduction to Push Relabel Algorithm

Last Updated : 06 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Given a graph which represents a flow network where every edge has a capacity. Also given two vertices source ‘s’ and sink ‘t’ in the graph, find the maximum possible flow from s to t with following constraints: 

  1. Flow on an edge doesn’t exceed the given capacity of the edge. 
  2. Incoming flow is equal to outgoing flow for every vertex except s and t. 

For example, consider the following graph from CLRS book.

 ford_fulkerson1 

The maximum possible flow in the above graph is 23. 

ford_fulkerson2 

We have discussed Ford Fulkerson Algorithm that uses augmenting path for computing maximum flow.  

Push-Relabel Algorithm

Push-Relabel approach is the more efficient than Ford-Fulkerson algorithm. In this post, Goldberg’s “generic” maximum-flow algorithm is discussed that runs in O(V2E) time. This time complexity is better than O(E2V) which is time complexity of Edmond-Karp algorithm (a BFS based implementation of Ford-Fulkerson). There exist a push-relabel approach based algorithm that works in O(V3) which is even better than the one discussed here. 

Similarities with Ford Fulkerson

  • Like Ford-Fulkerson, Push-Relabel also works on Residual Graph (Residual Graph of a flow network is a graph which indicates additional possible flow. If there is a path from source to sink in residual graph, then it is possible to add flow).

Differences with Ford Fulkerson

  • Push-relabel algorithm works in a more localized. Rather than examining the entire residual network to find an augmenting path, push-relabel algorithms work on one vertex at a time (Source : CLRS Book).
  • In Ford-Fulkerson, net difference between total outflow and total inflow for every vertex (Except source and sink) is maintained 0. Push-Relabel algorithm allows inflow to exceed the outflow before reaching the final flow. In final flow, the net difference is 0 for all except source and sink.
  • Time complexity wise more efficient.

The intuition behind the push-relabel algorithm (considering a fluid flow problem) is that we consider edges as water pipes and nodes are joints. The source is considered to be at the highest level and it sends water to all adjacent nodes. Once a node has excess water, it pushes water to a smaller height node. If water gets locally trapped at a vertex, the vertex is Relabeled which means its height is increased. Following are some useful facts to consider before we proceed to algorithm.

  • Each vertex has associated to it a height variable and a Excess Flow. Height is used to determine whether a vertex can push flow to an adjacent or not (A vertex can push flow only to a smaller height vertex). Excess flow is the difference of total flow coming into the vertex minus the total flow going out of the vertex.
     Excess Flow of u = Total Inflow to u - 
                        Total Outflow from u
  • Like Ford Fulkerson. each edge has associated to it a flow (which indicates current flow) and a capacity

Following are abstract steps of complete algorithm.

Push-Relabel Algorithm 
1) Initialize PreFlow : Initialize Flows 
   and Heights 

2) While it is possible to perform a Push() or 
   Relabel() on a vertex
   // Or while there is a vertex that has excess flow
           Do Push() or Relabel()

// At this point all vertices have Excess Flow as 0 (Except source
// and sink)
3) Return flow.

  There are three main operations in Push-Relabel Algorithm

1. Initialize PreFlow() It initializes heights and flows of all vertices.

Preflow() 
1) Initialize height and flow of every vertex as 0.
2) Initialize height of source vertex equal to total 
   number of vertices in graph.
3) Initialize flow of every edge as 0.
4) For all vertices adjacent to source s, flow and  
   excess flow is equal to capacity initially.

2. Push() is used to make the flow from a node which has excess flow. If a vertex has excess flow and there is an adjacent with smaller height (in residual graph), we push the flow from the vertex to the adjacent with lower height. The amount of pushed flow through the pipe (edge) is equal to the minimum of excess flow and capacity of edge.

3. Relabel() operation is used when a vertex has excess flow and none of its adjacent is at lower height. We basically increase height of the vertex so that we can perform push(). To increase height, we pick the minimum height adjacent (in residual graph, i.e., an adjacent to whom we can add flow) and add 1 to it.

Note that above operations are performed on residual graph (like Ford-Fulkerson). 

Illustration: 

Before we proceed to below example, we need to make sure that we understand residual graph (See this for more details of residual graph). Residual graph is different from graphs shown. 
Whenever we push or add a flow from a vertex u to v, we do following updates in residual graph : 

  1. We subtract the flow from capacity of edge from u to v. If capacity of an edge becomes 0, then the edge no longer exists in residual graph. 
  2. We add flow to the capacity of edge from v to u.
For example, consider two vertices u an v.

In original graph
        3/10
   u ---------> v
    3 is current flow from u to v and
    10 is capacity of edge from u to v.

In residual Graph, there are two edges corresponding
to one edge shown above.
         7
   u ---------> v

         3
   u <--------- v 

1. Initial given flow graph.

 pushrelabel1

2. After PreFlow operation. In residual graph, there is an edge from A to S with capacity 3 and no edge from S to A.

pushrelabel2

3. The highlighted vertex is relabeled (height becomes 1) as it has excess flow and there is no adjacent with smaller height. The new height is equal to minimum of heights of adjacent plus 1.  In residual graph, there are two adjacent of vertex A, one is S and other is B.  Height of S is 4 and height of B is 0.  Minimum of these two heights is 0. We take the minimum and add 1 to it. 

pushrelabel3

4. The highlighted vertex has excess flow and there is an adjacent with lower height, so push() happens. Excess flow of vertex A is 2 and capacity of edge (A, B) is 1. Therefore, the amount of pushed flow is 1 (minimum of two values).

 pushrelabel4

5. The highlighted vertex is relabeled (height becomes 1) as it has excess flow and there is no adjacent with smaller height. 

pushrelabel5

6. The highlighted vertex has excess flow and there is an adjacent with lower height, so flow() is pushed from B to T. 

pushrelabel6

7. The highlighted vertex is relabeled (height becomes 5) as it has excess flow and there is no adjacent with smaller height. 

pushrelabel7

8. The highlighted vertex has excess flow and there is an adjacent with lower height, so push() happens. 

pushrelabel8

9. The highlighted vertex is relabeled (height is increased by 1) as it has excess flow and there is no adjacent with smaller height. 

pushrelabel9



Previous Article
Next Article

Similar Reads

FIFO Push Relabel Algorithm
The push–relabel algorithm (alternatively, pre flow–push algorithm) is an algorithm for computing maximum flows in a flow network. Push-relabel algorithms work in a more localized manner than the Ford Fulkerson method. Rather than examine the entire residual network to find an augmenting path, push-relabel algorithms work on one vertex at a time, l
15+ min read
Push Relabel Algorithm | Set 2 (Implementation)
We strongly recommend to refer below article before moving on to this article. Push Relabel Algorithm | Set 1 (Introduction and Illustration) Problem Statement:  Given a graph that represents a flow network where every edge has a capacity. Also given two vertices source ‘s’ and sink ‘t’ in the graph, find the maximum possible flow from s to t with
15+ min read
Relabel-to-front Algorithm
The relabel-to-front algorithm is used to find the maximum flow in the network. The relabel-to-front algorithm is more efficient than the generic push-relabel method. In the push-relabel method, we can apply the basic operations of push and relabel in any order. The relabel-to-front algorithm chooses the order carefully and manages the network data
5 min read
Check if the given push and pop sequences of Stack is valid or not
Given push[] and pop[] sequences with distinct values. The task is to check if this could have been the result of a sequence of push and pop operations on an initially empty stack. Return "True" if it otherwise returns "False". Examples: Input: pushed = { 1, 2, 3, 4, 5 }, popped = { 4, 5, 3, 2, 1 }Output: TrueFollowing sequence can be performed:pus
11 min read
Minimum Cost To set Digital Clock Timer with given movement and push cost
Given integers A, B and N. The task is to minimize the cost to set N seconds in a digital clock where time is represented in the following format: at most 99 minutes and 99 secondsat least 1 secondThe first two digits represent minutes and the last two minutes represent seconds.It prepends 0 if less than 4 digits are pressed to set time A is the co
14 min read
What is the time efficiency of the push(), pop(), isEmpty() and peek() operations of Stacks?
Stack is a linear data structure that follows the LIFO (last in first out) order i.e., the data are entered from one end and while they are removed, they will be removed from the same end. The few most performed operations in a stack are: push()pop()isEmpty()peek()Now let us check the time efficiency of the operations: 1. push(): This function is c
2 min read
Edge Relaxation Property for Dijkstra’s Algorithm and Bellman Ford's Algorithm
In the field of graph theory, various shortest path algorithms especially Dijkstra’s algorithm and Bellmann-Ford’s algorithm repeatedly employ the use of the technique called Edge Relaxation. The idea of relaxation is the same in both algorithms and it is by understanding, the 'Relaxation property' we can fully grasp the working of the two algorith
4 min read
Difference between Greedy Algorithm and Divide and Conquer Algorithm
Greedy algorithm and divide and conquer algorithm are two common algorithmic paradigms used to solve problems. The main difference between them lies in their approach to solving problems. Greedy Algorithm:The greedy algorithm is an algorithmic paradigm that follows the problem-solving heuristic of making the locally optimal choice at each stage wit
3 min read
Z algorithm (Linear time pattern searching Algorithm)
This algorithm finds all occurrences of a pattern in a text in linear time. Let length of text be n and of pattern be m, then total time taken is O(m + n) with linear space complexity. Now we can see that both time and space complexity is same as KMP algorithm but this algorithm is Simpler to understand.In this algorithm, we construct a Z array. Wh
13 min read
Algorithm Library | C++ Magicians STL Algorithm
For all those who aspire to excel in competitive programming, only having a knowledge about containers of STL is of less use till one is not aware what all STL has to offer. STL has an ocean of algorithms, for all &lt; algorithm &gt; library functions : Refer here.Some of the most used algorithms on vectors and most useful one's in Competitive Prog
7 min read
Article Tags :
Practice Tags :