贪心算法,numpy,矩阵,外植

Greedy algorithm, numpy, matrix, explantation

距离

从0到1是1.0

从1到2是3.0

从0到2是2.0

D = [

     [ 0, 1.0, 2.0],
     [ 1.0, 0, 3.0],
     [ 2.0, 3.0, 0]
]

所以我得到了一个看起来像上面的矩阵。

但我不太明白为什么这些措施与我 post 顶部给出的措施一样?

0到1的距离怎么是1.0?

啊...这是一个pre-loaded距离数组。

例如,点 0 是 (5,0),点 1 是 (4,0),点 2 是 (7,0)。然后D预加载inter-point距离,即D[from_point][to_point] = distance(from_point, to_point).

然后您可以参考矩阵,而不必重新计算距离。