Ipopt Documentation  
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 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPSYMSCALEDMATRIX_HPP__
8 #define __IPSYMSCALEDMATRIX_HPP__
9 
10 #include "IpUtils.hpp"
11 #include "IpSymMatrix.hpp"
12 
13 namespace Ipopt
14 {
15 
16 /* forward declarations */
17 class SymScaledMatrixSpace;
18 
27 {
28 public:
34  const SymScaledMatrixSpace* owner_space
35  );
36 
40 
42  void SetUnscaledMatrix(
43  const SmartPtr<const SymMatrix> unscaled_matrix
44  );
45 
47  void SetUnscaledMatrixNonConst(
48  const SmartPtr<SymMatrix>& unscaled_matrix
49  );
50 
52  SmartPtr<const SymMatrix> GetUnscaledMatrix() const;
53 
55  SmartPtr<SymMatrix> GetUnscaledMatrixNonConst();
56 
58  SmartPtr<const Vector> RowColScaling() const;
59 
60 protected:
63  virtual void MultVectorImpl(
64  Number alpha,
65  const Vector& x,
66  Number beta,
67  Vector& y
68  ) const;
69 
70  virtual bool HasValidNumbersImpl() const;
71 
72  virtual void ComputeRowAMaxImpl(
73  Vector& rows_norms,
74  bool init
75  ) const;
76 
77  virtual void PrintImpl(
78  const Journalist& jnlst,
79  EJournalLevel level,
80  EJournalCategory category,
81  const std::string& name,
82  Index indent,
83  const std::string& prefix
84  ) const;
86 
87 private:
99 
102  const SymScaledMatrix&
103  );
104 
106  void operator=(
107  const SymScaledMatrix&
108  );
110 
113 
116 
119 };
120 
124 {
125 public:
132  const SmartPtr<const Vector>& row_col_scaling,
133  bool row_col_scaling_reciprocal,
134  const SmartPtr<const SymMatrixSpace>& unscaled_matrix_space
135  )
136  : SymMatrixSpace(unscaled_matrix_space->Dim()),
137  unscaled_matrix_space_(unscaled_matrix_space)
138  {
139  scaling_ = row_col_scaling->MakeNewCopy();
140  if( row_col_scaling_reciprocal )
141  {
142  scaling_->ElementWiseReciprocal();
143  }
144  }
145 
148  { }
150 
153  bool allocate_unscaled_matrix = false
154  ) const
155  {
156  SymScaledMatrix* ret = new SymScaledMatrix(this);
157  if( allocate_unscaled_matrix )
158  {
159  SmartPtr<SymMatrix> unscaled_matrix = unscaled_matrix_space_->MakeNewSymMatrix();
160  ret->SetUnscaledMatrixNonConst(unscaled_matrix);
161  }
162  return ret;
163  }
164 
165  virtual SymMatrix* MakeNewSymMatrix() const
166  {
167  return MakeNewSymScaledMatrix();
168  }
169 
170  virtual Matrix* MakeNew() const
171  {
172  return MakeNewSymScaledMatrix();
173  }
174 
177  {
178  return ConstPtr(scaling_);
179  }
180 
183  {
184  return unscaled_matrix_space_;
185  }
186 
187 private:
199 
202  const SymScaledMatrixSpace&
203  );
204 
207  const SymScaledMatrixSpace&
208  );
210 
213 
216 };
217 
219  const SmartPtr<const SymMatrix> unscaled_matrix
220 )
221 {
222  matrix_ = unscaled_matrix;
223  nonconst_matrix_ = NULL;
224  ObjectChanged();
225 }
226 
228  const SmartPtr<SymMatrix>& unscaled_matrix
229 )
230 {
231  nonconst_matrix_ = unscaled_matrix;
232  matrix_ = GetRawPtr(unscaled_matrix);
233  ObjectChanged();
234 }
235 
237 {
238  return matrix_;
239 }
240 
242 {
244  ObjectChanged();
245  return nonconst_matrix_;
246 }
247 
249 {
250  return ConstPtr(owner_space_->RowColScaling());
251 }
252 
253 } // namespace Ipopt
254 
255 #endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:28
Class responsible for all message output.
Matrix Base Class.
Definition: IpMatrix.hpp:28
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
SymMatrixSpace base class, corresponding to the SymMatrix base class.
Definition: IpSymMatrix.hpp:86
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:21
This is the matrix space for SymScaledMatrix.
SymScaledMatrixSpace()
Default constructor.
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 total number of rows and colu...
virtual Matrix * MakeNew() const
Pure virtual method for creating a new Matrix of the corresponding type.
SmartPtr< const SymMatrixSpace > unscaled_matrix_space_
unscaled matrix space
SmartPtr< Vector > scaling_
Row scaling vector.
SymScaledMatrixSpace(const SymScaledMatrixSpace &)
Copy Constructor.
SymScaledMatrixSpace & operator=(const SymScaledMatrixSpace &)
Default Assignment Operator.
virtual SymMatrix * MakeNewSymMatrix() const
Pure virtual method for creating a new matrix of this specific type.
SmartPtr< const Vector > RowColScaling() const
return the vector for the row and column scaling
SymScaledMatrix * MakeNewSymScaledMatrix(bool allocate_unscaled_matrix=false) const
Method for creating a new matrix of this specific type.
SmartPtr< const SymMatrixSpace > UnscaledMatrixSpace() const
return the matrix space for the unscaled matrix
Class for a Matrix in conjunction with its scaling factors for row and column scaling.
SmartPtr< const Vector > RowColScaling() const
return the vector for the row and column scaling
SymScaledMatrix(const SymScaledMatrix &)
Copy Constructor.
SmartPtr< const SymMatrix > GetUnscaledMatrix() const
Return the unscaled matrix in const form.
void operator=(const SymScaledMatrix &)
Default Assignment Operator.
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
void SetUnscaledMatrix(const SmartPtr< const SymMatrix > unscaled_matrix)
Set the unscaled matrix.
SmartPtr< const SymScaledMatrixSpace > owner_space_
Matrix space stored as a SymScaledMatrixSpace.
SymScaledMatrix()
Default Constructor.
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
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.
void SetUnscaledMatrixNonConst(const SmartPtr< SymMatrix > &unscaled_matrix)
Set the unscaled matrix in a non-const version.
SymScaledMatrix(const SymScaledMatrixSpace *owner_space)
Constructor, taking the owner_space.
SmartPtr< const SymMatrix > matrix_
const version of the unscaled matrix
SmartPtr< SymMatrix > GetUnscaledMatrixNonConst()
Return the unscaled matrix in non-const form.
~SymScaledMatrix()
Destructor.
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
SmartPtr< SymMatrix > nonconst_matrix_
non-const version of the unscaled matrix
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
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:665
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
EJournalCategory
Category Selection Enum.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
EJournalLevel
Print Level Enum.
double Number
Type of all numbers.
Definition: IpTypes.hpp:15