\begin{algorithm}[H]
\caption{How to write algorithms}
\KwIn{this text}
\KwOut{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;}{
go back to the beginning of current section\;}}
\end{algorithm}
#需要导入以下信息
\usepackage{algorithm}
\usepackage{algpseudocode}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}% Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}}% Use Output in the format of Algorithm
\begin{algorithm}[h]
\caption{Pseudocode of Simulated Annealing Algorithm}% 名称
\begin{algorithmic}[1]
\Require
$x_0$: initial individual or state;
$T_0$: a high enough initial temperature;
$T_{min}$: the lowest limit of temperature;
\Ensure
optimal state or approximate optimal state;
\State set $x_0 = x_{best}$, compute initial energy function $E(x_0)$;
\While {$T > T_{min}$}
\For{$i =1$; $i<n$; $i++$ }
\State perturb current state $x_i$ for a new state $x_{new}$ and compute energy function $E(x_{new})$;
\State compute $\Delta$ = $E(x_{new}-E(x_{(i)})$;
\If {$\Delta$$E<0$} \State $x_{best}= x_{new}$
\Else \State the probability $P = exp(-dE/T_{(i)})$;
\If {$rand(0,1)< P$ }\State $x_{best}= x_{new}$
\Else \State $x_{best}= x_{best}$
\EndIf
\EndIf
\EndFor
\State $T = T * $ $ \alpha$, where $\alpha$ is decay factor ;
\EndWhile
\end{algorithmic}
\end{algorithm}