在 Latex 中編寫演算法

在 Latex 中編寫演算法

\begin{algorithm}我想要一個 Latex 程式碼,它將使用和編寫以下演算法\begin{algorithmic}。我已經這樣做了

\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

但不知道如何讓其他人喜歡初始化..

輸入:

f: the function to optimize
ps: the swarm size
d: the problem dimension

輸出:

x*: the best fitness value found

初始化:

x_i = (x$_{i1}$,$\cdots$, x_{id}) and v_{i} = (v_{i1}, $\cdots$, $v_{id}$), for all particles in problem space
evaluate f(x_i) in d variables and get pbest_i, (i = 1, $\cdots$, ps) 
gbest $\gets$ best of pbest_i 

使用公式 (7) 計算 V_max

**While** stopping criteria is false do

     Begin Loop for ps times
        Begin Loop for d times
            **update v_i for particle using equation (4)**
            validate for velocity boundaries using V_max
        End
        **generate \tau**
        **update x_i for particle using equation (5) or equation (6)** 
        validate for position boundaries
End

If f(x_i) < f(pbest_i) then 

      pbest_i $\gets$  x_i 
end if

If f(x_i) < f(gbest_i) then 

gbest_i $\gets$ x_i 

end if

**End while**

x* $\gets$ gbest 

Return x*

結束PSO演算法

相關內容