SEclone basic classes for tagging

 

TZCF table of weak links

 

 

That class  should play later a wider role. For the time being,

 

It holds the current “phase” with the 2 TDB

  Direct implications

  Expanded implications.

 

It holds also a table of primary weak links, just keeping one occurrence for each couple of tags.

Each element of the table has enough data to track back the path when an elimination has been found, but as we have currently only “single chains”, one could tink that we have to many data.

 

It is also the entry for the search of Nice loops and  Chains except if the elimination comes from  a set of tags (cell of row/column/box).

 

Most of the code here has to be revisited later, so I’ll stress only on active code so far.

I erased here all entries not active for the time being. The .h file is bigger

 

First, small classes

 

TCF is an elementary weak link

         m[2] is a sorted table of tags

         for a direct weak link, id1 and id2 are the “TZPLN index” of the candidates7

         id  is set to 0 for a basic weak links. Other values will come later

         Other data are for complex tracking back

 

#define zcf_lim 100000

class TCF  

{ public: USHORT  m[2] ,id1,id2,detail;

       USHORT id,phase,used;         // balise pour detail niveau n

       void Charge(USHORT  m1,USHORT  m2 ,

                            USHORT ie,USHORT ie1,USHORT ie2,USHORT ph)

         {m[0]=m1;m[1]=m2;id=ie;id1=ie1;id2=ie2;phase=ph;detail=used=0;

          };

};

 

CFR is short clas to get back a weak link sorted in the same order as it appears in the path

 

// short class to get back a weak link data for length computation

class CF_R

  {public: USHORT p1,p2,length;

   CF_R(){p1=p2=length=0;}

   void Set(USHORT p1e,USHORT p2e,USHORT  m,USHORT lg)

                 {if((!p1e) || (!p2e)) return;

                  length=lg;

                     if(zpln.zp[p1e].m==m)    {p1=p1e; p2=p2e;}

                     else  {p1=p2e; p2=p1e;}

               }

       };

 

PHASE belonging to TZCF hlods the couple of TDB “direct” ;  “expanded”

 

Some comments on TZCF

  . Weak links are stored in “f”, index “ic”

  . “h” is the current phase, the only one needed for the time being

 . xb,xi,xbr,xbr2 are bit fields storing the list of tags in loop or to eliminate

 

The 2 key functions we are using are located in the file cf_interdit.cpp.

 

Aic_Cycle() looks for Nice loops

Aic_Chain() looks for chains

 

 

class TZCF

class PHASE{public: TDB d,dp; int icf;

               void Init(){d.Init();dp=d;}};

   public:  PHASE h;

   TCF f[zcf_lim],fw;

   USHORT ic,avecderive,avecchoix;

   CB1024 xb,xi,xbr,xbr2;

   void InitD(int npas=30){h.d=h.dp;  h.d.InitD(npas); }

   void Init() {ic=iphase=0;h.Init(); }

 

   int Chargeid (USHORT m1 ,USHORT m2,

                     USHORT id,USHORT id1,USHORT id2=0,USHORT maj=1);

   int LChemin(USHORT m1,USHORT m2)

            {h.d.Parents(m2); h.dp.Direct_Path(m1,m2,h.d.parents,0);

              return h.dp.length;}

 

 

   void  Aic_Cycle(int opx) ; // only nice loops 

   void  Aic_Chain() ; // only tags to clear 

 

 

 

 

 

   int IsConflitD(int m1,int m2)   {if(m1==(m2^1)) return 1;

                                    return h.dp.IsConflit(m1,m2);}

   int IsConflit(int m1,int m2)   {if(m1==(m2^1)) return 1;

                                    return h.d.IsConflit(m1,m2);}

 

   CF_R  GetConflitChemin(USHORT m1,USHORT m2);

 

   CB1024 * Getd(int m) {return & h.d.t[m];};

   CB1024 * Getdp(int m) {return & h.dp.t[m];};

   int Is(int i,int j)  {return h.d.Is(i,j);};

   int Isp(int i,int j) {return h.dp.Is(i,j);};

   int GetConflit(USHORT * m ,TCF &rr)

     {int ir=GetIf(m);if(ir<0) return 0; rr=f[ir];return 1;}

 

   private:

 

    int Plusp (int m1,int m2) {return h.dp.Plus(m1,m2);};

    int Entrep(int m1,int m2){ return(Plusp(m1,m2^1)+Plusp(m2,m1^1));};

    int PasDoublon(int m1,int m2);

    int Nouveau(int m1,int m2)

       {if(h.d.Is(m1,m2^1))return 0;  return PasDoublon(m1,m2); };

}zcf; 

 

