我必须使用algpseudocode
软件包来改善我的论文看起来更专业
但我无法编译成功。
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{document}
\begin{algorithm}
\caption{AIP}\label{euclid}
\begin{algorithmic}[1]
\Procedure{MyProcedure}{}
\State $\textit{locationAgent} \gets \text{position of }\textit{{agent}}$
\State $\textit{locationMD} \gets \text{position of }\textit{{MD}}$
\If {\textit{distance(eNB,$agent_i$)}}>$\delta$
\BState \emph{loop}:
\State $j \gets \textit{patlen}$
\If {$\textit{string}(i) = \textit{path}(j)$}\Return TURE
\State $j \gets j-1$.
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\EndIf
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto} loop
\EndProcedure
答案1
你遗漏了\EndIf
某个地方。我在清单的第 11 行后插入了一个。只需调整你的代码以告诉Procedure
,第二个 if 循环在哪里结束。
% arara: pdflatex
\documentclass{article}
\usepackage{amsmath}
\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{document}
\begin{algorithm}
\caption{AIP}\label{euclid}
\begin{algorithmic}[1]
\Procedure{MyProcedure}{}
\State \textit{locationAgent} $\gets$ position of \textit{agent}
\State \textit{locationMD} $\gets$ position of \textit{MD}
\If {\textit{distance(eNB,$agent_i$)} $> \delta$}
\BState \emph{loop}:
\State $j \gets \textit{patlen}$
\If {$\textit{string}(i) = \textit{path}(j)$} \Return TRUE
\State $j \gets j-1$.
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\EndIf % put this command to where it's actually needed!
\EndIf
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}