5

Given a weighted undirected graph G and two vertices a, b, we want to find two paths a -> b and b -> a such that they don't share any edge, and such that the sum of weights of edges in both paths is minimum. There can be up to 1,000 vertices, and up to 10,000 edges.

I had initially tried to come up with a dynamic programming approach, but couldn't find such. Any ideas/suggestions would be extremely appreciated.

Chris
  • 26,544
  • 5
  • 58
  • 71
  • Can weights be negative? – 6502 Aug 09 '12 at 10:10
  • If I have understood you question correctly. Then first check whether there exists two different paths for given pair of vertices which wont share any edge. If it exist then while walking from source to destination using dynamic programming and note all the edges and remove those edges from original graph G=(v,E) which reduces to G'(V,E') .Then while coming since graph G' is reduced try applying the dynamic programming to reach from destination to source... – Imposter Aug 09 '12 at 10:15
  • @6502 No, weights can't be negative. – Chris Aug 09 '12 at 10:16
  • @Imposter: that doesn't work. As a counter-example see http://raksy.dyndns.org/graph.png where there are two distinct paths (A345B and B12A) however if you start from A looking for a minimal path you end up with A12B and then there is no way for coming back. – 6502 Aug 09 '12 at 10:53
  • @6502: He said the graph is undirected. That said, I think what he's *trying* to say doesn't work due to Evgeny's counter-example below *(though I don't understand where dynamic programming comes into it...)* – BlueRaja - Danny Pflughoeft Aug 09 '12 at 15:50
  • @BlueRaja-DannyPflughoeft: Oh... sorry, I misread that as "unidirected" (like in unidirectional) that however for some reason is not an english word. – 6502 Aug 09 '12 at 16:12

1 Answers1

7

This is Minimum-cost flow problem. You can assign flow capacity for each edge equal to 1, then search for a minimum-cost flow between a and b with flow=2.


Someone may think that it is possible to use a simple algorithm to find shortest path from a to b, remove its edges from the graph, then find another shortest path.

This approach is not always optimal. For some graphs it gives a good approximation. For others it may give a very bad solution:

enter image description here

Here after removing edges of the first shortest path (green), the only remaining path (red) is very heavy. The cost of this solution is 1+1+10+1+1+2+90+2=108. While optimal cost is 1+15+1+2+1+10+1+2=32.

Evgeny Kluev
  • 24,287
  • 7
  • 55
  • 98
  • :thanks for clarification but is there any theoretical way to prove this ,because above approach is somewhat greedy as we picked shortest path for going and then we picked shortest path for coming so we are actually finding local optimal solution. How can we theoretically prove it using matroid,if possible .Because I want to learn how to prove or represent these situation in matroid theory . – Imposter Aug 09 '12 at 12:01
  • @Imposter: sorry, I didn't understand - to prove what? – Evgeny Kluev Aug 09 '12 at 12:06
  • In order to prove whether a greedy approach leads to optimal solution we use matroid theory. So in the above explanation we want to prove that a greedy approach doesn't lead to optimal solution . I wish someone to explain the proof in terms of matroid theory (although it is clear from the graph shown but what if graph is so complicated...) I may be completely wrong . Please correct me if i'm wrong – Imposter Aug 09 '12 at 13:06
  • 3
    @Imposter: I'm afraid I cannot prove non-optimality in terms of matroid theory. For negative proofs it is enough to provide a single counter-example to convince that conjecture is incorrect. – Evgeny Kluev Aug 09 '12 at 13:39
  • +1 for counter-example, that simple algorithm was my first thought but it didn't feel correct :) – BlueRaja - Danny Pflughoeft Aug 09 '12 at 15:53