0

I have the following code which produces the algorithm in the image.

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\begin{document}
    \begin{algorithm}[h]
        \caption{Q-learning}
        \begin{algorithmic}[1]
            \Require Set of good nodes $V^g$, $score(u) \; \forall u \in V^g, \mbox{ number of episodes } E, \mbox{ budget size } b$, $\epsilon$
            \Ensure Learned parameters $\Theta_Q$
            \State Initialise replay buffer $M = \emptyset$
            \For{Episode $e \leftarrow 1 \mbox{ to } E$}
                \State $S_t \leftarrow \emptyset,\; C_t \leftarrow V^g$
                \For{Step $t \leftarrow 1 \mbox{ to } b$}
                    \State 
                    \begin{equation}
                        v_t \leftarrow 
                        \begin{cases}
                            \mbox{A node chosen uniformly at random from } C_t & \mbox{w.p. } \epsilon \\
                            \argmax_{v \in C_t} Q(S_t, v) & \mbox{w.p. } 1-\epsilon
                        \end{cases}
                    \end{equation}
                \EndFor
            \EndFor
        \end{algorithmic}
    \end{algorithm}
\end{document}

image for question

I would like line 5 to be less centred in the middle of the page and more in-line with where it would be under the for loop if it was a normal piece of text. Can I do this using the equation/cases environment or do I need to create it some other way?

Sorry if I have any imports missing for the equation etc. as it may be in my preamble

David
  • 101
  • This may be helpful: https://tex.stackexchange.com/questions/145657/align-equation-left – Alan Xiang Jun 21 '21 at 13:49
  • @AlanXiang the accepted answer recommends not using an algorithm environment, but I am writing pseudocode so I need the algorithm environment. – David Jun 21 '21 at 13:52
  • 1
    Why don' you use a \\ $\begin{cases} … \end{cases}$? – Bernard Jun 21 '21 at 13:53
  • 1
    @Bernard perfect, thanks! I was unaware that cases worked if you were using the $ environment! please, write this as an answer and I can upvote and accept it :) – David Jun 21 '21 at 14:04
  • There's a problem, though: you won't have an equation number, as with equation. Do you need it? – Bernard Jun 21 '21 at 14:10
  • No, no equation number is required in this instance, so this still works for me :) – David Jun 21 '21 at 14:10

0 Answers0