1

Hello guys i am new to LaTeX, i have written an algorithm in algorithm environment which is as follows:

\documentclass{report}
\usepackage{amsmath}
\usepackage{algorithm}
%\usepackage[noend]{algpseudocode}
\usepackage{algpseudocode}

\begin{document}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\begin{algorithm}
    \caption{Reduct Construction Algorithm}\label{euclid}
    \begin{algorithmic}[1]
        \Procedure{Reduct Construction}{}\newline
        \textbf{Input:} Three matrices based on indiscernibility, discernibility and equal to one relations.\newline
        \textbf{Output:} Reducts (sentences)

\State {{\text{\,\,\,\,\,} \textbf{for} i = 2 to n \text{\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,\,\,\,} \textbf{for} j = 1 to n-1 \text{\,\,\,\,\,\,\,\,}}

\State {\text{\,\,\,\,\,\,\,\,\,\,\,} \textbf{if}$M(i,j) \neq \phi$ \text{\,\,\,\,\,\,\,\,\,\,\,}\textbf{then}

\State {{\text{\,\,\,\,\,} \textbf{for} every non-empty element M(i`,j`) \in B \text{\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,\,\,\,} \textbf{if} $M(i`,j`)\subset M(i,j)$   \text{\,\,\,\,\,\,\,\,}\textbf{then}}

\State {{\text{\,\,\,\,\,\,\,\,\,\,\,\,\,\,} $M(i,j) = M(i`,j`)$ \text{\,\,\,\,\,\,\,\,\,\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,} Divide M(i,j) into two parts\text{\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,} \textbf{Select} an attribute a from M(i,j); \text{\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,} $A = M(i,j)-\{a\}$ \text{\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,} $M(i,j)=\{a\}$ \text{\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,} Simplify every non empty element in B \text{\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,} \textbf{if} {$a \in M(i`,j`)$} \text{\,\,\,\,\,}\textbf{then}

\State {{\text{\,\,\,\,\,\,\,\,\,\,\,} $M(i`,j`)=\{a\}$ \text{\,\,\,\,\,\,\,\,\,\,\,}}

\State {{\text{\,\,\,\,\,} \textbf{Else} \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} $M(i`,j`) =  M(i`,j`)- A$ \text{\,\,\,\,\,}}

\end{algorithmic}

\end{algorithm}

\end{document}

the packages i am using are:

\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

there are alot of errors, although the visuallization is correct but when i run first time no pdf is generated on run time which is pathetic, the errors are

Package algorithmicx Error: Some blocks are not closed!!!. \end{algorithmic}
Missing } inserted. \end{algorithmic}
Missing \endcsname inserted. \Procedure
Missing $ inserted. ...{for} every non-empty element M(i`,j`) \in
Extra }, or forgotten $. ... element M(i`,j`) \in B \text{\,\,\,\,\,}}

i've tried to correct them but failed, any help correcting these errors would be helpful, thanks

3
  • Please, edit your code and post the complete code so we can compile it.
    – Sigur
    Jul 12, 2015 at 11:25
  • @Sigur edited i hope it helps now. Jul 12, 2015 at 11:35
  • Your code appears to have a lot of inconsistent material. See the documentation ctan.org/pkg/algorithmicx
    – Sigur
    Jul 12, 2015 at 11:37

1 Answer 1

2

You're misusing the tool:

\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\begin{document}

\begin{algorithm}
\caption{Reduct Construction Algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{Reduct Construction}{}\newline
\textbf{Input:} Three matrices based on indiscernibility, discernibility and equal to one relations.\newline
\textbf{Output:} Reducts (sentences)
\For{$i = 2$ to $n$}
  \For{$j = 1$ to $n-1$}
    \If{$M(i,j) \neq \emptyset$}
      \For{every non-empty element $M(i',j') \in B$}
        \If{$M(i',j')\subset M(i,j)$}
           \State{$M(i,j) = M(i',j')$}
        \EndIf
      \EndFor
    \EndIf
    \State{Divide $M(i,j)$ into two parts}
    \State{\textbf{Select} an attribute $a$ from $M(i,j)$;}
    \State{$A = M(i,j)-\{a\}$}
    \State{$M(i,j)=\{a\}$}
    \State{Simplify every non empty element in $B$}
    \If{$a \in M(i',j')$}
      \State{$M(i',j')=\{a\}$}
    \Else
      \State {$M(i',j') =  M(i',j')- A$}
    \EndIf
  \EndFor
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

enter image description here

I'm not sure the realization is exactly what you have in mind, but it should be easy to adjust it.

Note that math symbols should always be between $ signs. For priming a symbol, use an apostrophe ', not a backquote `

1
  • It was really helpful for me to use the tool correctly, thanks a lot for your help mate. Jul 12, 2015 at 12:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .