我正在使用networkx查找通过图中所有节点的最短路径。这是我的代码:
import networkx as nx
G = nx.Graph()
G.add_edge('a', 'b', weight=10)
G.add_edge('a', 'c', weight=20)
G.add_edge('a', 'd', weight=30)
G.add_edge('a', 'e', weight=40)
G.add_edge('b', 'c', weight=70)
G.add_edge('b', 'd', weight=80)
G.add_edge('b', 'e', weight=90)
G.add_edge('c', 'd', weight=50)
G.add_edge('c', 'e', weight=60)
G.add_edge('d', 'e', weight=100)
nx.shortest_path(G,source='a',target='a')
我试图找到从'a'到'a'的最短路径,但是我得到['a']作为输出。我的理解是,我输入代码的方式不允许从“ a”转到“ a”,那么为什么我得到此输出?我如何指定我不能从“ a”转到“ a”。
谢谢。