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

/magnus/back_end/Equations/include/TupleEnumerator.h

Go to the documentation of this file.
00001 // Copyright (C) 1995 The New York Group Theory Cooperative
00002 // See magnus/doc/COPYRIGHT for the full notice.
00003 
00004 // Contents: Definition and implementation of utility class 
00005 //           EnumeratorOfWordTuples.
00006 //
00007 // Principal Authors: Eugeny Paderin, Dmitry Pechkin
00008 //
00009 // Status: in progress
00010 //
00011 // Revision History:
00012 //
00013 // Special remarks:
00014 //
00015 // * Class EnumeratorOfWordTuple is implemented for to allow enumerating
00016 //   of tuple of word which may contain different number of generators.
00017 //
00018 //   It implicitly uses techniques of meta-enumerator: 
00019 //   enumerator of enumerators. Low level enumerators should supply only
00020 //   two operations: reset(restart) and get a next element.
00021 //   @dp do we want meta-enumerator at all?
00022 //
00023 // * Efficiency of the class depends on ability of Word::nextFreelyReduced()
00024 //   to effectively produce next freely reduced word.
00025 //
00026 // * Usage:
00027 //
00028 //   Semantics of using of class EnumeratorOfWordTuple is like iterator.
00029 //   
00030 //   Example of use:
00031 //
00032 //   FreeGroup F2(2);
00033 //   FreeGroup F3(3);
00034 //   EnumeratorOfWordTuple tuple(3, 2);
00035 //
00036 //   // Enumerating of maps F3 to F2:
00037 //   while( 1 ) {
00038 //      VectorOf<Word> images = tuple.value();
00039 //      Map M(F3, F2, images);
00040 //      cout << M << endl;
00041 //      ewt.next();
00042 //   }
00043 //
00044 //  More complex example:
00045 //    Enumerating of maps from F3 into F2 and from F2 into F3 simultaneously.
00046 //
00047 //      VectorOf<int> gens(5);
00048 //      gens[0]=gens[1]=gens[2]= 2; // 3 gens in the domain, 2 gens in the range
00049 //      gens[3]=gens[4]= 3;         // 2 gens in the domain, 3 gens in the range
00050 //      EnumeratorOfWordTuples tuples(gens);
00051 //      for(i = 0; i<100; i++) {
00052 //              VectorOf<Word> images = tuples.value();
00053 //              Map M32(F3,F2);
00054 //              for(int j = 0; j<3; j++)
00055 //                      M32.setGeneratingImages(j, images[j]);
00056 //              cout << "F3->F2: " << M32 << "; ";
00057 //              Map M23(F2, F3);
00058 //              for(j = 0; j<2; j++)
00059 //                      M23.setGeneratingImages(j, images[j+3]);
00060 //              cout << "F2->F3: " << M23 << endl;
00061 //              tuples.next();
00062 //      }
00063 //
00064 //
00065 
00066 #ifndef _TUPLE_ENUMERATOR_H_
00067 #define _TUPLE_ENUMERATOR_H_
00068 
00069 #include "Vector.h"
00070 #include "Word.h"
00071 
00072 class EnumeratorOfWordTuples
00073 {
00074 public:
00075 
00076         ///////////////////////////////////////////////////////////////////
00077         //                                                               //
00078         // Constructors                                                  //
00079         //                                                               //
00080         ///////////////////////////////////////////////////////////////////
00081 
00082   // no default constructor
00083 
00084         EnumeratorOfWordTuples(VectorOf<int> numOfGens) :
00085                 tupleSize(numOfGens.length()), tuple(numOfGens.length()),
00086                 maxWord(numOfGens.length()), numberOfGens(numOfGens),
00087                 fixedWord(0) {}
00088 
00089         EnumeratorOfWordTuples(int size, int numOfGens) :
00090                 tupleSize(size), tuple(size), maxWord(size),
00091                 numberOfGens(size), fixedWord(0)
00092         {
00093                 for(int i=0; i<size; i++)
00094                         numberOfGens[i] = numOfGens;
00095         }
00096 
00097         // copy constructor, operator=, and destructor provided by compiler.
00098 
00099         ///////////////////////////////////////////////////////////////////
00100         //                                                               //
00101         // Methods                                                       //
00102         //                                                               //
00103         ///////////////////////////////////////////////////////////////////
00104 
00105         void reset() {
00106                 for(int i=0; i<tupleSize; i++)
00107                         tuple[i] = maxWord[i] = Word();
00108                 fixedWord = tupleSize;
00109         }
00110   // Resets this enumerator to the state it was in after construction.
00111 
00112         void next();
00113         // Advances this enumerator.
00114 
00115         VectorOf<Word> value() const  { return tuple; }
00116   // Returns the current value.
00117 
00118 private:
00119 
00120         // Data members:
00121 
00122         int tupleSize;
00123 
00124         VectorOf<Word> tuple;
00125         VectorOf<Word> maxWord;
00126         VectorOf<int>  numberOfGens;
00127 
00128         int fixedWord;
00129 
00130 };
00131 
00132 class CantorEnumeration {
00133 public:
00134   static Integer encodePair( const Integer& x, const Integer& y);
00135 
00136   static void decodePair( const Integer& n, Integer& x, Integer& y );
00137 
00138   static Integer encodeTuple( const VectorOf<Integer>& tuple );
00139 
00140   static VectorOf<Integer> decodeTuple( const Integer& number );
00141 };
00142 
00143 
00144 #endif
00145 

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