3

Give two vertices u and v in G = (V,E) and a positive integer k, describe an algorithm to decide if there exists a k edge disjoint paths from u to v. If the answer to the decision problem is yes, describe how to compute a set of k edge disjoint paths.

Solution : Run max flow from u to v (giving all edges in the Graph G a weight of 1 so that one edge can be part of only one path from u to v) and get the value of flow. If the value of the flow is k then we have the answer to the decision problem as yes.

Now for finding all such paths find the min cut by doing BFS from u and hence I will have the partition of vertices which will separate the vertices into 2 sets one on each side of min cut.

Then do I need to again do a DFS from u to v looking for all the paths which have only these vertices which are there in the two partition set that I got from the min cut.

Or is there any other cleaner way ? to get all the k edge disjoint paths.

Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71
Ankit Mishra
  • 409
  • 2
  • 5
  • 17

1 Answers1

4

Once you have the flow you can extract the edge disjoint paths by following the flow.

The start node will have a flow of k leaving u along k edges.

For each of these edges you can keep moving in the direction of outgoing flow to extract the path until you reach v. All you need to do is to mark the edges you have already used to avoid duplicating edges.

Repeat for each of the k units of flow leaving u to extract all k paths.

Pseudocode

repeat k times:
  set x to start node
  set path to []
  while x is not equal to end node:
      find a edge from x which has flow>0, let y be the vertex at the far end
      decrease flow from x->y by 1 unit
      append y to path
      set x equal to y
  print path
Peter de Rivaz
  • 33,126
  • 4
  • 46
  • 75
  • Hi! I'm trying to solve this problem and everything I find about this subject has a 'hole' where I can't understand. So, in which graph should I follow the flow? The residual graph from the max-flow or the original graph? How do I treat cycles? Thanks in advance. – Marco Aug 09 '17 at 21:10
  • 1
    I've added some pseudocode to try and make things clearer. You are following edges in a graph where edges exist where the flow is greater than 0. As you extract paths, the flow decreases, so edges will gradually disappear until at the end all edges have gone (assuming no loops in the flow graph). Normal max-flow algorithms will not generate loops in the flow graph because they search for simple augmenting paths. (Simple means vertices are not repeated in the path) – Peter de Rivaz Aug 09 '17 at 22:11
  • Peter, sorry for the extended delay. I was thinking in your answer and trying to implement it and I had to travel in the meanwhile. Suppose I'm using the Edmonds-Karp approach to get the max-flow, meaning that for every augmenting path I find, I will change the direction of every edge `(u, v)` in it (or increase the capacity of `(v, u)` by 1), so its possible that I find two augmenting paths with the same edge (I even found an instance where this happens). How do I detect these edges with flow > 0 during / after the algorithm? Thanks again and sorry for the inconvenience. – Marco Aug 16 '17 at 11:48
  • 1
    @Marco You need to turn the output from the Edmonds-Karp into a true flow graph by computing the net flow along each edge. This net flow will either by 1,0,or -1 because your edges all have weight 1. Convert +1 flow to flow(u,v)=1, and -1 flow to flow(v,u)=1. At this point you should be able to use the algorithm I described above. If this isn't clear, it may help if you can post your Edmonds-Karp code so I can describe this process based on the variables in your program. – Peter de Rivaz Aug 16 '17 at 13:23
  • It finally worked, thanks! Just to clarify the entire algorithm if anyone runs into the same problem: 1) run the Edmonds-Karp in your graph, keeping the augmenting paths and their capacity. 2) create a new graph, with arc capacities = 0, it will be the graph containing the true flow (let's call it true graph). 3) for each arc `(v, u)` in each augmenting path, sum the capacity of the path to `(v, u)` and subtract it from `(u, v)`, both on the true graph. 4) remove all arcs with capacity <= 0 from the true graph. 5) run the code from Peter's answer on the 'true' graph. – Marco Aug 16 '17 at 18:32