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