1 / 22

Algorithme de Dijkstra

Algorithme de Dijkstra. R éférence : John W. Byers . Dijkstra Demo , Course notes CS 330 introduction to Algorithms , Doston Uniuversity , Spring 2013, [available at] http://www.cs.bu.edu/fac/byers/cs330.html Modifié par: Vincent Roberge. Pseudocode.

makara
Download Presentation

Algorithme de Dijkstra

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithme de Dijkstra • Référence: • John W. Byers. DijkstraDemo, Course notes CS 330 introduction to Algorithms, DostonUniuversity, Spring 2013, [available at] http://www.cs.bu.edu/fac/byers/cs330.html • Modifié par: Vincent Roberge

  2. Pseudocode dist[s] ←0 (distance to source vertex is zero)for  all v ∈ V–{s}        do  dist[v] ←∞ (set all other distances to infinity) S←∅ (S, the set of visited vertices is initially empty) Q←V  (Q, the queue initially contains all vertices) while Q ≠∅ (while the queue is not empty) do   u ← mindistance(Q,dist) (select the element of Q with the min. distance)   S←S∪{u} (add u to list of visited vertices)        for all v ∈ neighbors[u]               do  if   dist[v] > dist[u] + w(u, v) (if new shortest path found)                         then      d[v] ←d[u] + w(u, v) (set new value of shortest path) (if desired, add traceback code) return dist

  3. Dijkstra's Shortest Path Algorithm • Find shortest path from s to t. 24 2 3 9 s 18 14 6 2 6 4 19 30 11 5 15 5 6 16 20 t 7 44

  4. Dijkstra's Shortest Path Algorithm Visités= { } Non-visités= { s, 2, 3, 4, 5, 6, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ ]   24 2 3 0 9 s 18  14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label 

  5. Dijkstra's Shortest Path Algorithm Visités= { } Non-visités= { s, 2, 3, 4, 5, 6, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ ] delmin   24 2 3 0 9 s 18  14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label 

  6. Dijkstra's Shortest Path Algorithm Visités= { s } Non-visités= { 2, 3, 4, 5, 6, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s ss ] decrease key   9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label  15 X

  7. Dijkstra's Shortest Path Algorithm Visités= { s } Non-visités= { 2, 3, 4, 5, 6, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s ss ] delmin   9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label  15 X

  8. Dijkstra's Shortest Path Algorithm Visités= { s, 2 } Non-visités= { 3, 4, 5, 6, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s ss ]   9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44   15 X

  9. Dijkstra's Shortest Path Algorithm Visités= { s, 2 } Non-visités= { 3, 4, 5, 6, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 2 s s ] decrease key  33 X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44   15 X

  10. Dijkstra's Shortest Path Algorithm Visités= { s, 2 } Non-visités= { 3, 4, 5, 6, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 2 s s ]  33 X  9 X 24 2 3 0 9 delmin s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44   15 X

  11. Dijkstra's Shortest Path Algorithm Visités= { s, 2, 6 } Non-visités= { 3, 4, 5, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 6 s s ] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  44 4  X 19 30 11 5 15 5 6 16 20 t 7 44   15 X

  12. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 6 } Non-visités = { 3, 4, 5, 7, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 6 s s ] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  44 4  X 19 30 11 5 15 5 6 16 20 t 7 44  delmin  15 X

  13. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 6, 7 } Non-visités = { 3, 4, 5, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 7 s s 7] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  35 44 X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  59 X  15 X

  14. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 6, 7 } Non-visités = { 3, 4, 5, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 7 s s 7] delmin 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  35 44 X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  59 X  15 X

  15. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 6, 7 } Non-visités = { 4, 5, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 3 s s 3] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  35 34 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  51 59 X X  15 X

  16. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 6, 7 } Non-visités = { 4, 5, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 3 s s 3] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  35 34 44 X X 4  X 19 30 11 5 15 5 6 16 delmin 20 t 7 44  51 59 X X  15 X

  17. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 5, 6, 7 } Non-visités = { 4, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 5 3 s s 5] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  18. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 5, 6, 7 } Non-visités = { 4, t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 5 3 s s 5] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 delmin 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  19. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 4, 5, 6, 7 } Non-visités = { t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 5 3 s s 5] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  20. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 4, 5, 6, 7 } Non-visités = { t } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 5 3 s s 5] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  delmin 50 51 59 X X X  15 X

  21. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 4, 5, 6, 7, t } Non-visités = { } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 5 3 s s 5] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  22. Dijkstra's Shortest Path Algorithm Visités = { s, 2, 3, 4, 5, 6, 7, t } Non-visités = { } suivants = [s 2 3 4 5 6 7 t] precedents = [ s 6 5 3 s s 5] 32  33 X X  9 X 24 2 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

More Related