Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 3 27.04.00 der Algorithmus von Floyd Foliendesign:

Ähnliche Präsentationen


Präsentation zum Thema: "Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 3 27.04.00 der Algorithmus von Floyd Foliendesign:"—  Präsentation transkript:

1

2 Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 3 27.04.00 der Algorithmus von Floyd Foliendesign: cand. geod. Jörg Steinrücken

3 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.002 Ü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)

4 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.003 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

25 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.0024 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!

26 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.0025 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; }}}}}

27 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.0026 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)

28 Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 3 - 27.04.0027 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);}

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


Herunterladen ppt "Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 3 27.04.00 der Algorithmus von Floyd Foliendesign:"

Ähnliche Präsentationen


Google-Anzeigen