2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 14:28:05 +02:00

improved pseudocode

This commit is contained in:
Martin Thoma 2013-02-11 13:31:07 +01:00
parent e00050d8f7
commit 7c4cef9698

View file

@ -33,21 +33,22 @@
\State $f(s,v) \gets c(s,v)$ \Comment{Push maximum flow out at the beginning} \State $f(s,v) \gets c(s,v)$ \Comment{Push maximum flow out at the beginning}
\State $r(v,s) \gets c(v,s) - f(v,s)$ \State $r(v,s) \gets c(v,s) - f(v,s)$
\State $dist(v) \gets 0$ \State $dist(v) \gets 0$
\State $e(v) \gets c(s,v)$ \Comment{$v$ has to much flow} \State $e(v) \gets c(s,v)$ \Comment{$v$ has too much flow}
\EndFor \EndFor
\\ \\
\While{$\exists v \in V:$ \Call{isActive}{v}} \While{$\exists v \in V:$ \Call{isActive}{$v$}}
\If{\Call{isPushOk}{v}} \If{\Call{isPushOk}{$v$}}
\State \Call{Push}{v} \State \Call{Push}{$v$}
\ElsIf{\Call{isRelabelOk}{v}} \EndIf
\State \Call{Relabel}{v} \If{\Call{isRelabelOk}{$v$}}
\State \Call{Relabel}{$v$}
\EndIf \EndIf
\EndWhile \EndWhile
\\ \\
\State \Return $f$ \Comment{Maximaler Fluss} \State \Return $f$ \Comment{Maximaler Fluss}
\EndFunction \EndFunction
\\ \\
\Function{Push}{Graph $D$, Flow $f$, Node $v$, Node $w$} \Function{Push}{Node $v$, Node $w$}
\State $\Delta \gets \min\Set{e(v), r_f(v,w)}$ \State $\Delta \gets \min\Set{e(v), r_f(v,w)}$
\State $f(v,w) \gets f(v,w) + \Delta$ \State $f(v,w) \gets f(v,w) + \Delta$
\State $f(w,v) \gets f(w,v) - \Delta$ \State $f(w,v) \gets f(w,v) - \Delta$
@ -65,16 +66,16 @@
\EndIf \EndIf
\EndFunction \EndFunction
\\ \\
\Function{isActive}{Node v} \Function{isActive}{Node $v$}
\State\Return $(e(v) > 0) \land (dist(v) < \infty)$ \State\Return $(e(v) > 0) \land (dist(v) < \infty)$
\EndFunction \EndFunction
\\ \\
\Function{isRelabelOk}{Node v} \Function{isRelabelOk}{Node $v$}
\State\Return \Call{isActive}{v} $\land (\forall w \in \Set{r_f(v,w) >0}: dist(v) \leq dist(w))$ \State\Return \Call{isActive}{$v$} $\displaystyle \bigwedge_{w \in \Set{w \in V | r_f(v,w) >0}}(dist(v) \leq dist(w))$
\EndFunction \EndFunction
\\ \\
\Function{isPushOk}{Node v} \Function{isPushOk}{Node $v$}
\State\Return \Call{isActive}{v} $\land (r_f > 0) \land (dist(v) == dist(w)+1)$ \State\Return \Call{isActive}{$v$} $\land (e(v) > 0) \land (dist(v) == dist(w)+1)$
\EndFunction \EndFunction
\end{algorithmic} \end{algorithmic}
\caption{Algorithm of Goldberg and Tarjan} \caption{Algorithm of Goldberg and Tarjan}