正如您在我的乳胶中看到的那样,它显示在If语句之后结束,该语句假定在Else之后结束。我尝试删除IF的花括号,但不起作用。
\documentclass[journal]{IEEEtran}
\ifCLASSINFOpdf
\usepackage[pdftex]{graphicx}
\usepackage[dvips]{graphicx}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amsfonts}
\usepackage{amssymb,mathtools}
\usepackage[linesnumbered,ruled,vlined] {algorithm2e}
\usepackage{nomencl}
\usepackage{algpseudocode}
\usepackage{algorithm}
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\begin{algorithm}
\caption{PEC, \texttt{PEC}}
\SetAlgoLined
\DontPrintSemicolon
\textbf{Input:} I, P, C.
\textbf{Output:} Set of $PS^*$= $\{{PS_{1},PS_{2}, ...,PS_{n}}\}$
//Initialization
\quad \quad \quad $PS^* \gets \emptyset$
\For {each, $i \in I$} {
// Calculate
$PS^{temp}_{i} \gets P$
$PS^{loss}_{i} \gets C)$
\If { $ C_{i}- P_{i} > 0$}{
$PS_{i} \gets $($PS^{temp}_{i} - PS^{loss}_{i}$)
}
\Else {
$PS_{i} \gets 0$
}
}
return ($PS^*$)
\label{alg:PoEG}
\end{algorithm}
\end{document}
该问题的输出如下,您将看到突出显示的end,我需要消除它。
由于两个主要问题,您的代码无法编译:
您不得使用冲突的选项多次加载graphicx软件包。如果自“石器时代”以来,您的tex发行版本至少已更新一次,则最好不加选择地加载它,并让乳胶确定必要的驱动程序本身。
您不得为算法加载冲突的程序包。确定要使用的那个并加载它。Latex非常清楚地为您提供有关已定义命令的错误消息,请不要忽略错误!!!!
...然后还有一些其他的不便之处end
:只需使用\eIf
宏而不是\If
如果您有in-else语句
最后是一个建议:如果您不希望手动将\quad
s弄乱,而是使用适当的关键字,事情会自动对齐
\documentclass[journal]{IEEEtran}
\ifCLASSINFOpdf
%\usepackage[pdftex]{graphicx}
%\usepackage[dvips]{graphicx}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amsfonts}
\usepackage{amssymb,mathtools}
\usepackage{algpseudocode}
%\usepackage{algorithm}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{nomencl}
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\begin{algorithm}
\caption{Proof of Energy Generation, \texttt{PoEG}}
\SetAlgoLined
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}
\DontPrintSemicolon
\Input{Prosumer Set, $\textit{I}=\{{\textit{I}_{1},\textit{I}_{2},...,\textit{I}_{n}}$\},\linebreak
Predicted energy production, $\textit{P}= \{{\textit{P}_{1},\textit{P}_{2},...,\textit{P}_{n}}$\}, \linebreak
Predicted energy consumption, $\textit{C}= \{{\textit{C}_{1},\textit{C}_{2},...,\textit{C}_{n}}.$\},\linebreak
Distance from DS, $\textit{D}= \{{\textit{d}_{1},\textit{d}_{2},...,\textit{d}_{n}}$\}.}
\Output{Set of $PS^*$= $\{{PS_{1},PS_{2}, ...,PS_{n}}\}$ }
//Initialization
\quad \quad \quad $PS^* \gets \emptyset$
\For {each prosumers, $i \in I$} {
// Calculate proof score for energy balance and loss,
$PS^{temp}_{i} \gets \log(1/e^{C_i-P_i})$
$PS^{loss}_{i} \gets \log(e^{E_{d_i}})$
\eIf { $ C_{i}- P_{i} > 0$}{
$PS_{i} \gets $($PS^{temp}_{i} - PS^{loss}_{i}$)
}{
$PS_{i} \gets 0$
}
$PS^* \gets$ $PS^* \cup \{PS_{i}\}$
}
return ($PS^*$)
\label{alg:PoEG}
\end{algorithm}
\end{document}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句