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

3

10

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

Mingle answered 21/3, 2011 at 16:15 Comment(0)
P
4

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.)

Pusher answered 21/3, 2011 at 17:4 Comment(2)
can u explain the meanings of the numbers in the F nXn matrix?and how do I use them exactly?Mingle
@ciochPep: The matrix F gives the flow across each edge in the graph to achieve maximum flow -- essentially it's this that the Edmonds Karp algorithm is designed to compute. This also makes calculating the residual graph easy: it's simply the difference of the matrix C - the matrix F.Pusher
P
3

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!

Perjure answered 31/7, 2012 at 23:1 Comment(0)
C
2

If you already know the maximal flow, then the minimal cut is (S, T), where S is the set of vertices reachable from the source in the residual network, T is the complementary set. Edges that connect a vertex from S and a vertex from T belong to the cut.

Cyclosis answered 21/3, 2011 at 16:48 Comment(4)
I only know the min-cut value...not the setMingle
@Mingle You said you implemented Edmonds-Karp? It finds the flow together with the value.Cyclosis
can u explain the meanings of the numbers in the F nXn matrix?and how do I use them exactly?Mingle
@Mingle F[i,j] iss the flow along the edge from i to j. In a real algorithm it's probably represented as a list of edges, not a matrixCyclosis

© 2022 - 2024 — McMap. All rights reserved.