2

I am using the IEEEtran template in Overleaf. I am writing an algorithm in the overleaf. enter image description here

However, it adds a series of unwanted zeros on the left of the algorithm and also an unwanted =0 at the last line, here is also my code,

\begin{algorithm}
    \caption{Migration algorithm}
    \begin{algorithmic}
    \label{alg:migration}
        \For {$iteration=1,2,\ldots$,N}
            \For {$episodes=1,2,\ldots,M$}
                \State $R_b \leftarrow 0$
                \State $R_l \leftarrow 0$
                \For {$timesteps=1,2,\ldots,T$}
                    \State Run a trajectory $\pi_{\theta_{old/new}}$ for $T$ timesteps
                    \State Compute the timestep latency reward $r_l$
                    \State Compute the timestep binpacking reward $r_b$
                \EndFor
                \State $R_b \leftarrow R_b + r_b$
                \State $R_l \leftarrow R_l + r_l$
            \EndFor
            \State $R \leftarrow w_1 R_b + w_2 R_l$
            \State Optimize the RL Agent policy $\pi$ based on R
            \State Move the containers based on $\pi$
        \EndFor
    \end{algorithmic}
\end{algorithm}

Theses are also the list of packages related to the algorithm that I'm using.

\usepackage{algorithmic}[1]
\usepackage{algpseudocode}
\usepackage{algorithm}

Instead of zeros I want the line number of the algorithm and also at the end I don't want the end for=0 part.

3
  • Welcome to TeX.SE.
    – Mico
    Commented Jan 2, 2022 at 14:14
  • 1
    In order to get your code to compile with the IEEEtran document class in my TeX distribution (MacTeX2021, all updates applied), I find I mustn't execute \usepackage{algorithmic}[1]. Once I make that adjustment, the code doesn't show line numbers. Please confirm that removing \usepackage{algorithmic}[1] is the way to go.
    – Mico
    Commented Jan 2, 2022 at 14:22
  • Yes, that solved it! Commented Jan 2, 2022 at 14:35

1 Answer 1

1

(this answer builds on an earlier comment)

I suggest you (a) not load the algorithmic package and (b) change \begin{algorithmic} to \begin{algorithmic}[1] to enable line numbering.

enter image description here

\documentclass{IEEEtran}
\usepackage{amsmath,newtxtext,newtxmath}
%\usepackage{algorithmic}[1] % <-- don't load this package
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}

\begin{algorithm}
    \caption{Migration algorithm} \label{alg:migration}
    \begin{algorithmic}[1] % <-- added '[1]' to control line numbering
        \For {$\textrm{iteration}=1,2,\ldots,N$}
            \For {$\textrm{episodes}=1,2,\ldots,M$}
                \State $R_b \leftarrow 0$
                \State $R_l \leftarrow 0$
                \For {$\textrm{timesteps}=1,2,\ldots,T$}
                    \State Run a trajectory $\pi_{\theta_{\textrm{old/new}}}$ for $T$ timesteps
                    \State Compute the timestep latency reward $r_l$
                    \State Compute the timestep binpacking reward $r_b$
                \EndFor
                \State $R_b \leftarrow R_b + r_b$
                \State $R_l \leftarrow R_l + r_l$
            \EndFor
            \State $R \leftarrow w_1 R_b + w_2 R_l$
            \State Optimize the RL Agent policy $\pi$ based on $R$
            \State Move the containers based on $\pi$
        \EndFor
    \end{algorithmic}
\end{algorithm}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .