1

LWU-NN Algorithm

Please can someone guide me as to how to write the algorithm attached in Latex I have tried and its giving me a lot of errors

\begin{document}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{algorithm}
\caption{LWU-NN Algorithm}
\label{LWU-NN Algorithm}
\begin{algorithmic}[1]
\Procedure{R\textendash Routing Table}{}
\For {R = 1 to size (Lt)}    
\For {C = 1 to size (Lt)}    
\State    $ L_{1} $= $Tr^{-1} Lt{x,y}+O $ 
\State   $  K={Tr}^{-1}\theta (x)$  % 
\For {i = 1 to size Lt)}
\For {j = 1 to size Tr}
\State $Tr_{ij}=K_{ij} + \rho_{ij} = Tr^{-1}\theta{x} $ $+$ $\rho_{ij}  $   
\EndFor
\EndFor
\State $P_{i}(Tr)=1/{2\pi}^{n/2} 1/N_{i} \sum_{i=1}^{N_i}e^{-{ Tr_{i}-Tr_{j} }^{-1} {Tr_{i}-Tr_{j} }}/{2\sigma^2 }$

\State \if ${I_{RC} > P {Tr}}$  % 
\State $Rt_{RC}= Lb {P {Tr}}$;
\EndIf
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
1
  • 2
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Oct 20 '15 at 23:17
2

This would have been several times easier if I'd known which packages to load.

There are several problems:

  • You have one more \For than \EndFors;
  • You have an \EndIf with no \If;
  • You have an \if which is a regular conditional and not part of the markup for an algorithm, but you never close this. And, anyway, you can't use \if followed by a bit of pseudocode.

Fixing these issues:

pseudocode

If that is not quite the intended output, you'll have to adjust it. I wasn't always sure what you intended to say. (Should the \if have been an \If? Or was the \State intended and you meant the \EndIf to be \EndFor?)

Note that indenting your code consistently can help greatly in avoiding and finding typos, bugs and other weirdness:

\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
  \caption{LWU-NN Algorithm}
  \label{LWU-NN Algorithm}
  \begin{algorithmic}[1]
    \Procedure{R\textendash Routing Table}{}
      \For {R = 1 to size (Lt)}
        \For {C = 1 to size (Lt)}
          \State $L_{1} $= $Tr^{-1} Lt{x,y}+O $
          \State $K={Tr}^{-1}\theta (x)$
          \For {i = 1 to size Lt)}
            \For {j = 1 to size Tr}
              \State $Tr_{ij}=K_{ij} + \rho_{ij} = Tr^{-1}\theta{x} $ $+$ $\rho_{ij}$
            \EndFor
          \EndFor
          \State $P_{i}(Tr)=1/{2\pi}^{n/2} 1/N_{i} \sum_{i=1}^{N_i}e^{-{ Tr_{i}-Tr_{j} }^{-1} {Tr_{i}-Tr_{j} }}/{2\sigma^2 }$
          \If{${I_{RC} > P {Tr}}$}
            \State  $Rt_{RC}= Lb {P {Tr}}$;
          \EndIf
        \EndFor
      \EndFor
    \EndProcedure
  \end{algorithmic}
\end{algorithm}
\end{document}

Your Answer

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