6.4


*代码

点击查看代码
import numpy as np
import networkx as nx
a=np.zeros((5,5))
a[0,1:]=[0.8,2,3.8,6]
a[1,2:]=[0.9,2.1,3.9]
a[2,3:]=[1.1,2.3];
a[3,4]=1.4
G=nx.DiGraph(a)
p=nx.shortest_path(G,0,4,weight='weight')
d=nx.shortest_path_length(G,0,4,weight='weight')
print('最短路径为:',np.array(p)+1)
print('最小费用为:',d)
print('学号3015')
posted @ 2024-10-28 13:04  2023310143015  阅读(9)  评论(0)    收藏  举报