Ipopt  3.11.7
 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 2276 2013-05-05 12:33:44Z 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  {}
40 
42  virtual ~Matrix()
43  {}
45 
51  void MultVector(Number alpha, const Vector& x, Number beta,
52  Vector& y) const
53  {
54  MultVectorImpl(alpha, x, beta, y);
55  }
56 
61  void TransMultVector(Number alpha, const Vector& x, Number beta,
62  Vector& y) const
63  {
64  TransMultVectorImpl(alpha, x, beta, y);
65  }
67 
76  void AddMSinvZ(Number alpha, const Vector& S, const Vector& Z,
77  Vector& X) const;
78 
82  void SinvBlrmZMTdBr(Number alpha, const Vector& S,
83  const Vector& R, const Vector& Z,
84  const Vector& D, Vector& X) const;
86 
89  bool HasValidNumbers() const;
90 
94  inline
95  Index NRows() const;
96 
98  inline
99  Index NCols() const;
101 
107  void ComputeRowAMax(Vector& rows_norms, bool init=true) const
108  {
109  DBG_ASSERT(NRows() == rows_norms.Dim());
110  if (init) rows_norms.Set(0.);
111  ComputeRowAMaxImpl(rows_norms, init);
112  }
116  void ComputeColAMax(Vector& cols_norms, bool init=true) const
117  {
118  DBG_ASSERT(NCols() == cols_norms.Dim());
119  if (init) cols_norms.Set(0.);
120  ComputeColAMaxImpl(cols_norms, init);
121  }
123 
128  virtual void Print(SmartPtr<const Journalist> jnlst,
129  EJournalLevel level,
130  EJournalCategory category,
131  const std::string& name,
132  Index indent=0,
133  const std::string& prefix="") const;
134  virtual void Print(const Journalist& jnlst,
135  EJournalLevel level,
136  EJournalCategory category,
137  const std::string& name,
138  Index indent=0,
139  const std::string& prefix="") const;
141 
143  inline
145 
146  protected:
154  virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
155 
159  virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
160 
165  virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
166  Vector& X) const;
167 
171  virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
172  const Vector& R, const Vector& Z,
173  const Vector& D, Vector& X) const;
174 
178  virtual bool HasValidNumbersImpl() const
179  {
180  return true;
181  }
182 
186  virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const = 0;
190  virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const = 0;
191 
193  virtual void PrintImpl(const Journalist& jnlst,
194  EJournalLevel level,
195  EJournalCategory category,
196  const std::string& name,
197  Index indent,
198  const std::string& prefix) const =0;
200 
201  private:
211  Matrix();
212 
214  Matrix(const Matrix&);
215 
217  Matrix& operator=(const Matrix&);
219 
221 
225  mutable bool cached_valid_;
227  };
228 
229 
239  {
240  public:
246  MatrixSpace(Index nRows, Index nCols)
247  :
248  nRows_(nRows),
249  nCols_(nCols)
250  {}
251 
253  virtual ~MatrixSpace()
254  {}
256 
260  virtual Matrix* MakeNew() const=0;
261 
263  Index NRows() const
264  {
265  return nRows_;
266  }
268  Index NCols() const
269  {
270  return nCols_;
271  }
272 
276  bool IsMatrixFromSpace(const Matrix& matrix) const
277  {
278  return (matrix.OwnerSpace() == this);
279  }
280 
281  private:
291  MatrixSpace();
292 
294  MatrixSpace(const MatrixSpace&);
295 
299 
301  const Index nRows_;
303  const Index nCols_;
304  };
305 
306 
307  /* Inline Methods */
308  inline
310  {
311  return owner_space_->NRows();
312  }
313 
314  inline
316  {
317  return owner_space_->NCols();
318  }
319 
320  inline
322  {
323  return owner_space_;
324  }
325 
326 } // namespace Ipopt
327 
328 // Macro definitions for debugging matrices
329 #if COIN_IPOPT_VERBOSITY == 0
330 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
331 #else
332 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
333  if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
334  if (dbg_jrnl.Jnlst()!=NULL) { \
335  (__mat).Print(dbg_jrnl.Jnlst(), \
336  J_ERROR, J_DBG, \
337  __mat_name, \
338  dbg_jrnl.IndentationLevel()*2, \
339  "# "); \
340  } \
341  }
342 #endif // #if COIN_IPOPT_VERBOSITY == 0
343 
344 #endif
Number * x
Input: Starting point Output: Optimal solution.
const SmartPtr< const MatrixSpace > owner_space_
Definition: IpMatrix.hpp:220
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.
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 ~MatrixSpace()
Destructor.
Definition: IpMatrix.hpp:253
Matrix(const MatrixSpace *owner_space)
Constructor.
Definition: IpMatrix.hpp:35
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const =0
Compute the max-norm of the rows in the matrix.
MatrixSpace(Index nRows, Index nCols)
Constructor, given the number rows and columns of all matrices generated by this MatrixSpace.
Definition: IpMatrix.hpp:246
const Index nRows_
Number of rows for all matrices of this type.
Definition: IpMatrix.hpp:301
Index NRows() const
Accessor function for the number of rows.
Definition: IpMatrix.hpp:263
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
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).
Vector Base Class.
Definition: IpVector.hpp:47
Index NRows() const
Number of rows.
Definition: IpMatrix.hpp:309
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Definition: IpMatrix.hpp:178
EJournalLevel
Print Level Enum.
SmartPtr< const MatrixSpace > OwnerSpace() const
Return the owner MatrixSpace.
Definition: IpMatrix.hpp:321
TaggedObject class.
virtual void ComputeColAMaxImpl(Vector &cols_norms, bool init) const =0
Compute the max-norm of the columns in the matrix.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:182
ReferencedObject class.
bool IsMatrixFromSpace(const Matrix &matrix) const
Method to test if a given matrix belongs to a particular matrix space.
Definition: IpMatrix.hpp:276
void Set(Number alpha)
Set each element in the vector to the scalar alpha.
Definition: IpVector.hpp:592
Matrix & operator=(const Matrix &)
Overloaded Equals Operator.
Matrix Base Class.
Definition: IpMatrix.hpp:27
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).
TaggedObject::Tag valid_cache_tag_
Definition: IpMatrix.hpp:224
void ComputeRowAMax(Vector &rows_norms, bool init=true) const
Compute the max-norm of the rows in the matrix.
Definition: IpMatrix.hpp:107
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:238
bool cached_valid_
Definition: IpMatrix.hpp:225
void TransMultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
Definition: IpMatrix.hpp:61
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
bool HasValidNumbers() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
virtual void TransMultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const =0
Matrix(transpose) vector multiply.
Index NCols() const
Number of columns.
Definition: IpMatrix.hpp:315
std::pair< const TaggedObject *, unsigned int > Tag
Type for the Tag values.
const Index nCols_
Number of columns for all matrices of this type.
Definition: IpMatrix.hpp:303
Class responsible for all message output.
void MultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
Definition: IpMatrix.hpp:51
Matrix()
default constructor
void ComputeColAMax(Vector &cols_norms, bool init=true) const
Compute the max-norm of the columns in the matrix.
Definition: IpMatrix.hpp:116
Index Dim() const
Dimension of the Vector.
Definition: IpVector.hpp:732
virtual Matrix * MakeNew() const =0
Pure virtual method for creating a new Matrix of the corresponding type.
void AddMSinvZ(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = X + alpha*(Matrix S^{-1} Z).
EJournalCategory
Category Selection Enum.
virtual void AddMSinvZImpl(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = X + alpha*(Matrix S^{-1} Z).
MatrixSpace()
default constructor
MatrixSpace & operator=(const MatrixSpace &)
Overloaded Equals Operator.
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const =0
Matrix-vector multiply.
Index NCols() const
Accessor function for the number of columns.
Definition: IpMatrix.hpp:268
virtual ~Matrix()
Destructor.
Definition: IpMatrix.hpp:42