00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __IPMATRIX_HPP__
00010 #define __IPMATRIX_HPP__
00011
00012 #include "IpVector.hpp"
00013
00014 namespace Ipopt
00015 {
00016
00017
00018 class MatrixSpace;
00019
00027 class Matrix : public TaggedObject
00028 {
00029 public:
00035 Matrix(const MatrixSpace* owner_space);
00036
00038 virtual ~Matrix();
00040
00046 void MultVector(Number alpha, const Vector& x, Number beta,
00047 Vector& y) const;
00048
00053 void TransMultVector(Number alpha, const Vector& x, Number beta,
00054 Vector& y) const;
00056
00065 void AddMSinvZ(Number alpha, const Vector& S, const Vector& Z,
00066 Vector& X) const;
00067
00071 void SinvBlrmZMTdBr(Number alpha, const Vector& S,
00072 const Vector& R, const Vector& Z,
00073 const Vector& D, Vector& X) const;
00075
00078 bool HasValidNumbers() const;
00079
00080
00082
00083 Index NRows() const;
00084
00086 Index NCols() const;
00088
00093 virtual void Print(SmartPtr<const Journalist> jnlst,
00094 EJournalLevel level,
00095 EJournalCategory category,
00096 const std::string& name,
00097 Index indent=0,
00098 const std::string& prefix="") const;
00099 virtual void Print(const Journalist& jnlst,
00100 EJournalLevel level,
00101 EJournalCategory category,
00102 const std::string& name,
00103 Index indent=0,
00104 const std::string& prefix="") const;
00106
00108 SmartPtr<const MatrixSpace> OwnerSpace() const;
00109
00110 protected:
00118 virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
00119
00123 virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
00124
00129 virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
00130 Vector& X) const;
00131
00135 virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
00136 const Vector& R, const Vector& Z,
00137 const Vector& D, Vector& X) const;
00138
00142 virtual bool HasValidNumbersImpl() const
00143 {
00144 return true;
00145 }
00146
00148 virtual void PrintImpl(const Journalist& jnlst,
00149 EJournalLevel level,
00150 EJournalCategory category,
00151 const std::string& name,
00152 Index indent,
00153 const std::string& prefix) const =0;
00155
00156 private:
00166 Matrix();
00167
00169 Matrix(const Matrix&);
00170
00172 Matrix& operator=(const Matrix&);
00174
00175 const SmartPtr<const MatrixSpace> owner_space_;
00176
00179 mutable TaggedObject::Tag valid_cache_tag_;
00180 mutable bool cached_valid_;
00182 };
00183
00184
00193 class MatrixSpace : public ReferencedObject
00194 {
00195 public:
00201 MatrixSpace(Index nRows, Index nCols);
00202
00204 virtual ~MatrixSpace();
00206
00210 virtual Matrix* MakeNew() const=0;
00211
00213 Index NRows() const
00214 {
00215 return nRows_;
00216 }
00218 Index NCols() const
00219 {
00220 return nCols_;
00221 }
00222
00226 bool IsMatrixFromSpace(const Matrix& matrix) const;
00227
00228 private:
00238 MatrixSpace();
00239
00241 MatrixSpace(const MatrixSpace&);
00242
00244 MatrixSpace& operator=(const MatrixSpace&);
00246
00248 const Index nRows_;
00250 const Index nCols_;
00251 };
00252
00253
00254
00255 inline
00256 Matrix::Matrix(const MatrixSpace* owner_space)
00257 :
00258 TaggedObject(),
00259 owner_space_(owner_space),
00260 valid_cache_tag_(0)
00261 {}
00262
00263 inline
00264 Matrix::~Matrix()
00265 {}
00266
00267 inline
00268 Index Matrix::NRows() const
00269 {
00270 return owner_space_->NRows();
00271 }
00272
00273 inline
00274 Index Matrix::NCols() const
00275 {
00276 return owner_space_->NCols();
00277 }
00278
00279 inline
00280 SmartPtr<const MatrixSpace> Matrix::OwnerSpace() const
00281 {
00282 return owner_space_;
00283 }
00284
00285 }
00286
00287
00288 #ifndef IP_DEBUG
00289 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
00290 #else
00291 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
00292 if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
00293 if (dbg_jrnl.Jnlst()!=NULL) { \
00294 (__mat).Print(dbg_jrnl.Jnlst(), \
00295 J_ERROR, J_DBG, \
00296 __mat_name, \
00297 dbg_jrnl.IndentationLevel()*2, \
00298 "# "); \
00299 } \
00300 }
00301 #endif // IP_DEBUG
00302
00303 #endif