开发者

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 trie开发者_开发技巧d to change the algorithm, with no success, can you guys help?

Thank you


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


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