# IpMatrix.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2004, 2008 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Eclipse Public License.
    00004 //
    00005 // $Id: IpMatrix.hpp 2276 2013-05-05 12:33:44Z stefan $
    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     {}
    00040
    00042     virtual ~Matrix()
    00043     {}
    00045
    00051     void MultVector(Number alpha, const Vector& x, Number beta,
    00052                     Vector& y) const
    00053     {
    00054       MultVectorImpl(alpha, x, beta, y);
    00055     }
    00056
    00061     void TransMultVector(Number alpha, const Vector& x, Number beta,
    00062                          Vector& y) const
    00063     {
    00064       TransMultVectorImpl(alpha, x, beta, y);
    00065     }
    00067
    00076     void AddMSinvZ(Number alpha, const Vector& S, const Vector& Z,
    00077                    Vector& X) const;
    00078
    00082     void SinvBlrmZMTdBr(Number alpha, const Vector& S,
    00083                         const Vector& R, const Vector& Z,
    00084                         const Vector& D, Vector& X) const;
    00086
    00089     bool HasValidNumbers() const;
    00090
    00094     inline
    00095     Index  NRows() const;
    00096
    00098     inline
    00099     Index  NCols() const;
    00101
    00107     void ComputeRowAMax(Vector& rows_norms, bool init=true) const
    00108     {
    00109       DBG_ASSERT(NRows() == rows_norms.Dim());
    00110       if (init) rows_norms.Set(0.);
    00111       ComputeRowAMaxImpl(rows_norms, init);
    00112     }
    00116     void ComputeColAMax(Vector& cols_norms, bool init=true) const
    00117     {
    00118       DBG_ASSERT(NCols() == cols_norms.Dim());
    00119       if (init) cols_norms.Set(0.);
    00120       ComputeColAMaxImpl(cols_norms, init);
    00121     }
    00123
    00128     virtual void Print(SmartPtr<const Journalist> jnlst,
    00129                        EJournalLevel level,
    00130                        EJournalCategory category,
    00131                        const std::string& name,
    00132                        Index indent=0,
    00133                        const std::string& prefix="") const;
    00134     virtual void Print(const Journalist& jnlst,
    00135                        EJournalLevel level,
    00136                        EJournalCategory category,
    00137                        const std::string& name,
    00138                        Index indent=0,
    00139                        const std::string& prefix="") const;
    00141
    00143     inline
    00144     SmartPtr<const MatrixSpace> OwnerSpace() const;
    00145
    00146   protected:
    00154     virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
    00155
    00159     virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
    00160
    00165     virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
    00166                                Vector& X) const;
    00167
    00171     virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
    00172                                     const Vector& R, const Vector& Z,
    00173                                     const Vector& D, Vector& X) const;
    00174
    00178     virtual bool HasValidNumbersImpl() const
    00179     {
    00180       return true;
    00181     }
    00182
    00186     virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const = 0;
    00190     virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const = 0;
    00191
    00193     virtual void PrintImpl(const Journalist& jnlst,
    00194                            EJournalLevel level,
    00195                            EJournalCategory category,
    00196                            const std::string& name,
    00197                            Index indent,
    00198                            const std::string& prefix) const =0;
    00200
    00201   private:
    00211     Matrix();
    00212
    00214     Matrix(const Matrix&);
    00215
    00217     Matrix& operator=(const Matrix&);
    00219
    00220     const SmartPtr<const MatrixSpace> owner_space_;
    00221
    00224     mutable TaggedObject::Tag valid_cache_tag_;
    00225     mutable bool cached_valid_;
    00227   };
    00228
    00229
    00238   class MatrixSpace : public ReferencedObject
    00239   {
    00240   public:
    00246     MatrixSpace(Index nRows, Index nCols)
    00247         :
    00248         nRows_(nRows),
    00249         nCols_(nCols)
    00250     {}
    00251
    00253     virtual ~MatrixSpace()
    00254     {}
    00256
    00260     virtual Matrix* MakeNew() const=0;
    00261
    00263     Index NRows() const
    00264     {
    00265       return nRows_;
    00266     }
    00268     Index NCols() const
    00269     {
    00270       return nCols_;
    00271     }
    00272
    00276     bool IsMatrixFromSpace(const Matrix& matrix) const
    00277     {
    00278       return (matrix.OwnerSpace() == this);
    00279     }
    00280
    00281   private:
    00291     MatrixSpace();
    00292
    00294     MatrixSpace(const MatrixSpace&);
    00295
    00297     MatrixSpace& operator=(const MatrixSpace&);
    00299
    00301     const Index nRows_;
    00303     const Index nCols_;
    00304   };
    00305
    00306
    00307   /* Inline Methods */
    00308   inline
    00309   Index  Matrix::NRows() const
    00310   {
    00311     return owner_space_->NRows();
    00312   }
    00313
    00314   inline
    00315   Index  Matrix::NCols() const
    00316   {
    00317     return owner_space_->NCols();
    00318   }
    00319
    00320   inline
    00321   SmartPtr<const MatrixSpace> Matrix::OwnerSpace() const
    00322   {
    00323     return owner_space_;
    00324   }
    00325
    00326 } // namespace Ipopt
    00327
    00328 // Macro definitions for debugging matrices
    00329 #if COIN_IPOPT_VERBOSITY == 0
    00330 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
    00331 #else
    00332 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
    00333    if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
    00334       if (dbg_jrnl.Jnlst()!=NULL) { \
    00335         (__mat).Print(dbg_jrnl.Jnlst(), \
    00336         J_ERROR, J_DBG, \
    00337         __mat_name, \
    00338         dbg_jrnl.IndentationLevel()*2, \
    00339         "# "); \
    00340       } \
    00341    }
    00342 #endif // #if COIN_IPOPT_VERBOSITY == 0
    00343
    00344 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines