TravelingSalesperson.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:GoodEnoughAlgs 作者: elsander 项目源码 文件源码
def GenerateMap(stops, fname=None, seed=None):
    '''Generate a map with "stops" stops for the salesman
    to traverse. Write coordinates to file if "fname" is
    specified. Return the distance matrix for all coordinates.'''
    random.seed(seed)
    # randomly place stop coordinates in the unit square
    xs = [random.uniform(0, 1) for x in range(stops)]
    ys = [random.uniform(0, 1) for x in range(stops)]
    coords = scipy.array([xs, ys])
    # calculate matrix of distances
    distMat = DistanceMatrix(coords)
    if fname is not None:
        scipy.savetxt(fname, coords)

    return distMat
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号