Aic_Cycle() search of Nice loops

 

This is the entry for all kinds of loops: X;Y or XY, but XY loop does not seem of any use .

An X loop is always active (leads to eliminations) in tag mode.

Reversely, many Y loop  have no effect, so the search for Y loop is done when a potential eliminaton is found.

 

 /* we are looking for nice loops

    first we extract all tags in loops

       then isolate several sub sets of tags in loop

    in a specific subset

          with X cycle, the loop is always active

          with y cycle we have first to locate active couples of tags

            and then to find a loop crossing both tags

*/

void TZCF::Aic_Cycle(int opx)  // only nice loops and solve them

{E$.Enl("\nzcf Aic_cycle ");

            // first collect tags in loop

CB1024 xi;

xb.Init(); xi.Init();// collect tags in loop ok and "to eliminate"

for(int i=2;i<col;i++) {if(h.d.Is(i,i)&& (h.d.Is(i^1,i^1)) )xb.Set(i); 

                        if(h.d.Is(i,i^1) || (h.d.Is(i^1,i)) )xi.Set(i); }

if( xb.Nul() )return;  xbr=xb;

if(o$.ot){ xb.ImageMarques("all tags in loop ",0);

           xi.ImageMarques("but skipping",0);}

 

                // now find and process sub sets     

 

for(int ib=2;ib<col;ib++) if(xbr.On(ib))

  {CB1024  ww2=(*Getd(ib^1)).Inverse(),

           ww1=(*Getd(ib))&ww2; xbr2=ww1; // a subset

    xbr-=(ww1|ww1.Inverse());   // not to ne any more processed

 

       if(o$.ot)  {jdk.PointK();xbr2.ImageMarques(" study loop",0);E$.Enl();  }

       if(opx)     // it is Xloop mode

       { h.dp.Direct_Path(ib,ib,xbr2,0); h.dp.Copy_Path(1);

         USHORT length=h.dp.length;

        for(int j=ib+2;j<col;j++) if(xbr2.On(j))

           {h.dp.Direct_Path(j,j,xbr2,0); USHORT l2=h.dp.length;

           if(l2<length) {length=l2; h.dp.Copy_Path(1);}

           }

 

      h.dp.Copy_Back(1);// get back the good loop

        h.dp.path.CleanLoop(length); // got ot chain and clean

       }

  else    // y cycle

     {for(int i=2;i<col;i++) if(ww1.On(i)) 

      for(int j=i+1;j<col;j++) if(ww1.On(j))  // each pair of tags in the loop

       {CB1024 zw=( (h.dp.t[i] & h.dp.t[j^1]) |

                      (h.dp.t[i^1] & h.dp.t[j])  );

           if( zw.NonNul()    )  h.dp.Yloop(i,j,ww1); // pair i;j active

       }

    }

  if(xbr.Nul()) break;

 }

}

 

 

Aic_Chain() search of discontinued Nice loops

 

This is the entry for all kinds of chains : X;Y or XY, active by definition,

The search is cancelled for all tags parents of a tag to eliminate.

In “Y” mode, the search must be limited to a realistic length to avoid a huge increase in run time.

That code will be revisited towards that key issue.

 

.

 

/* looking for discontinued nice loop

   if A -> B and B is false

   then the chain killing B is shorter

   if the chain kiliin A goes thru B it is not be seen (no reverse path)*/

 

 

void TZCF::Aic_Chain()  // only tags to clear

{int ir=0; // first check direct or

 xi.Init();for(int i=2;i<col;i++) if(h.d.Is(i,i^1)) xi.Set(i);

 if(xi.Nul()) return;

 // reduce the scope

 for(int i=2;i<col;i++)

          if(xi.On(i) && (!h.d.Is(i,i)) // there and not in loop

          && (xi&h.d.t[i]).NonNul() ) xi.Clear(i);

 for(int i=2;i<col;i++) if(xi.On(i))  

   {if(o$.ot) {jdk.PointK(); // only if test mode

               E$.E(" chain killing "); mms.ev(i); E$.Enl();   }

   CB1024 w=h.d.t[i]; // look for parents

        for(int j=2;j<col;j++) if((j-(i^1))&& w.On(j))

              if(!h.d.Is(j,i^1))w.Clear(j);     

       h.dp.Direct_Path(i,i^1,w,1); // and go to generate chains

   }

}