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
andalgpseudocode
(variant ofalgorithmicx
) which are not compatible.The syntax you are using is the one of
algpseudocode
so don't loadalgorithmic
. Moreover, you are using\text
and forgot to loadamsmath
.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):Output: