[Tex/LaTex] Algorithm environment problem

algorithmicalgorithmicxalgorithmserrors

I am doing my master thesis and need to include an algorithm into my LaTeX code. I have been trying for hours now, but I still have several errors that always show up. It is my first time using the algorithm package, so help would be appreciated. Here is the code:

\documentclass{article}
\usepackage{algorithm,algorithmic,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Resource Allocation Algorithm }
\label{alg:algorithm_sum}
\begin{algorithmic}[1]
\State{Initialization of maximum number of iteration $I_{\text{max}}$, given $\mu^m$ and $\beta^m$ and obtain the intermediate solution for (opt. variables)} 
\If{ref. is satisfied} 
\State{Convergence =  true} 
\Return{opt. variables} 
\Else 
\State{update $\mu$ and $\beta$ according to ref. and $m=m+1$} 
\State{Convergence =  false} 
\EndIf
\Until{Convergence = true or $m=I_{\text{max}}$} 
\end{algorithmic}
\end{algorithm}
\end{document}

Best Answer

First of all you are loading both algorithmic and algpseudocode (variant of algorithmicx) which are not compatible.

The syntax you are using is the one of algpseudocode so don't load algorithmic. Moreover, you are using \text and forgot to load amsmath.

Finally, the \Until command has to be used to close a \Repeat statement which is missing in your code.

This is your modified MWE with \Repeat (move it to the right place in the algorithm):

\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Resource Allocation Algorithm }
\label{alg:algorithm_sum}
\begin{algorithmic}[1]
\State{Initialization of maximum number of iteration $I_{\text{max}}$, given $\mu^m$ and $\beta^m$ and obtain the intermediate solution for (opt. variables)}
\Repeat
\If{ref. is satisfied}
\State{Convergence =  true}
\Return{opt. variables}
\Else
\State{update $\mu$ and $\beta$ according to ref. and $m=m+1$}
\State{Convergence =  false}
\EndIf
\Until{Convergence = true or $m=I_{\text{max}}$}
\end{algorithmic}
\end{algorithm}
\end{document} 

Output:

enter image description here

Related Question