Ipopt  3.12.8
IpSymScaledMatrix.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: IpSymScaledMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPSYMSCALEDMATRIX_HPP__
10 #define __IPSYMSCALEDMATRIX_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpSymMatrix.hpp"
14 
15 namespace Ipopt
16 {
17 
18  /* forward declarations */
19  class SymScaledMatrixSpace;
20 
26  class SymScaledMatrix : public SymMatrix
27  {
28  public:
29 
32 
35  SymScaledMatrix(const SymScaledMatrixSpace* owner_space);
36 
40 
42  void SetUnscaledMatrix(const SmartPtr<const SymMatrix> unscaled_matrix);
43 
45  void SetUnscaledMatrixNonConst(const SmartPtr<SymMatrix>& unscaled_matrix);
46 
49 
52 
55 
56  protected:
59  virtual void MultVectorImpl(Number alpha, const Vector& x,
60  Number beta, Vector& y) const;
61 
65  virtual bool HasValidNumbersImpl() const;
66 
67  virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
68 
69  virtual void PrintImpl(const Journalist& jnlst,
70  EJournalLevel level,
71  EJournalCategory category,
72  const std::string& name,
73  Index indent,
74  const std::string& prefix) const;
76 
77  private:
88 
91 
93  void operator=(const SymScaledMatrix&);
95 
100 
103  };
104 
108  {
109  public:
116  bool row_col_scaling_reciprocal,
117  const SmartPtr<const SymMatrixSpace>& unscaled_matrix_space)
118  :
119  SymMatrixSpace(unscaled_matrix_space->Dim()),
120  unscaled_matrix_space_(unscaled_matrix_space)
121  {
122  scaling_ = row_col_scaling->MakeNewCopy();
123  if (row_col_scaling_reciprocal) {
124  scaling_->ElementWiseReciprocal();
125  }
126  }
127 
130  {}
132 
134  SymScaledMatrix* MakeNewSymScaledMatrix(bool allocate_unscaled_matrix = false) const
135  {
136  SymScaledMatrix* ret = new SymScaledMatrix(this);
137  if (allocate_unscaled_matrix) {
138  SmartPtr<SymMatrix> unscaled_matrix = unscaled_matrix_space_->MakeNewSymMatrix();
139  ret->SetUnscaledMatrixNonConst(unscaled_matrix);
140  }
141  return ret;
142  }
143 
145  virtual SymMatrix* MakeNewSymMatrix() const
146  {
147  return MakeNewSymScaledMatrix();
148  }
151  virtual Matrix* MakeNew() const
152  {
153  return MakeNewSymScaledMatrix();
154  }
155 
158  {
159  return ConstPtr(scaling_);
160  }
161 
164  {
165  return unscaled_matrix_space_;
166  }
167 
168  private:
179 
182 
186 
191  };
192 
193  inline
195  {
196  matrix_ = unscaled_matrix;
197  nonconst_matrix_ = NULL;
198  ObjectChanged();
199  }
200 
201  inline
203  {
204  nonconst_matrix_ = unscaled_matrix;
205  matrix_ = GetRawPtr(unscaled_matrix);
206  ObjectChanged();
207  }
208 
209  inline
211  {
212  return matrix_;
213  }
214 
215  inline
217  {
219  ObjectChanged();
220  return nonconst_matrix_;
221  }
222 
224  {
225  return ConstPtr(owner_space_->RowColScaling());
226  }
227 
228 } // namespace Ipopt
229 
230 #endif
SymScaledMatrix * MakeNewSymScaledMatrix(bool allocate_unscaled_matrix=false) const
Method for creating a new matrix of this specific type.
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:579
Number * x
Input: Starting point Output: Optimal solution.
SmartPtr< SymMatrix > nonconst_matrix_
non-const version of the unscaled matrix
Index Dim() const
Dimension of the matrix (number of rows and columns)
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.
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
Class for a Matrix in conjunction with its scaling factors for row and column scaling.
EJournalLevel
Print Level Enum.
void SetUnscaledMatrix(const SmartPtr< const SymMatrix > unscaled_matrix)
Set the unscaled matrix.
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:23
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
SmartPtr< Vector > scaling_
Row scaling vector.
SmartPtr< const Vector > RowColScaling() const
return the vector for the row and column scaling
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
Matrix Base Class.
Definition: IpMatrix.hpp:27
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
SymScaledMatrixSpace(const SmartPtr< const Vector > &row_col_scaling, bool row_col_scaling_reciprocal, const SmartPtr< const SymMatrixSpace > &unscaled_matrix_space)
Constructor, given the number of row and columns blocks, as well as the totel number of rows and colu...
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
SmartPtr< const SymMatrix > matrix_
const version of the unscaled matrix
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
This is the matrix space for SymScaledMatrix.
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:572
SymScaledMatrix()
Default Constructor.
SymMatrixSpace base class, corresponding to the SymMatrix base class.
Definition: IpSymMatrix.hpp:81
SmartPtr< const SymMatrixSpace > UnscaledMatrixSpace() const
return the matrix space for the unscaled matrix
Class responsible for all message output.
virtual SymMatrix * MakeNewSymMatrix() const
Overloaded method from SymMatrixSpace.
SmartPtr< SymMatrix > GetUnscaledMatrixNonConst()
Return the unscaled matrix in non-const form.
SmartPtr< const SymMatrix > GetUnscaledMatrix() const
Return the unscaled matrix in const form.
SmartPtr< const Vector > RowColScaling() const
return the vector for the row and column scaling
SmartPtr< const SymMatrixSpace > unscaled_matrix_space_
unscaled matrix space
~SymScaledMatrix()
Destructor.
void operator=(const SymScaledMatrix &)
Overloaded Equals Operator.
EJournalCategory
Category Selection Enum.
virtual Matrix * MakeNew() const
Overloaded MakeNew method for the MatrixSpace base class.
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
SmartPtr< const SymScaledMatrixSpace > owner_space_
Matrix space stored as a SymScaledMatrixSpace.
void SetUnscaledMatrixNonConst(const SmartPtr< SymMatrix > &unscaled_matrix)
Set the unscaled matrix in a non-const version.