I use FindShortestTour
as explained here and it works nicely for a small number of cities. However when I try this with as little as 16 cities, the given tour isn't optimal anymore. I've tried using different Methods
but none of them gave me the optimal tour (solutions within a 5% to 400% range of the optimal solution).
How can I force Mathematica to give me the optimal solution?
Edit:
This is my code (pretty much copy-paste from the link above as I'm very new to Mathematica)
dim = 16;
max = 100;
(* create symmetric matrix with random integers *)
d = RandomInteger[max, {dim, dim}];
d = Table[If[i > j, d[[i, j]], d[[j, i]]], {i, 1, Length[d[[1]]]}, {j, 1,Length[d[[1]]]}];
(d[[#, #]] = Infinity) & /@ Range[dim];
d // Grid
(* find tour *)
{len, tour} = FindShortestTour[Range[dim], DistanceFunction -> (d[[#1, #2]] &),
Method -> "TwoOpt"]
(* display tour *)
HighlightGraph[ WeightedAdjacencyGraph[d, DirectedEdges -> False,
GraphStyle -> "SmallNetwork", EdgeLabels -> "EdgeWeight"],
Style[UndirectedEdge[#1, #2], Thickness[.01], Red] & @@@ Partition[tour, 2, 1, 1]]
888
as distance whereas the optimal was198
. The best for this specific layout wasTwoOpt
giving me a solution of205
but none of them ever seem to give me an optimal solution. (which I need to compare my algorithm against) $\endgroup$