Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/KB/include/DiffHistoryRep.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: DiffHistoryRep.h,v 1.1 1996/08/15 18:55:37 bormotov Exp $
00003  */
00004 
00005 // Copyright (C) 1994 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: Definition of DiffHistoryRep and related classes.
00009 //
00010 // Principal Author: Sarah Rees
00011 //
00012 // Status: in progress
00013 //
00014 // Revision History:
00015 //
00016 
00017 #ifndef _DiffHistoryRep_H_
00018 #define _DiffHistoryRep_H_
00019 
00020 #include "Word.h"
00021 #include "Vector.h"
00022 #include "RefCounter.h"
00023 // #include "DFSARep.h"
00024 typedef int State; 
00025 // @sr for now this file needs to be independent of DFSARep.
00026 // So for now we'll typedef State to be int, but that's only temporary.
00027 // That's because a declaration of SetOf<DiffHistory> is necessary in Set.C
00028 // and that can't be dependent on the FSA hierarchy.
00029 // If that weren't necessary, this could all be in DiffMachineRep.h
00030 
00031 class DiffHistoryVtx;
00032 
00033 // First the AheadInfoRep hierarchy, one derived class for each word order.
00034 
00035 class AheadInfoRep : public RefCounter {
00036 public:
00037 //constructor
00038   AheadInfoRep() {};
00039 // copy constructor
00040   AheadInfoRep (const AheadInfoRep & ai) {}; 
00041   virtual AheadInfoRep *clone() const {};
00042 //destructor
00043   virtual ~AheadInfoRep() {};
00044 };
00045 
00046 class SLAheadInfoRep : public AheadInfoRep {
00047 public:
00048 //constructor
00049   SLAheadInfoRep() {};
00050 // copy constructor
00051   SLAheadInfoRep(const SLAheadInfoRep & ai) {}; 
00052   AheadInfoRep *clone() const { return new SLAheadInfoRep(*this); }
00053 //destructor
00054   ~SLAheadInfoRep() {};
00055 private:
00056 };
00057 
00058 class WtSLAheadInfoRep : public AheadInfoRep {
00059 public:
00060 //constructor
00061   WtSLAheadInfoRep() {};
00062   WtSLAheadInfoRep(int wd) {wtdiff=wd;};
00063 // copy constructor
00064   WtSLAheadInfoRep (const WtSLAheadInfoRep & ai) {wtdiff=ai.wtdiff;}; 
00065   AheadInfoRep *clone() const { return new WtSLAheadInfoRep(*this); }
00066 //destructor
00067   ~WtSLAheadInfoRep() {};
00068   int getWtDiff() const { return wtdiff;}
00069 private:
00070   int wtdiff;
00071 };
00072 
00073 class WtLexAheadInfoRep : public AheadInfoRep {
00074 public:
00075 //constructor
00076   WtLexAheadInfoRep(): sign(0) {};
00077   WtLexAheadInfoRep(int wd,int sgn): wtdiff(wd), sign(sgn) {};
00078 // copy constructor
00079   WtLexAheadInfoRep(const WtLexAheadInfoRep & ai) : 
00080      wtdiff(ai.wtdiff), sign(ai.sign){}; 
00081   AheadInfoRep *clone() const { return new WtLexAheadInfoRep(*this); }
00082 //destructor
00083   ~WtLexAheadInfoRep() {};
00084   int getWtDiff() const { return wtdiff;}
00085   int getSign() const { return sign;}
00086 private:
00087   int wtdiff; 
00088   int sign;
00089 };
00090 
00091 
00092 // Now the DiffHistoryRep hierarchy. There is one type for each word order.
00093 // In the comments below d is always a word difference, which has arise
00094 // as various products of the form w^-1u
00095 
00096 class DiffHistoryRep : public RefCounter {
00097 public:
00098 //constructor
00099   DiffHistoryRep() {};
00100 //copy constructor
00101   DiffHistoryRep(const DiffHistoryRep & dh) {};
00102   virtual DiffHistoryRep *clone() const {};
00103 //destructor
00104   virtual ~DiffHistoryRep() {};
00105 
00106 //hash function
00107   virtual int hash() const {};
00108   virtual Bool empty() const {};
00109 
00110   virtual State getDiff() const {};
00111 //operators
00112   virtual int operator== ( const DiffHistoryRep & dh) const {
00113   };
00114   virtual DiffHistoryRep&  operator= ( const DiffHistoryRep & dh ) {};
00115 
00116   virtual Bool sameLengthWords() const {};
00117 // returns YES if d has arisen as the word difference from two words
00118 // of equal length
00119 
00120   virtual void improveBy(const DiffHistoryRep & dh) {};
00121 //  add in to the current word difference history the information carried
00122 // by the difference history dh (which is associated associated with the same
00123 // word difference)
00124 
00125   virtual Bool possibleReductionAhead() const {};
00126 // return YES if the possibility cannot be ruled out that some w is equal
00127 // in G to a longer word u', of which u is a prefix, and such that u<w.
00128 
00129   virtual AheadInfoRep *  buildAheadInfoRep() const {};
00130 // constuct and return an AheadInfoRep * for this DiffHistory 
00131 
00132   virtual void printOn(ostream &ostr = cout) const {};
00133 
00134   virtual inline ostream& operator << ( const DiffHistoryRep& dh ) {};
00135 };
00136 
00137 class SLDiffHistoryRep : public DiffHistoryRep {
00138 // Together with each word difference d, integers c0,c1
00139 // are stored, where
00140 // c0 = 1 if d=_G w^-1u for some w, u with l(w)=l(u) and w>u
00141 //    =  -1 if for all w,u with d=_G w^-1u and l(w)=l(u), w<u
00142 //    = 0 if d does not arise as the word difference for 
00143 //        words of equal length.
00144 // c1 = 1 if d = _G w^-1u for some w,u with l(w)>l(u)
00145 //    = 0 otherwise.
00146 //
00147 public:
00148 //constructors
00149   SLDiffHistoryRep(): d(0),c0(0),c1(0){};
00150   SLDiffHistoryRep(State D,int C0,int C1):
00151     d(D),c0(C0),c1(C1){};
00152 //copy constructor
00153   SLDiffHistoryRep(const SLDiffHistoryRep & dh) : 
00154     d(dh.d), c0(dh.c0), c1 (dh.c1) {};
00155   DiffHistoryRep *clone() const { return new SLDiffHistoryRep(*this); }
00156 //destructor
00157   ~SLDiffHistoryRep() {};
00158 //hash function
00159   int hash() const { return (int)d; };
00160   Bool empty() const { return (c0==0 && c1==0); };
00161 //accessors
00162   int getDiff() const { return d;};
00163   int getC0() const { return c0;};
00164   int getC1() const { return c1;};
00165 
00166   //operators
00167   int operator== ( const DiffHistoryRep & dh) const
00168   {
00169     const SLDiffHistoryRep& ddh = (SLDiffHistoryRep&)dh;
00170     return (d == ddh.d && c0 == ddh.c0  && c1 == ddh.c1);
00171   }
00172  
00173   DiffHistoryRep&  operator= ( const DiffHistoryRep & dh )
00174   {
00175     const SLDiffHistoryRep& ddh = (SLDiffHistoryRep&)dh;
00176     d = ddh.d; c0 = ddh.c0; c1 = ddh.c1;
00177     return *this;
00178   }
00179 
00180   Bool sameLengthWords() const  { return (c0!=0);};
00181 
00182   void improveBy(const DiffHistoryRep & dh) 
00183   {
00184     const SLDiffHistoryRep& ddh = (SLDiffHistoryRep&)dh;
00185     if ((ddh.c0==0 || (c0!=0 && c0>= ddh.c0 ))
00186              && (ddh.c1==0 || (c1>= ddh.c1 )))
00187         return;
00188   // ddh is no better than the current SLDiffHistoryRep
00189     else {
00190       if (ddh.c0 && (c0==0 || ddh.c0 == 1)){ 
00191        c0 = ddh.c0;}
00192       if (ddh.c1 && c1==0 ) {
00193         c1 = ddh.c1; } 
00194     }
00195   }
00196   Bool possibleReductionAhead() const { return NO;}
00197 
00198   AheadInfoRep * buildAheadInfoRep() const { return new SLAheadInfoRep(); }
00199 
00200   void printOn(ostream &ostr = cout) const 
00201   {
00202     ostr << "d="<< d << " c0="<< c0 <<" c1="<<c1<<"; ";
00203   }
00204   
00205   inline friend ostream& operator << 
00206         ( ostream& ostr, const SLDiffHistoryRep& dh ) {
00207                   ostr << "d="<< dh.d << " c0="<< dh.c0 <<
00208                          " c1="<<dh.c1<<"; ";
00209     return ostr;
00210   }
00211   
00212   
00213 private:
00214   State d;
00215   int c0, c1;
00216 };
00217 
00218 class WtSLDiffHistoryRep : public DiffHistoryRep {
00219 // Together with each word difference d, integers c0,w0,c1,w1
00220 // are stored, where
00221 // w0 = max{wt(w)-wt(u):l(u)=l(w),u \neq w, d=_G w^-1u }, 
00222 // where that set is non-empty,
00223 // and is otherwise meaningless. c0=0 if the set above is empty, 1 if there
00224 // is some u with wt(w)-wt(u)=w0, l(u)=l(w), d=_G w^-1u and u<w in shortlex,
00225 // and -1 if for all such u, w<u in shortlex.
00226 // w1 = min{1,max{wt(w)-wt(u):l(u)<l(w), d_G w^-1u }, 
00227 // where that set is non-empty,
00228 // and is otherwise meaningless. c1=0 if that set if empty, 1 otherwise.
00229 //
00230 // Given such a difference history (d,c0,w0,c1,w1)
00231 // 
00232 // Where g is a generator, and g^-1d=_G id,
00233 //    if either c0 is nonzero and w0+wt(g)>=0 
00234 //       or c1 is non-zero and w1+wt(g)>=0,
00235 //    then for some w where d=_G w^-1u, wg is equal in G to a 
00236 //       shorter word of no greater weight.
00237 //
00238 //  Where g,h are generators and g^-1dh=_G id,
00239 //     c0 is non-zero,
00240 //     and either w0+wt(g)-wt(h)>0
00241 //         or w0+wt(g)-wt(h)=0 and c0=1,
00242 //     then wg reduces to uh, of the same length as wg,
00243 //         but preceding it in weighted shortlex
00244 //         (in the first case it has lesser weight, in the
00245 //          second it has the same weight but is lexicographically earlier)
00246 //
00247 //   Where H is a word of length >= 2 with H^-1dg=id, c0 is non-zero
00248 //   and g^-1d(h_1h_2..h_i) is in D for all prefixes h_1h_2..h_i of H
00249 //   and w0 + wt(g) - wt(h_1) - ... wt(h_n) > 0,
00250 //   then wg reduces to uH which is longer, but of lower weight.
00251 //
00252 
00253 public:
00254 //constructors
00255   WtSLDiffHistoryRep(): d(0),c0(0),w0(0),c1(0),w1(0){};
00256   WtSLDiffHistoryRep(State D,int C0,int W0,int C1,int W1):
00257     d(D),c0(C0),w0(W0),c1(C1),w1(W1){};
00258 //copy constructor
00259   WtSLDiffHistoryRep(const WtSLDiffHistoryRep & dh):
00260     d(dh.d), c0(dh.c0), w0(dh.w0), c1(dh.c1), w1(dh.w1){};
00261   DiffHistoryRep *clone() const { return new WtSLDiffHistoryRep(*this); }
00262 //destructor
00263   ~WtSLDiffHistoryRep() {};
00264 //hash function
00265   int hash() const { return (int)d; };
00266   Bool empty() const { return (c0==0 && c1==0); };
00267 //accessors
00268   int getDiff() const { return d;};
00269   int getC0() const { return c0;};
00270   int getW0() const { return w0;};
00271   int getC1() const { return c1;};
00272   int getW1() const { return w1;};
00273 
00274   //operators
00275   int operator== ( const DiffHistoryRep & dh) const
00276   {
00277     const WtSLDiffHistoryRep& ddh = (WtSLDiffHistoryRep&)dh;
00278     return (d == ddh.d && c0 == ddh.c0 && w0 == ddh.w0 
00279                  && c1 == ddh.c1 && w1 == ddh.w1);
00280   }
00281  
00282   DiffHistoryRep&  operator= ( const DiffHistoryRep & dh )
00283   {
00284     const WtSLDiffHistoryRep& ddh = (WtSLDiffHistoryRep&)dh;
00285     d = ddh.d; c0 = ddh.c0; w0 = ddh.w0; c1 = ddh.c1; w1 = ddh.w1;
00286     return *this;
00287   }
00288   Bool sameLengthWords() const  { return (c0!=0);};
00289   void improveBy(const DiffHistoryRep & dh) 
00290   {
00291     const WtSLDiffHistoryRep& ddh = (WtSLDiffHistoryRep&)dh;
00292     if (ddh.c0 && (c0==0 || w0 < ddh.w0 || (w0==ddh.w0 && ddh.c0 == 1))){ 
00293       c0 = ddh.c0; w0 = ddh.w0;}
00294     if (ddh.c1 && (c1==0 || w1 < ddh.w1)){ 
00295       c1 = ddh.c1; w1 = ddh.w1;}
00296   }
00297   Bool possibleReductionAhead() const { return (c0 && w0 > 1);}
00298 
00299   AheadInfoRep * buildAheadInfoRep() const { 
00300     WtSLAheadInfoRep *  aip = new WtSLAheadInfoRep(w0); return aip; }
00301 
00302   void printOn(ostream &ostr = cout) const 
00303   {
00304     ostr << "d="<< d << " c0="<< c0 <<" w0="<<w0<<
00305           " c1="<<c1<<" w1="<<w1<<"; ";
00306   }
00307   
00308   inline friend ostream& operator << 
00309         ( ostream& ostr, const WtSLDiffHistoryRep& dh ) {
00310                   ostr << "d="<< dh.d << " c0="<< dh.c0 <<
00311                          " w0="<<dh.w0<<" c1="<<dh.c1<<" w1="<<dh.w1<<"; ";
00312     return ostr;
00313   }
00314   
00315   
00316 private:
00317   State d;
00318   int c0, c1;
00319   int w0, w1;
00320 };
00321 
00322 class WtLexDiffHistoryRep : public DiffHistoryRep {
00323 // There are only very minor differences between this class and
00324 // WtSLDifferenceRep. The same data is held, but c1 can also take the value -1.
00325 // The function improveBy is slightly different, and the AheadInfo needs to
00326 // carry more information. The situations in which reduction can occur are
00327 // also slightly different.
00328 // Much of the code is a copy of WtSLDiffHistoryRep code, but it seems safer
00329 // to keep the 2 classes separate, because of the minor differences which could
00330 // lead to confusion if code were shared (or, for example if one class were
00331 // derived from another). 
00332 
00333 // Together with each word difference d, integers c0,w0,c1,w1
00334 // are stored, where
00335 // w0 = max{wt(w)-wt(u):l(u)=l(w),u \neq w, d=_G w^-1u }, 
00336 // where that set is non-empty,
00337 // and is otherwise meaningless. c0=0 if the set above is empty, 1 if there
00338 // is some u with wt(w)-wt(u)=w0, l(u)=l(w), d=_G w^-1u and u<w in lex,
00339 // and -1 if for all such u, w<u in lex.
00340 // w1 = min{1,max{wt(w)-wt(u):l(u)<l(w), d_G w^-1u }, 
00341 // where that set is non-empty,
00342 // and is otherwise meaningless. c1=0 if the set above is empty, 1 if there
00343 // is some u with wt(w)-wt(u)=w0, l(u)<l(w), d=_G w^-1u and u<w in lex,
00344 // and -1 if for all such u, w<u in lex.
00345 //
00346 // Given such a difference history (d,c0,w0,c1,w1)
00347 // 
00348 // Where g is a generator, and g^-1d=_G id,
00349 //    if either c0 is nonzero and w0+wt(g)>0 
00350 //       or c0=1 and w0+wt(g)=0
00351 //       or c1 is non-zero and w1+wt(g)>0,
00352 //       or c1=1 and w1+wt(g)=0
00353 //    then for some w where d=_G w^-1u, wg is equal in G to a 
00354 //       word u which is either of lesser weight, or of the same weight, 
00355 //       but preceding it in lex.
00356 //
00357 //  Where g,h are generators and g^-1dh=_G id,
00358 //     c0 is non-zero,
00359 //     and either w0+wt(g)-wt(h)>0
00360 //         or w0+wt(g)-wt(h)=0 and c0=1,
00361 //     then wg reduces to uh, of the same length as wg,
00362 //         but preceding it in weighted lex
00363 //         (in the first case it has lesser weight, in the
00364 //          second it has the same weight but is lexicographically earlier)
00365 //
00366 //   Where H is a word of length >= 2 with H^-1dg=id, c0 is non-zero
00367 //   and g^-1d(h_1h_2..h_i) is in D for all prefixes h_1h_2..h_i of H
00368 //   and w0 + wt(g) - wt(h_1) - ... wt(h_n) > 0,
00369 //   or  w0+wt(g)-wt(h_1)- .. wt(h_n)=0 and c0=1
00370 //   then wg reduces to uH which is longer, either of lower weight than wg
00371 //   or of the same weight as wg, and preceding it lexicographically.
00372 //
00373 
00374 public:
00375 //constructors
00376   WtLexDiffHistoryRep(): d(0),c0(0),w0(0),c1(0),w1(0){};
00377   WtLexDiffHistoryRep(State D,int C0,int W0,int C1,int W1):
00378     d(D),c0(C0),w0(W0),c1(C1),w1(W1){};
00379 //copy constructor
00380   WtLexDiffHistoryRep(const WtLexDiffHistoryRep & dh):
00381     d(dh.d), c0(dh.c0), w0(dh.w0), c1(dh.c1), w1(dh.w1) {};
00382   DiffHistoryRep *clone() const { return new WtLexDiffHistoryRep(*this); }
00383 //destructor
00384   ~WtLexDiffHistoryRep() {};
00385 //hash function
00386   int hash() const { return (int)d; };
00387   Bool empty() const { return (c0==0 && c1==0); };
00388 //accessors
00389   int getDiff() const { return d;};
00390   int getC0() const { return c0;};
00391   int getW0() const { return w0;};
00392   int getC1() const { return c1;};
00393   int getW1() const { return w1;};
00394 
00395   //operators
00396   int operator== ( const DiffHistoryRep & dh) const
00397   {
00398     const WtLexDiffHistoryRep& ddh = (WtLexDiffHistoryRep&)dh;
00399     return (d == ddh.d && c0 == ddh.c0 && w0 == ddh.w0 
00400                  && c1 == ddh.c1 && w1 == ddh.w1);
00401   }
00402  
00403   DiffHistoryRep&  operator= ( const DiffHistoryRep & dh )
00404   {
00405     const WtLexDiffHistoryRep& ddh = (WtLexDiffHistoryRep&)dh;
00406     d = ddh.d; c0 = ddh.c0; w0 = ddh.w0; c1 = ddh.c1; w1 = ddh.w1;
00407     return *this;
00408   }
00409   Bool sameLengthWords() const  { return (c0!=0);};
00410   void improveBy(const DiffHistoryRep & dh) 
00411   {
00412     const WtLexDiffHistoryRep& ddh = (WtLexDiffHistoryRep&)dh;
00413     if (ddh.c0 && (c0==0 || w0 < ddh.w0 || (w0==ddh.w0 && ddh.c0 == 1))){ 
00414       c0 = ddh.c0; w0 = ddh.w0;}
00415     if (ddh.c1 && (c1==0 || w1 < ddh.w1 || (w1==ddh.w1 && ddh.c1 == 1))){ 
00416       c1 = ddh.c1; w1 = ddh.w1;}
00417   }
00418   Bool possibleReductionAhead() const { 
00419      return ((c0 && w0 > 0) || (w0 > 1 && c0==1));}
00420 
00421   AheadInfoRep * buildAheadInfoRep() const { 
00422     WtLexAheadInfoRep *  aip = new WtLexAheadInfoRep(w0,c0); return aip; }
00423 
00424   void printOn(ostream &ostr = cout) const 
00425   {
00426     ostr << "d="<< d << " c0="<< c0 <<" w0="<<w0<<" c1="<<c1<<" w1="<<w1<<"; ";
00427   }
00428   
00429   inline friend ostream& operator << 
00430         ( ostream& ostr, const WtLexDiffHistoryRep& dh ) {
00431                   ostr << "d="<< dh.d << " c0="<< dh.c0 <<
00432                          " w0="<<dh.w0<<" c1="<<dh.c1<<" w1="<<dh.w1<<"; ";
00433     return ostr;
00434   }
00435   
00436   
00437 private:
00438   State d;
00439   int c0, c1;
00440   int w0, w1;
00441 };
00442 
00443 
00444 // Now the DiffHistoryVtxRep hierarchy. There is one type for each word order. 
00445 // In the comments below d is always a word difference, which has arisen
00446 // as various products of the form w^-1u
00447 
00448 class DiffHistoryVtxRep : public RefCounter {
00449 public:
00450 //constructor
00451   DiffHistoryVtxRep(): diff(0), gen(0), backptr(0),len(0) {};
00452   DiffHistoryVtxRep(State D,int G,DiffHistoryVtx * ptr,int L):
00453      diff(D), gen(G), backptr(ptr),len(L) {};
00454 //copy constructor
00455   DiffHistoryVtxRep(const DiffHistoryVtxRep & dh) {
00456     diff = dh.diff; gen = dh.gen; backptr = dh.backptr; len = dh.len;
00457   };
00458   DiffHistoryVtxRep *clone() const { return new DiffHistoryVtxRep(*this);};
00459 //destructor
00460   ~DiffHistoryVtxRep() {};
00461 
00462   State getDiff() const {return diff;};
00463   int getGenerator() const { return gen;}
00464   DiffHistoryVtx *getBackptr() const { return backptr;}
00465   int getLength() const { return len;}
00466 //operators
00467   int operator== ( const DiffHistoryVtxRep & dh) const {
00468   diff == dh.diff; gen==dh.gen; backptr == dh.backptr; len==dh.len;};
00469   DiffHistoryVtxRep&  operator= ( const DiffHistoryVtxRep & dh ) {
00470     diff = dh.diff; gen = dh.gen; backptr = dh.backptr; len = dh.len;
00471     return *this;
00472   };
00473 
00474   virtual Trichotomy betterThan(const DiffHistoryVtxRep & dh) const {};
00475 // Only to be called if the word differences match.
00476 // If the word differences match,
00477 // returns yes if whenever dh predicts a reduction, the current
00478 // DiffHistoryVtx predicts one too and there could be situations
00479 // where the current DiffHistoryVtx predicts a reduction but dh 
00480 // does not, no if dh predicts a
00481 // reduction whenever the current DiffHistoryVtx does,
00482 // dontknow if neither of the above is true (or it seems too much work 
00483 // to find out).
00484 
00485   virtual Bool possibleReductionAhead() const {};
00486 // return YES if the possibility cannot be ruled out that some w is equal
00487 // in G to a longer word u', of which u is a prefix, and such that u<w.
00488 
00489 
00490   void printOn(ostream &ostr = cout) const {
00491     ostr << "diff="<< diff <<", gen= "<<gen<<", backptr = "<<backptr
00492          <<", len="<<len<<"; ";
00493   };
00494 
00495   inline friend ostream& operator << (ostream & ostr, const DiffHistoryVtxRep& dh ) {
00496     ostr << "diff="<< dh.diff <<", gen= "<<dh.gen<<", backptr = "<<dh.backptr
00497          <<", len="<<dh.len<<"; ";
00498     return ostr;
00499   };
00500 private:
00501   State diff;
00502   int gen;
00503   DiffHistoryVtx * backptr;
00504   int len;
00505 };
00506 
00507 
00508 class SLDiffHistoryVtxRep : public DiffHistoryVtxRep {
00509 
00510 public:
00511 //constructors
00512   SLDiffHistoryVtxRep(): DiffHistoryVtxRep(),lexComp(0){};
00513   SLDiffHistoryVtxRep(State D,int G,DiffHistoryVtx * ptr,int L,int C):
00514     DiffHistoryVtxRep(D,G,ptr,L),lexComp(C) {};
00515 //copy constructor
00516   SLDiffHistoryVtxRep(const SLDiffHistoryVtxRep & dh) 
00517     : DiffHistoryVtxRep(dh), lexComp(dh.lexComp){};
00518   DiffHistoryVtxRep *clone() const { 
00519     return new SLDiffHistoryVtxRep(*this); } 
00520 //destructor
00521   ~SLDiffHistoryVtxRep() {};
00522 //accessors
00523   int getLexComp() const { return lexComp;};
00524 
00525   //operators
00526 /*
00527   int operator== ( const DiffHistoryVtxRep & dh) const
00528   {
00529 LOOK in FSA hierarchy
00530     const SLDiffHistoryVtxRep& ddh = (SLDiffHistoryVtxRep&)dh;
00531     return (SOMETHING && lexComp = ddh.lexComp);
00532   }
00533 */
00534  
00535   DiffHistoryVtxRep&  operator= ( const DiffHistoryVtxRep & dh )
00536   {
00537     (DiffHistoryVtxRep)*this = dh;
00538     const SLDiffHistoryVtxRep& ddh = (SLDiffHistoryVtxRep&)dh;
00539     lexComp = ddh.lexComp;
00540     return *this;
00541   }
00542 
00543    Trichotomy betterThan(const DiffHistoryVtxRep & dh) const {
00544 // Only to be called if the word differences match.
00545 // If the word differences match,
00546 // returns yes if whenever dh predicts a reduction, the current
00547 // DiffHistoryVtx predicts one too and there could be situations
00548 // where the current DiffHistoryVtx predicts a reduction but dh 
00549 // does not, no if dh predicts a
00550 // reduction whenever the current DiffHistoryVtx does,
00551 // dontknow if neither of the above is true (or it seems too much work 
00552 // to find out).
00553 
00554     if (getDiff()!=dh.getDiff()) return dontknow;
00555 
00556     int g1,g2;
00557 
00558 // If one DiffHistoryVtx corresponds to a shorter word and one to a word
00559 // the same length as w, neither can be considered to be better than
00560 // the other
00561     if (((g1=getGenerator())==0 && (g2=dh.getGenerator()))||
00562          g1 & g2==0) return dontknow;
00563 
00564 // If both words are shorter than w, either DiffHistoryVtx is as
00565 // good as the other, so we return no
00566 
00567     if (g1==0 && g2==0) return no;
00568 
00569 // If both words are the same length as w, we return yes if the
00570 // current DiffHistoryVtx corresponds to a word which precedes w
00571 // lexicographically, but dh does not.
00572 // Otherwise dh is just as good as the current DiffHistoryVtx, so
00573 // we return no.
00574      
00575     const SLDiffHistoryVtxRep& ddh = (SLDiffHistoryVtxRep&)dh;
00576     if (lexComp==1 && ddh.lexComp== -1) return yes;
00577     else return no; 
00578   }
00579 
00580   Bool possibleReductionAhead() const { return no;}
00581 
00582   void printOn(ostream &ostr = cout) const 
00583   {
00584     DiffHistoryVtxRep::printOn(ostr);
00585     ostr << " lexComp="<< lexComp <<"; ";
00586   }
00587   
00588   inline friend ostream& operator << 
00589         ( ostream& ostr, const SLDiffHistoryVtxRep& dh ) {
00590     DiffHistoryVtxRep ddh = (DiffHistoryVtxRep)dh;
00591     ostr << ddh << ", lexComp="<< dh.lexComp <<"; ";
00592     return ostr;
00593   }
00594   
00595   
00596 private:
00597   int lexComp; // =1 if, where d=w^-1u, w>u in lex, -1 if w<u
00598                       // 0 if not set
00599 };
00600 
00601 // at the moment the two classes below are identical.
00602 // if they don't change we could probably manage with one!
00603 
00604 class WtSLDiffHistoryVtxRep : public DiffHistoryVtxRep {
00605 
00606 public:
00607 //constructors
00608   WtSLDiffHistoryVtxRep(): DiffHistoryVtxRep(),lexComp(0), wtdiff(0){};
00609   WtSLDiffHistoryVtxRep(State D,int G,DiffHistoryVtx * ptr,int L,
00610                          int C, int WD):
00611     DiffHistoryVtxRep(D,G,ptr,L),lexComp(C), wtdiff(WD) {};
00612 //copy constructor
00613   WtSLDiffHistoryVtxRep(const WtSLDiffHistoryVtxRep & dh) 
00614     : DiffHistoryVtxRep(dh), lexComp(dh.lexComp), wtdiff(dh.wtdiff) {};
00615   DiffHistoryVtxRep *clone() const { 
00616     return new WtSLDiffHistoryVtxRep(*this); } 
00617 //destructor
00618   ~WtSLDiffHistoryVtxRep() {};
00619 //accessors
00620   int getLexComp() const { return lexComp;};
00621   int getWtDiff() const { return wtdiff;};
00622 
00623   //operators
00624 /*
00625   int operator== ( const DiffHistoryVtxRep & dh) const
00626   {
00627 LOOK in FSA hierarchy
00628     const WtSLDiffHistoryVtxRep& ddh = (WtSLDiffHistoryVtxRep&)dh;
00629     return (SOMETHING && lexComp = ddh.lexComp && wtdiff == ddh.wtdiff);
00630   }
00631 */
00632  
00633   DiffHistoryVtxRep&  operator= ( const DiffHistoryVtxRep & dh )
00634   {
00635     (WtSLDiffHistoryVtxRep)*this = dh;
00636     const WtSLDiffHistoryVtxRep& ddh = (WtSLDiffHistoryVtxRep&)dh;
00637     lexComp = ddh.lexComp; wtdiff = ddh.wtdiff;
00638     return *this;
00639   }
00640 
00641    Trichotomy betterThan(const DiffHistoryVtxRep & dh) const {
00642 // Only to be called if the word differences match.
00643 // If the word differences match,
00644 // returns yes if whenever dh predicts a reduction, the current
00645 // DiffHistoryVtx predicts one too and there could be situations
00646 // where the current DiffHistoryVtx predicts a reduction but dh 
00647 // does not, no if dh predicts a
00648 // reduction whenever the current DiffHistoryVtx does,
00649 // dontknow if neither of the above is true (or it seems too much work 
00650 // to find out).
00651 
00652     if (getDiff()!=dh.getDiff()) return dontknow;
00653 
00654     int g1,g2;
00655 
00656 // If one DiffHistoryVtx corresponds to a shorter word and one to a word
00657 // the same length as w, neither can be considered to be better than
00658 // the other
00659     if (((g1=getGenerator())==0 && (g2=dh.getGenerator()))||
00660          g1 & g2==0) return dontknow;
00661 
00662 // If both words are shorter than w, 
00663 // the current history is better if it has a larger weight difference,
00664 // but otherwise dh is at least as good as the other, so we return no.
00665 
00666     const WtSLDiffHistoryVtxRep& ddh = (WtSLDiffHistoryVtxRep&)dh;
00667     if (g1==0 && g2==0){
00668       if (wtdiff > ddh.wtdiff) return yes;
00669       else return no;
00670     }
00671 
00672 // If both words are the same length as w, we return yes if the
00673 // current DiffHistoryVtx has larger weight difference than dh,
00674 // or if it has the same weight difference as dh and corresponds 
00675 // to a word which precedes w lexicographically, but dh does not.
00676 // Otherwise dh is just as good as the current DiffHistoryVtx, so
00677 // we return no.
00678      
00679     if ((wtdiff>ddh.wtdiff) ||
00680     (wtdiff==ddh.wtdiff && lexComp==1 && ddh.lexComp== -1))
00681       return yes;
00682     else return no; 
00683   }
00684 
00685   Bool possibleReductionAhead() const { return (wtdiff > 1);}
00686 
00687   void printOn(ostream &ostr = cout) const 
00688   {
00689     DiffHistoryVtxRep::printOn(ostr);
00690     ostr << " lexComp="<< lexComp <<" wtdiff="<<wtdiff<<"; ";
00691   }
00692   
00693   inline friend ostream& operator << 
00694         ( ostream& ostr, const WtSLDiffHistoryVtxRep& dh ) {
00695     DiffHistoryVtxRep ddh = (DiffHistoryVtxRep)dh;
00696     ostr << ddh << ", lexComp="<< dh.lexComp <<" wtdiff="<<dh.wtdiff<<"; ";
00697     return ostr;
00698   }
00699   
00700   
00701 private:
00702   int lexComp;
00703   int wtdiff;
00704 };
00705 
00706 class WtLexDiffHistoryVtxRep : public DiffHistoryVtxRep {
00707 public:
00708 //constructors
00709   WtLexDiffHistoryVtxRep(): DiffHistoryVtxRep(),lexComp(0), wtdiff(0){};
00710   WtLexDiffHistoryVtxRep(State D,int G,DiffHistoryVtx * ptr,int L,
00711                          int C, int WD):
00712     DiffHistoryVtxRep(D,G,ptr,L),lexComp(C), wtdiff(WD) {};
00713 //copy constructor
00714   WtLexDiffHistoryVtxRep(const WtLexDiffHistoryVtxRep & dh) 
00715     : DiffHistoryVtxRep(dh), lexComp(dh.lexComp), wtdiff(dh.wtdiff) {};
00716   DiffHistoryVtxRep *clone() const { 
00717     return new WtLexDiffHistoryVtxRep(*this); } 
00718 //destructor
00719   ~WtLexDiffHistoryVtxRep() {};
00720 //accessors
00721   int getLexComp() const { return lexComp;};
00722   int getWtDiff() const { return wtdiff;};
00723 
00724   //operators
00725 /*
00726   int operator== ( const DiffHistoryVtxRep & dh) const
00727   {
00728 LOOK in FSA hierarchy
00729     const WtLexDiffHistoryVtxRep& ddh = (WtLexDiffHistoryVtxRep&)dh;
00730     return (SOMETHING && lexComp = ddh.lexComp && wtdiff == ddh.wtdiff);
00731   }
00732 */
00733  
00734   DiffHistoryVtxRep&  operator= ( const DiffHistoryVtxRep & dh )
00735   {
00736     (WtLexDiffHistoryVtxRep)*this = dh;
00737     const WtLexDiffHistoryVtxRep& ddh = (WtLexDiffHistoryVtxRep&)dh;
00738     lexComp = ddh.lexComp; wtdiff = ddh.wtdiff;
00739     return *this;
00740   }
00741 
00742    Trichotomy betterThan(const DiffHistoryVtxRep & dh) const {
00743 // Only to be called if the word differences match.
00744 // If the word differences match,
00745 // returns yes if whenever dh predicts a reduction, the current
00746 // DiffHistoryVtx predicts one too and there could be situations
00747 // where the current DiffHistoryVtx predicts a reduction but dh 
00748 // does not, no if dh predicts a
00749 // reduction whenever the current DiffHistoryVtx does,
00750 // dontknow if neither of the above is true (or it seems too much work 
00751 // to find out).
00752 
00753     if (getDiff()!=dh.getDiff()) return dontknow;
00754 
00755     int g1,g2;
00756 
00757 // If one DiffHistoryVtx corresponds to a shorter word and one to a word
00758 // the same length as w, neither can be considered to be better than
00759 // the other
00760     if (((g1=getGenerator())==0 && (g2=dh.getGenerator()))||
00761          g1 & g2==0) return dontknow;
00762 
00763 // If both words are shorter than w, 
00764 // the current history is better if it has a larger weight difference,
00765 // but otherwise dh is at least as good as the other, so we return no.
00766 
00767     const WtLexDiffHistoryVtxRep& ddh = (WtLexDiffHistoryVtxRep&)dh;
00768     if (g1==0 && g2==0){
00769       if (wtdiff > ddh.wtdiff) return yes;
00770       else return no;
00771     }
00772 
00773 // If both words are the same length as w, we return yes if the
00774 // current DiffHistoryVtx has larger weight difference than dh,
00775 // or if it has the same weight difference as dh and corresponds 
00776 // to a word which precedes w lexicographically, but dh does not.
00777 // Otherwise dh is just as good as the current DiffHistoryVtx, so
00778 // we return no.
00779      
00780     if ((wtdiff>ddh.wtdiff) ||
00781     (wtdiff==ddh.wtdiff && lexComp==1 && ddh.lexComp== -1))
00782       return yes;
00783     else return no; 
00784   }
00785 
00786 
00787   Bool possibleReductionAhead() const { 
00788      return (wtdiff>1 ||(lexComp==1 && wtdiff > 0));}
00789 
00790   void printOn(ostream &ostr = cout) const 
00791   {
00792     DiffHistoryVtxRep::printOn(ostr);
00793     ostr << " lexComp="<< lexComp <<" wtdiff="<<wtdiff<<"; ";
00794   }
00795   
00796   inline friend ostream& operator << 
00797         ( ostream& ostr, const WtLexDiffHistoryVtxRep& dh ) {
00798     DiffHistoryVtxRep ddh = (DiffHistoryVtxRep)dh;
00799     ostr << ddh << ", lexComp="<< dh.lexComp <<
00800           " wtdiff="<<dh.wtdiff<<"; ";
00801     return ostr;
00802   }
00803   
00804   
00805 private:
00806   int lexComp;
00807   int wtdiff;
00808 };
00809 
00810 
00811 #endif

Generated at Tue Jun 19 09:49:36 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001