def testBellmanFord(self):
s = Vertex('s')
t = Vertex('t')
y = Vertex('y')
x = Vertex('x')
z = Vertex('z')
vertices = [s, t, y, x, z]
edges = [(s, t), (s, y), (t, y), (t, x), (t, z), (y, x), (y, z), (x, t), (z, s), (z, x)]
weight = [6, 7, 8, 5, -4, -3, 9, -2, 2, 7]
G = Graph(vertices, edges)
we = dict()
for x,y in zip(edges, weight):
we[x] = y
def w(x, y):
return we[(x, y)]
G.Bellman_Ford(w, z)
评论列表
文章目录