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

/magnus/back_end/KB/include/DiffMachineRep.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: DiffMachineRep.h,v 1.4 1999/11/23 20:28:52 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 DiffMachineRep class.
00009 //
00010 // Principal Author: Sarah Rees
00011 //
00012 // Status: in progress
00013 //
00014 // Revision History:
00015 //
00016 // * 08/96 Dmitry B. implemented IPC tools.
00017 //
00018 
00019 #ifndef _DiffMachineRep_H_
00020 #define _DiffMachineRep_H_
00021 
00022 #include "Word.h"
00023 #include "Set.h"
00024 #include "Vector.h"
00025 #include "DFSARep.h"
00026 #include "DFSA.h"
00027 #include "DiffHistory.h"
00028 #include "WordOrder.h"
00029 
00030 
00031 class DiffMachineRep : public GroupDFSARep {
00032 public:
00033   //@rn Kludge!!?
00034   DiffMachineRep() : GroupDFSARep() {}
00035 
00036   DiffMachineRep(const VectorOf<Chars> & genNames) : 
00037     GroupDFSARep("",genNames),
00038     diffs(1,1) { 
00039      Word w; diffs[0]=w; // position 0 isn't actually used
00040      setNumStrings(2);
00041     }
00042 
00043   DiffMachineRep(const VectorOf<Chars> & genNames,const WordOrder & word_order) : 
00044     GroupDFSARep("",genNames,word_order),
00045     diffs(1,1) { 
00046      Word w; diffs[0]=w; // position 0 isn't actually used
00047      setNumStrings(2);
00048     }
00049 
00050   DiffMachineRep( const DiffMachineRep& D ) :  // Copy constructor does deep copy.
00051     GroupDFSARep(D), diffs(D.diffs) { }
00052 
00053   DiffMachineRep & operator = ( const DiffMachineRep & D ) 
00054   {
00055     GroupDFSARep& temp = *this;
00056     temp = (GroupDFSARep)D;
00057     (DFSARep)*this = (DFSARep)D;
00058     diffs = D.diffs;
00059     return *this;
00060   }
00061   FSARep *clone() const { return new DiffMachineRep(*this); }
00062 
00063   Bool operator == ( const DiffMachineRep& D ) const { 
00064     if (equalDFSA(D)==0) return 0;
00065     else for (State s=1;s<=getNumStates();s++){
00066       if (category(s)==1 && diffs[s] != (D.diffs)[s]) 
00067         return 0;
00068     }
00069     return 1;
00070   } 
00071 
00072 
00073 //  Bool nextAcceptedWord(Word w, int*& history) const {}; //@rn bad arg
00074   void minimize() {};
00075   
00076   void readFrom(istream &str = cin);
00077 
00078   void printAccepting(ostream &str = cout) const ;
00079   void printStates(ostream &str = cout) const ;
00080 
00081  // Set/reset the number of states in the automaton to numOfStates 
00082    
00083   void setNumStates(int numOfStates);
00084     
00085   Word getDifference(State s) const { 
00086       //cerr << "Got difference  number" << s << ": "<< diffs[s] << endl;
00087                                           return diffs[s];}
00088 
00089   void setDifference(State s,Word w) { diffs[s] = w;}
00090 
00091   void addDifferencesEqn
00092        (const Word & w1,const Word & w2,const WordOrder & word_order);
00093   void closeUnderSubstrings(int mode,const WordOrder & word_order);
00094   void closeUnderInverses(const WordOrder & word_order);
00095   Bool rewrite(Word & w) const;
00096   Bool rewrite(Word & w,const WordOrder & word_order) const;
00097   GroupDFSA wordAcceptor(const WordOrder & word_order) const;
00098   void DiffMachineRep::buildDifferenceMachine(DiffMachineRep & D,
00099        const SetOf<Word> & differences,const WordOrder & word_order) const;
00100   void DiffMachineRep::rebuildDifferenceMachine(const WordOrder & word_order);
00101 
00102 
00103   /////////////////////////////////////////////////////////////////////////
00104   //                                                                     //
00105   // IPC tools:                                                          //
00106   //                                                                     //
00107   /////////////////////////////////////////////////////////////////////////
00108     
00109   void write( ostream& ostr ) const
00110   {
00111     GroupDFSARep::write(ostr);
00112     ostr < diffs;
00113   }
00114 
00115   void read( istream& istr )
00116   {
00117     GroupDFSARep::read(istr);
00118     istr > diffs;
00119   }
00120 
00121 private:
00122 
00123   VectorOf<Word> diffs;
00124   void buildWordAcceptor(GroupDFSARep & Wp,const WordOrder & word_order) const;
00125   GroupDFSA convertToGroupDFSA(GroupDFSARep * Wp) const;
00126   Bool reductionAhead(State d,const AheadInfo & ai,const WordOrder & word_order) const;
00127 };
00128 
00129 #endif

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