- Main Page
- Classes
- Files

- File List
- File Members

# src/LinAlg/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 2472 2014-04-05 17:47:20Z 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         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
    00095     inline
    00096     Index  NRows() const;
    00097
    00099     inline
    00100     Index  NCols() const;
    00102
    00108     void ComputeRowAMax(Vector& rows_norms, bool init=true) const
    00109     {
    00110       DBG_ASSERT(NRows() == rows_norms.Dim());
    00111       if (init) rows_norms.Set(0.);
    00112       ComputeRowAMaxImpl(rows_norms, init);
    00113     }
    00117     void ComputeColAMax(Vector& cols_norms, bool init=true) const
    00118     {
    00119       DBG_ASSERT(NCols() == cols_norms.Dim());
    00120       if (init) cols_norms.Set(0.);
    00121       ComputeColAMaxImpl(cols_norms, init);
    00122     }
    00124
    00129     virtual void Print(SmartPtr<const Journalist> jnlst,
    00130                        EJournalLevel level,
    00131                        EJournalCategory category,
    00132                        const std::string& name,
    00133                        Index indent=0,
    00134                        const std::string& prefix="") const;
    00135     virtual void Print(const Journalist& jnlst,
    00136                        EJournalLevel level,
    00137                        EJournalCategory category,
    00138                        const std::string& name,
    00139                        Index indent=0,
    00140                        const std::string& prefix="") const;
    00142
    00144     inline
    00145     SmartPtr<const MatrixSpace> OwnerSpace() const;
    00146
    00147   protected:
    00155     virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
    00156
    00160     virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
    00161
    00166     virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
    00167                                Vector& X) const;
    00168
    00172     virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
    00173                                     const Vector& R, const Vector& Z,
    00174                                     const Vector& D, Vector& X) const;
    00175
    00179     virtual bool HasValidNumbersImpl() const
    00180     {
    00181       return true;
    00182     }
    00183
    00187     virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const = 0;
    00191     virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const = 0;
    00192
    00194     virtual void PrintImpl(const Journalist& jnlst,
    00195                            EJournalLevel level,
    00196                            EJournalCategory category,
    00197                            const std::string& name,
    00198                            Index indent,
    00199                            const std::string& prefix) const =0;
    00201
    00202   private:
    00212     Matrix();
    00213
    00215     Matrix(const Matrix&);
    00216
    00218     Matrix& operator=(const Matrix&);
    00220
    00221     const SmartPtr<const MatrixSpace> owner_space_;
    00222
    00225     mutable TaggedObject::Tag valid_cache_tag_;
    00226     mutable bool cached_valid_;
    00228   };
    00229
    00230
    00239   class MatrixSpace : public ReferencedObject
    00240   {
    00241   public:
    00247     MatrixSpace(Index nRows, Index nCols)
    00248         :
    00249         nRows_(nRows),
    00250         nCols_(nCols)
    00251     {}
    00252
    00254     virtual ~MatrixSpace()
    00255     {}
    00257
    00261     virtual Matrix* MakeNew() const=0;
    00262
    00264     Index NRows() const
    00265     {
    00266       return nRows_;
    00267     }
    00269     Index NCols() const
    00270     {
    00271       return nCols_;
    00272     }
    00273
    00277     bool IsMatrixFromSpace(const Matrix& matrix) const
    00278     {
    00279       return (matrix.OwnerSpace() == this);
    00280     }
    00281
    00282   private:
    00292     MatrixSpace();
    00293
    00295     MatrixSpace(const MatrixSpace&);
    00296
    00298     MatrixSpace& operator=(const MatrixSpace&);
    00300
    00302     const Index nRows_;
    00304     const Index nCols_;
    00305   };
    00306
    00307
    00308   /* Inline Methods */
    00309   inline
    00310   Index  Matrix::NRows() const
    00311   {
    00312     return owner_space_->NRows();
    00313   }
    00314
    00315   inline
    00316   Index  Matrix::NCols() const
    00317   {
    00318     return owner_space_->NCols();
    00319   }
    00320
    00321   inline
    00322   SmartPtr<const MatrixSpace> Matrix::OwnerSpace() const
    00323   {
    00324     return owner_space_;
    00325   }
    00326
    00327 } // namespace Ipopt
    00328
    00329 // Macro definitions for debugging matrices
    00330 #if COIN_IPOPT_VERBOSITY == 0
    00331 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
    00332 #else
    00333 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
    00334    if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
    00335       if (dbg_jrnl.Jnlst()!=NULL) { \
    00336         (__mat).Print(dbg_jrnl.Jnlst(), \
    00337         J_ERROR, J_DBG, \
    00338         __mat_name, \
    00339         dbg_jrnl.IndentationLevel()*2, \
    00340         "# "); \
    00341       } \
    00342    }
    00343 #endif // #if COIN_IPOPT_VERBOSITY == 0
    00344
    00345 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines