// // $Source: /cvsroot/gambit/gambit/sources/tools/lp/ludecomp.h,v $ // $Date: 2006/07/20 16:23:16 $ // $Revision: 1.6 $ // // DESCRIPTION: // Interface to LU decomposition classes // // This file is part of Gambit // Copyright (c) 2002, The Gambit Project // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef LUDECOMP_H #define LUDECOMP_H #include "libgambit/libgambit.h" #include "basis.h" template class Tableau; // --------------------------------------------------------------------------- // Class EtaMatrix // --------------------------------------------------------------------------- template class EtaMatrix { public: int col; Gambit::Vector etadata; EtaMatrix(int c, Gambit::Vector &v) : col(c), etadata(v) {}; // required for list class bool operator==(const EtaMatrix &) const; bool operator!=(const EtaMatrix &) const; }; // --------------------------------------------------------------------------- // Class LUdecomp // --------------------------------------------------------------------------- template class LUdecomp { private: Tableau &tab; Basis &basis; Gambit::List< EtaMatrix > L; Gambit::List< EtaMatrix > U; Gambit::List< EtaMatrix > E; Gambit::List< int > P; Gambit::Vector scratch1; // scratch vectors so we don't reallocate them Gambit::Vector scratch2; // everytime we do something. int refactor_number; int iterations; int total_operations; const LUdecomp *parent; int copycount; // don't use this copy constructor LUdecomp( const LUdecomp &a); // don't use the equals operator, use the Copy function instead LUdecomp& operator=(const LUdecomp&); public: class BadPivot : public Gambit::Exception { public: virtual ~BadPivot(); std::string GetDescription(void) const; }; class BadCount : public Gambit::Exception { public: virtual ~BadCount(); std::string GetDescription(void) const; }; // ------------------------ // Constructors, Destructor // ------------------------ // copy constructor // note: Copying will fail an assertion if you try to update or delete // the original before the copy has been deleted, refactored // Or set to something else. LUdecomp( const LUdecomp &, Tableau & ); // Decompose given matrix LUdecomp( Tableau &, int rfac = 0 ); // Destructor ~LUdecomp(); // -------------------- // Public Members // -------------------- // copies the LUdecomp given (expect for the basis &). void Copy( const LUdecomp &, Tableau & ); // replace (update) the column given with the vector given. void update( int, int matcol ); // matcol is the column number in the matrix // refactor void refactor(); // solve: Bk d = a void solve (const Gambit::Vector &, Gambit::Vector & ) const; // solve: y Bk = c void solveT( const Gambit::Vector &, Gambit::Vector & ) const; // set number of etamatrices added before refactoring; // if number is set to zero, refactoring is done automatically. // if number is < 0, no refactoring is done; void SetRefactor( int ); //------------------- // Private Members //------------------- private: void FactorBasis(); void GaussElem( Gambit::Matrix &, int, int ); bool CheckBasis(); bool RefactorCheck(); void BTransE( Gambit::Vector & ) const; void FTransE( Gambit::Vector & ) const; void BTransU( Gambit::Vector & ) const; void FTransU( Gambit::Vector & ) const; void LPd_Trans( Gambit::Vector & ) const; void yLP_Trans( Gambit::Vector & ) const; void VectorEtaSolve( const Gambit::Vector &v, const EtaMatrix &, Gambit::Vector &y ) const; void EtaVectorSolve( const Gambit::Vector &v, const EtaMatrix &, Gambit::Vector &d ) const; void yLP_mult( const Gambit::Vector &y, int j, Gambit::Vector &) const; void LPd_mult( Gambit::Vector &d, int j, Gambit::Vector &) const; }; // end of class LUdecomp #endif // LUDECOMP_H