Ipopt Documentation  
 
Loading...
Searching...
No Matches
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// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6
7#ifndef __IPMATRIX_HPP__
8#define __IPMATRIX_HPP__
9
10#include "IpVector.hpp"
11
12namespace Ipopt
13{
14
15/* forward declarations */
16class MatrixSpace;
17
28{
29public:
32
38 )
39 : TaggedObject(),
40 owner_space_(owner_space),
41 valid_cache_tag_(0)
42 { }
43
45 virtual ~Matrix()
46 { }
48
51
59 const Vector& x,
61 Vector& y
62 ) const
63 {
64 MultVectorImpl(alpha, x, beta, y);
65 }
66
75 const Vector& x,
77 Vector& y
78 ) const
79 {
80 TransMultVectorImpl(alpha, x, beta, y);
81 }
83
90
96 const Vector& S,
97 const Vector& Z,
98 Vector& X
99 ) const;
100
107 const Vector& S,
108 const Vector& R,
109 const Vector& Z,
110 const Vector& D,
111 Vector& X
112 ) const;
114
116 bool HasValidNumbers() const;
117
120
121 inline Index NRows() const;
122
124 inline Index NCols() const;
126
129
136 bool init = true
137 ) const
138 {
139 DBG_ASSERT(NRows() == rows_norms.Dim());
140 if( init )
141 {
142 rows_norms.Set(0.);
143 }
144 ComputeRowAMaxImpl(rows_norms, init);
145 }
146
154 bool init = true
155 ) const
156 {
157 DBG_ASSERT(NCols() == cols_norms.Dim());
158 if( init )
159 {
160 cols_norms.Set(0.);
161 }
162 ComputeColAMaxImpl(cols_norms, init);
163 }
165
171 virtual void Print(
175 const std::string& name,
176 Index indent = 0,
177 const std::string& prefix = ""
178 ) const;
179
180 virtual void Print(
181 const Journalist& jnlst,
184 const std::string& name,
185 Index indent = 0,
186 const std::string& prefix = ""
187 ) const;
189
191 inline SmartPtr<const MatrixSpace> OwnerSpace() const;
192
193protected:
198
202 virtual void MultVectorImpl(
204 const Vector& x,
205 Number beta,
206 Vector& y
207 ) const = 0;
208
215 const Vector& x,
216 Number beta,
217 Vector& y
218 ) const = 0;
219
225 virtual void AddMSinvZImpl(
227 const Vector& S,
228 const Vector& Z,
229 Vector& X
230 ) const;
231
236 virtual void SinvBlrmZMTdBrImpl(
238 const Vector& S,
239 const Vector& R,
240 const Vector& Z,
241 const Vector& D,
242 Vector& X
243 ) const;
244
250 virtual bool HasValidNumbersImpl() const
251 {
252 return true;
253 }
254
259 virtual void ComputeRowAMaxImpl(
261 bool init
262 ) const = 0;
263
268 virtual void ComputeColAMaxImpl(
270 bool init
271 ) const = 0;
272
274 virtual void PrintImpl(
275 const Journalist& jnlst,
278 const std::string& name,
280 const std::string& prefix
281 ) const = 0;
283
284private:
294
296
299 const Matrix&
300 );
301
304 const Matrix&
305 );
307
309
313 mutable bool cached_valid_;
315};
316
327{
328public:
331
335 Index nRows,
336 Index nCols)
337 : nRows_(nRows),
338 nCols_(nCols)
339 { }
340
342 virtual ~MatrixSpace()
343 { }
345
347 virtual Matrix* MakeNew() const = 0;
348
350 Index NRows() const
351 {
352 return nRows_;
353 }
354
356 Index NCols() const
357 {
358 return nCols_;
359 }
360
363 const Matrix& matrix
364 ) const
365 {
366 return (matrix.OwnerSpace() == this);
367 }
368
369private:
379
381
384 const MatrixSpace&
385 );
386
389 const MatrixSpace&
390 );
392
395
398};
399
400/* Inline Methods */
401inline Index Matrix::NRows() const
402{
403 return owner_space_->NRows();
404}
405
406inline Index Matrix::NCols() const
407{
408 return owner_space_->NCols();
409}
410
415
416} // namespace Ipopt
417
418// Macro definitions for debugging matrices
419#if IPOPT_VERBOSITY == 0
420# define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
421#else
422# define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
423 if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
424 if (dbg_jrnl.Jnlst()!=NULL) { \
425 (__mat).Print(dbg_jrnl.Jnlst(), \
426 J_ERROR, J_DBG, \
427 __mat_name, \
428 dbg_jrnl.IndentationLevel()*2, \
429 "# "); \
430 } \
431 }
432#endif // #if IPOPT_VERBOSITY == 0
433
434#endif
#define DBG_ASSERT(test)
Definition IpDebug.hpp:27
Templated class which stores one entry for the CachedResult class.
Class responsible for all message output.
MatrixSpace base class, corresponding to the Matrix base class.
Definition IpMatrix.hpp:327
const Index nRows_
Number of rows for all matrices of this type.
Definition IpMatrix.hpp:394
MatrixSpace(const MatrixSpace &)
Copy constructor.
virtual ~MatrixSpace()
Destructor.
Definition IpMatrix.hpp:342
const Index nCols_
Number of columns for all matrices of this type.
Definition IpMatrix.hpp:397
MatrixSpace & operator=(const MatrixSpace &)
Default Assignment Operator.
MatrixSpace(Index nRows, Index nCols)
Constructor, given the number rows and columns of all matrices generated by this MatrixSpace.
Definition IpMatrix.hpp:334
Index NCols() const
Accessor function for the number of columns.
Definition IpMatrix.hpp:356
bool IsMatrixFromSpace(const Matrix &matrix) const
Method to test if a given matrix belongs to a particular matrix space.
Definition IpMatrix.hpp:362
virtual Matrix * MakeNew() const =0
Pure virtual method for creating a new Matrix of the corresponding type.
Index NRows() const
Accessor function for the number of rows.
Definition IpMatrix.hpp:350
MatrixSpace()
Default constructor.
Matrix Base Class.
Definition IpMatrix.hpp:28
void ComputeColAMax(Vector &cols_norms, bool init=true) const
Compute the max-norm of the columns in the matrix.
Definition IpMatrix.hpp:152
const SmartPtr< const MatrixSpace > owner_space_
Definition IpMatrix.hpp:308
bool HasValidNumbers() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Matrix & operator=(const Matrix &)
Default Assignment Operator.
Index NRows() const
Number of rows.
Definition IpMatrix.hpp:401
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const =0
Matrix-vector multiply.
virtual void TransMultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const =0
Matrix(transpose) vector multiply.
void TransMultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
Definition IpMatrix.hpp:73
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.
TaggedObject::Tag valid_cache_tag_
Definition IpMatrix.hpp:312
virtual ~Matrix()
Destructor.
Definition IpMatrix.hpp:45
SmartPtr< const MatrixSpace > OwnerSpace() const
Return the owner MatrixSpace.
Definition IpMatrix.hpp:411
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).
Matrix(const Matrix &)
Copy constructor.
virtual void AddMSinvZImpl(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = X + alpha*(Matrix S^{-1} Z).
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const =0
Compute the max-norm of the rows in the matrix.
Matrix(const MatrixSpace *owner_space)
Constructor.
Definition IpMatrix.hpp:36
virtual void Print(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent=0, const std::string &prefix="") const
void MultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
Definition IpMatrix.hpp:57
Matrix()
Default constructor.
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.
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Definition IpMatrix.hpp:250
void ComputeRowAMax(Vector &rows_norms, bool init=true) const
Compute the max-norm of the rows in the matrix.
Definition IpMatrix.hpp:134
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).
virtual void ComputeColAMaxImpl(Vector &cols_norms, bool init) const =0
Compute the max-norm of the columns in the matrix.
void AddMSinvZ(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = X + alpha*(Matrix S^{-1} Z).
Index NCols() const
Number of columns.
Definition IpMatrix.hpp:406
Storing the reference count of all the smart pointers that currently reference it.
TaggedObject class.
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.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:20
EJournalCategory
Category Selection Enum.
EJournalLevel
Print Level Enum.
ipnumber Number
Type of all numbers.
Definition IpTypes.hpp:17