Ipopt Documentation  
IpCompoundMatrix.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2009 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 __IPCOMPOUNDMATRIX_HPP__
8 #define __IPCOMPOUNDMATRIX_HPP__
9 
10 #include "IpUtils.hpp"
11 #include "IpMatrix.hpp"
12 
13 namespace Ipopt
14 {
15 
16 /* forward declarations */
17 class CompoundMatrixSpace;
18 
35 {
36 public:
37 
39 
49  const CompoundMatrixSpace* owner_space
50  );
51 
53  virtual ~CompoundMatrix();
55 
61  void SetComp(
62  Index irow,
63  Index jcol,
64  const Matrix& matrix
65  );
66 
68  void SetCompNonConst(
69  Index irow,
70  Index jcol,
71  Matrix& matrix
72  );
73 
75  void CreateBlockFromSpace(
76  Index irow,
77  Index jcol
78  );
79 
84  Index irow,
85  Index jcol
86  ) const
87  {
88  return ConstComp(irow, jcol);
89  }
90 
99  Index irow,
100  Index jcol
101  )
102  {
103  ObjectChanged();
104  return Comp(irow, jcol);
105  }
106 
108  inline Index NComps_Rows() const;
109 
111  inline Index NComps_Cols() const;
112 
113 protected:
115  virtual void MultVectorImpl(
117  Number alpha,
118  const Vector& x,
119  Number beta,
120  Vector& y
121  ) const;
122 
123  virtual void TransMultVectorImpl(
124  Number alpha,
125  const Vector& x,
126  Number beta,
127  Vector& y
128  ) const;
129 
130  virtual void AddMSinvZImpl(
131  Number alpha,
132  const Vector& S,
133  const Vector& Z,
134  Vector& X
135  ) const;
136 
137  virtual void SinvBlrmZMTdBrImpl(
138  Number alpha,
139  const Vector& S,
140  const Vector& R,
141  const Vector& Z,
142  const Vector& D,
143  Vector& X
144  ) const;
145 
146  virtual bool HasValidNumbersImpl() const;
147 
148  virtual void ComputeRowAMaxImpl(
149  Vector& rows_norms,
150  bool init
151  ) const;
152 
153  virtual void ComputeColAMaxImpl(
154  Vector& cols_norms,
155  bool init
156  ) const;
157 
158  virtual void PrintImpl(
159  const Journalist& jnlst,
160  EJournalLevel level,
161  EJournalCategory category,
162  const std::string& name,
163  Index indent,
164  const std::string& prefix
165  ) const;
167 
168 private:
176 
178  CompoundMatrix();
179 
182  const CompoundMatrix&);
183 
185  void operator=(
186  const CompoundMatrix&);
188 
190  std::vector<std::vector<SmartPtr<Matrix> > > comps_;
191 
193  std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
194 
199 
201  mutable bool matrices_valid_;
202 
204  bool MatricesValid() const;
205 
206  inline const Matrix* ConstComp(
207  Index irow,
208  Index jcol
209  ) const;
210 
211  inline Matrix* Comp(
212  Index irow,
213  Index jcol
214  );
215 };
216 
223 {
224 public:
226 
231  Index ncomps_rows,
232  Index ncomps_cols,
233  Index total_nRows,
234  Index total_nCols
235  );
236 
239  { }
241 
243 
245  void SetBlockRows(
246  Index irow,
247  Index nrows
248  );
249 
251  void SetBlockCols(
252  Index jcol,
253  Index ncols
254  );
255 
257  Index GetBlockRows(
258  Index irow
259  ) const;
260 
262  Index GetBlockCols(
263  Index jcol
264  ) const;
265 
274  void SetCompSpace(
275  Index irow,
276  Index jcol,
277  const MatrixSpace& mat_space,
278  bool auto_allocate = false
279  );
281 
286  Index irow,
287  Index jcol
288  ) const
289  {
290  DBG_ASSERT(irow < NComps_Rows());
291  DBG_ASSERT(jcol < NComps_Cols());
292  return comp_spaces_[irow][jcol];
293  }
294 
296 
299  {
300  return ncomps_rows_;
301  }
302 
305  {
306  return ncomps_cols_;
307  }
308 
310  bool Diagonal() const
311  {
312  return diagonal_;
313  }
315 
317  CompoundMatrix* MakeNewCompoundMatrix() const;
318 
319  virtual Matrix* MakeNew() const
320  {
321  return MakeNewCompoundMatrix();
322  }
323 
324 private:
332 
335 
338  const CompoundMatrixSpace&);
339 
341  CompoundMatrixSpace& operator=(
342  const CompoundMatrixSpace&
343  );
345 
348 
351 
353  mutable bool dimensions_set_;
354 
356  std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
357 
361  std::vector<std::vector<bool> > allocate_block_;
362 
364  std::vector<Index> block_rows_;
365 
367  std::vector<Index> block_cols_;
368 
374  bool diagonal_;
375 
379  bool DimensionsSet() const;
380 };
381 
382 /* inline methods */
384 {
385  return owner_space_->NComps_Rows();
386 }
387 
389 {
390  return owner_space_->NComps_Cols();
391 }
392 
394  Index irow,
395  Index jcol
396 ) const
397 {
398  DBG_ASSERT(irow < NComps_Rows());
399  DBG_ASSERT(jcol < NComps_Cols());
400  if( IsValid(comps_[irow][jcol]) )
401  {
402  return GetRawPtr(comps_[irow][jcol]);
403  }
404  else if( IsValid(const_comps_[irow][jcol]) )
405  {
406  return GetRawPtr(const_comps_[irow][jcol]);
407  }
408 
409  return NULL;
410 }
411 
413  Index irow,
414  Index jcol
415 )
416 {
417  DBG_ASSERT(irow < NComps_Rows());
418  DBG_ASSERT(jcol < NComps_Cols());
419  return GetRawPtr(comps_[irow][jcol]);
420 }
421 
422 } // namespace Ipopt
423 #endif
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
bool diagonal_
true if the CompoundMatrixSpace only has Matrix spaces along the diagonal.
const Matrix * ConstComp(Index irow, Index jcol) const
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
This is the matrix space for CompoundMatrix.
Vector Base Class.
Definition: IpVector.hpp:47
virtual Matrix * MakeNew() const
Pure virtual method for creating a new Matrix of the corresponding type.
EJournalLevel
Print Level Enum.
Matrix * Comp(Index irow, Index jcol)
SmartPtr< const MatrixSpace > GetCompSpace(Index irow, Index jcol) const
Obtain the component MatrixSpace in block row irow and block column jcol.
Index NComps_Cols() const
Number of block colmuns of this compound matrix.
bool matrices_valid_
boolean indicating if the compound matrix is in a "valid" state
This file contains a base class for all exceptions and a set of macros to help with exceptions...
Index NComps_Cols() const
Number of block columns.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
std::vector< std::vector< SmartPtr< const MatrixSpace > > > comp_spaces_
2-dim std::vector of matrix spaces for the components
Index ncomps_rows_
Number of block rows.
std::vector< std::vector< SmartPtr< Matrix > > > comps_
Matrix of matrix&#39;s containing the components.
bool dimensions_set_
Store whether or not the dimensions are valid.
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
Matrix Base Class.
Definition: IpMatrix.hpp:27
Index NComps_Rows() const
Number of block rows.
SmartPtr< Matrix > GetCompNonConst(Index irow, Index jcol)
Method for retrieving one block from the compound matrix as a non-const Matrix.
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:326
bool Diagonal() const
True if the blocks lie on the diagonal - can make some operations faster.
SmartPtr< const Matrix > GetComp(Index irow, Index jcol) const
Method for retrieving one block from the compound matrix as a const Matrix.
std::vector< std::vector< bool > > allocate_block_
2-dim std::vector of booleans deciding whether to allocate a new matrix for the blocks automagically ...
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
std::vector< std::vector< SmartPtr< const Matrix > > > const_comps_
Matrix of const matrix&#39;s containing the components.
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
#define IPOPTLIB_EXPORT
Class responsible for all message output.
std::vector< Index > block_rows_
Vector of the number of rows in each comp column.
Index NComps_Rows() const
Number of block rows of this compound matrix.
const CompoundMatrixSpace * owner_space_
Copy of the owner_space ptr as a CompoundMatrixSpace instead of MatrixSpace.
std::vector< Index > block_cols_
Vector of the number of cols in each comp row.
Index ncomps_cols_
Number of block columns.
Class for Matrices consisting of other matrices.
EJournalCategory
Category Selection Enum.