Skip to content

Commit

Permalink
adapted pseudocode
Browse files Browse the repository at this point in the history
  • Loading branch information
adrelino committed Dec 24, 2016
1 parent bcc507c commit 8bc8369
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 98 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Expand Up @@ -10,15 +10,15 @@ module.exports = function(grunt) {
options: {
port: port,
base: base,
livereload: true,
livereload: false,
open: true
}
}
},

watch: {
options: {
livereload: true
livereload: false
},
// js: {
// files: [ 'Gruntfile.js', 'js/reveal.js' ],
Expand Down
16 changes: 14 additions & 2 deletions documentation/contents/chapter3-background.tex
Expand Up @@ -69,6 +69,19 @@ \section{The \maxflow{}}


\section{\pushRelabel{}}
The push-relabel algorithm operates locally and does not, in contrast to the less efficient globally operating maximum flow algorithms based on augmenting paths, maintain a feasible flow during the algorithm execution. Instead, it maintains a preflow. The capacity constraints of the edges are still maintainted, but the flow conservation at the nodes is not:

\begin{definition}[preflow]
The preflow $\tilde f$ is a generalization of the flow $f$, the equality sign $=$ in the flow conservation is replaced with $\geq$. This means that more flow can enter an inner node than leaving it, e.g. we allow leaks in our pipe system.
\end{definition}

Another important concept in in the push-relabel algorithm is the height function, which is an approximation of the distance of a node towards the sink. The local \textit{push} operations try to move \textit{excess} at inner nodes 'downwards' towards the sink. If the current node is at a local minimum and still has excess, we \textit{relabel} the node by increasing its \textit{height} so that subsequent push operations can remove the excess.
\begin{definition}[valid edge with respect to the height function]
An edge $e'=(v,w)$ of the \textbf{residual graph} is valid with respect to the current height function, if $h(v)==h(w)+1$, meaning that the current node is one level above the one to where we wish to push excess to.
\end{definition}

The important property of the push-relabel algorithm is that when the algorithm terminates, the computed preflow is actually a flow!

\input{pseudocode/pseudocode-maxflow}


Expand Down Expand Up @@ -106,10 +119,9 @@ \section{The \spprc{}}
\begin{example}[SPPTW]
An illustrative example is the two-resource SPPRC, the shortest path problem with time windows (SPPTW). In addition to the \textit{cost} $c$, each edge additionally bears the resource \textit{time} $t$. Thus each edge is associated with the two-dimensional resource vector $(t,c) \forall e \in E$. The secondary resource \textit{time} is constrained, while the primary resource \textit{cost} is unconstrained, but seeks to be minimized.

The accumulated consumptions of the resource \textit{time} along a path are constrained at the intermediate vertices along that path by lower and upper limits, that is the earliest arrival time $t_a$ and the latest departure time $t_b$ and called the \textit{resource window}, denoted as a tuple $[t_a,t_b] \forall v \in V$.
The accumulated consumptions of the resource \textit{time} along a path are constrained at the intermediate vertices along that path by lower and upper limits, that is the earliest arrival time $t_a$ and the latest departure time $t_b$ and called the \textit{resource window}, denoted as tuples $[t_a,t_b] \, \forall v \in V$.
\end{example}

$[t_{arrival},t_{departure}] \forall v \in V$


\section{\labelSetting{}}
Expand Down
35 changes: 16 additions & 19 deletions documentation/pseudocode/pseudocode-maxflow.tex
Expand Up @@ -6,42 +6,39 @@

\begin{algorithm}[h!]
\caption{Goldberg-Tarjan Push-Relabel algorithm}
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon instead
\KwIn{directed Graph $G=(V,E)$ with
\begin{itemize}
\setlength\itemsep{0pt}
\setlength{\parskip}{0pt}
\item digraph $G=(V,E)$ with start $s$, sink $t$
\item $\forall$ edges $e \in E$: (cap) capacity
\end{itemize}
\DontPrintSemicolon
\KwIn{digraph $G=(V,E)$ with nodes $s,t \in V$ and edge capacities $c(e) \, \forall e \in E$
%\begin{itemize}
% \setlength\itemsep{0pt}
% \setlength{\parskip}{0pt}
% \item nodes start $s \in V$, sink $t \in V$
% \item edge capacities $c(e) \, \forall e \in E$
%\end{itemize}
}
\KwOut{A feasible maximum s-t flow f(e)}\vspace{0.2cm}
(* Initialize the preflow *)\;
\ForAll{$e=(u,w) \in E$}{
\If{$u==s$}{
$f(e) \gets c(e)$\;
\If{$w \neq t$}{$Q$.add(w)}
}
\Else{$f(e) \gets 0$}
$f(e) \gets (u==s) \; ? \; c(e) : 0$\;
\If{$u==s$ AND $w \neq t$}{$Q$.add(w)}
}
((* Initialize the height function *))\;
$h(s) = |V|$\;
\ForAll{$v \in V$}{
$h(v) \gets$ number of arcs on directed v-t path\;
$h(s) \gets |V|$\;
\ForAll{$v \in V \setminus \{s \}$}{
$h(v) \gets$ number of arcs on shortest v-t path\;
}
((* Main Loop *))\;
\While{$\setfont{Q} \neq \emptyset$}{
$v \gets \setfont{Q}$.pop()\;
\While{$e(v)>0$ AND $\exists e'=(v,w) \in E' | h(v)==h(w)+1$}{
\While{$e(v)>0$ AND $\exists \, e'=(v,w) \in E' \, | \, h(v)==h(w)+1$}{
(* Push *)\;
push $\min(e(v),c'(e'))$ flow from v to w\;
\If{$w \neq s,t$ AND $w \notin \setfont{Q}$}{
$\setfont{Q}$.add($w$)\;
}
}
\If{$e(v)>0$ AND $\not\exists e'=(v,w) \in E' | h(v)==h(w)+1$}{
\If{$e(v)>0$}{
(* Relabel *)\;
$h(v) \gets 1 + \min(h(w) | e*=(v,w)\in E'$ \;
$h(v) \gets 1 + \min(\{h(w) | e^*=(v,w)\in E'\})$ \;
$\setfont{Q}$.add($v$) \;
}
}
Expand Down
38 changes: 17 additions & 21 deletions documentation/pseudocode/pseudocode-spprc.tex
Expand Up @@ -6,34 +6,30 @@

\begin{algorithm}[h!]
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon instead
\KwIn{directed Graph $G=(V,E)$ with
\begin{itemize}
\setlength\itemsep{0pt}
\setlength{\parskip}{0pt}
\item $\forall$ nodes $v \in V$: [arrive, depart] time window resource constraint
\item $\forall$ edges $e \in E$: (time,cost) 2-dimensional resource consumptions
\item start Node $s$, end Node $t$
\end{itemize}}
\KwOut{feasible, pareto-optimal $s \rightarrow t$ paths} \vspace{0.2cm}
\KwIn{digraph $G=(V,E)$ with start node $s \in V$, target node $t \in V$, resource windows for all nodes %$[t_a, t_d] \, \forall v \in V$
and resource vectors for all edges} %$(t,c) \, \forall e \in E$}
\KwOut{feasible, pareto-optimal $s$-$t$ path $l^*$ with minimal cost} \vspace{0.2cm}
(* Initialize *) \;
SET $\setfont{U} = \{(s)\}$ and $\setfont{P} = \emptyset$ \;
\While{$\setfont{U} \neq \emptyset$}{
$U \gets \{(\epsilon,s)\}$ and $P \gets \emptyset$ \;
(* Main Loop *) \;
\While{$\exists l=(\sim,v) \in U$}{
$U \gets U \setminus \{l\}$\;
(* Path extension step *)\;
CHOOSE a path $\setfont{Q} \in \setfont{U}$ and REMOVE $\setfont{Q}$ from $\setfont{U}$\;
\ForAll{arcs $(v(\setfont{Q}), w) \in A$ of the forward star of $v(\setfont{Q})$}{
\If{$(\setfont{Q},w) \in \setfont{F}(s,w) \cap \setfont{G}$}{
ADD $(\setfont{Q},w)$ to $\setfont{U}$
\ForAll{$e=(v,w) \in E$}{
$l'=(l,w) \gets$ EXTEND$(l,e)$\;
\If{$l' \in \mathrm{FEASIBLE}(w)$}{
$U \gets U \cup \{l'\}$\;
}
}
ADD $\setfont{Q}$ to $\setfont{P}$\;
$P \gets P \cup \{l\}$\;
(* Dominance step *)\;
\If{(* any condition *)}{
APPLY dominance algorithm to paths from $\setfont{U} \cup \setfont{P}$ ending at some node $v$\;
\ForAll{$v \in V\setminus\{s\}$}{
$U,P \gets$ REMOVE-DOMINATED$(U,P)$\;
}
}
(* Filtering step *)\;
FILTER $\setfont{P}$, i.e., identify a solution $\setfont{S} \subseteq \setfont{P}$\;
\caption{Generic Dynamic Programming SPPRC Algorithm}
((* Filtering step *))\;
$l^* \in P \; | \; cost(l^*) ==\min( \{ cost(l=(\sim,t)\in P) \} )$\;
\caption{Generic Dynamic Programming SPPTW Label Setting Algorithm}
\end{algorithm}


Expand Down
2 changes: 1 addition & 1 deletion implementation/library-d3-svg/js/AlgorithmTab.js
Expand Up @@ -88,7 +88,7 @@ function AlgorithmTab(algo,p_tab) {
return "pseudocode";
});

d3.select("#tw_div_statusPseudocode").text(pseudocode.text())
d3.select("#tw_div_statusPseudocode").html(pseudocode.html())

Tab.prototype.init.call(this);

Expand Down
2 changes: 1 addition & 1 deletion implementation/library-d3-svg/js/GraphDrawer.js
Expand Up @@ -101,7 +101,7 @@ GraphDrawer = function(svgOrigin,extraMargin,transTime){
left: global_KnotenRadius+wS +(extraMargin.left || 0)
}

var width = xRange - margin.left - margin.right,
var width = xRange - margin.left - margin.right;
var height = yRange - margin.top - margin.bottom;

this.height = height;
Expand Down
44 changes: 22 additions & 22 deletions implementation/maxflow-push-relabel/index_en.html
Expand Up @@ -416,27 +416,25 @@ <h3>Finished</h3>
<div><p>s &larr; pick(v)</p></div>
<div><p>t &larr; pick(v)</p></div>
<div><p>BEGIN</p></div>
<div><p>(* Initializing the preflow *)</p>
<p> FORALL e=(u,w) &isin; E</p>
<p> IF u == s THEN f(e) &larr; c(e)</p>
<p> ELSE f(e) &larr; 0</p>
<p> IF u == s AND w &ne; t THEN Q.add(w)</p></div>
<div><p>(* Initializing the height function *)</p>
<p> h(s) = |V|</p>
<p> FORALL v &isin; V\{s}</p>
<p> h(v) &larr; #arcs on directed v-t path</p></div>
<div><p>(* Initialize the preflow *)</p>
<p>FORALL e=(u,w) &isin; E</p>
<p> f(e) &larr; (u == s) ? c(e) : 0</p>
<p> IF u == s AND w &ne; t THEN Q.add(w)</p></div>
<div><p>(* Initialize the height function *)</p>
<p>h(s) &larr; |V|</p>
<p>FORALL v &isin; V\{s}</p>
<p> h(v) &larr; #arcs on shortest v-t path</p></div>
<div><p>(* Main Loop *)</p>
<p> WHILE Q &ne; &empty;</p>
<p> v &larr; Q.pop()</p></div>
<div><p> WHILE e(v)>0 </p>
<p> AND &exist; e'=(v,w)&isin;E'|h(v)==h(w)+1</p></div>
<div><p> (* PUSH *)</p>
<p> push min{e(v),c'(e')} flow from v to w</p>
<p> IF w != s,t AND w &notin; Q THEN Q.add(w)</p></div>
<div><p> IF e(v)>0 AND &#8708; e'=(v,w)&isin;E'|h(v)==h(w)+1</p></div>
<div><p> (* RELABEL *)</p>
<p> h(v) &larr; 1+min{h(w)|e*=(v,w)&isin;E'}</p>
<p> Q.add(v)</p></div>
<p>WHILE Q &ne; &empty;</p>
<p> v &larr; Q.pop()</p></div>
<div><p> WHILE e(v)>0 AND &exist; e'=(v,w)&isin;E'|h(v)==h(w)+1</p></div>
<div><p> (* PUSH *)</p>
<p> push min(e(v),c'(e')) flow from v to w</p>
<p> IF w &ne; s,t AND w &notin; Q THEN Q.add(w)</p></div>
<div><p> IF e(v)>0</p></div>
<div><p> (* RELABEL *)</p>
<p> h(v) &larr; 1+min({h(w)|e*=(v,w)&isin;E'})</p>
<p> Q.add(v)</p></div>
<div><p>END</p></div>
</div>
<!-- </div> -->
Expand Down Expand Up @@ -544,8 +542,10 @@ <h3>What is the pseudocode of the algorithm?</h3>
The flow value of f(e) is maximized along all feasible flows
</code></pre><!-- , which fulfills the capacity constraints f(e) leq c(e) for all edges, flow conservation at all inner nodes and maximises the flow value over all feasible flows. -->
<hr>
<pre><code id=tw_div_statusPseudocode>
</code></pre>
<!-- <pre><code id=tw_div_statusPseudocode>
</code></pre> -->
<div id=tw_div_statusPseudocode>
</div>
</div>
<h3>How fast is the algorithm?</h3>
<div>
Expand Down
63 changes: 33 additions & 30 deletions implementation/spp-rc-label-setting/index_en.html
Expand Up @@ -421,31 +421,31 @@ <h3>Filtering step</h3>
var STATUS_DOMINANCE = id++;
var STATUS_DOMINANCE_NODE = id++;
var STATUS_FINISHED = id;-->
<div class="PseudocodeWrapper" id="ta_div_statusPseudocode">
<div><p>s &larr; pick(v)</p></div>
<div><p>BEGIN</p></div>
<div><p>(* Initialize *)</p>
<p>U &larr; {(&epsilon;,s)}, P &larr; &empty;</p></div>
<div><p>(* Main Loop *)</p>
<p>WHILE &exist; l=(~,v) &in; U</p></div>
<!-- <p>WHILE U &ne; &empty; DO</p>
<!-- <p>WHILE U &ne; &empty; DO</p>
<p> l=(~,v) &larr; U.pop()</p></div> -->
<div><p> (* Path extension step *)</p>
<p> FORALL e=(v,w) &isin; E</p>
<p> l'=(l,w) &larr; EXTEND(l,e)</p></div>
<div><p> IF l' &isin; FEASIBLE(w)</p>
<p> U &larr; U &cup; {l'}</p></div>
<div><p> ELSE</p>
<p> throw away l'</p></div>
<div><p> P &larr; P &cup; {l}</p></div>
<div><p> (* Dominance step *)</p>
<p> FORALL v &isin; V\{s}</p></div>
<div><p> U,P &larr; REMOVE-DOMINATED(U,P)</p></div>
<div><p>END</p>
<p>t &larr; pick(v)</p>
<p>(* Filtering step *)</p>
<p>solution &larr; l=(~,t) &in; P : </p>
<p>cost(l) = min(cost(l)) &forall; l=(~,t) &in; P </p></div>
<div class="PseudocodeWrapper" id="ta_div_statusPseudocode">
<div><p>s &larr; pick(v)</p></div>
<div><p>BEGIN</p></div>
<div><p>(* Initialize *)</p>
<p>U &larr; {(&epsilon;,s)} and P &larr; &empty;</p></div>
<div><p>(* Main Loop *)</p>
<p>WHILE &exist; l=(~,v) &in; U</p>
<p> U &larr; U \ {l}</p></div>
<div><p> (* Path extension step *)</p>
<p> FORALL e=(v,w) &isin; E</p>
<p> l'=(l,w) &larr; EXTEND(l,e)</p></div>
<div><p> IF l' &isin; FEASIBLE(w)</p>
<p> U &larr; U &cup; {l'}</p></div>
<div><p> ELSE</p>
<p> throw away l'</p></div>
<div><p> P &larr; P &cup; {l}</p></div>
<div><p> (* Dominance step *)</p>
<p> FORALL v &isin; V\{s}</p></div>
<div><p> U,P &larr; REMOVE-DOMINATED(U,P)</p></div>
<div><p>END</p>
<p>(* Filtering step *)</p>
<p>t &larr; pick(v)</p>
<p>l* &in; P | cost(l*) == min({cost(l=(~,t)&in;P)}) </p></div>
</div>
<!-- </div> -->
<h3>Variable status</h3>
Expand Down Expand Up @@ -560,14 +560,17 @@ <h2>Negative cycles: Label-setting vs. Label-correcting</h2>
<h3>What is the pseudocode of the algorithm?</h3>
<div>
<pre><code>
Input: Weighted, undirected graph G=(V,E) with weight function l.
Output: A list {d(v[j]) : j = 1,..,n} containing the distances dist(v[1],v[j]) = d(v[j]),
if there are no negative circles reachable from v[1].
The message "Negative Circle" is shown, if a negative circle can be reached from v[1].
Input: directed graph G=(V,E) with
start node s and end node t
resource windows for all nodes
resource vectors for all edges
Output: feasible, pareto-optimal s-t path l* with minimal cost
</code></pre>
<hr>
<pre><code id=tw_div_statusPseudocode>
</code></pre>
<!-- <pre><code id=tw_div_statusPseudocode>
</code></pre> -->
<div id=tw_div_statusPseudocode>
</div>
</div>
<h3>How fast is the algorithm?</h3>
<div>
Expand Down

0 comments on commit 8bc8369

Please sign in to comment.