我有自己的东西,比如意大利辣香肠。我有每个意大利辣香肠的边缘列表和意大利辣香肠列表。然后我使用networkx构建一个图表。我试图找到从一个意大利辣香肠到另一个意大利辣香肠的最短路径的重量。但是,我收到如下错误,它跟踪来自 networkx 的内部事物,如下所示:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pizza.py", line 437, in shortestPath
cost = nx.shortest_path_length(a, spepp, tpepp, True)
File "/Library/Python/2.6/site-packages/networkx-1.3-py2.6.egg/networkx/algorithms/shortest_paths/generic.py", line 181, in shortest_path_length
paths=nx.dijkstra_path_length(G,source,target)
File "/Library/Python/2.6/site-packages/networkx-1.3-py2.6.egg/networkx/algorithms/shortest_paths/weighted.py", line 119, in dijkstra_path_length
(length,path)=single_source_dijkstra(G,source, weight = weight)
File "/Library/Python/2.6/site-packages/networkx-1.3-py2.6.egg/networkx/algorithms/shortest_paths/weighted.py", line 424, in single_source_dijkstra
edata=iter(G[v].items())
File "/Library/Python/2.6/site-packages/networkx-1.3-py2.6.egg/networkx/classes/graph.py", line 323, in __getitem__
return self.adj[n]
KeyError: <pizza.pepperoni object at 0x100ea2810>
关于错误是什么的任何想法,或者我必须在我的披萨类中添加什么才能不得到这个 KeyError?
编辑:我的边缘格式正确。我不知道这些对象是否可以作为节点处理。