编辑:找到解决方案,这是找到最小最大瓶颈路线的工作算法。
def dijkstra(g,s):
for i in g.vertices:
g.dist[i] = INF
g.pred[i] = 0
g.dist[s] = 0
queue = [i for i in g.vertices]
while len(queue) > 0:
minval = INF
u = 0
for vert in queue:
if g.dist[vert] < minval:
minval = g.dist[vert]
u = vert
queue.remove(u)
for edge in g.adj_list[u]:
v = edge.node
if g.dist[v] > max(g.dist[u], edge.weight):
g.dist[v] = max(g.dist[u], edge.weight)
g.pred[v] = u
所以这是我现在用 Python 编码的 dijkstra,但我不知道我应该如何修改它来计算最大重量最小的路线
def dijkstra(g,s):
for i in g.vertices:
g.dist[i] = INF
g.pred[i] = 0
g.dist[s] = 0
queue = [i for i in g.vertices]
while len(queue) > 0:
minval = INF
u = 0
for vert in queue:
if g.dist[vert] < minval:
minval = g.dist[vert]
u = vert
queue.remove(u)
for edge in g.adj_list[u]:
v = edge.node
if g.dist[v] > g.dist[u] + edge.weight:
g.dist[v] = g.dist[u] + edge.weight
g.pred[v] = u