Ipopt  3.12.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpScaledMatrix.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2008 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: IpScaledMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPSCALEDMATRIX_HPP__
10 #define __IPSCALEDMATRIX_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpMatrix.hpp"
14 
15 namespace Ipopt
16 {
17 
18  /* forward declarations */
19  class ScaledMatrixSpace;
20 
26  class ScaledMatrix : public Matrix
27  {
28  public:
29 
32 
35  ScaledMatrix(const ScaledMatrixSpace* owner_space);
36 
38  ~ScaledMatrix();
40 
42  void SetUnscaledMatrix(const SmartPtr<const Matrix> unscaled_matrix);
43 
45  void SetUnscaledMatrixNonConst(const SmartPtr<Matrix>& unscaled_matrix);
46 
49 
52 
55 
58 
59  protected:
62  virtual void MultVectorImpl(Number alpha, const Vector& x,
63  Number beta, Vector& y) const;
64 
65  virtual void TransMultVectorImpl(Number alpha, const Vector& x,
66  Number beta, Vector& y) const;
67 
71  virtual bool HasValidNumbersImpl() const;
72 
73  virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
74 
75  virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const;
76 
77  virtual void PrintImpl(const Journalist& jnlst,
78  EJournalLevel level,
79  EJournalCategory category,
80  const std::string& name,
81  Index indent,
82  const std::string& prefix) const;
83 
87  virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
88  Vector& X) const;
89 
93  virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
94  const Vector& R, const Vector& Z,
95  const Vector& D, Vector& X) const;
97 
98  private:
108  ScaledMatrix();
109 
111  ScaledMatrix(const ScaledMatrix&);
112 
114  void operator=(const ScaledMatrix&);
116 
121 
124  };
125 
129  {
130  public:
136  ScaledMatrixSpace(const SmartPtr<const Vector>& row_scaling,
137  bool row_scaling_reciprocal,
138  const SmartPtr<const MatrixSpace>& unscaled_matrix_space,
139  const SmartPtr<const Vector>& column_scaling,
140  bool column_scaling_reciprocal);
141 
144  {}
146 
148  ScaledMatrix* MakeNewScaledMatrix(bool allocate_unscaled_matrix = false) const
149  {
150  ScaledMatrix* ret = new ScaledMatrix(this);
151  if (allocate_unscaled_matrix) {
152  SmartPtr<Matrix> unscaled_matrix = unscaled_matrix_space_->MakeNew();
153  ret->SetUnscaledMatrixNonConst(unscaled_matrix);
154  }
155  return ret;
156  }
157 
160  virtual Matrix* MakeNew() const
161  {
162  return MakeNewScaledMatrix();
163  }
164 
167  {
168  return ConstPtr(row_scaling_);
169  }
170 
173  {
174  return unscaled_matrix_space_;
175  }
176 
179  {
180  return ConstPtr(column_scaling_);
181  }
182 
183  private:
194 
197 
201 
208  };
209 
210  inline
212  {
213  matrix_ = unscaled_matrix;
214  nonconst_matrix_ = NULL;
215  ObjectChanged();
216  }
217 
218  inline
220  {
221  nonconst_matrix_ = unscaled_matrix;
222  matrix_ = GetRawPtr(unscaled_matrix);
223  ObjectChanged();
224  }
225 
226  inline
228  {
229  return matrix_;
230  }
231 
232  inline
234  {
236  ObjectChanged();
237  return nonconst_matrix_;
238  }
239 
240  inline
242  {
243  return ConstPtr(owner_space_->RowScaling());
244  }
245 
246  inline
248  {
249  return ConstPtr(owner_space_->ColumnScaling());
250  }
251 
252 } // namespace Ipopt
253 
254 #endif
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:579
Number * x
Input: Starting point Output: Optimal solution.
SmartPtr< const ScaledMatrixSpace > owner_space_
Matrix space stored as a ScaledMatrixSpace.
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
SmartPtr< const MatrixSpace > UnscaledMatrixSpace() const
return the matrix space for the unscaled matrix
ScaledMatrix()
Default Constructor.
Class for a Matrix in conjunction with its scaling factors for row and column scaling.
SmartPtr< Vector > row_scaling_
Row scaling vector.
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Vector Base Class.
Definition: IpVector.hpp:47
virtual void PrintImpl(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent, const std::string &prefix) const
Print detailed information about the matrix.
SmartPtr< const Vector > ColumnScaling() const
return the vector for the column scaling
virtual Matrix * MakeNew() const
Overloaded MakeNew method for the MatrixSpace base class.
SmartPtr< const Vector > ColumnScaling() const
return the vector for the column scaling
EJournalLevel
Print Level Enum.
SmartPtr< const Vector > RowScaling() const
return the vector for the row scaling
virtual void TransMultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
SmartPtr< const Matrix > GetUnscaledMatrix() const
Return the unscaled matrix in const form.
ScaledMatrix * MakeNewScaledMatrix(bool allocate_unscaled_matrix=false) const
Method for creating a new matrix of this specific type.
~ScaledMatrixSpace()
Destructor.
This is the matrix space for ScaledMatrix.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
ScaledMatrixSpace()
Default constructor.
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:560
void SetUnscaledMatrixNonConst(const SmartPtr< Matrix > &unscaled_matrix)
Set the unscaled matrix in a non-const version.
Matrix Base Class.
Definition: IpMatrix.hpp:27
virtual void AddMSinvZImpl(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = beta*X + alpha*(Matrix S^{-1} Z).
SmartPtr< Matrix > GetUnscaledMatrixNonConst()
Return the unscaled matrix in non-const form.
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:239
void operator=(const ScaledMatrix &)
Overloaded Equals Operator.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
SmartPtr< const MatrixSpace > unscaled_matrix_space_
unscaled matrix space
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:572
Class responsible for all message output.
virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector &S, const Vector &R, const Vector &Z, const Vector &D, Vector &X) const
X = S^{-1} (r + alpha*Z*M^Td).
ScaledMatrixSpace & operator=(const ScaledMatrixSpace &)
Overloaded Equals Operator.
SmartPtr< Matrix > nonconst_matrix_
non-const version of the unscaled matrix
~ScaledMatrix()
Destructor.
void SetUnscaledMatrix(const SmartPtr< const Matrix > unscaled_matrix)
Set the unscaled matrix.
SmartPtr< const Matrix > matrix_
const version of the unscaled matrix
virtual void ComputeColAMaxImpl(Vector &cols_norms, bool init) const
Compute the max-norm of the columns in the matrix.
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
EJournalCategory
Category Selection Enum.
SmartPtr< Vector > column_scaling_
column scaling vector
SmartPtr< const Vector > RowScaling() const
return the vector for the row scaling