60 likes | 417 Views
DIJKSTRA’s Algorithm. Definition fwd search. Find the shortest paths from a given SOURCE node to ALL other nodes, by developing the paths in order of increasing path length. The alg. Proceeds in stages. N = set of nodes in the network; S = sourse node;
E N D
Definition fwd search • Find the shortest paths from a given SOURCE node to ALL other nodes, by developing the paths in order of increasing path length. The alg. Proceeds in stages. • N = set of nodes in the network; • S = sourse node; • M set of nodes so far incorporated by the alg • l(i,j)= link cost from node i to j;l(i,i)=0; l(i,j)= if the two nodes are not directly connected; l(i,j)>0 if they are directly connected; • C1(n) = least-cost paths from S to n
FWD. Search Algorithm 1.Set M={S}; for each node nN-S, set C1(n)=l(S,n); 2. Find W N-M so that C1(w) in minimum, add W to M. Set C1(n)= MIN C1(n) and C1(w)+l(w,n) 3. Repeat 2. until M=N
Definition bwd search • Find the shortest paths from a given DESTINATION node from ALL other nodes. • N = set of nodes in the network; • D = destination node; • M set of nodes so far incorporated by the alg • l(i,j)= link cost from node i to j;l(i,i)=0; l(i,j)= if the two nodes are not directly connected; l(i,j)>0 if they are directly connected; • C2(n) = least-cost paths from D to n
BWD. Search Algorithm 1.Set C2(D)=0; for each node nN-D set C2(n)= ; 2. For each node n N-D set C2(n)= MIN C2(n) and C2(w)+l(n,w) (w N) 3. Repeat 2. until no changes in C2