Ipopt Documentation  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
12 namespace Ipopt
13 {
14 
15 /* forward declarations */
16 class MatrixSpace;
17 
28 {
29 public:
31 
37  const MatrixSpace* owner_space
38  )
39  : TaggedObject(),
40  owner_space_(owner_space),
41  valid_cache_tag_(0)
42  { }
43 
45  virtual ~Matrix()
46  { }
48 
50 
57  void MultVector(
58  Number alpha,
59  const Vector& x,
60  Number beta,
61  Vector& y
62  ) const
63  {
64  MultVectorImpl(alpha, x, beta, y);
65  }
66 
74  Number alpha,
75  const Vector& x,
76  Number beta,
77  Vector& y
78  ) const
79  {
80  TransMultVectorImpl(alpha, x, beta, y);
81  }
83 
89 
94  void AddMSinvZ(
95  Number alpha,
96  const Vector& S,
97  const Vector& Z,
98  Vector& X
99  ) const;
100 
105  void SinvBlrmZMTdBr(
106  Number alpha,
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 
119 
121  inline Index NRows() const;
122 
124  inline Index NCols() const;
126 
128 
135  Vector& rows_norms,
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 
153  Vector& cols_norms,
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 
170  virtual void Print(
173  EJournalLevel level,
174  EJournalCategory category,
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,
182  EJournalLevel level,
183  EJournalCategory category,
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 
193 protected:
197 
202  virtual void MultVectorImpl(
203  Number alpha,
204  const Vector& x,
205  Number beta,
206  Vector& y
207  ) const = 0;
208 
213  virtual void TransMultVectorImpl(
214  Number alpha,
215  const Vector& x,
216  Number beta,
217  Vector& y
218  ) const = 0;
219 
225  virtual void AddMSinvZImpl(
226  Number alpha,
227  const Vector& S,
228  const Vector& Z,
229  Vector& X
230  ) const;
231 
236  virtual void SinvBlrmZMTdBrImpl(
237  Number alpha,
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(
260  Vector& rows_norms,
261  bool init
262  ) const = 0;
263 
268  virtual void ComputeColAMaxImpl(
269  Vector& cols_norms,
270  bool init
271  ) const = 0;
272 
274  virtual void PrintImpl(
275  const Journalist& jnlst,
276  EJournalLevel level,
277  EJournalCategory category,
278  const std::string& name,
279  Index indent,
280  const std::string& prefix
281  ) const = 0;
283 
284 private:
293 
295  Matrix();
296 
298  Matrix(
299  const Matrix&
300  );
301 
303  Matrix& operator=(
304  const Matrix&
305  );
307 
309 
311  mutable TaggedObject::Tag valid_cache_tag_;
313  mutable bool cached_valid_;
315 };
316 
327 {
328 public:
330 
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 
369 private:
378 
380  MatrixSpace();
381 
383  MatrixSpace(
384  const MatrixSpace&
385  );
386 
388  MatrixSpace& operator=(
389  const MatrixSpace&
390  );
392 
394  const Index nRows_;
395 
397  const Index nCols_;
398 };
399 
400 /* Inline Methods */
401 inline Index Matrix::NRows() const
402 {
403  return owner_space_->NRows();
404 }
405 
406 inline Index Matrix::NCols() const
407 {
408  return owner_space_->NCols();
409 }
410 
412 {
413  return owner_space_;
414 }
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
const SmartPtr< const MatrixSpace > owner_space_
Definition: IpMatrix.hpp:308
virtual ~MatrixSpace()
Destructor.
Definition: IpMatrix.hpp:342
Matrix(const MatrixSpace *owner_space)
Constructor.
Definition: IpMatrix.hpp:36
MatrixSpace(Index nRows, Index nCols)
Constructor, given the number rows and columns of all matrices generated by this MatrixSpace.
Definition: IpMatrix.hpp:334
const Index nRows_
Number of rows for all matrices of this type.
Definition: IpMatrix.hpp:394
Index NRows() const
Accessor function for the number of rows.
Definition: IpMatrix.hpp:350
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
Vector Base Class.
Definition: IpVector.hpp:47
Index NRows() const
Number of rows.
Definition: IpMatrix.hpp:401
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Definition: IpMatrix.hpp:250
EJournalLevel
Print Level Enum.
SmartPtr< const MatrixSpace > OwnerSpace() const
Return the owner MatrixSpace.
Definition: IpMatrix.hpp:411
TaggedObject class.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
Storing the reference count of all the smart pointers that currently reference it.
bool IsMatrixFromSpace(const Matrix &matrix) const
Method to test if a given matrix belongs to a particular matrix space.
Definition: IpMatrix.hpp:362
void Set(Number alpha)
Set each element in the vector to the scalar alpha.
Definition: IpVector.hpp:682
Matrix Base Class.
Definition: IpMatrix.hpp:27
void ComputeRowAMax(Vector &rows_norms, bool init=true) const
Compute the max-norm of the rows in the matrix.
Definition: IpMatrix.hpp:134
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:326
bool cached_valid_
Definition: IpMatrix.hpp:313
void TransMultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
Definition: IpMatrix.hpp:73
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
Index NCols() const
Number of columns.
Definition: IpMatrix.hpp:406
unsigned int Tag
Type for the Tag values.
#define IPOPTLIB_EXPORT
const Index nCols_
Number of columns for all matrices of this type.
Definition: IpMatrix.hpp:397
Class responsible for all message output.
void MultVector(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
Definition: IpMatrix.hpp:57
void ComputeColAMax(Vector &cols_norms, bool init=true) const
Compute the max-norm of the columns in the matrix.
Definition: IpMatrix.hpp:152
Index Dim() const
Dimension of the Vector.
Definition: IpVector.hpp:836
EJournalCategory
Category Selection Enum.
Index NCols() const
Accessor function for the number of columns.
Definition: IpMatrix.hpp:356
virtual ~Matrix()
Destructor.
Definition: IpMatrix.hpp:45