1

I'm trying to add a pseudocode to my article using latex and the algorithm2e package.

Unfortunatly i'm getting a bad format for one of my algorithms.

Here is my latex file :

\documentclass[12pt,a4paper,oneside]

\usepackage{url}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{amssymb,amsmath,amsthm}
%\\usepackage{graphics}
\usepackage{graphicx}
\usepackage[linesnumbered,french]{algorithm2e}
\usepackage{hyperref}
\usepackage{cite}
\usepackage{float}


\begin{document}

\begingroup
    \fontsize{10pt}{12pt}\selectfont
 \begin{algorithm}[H]
 \Entree{Un Graphe G, Ensemble de Sommets X}
 \Sortie{Liste de sommets: ensemble dominant minimum}
 \caption{Algorithme pour tout type de graphe}
 \Si{$taille(X) = 0$}{\State \Retour\{\}}
 \State Choisir v tel que $d(v) =1$ ou $2$\\
 \Si {v est vide}{
   \State X0 = sommets dans X avec degré 0\\
   \Si {taille$(X0)$ = taille$(X)$}{
         \State \Retour X0
        }
   \State X1 = X - X0\\
   \State X2 = ensemble des sous-ensembles de X1 de taille $1$ à $3 *$ taille$(X1)/8$\\
     \State \Retour {l'ensemble de X2 qui est MDS de X1}
    }
\Si{$d(v) = 1$}{
    \Si {v \in V - X}
          {\State \Retour mdsForArbitraryGraph $(G-\{v\}, X-\{v\})$}
    \SinonSi {$v \in X$}
          {\State choisir w tel que w et le voisin unique de v\\
          \State \Retour mdsForArbitraryGraph$(G-\{v, w\}, X-N[w])$}
}
\SinonSi {$d(v) = 2$}{
   \State {u1, u2 = voisins de v}\\ 
   \Si {v \in V-X}{
         \State C1 = mdsForArbitraryGraph $(G-\{u1, v\}, X-N[u1])$\\
         \State C2 = mdsForArbitraryGraph $(G-\{u1, v, u2\}, X-\{u1, u2\})$\\
         \State C3 = mdsForArbitraryGraph $(G-\{v\}, X)$\\
         \State \Retour min (C1, C2, C3)
        }
   \SinonSi {v \in X}{
         \State D1 = mdsForArbitraryGraph $(G-\{u1, v\}, X-N [u1])$\\
         \State D2 = mdsForArbitraryGraph $(G-\{u1, v, u2\}, X-\{u1, v, u2\})$\\
         \State D3 = mdsForArbitraryGraph $(G-\{u2, v\}, X-N[u2])$\\
         \State \Retour min (D1, D2, D3)\\
                }
}

\end{algorithm}
\endgroup
\end{document}

and here the bad output:

enter image description here

could anyone check why i'm getting this bad format.

as we can see the end of the pseudocode is not complete with the end statement(fin in french).

Thank you

3

There is no \State command in algorithm2e. You also have several errors of missing $; I fixed a few, but you should review the whole thing to get uniform treatment of your variables.

I also used \small to make the big thing fit in one page. Remove [H] so it can really float.

\documentclass[12pt,a4paper,oneside]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage{amssymb,amsmath,amsthm}
\usepackage[linesnumbered,french]{algorithm2e}

\begin{document}

 \begin{algorithm}
 \small
 \Entree{Un Graphe G, Ensemble de Sommets X}
 \Sortie{Liste de sommets: ensemble dominant minimum}
 \caption{Algorithme pour tout type de graphe}
 \Si{$taille(X) = 0$}{\Retour\{\}}
 Choisir $v$ tel que $d(v) =1$ ou $2$\\
 \Si {$v$ est vide}{
   X0 = sommets dans X avec degré 0\\
   \Si {taille$(X0)$ = taille$(X)$}{
         \Retour X0
        }
   X1 = X - X0\\
   X2 = ensemble des sous-ensembles de X1 de taille $1$ à $3 *$ taille$(X1)/8$\\
     \Retour {l'ensemble de X2 qui est MDS de X1}
    }
\Si{$d(v) = 1$}{
    \Si {$v \in V - X$}
          {\Retour mdsForArbitraryGraph $(G-\{v\}, X-\{v\})$}
    \SinonSi {$v \in X$}
          {choisir w tel que w et le voisin unique de v\\
          \Retour mdsForArbitraryGraph$(G-\{v, w\}, X-N[w])$}
}
\SinonSi {$d(v) = 2$}{
   {u1, u2 = voisins de v}\\ 
   \Si {$v \in V-X$}{
         C1 = mdsForArbitraryGraph $(G-\{u1, v\}, X-N[u1])$\\
         C2 = mdsForArbitraryGraph $(G-\{u1, v, u2\}, X-\{u1, u2\})$\\
         C3 = mdsForArbitraryGraph $(G-\{v\}, X)$\\
         \Retour min (C1, C2, C3)
        }
   \SinonSi {$v \in X$}{
         D1 = mdsForArbitraryGraph $(G-\{u1, v\}, X-N [u1])$\\
         D2 = mdsForArbitraryGraph $(G-\{u1, v, u2\}, X-\{u1, v, u2\})$\\
         D3 = mdsForArbitraryGraph $(G-\{u2, v\}, X-N[u2])$\\
         \Retour min (D1, D2, D3)\\
                }
}

\end{algorithm}
\end{document}

enter image description here

  • i don't know how much i can thank you.you helped me a lot. – zak zak Oct 27 '18 at 4:17

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.