Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the cut-set using the Edmonds–Karp algorithm?

I implemented the Edmonds–Karp algorithm using the Pseudocode that I found in the Edmonds–Karp algorithm wiki page: http://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm

It works great, yet the algorithm output is the max flow value(min cut value), I need to the list of edges that this cut contains

I tried to change the algorithm, with no success, can you guys help?

Thank you

like image 365
ciochPep Avatar asked Mar 21 '11 16:03

ciochPep


People also ask

How does Edmonds-Karp algorithm work?

Edmonds-Karp algorithmThe algorithm runs in O ( V E 2 ) time, even for irrational capacities. The intuition is, that every time we find an augmenting path one of the edges becomes saturated, and the distance from the edge to will be longer if it appears later again in an augmenting path.

Does Edmonds-Karp use BFS?

The Edmonds-Karp algorithm is a modified form of the Ford-Fulkerson algorithm. The difference Is that Ford-Fulkerson uses the DFS approach and Edmonds-Karp uses the BFS approach. The time complexity of this algorithm Is O(E^2) for irrational capacities and maximum longest path from source to sink.

Why is Edmonds-Karp better than Ford-Fulkerson?

Edmonds-Karp differs from Ford-Fulkerson in that it chooses the next augmenting path using breadth-first search (bfs). So, if there are multiple augmenting paths to choose from, Edmonds-Karp will be sure to choose the shortest augmenting path from the source to the sink.

What is the complexity of Ford-Fulkerson's algorithm?

Time Complexity: Time complexity of the above algorithm is O(max_flow * E). We run a loop while there is an augmenting path. In worst case, we may add 1 unit flow in every iteration. Therefore the time complexity becomes O(max_flow * E).


2 Answers

If you already have the flow, then compute the residual graph. Then do a depth first search from the source (or breadth first search, I don't think it matters), to compute the vertices in one half of the cut (S). The remaining vertices are in the other half of your cut, T.

This gives you your cut (S, T). If you specifically want the edges between S and T, you could iterate through all the edges, selecting the ones which connect S and T. (Though there may a be a more eleegant way to do this last part.)

like image 153
Rob Lachlan Avatar answered Sep 19 '22 19:09

Rob Lachlan


Here's some pointers to help clarify how to do this for anyone in the future.

  1. To find the S vertices, do a BFS (or DFS) search from source vertex, only following edges in which some capacity for flow is remaining. (In other words, the non-saturated edges). These ones by definition cannot be in the mincut.

  2. To find the T vertices perform a BFS (or DFS) search from the sink vertex, only connecting to vertices that were not already added to the S set. These can have residual flow, or could be fully saturated, it doesn't matter. Because you are performing BFS from the sink, you'll need to make sure you follow the opposite direction the edge is pointed if the graph is directed. NOTE: It's important to only include vertices that can be reached from the sink in your T set, otherwise you'll end up including edges in your min-cut that do not belong there. (This is what threw me for a long time.)

  3. Once you have these two sets of vertices you can then iterate over all the edges of the graph. Anyone that has a source node in S and a target node in T is part of your min-cut. It's important to note, though, that this is just one of many possible min-cuts. It's much more time intensive to find all the possible S-T min-cuts in a graph.

Hope this helps any future internet people trying to figure this out! Good luck!

like image 43
Patrick M Avatar answered Sep 20 '22 19:09

Patrick M