/home/coin/SVN-release/CoinAll-1.1.0/Ipopt/src/LinAlg/IpMatrix.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2006 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpMatrix.hpp 1035 2007-07-03 01:03:28Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPMATRIX_HPP__
00010 #define __IPMATRIX_HPP__
00011 
00012 #include "IpVector.hpp"
00013 
00014 namespace Ipopt
00015 {
00016 
00017   /* forward declarations */
00018   class MatrixSpace;
00019 
00027   class Matrix : public TaggedObject
00028   {
00029   public:
00035     Matrix(const MatrixSpace* owner_space)
00036         :
00037         TaggedObject(),
00038         owner_space_(owner_space),
00039         valid_cache_tag_(0)
00040     {}
00041 
00043     virtual ~Matrix()
00044     {}
00046 
00052     void MultVector(Number alpha, const Vector& x, Number beta,
00053                     Vector& y) const
00054     {
00055       MultVectorImpl(alpha, x, beta, y);
00056     }
00057 
00062     void TransMultVector(Number alpha, const Vector& x, Number beta,
00063                          Vector& y) const
00064     {
00065       TransMultVectorImpl(alpha, x, beta, y);
00066     }
00068 
00077     void AddMSinvZ(Number alpha, const Vector& S, const Vector& Z,
00078                    Vector& X) const;
00079 
00083     void SinvBlrmZMTdBr(Number alpha, const Vector& S,
00084                         const Vector& R, const Vector& Z,
00085                         const Vector& D, Vector& X) const;
00087 
00090     bool HasValidNumbers() const;
00091 
00092     //* @name Information about the size of the matrix */
00094 
00095     Index  NRows() const;
00096 
00098     Index  NCols() const;
00100 
00105     virtual void Print(SmartPtr<const Journalist> jnlst,
00106                        EJournalLevel level,
00107                        EJournalCategory category,
00108                        const std::string& name,
00109                        Index indent=0,
00110                        const std::string& prefix="") const;
00111     virtual void Print(const Journalist& jnlst,
00112                        EJournalLevel level,
00113                        EJournalCategory category,
00114                        const std::string& name,
00115                        Index indent=0,
00116                        const std::string& prefix="") const;
00118 
00120     SmartPtr<const MatrixSpace> OwnerSpace() const;
00121 
00122   protected:
00130     virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
00131 
00135     virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
00136 
00141     virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
00142                                Vector& X) const;
00143 
00147     virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
00148                                     const Vector& R, const Vector& Z,
00149                                     const Vector& D, Vector& X) const;
00150 
00154     virtual bool HasValidNumbersImpl() const
00155     {
00156       return true;
00157     }
00158 
00160     virtual void PrintImpl(const Journalist& jnlst,
00161                            EJournalLevel level,
00162                            EJournalCategory category,
00163                            const std::string& name,
00164                            Index indent,
00165                            const std::string& prefix) const =0;
00167 
00168   private:
00178     Matrix();
00179 
00181     Matrix(const Matrix&);
00182 
00184     Matrix& operator=(const Matrix&);
00186 
00187     const SmartPtr<const MatrixSpace> owner_space_;
00188 
00191     mutable TaggedObject::Tag valid_cache_tag_;
00192     mutable bool cached_valid_;
00194   };
00195 
00196 
00205   class MatrixSpace : public ReferencedObject
00206   {
00207   public:
00213     MatrixSpace(Index nRows, Index nCols)
00214         :
00215         nRows_(nRows),
00216         nCols_(nCols)
00217     {}
00218 
00220     virtual ~MatrixSpace()
00221     {}
00223 
00227     virtual Matrix* MakeNew() const=0;
00228 
00230     Index NRows() const
00231     {
00232       return nRows_;
00233     }
00235     Index NCols() const
00236     {
00237       return nCols_;
00238     }
00239 
00243     bool IsMatrixFromSpace(const Matrix& matrix) const
00244     {
00245       return (matrix.OwnerSpace() == this);
00246     }
00247 
00248   private:
00258     MatrixSpace();
00259 
00261     MatrixSpace(const MatrixSpace&);
00262 
00264     MatrixSpace& operator=(const MatrixSpace&);
00266 
00268     const Index nRows_;
00270     const Index nCols_;
00271   };
00272 
00273 
00274   /* Inline Methods */
00275   inline
00276   Index  Matrix::NRows() const
00277   {
00278     return owner_space_->NRows();
00279   }
00280 
00281   inline
00282   Index  Matrix::NCols() const
00283   {
00284     return owner_space_->NCols();
00285   }
00286 
00287   inline
00288   SmartPtr<const MatrixSpace> Matrix::OwnerSpace() const
00289   {
00290     return owner_space_;
00291   }
00292 
00293 } // namespace Ipopt
00294 
00295 // Macro definitions for debugging matrices
00296 #if COIN_IPOPT_VERBOSITY == 0
00297 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
00298 #else
00299 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
00300    if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
00301       if (dbg_jrnl.Jnlst()!=NULL) { \
00302         (__mat).Print(dbg_jrnl.Jnlst(), \
00303         J_ERROR, J_DBG, \
00304         __mat_name, \
00305         dbg_jrnl.IndentationLevel()*2, \
00306         "# "); \
00307       } \
00308    }
00309 #endif // #if COIN_IPOPT_VERBOSITY == 0
00310 
00311 #endif

Generated on Sun Nov 14 14:06:36 2010 for Coin-All by  doxygen 1.4.7