(See the previous and initial iteration.)
I have this second version of my LaTeX code. I made it less dry by removing the duplicate keyword definitions shared by the two algorithms being typeset. Also, in the previous version, in the argument of main While
loop, OPEN
was typeset instead of desired OPEN
.
See what I have now:
\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\SetArgSty{textnormal} % Make the While argument non-italic
% Define special keywords.
\SetKw{Nil}{nil}
\SetKw{Is}{is}
\SetKw{Not}{not}
\SetKw{Mapped}{mapped}
\SetKw{In}{in}
\SetKw{ChildNode}{child node}
\SetKw{Of}{of}
\SetKw{Continue}{continue}
\begin{document}
% A*.
\begin{algorithm}
$\text{OPEN} = \{ s \}$ \\
$\text{CLOSED} = \emptyset$ \\
$\pi = \{ (s \mapsto$ \Nil $)\}$ \\
$g = \{ (s \mapsto 0) \}$ \\
\While{$|\text{OPEN}| > 0$}{
$u = \textsc{ExtractMinimum}(\text{OPEN})$ \\
\If{$u$ \Is $t$}{
\KwRet \textsc{TracebackPath}$(u, \pi)$ \\
}
$\text{CLOSED} = \text{CLOSED} \cup \{ u \}$ \\
\ForEach{\ChildNode $v$ \Of $u$}{
\If{$v \in \textsc{CLOSED}$}{
\Continue \\
}
$c = g(u) + w(u, v)$ \\
\If{$v$ \Is \Not \Mapped \In $g$}{
$g(v) = c$ \\
$\pi(v) = u$ \\
\textsc{Insert}$(\text{OPEN}, v, c + h(v))$ \\
}
\ElseIf{$g(v) > c$}{
$g(v) = c$ \\
$\pi(v) = u$ \\
\textsc{DecreaseKey}$(\text{OPEN}, v, c + h(v))$ \\
}
}
}
\KwRet $\langle \rangle$
\caption{\textsc{AStarPathFinder}$(s, t, w, h)$}
\end{algorithm}
% Traceback path.
\begin{algorithm}
$p = \langle \rangle$ \\
\While{$u$ \Is \Not \Nil}{
$p = u \circ p$ \\
$u = \pi(u)$ \\
}
\KwRet $p$
\caption{\textsc{TracebackPath}$(u, \pi)$}
\end{algorithm}
\end{document}
The result looks like this:
Any critique is much appreciated.