\documentclass[a4paper,11pt]{article}
\usepackage{siunitx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{textcomp}
\usepackage{mathpazo}
\usepackage{eulervm}
\usepackage[utf8]{inputenc}
\usepackage{algorithmic}
\usepackage{ifthen}
\usepackage{amsmath}
\DeclareUnicodeCharacter{2212}{\textminus}% requires a Unicode capable editor
\sisetup{
detect-mode,
detect-family,
detect-inline-family=math,}
\begin{document}
\begin{algorithm}
\caption{PPO}
\begin{algorithmic}[1]
\For {$i=1,2,\ldots ,m$}
\EndFor
\For {$i=1,2,\ldots,m$}
\State $forbidden\_set\leftarrow\theta$
\State ${u}\leftarrow\ {p}[i]$
\State ${v\leftarrow\ {get}\_original\_node(u)}$
\For {each node $s$ that adjacent to $u$}
\IF{$c[$s$]!\= -1$}
\State ${v\leftarrow\ {get}\_original\_node(s)}$
\State ${a\leftarrow\ Max}\rbra\_original\_node(u)}$
\ENDIF
\State Run policy $\pi_{\theta_{old}}$ in environment for $T$ time steps
\State Compute advantage estimates $\hat{A}_{1},\ldots,\hat{A}_{T}$
\EndFor
\State Optimize surrogate $L$ wrt. $\theta$, with $K$ epochs and minibatch size $M\leq NT$
\State $\theta_{old}\leftarrow\theta$
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
您不应该algorithmic
一起加载algpseudocode
:它们彼此不兼容。
您正在使用前一个包的语法,因此请坚持使用它\If{...}...\EndIf
。
我还对代码做了一些更改,请仔细检查。我删除了\rbra
没有出现在任何地方的代码;修复它。
\documentclass[a4paper,11pt]{article}
\usepackage{siunitx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{textcomp}
\usepackage{mathpazo}
\usepackage{eulervm}
\usepackage[utf8]{inputenc}
%\usepackage{algorithmic} %%%% NOT along algpseudocode
\usepackage{ifthen}
\usepackage{amsmath}
\DeclareUnicodeCharacter{2212}{\textminus}% requires a Unicode capable editor
\sisetup{
detect-mode,
detect-family,
detect-inline-family=math,}
\begin{document}
\begin{algorithm}
\caption{PPO}
\begin{algorithmic}[1]
\For {$i=1,2,\dots ,m$}
\EndFor
\For {$i=1,2,\dots,m$}
\State $\mathit{forbidden\_set}\leftarrow\theta$
\State $u\leftarrow {p}[i]$
\State $v\leftarrow \mathit{get\_original\_node}(u)$
\For {each node $s$ that adjacent to $u$}
\If{$c[s]\neq -1$}
\State $v\leftarrow \mathit{get\_original\_node}(s)$
\State $a\leftarrow \mathit{Max\_original\_node}(u)$
\EndIf
\State Run policy $\pi_{\theta_{\mathrm{old}}}$ in environment for $T$ time steps
\State Compute advantage estimates $\hat{A}_{1},\dots,\hat{A}_{T}$
\EndFor
\State Optimize surrogate $L$ wrt. $\theta$, with $K$
epochs and minibatch size $M\leq\nobreak NT$
\State $\theta_{\mathrm{old}}\leftarrow\theta$
\EndFor
\end{algorithmic}
\end{algorithm}
\end{document}
为了修复长行 15,您可以这样做(等到您确定文本已是最终形式)
\State Optimize surrogate $L$ wrt. $\theta$, with $K$\hspace*{\fill}\linebreak
\hspace*{3em}epochs and minibatch size $M\leq NT$
这将产生