2012-01-14 65 views
0

我必須在repy中將我的項目導入到我的項目中,但它會返回一個草稿。 我想用模塊和Dijkstra算法在西雅圖船隻上運行,以顯示船隻之間的最短路徑。如何在使用西雅圖環境的repy中導入lib

from priodict import priorityDictionary 

def Dijkstra(G,start,end=None): 

D = {} # dictionary of final distances 
P = {} # dictionary of predecessors 
Q = priorityDictionary() # est.dist. of non-final vert. 
Q[start] = 0 

for v in Q: 
    D[v] = Q[v] 
    if v == end: break 

    for w in G[v]: 
     vwLength = D[v] + G[v][w] 
     if w in D: 
      if vwLength < D[w]: 
       raise ValueError, \ 
    "Dijkstra: found better path to already-final vertex" 
     elif w not in Q or vwLength < Q[w]: 
      Q[w] = vwLength 
      P[w] = v 

return (D,P) 

def shortestPath(G,start,end): 

D,P = Dijkstra(G,start,end) 
Path = [] 
while 1: 
    Path.append(end) 
    if end == start: break 
    end = P[end] 
Path.reverse() 
return Path 

它拋出的錯誤是這樣的:

Uncaught exception! Following is a full traceback, and a user traceback. 
The user traceback excludes non-user modules. The most recent call is displayed 
last. 

Full debugging traceback: 
    "repy.py", line 428, in <module> 
    "repy.py", line 178, in main 
    "D:\STUDIA\LAN\seattle\seattle_repy\virtual_namespace.py", line 78, in __init 
_ 

User traceback: 

Exception (with type 'exceptions.ValueError'): Code failed safety check! Error: 
("<class 'safety_exceptions.CheckNodeException'> (4, 'From')",) 

我應該怎麼做,使它的工作原理?

回答

相關問題