import numpy as np
import networkx as nx
a=np.loadtxt(“Pdata10_6.txt”)
G=nx.Graph(a)
d=nx.shortest_path_length(G,weight=‘weight’)
Ld=dict(d)
print("顶点对之间的距离为: ",Ld)
print("顶点0到3之间的距离为: “,Ld[0][3])
m,n=a.shape; dd=np.zeros((m,n))
for i in range(m):
for j in range(n): dd[i,j]=Ld[i][j]
print(“顶点对之间最短距离的数组为: \n”,dd)
np.savetxt(‘Pdata10_8.txt’,dd)
p=nx.shortest_path(G,weight=‘weight’)
dp=dict§
print(”\n顶点对之间的最短路径为: ",dp)
print(“顶点0到3的最短路径为:”,dp[0][3])
2021-05-28
最新推荐文章于 2022-02-24 13:31:38 发布