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 1861 2010-12-21 21:34:47Z andreasw $
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),
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  Index NRows() const;
96 
98  Index NCols() const;
100 
106  void ComputeRowAMax(Vector& rows_norms, bool init=true) const
107  {
108  DBG_ASSERT(NRows() == rows_norms.Dim());
109  if (init) rows_norms.Set(0.);
110  ComputeRowAMaxImpl(rows_norms, init);
111  }
115  void ComputeColAMax(Vector& cols_norms, bool init=true) const
116  {
117  DBG_ASSERT(NCols() == cols_norms.Dim());
118  if (init) cols_norms.Set(0.);
119  ComputeColAMaxImpl(cols_norms, init);
120  }
122 
127  virtual void Print(SmartPtr<const Journalist> jnlst,
128  EJournalLevel level,
129  EJournalCategory category,
130  const std::string& name,
131  Index indent=0,
132  const std::string& prefix="") const;
133  virtual void Print(const Journalist& jnlst,
134  EJournalLevel level,
135  EJournalCategory category,
136  const std::string& name,
137  Index indent=0,
138  const std::string& prefix="") const;
140 
143 
144  protected:
152  virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
153 
157  virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0;
158 
163  virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
164  Vector& X) const;
165 
169  virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
170  const Vector& R, const Vector& Z,
171  const Vector& D, Vector& X) const;
172 
176  virtual bool HasValidNumbersImpl() const
177  {
178  return true;
179  }
180 
184  virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const = 0;
188  virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const = 0;
189 
191  virtual void PrintImpl(const Journalist& jnlst,
192  EJournalLevel level,
193  EJournalCategory category,
194  const std::string& name,
195  Index indent,
196  const std::string& prefix) const =0;
198 
199  private:
209  Matrix();
210 
212  Matrix(const Matrix&);
213 
215  Matrix& operator=(const Matrix&);
217 
219 
223  mutable bool cached_valid_;
225  };
226 
227 
237  {
238  public:
244  MatrixSpace(Index nRows, Index nCols)
245  :
246  nRows_(nRows),
247  nCols_(nCols)
248  {}
249 
251  virtual ~MatrixSpace()
252  {}
254 
258  virtual Matrix* MakeNew() const=0;
259 
261  Index NRows() const
262  {
263  return nRows_;
264  }
266  Index NCols() const
267  {
268  return nCols_;
269  }
270 
274  bool IsMatrixFromSpace(const Matrix& matrix) const
275  {
276  return (matrix.OwnerSpace() == this);
277  }
278 
279  private:
289  MatrixSpace();
290 
292  MatrixSpace(const MatrixSpace&);
293 
297 
299  const Index nRows_;
301  const Index nCols_;
302  };
303 
304 
305  /* Inline Methods */
306  inline
308  {
309  return owner_space_->NRows();
310  }
311 
312  inline
314  {
315  return owner_space_->NCols();
316  }
317 
318  inline
320  {
321  return owner_space_;
322  }
323 
324 } // namespace Ipopt
325 
326 // Macro definitions for debugging matrices
327 #if COIN_IPOPT_VERBOSITY == 0
328 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
329 #else
330 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \
331  if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
332  if (dbg_jrnl.Jnlst()!=NULL) { \
333  (__mat).Print(dbg_jrnl.Jnlst(), \
334  J_ERROR, J_DBG, \
335  __mat_name, \
336  dbg_jrnl.IndentationLevel()*2, \
337  "# "); \
338  } \
339  }
340 #endif // #if COIN_IPOPT_VERBOSITY == 0
341 
342 #endif