Typesetting A* in LaTeX using algorithm2e - follow-up
Nice.  I mean if you're going for perfection I'm going to write
something but otherwise that looks really good.


The
documentation for algorithm2e
mentions that every line should be terminated with \; - and then has
a flag to disable showing that semicolon, \DontPrintSemicolon - take
that how you will.  At least Emacs highlights that less garishly than
the forced newline.
The variables could be marked via \SetKwData.  If you want to keep
the same style, modify it via \SetDataSty{textnormal}.  Similarly
for the functions via \SetKwFunction.
The style for the captions could also just be set to smallcaps
globally via \let\AlCapNameSty\textsc (works and should be correct,
but I'm not a \$\LaTeX\$ expert by any means.
Also there's the procedure environment (instead of algorithm) that
has some more shortcuts.  Note that I added procnumbered and
\SetAlgoProcName to set the names and numbering back to what is the
default algorithm settings.


Looks like this:

\documentclass[10pt]{article}

\usepackage{amsmath}
\usepackage[ruled,vlined,linesnumbered,procnumbered]{algorithm2e}

\SetArgSty{textnormal} % Make the While argument non-italic
\SetDataSty{textnormal}
\SetFuncSty{textsc}
\let\AlCapNameSty\textsc
\DontPrintSemicolon
\SetAlgoProcName{Algorithm}

% 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}

\SetKwData{Open}{OPEN}
\SetKwData{Closed}{CLOSED}

\SetKwFunction{ExtractMinimum}{ExtractMinimum}
\SetKwFunction{TracebackPath}{TracebackPath}
\SetKwFunction{Insert}{Insert}
\SetKwFunction{DecreaseKey}{DecreaseKey}

\begin{document}

% A*.
\begin{procedure}
        $\Open = \{ s \}$ \;
        $\Closed = \emptyset$ \;
        $\pi = \{ (s \mapsto$ \Nil $)\}$ \;
        $g = \{ (s \mapsto 0) \}$ \;
        \While{$|\Open| &gt; 0$}{
        $u = \ExtractMinimum(\Open)$ \;
        \If{$u$ \Is $t$}{
            \KwRet \TracebackPath{$u$, $\pi$} \;
        }
        $\Closed = \Closed \cup \{ u \}$ \;
        \ForEach{\ChildNode $v$ \Of $u$}{
            \If{$v \in \Closed$}{
            \Continue \;
            }
            $c = g(u) + w(u, v)$ \;
            \If{$v$ \Is \Not \Mapped \In $g$}{
            $g(v) = c$ \;
            $\pi(v) = u$ \;
            \Insert{\Open, $v$, $c + h(v)$} \;
            }
            \ElseIf{$g(v) &gt; c$}{
            $g(v) = c$ \;
            $\pi(v) = u$ \;
            \DecreaseKey{\Open, $v$, $c + h(v)$} \;
            }
        }
        }
        \KwRet $\langle \rangle$
        \caption{AStarPathFinder($s$, $t$, $w$, $h$)}
\end{procedure}

% Traceback path.
\begin{procedure}
        $p = \langle \rangle$ \;
        \While{$u$ \Is \Not \Nil}{
        $p = u \circ p$ \;
        $u = \pi(u)$ \;
        }
        \KwRet $p$
    \caption{TracebackPath($u$, $\pi$)}
\end{procedure}

\end{document}