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

/magnus/back_end/Matrix/include/GaussTransformation.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: GaussTransformation.h,v 1.8 2000/02/09 22:36:53 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 the GaussTransformation class.
00009 //
00010 // Principal Authors: Dmitry Bormotov, Aleksey Myasnikov
00011 //
00012 // Status: Useable
00013 //
00014 // Revision History:
00015 //
00016 
00017 
00018 #ifndef _GAUSS_TRANSFORMATION_H_
00019 #define _GAUSS_TRANSFORMATION_H_
00020 
00021 #include "Integer.h"
00022 #include "Rational.h"
00023 #include "Matrix.h"
00024 
00025 // --------------------------------------------------------------------------//
00026 // ------------------------- GaussTransformation ----------------------------//
00027 // --------------------------------------------------------------------------//
00028 
00029 
00030 
00031 template <class T> class GaussTransformation {
00032 
00033 
00034 public:
00035 
00036 
00037   /////////////////////////////////////////////////////////////////////////
00038   //                                                                     //
00039   // Constructors:                                                       //
00040   //                                                                     //
00041   /////////////////////////////////////////////////////////////////////////
00042   // If buildTransMatrix or buildInvTransMatrix = true the transformation matrix would be built
00043   GaussTransformation(const Matrix<T>& M, bool buildTransMatrix = false, bool buildInvTransMatrix = false) : 
00044     matrix( M ), 
00045     bDone( false ), bStart( false ),transformed(false), 
00046     isSingularMatrix( dontknow ), isInvertibleMatrix( dontknow ),
00047     transMatrix(NULL),invTransMatrix(NULL),buildTransformations(buildTransMatrix),
00048     buildInverseTransformations(buildInvTransMatrix) 
00049   { }
00050 
00051   // Copy constructor and operator = are disabled.
00052   GaussTransformation(const GaussTransformation&);
00053   GaussTransformation operator = ( const GaussTransformation& );
00054 
00055   ~GaussTransformation() {
00056     if (transMatrix)  delete transMatrix;
00057   }
00058    
00059   /////////////////////////////////////////////////////////////////////////
00060   //                                                                     //
00061   // Activation members:                                                 //
00062   //                                                                     //
00063   /////////////////////////////////////////////////////////////////////////
00064 
00065   // This was left, because sometimes Gauss runing with breaks or restarting,
00066   // so it's needed to reinitialize the algorithm
00067   void startComputation( );
00068          
00069   // Runs until the end of transformation. It's long time algorithm
00070   void run(){
00071         continueComputation( RUNALL);
00072   }
00073 
00074   // Run for 'rowNum' rows, then suspends.
00075   void runRow(int rowNum);
00076 
00077   // Runs until a zero element appears on diagonal.
00078   void runUntilDiagHasZero();
00079 
00080   // Runs while diagonal elements are 1 or -1.
00081   // It's a very stupid name for such procedure, but i couldn't find something better.
00082   void runWhileDiagHasSingles();
00083 
00084   // returns the indexs of current diagonal element.
00085   int getCurrentRow() const { return currentRow-1;}
00086   int getCurrentCol() const { return currentCol-1;}
00087   /////////////////////////////////////////////////////////////////////////
00088   //                                                                     //
00089   // Status Queries:                                                     //
00090   //                                                                     //
00091   /////////////////////////////////////////////////////////////////////////
00092 
00093   bool canChange( ) const { return !bStart; }
00094   // You can change matrix only if GausTransformation is not in process.
00095   // Return true if you can change matrix.
00096 
00097   bool done( ) const { return bDone; }
00098   // True if computation was finished
00099   /////////////////////////////////////////////////////////////////////////
00100   //                                                                     //
00101   // Accessors:                                                          //
00102   //                                                                     //
00103   /////////////////////////////////////////////////////////////////////////
00104   
00105   Trichotomy isSingular( ) const 
00106   {
00107     return isSingularMatrix;
00108   }
00109 
00110   Trichotomy isInvertible( ) const; 
00111   
00112   // Returns transformated matrix
00113   const Matrix<T>& getMatrix() const
00114     {
00115       return matrix;
00116     }
00117   // Returns transformation matrix
00118   const Matrix<T>& getTrMatrix()const
00119     {
00120    #if SAFETY > 0
00121     if (!transMatrix )
00122       error("void GaussTransformation::getTrMatrix( ) : object was not built.");
00123    #endif
00124       return *transMatrix;
00125     }
00126   // Returns inverse transformation matrix
00127   const Matrix<T>& getInvTrMatrix()const
00128     {
00129    #if SAFETY > 0
00130     if (!invTransMatrix )
00131       error("void GaussTransformation::getInvTrMatrix( ) : object was not built.");
00132    #endif
00133       return *invTransMatrix;
00134     }
00135   
00136   // Returns reference on transformated matrix
00137   Matrix<T>& refMatrix()
00138     {
00139    #if SAFETY > 0
00140     if (!canChange() )
00141       error("void GaussTransformation::refMatrix( ) : transformations are in process.");
00142    #endif
00143       return matrix;
00144     }
00145     bool isTransformed() const{
00146       return transformed;
00147     }
00148 
00149 private:
00150 
00151   /////////////////////////////////////////////////////////////////////////
00152   //                                                                     //
00153   // Data Members:                                                       //
00154   //                                                                     //
00155   /////////////////////////////////////////////////////////////////////////
00156 
00157   bool bDone; 
00158   bool bStart;
00159   bool transformed;
00160   Trichotomy isSingularMatrix;
00161   Trichotomy isInvertibleMatrix;
00162 
00163   Matrix<T> matrix;  // Main  matrix
00164   Matrix<T>* transMatrix; // Transformation matrix
00165   Matrix<T>* invTransMatrix; // Inverse transformation matrix
00166   int untilRow;  // Number of rows to run gaus transformation for
00167   int currentRow; // Current row of transformation
00168   int currentCol; // Current column of transformation
00169   bool buildTransformations; // True if transformation matrix is building
00170   bool buildInverseTransformations; // True if inverse transformation matrix is building
00171 
00172   // Constants for types of running a computations.
00173   static const int  UNTILNOT_0 = 0;
00174   static const int  UNTIL_1 = 1;
00175   static const int  RUNROW = 2;
00176   static const int  RUNALL = 3;
00177   /////////////////////////////////////////////////////////////////////////
00178   //                                                                     //
00179   // Inner methods:                                                      //
00180   //                                                                     //
00181   /////////////////////////////////////////////////////////////////////////
00182   void continueComputation( int whatDeal);
00183 
00184   void finishComputation( Trichotomy isSingular, Trichotomy isInvertible )
00185   {
00186     if (isSingularMatrix != yes)
00187         isSingularMatrix = isSingular;
00188     if (isInvertibleMatrix != no)
00189         isInvertibleMatrix = isInvertible;
00190     if (matrix.height()!=matrix.width())
00191         isSingularMatrix = no;
00192     bDone = true;
00193     bStart = false;
00194   }
00195 
00196   void addRow( int firstRow, int secondRow, T koef);
00197   // Adds elements of secondRow * koef to elements of firstRow
00198 
00199   void makeZero( int& row1, int& row2 );
00200   // Makes a zero in column
00201 
00202   /////////////////////////////////////////////////////////////////////////
00203   //                                                                     //
00204   //  Debugging stuff:                                                   //
00205   //                                                                     //
00206   /////////////////////////////////////////////////////////////////////////
00207 
00208 #ifdef DEBUG
00209 
00210   //friend int main( );
00211 
00212 #endif
00213 
00214 };
00215 #endif
00216 
00217 
00218 

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