Linux, etc

Latex으로 알고리즘 Algorithm 작성하기

jiheek 2022. 9. 26. 22:38

내가 도움을 많이 받은 latex 예시 코드는 아래 코드이다. 밑에서 출처 확인할 수 있다.

 

for{}, $수식$, \medskip, \gets, \textbf, \lambda 사용법 익힐 수 있었음

https://stackoverflow.com/questions/72349340/latex-nested-loop-not-displaying-correctly

 

\documentclass{article}
\usepackage[
%utf8,
linesnumbered,ruled,vlined]{algorithm2e}
\usepackage {algpseudocode}
\usepackage{algorithmicx}
\usepackage{algcompatible}


\begin{document}
\begin{algorithm}
%\ContinuedFloat
\caption{My algorithm}
\textbf{Input:} solution,bound, data\_matrix, vehicle\_capacity, demand\_data,k\_max,operations\_data, move\_type,tenure, max\_number\_of\_moves,max\_iter,non\_improvement\_maxiter,itermax,epsilon

\textbf{Output:} \emph{best solution}

\medskip

routes = extract routes from \textbf{solution}

oldfitness = fitness(\textbf{solution})

ls\_move\_type = inversion

best\_solution = routes

\medskip

\For{$0 \leq i \leq$ itermax}{
    new\_routes = [ ]
    
    desc = 'normal route'
    
    \For{route \textbf{in} routes}{
        n=length(route)
        
        comb = int($\frac{n!}{(n-2)!}$)
        
        \If{$n \geq 4$}{
            tabu\_list\_tenure = $\frac{comb}{5}$
            
            ls\_maxiteration = 50 
            
            ls\_move\_type = 'inversion'
        }
        \If{$3 \leq n \leq 4$}{
            tabu\_list\_tenure = $\frac{comb}{4}$
            
            ls\_maxiteration = 25
            
            ls\_move\_type = 'relocation'
        }
       \Else{
         append \textbf{route} to \textbf{new\_routes}
         
         desc = 'short route'         
        }
        
        \medskip
        
        }
    some action   
    }
\Return
\end{algorithm}

\end{document}

 

 

 

https://stackoverflow.com/questions/72349340/latex-nested-loop-not-displaying-correctly

 

Latex nested loop not displaying correctly

Hi I'm new to latex I use here the Algorithmic package to write my pseudo code the problem I faced is that 'some text' is displayed correctly under the second loop but the 'return' statement which ...

stackoverflow.com