/build/buildd/coinor-ipopt-3.10.1/Ipopt/src/LinAlg/IpSymScaledMatrix.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: IpSymScaledMatrix.hpp 1861 2010-12-21 21:34:47Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPSYMSCALEDMATRIX_HPP__
00010 #define __IPSYMSCALEDMATRIX_HPP__
00011 
00012 #include "IpUtils.hpp"
00013 #include "IpSymMatrix.hpp"
00014 
00015 namespace Ipopt
00016 {
00017 
00018   /* forward declarations */
00019   class SymScaledMatrixSpace;
00020 
00026   class SymScaledMatrix : public SymMatrix
00027   {
00028   public:
00029 
00032 
00035     SymScaledMatrix(const SymScaledMatrixSpace* owner_space);
00036 
00038     ~SymScaledMatrix();
00040 
00042     void SetUnscaledMatrix(const SmartPtr<const SymMatrix> unscaled_matrix);
00043 
00045     void SetUnscaledMatrixNonConst(const SmartPtr<SymMatrix>& unscaled_matrix);
00046 
00048     SmartPtr<const SymMatrix> GetUnscaledMatrix() const;
00049 
00051     SmartPtr<SymMatrix> GetUnscaledMatrixNonConst();
00052 
00054     SmartPtr<const Vector> RowColScaling() const;
00055 
00056   protected:
00059     virtual void MultVectorImpl(Number alpha, const Vector& x,
00060                                 Number beta, Vector& y) const;
00061 
00065     virtual bool HasValidNumbersImpl() const;
00066 
00067     virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
00068 
00069     virtual void PrintImpl(const Journalist& jnlst,
00070                            EJournalLevel level,
00071                            EJournalCategory category,
00072                            const std::string& name,
00073                            Index indent,
00074                            const std::string& prefix) const;
00076 
00077   private:
00087     SymScaledMatrix();
00088 
00090     SymScaledMatrix(const SymScaledMatrix&);
00091 
00093     void operator=(const SymScaledMatrix&);
00095 
00097     SmartPtr<const SymMatrix> matrix_;
00099     SmartPtr<SymMatrix> nonconst_matrix_;
00100 
00102     SmartPtr<const SymScaledMatrixSpace> owner_space_;
00103   };
00104 
00107   class SymScaledMatrixSpace : public SymMatrixSpace
00108   {
00109   public:
00115     SymScaledMatrixSpace(const SmartPtr<const Vector>& row_col_scaling,
00116                          bool row_col_scaling_reciprocal,
00117                          const SmartPtr<const SymMatrixSpace>& unscaled_matrix_space)
00118         :
00119         SymMatrixSpace(unscaled_matrix_space->Dim()),
00120         unscaled_matrix_space_(unscaled_matrix_space)
00121     {
00122       scaling_ = row_col_scaling->MakeNewCopy();
00123       if (row_col_scaling_reciprocal) {
00124         scaling_->ElementWiseReciprocal();
00125       }
00126     }
00127 
00129     ~SymScaledMatrixSpace()
00130     {}
00132 
00134     SymScaledMatrix* MakeNewSymScaledMatrix(bool allocate_unscaled_matrix = false) const
00135     {
00136       SymScaledMatrix* ret = new SymScaledMatrix(this);
00137       if (allocate_unscaled_matrix) {
00138         SmartPtr<SymMatrix> unscaled_matrix = unscaled_matrix_space_->MakeNewSymMatrix();
00139         ret->SetUnscaledMatrixNonConst(unscaled_matrix);
00140       }
00141       return ret;
00142     }
00143 
00145     virtual SymMatrix* MakeNewSymMatrix() const
00146     {
00147       return MakeNewSymScaledMatrix();
00148     }
00151     virtual Matrix* MakeNew() const
00152     {
00153       return MakeNewSymScaledMatrix();
00154     }
00155 
00157     SmartPtr<const Vector> RowColScaling() const
00158     {
00159       return ConstPtr(scaling_);
00160     }
00161 
00163     SmartPtr<const SymMatrixSpace> UnscaledMatrixSpace() const
00164     {
00165       return unscaled_matrix_space_;
00166     }
00167 
00168   private:
00178     SymScaledMatrixSpace();
00179 
00181     SymScaledMatrixSpace(const SymScaledMatrixSpace&);
00182 
00184     SymScaledMatrixSpace& operator=(const SymScaledMatrixSpace&);
00186 
00188     SmartPtr<Vector> scaling_;
00190     SmartPtr<const SymMatrixSpace> unscaled_matrix_space_;
00191   };
00192 
00193   inline
00194   void SymScaledMatrix::SetUnscaledMatrix(const SmartPtr<const SymMatrix> unscaled_matrix)
00195   {
00196     matrix_ = unscaled_matrix;
00197     nonconst_matrix_ = NULL;
00198     ObjectChanged();
00199   }
00200 
00201   inline
00202   void SymScaledMatrix::SetUnscaledMatrixNonConst(const SmartPtr<SymMatrix>& unscaled_matrix)
00203   {
00204     nonconst_matrix_ = unscaled_matrix;
00205     matrix_ = GetRawPtr(unscaled_matrix);
00206     ObjectChanged();
00207   }
00208 
00209   inline
00210   SmartPtr<const SymMatrix> SymScaledMatrix::GetUnscaledMatrix() const
00211   {
00212     return matrix_;
00213   }
00214 
00215   inline
00216   SmartPtr<SymMatrix> SymScaledMatrix::GetUnscaledMatrixNonConst()
00217   {
00218     DBG_ASSERT(IsValid(nonconst_matrix_));
00219     ObjectChanged();
00220     return nonconst_matrix_;
00221   }
00222 
00223   inline SmartPtr<const Vector> SymScaledMatrix::RowColScaling() const
00224   {
00225     return ConstPtr(owner_space_->RowColScaling());
00226   }
00227 
00228 } // namespace Ipopt
00229 
00230 #endif