MiKTeX에서 의사 코드를 작성하려고 합니다. 나는 사용했지만 \usepackage{algorithm}
\usepackage{algorithmic}
다음을 얻습니다.
모든 구조(\State, \While, \For, \If)에 대해 정의되지 않은 제어 시퀀스'입니다.
\begin{algorithm}
\caption{PSO}
\label{pseudoPSO}
\begin{algorithmic}[1]
\State Initialize a population of particles with random values positions and velocities from \textit{D} dimensions in the search space
\WHILE{Termination condition not reached}
\For{ Each particle \textit{i}}
\State Adapt velocity of the particle using Equation \ref{eq:1}
\State Update the position of the particle using Equation \ref{eq:2}
\State Evaluate the fitness {$f(\overrightarrow{X}_i)$}
\If{\begin{equation}f(\overrightarrow{X}_i)<f(\overrightarrow{P}_i)\end {equation}
\begin{equation}\overrightarrow{P}_i \gets \overrightarrow{X}_i\end{equation}
\EndIf
\If{\begin{equation}f(\overrightarrow{X}_i)<f(\overrightarrow{P}_g)\end{equation}
\begin{equation}\overrightarrow{P}_g \gets \overrightarrow{X}_i\end{equation}
\EndIf
\EndFor
\ENDWHILE
\end{algorithmic}
\end{algorithm}
답변1
을 로드하고 algorithmic
있지만 의 구문을 사용하고 있습니다 algpseudocode
.
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{PSO}
\label{pseudoPSO}
\begin{algorithmic}[1]
\State Initialize a population of particles with random values positions
and velocities from \textit{D} dimensions in the search space
\While{Termination condition not reached}
\For{Each particle $i$}
\State Adapt velocity of the particle using Equation \ref{eq:1}
\State Update the position of the particle using Equation \ref{eq:2}
\State Evaluate the fitness {$f(\overrightarrow{X}_i)$}
\If{$f(\overrightarrow{X}_i)<f(\overrightarrow{P}_i)$}
\State $\overrightarrow{P}_i \gets \overrightarrow{X}_i$
\EndIf
\If{$f(\overrightarrow{X}_i)<f(\overrightarrow{P}_g)$}
\State $\overrightarrow{P}_g \gets \overrightarrow{X}_i$
\EndIf
\EndFor
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}
특히 .equation
\If
및 는 \WHILE
및 이어야 \ENDWHILE
합니다 .\While
\EndWhile