0

Hello how can I rewrite repeat until command so ''until'' in line 15 is closer to number 15 (not in the same column as line14)

\documentclass{article} 
\usepackage{amsmath}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{algorithm}
\clearpage
\begin{algorithm}
\caption{2-opt algoritmus}
\begin{algorithmic}[1]
\Repeat
\For{$i = 1$ do $n - 1$}
\For{$j = i + 1$ do $n$}
\If{$j < n$}
\If{$c(x_i, x_{i+1}) + c(x_j, x_{i+1}) < c(x_j, x_{i+1}) + c(x_j, x_{j+1})$}
\State Swap \textit{$x_i$} a \textit{$x_j$}
\EndIf
\Else
\If{$c(x_i, x_1) + c(x_n, x_{i+1}) < c(x_i, x_{i+1}) + c(x_n, x_1)$}
\State Swap \textit{$x_i$} a \textit{$x_n$}
\textbf{until}
\EndIf
\EndIf
\EndFor
\EndFor
\State 
\textbf{Until}
\end{algorithmic}
\end{algorithm}
\end{document}
  • The last \State should be removed and \textbf{Until} should be \Until{<some condition>}. As an aside, what's the purpose of \textit{$x_i$}? The \textit command does nothing at all. – egreg Apr 18 '19 at 22:11
2

The format for “repeat until” is

\Repeat
  <body>
\Until{<condition>}

So your code should be

\documentclass{article} 
\usepackage{amsmath}
\usepackage{algpseudocode}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}
\caption{2-opt algoritmus}
\begin{algorithmic}[1]
\Repeat
  \For{$i = 1$ do $n - 1$}
    \For{$j = i + 1$ do $n$}
      \If{$j < n$}
        \If{$c(x_i, x_{i+1}) + c(x_j, x_{i+1}) < c(x_j, x_{i+1}) + c(x_j, x_{j+1})$}
          \State Swap $x_i$ a $x_j$
        \EndIf
      \Else
        \If{$c(x_i, x_1) + c(x_n, x_{i+1}) < c(x_i, x_{i+1}) + c(x_n, x_1)$}
          \State Swap $x_i$ a $x_n$
        \EndIf
      \EndIf
    \EndFor
  \EndFor
\Until{you're tired}
\end{algorithmic}
\end{algorithm}

\end{document}

Change “you're tired” with the proper condition.

enter image description here

| improve this answer | |
  • Thank you very mutch – Thomas Kyle Apr 19 '19 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.