Generating some random Gaussian coordinates, I noticed the TSP-solver returns horrible solutions, however it also returns the same horrible solution over and over again for the
I think the problem is with the distance-measure :). I can remember a kScalingFactor
in the C-code samples from or-tools, which was used to scale up distances, and then round (by casting) them to integers: or-tools expects distances to be integers.
Or course, distances between standard Gaussian random coordinates typically lie between 0 and maybe 2, hence most point pairs have the same distances when mapped to integers: garbage in, garbage out.
I fixed it by simply multiplying and casting to integers (just to be sure swig won't interpreter the floats as integers):
# ...
def distance(self, x, y):
return int(10000 * math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2))
# ...
Then the results make a lot more sense:
10 points:
20 points:
200 points: