diff --git a/ad/AD-Gruppe_8_Koehler_Krabbe_Martens_Blatt5.tex b/ad/AD-Gruppe_8_Koehler_Krabbe_Martens_Blatt5.tex index 5ed1c08..1e2a697 100644 --- a/ad/AD-Gruppe_8_Koehler_Krabbe_Martens_Blatt5.tex +++ b/ad/AD-Gruppe_8_Koehler_Krabbe_Martens_Blatt5.tex @@ -99,4 +99,145 @@ Jim Martens (6420323)} \subsection{} %a \subsection{} %b \section{} %6 + \begin{tikzpicture}[shorten >=1pt,node distance=1.1cm] + \node[state] (s) {s}; + \node[state] (a) [above right=1.5 and 1.0 of s] {A}; + \node[state] (b) [below right=1.5 and 1.0 of s] {B}; + \node[state] (c) [above right=0.5 and 1.0 of b] {C}; + \node[state] (d) [below right=0.5 and 1.0 of b] {D}; + \node[state] (e) [above right=0.5 and 1.0 of a] {E}; + \node[state] (f) [below right=0.5 and 1.0 of a] {F}; + \node[state] (g) [above right=0.5 and 2.0 of c] {G}; + + \path[every node/.style={font=\scriptsize},->] + (s) edge node [above] {30} (a) + (s) edge node [below] {18} (b) + (a) edge node [above] {20} (e) + (a) edge node [below] {22} (f) + (b) edge node [above] {21} (c) + (b) edge node [below] {38} (d) + (f) edge node [above] {9} (g) + (c) edge node [below] {9} (g); + \end{tikzpicture} + + Da dies ein gerichteter Graph ohne Zyklen ist und auch keine negativen Kantengewichte vorkommen, kann der Dijkstra-Algorithmus angewendet werden. Da von 9 bis 17 Uhr Fahrer bezahlt werden müssen, kommen nur die Pfade in Betrachtung, die zu einer Senke führen. Senken sind D, E und G. Derjenige dieser Knoten welcher als erster vom Algorithmus gefunden wird (über den eindeutig bestimmbaren Weg), ist auch der kürzeste Pfad vom Startknoten aus, der die Bedingungen erfüllt. + + Es ergibt sich folgende Abfolge: + \begin{verbatim} + S = {s} + d(s) = 0 + while 1. + U = {A, B} + for all u in U -> u = A + for all pre(u) in S that are predecessors of u -> pre(u) = s + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 0 + 30 + for all u in U -> u = B + for all pre(u) in S that are predecessors of u -> pre(u) = s + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 0 + 18 + u* = B + d(u*) = 18 + S = {s, B} + while 2. + U = {A, C, D} + for all u in U -> u = A + for all pre(u) in S that are predecessors of u -> pre(u) = s + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 0 + 30 + for all u in U -> u = C + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 21 + for all u in U -> u = D + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 38 + u* = A + d(u*) = 30 + S = {S, B, A} + while 3. + U = {C, D, E, F} + for all u in U -> u = C + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 21 + for all u in U -> u = D + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 38 + for all u in U -> u = E + for all pre(u) in S that are predecessors of u -> pre(u) = A + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 30 + 20 + for all u in U -> u = F + for all pre(u) in S that are predecessors of u -> pre(u) = A + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 30 + 22 + u* = C + d(u*) = 39 + S = {s, B, A, C} + while 4. + U = {D, E, F, G} + for all u in U -> u = D + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 38 + for all u in U -> u = E + for all pre(u) in S that are predecessors of u -> pre(u) = A + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 30 + 20 + for all u in U -> u = F + for all pre(u) in S that are predecessors of u -> pre(u) = A + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 30 + 22 + for all u in U -> u = G + for all pre(u) in S that are predecessors of u -> pre(u) = C + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 39 + 9 + u* = G + d(u*) = 48 + S = {s, B, A, C, G} + while 5. + U = {D, E, F} + for all u in U -> u = D + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 38 + for all u in U -> u = E + for all pre(u) in S that are predecessors of u -> pre(u) = A + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 30 + 20 + for all u in U -> u = F + for all pre(u) in S that are predecessors of u -> pre(u) = A + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 30 + 22 + u* = E + d(u*) = 50 + S = {s, B, A, C, G, E} + while 6. + U = {D, F} + for all u in U -> u = D + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 38 + for all u in U -> u = F + for all pre(u) in S that are predecessors of u -> pre(u) = A + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 30 + 22 + u* = F + d(u*) = 52 + S = {s, B, A, C, G, E, F} + while 7. + U = {D} + for all u in U -> u = D + for all pre(u) in S that are predecessors of u -> pre(u) = B + d'(u, pre(u)) = d(pre(u)) + w(pre(u), u) + d'(u, pre(u)) = 18 + 38 + u* = D + d(u*) = 56 + S = {s, B, A, C, G, E, F, D} + \end{verbatim} + + Wie zu sehen ist wird die Senke G zuerst erreicht. Folgt man dem Weg zu G, so ergibt sich, dass der kürzeste Pfad von s über B und C nach G führt. Weniger Kosten als 48 sind daher nicht möglich. \end{document}