代码:
\begin{algorithm}[!t]
\begin{algorithmic}[1]
\caption{Adaptive Random Search}\label{algo_ARS}
\State define the probability of local search as $P_s$ and global search as 1 - $P_s$
\Repeat
\State generate a random number r(0,1)
\If{r \leq $P_s$}
\State local search is selected
\Else
\State global search is selected
\Until{$X_{ARS}$ is accepted}
\end{algorithmic}
\end{algorithm}
我编写的伪代码不起作用。我无法获得直到部分作为输出。
答案1
我不知道您具体使用了哪些包,但您可能缺少一个\EndIf
关闭嵌套 if 语句的命令:
\documentclass{article}
\usepackage{algorithm, algpseudocode}
\begin{document}
\begin{algorithm}[!t]
\begin{algorithmic}[1]
\caption{Adaptive Random Search}\label{algo_ARS}
\State define the probability of local search as $P_s$ and global search as $1 - P_s$
\Repeat
\State generate a random number $r(0,1)$
\If{$r \leq P_s$}
\State local search is selected
\Else
\State global search is selected
\EndIf
\Until{$X_\mathrm{ARS}$ is accepted}
\end{algorithmic}
\end{algorithm}
\end{document}