Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpMatrix.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: IpMatrix.hpp 2472 2014-04-05 17:47:20Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8
9 #ifndef __IPMATRIX_HPP__
10 #define __IPMATRIX_HPP__
11
12 #include "IpVector.hpp"
13
14 namespace Ipopt
15 {
16
17 /* forward declarations */
18 class MatrixSpace;
19
27 class Matrix : public TaggedObject
28 {
29 public:
35 Matrix(const MatrixSpace* owner_space)
36 :
37 TaggedObject(),
38 owner_space_(owner_space),
39 valid_cache_tag_(0)
40 {}
41
43 virtual ~Matrix()
44 {}
46
52 void MultVector(Number alpha, const Vector& x, Number beta,
53 Vector& y) const
54 {
55 MultVectorImpl(alpha, x, beta, y);
56 }
57
62 void TransMultVector(Number alpha, const Vector& x, Number beta,
63 Vector& y) const
64 {
65 TransMultVectorImpl(alpha, x, beta, y);
66 }
68
77 void AddMSinvZ(Number alpha, const Vector& S, const Vector& Z,
78 Vector& X) const;
79
83 void SinvBlrmZMTdBr(Number alpha, const Vector& S,
84 const Vector& R, const Vector& Z,
85 const Vector& D, Vector& X) const;
87
90 bool HasValidNumbers() const;
91
95 inline
96 Index NRows() const;
97
99 inline
100 Index NCols() const;
102
108 void ComputeRowAMax(Vector& rows_norms, bool init=true) const
109 {
110 DBG_ASSERT(NRows() == rows_norms.Dim());
111 if (init) rows_norms.Set(0.);
112 ComputeRowAMaxImpl(rows_norms, init);
113 }
117 void ComputeColAMax(Vector& cols_norms, bool init=true) const
118 {
119 DBG_ASSERT(NCols() == cols_norms.Dim());
120 if (init) cols_norms.Set(0.);
121 ComputeColAMaxImpl(cols_norms, init);
122 }
124
129 virtual void Print(SmartPtr<const Journalist> jnlst,
130 EJournalLevel level,
131 EJournalCategory category,
132 const std::string& name,
133 Index indent=0,
134 const std::string& prefix="") const;
135 virtual void Print(const Journalist& jnlst,
136 EJournalLevel level,
137 EJournalCategory category,
138 const std::string& name,
139 Index indent=0,
140 const std::string& prefix="") const;
142
144 inline
145 SmartPtr<const MatrixSpace> OwnerSpace() const;
146
147 protected:
155 virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
156
160 virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
161
166 virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
167 Vector& X) const;
168
172 virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
173 const Vector& R, const Vector& Z,
174 const Vector& D, Vector& X) const;
175
179 virtual bool HasValidNumbersImpl() const
180 {
181 return true;
182 }
183
187 virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const = 0;
191 virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const = 0;
192
194 virtual void PrintImpl(const Journalist& jnlst,
195 EJournalLevel level,
196 EJournalCategory category,
197 const std::string& name,
198 Index indent,
199 const std::string& prefix) const =0;
201
202 private:
212 Matrix();
213
215 Matrix(const Matrix&);
216
218 Matrix& operator=(const Matrix&);
220
221 const SmartPtr<const MatrixSpace> owner_space_;
222
225 mutable TaggedObject::Tag valid_cache_tag_;
226 mutable bool cached_valid_;
228 };
229
230
239 class MatrixSpace : public ReferencedObject
240 {
241 public:
247 MatrixSpace(Index nRows, Index nCols)
248 :
249 nRows_(nRows),
250 nCols_(nCols)
251 {}
252
254 virtual ~MatrixSpace()
255 {}
257
261 virtual Matrix* MakeNew() const=0;
262
264 Index NRows() const
265 {
266 return nRows_;
267 }
269 Index NCols() const
270 {
271 return nCols_;
272 }
273
277 bool IsMatrixFromSpace(const Matrix& matrix) const
278 {
279 return (matrix.OwnerSpace() == this);
280 }
281
282 private:
292 MatrixSpace();
293
295 MatrixSpace(const MatrixSpace&);
296
298 MatrixSpace& operator=(const MatrixSpace&);
300
302 const Index nRows_;
304 const Index nCols_;
305 };
306
307
308 /* Inline Methods */
309 inline
310 Index Matrix::NRows() const
311 {
312 return owner_space_->NRows();
313 }
314
315 inline
316 Index Matrix::NCols() const
317 {
318 return owner_space_->NCols();
319 }
320
321 inline
322 SmartPtr<const MatrixSpace> Matrix::OwnerSpace() const
323 {
324 return owner_space_;
325 }
326
327 } // namespace Ipopt
328
329 // Macro definitions for debugging matrices
330 #if COIN_IPOPT_VERBOSITY == 0
331 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
332 #else
333 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
334 if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
335 if (dbg_jrnl.Jnlst()!=NULL) { \
336 (__mat).Print(dbg_jrnl.Jnlst(), \
337 J_ERROR, J_DBG, \
338 __mat_name, \
339 dbg_jrnl.IndentationLevel()*2, \
340 "# "); \
341 } \
342 }
343 #endif // #if COIN_IPOPT_VERBOSITY == 0
344
345 #endif
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
Ipopt::Matrix::owner_space_
const SmartPtr< const MatrixSpace > owner_space_
Definition: IpMatrix.hpp:221
Ipopt::Matrix::Print
virtual void Print(SmartPtr< const Journalist > jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent=0, const std::string &prefix="") const
Print detailed information about the matrix.
Ipopt::Matrix::PrintImpl
virtual void PrintImpl(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent, const std::string &prefix) const =0
Print detailed information about the matrix.
Ipopt::MatrixSpace::~MatrixSpace
virtual ~MatrixSpace()
Destructor.
Definition: IpMatrix.hpp:254
Ipopt::Matrix::Matrix
Matrix(const MatrixSpace *owner_space)
Constructor.
Definition: IpMatrix.hpp:35
IpVector.hpp
Ipopt::Matrix::ComputeRowAMaxImpl
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const =0
Compute the max-norm of the rows in the matrix.
Ipopt::MatrixSpace::MatrixSpace
MatrixSpace(Index nRows, Index nCols)
Constructor, given the number rows and columns of all matrices generated by this MatrixSpace.
Definition: IpMatrix.hpp:247
Ipopt::MatrixSpace::nRows_
const Index nRows_
Number of rows for all matrices of this type.
Definition: IpMatrix.hpp:302
Ipopt::MatrixSpace::NRows
Index NRows() const
Accessor function for the number of rows.
Definition: IpMatrix.hpp:264
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::Matrix::SinvBlrmZMTdBrImpl
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).
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:47
Ipopt::Matrix::NRows
Index NRows() const
Number of rows.
Definition: IpMatrix.hpp:310
Ipopt::Matrix::HasValidNumbersImpl
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Definition: IpMatrix.hpp:179
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:51
Ipopt::Matrix::OwnerSpace
SmartPtr< const MatrixSpace > OwnerSpace() const
Return the owner MatrixSpace.
Definition: IpMatrix.hpp:322
Ipopt::TaggedObject
TaggedObject class.
Definition: IpTaggedObject.hpp:76
Ipopt::Matrix::ComputeColAMaxImpl
virtual void ComputeColAMaxImpl(Vector &cols_norms, bool init) const =0
Compute the max-norm of the columns in the matrix.
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::ReferencedObject
ReferencedObject class.
Definition: IpReferenced.hpp:174
Ipopt::MatrixSpace::IsMatrixFromSpace
bool IsMatrixFromSpace(const Matrix &matrix) const
Method to test if a given matrix belongs to a particular matrix space.
Definition: IpMatrix.hpp:277
Ipopt::Vector::Set
void Set(Number alpha)
Set each element in the vector to the scalar alpha.
Definition: IpVector.hpp:599
Ipopt::Matrix::operator=
Matrix & operator=(const Matrix &)
Overloaded Equals Operator.
Ipopt::Matrix
Matrix Base Class.
Definition: IpMatrix.hpp:27
Ipopt::Matrix::SinvBlrmZMTdBr
void SinvBlrmZMTdBr(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).
Ipopt::Matrix::valid_cache_tag_
TaggedObject::Tag valid_cache_tag_
Definition: IpMatrix.hpp:225
Ipopt::Matrix::ComputeRowAMax
void ComputeRowAMax(Vector &rows_norms, bool init=true) const
Compute the max-norm of the rows in the matrix.
Definition: IpMatrix.hpp:108
Ipopt::MatrixSpace
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:239
Ipopt::Matrix::cached_valid_
bool cached_valid_
Definition: IpMatrix.hpp:226
Ipopt::Matrix::TransMultVector
void TransMultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
Definition: IpMatrix.hpp:62
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
Ipopt::Matrix::HasValidNumbers
bool HasValidNumbers() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
Ipopt::Matrix::TransMultVectorImpl
virtual void TransMultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const =0
Matrix(transpose) vector multiply.
Ipopt::Matrix::NCols
Index NCols() const
Number of columns.
Definition: IpMatrix.hpp:316
Ipopt::TaggedObject::Tag
unsigned int Tag
Type for the Tag values.
Definition: IpTaggedObject.hpp:80
Ipopt::MatrixSpace::nCols_
const Index nCols_
Number of columns for all matrices of this type.
Definition: IpMatrix.hpp:304
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:134
Ipopt::Matrix::MultVector
void MultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
Definition: IpMatrix.hpp:52
Ipopt::Matrix::Matrix
Matrix()
default constructor
Ipopt::Matrix::ComputeColAMax
void ComputeColAMax(Vector &cols_norms, bool init=true) const
Compute the max-norm of the columns in the matrix.
Definition: IpMatrix.hpp:117
Ipopt::Vector::Dim
Index Dim() const
Dimension of the Vector.
Definition: IpVector.hpp:739
Ipopt::MatrixSpace::MakeNew
virtual Matrix * MakeNew() const =0
Pure virtual method for creating a new Matrix of the corresponding type.
Ipopt::Matrix::AddMSinvZ
void AddMSinvZ(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = X + alpha*(Matrix S^{-1} Z).
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:70
Ipopt::Matrix::AddMSinvZImpl
virtual void AddMSinvZImpl(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = X + alpha*(Matrix S^{-1} Z).
Ipopt::MatrixSpace::MatrixSpace
MatrixSpace()
default constructor
Ipopt::MatrixSpace::operator=
MatrixSpace & operator=(const MatrixSpace &)
Overloaded Equals Operator.
Ipopt::Matrix::MultVectorImpl
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const =0
Matrix-vector multiply.
Ipopt::MatrixSpace::NCols
Index NCols() const
Accessor function for the number of columns.
Definition: IpMatrix.hpp:269
Ipopt::Matrix::~Matrix
virtual ~Matrix()
Destructor.
Definition: IpMatrix.hpp:43