chapitre 5- Shortest path problem
chapitre 5- Shortest path problem
30
31
R
32
𝒂 𝑪
33
34
(a) (b)
Figure 1: A network with a root and a network with an absorbing (negative) circuit.
35
36
𝒂 𝑪
37
38
39
-
40
Bellman’s algorithm
Input:Let R=(X,A,l) be an acyclic network, with r as the initial
vertex.
Output: The shortest paths from the root r to all the vertices in R,
with their lengths.
Figure 2 : Weighted graph (network) without circuit and with negative weights.
42
Dijkstra's Algorithm
Input : R=(X,A,l) A network with positive edge lengths,r
as the initial vertex.
Output: The shortest paths from the root r to all
vertices in R, along with their lengths.
S{r}; π(r) 0; xV, x≠r, π(x)+; Arc(x) , xV;
While S ≠ V do
For every vertex y that is a successor of x do
If π(x)+l(xy)< π(y) then
π(y) π(x)+l(xy) ;
Arc(y){xy} ;
EndIf
EndFor
Choose a vertex zV\S such that π(z)minxV\S(π(x)) ;
47
If π(z)=+ then
Termination of the algorithm: the vertex r is not a
root, and there is no solution.
else
S S{z} ; xZ ;
EndIf
EndWhile
48
Iteration3 x=3
Y=2 :π(3)+l(32)=5<π(2)=7 π(2)π(3)+l(32)=3+2=5;
Arc(2){32};
Y=4 :π(3)+l(34)=7<π(4)=+ π(4)π(3)+l(34)=3+4=7;
Arc(4){34};
Y=5 :π(3)+l(35)=4<π(5)=+ π(5)π(3)+l(35)=3+1=4;
Arc(5){35};
Choose a vertex z : z5 ; S S{5} ; x5;
Vertex 5 has no successors.
Choose a vertex z : z2 ; S S{2} ; x2;
Iteration4 x=2
Y=4 :π(2)+l(24)=6<π(4)=7 π(4)π(2)+l(24)=5+1=6;
Arc(4){24};
Choose a vertex z : z4 ; S S{4} ; x4;
S=V End of the algorithm.
51
Figure 5 : The shortest paths from r to all other vertices in the network R.