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 :
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 Index NRows() const;
00096
00098 Index NCols() const;
00100
00106 void ComputeRowAMax(Vector& rows_norms, bool init=true) const
00107 {
00108 DBG_ASSERT(NRows() == rows_norms.Dim());
00109 if (init) rows_norms.Set(0.);
00110 ComputeRowAMaxImpl(rows_norms, init);
00111 }
00115 void ComputeColAMax(Vector& cols_norms, bool init=true) const
00116 {
00117 DBG_ASSERT(NCols() == cols_norms.Dim());
00118 if (init) cols_norms.Set(0.);
00119 ComputeColAMaxImpl(cols_norms, init);
00120 }
00122
00127 virtual void Print(SmartPtr<const Journalist> jnlst,
00128 EJournalLevel level,
00129 EJournalCategory category,
00130 const std::string& name,
00131 Index indent=0,
00132 const std::string& prefix="") const;
00133 virtual void Print(const Journalist& jnlst,
00134 EJournalLevel level,
00135 EJournalCategory category,
00136 const std::string& name,
00137 Index indent=0,
00138 const std::string& prefix="") const;
00140
00142 SmartPtr<const MatrixSpace> OwnerSpace() const;
00143
00144 protected:
00152 virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
00153
00157 virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
00158
00163 virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
00164 Vector& X) const;
00165
00169 virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
00170 const Vector& R, const Vector& Z,
00171 const Vector& D, Vector& X) const;
00172
00176 virtual bool HasValidNumbersImpl() const
00177 {
00178 return true;
00179 }
00180
00184 virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const = 0;
00188 virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const = 0;
00189
00191 virtual void PrintImpl(const Journalist& jnlst,
00192 EJournalLevel level,
00193 EJournalCategory category,
00194 const std::string& name,
00195 Index indent,
00196 const std::string& prefix) const =0;
00198
00199 private:
00209 Matrix();
00210
00212 Matrix(const Matrix&);
00213
00215 Matrix& operator=(const Matrix&);
00217
00218 const SmartPtr<const MatrixSpace> owner_space_;
00219
00222 mutable TaggedObject::Tag valid_cache_tag_;
00223 mutable bool cached_valid_;
00225 };
00226
00227
00236 class MatrixSpace : public ReferencedObject
00237 {
00238 public:
00244 MatrixSpace(Index nRows, Index nCols)
00245 :
00246 nRows_(nRows),
00247 nCols_(nCols)
00248 {}
00249
00251 virtual ~MatrixSpace()
00252 {}
00254
00258 virtual Matrix* MakeNew() const=0;
00259
00261 Index NRows() const
00262 {
00263 return nRows_;
00264 }
00266 Index NCols() const
00267 {
00268 return nCols_;
00269 }
00270
00274 bool IsMatrixFromSpace(const Matrix& matrix) const
00275 {
00276 return (matrix.OwnerSpace() == this);
00277 }
00278
00279 private:
00289 MatrixSpace();
00290
00292 MatrixSpace(const MatrixSpace&);
00293
00295 MatrixSpace& operator=(const MatrixSpace&);
00297
00299 const Index nRows_;
00301 const Index nCols_;
00302 };
00303
00304
00305
00306 inline
00307 Index Matrix::NRows() const
00308 {
00309 return owner_space_->NRows();
00310 }
00311
00312 inline
00313 Index Matrix::NCols() const
00314 {
00315 return owner_space_->NCols();
00316 }
00317
00318 inline
00319 SmartPtr<const MatrixSpace> Matrix::OwnerSpace() const
00320 {
00321 return owner_space_;
00322 }
00323
00324 }
00325
00326
00327 #if COIN_IPOPT_VERBOSITY == 0
00328 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
00329 #else
00330 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
00331 if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
00332 if (dbg_jrnl.Jnlst()!=NULL) { \
00333 (__mat).Print(dbg_jrnl.Jnlst(), \
00334 J_ERROR, J_DBG, \
00335 __mat_name, \
00336 dbg_jrnl.IndentationLevel()*2, \
00337 "# "); \
00338 } \
00339 }
00340 #endif // #if COIN_IPOPT_VERBOSITY == 0
00341
00342 #endif