3
我有我自己的对象,比如辣香肠。我有一份来自每个意大利辣香肠和一份胡椒粉的清单。然后我使用networkx构建一个图。我试图找到从一个意式香肠到另一个意式香肠的最短路径的重量。然而,我发现了一个错误,如下所示,它跟踪从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?
编辑:我有我的边格式正确。我不知道对象是否可以作为节点处理。
说实话,我不知道我的问题究竟是什么,但我愚弄了对象,并最终让它正常工作。感谢您经过深思熟虑的回应。它让我想到了:) – Trim 2010-11-18 02:44:15