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
评论列表
文章目录