Ipopt  3.11.9
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 1861 2010-12-21 21:34:47Z andreasw $
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 
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:
109 
112 
114  void operator=(const ScaledMatrix&);
116 
121 
124  };
125 
129  {
130  public:
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
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
Number * x
Input: Starting point Output: Optimal solution.
Class responsible for all message output.
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:240
Matrix Base Class.
Definition: IpMatrix.hpp:28
This is the matrix space for ScaledMatrix.
ScaledMatrixSpace & operator=(const ScaledMatrixSpace &)
Overloaded Equals Operator.
ScaledMatrixSpace()
Default constructor.
SmartPtr< Vector > column_scaling_
column scaling vector
ScaledMatrix * MakeNewScaledMatrix(bool allocate_unscaled_matrix=false) const
Method for creating a new matrix of this specific type.
SmartPtr< const Vector > RowScaling() const
return the vector for the row scaling
virtual Matrix * MakeNew() const
Overloaded MakeNew method for the MatrixSpace base class.
SmartPtr< Vector > row_scaling_
Row scaling vector.
ScaledMatrixSpace(const ScaledMatrixSpace &)
Copy Constructor.
SmartPtr< const MatrixSpace > unscaled_matrix_space_
unscaled matrix space
SmartPtr< const Vector > ColumnScaling() const
return the vector for the column scaling
SmartPtr< const MatrixSpace > UnscaledMatrixSpace() const
return the matrix space for the unscaled matrix
ScaledMatrixSpace(const SmartPtr< const Vector > &row_scaling, bool row_scaling_reciprocal, const SmartPtr< const MatrixSpace > &unscaled_matrix_space, const SmartPtr< const Vector > &column_scaling, bool column_scaling_reciprocal)
Constructor, given the number of row and columns blocks, as well as the totel number of rows and colu...
Class for a Matrix in conjunction with its scaling factors for row and column scaling.
SmartPtr< const Vector > ColumnScaling() const
return the vector for the column scaling
void SetUnscaledMatrixNonConst(const SmartPtr< Matrix > &unscaled_matrix)
Set the unscaled matrix in a non-const version.
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
ScaledMatrix(const ScaledMatrixSpace *owner_space)
Constructor, taking the owner_space.
SmartPtr< Matrix > GetUnscaledMatrixNonConst()
Return the unscaled matrix in non-const form.
virtual void ComputeColAMaxImpl(Vector &cols_norms, bool init) const
Compute the max-norm of the columns in the matrix.
void operator=(const ScaledMatrix &)
Overloaded Equals Operator.
SmartPtr< const Matrix > GetUnscaledMatrix() const
Return the unscaled matrix in const form.
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).
ScaledMatrix(const ScaledMatrix &)
Copy Constructor.
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 > RowScaling() const
return the vector for the row scaling
~ScaledMatrix()
Destructor.
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
SmartPtr< Matrix > nonconst_matrix_
non-const version of the unscaled matrix
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
ScaledMatrix()
Default Constructor.
virtual void TransMultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
virtual void AddMSinvZImpl(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = beta*X + alpha*(Matrix S^{-1} Z).
void SetUnscaledMatrix(const SmartPtr< const Matrix > unscaled_matrix)
Set the unscaled matrix.
SmartPtr< const Matrix > matrix_
const version of the unscaled matrix
SmartPtr< const ScaledMatrixSpace > owner_space_
Matrix space stored as a ScaledMatrixSpace.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:183
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Vector Base Class.
Definition: IpVector.hpp:48
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:582
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:589
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:570
EJournalCategory
Category Selection Enum.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
EJournalLevel
Print Level Enum.
double Number
Type of all numbers.
Definition: IpTypes.hpp:17