以下代码给出错误消息:
\documentclass[energies,article,accept,moreauthors,pdftex,10pt,a4paper]{mdpi}
\usepackage{booktabs}
\usepackage{array} \newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
\newcolumntype{C}[1]{>{\PreserveBackslash\centering}m{#1}}
\newcolumntype{R}[1]{>{\PreserveBackslash\raggedleft}m{#1}}
\newcolumntype{L}[1]{>{\PreserveBackslash\raggedright}m{#1}}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{algorithm}[H]
\caption{EDE.}
\label{pseudoEDE}
Parameters initialization ${Max.iter,CR, POP, and h}$\;
Population generation using Equation (\ref{eq:7}) \;
\For {h = 1:H}
{
Compute mutant vector using Equation (\ref{eq:8})\;
\For{iter= 1:Max.iter}
{ Compute first trial vector with CR 0.3\;
\If {$rand() \leq 0.3$}
{$\mu_{j}=\upsilon_{j}$\\
else\\
{$\mu_{j}=x_{j}$}
}
Compute second trial vector with CR 0.6\;
\If {$rand() \leq 0.6$}
{ $\mu_{j}=\upsilon_{j}$\\
else\\
{ $\mu_{j}=x_{j}$ }
}
Compute third trial vector with CR 0.9\;
\If {$rand() \leq 0.9$}
{$\mu_{j}=\upsilon_{j}$\\
else\\
{$\mu_{j}=x_{j}$}
}
Create $4^{th}$ and $5^{th}$ trial vector using Equations (\ref{4_trial}) and (\ref{5_trial})\;
Findout trial vector which is best \;
$X_{new} \gets$ best of $ \mu_{j}$ \;
Compare trial vector with target vector\;
\If {$f({X_{new}}) < f (X_{j})$}
{$X_{j} = X_{new}$}
}
}
\end{algorithm}
\begin{algorithm}[H]
\caption{GWO.}
\label{pseudoGWO}
Parameters initialization ${Maxiter, POP, D, \alpha, \beta, \delta}$\;
Initial population of gray wolves generation $X{i} (i=1,2,...,n)$\;
$X(i,j)= rand (POP, D)$\;
\While {iter $<$ Maxiter}
{
\For{i=1:POP}
{
Compute fitness using Equation (\ref{eq:17})\;
\If {fitness $ < \alpha_{score} $ }
{$\alpha_{score}$=fitness\;
$\alpha_{Pos}$= $X(i, :)$\;}
\If {fitness $ > \alpha_{score}$ and fitness$<\beta_{score }$}
{$\beta_{score}$=fitness\;
$\beta_{Pos}$= $X(i, :)$\;}
\If {fitness $ > \alpha_{score}$ and fitness$>\beta_{score }$ and fitness$<\delta_{score }$}
{$\delta_{score}$=fitness\;
$\delta_{Pos}$= $X(i, :)$\;}
}
\For {i = 1:POP}
{\For {j = 1:D}
{ Create $r1$ and $r2$ randomly with rand command\;
Compute fitness coefficients A and C using Equations (\ref{eq:ENP3}) and (\ref{eq:ENP4})\;
Update values of ${\alpha, \beta$, and $\delta}$ using Equation (\ref{H5})--(\ref{H7})\;
}
}
}
\end{algorithm}\par
\vspace{12pt}
\end{document}
答案1
您给出的代码中存在一些问题:
您需要调用以下包
\usepackage{algorithm2e} % <============================================ \usepackage{pseudocode} % <=============================================
- 我曾经
blindtext
在文档中添加过一些虚拟文本。 - 我添加了一些课堂所需的缺失信息
mdpi
。 我纠正了
$
一些Update values of $\alpha$, $\beta$, and $\delta$ using Equation (\ref{H5})--(\ref{H7})\;
使用以下完整的 MWE
\documentclass[energies,article,accept,moreauthors,pdftex,10pt,a4paper]{mdpi}
%\usepackage{booktabs}
%\usepackage{array}
\usepackage{algorithm2e} % <============================================
\usepackage{pseudocode} % <=============================================
\usepackage{blindtext} % <======================= dummy text in document
%\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
%\newcolumntype{C}[1]{>{\PreserveBackslash\centering}m{#1}}
%\newcolumntype{R}[1]{>{\PreserveBackslash\raggedleft}m{#1}}
%\newcolumntype{L}[1]{>{\PreserveBackslash\raggedright}m{#1}}
%
%\usepackage{multirow}
\Title{Title}
\newcommand{\orcidauthorA}{0000-0000-000-000X}
\Author{Firstname Lastname $^{1,\dagger,\ddagger}$\orcidA{}, Firstname Lastname $^{1,\ddagger}$ and Firstname Lastname $^{2,}$*}
% Authors, for metadata in PDF
\AuthorNames{Firstname Lastname, Firstname Lastname and Firstname Lastname}
% Affiliations / Addresses (Add [1] after \address if there is only one affiliation.)
\address{%
$^{1}$ \quad Affiliation 1; [email protected]\\
$^{2}$ \quad Affiliation 2; [email protected]}
\pubvolume{xx}
\issuenum{1}
\articlenumber{5}
\pubyear{2019}
\copyrightyear{2019}
\history{Received: date; Accepted: date; Published: date}
\begin{document}
\blindtext
\begin{algorithm}%[H]
\caption{EDE.}
\label{pseudoEDE}
Parameters initialization ${Max.iter,CR, POP, and h}$\;
Population generation using Equation (\ref{eq:7}) \;
\For {h = 1:H}
{
Compute mutant vector using Equation (\ref{eq:8})\;
\For{iter= 1:Max.iter}
{ Compute first trial vector with CR 0.3\;
\If {$rand() \leq 0.3$}
{$\mu_{j}=\upsilon_{j}$\\
else\\
{$\mu_{j}=x_{j}$}
}
Compute second trial vector with CR 0.6\;
\If {$rand() \leq 0.6$}
{ $\mu_{j}=\upsilon_{j}$\\
else\\
{ $\mu_{j}=x_{j}$ }
}
Compute third trial vector with CR 0.9\;
\If {$rand() \leq 0.9$}
{$\mu_{j}=\upsilon_{j}$\\
else\\
{$\mu_{j}=x_{j}$}
}
Create $4^{th}$ and $5^{th}$ trial vector using Equations (\ref{4_trial}) and (\ref{5_trial})\;
Findout trial vector which is best \;
$X_{new} \gets$ best of $ \mu_{j}$ \;
Compare trial vector with target vector\;
\If {$f({X_{new}}) < f (X_{j})$}
{$X_{j} = X_{new}$}
}
}
\end{algorithm}
\blindtext
\begin{algorithm}%[H]
\caption{GWO.}
\label{pseudoGWO}
Parameters initialization ${Maxiter, POP, D, \alpha, \beta, \delta}$\;
Initial population of gray wolves generation $X{i} (i=1,2,...,n)$\;
$X(i,j)= rand (POP, D)$\;
\While {iter $<$ Maxiter}
{
\For{i=1:POP}
{
Compute fitness using Equation (\ref{eq:17})\;
\If {fitness $ < \alpha_{score} $ }
{$\alpha_{score}$=fitness\;
$\alpha_{Pos}$= $X(i, :)$\;}
\If {fitness $ > \alpha_{score}$ and fitness$<\beta_{score }$}
{$\beta_{score}$=fitness\;
$\beta_{Pos}$= $X(i, :)$\;}
\If {fitness $ > \alpha_{score}$ and fitness$>\beta_{score }$ and fitness$<\delta_{score }$}
{$\delta_{score}$=fitness\;
$\delta_{Pos}$= $X(i, :)$\;}
}
\For {i = 1:POP}
{\For {j = 1:D}
{ Create $r1$ and $r2$ randomly with rand command\;
Compute fitness coefficients A and C using Equations (\ref{eq:ENP3}) and (\ref{eq:ENP4})\;
Update values of $\alpha$, $\beta$, and $\delta$ using Equation (\ref{H5})--(\ref{H7})\;
}
}
}
\end{algorithm}
\blindtext
\end{document}
我只能通过一个错误进行编译(我没有该类所需的图像):
第二页