算法:ELSEIF 问题

算法:ELSEIF 问题

我想在 Latex 中编译此代码(如下所示)。我使用三个库。我特别需要elseif\state命令和line number

LaTeX 错误:

Command \algorithmicindent already defined.Or name \end... illegal,
see p.192 of the manual.See the LaTeX manual or LaTeX Companion for
explanation.Type H <return> for immediate help....
\newlength{\algorithmicindent}

梅威瑟:

\documentclass[12pt]{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
%\usepackage{algorithmic}

\begin{document}

\begin{algorithm}
\caption{Offloading decision}\label{offloading_decision_pseudocode}
\begin{algorithmic}[1]
\State Known: Smartphone to Edge Cloud and Smartphone to Core Cloud bandwidth,
smartphone to Edge Cloud and smartphone to Core Cloud RTT,
smartphone and Edge/Core Cloud processor speed,
Edge and Core Cloud processing cost
\State Set weights $w1$, $w2$, $w3$ based on user preferences 
\State Estimate $T_{L}$, $T_{R-edge}$, $T_{R-Core}$ (section \ref{estimate_processing_time})
\State Estimate $E_{L}$, $E_{R-edge}$, $E_{R-Core}$ (section \ref{estimate_energy_consumption})
\State Estimate $C_{L}$, $C_{R-edge}$, $C_{R-Core}$ (section \ref{estimate_processing_cost})
\State Compute $P_{s}$, $P_{E}$, $P_{C}$ 
\If {$P_{s}\: is\: maximum $} 
    \State
     \ElseIf {$P_{E}$ is maximum}
\EndIf
\If {$i > \textit{stringlen}$} \Return false
\EndIf
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto} \emph{top}.
\end{algorithmic}
\end{algorithm}
\end{document}

答案1

  1. algpseudocode定义了命令\ElsIf,而不是\ElseIF
  2. 正如@DG'所注意到的,删除\usepackage{algoritmic}
  3. 如果您使用则\usepackage{algpseudocode}不必\usepackage{algortihmicx}明确调用!

    \documentclass[12pt]{article}
     \usepackage{algorithm}
     \usepackage{algpseudocode}
     %\usepackage{algorithmic}
    
    \begin{document}
    
    \begin{algorithm}
    \caption{Offloading decision}\label{offloading_decision_pseudocode}
    \begin{algorithmic}[1]
    \State Known: Smartphone to Edge Cloud and Smartphone to Core Cloud bandwidth,
    smartphone to Edge Cloud and smartphone to Core Cloud RTT,
    smartphone and Edge/Core Cloud processor speed,
    Edge and Core Cloud processing cost
    \State Set weights $w1$, $w2$, $w3$ based on user preferences 
    \State Estimate $T_{L}$, $T_{R-edge}$, $T_{R-Core}$ (section \ref{estimate_processing_time})
    \State Estimate $E_{L}$, $E_{R-edge}$, $E_{R-Core}$ (section \ref{estimate_energy_consumption})
    \State Estimate $C_{L}$, $C_{R-edge}$, $C_{R-Core}$ (section \ref{estimate_processing_cost})
    \State Compute $P_{s}$, $P_{E}$, $P_{C}$ 
    \If {$P_{s}\: is\: maximum $} 
        \State
         \ElsIf {$P_{E}$ is maximum}
    \EndIf
    \If {$i > \textit{stringlen}$} \Return false
    \EndIf
    \State $i \gets i-1$.
    \State \textbf{goto} \emph{loop}.
    \State \textbf{close};
    \State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
    \State \textbf{goto} \emph{top}.
    \end{algorithmic}
    \end{algorithm}
    \end{document}
    

相关内容