3

I am implementing the Christofides algorithm for getting a 3/2-approximation to TSP in graphs that obey the triangle inequality. I already have code for computing a minimum spanning tree using Kruskal's algorithm and an adjacency matrix.

Now, I want to implement Christofides by doubling the edges and finding an Euler tour and then shortcutting duplicate nodes. How do I perform this step? I'd like the algorithm and (optionally) C code.

Thanks!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Junaid
  • 1,668
  • 7
  • 30
  • 51
  • Does an MST really help solving a TSP? – Daniel Fischer Dec 02 '11 at 11:16
  • Yea it does. You have to use other algorithms after finding MST in a graph. – Junaid Dec 02 '11 at 16:40
  • I don't fully understand your problem, Junaid. Do you just want to know how to get a solution to the TSP problem using an MST heuristic? Since Kruskal sorts the edges already, you just have to traverse the MST by using a DFS algorithm. If you want more information, tell me. – Fatso Feb 03 '12 at 09:54
  • The DFS algorithm is simple because your edges are already sorted. – Fatso Feb 03 '12 at 09:54

1 Answers1

1

The "shortcutting" step works by cutting out from the Euler tour all nodes that have already appeared at least once in the tour. For example, if you had the tour

A → B → A → D → A → E → A

You would end up with the cycle

A → B → D → E → A

One way to do this is the following. Maintain a set of all the nodes you've visited so far in the tour. As you walk along the tour, if you encounter an unvisited node, append it to your cycle and add it to the set. If you encounter a visited node, skip it. At the very end, add an edge from the last node you found back to the start node.

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • How do you handle the situation that there may be a huge number of alternatives to do the short cutting? Of course all with different weighing! E.g. A-B-C-D-E-D-C-B-F-B-A can be shortened: A-B-C-D-E-F-A or A-B-C-E-D-F-A or A-B-E-D-C-F-A or ... – CSharper Nov 20 '21 at 00:58
  • The Chrisofides algorithm assumes you have a complete graph as an input. To do the short cutting from a node A to a node B, just directly proceed from A to B. In practice, if not all the edges are present, you can use your favorite shortest paths algorithm to find the best path from A to B and then use that. – templatetypedef Nov 20 '21 at 01:02