Ipopt Documentation  
 
Loading...
Searching...
No Matches
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
13namespace Ipopt
14{
15
16/* forward declarations */
17class CompoundMatrixSpace;
18
35{
36public:
37
40
50 );
51
53 virtual ~CompoundMatrix();
55
61 void SetComp(
62 Index irow,
63 Index jcol,
64 const Matrix& matrix
65 );
66
69 Index irow,
70 Index jcol,
72 );
73
76 Index irow,
78 );
79
84 Index irow,
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
113protected:
116 virtual void MultVectorImpl(
118 const Vector& x,
119 Number beta,
120 Vector& y
121 ) const;
122
125 const Vector& x,
126 Number beta,
127 Vector& y
128 ) const;
129
130 virtual void AddMSinvZImpl(
132 const Vector& S,
133 const Vector& Z,
134 Vector& X
135 ) const;
136
137 virtual void SinvBlrmZMTdBrImpl(
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(
150 bool init
151 ) const;
152
153 virtual void ComputeColAMaxImpl(
155 bool init
156 ) const;
157
158 virtual void PrintImpl(
159 const Journalist& jnlst,
162 const std::string& name,
164 const std::string& prefix
165 ) const;
167
168private:
177
179
182 const CompoundMatrix&);
183
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{
224public:
227
235 );
236
241
244
246 Index irow,
248 );
249
252 Index jcol,
254 );
255
258 Index irow
259 ) const;
260
263 Index jcol
264 ) const;
265
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
297
299 {
300 return ncomps_rows_;
301 }
302
305 {
306 return ncomps_cols_;
307 }
308
310 bool Diagonal() const
311 {
312 return diagonal_;
313 }
315
318
319 virtual Matrix* MakeNew() const
320 {
321 return MakeNewCompoundMatrix();
322 }
323
324private:
333
335
338 const CompoundMatrixSpace&);
339
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
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{
400 if( IsValid(comps_[irow][jcol]) )
401 {
402 return GetRawPtr(comps_[irow][jcol]);
403 }
404 else if( IsValid(const_comps_[irow][jcol]) )
405 {
407 }
408
409 return NULL;
410}
411
413 Index irow,
414 Index jcol
415)
416{
419 return GetRawPtr(comps_[irow][jcol]);
420}
421
422} // namespace Ipopt
423#endif
#define DBG_ASSERT(test)
Definition IpDebug.hpp:27
This is the matrix space for CompoundMatrix.
bool Diagonal() const
True if the blocks lie on the diagonal - can make some operations faster.
Index NComps_Rows() const
Number of block rows.
std::vector< std::vector< bool > > allocate_block_
2-dim std::vector of booleans deciding whether to allocate a new matrix for the blocks automagically
CompoundMatrixSpace()
Default constructor.
Index ncomps_cols_
Number of block columns.
Index GetBlockRows(Index irow) const
Get the number nrows of rows in row-block number irow.
CompoundMatrixSpace & operator=(const CompoundMatrixSpace &)
Default Assignment Operator.
Index NComps_Cols() const
Number of block columns.
void SetBlockRows(Index irow, Index nrows)
Set the number nrows of rows in row-block number irow.
void SetCompSpace(Index irow, Index jcol, const MatrixSpace &mat_space, bool auto_allocate=false)
Set the component MatrixSpace.
Index GetBlockCols(Index jcol) const
Set the number ncols of columns in column-block number jcol.
virtual Matrix * MakeNew() const
Pure virtual method for creating a new Matrix of the corresponding type.
CompoundMatrixSpace(Index ncomps_rows, Index ncomps_cols, Index total_nRows, Index total_nCols)
Constructor, given the number of row and columns blocks, as well as the totel number of rows and colu...
SmartPtr< const MatrixSpace > GetCompSpace(Index irow, Index jcol) const
Obtain the component MatrixSpace in block row irow and block column jcol.
std::vector< Index > block_cols_
Vector of the number of cols in each comp row.
CompoundMatrixSpace(const CompoundMatrixSpace &)
Copy Constructor.
std::vector< Index > block_rows_
Vector of the number of rows in each comp column.
bool diagonal_
true if the CompoundMatrixSpace only has Matrix spaces along the diagonal.
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.
CompoundMatrix * MakeNewCompoundMatrix() const
Method for creating a new matrix of this specific type.
void SetBlockCols(Index jcol, Index ncols)
Set the number ncols of columns in column-block number jcol.
bool DimensionsSet() const
Auxiliary function for debugging to set if all block dimensions have been set.
bool dimensions_set_
Store whether or not the dimensions are valid.
Class for Matrices consisting of other matrices.
void CreateBlockFromSpace(Index irow, Index jcol)
Method to create a new matrix from the space for this block.
virtual void TransMultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
void operator=(const CompoundMatrix &)
Default Assignment Operator.
void SetComp(Index irow, Index jcol, const Matrix &matrix)
Method for setting an individual component at position (irow, icol) in the compound matrix.
virtual ~CompoundMatrix()
Destructor.
SmartPtr< Matrix > GetCompNonConst(Index irow, Index jcol)
Method for retrieving one block from the compound matrix as a non-const Matrix.
void SetCompNonConst(Index irow, Index jcol, Matrix &matrix)
Method to set a non-const Matrix entry.
SmartPtr< const Matrix > GetComp(Index irow, Index jcol) const
Method for retrieving one block from the compound matrix as a const Matrix.
const Matrix * ConstComp(Index irow, Index jcol) const
const CompoundMatrixSpace * owner_space_
Copy of the owner_space ptr as a CompoundMatrixSpace instead of MatrixSpace.
std::vector< std::vector< SmartPtr< const Matrix > > > const_comps_
Matrix of const matrix's containing the components.
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).
bool MatricesValid() const
Method to check whether or not the matrices are valid.
Index NComps_Rows() const
Number of block rows of this compound matrix.
virtual void ComputeColAMaxImpl(Vector &cols_norms, bool init) const
Compute the max-norm of the columns in the matrix.
virtual void AddMSinvZImpl(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = X + alpha*(Matrix S^{-1} Z).
CompoundMatrix(const CompoundMatrixSpace *owner_space)
Constructor, taking the owner_space.
CompoundMatrix()
Default Constructor.
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
std::vector< std::vector< SmartPtr< Matrix > > > comps_
Matrix of matrix's containing the components.
Index NComps_Cols() const
Number of block colmuns of this compound matrix.
Matrix * Comp(Index irow, Index jcol)
bool matrices_valid_
boolean indicating if the compound matrix is in a "valid" state
CompoundMatrix(const CompoundMatrix &)
Copy Constructor.
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
virtual void PrintImpl(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent, const std::string &prefix) const
Print detailed information about the matrix.
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
Matrix Base Class.
Definition IpMatrix.hpp:28
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.
bool IsValid(const SmartPtr< U > &smart_ptr)
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
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