Algorithme de Dijkstra - Licence de mathématiques Lyon...

21
Algorithme de Dijkstra Algorithme de Dijkstra 21 octobre 2008

Transcript of Algorithme de Dijkstra - Licence de mathématiques Lyon...

Page 1: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Algorithme de Dijkstra

21 octobre 2008

Page 2: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Introduction

Le but de cette présentation est de faire fonctionnerl’algorithme de Dijkstra sur des exemples concrets.

Exemple 1Cherchons les plus courts chemins d’origine A dans ce graphe:

A

B

E

C

D

10

5

1

9

2

32 4 6

7

Page 3: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Introduction

Le but de cette présentation est de faire fonctionnerl’algorithme de Dijkstra sur des exemples concrets.

Exemple 1Cherchons les plus courts chemins d’origine A dans ce graphe:

A

B

E

C

D

10

5

1

9

2

32 4 6

7

Page 4: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

On se place au sommet de plus petit poids, ici le sommet A.

0A

∞B

∞E

∞C

∞D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞•••••

Page 5: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

On étudie chacune des arêtes partant du sommet choisi.

0A

10B

5

E

∞C

∞D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A••••

Dans les colonnes, on mets la distance à A, et le sommet d’oùl’on vient.

Page 6: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

On se place de nouveau au sommet de plus petit poids, ici E .

0A

10B

5

E

∞C

∞D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A

• •• •• •• •

Page 7: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

Et ainsi de suite.

0A

8B

5

E

14C

7D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A

• 8E 14E 7E •• •• •

Page 8: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

0A

8B

5

E

14C

7D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A

• 8E 14E 7E •• • •• • •

Page 9: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

0A

8B

5

E

13C

7D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A

• 8E 14E 7E •• 8E 13D • •• • •• • •

Page 10: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

0A

8B

5

E

13C

7D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A• 8E 14E 7E •• 8E 13D • •• • • •• • • •

Page 11: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

0A

8B

5

E

9C

7D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A• 8E 14E 7E •• 8E 13D • •• • 9B • •• • • • •

Page 12: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Premier exemple

0A

8B

5

E

9C

7D

10

5

1

9

2

32 4 6

7

A B C D E0 ∞ ∞ ∞ ∞• 10A ∞ ∞ 5A• 8E 14E 7E •• 8E 13D • •• • 9B • •• • • • •

Si l’on ne considère que les flèches soulignées, on obtient unarbre, un graphe sans cycle.

Page 13: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

Exemple 2Cherchons les plus courts chemins d’origine E dans ce graphe:

E

A

B

C

D

S

3

1

1

3

3

5

1

3

1

Page 14: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

Exemple 2Cherchons les plus courts chemins d’origine E dans ce graphe:

E

A

B

C

D

S

3

1

1

3

3

5

1

3

1

Page 15: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

0E

∞A

∞B

∞C

∞D

∞ S

3

1

1

3

3

5

1

3

1

E A B C D S0 ∞ ∞ ∞ ∞ ∞•••••

Page 16: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

0E

3A

1B

∞C

∞D

∞ S

3

1

1

3

3

5

1

3

1

E A B C D S0 ∞ ∞ ∞ ∞ ∞• 3E 1E ∞ ∞ ∞• •• •• •• •

Page 17: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

0E

2A

1B

4C

6D

∞ S

3

1

1

3

3

5

1

3

1

E A B C D S0 ∞ ∞ ∞ ∞ ∞• 3E 1E ∞ ∞ ∞• 2B • 4B 6B ∞• • •• • •• • •

Page 18: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

0E

2A

1B

4C

6D

∞ S

3

1

1

3

3

5

1

3

1

E A B C D S0 ∞ ∞ ∞ ∞ ∞• 3E 1E ∞ ∞ ∞• 2B • 4B 6B ∞• • • 4B 6B ∞• • • •• • • •

Page 19: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

0E

2A

1B

4C

5

D

7 S

3

1

1

3

3

5

1

3

1

E A B C D S0 ∞ ∞ ∞ ∞ ∞• 3E 1E ∞ ∞ ∞• 2B • 4B 6B ∞• • • 4B 6B ∞• • • • 5C 7C

• • • • •

Page 20: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

0E

2A

1B

4C

5

D

6 S

3

1

1

3

3

5

1

3

1

E A B C D S0 ∞ ∞ ∞ ∞ ∞• 3E 1E ∞ ∞ ∞• 2B • 4B 6B ∞• • • 4B 6B ∞• • • • 5C 7C

• • • • • 6D

Page 21: Algorithme de Dijkstra - Licence de mathématiques Lyon 1licence-math.univ-lyon1.fr/lib/exe/fetch.php?media=gla:dijkstra.pdf · Algorithme de Dijkstra Introduction Le but de cette

Algorithme de Dijkstra

Deuxième exemple

0E

2A

1B

4C

5

D

6 S

3

1

1

3

3

5

1

3

1

E A B C D S0 ∞ ∞ ∞ ∞ ∞• 3E 1E ∞ ∞ ∞• 2B • 4B 6B ∞• • • 4B 6B ∞• • • • 5C 7C• • • • • 6B