📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / source-code / Pseudocode / label-correction / label-correction.tex
132930 viewsLicense: OTHER
\documentclass{article}1\usepackage[pdftex,active,tightpage]{preview}2\setlength\PreviewBorder{2mm}34\usepackage[utf8]{inputenc} % this is needed for umlauts5\usepackage[ngerman]{babel} % this is needed for umlauts6\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf7\usepackage{amssymb,amsmath,amsfonts} % nice math rendering8\usepackage{braket} % needed for \Set9\usepackage{caption}10\usepackage{algorithm}11\usepackage[noend]{algpseudocode}1213\DeclareCaptionFormat{myformat}{#3}14\captionsetup[algorithm]{format=myformat}1516\begin{document}17\begin{preview}18\begin{algorithm}[H]19\begin{algorithmic}20\Require21\Statex Graph $G = (V, E)$22\Statex Weight from node $i$ to node $j$: $g_{ij} \in \mathbb{R}_0^+$23\Statex Starting node $s \in V$24\Statex End node $t \in V$25\Statex Lower bound to get from node $j$ to $t$: $h_j$ (default: $h_j = 0$)26\Statex Upper bound to get from node $j$ to $t$: $m_j$ (default: $m_j = \infty$)27\Procedure{LabelCorrection}{$G$, $s$, $t$, $h$, $m$}28\State $d_s \gets 0$29\State $d_i \gets \infty \quad \forall i \neq s$ \Comment{Distance of node $i$ from $s$}30\State $u \gets \infty$ \Comment{Distance from $s$ to $t$}31\State $K \gets \{s\}$ \Comment{Choose some datastructure here}32\While{$K$ is not empty}33\State $v \gets K.pop()$34\For{child $c$ of $v$}35\If{$d_v + g_{vc} + h_c < \min(d_c, u)$}36\State $d_c \gets d_v + g_{vc}$37\State $c.parent \gets v$38\If{$c \neq t$ and $c \notin K$}39\State $K.insert(c)$40\EndIf41\If{$c = t$}42\State $u \gets d_v + g_{vt}$43\EndIf44\EndIf45\State $u \gets \min (u, d_c + m_c)$46\EndFor47\EndWhile48\Return $u, t$49\EndProcedure50\end{algorithmic}51\caption{Label correction algorithm: Find shortest path}52\label{alg:label-correction-algorithm}53\end{algorithm}54\end{preview}55\end{document}565758