565 plus courts chemins toutes paires d'états (algorithme de warshallo(card s 3 ) ) algorithme...
TRANSCRIPT
![Page 1: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/1.jpg)
1
Plus courts chemins
Toutes paires d'états(algorithme de Warshall O(card S3) )algorithme de Floyd O(card S3)
Chemins de même origine (ou même destination)(selon les hypothèses)algorithme de Dijkstra O(card S2)
ou O(card S + card A.log card S)algorithme de Bellman-Ford O(card A.card S)
UMLV
![Page 2: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/2.jpg)
2
Graphe valué : G = (S, A, v) avec valuation v : A R
Source du graphe : s S
Problème : pour tout t S calculer (s, t) = min { v(c) ; c chemin de s à t } {+}
Exemple Coûts
UMLV Problème
s
dc
b
a3
5
3
1 1 1 3
5
5
5s
dc
b
a3
5
3
1 1 1 3
5
5
5
3 8
4 9
0
![Page 3: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/3.jpg)
3
UMLV Arbres de plus courts chemins
Arbres de racine sdont les branches sont des chemins de coût minimal
s
dc
b
a3
5
3
1 1 1 3
5
5
5
3 8
4 9
0s
dc
b
a3
5
3
1 1 1 3
5
5
5
3 8
4 9
0
![Page 4: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/4.jpg)
4
Proposition pour tout t S (s, t) > -ssi le graphe n’a pas de circuit de coût < 0accessible depuis s
UMLV Existence
s
dc
b
a3
5
3
1 1 1 -3
5
5
5
![Page 5: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/5.jpg)
5
UMLV Propriétés de base
Propriété 1 : G = (S, A, v) soit c un plus court chemin de p à r dont l’avant-dernier sommet est qAlors (p, r) = (p, q) + v(q, r)
Propriété 2 : G = (S, A, v) soit c un chemin de p à r dont l’avant-dernier sommet est qAlors (p, r) (p, q) + v(q, r)
p r q
![Page 6: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/6.jpg)
6
Relaxation
Calcul des (s,t) par approximations successives
t S d(t) = estimation de (s, t)
(t) = prédécesseur de t : avant-dernier sommet
d’un chemin de s à t ayant pour coût d(t)
Initialisation de d et INIT
pour chaque t S faire{ d(t) ; (t) nil; }d(s) 0;
Relaxation de l ’arc (q, r)RELAX(q, r)
si d(q) + v(q, r) < d(r)alors { d(r) d(q) + v(q, r) ; (r) q ; }
UMLV
s r q
d(r)
d(q)
![Page 7: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/7.jpg)
7
Proposition : la propriété « pour tout t S d(t) (s, t) »est un invariant de relax
Preuve par induction sur le nombred ’exécution de relax
UMLV Relaxation (suite)
![Page 8: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/8.jpg)
8
Algorithme de Dijkstra
Condition : v(p, q) 0 pour tout arc (p, q)
débutINIT;Q S ;tant que Q faire {
q MINd (Q) ; Q Q - {q} ;pour chaque r successeur de q faire
RELAX(q, r) ;}
fin
Algorithme glouton (séquentiel)
UMLV
![Page 9: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/9.jpg)
9
s
dc
b
a3
5
3
1 1 1 3
5
5
5
0
UMLV Exemple
s
dc
b
a3
5
3
1 1 1 3
5
5
5
3
5
0
Q = { s, a, b, c, d }(s) = nil(a) = nil(b) = nil(c) = nil(d) = nil
Q = { a, b, c, d }(s) = nil(a) = s(b) = nil(c) = s(d) = nil
![Page 10: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/10.jpg)
10
s
dc
b
a3
5
3
1 1 1 3
5
5
5
3
5
0
UMLV
s
dc
b
a3
5
3
1 1 1 3
5
5
5
3 8
4
0
Q = { a, b, c, d }(s) = nil(a) = s(b) = nil(c) = s(d) = nil
Q = { b, c, d }(s) = nil(a) = s(b) = a(c) = a(d) = nil
Exemple (suite)
![Page 11: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/11.jpg)
11
s
dc
b
a3
5
3
1 1 1 3
5
5
5
3 8
4
0
UMLV
s
dc
b
a3
5
3
1 1 1 3
5
5
5
3 8
4 9
0
Q = { b, c, d }(s) = nil(a) = s(b) = a(c) = a(d) = nil
Q = { b, d }(s) = nil(a) = s(b) = a(c) = a(d) = c
Exemple (suite)
![Page 12: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/12.jpg)
12
s
dc
b
a3
5
3
1 1 1 3
5
5
5
3 8
4 9
0
UMLV
Q = { b, d }, Q = { d } puis Q = (s) = nil(a) = s(b) = a(c) = a(d) = c
Exemple (suite)
s
dc
b
a
![Page 13: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/13.jpg)
13
Implémentation
Par matrice d'adjacencetemps global O(card S2)
Par listes de successeurs Q : file de priorité (tas)card S opérations MINdO(card S.log card S) card A opérations RELAX O(card A.log card S)
temps global O((card S+card A).log card S)
UMLV
![Page 14: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/14.jpg)
14
Algorithme de Bellman-Ford
Aucune condition : pour tout arc (p, q), v(p, q) R
débutINIT;Q S ;répéter card S-1 fois
pour chaque (q, r) A faireRELAX(q, r) ;
pour chaque (q, r) A fairesi d(q) + v(q, r) < d(r) alors
retour « cycle de coût négatif »sinon
retour « coûts calculés »fin
Temps : O(card S.card A)
UMLV
![Page 15: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/15.jpg)
15
s
dc
b
a3
5
3
1 1 1 -3
5
5
5
0
UMLV Exemple 1
s
dc
b
a3
5
3
1 1 1 -3
5
5
5
3 6
4 9
0
Étape 1 relaxation de tous les arcs dans l’ordre :(s,a) (s,c) (a,b) (a,c) (b,d) (c,a) (c,b) (c,d) (d,b) (d,s)
![Page 16: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/16.jpg)
16
UMLV Exemple 1 (suite)
s
dc
b
a3
5
3
1 1 1 -3
5
5
5
3 4
4 7
0s
dc
b
a3
5
3
1 1 1 -3
5
5
5
3 6
4 9
0
Étape 2 relaxation de tous les arcs dans l’ordre :(s,a) (s,c) (a,b) (a,c) (b,d) (c,a) (c,b) (c,d) (d,b) (d,s)
![Page 17: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/17.jpg)
17
UMLV Exemple 1 (suite)
s
dc
b
a3
5
3
1 1 1 -3
5
5
5
3 2
4 5
0s
dc
b
a3
5
3
1 1 1 -3
5
5
5
3 4
4 7
0
Étape 3 relaxation de tous les arcs dans l’ordre :(s,a) (s,c) (a,b) (a,c) (b,d) (c,a) (c,b) (c,d) (d,b) (d,s)
![Page 18: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/18.jpg)
18
UMLV Exemple 1 (suite)
s
dc
b
a3
5
3
1 1 1 -3
5
5
5
3 0
4 3
0s
dc
b
a3
5
3
1 1 1 -3
5
5
5
3 2
4 5
0
Étape 4 relaxation de tous les arcs dans l’ordre :(s,a) (s,c) (a,b) (a,c) (b,d) (c,a) (c,b) (c,d) (d,b) (d,s)
reduction possible : cycle de coût négatif
![Page 19: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/19.jpg)
19
s
dc
b
a3
5
-3
1 -1 -1 3
5
5
5
0
UMLV Exemple 2
Étape 1 relaxation de tous les arcs dans l’ordre :(s,a) (s,c) (a,b) (a,c) (b,d) (c,a) (c,b) (c,d) (d,b) (d,s)
s
dc
b
a3
5
-3
1 -1 -1 3
5
5
5
3 8
4 7
0
![Page 20: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/20.jpg)
20
s
dc
b
a3
5
-3
1 -1 -1 3
5
5
5
3 8
4 7
0
UMLV
Étape 2 relaxation de tous les arcs dans l’ordre :(s,a) (s,c) (a,b) (a,c) (b,d) (c,a) (c,b) (c,d) (d,b) (d,s)
pas de réduction possible : coûts corrects
s
dc
b
a3
5
-3
1 -1 -1 3
5
5
5
3 8
4 7
0
Exemple 2 (suite)
![Page 21: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/21.jpg)
21
Aucune condition : pour tout arc (p, q), v(p, q) R Calcul après ordre topologique
débutINIT;pour chaque qS en ordre topologique faire
pour chaque r successeur de q faireRELAX(q, r) ;
fin
Temps : O(card S + card A)chaque sommet et chaque arc est examiné une fois
Graphes acycliques UMLV
![Page 22: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/22.jpg)
22
UMLV Exemple
s
dc
b
a3
5-1 -1
-6
5
5
-3
-15
5-3
s dc b
a35 -1-6
Ordre topologiquec, s, a, b, d
![Page 23: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/23.jpg)
23
UMLV Calcul des coûts
Examen de c
Examen de s
-15
5-3
s dc b
a35 -1-6 0
-15
5-3
s dc b
a35 -1-6 0
0 -33 -15
5-3
s dc b
a35 -1-6
![Page 24: 565 Plus courts chemins Toutes paires d'états (algorithme de WarshallO(card S 3 ) ) algorithme de FloydO(card S 3 ) Chemins de même origine (ou même destination)](https://reader036.vdocuments.site/reader036/viewer/2022062417/551d9db6497959293b8dafe7/html5/thumbnails/24.jpg)
24
UMLV Calcul des coûts (suite)
Examen de a
Examen de b
Examen de d inutile
0 -33 -15
5-3
s dc b
a35 -1-6-3
0 -43 -15
5-3
s dc b
a35 -1-6-3