Skip to content

jeraldlyh/smu-cs202-push-relabel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Max Flow Algorithm (Push-Relabel)

Push relabel is an algorithm that computes maximum flow in a flow network. It's considered one of the most efficient maximum flow algorithms that is able to achieve O(V^E) time complexity which is asymptopically more efficient than O(VE^2) Edmonds-Karp algorithm that adopts breadth-first search (BFS). (Source)

Visualization

Debug Visualizer is used in this demonstration to better visualize the underlying implementation and data structure of Push-Relabel algorithm. Vertices are displayed with labels (Height : Excess Flow)

Graph Color Legend

  • Red - Adjacent vertex that's selected to receive excess flow
  • Light Gray - Vertex that's performing relabel
  • Light Blue - Normal vertex in the graph
  • Light Green - Currently selected vertex
  • Light Yellow - Adjacent vertices of the currently selected vertex
  • Light Pink - Source vertex
  • Orange - Sink vertex

Demo Demo

Setup

Since this application relies heavily on Debug Visualizer, breakpoints are required to be set in order to enter debug mode and notice what happens in each step of the algorithm.

Breakpoints

  • Line 235 - Selects the destination vertex
  • Line 237 - Shows which vertex has been selected with its adjacent vertices
  • Line 288 - Shows which vertex has performed relabel to increase its height
  • Line 303 - Reflects the changes of the graphs till none of the vertices have excess flow
  • Line 307 - Shows which node is selected for relabeling
  • Line 310 - Shows the current state of the graph prior to relabeling
  • Line 358 - Shows the final max flow network graph with its corresponding residual graph

Steps to Replicate

  1. Install Debug Visualizer
  2. git clone https://github.com/jeraldlyh/smu-cs202-push-relabel
  3. Select max_flow.py
  4. Set the respective breakpoints as shown in the setup
  5. Ctrl + Shift + P -> Debug: Start Debugging
  6. Ctrl + Shift + P -> Debug Visualizer: New View
  7. Enter GRAPH into input box
  8. Ctrl + Shift + P -> Debug Visualizer: New View
  9. Enter RESIDUAL_GRAPH into input box
  10. Shift + F10 to reflect changes in the graph

Contributors