BookML test: algorithm2e.sty — package for algorithms
release 5.2

(c) 1995-1997 Christophe Fiorio, Tu-Berlin, Germany
(c) 1998-2017 Christophe Fiorio, LIRMM, Montpellier University, France

July 18 2017

BookML

v0.28.5

0.8.8

2018/12/01

Data: this text
Result: how to write algorithm with 2e
initialization;
while not at end of this document do
      read current section;
      if understand then
           go to next section;
           current section becomes this one;
          
     else
           go back to the beginning of current section;
          
      end if
     
end while
Algorithm 1 How to write algorithms
1
input : A bitmap ImIm of size w×lw\times l
output : A partition of the bitmap
2 special treatment of the first line;
3 for i2i\leftarrow 2 to ll do
4       special treatment of the first element of line ii;
5       for j2j\leftarrow 2 to ww do
6            left \leftarrow FindCompress(Im[i,j1]Im[i,j-1]);
7            up \leftarrow FindCompress(Im[i1,]Im[i-1,]);
8            this \leftarrow FindCompress(Im[i,j]Im[i,j]);
9            if left compatible with this then // O(left,this)==1
10                 if left << this then Union(left,this);
11                 else Union(this,left);
12                
13            end if
14           if up compatible with this then // O(up,this)==1
15                 if up << this then Union(up,this);
16                 // this is put under up to keep tree as flat as possible
17                 else Union(this,up);
18                // this linked to up
19            end if
20           
21       end for
22      foreach element ee of the line ii do FindCompress(p);
23      
24 end for
Algorithm 2 disjoint decomposition
Data: G=(X,U)G=(X,U) such that GtcG^{tc} is an order.
Result: G=(X,V)G^{\prime}=(X,V) with VUV\subseteq U such that GtcG^{\prime tc} is an interval order.
begin
      VUV\longleftarrow U
      S∅︀S\longleftarrow\emptyset
      for xXx\in X do
           NbSuccInS(x)0NbSuccInS(x)\longleftarrow 0
           NbPredInMin(x)0NbPredInMin(x)\longleftarrow 0
           NbPredNotInMin(x)|ImPred(x)|NbPredNotInMin(x)\longleftarrow|ImPred(x)|
          
     for xXx\in X do
           if NbPredInMin(x)=0NbPredInMin(x)=0 and NbPredNotInMin(x)=0NbPredNotInMin(x)=0 then
                AppendToMin(x)AppendToMin(x)
          
1      while S∅︀S\neq\emptyset do
REM            remove xx from the list of TT of maximal index
2            while |SImSucc(x)||S||S\cap ImSucc(x)|\neq|S| do
                for ySImSucc(x)y\in S-ImSucc(x) do
                     { remove from VV all the arcs zyzy : }
                     for zImPred(y)Minz\in ImPred(y)\cap Min do
                          remove the arc zyzy from VV
                          NbSuccInS(z)NbSuccInS(z)1NbSuccInS(z)\longleftarrow NbSuccInS(z)-1
                          move zz in TT to the list preceding its present list
                          {i.e. If zT[k]z\in T[k], move zz from T[k]T[k] to T[k1]T[k-1]}
                         
                    NbPredInMin(y)0NbPredInMin(y)\longleftarrow 0
                     NbPredNotInMin(y)0NbPredNotInMin(y)\longleftarrow 0
                     SS{y}S\longleftarrow S-\{y\}
                     AppendToMin(y)AppendToMin(y)
                    
               
          RemoveFromMin(x)RemoveFromMin(x)
          
     
Algorithm 3 IntervalRestriction
1 Function FnRecursive(some args) /* algorithm as a recursive function */
      Data: Some input data
     these inputs can be displayed on several lines and one input can be wider than line’s width.
      Result: Same for output data
2       /* this is a comment to tell you that we will now really start code */
3       if this is true then /* a simple if but with a comment on the same line */
4            we do that, else nothing
5            /* we will include other if so you can see this is possible */
6            if we agree that then
7                 we do that
8                
9           else
10                 else we will do a more complicated if using else if
11                 if this first condition is true then
12                      we do that
13                     
14                 else if this other condition is true then
15                      this is done
16                       /* else if */
17                     
18                 else
19                      in other case, we do this
20                       /* else */
21                     
22                 end if
23                
24            end if
25           
26       end if
27      /* now loops */
28       for i=0i=0 to nn do
29            a for loop
30           
31       end for
32      while i<ni<n do
33            a while loop including a repeat–until loop
34            repeat
35                 do this things
36                
37           until this end condition
38       end while
39      They are many other possibilities and customization possible that you have to discover by reading the documentation.
40 end
Algorithm 4 Generic example with most classical expressions derived in pseudo-code