0

The following code gives error message:

\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} 
  • 3
    What is the error? – jaspast Apr 3 at 16:31
  • 3
    Where is mdpi.cls? By the way, you don't have \end{document}. Moreover, in Update values of ${\alpha, \beta$, and $\delta}$ using... (the seventh line from below), for what purpose are the { and } supposed to do? – user156344 Apr 3 at 16:32
  • 1
    @JouleV - I suspect that the second \begin{document} is supposed to be \end{document}... – Mico Apr 3 at 16:47
  • The error is \begin{algorithm} ?@ jaspast – Ghulam Hafeez Apr 17 at 17:02
4

In your given code there are some issues:

  1. You need to call the following packages

    \usepackage{algorithm2e} % <============================================
    \usepackage{pseudocode} % <=============================================
    
  2. I used blindtext to get some dummy text into the document.
  3. I added some missing informations needed for class mdpi.
  4. I corrected some $ in line

    Update values of $\alpha$, $\beta$, and $\delta$ using Equation (\ref{H5})--(\ref{H7})\;
    

With the following complete 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; e-mail@e-mail.com\\
$^{2}$ \quad Affiliation 2; e-mail@e-mail.com}

\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}

I can compile with only one error (I do not have the needed image for the class):

first page

and the second page

second page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.