function Dijkstra(Graph, source):
for each vertex v in Graph: // Initializations
dist[v] := infinity ; // Unknown distance function from source to v
previous[v] := undefined ; // Previous node in optimal path from source
end for ;
dist[source] := 0 ; // Distance from source to source
Q := the set of all nodes in Graph ;
// All nodes in the graph are unoptimized - thus are in Q
while Q is not empty: // The main loop
u := vertex in Q with smallest dist[] ;
if dist[u] = infinity:
break ; // all remaining vertices are inaccessible from source
fi ;
remove u from Q ;
for each neighbor v of u: // where v has not yet been removed from Q.
alt := dist[u] + dist_between(u, v) ;
if alt < dist[v]: // Relax (u,v,a)
dist[v] := alt ;
previous[v] := u ;
fi ;
end for ;
end while ;
return dist[] ;
end Dijkstra.
上記のアルゴリズムはDijkstraの最短経路についてWikipediaで言及されています。私がここで理解できないことは、すべての頂点までの距離を無限大[行番号3]に設定している間に、行9ではu := vertex in Q with smallest dist[]
を割り当てているが、すべての距離は無限大である(行番号3 )どのように最小距離がありますか?ウィキペディアでDijkstraのアルゴリズムの実装についての質問
これは、dist_between(u、v)もdist []に基づいて距離を計算していると考えていました –