OR-tools consistently returns very sub-optimal TSP solution

浪子不回头ぞ 提交于 2019-12-04 04:46:26

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:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!