0

I am currently working on a project involving a mixture of travelling salesman and shortest path. It goes as follows:

I am given a set of 9 vertices,all with positive coordinates in 2 space, (x,y), where x and y are positive real numbers. I am then asked to compute the shortest path a travelling salesman can take, and traverse through all the points. In essence, the graph is simply a collection of nodes with coordinates, and I have to arrange the edges, such that there is a connection from node 1 to node 9, that is the shortest possible one. It is assumed that I have already visited at the beginning node 1 (x1,y1), and need to visit each node once and only once. I will end on node 9, specified by (x9,y9).

I am writing the program in Java, although the professor said that the program can be written in any language.

I started by writing a node class, which represents each node, and has fields x,y which represent the x and y coordinates respectively. However, I am completely stumped as to how to perform the optimization.

I would greatly appreciate any assistance with respect to this problem.

Thank you very much, and I am excited to become a member of this community!

Darek Kay
  • 15,827
  • 7
  • 64
  • 61
  • 1
    Maybe you should post your question at [Computer Science section](http://cs.stackexchange.com/). It seems to be off-topic for StackOverflow – Stefan Freitag May 16 '15 at 19:44

1 Answers1

1

Euclidean TSP remains NP-hard, so just go for whatever algorithm for general TSP you want; for 9 vertices, the brute force solution compares 7! = 5040 permutations of the 7 intermediate vertices (since you start at 1 and end in 9 as per the problem description), so all you would need to do for that is generate all permutations of {2,...,8} and then just check the length of those paths.

If you want something slightly fancy, go for the dynamic programming approach by Held, Karp and separately Bellman which you can read up on in lots of places online, so I won't be posting how that works.

G. Bach
  • 3,869
  • 2
  • 25
  • 46