I have tried to solve this problem following this tutorial, but with no success. I was using \If and \EndIf and now I have switched to \eIf but with no success. I'm using \; at the end of each line to avoid breaking the paragraph. What's wrong in my if?!
- http://ctan.mirror.garr.it/mirrors/CTAN/macros/latex/contrib/algorithm2e/doc/algorithm2e.pdf
-
Misunderstood error with algorithm2e in LateX
\begin{algorithm} \ForAll {Partition p} skip1=0 \ForAll {Edges i=(a,b)} skip2=0 \ForAll {bucket in p} j=0 % conta i caratteri \ForAll{chr in bucket} \eIf{ chr == a or chr == b}{ other2find = set(set((a,b,)) - set((chr,))) \; % give the missing element to find skip1=1 \; \ForAll {other char k} \; \eIf{other2find \== k} { unstableNumber=unstableNumber+1 \; skip2=1 \; break \; % smette di cercare nei caratteri del bucket \EndIf \; break \; } }{ j=j+1 } \EndFor %\If{skip1=1} % se ho trovato almeno un nodo in un bucket, salto tutta la partizione % % perche' tanto l'altro nodo sara da qualche parte ma non rendera di certo la partizione % % non stabile % break %tutto questo codice non serve perche' e incluso nel break dopo if(other2find) \EndFor \EndFor \If{skip2} break % non serve controllare tutti gli archi per sapere che una partizione non e' stabile \EndIf \If{!skip2} stablePartition.append(p) skip2=0 \EndIf \EndFor \end{algorithm}
Best Answer
You seem to be mixing your syntax between what is provided by
algorithm2e
and that ofalgorithmicx
. The latter uses a\For{..} ... \EndFor
and\If{..} ... \EndIf
construction while the former uses\For{..}{...}
and\If{..}{...}
construction together with a\;
line-terminating macro.Here's an
algorithm2e
implementation:Note that it would be advisable to define a macro for your variable definitions (like
skip1
,skip2
,chr
, ...) that you can use throughout your algorithms. You may want to do the same for function calls, or use\call
. See thealgorithm2e
documentation for many more options/details.