/home/coin/SVN-release/CoinAll-1.1.0/Ipopt/src/LinAlg/IpScaledMatrix.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2007 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpScaledMatrix.hpp 1001 2007-06-18 20:36:53Z andreasw $
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 PrintImpl(const Journalist& jnlst,
00074                            EJournalLevel level,
00075                            EJournalCategory category,
00076                            const std::string& name,
00077                            Index indent,
00078                            const std::string& prefix) const;
00079 
00083     virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
00084                                Vector& X) const;
00085 
00089     virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
00090                                     const Vector& R, const Vector& Z,
00091                                     const Vector& D, Vector& X) const;
00093 
00094   private:
00104     ScaledMatrix();
00105 
00107     ScaledMatrix(const ScaledMatrix&);
00108 
00110     void operator=(const ScaledMatrix&);
00112 
00114     SmartPtr<const Matrix> matrix_;
00116     SmartPtr<Matrix> nonconst_matrix_;
00117 
00119     SmartPtr<const ScaledMatrixSpace> owner_space_;
00120   };
00121 
00124   class ScaledMatrixSpace : public MatrixSpace
00125   {
00126   public:
00132     ScaledMatrixSpace(const SmartPtr<const Vector>& row_scaling,
00133                       bool row_scaling_reciprocal,
00134                       const SmartPtr<const MatrixSpace>& unscaled_matrix_space,
00135                       const SmartPtr<const Vector>& column_scaling,
00136                       bool column_scaling_reciprocal);
00137 
00139     ~ScaledMatrixSpace()
00140     {}
00142 
00144     ScaledMatrix* MakeNewScaledMatrix(bool allocate_unscaled_matrix = false) const
00145     {
00146       ScaledMatrix* ret = new ScaledMatrix(this);
00147       if (allocate_unscaled_matrix) {
00148         SmartPtr<Matrix> unscaled_matrix = unscaled_matrix_space_->MakeNew();
00149         ret->SetUnscaledMatrixNonConst(unscaled_matrix);
00150       }
00151       return ret;
00152     }
00153 
00156     virtual Matrix* MakeNew() const
00157     {
00158       return MakeNewScaledMatrix();
00159     }
00160 
00162     SmartPtr<const Vector> RowScaling() const
00163     {
00164       return ConstPtr(row_scaling_);
00165     }
00166 
00168     SmartPtr<const MatrixSpace> UnscaledMatrixSpace() const
00169     {
00170       return unscaled_matrix_space_;
00171     }
00172 
00174     SmartPtr<const Vector> ColumnScaling() const
00175     {
00176       return ConstPtr(column_scaling_);
00177     }
00178 
00179   private:
00189     ScaledMatrixSpace();
00190 
00192     ScaledMatrixSpace(const ScaledMatrixSpace&);
00193 
00195     ScaledMatrixSpace& operator=(const ScaledMatrixSpace&);
00197 
00199     SmartPtr<Vector> row_scaling_;
00201     SmartPtr<const MatrixSpace> unscaled_matrix_space_;
00203     SmartPtr<Vector> column_scaling_;
00204   };
00205 
00206   inline
00207   void ScaledMatrix::SetUnscaledMatrix(const SmartPtr<const Matrix> unscaled_matrix)
00208   {
00209     matrix_ = unscaled_matrix;
00210     nonconst_matrix_ = NULL;
00211     ObjectChanged();
00212   }
00213 
00214   inline
00215   void ScaledMatrix::SetUnscaledMatrixNonConst(const SmartPtr<Matrix>& unscaled_matrix)
00216   {
00217     nonconst_matrix_ = unscaled_matrix;
00218     matrix_ = GetRawPtr(unscaled_matrix);
00219     ObjectChanged();
00220   }
00221 
00222   inline
00223   SmartPtr<const Matrix> ScaledMatrix::GetUnscaledMatrix() const
00224   {
00225     return matrix_;
00226   }
00227 
00228   inline
00229   SmartPtr<Matrix> ScaledMatrix::GetUnscaledMatrixNonConst()
00230   {
00231     DBG_ASSERT(IsValid(nonconst_matrix_));
00232     ObjectChanged();
00233     return nonconst_matrix_;
00234   }
00235 
00236   inline
00237   SmartPtr<const Vector> ScaledMatrix::RowScaling() const
00238   {
00239     return ConstPtr(owner_space_->RowScaling());
00240   }
00241 
00242   inline
00243   SmartPtr<const Vector> ScaledMatrix::ColumnScaling() const
00244   {
00245     return ConstPtr(owner_space_->ColumnScaling());
00246   }
00247 
00248 } // namespace Ipopt
00249 
00250 #endif

Generated on Sun Nov 14 14:06:36 2010 for Coin-All by  doxygen 1.4.7