Ipopt
trunk
|
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$ 00006 // 00007 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 00008 00009 #ifndef __IPSCALEDMATRIX_HPP__ 00010 #define __IPSCALEDMATRIX_HPP__ 00011 00012 #include "IpUtils.hpp" 00013 #include "IpMatrix.hpp" 00014 00015 namespace Ipopt 00016 { 00017 00018 /* forward declarations */ 00019 class ScaledMatrixSpace; 00020 00026 class ScaledMatrix : public Matrix 00027 { 00028 public: 00029 00032 00035 ScaledMatrix(const ScaledMatrixSpace* owner_space); 00036 00038 ~ScaledMatrix(); 00040 00042 void SetUnscaledMatrix(const SmartPtr<const Matrix> unscaled_matrix); 00043 00045 void SetUnscaledMatrixNonConst(const SmartPtr<Matrix>& unscaled_matrix); 00046 00048 SmartPtr<const Matrix> GetUnscaledMatrix() const; 00049 00051 SmartPtr<Matrix> GetUnscaledMatrixNonConst(); 00052 00054 SmartPtr<const Vector> RowScaling() const; 00055 00057 SmartPtr<const Vector> ColumnScaling() const; 00058 00059 protected: 00062 virtual void MultVectorImpl(Number alpha, const Vector& x, 00063 Number beta, Vector& y) const; 00064 00065 virtual void TransMultVectorImpl(Number alpha, const Vector& x, 00066 Number beta, Vector& y) const; 00067 00071 virtual bool HasValidNumbersImpl() const; 00072 00073 virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; 00074 00075 virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const; 00076 00077 virtual void PrintImpl(const Journalist& jnlst, 00078 EJournalLevel level, 00079 EJournalCategory category, 00080 const std::string& name, 00081 Index indent, 00082 const std::string& prefix) const; 00083 00087 virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z, 00088 Vector& X) const; 00089 00093 virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S, 00094 const Vector& R, const Vector& Z, 00095 const Vector& D, Vector& X) const; 00097 00098 private: 00108 ScaledMatrix(); 00109 00111 ScaledMatrix(const ScaledMatrix&); 00112 00114 void operator=(const ScaledMatrix&); 00116 00118 SmartPtr<const Matrix> matrix_; 00120 SmartPtr<Matrix> nonconst_matrix_; 00121 00123 SmartPtr<const ScaledMatrixSpace> owner_space_; 00124 }; 00125 00128 class ScaledMatrixSpace : public MatrixSpace 00129 { 00130 public: 00136 ScaledMatrixSpace(const SmartPtr<const Vector>& row_scaling, 00137 bool row_scaling_reciprocal, 00138 const SmartPtr<const MatrixSpace>& unscaled_matrix_space, 00139 const SmartPtr<const Vector>& column_scaling, 00140 bool column_scaling_reciprocal); 00141 00143 ~ScaledMatrixSpace() 00144 {} 00146 00148 ScaledMatrix* MakeNewScaledMatrix(bool allocate_unscaled_matrix = false) const 00149 { 00150 ScaledMatrix* ret = new ScaledMatrix(this); 00151 if (allocate_unscaled_matrix) { 00152 SmartPtr<Matrix> unscaled_matrix = unscaled_matrix_space_->MakeNew(); 00153 ret->SetUnscaledMatrixNonConst(unscaled_matrix); 00154 } 00155 return ret; 00156 } 00157 00160 virtual Matrix* MakeNew() const 00161 { 00162 return MakeNewScaledMatrix(); 00163 } 00164 00166 SmartPtr<const Vector> RowScaling() const 00167 { 00168 return ConstPtr(row_scaling_); 00169 } 00170 00172 SmartPtr<const MatrixSpace> UnscaledMatrixSpace() const 00173 { 00174 return unscaled_matrix_space_; 00175 } 00176 00178 SmartPtr<const Vector> ColumnScaling() const 00179 { 00180 return ConstPtr(column_scaling_); 00181 } 00182 00183 private: 00193 ScaledMatrixSpace(); 00194 00196 ScaledMatrixSpace(const ScaledMatrixSpace&); 00197 00199 ScaledMatrixSpace& operator=(const ScaledMatrixSpace&); 00201 00203 SmartPtr<Vector> row_scaling_; 00205 SmartPtr<const MatrixSpace> unscaled_matrix_space_; 00207 SmartPtr<Vector> column_scaling_; 00208 }; 00209 00210 inline 00211 void ScaledMatrix::SetUnscaledMatrix(const SmartPtr<const Matrix> unscaled_matrix) 00212 { 00213 matrix_ = unscaled_matrix; 00214 nonconst_matrix_ = NULL; 00215 ObjectChanged(); 00216 } 00217 00218 inline 00219 void ScaledMatrix::SetUnscaledMatrixNonConst(const SmartPtr<Matrix>& unscaled_matrix) 00220 { 00221 nonconst_matrix_ = unscaled_matrix; 00222 matrix_ = GetRawPtr(unscaled_matrix); 00223 ObjectChanged(); 00224 } 00225 00226 inline 00227 SmartPtr<const Matrix> ScaledMatrix::GetUnscaledMatrix() const 00228 { 00229 return matrix_; 00230 } 00231 00232 inline 00233 SmartPtr<Matrix> ScaledMatrix::GetUnscaledMatrixNonConst() 00234 { 00235 DBG_ASSERT(IsValid(nonconst_matrix_)); 00236 ObjectChanged(); 00237 return nonconst_matrix_; 00238 } 00239 00240 inline 00241 SmartPtr<const Vector> ScaledMatrix::RowScaling() const 00242 { 00243 return ConstPtr(owner_space_->RowScaling()); 00244 } 00245 00246 inline 00247 SmartPtr<const Vector> ScaledMatrix::ColumnScaling() const 00248 { 00249 return ConstPtr(owner_space_->ColumnScaling()); 00250 } 00251 00252 } // namespace Ipopt 00253 00254 #endif