我正在尝试编写一个算法并收到以下错误
Missing = inserted for \ifnum. \end{algorithmic}
Command \algorithmic already defined. }
Missing = inserted for \ifnum. \end{algorithmic}
Something's wrong--perhaps a missing \item.
...methodTrace.Method.Owner.DeveloperGold==E}
Something's wrong--perhaps a missing \item. \ENDWHILE
Underfull \vbox (badness 1270) has occurred while \output is active []
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
% The preceding line is only needed to identify funding in the first
%footnote. If that is unneeded, please comment it out.
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm,algpseudocode}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{multirow}
\setlength{\textfloatsep}{0.1cm}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}
\begin{algorithm}
\caption{Calculate $y = x^n$}
\begin{algorithmic}
\FORALL{methodTrace in methodTraceList}
\IF{methodTrace.Method.Owner.DeveloperGold==T} methodTrace.Prediction=E
\ELSIF{methodTrace.Method.Owner.DeveloperGold==N} methodTrace.Prediction=N
\ELSIF{methodTrace.Method.Owner.DeveloperGold==E} methodTrace.Prediction=E
\ENDIF
\ENDFOR
\WHILE{$OldPredictions \neq NewPredictions$}
\FORALL{methodTrace in methodTraceList}
\IF{ \NOT methodtrace.Method.Callees.isEmpty() \AND
\NOT methodtrace.Method.Callers.isEmpty()
\AND methodtrace.Method.Callees.AllTs(methodtrace.Requirement, methodtraces2HashMap)
\AND methodtrace.Method.Callers.AllTs(methodtrace.Requirement, methodtraces2HashMap)
} methodTrace.Prediction=E
\ENDFOR
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
您缺少\ENDIF
最后一个\IF
,并且每个都\IF-\ELSIF
需要一个\STATE
。此外,if-elsif-elsif-end
应该是if-elsif-else-end
。
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
% The preceding line is only needed to identify funding in the first
%footnote. If that is unneeded, please comment it out.
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithm,algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{multirow}
\setlength{\textfloatsep}{0.1cm}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}
\begin{algorithm}
\caption{Calculate $y = x^n$}
\begin{algorithmic}
\FORALL {methodTrace in methodTraceList}
\IF {methodTrace.Method.Owner.DeveloperGold==T} \STATE methodTrace.Prediction=E
\ELSIF {methodTrace.Method.Owner.DeveloperGold==N} \STATE methodTrace.Prediction=N
\ELSIF {methodTrace.Method.Owner.DeveloperGold==E} \STATE methodTrace.Prediction=E
\ENDIF
\ENDFOR
\WHILE {$OldPredictions \neq NewPredictions$}
\FORALL{methodTrace in methodTraceList}
\IF {\NOT methodtrace.Method.Callees.isEmpty() \AND
\NOT methodtrace.Method.Callers.isEmpty()
\AND methodtrace.Method.Callees.AllTs(methodtrace.Requirement, methodtraces2HashMap)
\AND methodtrace.Method.Callers.AllTs(methodtrace.Requirement, methodtraces2HashMap)
} \STATE methodTrace.Prediction=E
\ENDIF
\ENDFOR
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{document}