GeneralAlgorithm Compilation Errors

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
phloxicon
Posts: 1
Joined: Thu Jul 16, 2009 5:19 pm

Algorithm Compilation Errors

Post by phloxicon »

I'm trying to work on LaTeX from home and I'm getting compiler errors that I wasn't getting in work. Here's the code generating the errors:

Code: Select all

\begin{algorithm}[H]
%\SetLine
	  \SetKwData{OpenList}{openList}
	  \SetKwData{ClosedList}{closedList}
	  \SetKwData{Start}{start}
	  \SetKwData{End}{end}
	  \SetKwData{BestNode}{bestNode}
	  \SetKwData{OpenNode}{openNode}
	  \SetKwData{AdjacentNode}{adjacentNode}
	  \SetKwData{G}{g}
	  \SetKwData{H}{h}
	  \SetKwData{F}{f}
	  \SetKwData{Parent}{parent}
	  
	  \SetKwFunction{Empty}{Empty}
	  \SetKwFunction{IsEmpty}{IsEmpty}
	  \SetKwFunction{IsTraversable}{IsTraversable}
	  \SetKwFunction{HeuristicCostTo}{HeuristicCostTo}
	  \SetKwFunction{CostTo}{CostTo}
	  \SetKwFunction{PopLowestFScoreNode}{PopLowestFScoreNode}
	  \SetKwFunction{Push}{Push}
	  \SetKwFunction{Find}{Find}
	  \SetKwFunction{Exists}{Exists}
	  
	  \SetKwInOut{Input}{input}
	  \SetKwInOut{Output}{output}
	  
		\KwIn{Node start}
		\KwIn{Node end}
  
		\BlankLine
		List \OpenList, \ClosedList\;
		\OpenList$\leftarrow$\Empty{}; \ClosedList$\leftarrow$\Empty{}\;
		\Start.\F = \Start.\G = \Start.\H = 0\;
		\OpenList$\leftarrow$\Push(\Start)\;
		\BlankLine
		\While{ ! \OpenList$\leftarrow$\IsEmpty{} }
		{
				\BestNode = \OpenList$\leftarrow$\PopLowestFScoreNode()\;
				\If {\BestNode == \End} {
				\emph{Iterate from end to start via parents and construct the path}
				}
				\ClosedList$\leftarrow$\Push(\BestNode)\;
				\BlankLine
				\Parent = \BestNode\;
				\ForEach{\AdjacentNode in \BestNode.\AdjacentNode()}
				{
						\If {\AdjacentNode$\leftarrow$\IsTraversable()}
						{
								\If {! \ClosedList$\leftarrow$\Exists {\AdjacentNode}}
								{
										\If {! \OpenList$\leftarrow$\Exists {\AdjacentNode}}
										{
												\AdjacentNode.\H = \HeuristicCostTo{\End}\;
												\AdjacentNode.\G = \Parent.\G + \CostTo{\AdjacentNode}\;
												\AdjacentNode.\F = \AdjacentNode.\G + \AdjacentNode.h\;
												\AdjacentNode.\Parent = \Parent\;
												\OpenList$\leftarrow$\Push(\AdjacentNode)\;
										}
										\Else
										{
												\emph{Edge relaxation}
												\BlankLine
												\OpenNode = \OpenList$\leftarrow$\Find{\AdjacentNode}\;
												\AdjacentNode.\G = \Parent.\G + \CostTo{\AdjacentNode}\;
												\If {\AdjacentNode.\G \leftarrow \OpenNode.\G}
												{
														\OpenNode.\G = \AdjacentNode.\G\;
														\OpenNode.\Parent = \Parent\;
												}
										}
								}
						}
				}
		}
\caption{Pseudo Code of the A* Algorithm}
\end{algorithm}
They error is "\@H is undefined" for the line "\SetKwData{H}{h}". The rest of the errors complain about missing $s and }s but I've double checked and they're all there. Furthermore, it compiled properly in work so I know the code must be fine.

I have included "\usepackage{algorithm2e}" in my code and the .sty file (http://www.ctan.org/tex-archive/macros/ ... gorithm2e/) in the same directory as the project file (which also contains the .tex that contains the code that calls the usepackage). I'm stumped as to what I should do next.





Also, three more small questions regarding TeXnicCenter:
1. Is there a way to quickly comment out (and back in) code that I have highlighted?
2. Is there a way to compile my code without having to go back to the main .tex file? (When I try to do it from one of the \input tex files, I get compiler errors)
3. Is there a way to copy the Build window output so that I can paste it elsewhere (for you guys to see)?



Mainly it's the algorithm thing I would like to know. I really appreciate any help on this. Thanks :D

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
christiem
Posts: 4
Joined: Wed Aug 05, 2009 8:23 pm

Algorithm Compilation Errors

Post by christiem »

I was wondering if you had figured out the problem yet.

It works fine if you change \SetKwData{H}{h} to \SetKwData{HH}{h}, however I have no idea why it thinks H is protected variable..?

p.s. you probably already know, but as for the other {,$ errors, you are missing two $$ around a \leftarrow command.

Code: Select all

\Else
[...]
\If {\AdjacentNode.\G **\leftarrow** \OpenNode.\G}
{
   \OpenNode.\G = \AdjacentNode.\G\;
   \OpenNode.\Parent = \Parent\;
--
"The fish seem to like me", said Tom with baited breath.
Post Reply