📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / source-code / Pseudocode / Goldberg-Tarjan-Push-Relabel / Goldberg-Tarjan-Push-Relabel.tex
132930 viewsLicense: OTHER
\documentclass{article}1\usepackage[pdftex,active,tightpage]{preview}2\setlength\PreviewBorder{2mm}34\usepackage{amssymb,amsmath,amsfonts} % nice math rendering5\usepackage{braket} % needed for \Set6\usepackage{algorithm,algpseudocode}78\begin{document}9\begin{preview}10\begin{itemize}11\item $c:E \rightarrow \mathbb{R}_0^+$: capacity of an edge12\item $e: V \rightarrow \mathbb{R}_0^+$: excess (too much flow in one node)13\item $r_f: V \times V \rightarrow \mathbb{R}, \; r_f(u,v) := c(u,v) - f(u,v) $: remaining capacity14\item $dist: V \rightarrow \mathbb{N}$: the label (imagine this as height)15\end{itemize}1617\begin{algorithm}[H]18\begin{algorithmic}19\Function{PushRelabel}{Network $N(D, s, t, c)$}20\ForAll{$(v,w) \in (V \times V \setminus E)$} \Comment{If an edge is not in $D=(V,E)$,}21\State $c(v,w) \gets 0$ \Comment{then its capacity is 0}22\EndFor23\\24\ForAll{$(v,w) \in V \times V$} \Comment{At the beginning, every edge}25\State $f(v,w) \gets 0$ \Comment{has flow=0}26\State $r_f(v,w) \gets c(v,w)$ \Comment{flow=max in the residualgraph}27\EndFor28\\29\State $dist(s) \gets |V|$3031\ForAll{$v \in V \setminus \Set{s}$}32\State $f(s,v) \gets c(s,v)$ \Comment{Push maximum flow out at the beginning}33\State $r(v,s) \gets c(v,s) - f(v,s)$34\State $dist(v) \gets 0$35\State $e(v) \gets c(s,v)$ \Comment{$v$ has too much flow}36\EndFor37\\38\While{$\exists v \in V:$ \Call{isActive}{$v$}}39\If{\Call{isPushOk}{$v$}}40\State \Call{Push}{$v$}41\EndIf42\If{\Call{isRelabelOk}{$v$}}43\State \Call{Relabel}{$v$}44\EndIf45\EndWhile46\\47\State \Return $f$ \Comment{Maximaler Fluss}48\EndFunction49\\50\Function{Push}{Node $v$, Node $w$}51\State $\Delta \gets \min\Set{e(v), r_f(v,w)}$52\State $f(v,w) \gets f(v,w) + \Delta$53\State $f(w,v) \gets f(w,v) - \Delta$54\State $r_f(v,w) \gets r_f(v,w) - \Delta$55\State $r_f(w,v) \gets r_f(w,v) + \Delta$56\State $e(v) \gets e(v) - \Delta$57\State $e(w) \gets e(w) + \Delta$58\EndFunction59\\60\Function{Relabel}{Node $v$}61\If{$\Set{w \in V |r_f(v,w) > 0} == \emptyset$}62\State $dist(v) \gets \infty$63\Else64\State $dist(v) \gets \min\Set{dist(w)+1|w \in V: r_f(v,w) > 0}$65\EndIf66\EndFunction67\\68\Function{isActive}{Node $v$}69\State\Return $(e(v) > 0) \land (dist(v) < \infty)$70\EndFunction71\\72\Function{isRelabelOk}{Node $v$}73\State\Return \Call{isActive}{$v$} $\displaystyle \bigwedge_{w \in \Set{w \in V | r_f(v,w) >0}}(dist(v) \leq dist(w))$74\EndFunction75\\76\Function{isPushOk}{Node $v$}77\State\Return \Call{isActive}{$v$} $\land (e(v) > 0) \land (dist(v) == dist(w)+1)$78\EndFunction79\end{algorithmic}80\caption{Algorithm of Goldberg and Tarjan}81\label{alg:seq1}82\end{algorithm}83\end{preview}84\end{document}858687