0

I was just wondering if all algorithms for the TSP will give the same optimum routes? I thought that this would be the case but ive implemented branch and bound and A* and they both give very different results to the same input, I was just wondering if this is normal?

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
thrash
  • 187
  • 1
  • 4
  • 18
  • 1
    All the *optimum* routes have the same cost. Walk left first or walk right first. As long as getting home takes the same amount of time .. –  Jan 17 '13 at 18:13

2 Answers2

2

The route my differ, but the cost of all optimal solution should be the same.

If your A* solution is more expensive, than your heuristic is wrong. Have a look at wikipedia A* algorithm for proofs that it always finds an optimal solution.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
  • Thanks for the reply again! My A* solution is more expensive and is taking significantly longer than branch and bound which visits 13,333 nodes and comes up with the best solution in 94 ns compared to A* which visits 11 in 7,729,000 ns :/ – thrash Jan 17 '13 at 18:18
  • Your heuristic must always 'underestimate' the cost of the missing part to a solution! – MrSmith42 Jan 17 '13 at 18:20
  • Changing my heuristic constant from 50 to 3 gave me the exact same cost as branch and bound, so im guessing thats right? :) – thrash Jan 17 '13 at 18:22
  • 1
    I do not know, how your heuristic looks like. I think the sum of the lowest costs of all still missing cities is a good one (can be calculated quite cheaply and is guaranteed to underestimate the real costs) – MrSmith42 Jan 17 '13 at 18:40
  • Or a not so good, but even easier to calculate heuristic: Number of still missing cities multiplied with the lowest of all costs between two cities. (With this heuristic the algorithm may need a lot more steps but the heuristic is very cheap to calculate) – MrSmith42 Jan 17 '13 at 19:08
  • The heuristic function is: heuristic_constant * (distances.getCitiesCount() - level) if you understand what means what in that function? – thrash Jan 17 '13 at 19:24
  • 1
    If you set *heuristic_constant* to the lowest cost of the distance between two cities the A* search will find an optimal solution. For higher values the heuristic may fail. – MrSmith42 Jan 17 '13 at 19:30
  • As you seem to know a lot more about this then I do, im having a problem with branch and bound which is the same as the depth first, im searching 21 nodes and its been running for about 20 minutes now with no solution. Any ideas? :/ – thrash Jan 17 '13 at 20:51
  • 1
    It's quite late here in Germany and it is very hard to analyze such problems via comments and without the code. I recommend to have a look at the wikipedia article or have a look in a book. – MrSmith42 Jan 17 '13 at 20:56
1

No. Provided more than one optimal route exists, different algorithms will not necesarily find the same path. It will depend on the implementation, and I assume it will also depend on how you label the graph, so that different labelings will make the same algorithm find different routes.