以下算法的错误 -inputenc 错误

以下算法的错误 -inputenc 错误
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document

\begin{algorithm}
\caption{PUML Algorithm}
\label{PUML Algorithm}
\begin{algorithmic}[1]
\Procedure{Path\textendash Binary table for Path}{}
    \For {i = 1 to Number of Nodes}
    \For {j = 1 to Number of Nodes}
    \State $fx$ = $\left\{ \begin{array}{rl}$
      $ 1     &  \text{N(i) }  \\ 0$ $& \text{otherwise}$
      $\end{array} \right$
    \If $N (i) connect to N (j)$
        \State Matrix element represent as 1
    \Else
        \State Matrix element represent as 0
    \EndIf
    \EndFor
    \EndFor
    \State $D =\sum f(x)$
    \State $L=max (d)$
    \State  Calculate the node connection for Lth node and place          

    \State Update the binary table by eliminating the node from binary table
    \State Initialize particles
    \State Position of particles = x and y coordinating points of node location.
        \State $Velocity = random (number of nodes)$
        \State Check fitness for given position by using objective function.
        \State $F_{Position}$ = $\sum {i=1}^n$ ${i\times\cos⁡((i+1)\times particle+i)}\times \sum{j=1}^m$ ${j\times\cos⁡((j+1)\times particle+j) + Weight(Particle)}$

        \State $ Minimum (F_Position)$ 
        \State $Velocity= w \times velocity+c1 \times(r1*(L_Position-Position))+c2 \times(r2  \times (G_Position-Position))$
        \State $Position = Position + Velocity$

            \For {k = 1 to iteration}
            \If $Present_fitness < Last_fitness$
            \State Update fitness value
\EndIf
\State $Update velocity and position$
\EndFor
           \State $ Find maximum (fitness value), mf = max (fitness)$
           \State $Place SELECTED INDEX on that node. Pth_((x,y) )=N(Ind(mf))$
           \State $ Update binary table by eliminating the node from binary table$
           \State $Loop to Step 6 until binary table gets empty$

\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

有人能帮助我吗我在以下部分遇到了错误

  \State $fx$ = $\left\{ \begin{array}{rl}$
      $ 1     &  \text{N(i) }  \\ 0$ $& \text{otherwise}$
      $\end{array} \right$
    \If $N (i) connect to N (j)$

并且`

  \State $F_{Position}$ = $\sum {i=1}^n$ ${i\times\cos⁡((i+1)\times particle+i)}\times \sum{j=1}^m$ ${j\times\cos⁡((j+1)\times particle+j) + Weight(Particle)}$

        \State $ Minimum (F_Position)$ 
        \State $Velocity= w \times velocity+c1 \times(r1*(L_Position-Position))+c2 \times(r2  \times (G_Position-Position))$

答案1

您不需要那么多,$尤其是对于array。而且最好在许多地方使用\text(或)。进一步→等等。\mathrmmax\max

\documentclass{article}
\usepackage{algorithm,algpseudocode,amsmath}
\begin{document}

\begin{algorithm}
\caption{PUML Algorithm}
\label{PUML Algorithm}
\begin{algorithmic}[1]
\Procedure{Path\textendash Binary table for Path}{}
    \For {i = 1 to Number of Nodes}
    \For {j = 1 to Number of Nodes}
    \State $f_x = \left\{ \begin{array}{rl}
       1     &  \text{N(i) }  \\ 0 & \text{otherwise}
      \end{array} \right.$
    \If $N (i)$ connect to $N (j)$
        \State Matrix element represent as 1
    \Else
        \State Matrix element represent as 0
    \EndIf
    \EndFor
    \EndFor
    \State $D =\sum f(x)$
    \State $L=\max (d)$
    \State  Calculate the node connection for $L^{\text{th}}$ node and place

    \State Update the binary table by eliminating the node from binary table
    \State Initialize particles
    \State Position of particles $= x$ and $y$ coordinating points of node location.
        \State $\text{Velocity} = \text{random (number of nodes)}$
        \State Check fitness for given position by using objective function.
        \State $F_{\text{Position}}$ = $\sum {i=1}^n$ ${i\times\cos⁡((i+1)\times \text{particle}+i)}\times \sum{j=1}^m$ ${j\times\cos⁡((j+1)\times \text{particle}+j) + \text{Weight(Particle)}}$

        \State  Minimum $(F_\text{Position})$
        \State $\text{Velocity}= w \times \text{velocity}+c1 \times(r1*(L_\text{Position$-$Position}))+c2 \times(r2  \times (G_\text{Position$-$Position}))$
        \State $\text{Position} = \text{Position} + \text{Velocity}$

            \For {k = 1 to iteration}
            \If $ \,\text{Present}_\text{fitness} < \text{Last}_\text{fitness}$
            \State Update fitness value
\EndIf
\State Update velocity and position
\EndFor
           \State  Find maximum (fitness value), $mf = \max (\text{fitness})$
           \State Place SELECTED INDEX on that node. $P^{\text{th}}_((x,y) )=N(Ind(mf))$
           \State  Update binary table by eliminating the node from binary table
           \State Loop to Step 6 until binary table gets empty

\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

在此处输入图片描述

相关内容