5

We're given an unweighted undirected graph G = (V, E) where |V| <= 40,000 and |E| <= 106. We're also given four vertices a, b, a', b'. Is there a way to find two node-disjoint paths a -> a' and b -> b' such that the sum of their lengths is minimum?
My first thought was to first find the shortest path a -> a', delete it from the graph, and then find the shortest path b -> b'. I don't think this greedy approach would work.

Note: Throughout the application, a and b are fixed, while a' and b' change at each query, so a solution that uses precomputing in order to provide efficient querying would be preferable. Note also that only the minimum sum of lengths is needed, not the actual paths.

Any help, ideas, or suggestions would be extremely appreciated. Thanks a lot in advance!

Chris
  • 26,544
  • 5
  • 58
  • 71
  • 1
    it wont work because the shortest path a->a' might pass through a node that is the only way to reach b from b'. as a pre processing stage you could store the minimal distance of each node in the graph from a and b – Gir Aug 11 '12 at 15:07
  • @Gir Yes, that does make sense. – Chris Aug 11 '12 at 15:08
  • Probably not that helpful, but I'd point out that it is possible for there to be NO solution, even if there is a path between any pair of nodes (imagine 2 graphs, one containing a & b, the other a' & b', and one extra node which is the only way to get between the two graphs). – Scott Hunter Aug 11 '12 at 15:15
  • 1
    There is a book *Survivable Networks: Algorithms for Diverse Routing*, which has done a lot great introduction and solutions for these problems. Here is [a link](http://books.google.com.hk/books?hl=en&lr=&id=SIkfR0lAN1wC&oi=fnd&pg=PR11&ots=LQJxh2ghfa&sig=9PjKDkP0SaO6_rcMbHZ_bQBR5O8&redir_esc=y&hl=zh-CN&sourceid=cndr#v=onepage&q&f=false) on google book for it. – JackeyLyu Mar 18 '13 at 09:14

2 Answers2

12

This may be reduced to the shortest edge-disjoint paths problem:

  1. (Optionally) Collapse all chains in the graph into single edges. This produces a smaller weighted graph (if there are any chains in the original graph).
  2. Transform undirected graph into digraph by substituting each edge by a pair of directed edges.
  3. Split each node into the pair of nodes: one with only incoming edges of the original node, other with only its outgoing edges. Connect each pair of nodes with a single directed edge. (For example, node c in the diagram below should be split into c1 and c2; now every path containing node c in the original graph should pass through the edge c1 -> c2 in the transformed graph; here x and y represent all nodes in the graph except node c).

enter image description here enter image description here enter image description here

Now if a = b or a' = b', you get exactly the same problem as in your previous question (which is Minimum-cost flow problem and may be solved by assigning flow capacity for each edge equal to 1, then searching for a minimum-cost flow between a and b with flow=2). If a != b, you just create a common source node and connect both a and b to it. If a' != b', do the same with a common destination node.

But if a != b and a' != b', minimum-cost flow problem is not applicable. Instead this problem may be solved as Multi-commodity flow problem.


My previous (incorrect) solution was to connect both pairs of (a, b) and (a', b') to common source/destination nodes, then to find a minimum-cost flow. Following graph is a counter-example for this approach:

enter image description here

Community
  • 1
  • 1
Evgeny Kluev
  • 24,287
  • 7
  • 55
  • 98
0

How about this? Do BFS (breadth first search) traversal from a1 -> a2 and remove the path and compute BFS b1 -> b2. Now reset the graph and do same with b1->b2 first and remove path and then a1->a2. Whatever sum is minumum is the answer.

Ankush
  • 2,454
  • 2
  • 21
  • 27