i want to implement this Dijkstra's pseudocode exactly to my python graph.
Dijkstra's Algorithm DIJKSTRA(G,s,d) //graph, source, destination
v ← s //v is always our currently scanned node
for all n in G.vertices
n.tw ← ∞ s.tw ← 0 //Source is no distance from itself
visited ← []
while v≠d
for all vertices, u, adjacent to v
if v.tw+v[u].w < u.tw
u.tw ← v.tw+v[u].w
u.pre ← v //Store the return path
visited.append(v)
min ← ∞
for all nodes n ∈ V
if n ∉ visited ∧ n.tw < min
v ← n
min ← n.tw
What I have tried:
graph = {
'a':{'b':3,'c':4, 'd':7},
'b':{'c':1,'f':5},
'c':{'f':6,'d':2},
'd':{'e':3, 'g':6},
'e':{'g':3, 'h':4},
'f':{'e':1, 'h':8},
'g':{'h':2},
'h':{'g':2}
}
def dijkstra(graph,start,goal):