1 / 28

Diskrete Mathematik II

Diskrete Mathematik II. Vorlesung 3 27.04.00 der Algorithmus von Floyd. Foliendesign: cand. geod. Jörg Steinrücken. Übersicht. letzte Stunden: Algorithmus von Dijkstra alle kürzesten Wege von einem Knoten ( 1:n ) Datenstrukuren für den Algorithmus von Dijkstra

alban
Download Presentation

Diskrete Mathematik II

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. Diskrete Mathematik II Vorlesung 3 27.04.00 der Algorithmus von Floyd Foliendesign: cand. geod. Jörg Steinrücken

  2. Übersicht • letzte Stunden: • Algorithmus von Dijkstra • alle kürzesten Wege von einem Knoten (1:n) • Datenstrukuren für den Algorithmus von Dijkstra • Datenstruktur für Graphen mit Kosten • Adjazenzliste • Adjazenzmatrix • Datenstruktur für grüne Knoten • Heute: • Algorithmus von Floyd • kürzeste Wege zwischen allen Paaren von Knoten (n:n) Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  3. Algorithmus von Floyd • Problem: Bestimmung der kürzesten Wege zwischen allen Paaren von Knoten • Lösung • iterative Anwendung des Algorithmus von Dijkstra • besser: Algorithmus von Floyd Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  4. Algorithmus von Floyd: Idee Do Vorgänger 20 35 füge neue direkte Kante ein, wenn noch keine Kante vorhanden oder die neue Kante kürzer ist als eine vorhandene Ha betrachteter Knoten 15 W Nachfolger Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  5. Algorithmus von Floyd: Idee Do 20 Für jedes Paar Vorgänger / Nachfolger 35 Ha Für jeden Knoten 15 W Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  6. Algorithmus von Floyd (Beispiel) Do 80 Vorgänger Du 20 Ha 30 20 betrachteter Knoten 15 W D 150 15 80 Nachfolger K Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  7. Do 80 20 Du Ha 30 20 15 D W 150 15 80 K Algorithmus von Floyd (Beispiel) Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  8. Do 80 20 Du Ha 30 20 15 D W 150 15 80 K Algorithmus von Floyd (Beispiel) fangen wir wieder an mit Dortmund Knoten besitzt nur Nachfolger Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  9. Do 80 20 35 Du Ha 30 20 15 D W 150 15 80 K Algorithmus von Floyd (Beispiel) als nächstes Hagen Do W Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  10. Do 20 35 Du Ha 30 20 15 D W 150 15 80 K Algorithmus von Floyd (Beispiel) Jetzt haben wir 2 Vorgänge und 3 Nachfolger - wie viele Paare also? Do 80 80 Du Ha D K Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  11. Do 20 35 185 45 Du Ha 30 20 15 D W 150 115 15 80 K Algorithmus von Floyd (Beispiel) 65 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  12. Do 65 20 35 185 45 Du Ha 30 165 20 15 D W 150 95 115 15 80 K Algorithmus von Floyd (Beispiel) Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  13. Do 65 20 35 185 45 Du Ha 30 165 20 15 D W 150 95 115 15 80 K Algorithmus von Floyd (Beispiel) Do Ha D W Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  14. Do 65 20 35 185 45 Du Ha 30 165 20 15 D W 150 95 115 15 80 K Algorithmus von Floyd (Beispiel) Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  15. Do 65 20 35 45 Du Ha 30 20 15 D W 150 95 115 15 80 K Algorithmus von Floyd (Beispiel) 85 165 165 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  16. Do 65 20 35 85 45 Du Ha 30 20 15 D W 95 115 15 80 K Algorithmus von Floyd (Beispiel) 65 150 150 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  17. Do 65 20 35 85 45 Du Ha 30 65 20 15 D W 95 115 15 80 K Algorithmus von Floyd (Beispiel) 50 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  18. Do 65 20 35 85 45 Du Ha 30 65 20 15 D W 50 95 115 15 80 K Algorithmus von Floyd (Beispiel) Do Du Ha W K Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  19. Do 65 20 35 85 45 Du Ha 30 65 20 15 D W 50 95 15 80 K Algorithmus von Floyd (Beispiel) 115 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  20. Do 65 20 35 85 45 Du Ha 30 65 20 15 D W 50 15 80 K Algorithmus von Floyd (Beispiel) 95 95 100 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  21. Do 65 20 35 85 45 Du Ha 30 65 20 15 D W 50 100 15 K Algorithmus von Floyd (Beispiel) 80 80 80 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  22. Do 65 20 35 85 45 Du Ha 30 65 20 15 D W 50 35 80 100 15 K Algorithmus von Floyd (Beispiel) 65 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  23. Algorithmus von Floyd (Beispiel) Do 65 20 35 85 45 Du Ha 30 65 20 15 D W 50 35 80 100 15 65 K Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  24. Implementierung mit der Kostenmatrix-Darstellung private floyd (float A [n,n], float C [n,n]) { int i, j, k; for(j = 1; j <= n; j++) {for(k = 1; k <=n; k++) //A: Wege { A[j,k] = C[j,k]; } //C: Kanten, ggf.  } for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { for(k = 1; k <= n; k++) { if(A[j,i] + A[i,k] < A[j,k]) { A[j,k] = A[j,i] + A[i,k]; }}}}} Heute wieder Java! Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  25. Floyd-Erweiterung: Mitführung der kürzesten Wege private floyd (float A[n,n], float C[n,n], int W[n,n]) { int i, j, k; for(j = 1; j <= n; j++) {for(k = 1; k <=n; k++) { A[j,k] = C[j,k]; W[j,k] = } } for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { for(k = 1; k <= n; k++) { if(A[j,i] + A[i,k] < A[j,k]) { A[j,k] = A[j,i] + A[i,k]; W[j,k] = i; }}}}} Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  26. Floyd (3) • Beachten Sie: • Die Ausgabeprozedur setzt voraus, daß ein Weg zwischen 2 Knoten x und y existiert • Übung: • Wie sehen Sie der Matrix A an, ob ein Weg zwischen 2 Knoten existiert • allgemeiner: Wie sehen Sie der Matrix A an, ob der Graph zusammenhängend ist • der Graph ist zusammenhängend, wenn zwischen jedem Paar (a,b) von Knoten ein Weg existiert • beachten Sie, dass wir von gerichteten Graphen sprechen, also (a,b)  (b,a) Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  27. Ausgabe des kürzesten Weges public weg(int[][] W,int X,int Y) //gibt kürzesten Weg von X nach Y aus { weg_rekursiv(X,Y); gib Y aus; } private weg_rekursiv(int[][] W,int X,int Y) { if( W[X,Y] =  ) then gib X aus; else { Z = W[X,Y]; weg_rekursiv(W,X,Z); weg_rekursiv(W,Z,Y); }} Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.00

  28. Schönen Dank für Ihre Aufmerksamkeit und Auf Wiedersehen

More Related