Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 // $Id: IpCompoundMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8
9 #ifndef __IPCOMPOUNDMATRIX_HPP__
10 #define __IPCOMPOUNDMATRIX_HPP__
11
12 #include "IpUtils.hpp"
13 #include "IpMatrix.hpp"
14
15 namespace Ipopt
16 {
17
18 /* forward declarations */
19 class CompoundMatrixSpace;
20
34 class CompoundMatrix : public Matrix
35 {
36 public:
37
40
47 CompoundMatrix(const CompoundMatrixSpace* owner_space);
48
50 virtual ~CompoundMatrix();
52
56 void SetComp(Index irow, Index jcol, const Matrix& matrix);
57
59 void SetCompNonConst(Index irow, Index jcol, Matrix& matrix);
60
62 void CreateBlockFromSpace(Index irow, Index jcol);
63
67 SmartPtr<const Matrix> GetComp(Index irow, Index jcol) const
68 {
69 return ConstComp(irow, jcol);
70 }
71
76 SmartPtr<Matrix> GetCompNonConst(Index irow, Index jcol)
77 {
78 ObjectChanged();
79 return Comp(irow, jcol);
80 }
81
83 inline Index NComps_Rows() const;
85 inline Index NComps_Cols() const;
86
87 protected:
90 virtual void MultVectorImpl(Number alpha, const Vector& x,
91 Number beta, Vector& y) const;
92
93 virtual void TransMultVectorImpl(Number alpha, const Vector& x,
94 Number beta, Vector& y) const;
95
98 virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
99 Vector& X) const;
100
103 virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
104 const Vector& R, const Vector& Z,
105 const Vector& D, Vector& X) const;
106
109 virtual bool HasValidNumbersImpl() const;
110
111 virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
112
113 virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const;
114
115 virtual void PrintImpl(const Journalist& jnlst,
116 EJournalLevel level,
117 EJournalCategory category,
118 const std::string& name,
119 Index indent,
120 const std::string& prefix) const;
122
123 private:
133 CompoundMatrix();
134
136 CompoundMatrix(const CompoundMatrix&);
137
139 void operator=(const CompoundMatrix&);
141
143 std::vector<std::vector<SmartPtr<Matrix> > > comps_;
144
146 std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
147
150 const CompoundMatrixSpace* owner_space_;
151
153 mutable bool matrices_valid_;
154
156 bool MatricesValid() const;
157
158 inline const Matrix* ConstComp(Index irow, Index jcol) const;
159
160 inline Matrix* Comp(Index irow, Index jcol);
161 };
162
168 class CompoundMatrixSpace : public MatrixSpace
169 {
170 public:
176 CompoundMatrixSpace(Index ncomps_rows,
177 Index ncomps_cols,
178 Index total_nRows,
179 Index total_nCols);
180
182 ~CompoundMatrixSpace()
183 {}
185
189 void SetBlockRows(Index irow, Index nrows);
190
192 void SetBlockCols(Index jcol, Index ncols);
193
195 Index GetBlockRows(Index irow) const;
196
198 Index GetBlockCols(Index jcol) const;
199
206 void SetCompSpace(Index irow, Index jcol,
207 const MatrixSpace& mat_space,
208 bool auto_allocate = false);
210
214 SmartPtr<const MatrixSpace> GetCompSpace(Index irow, Index jcol) const
215 {
216 DBG_ASSERT(irow<NComps_Rows());
217 DBG_ASSERT(jcol<NComps_Cols());
218 return comp_spaces_[irow][jcol];
219 }
220
224 Index NComps_Rows() const
225 {
226 return ncomps_rows_;
227 }
229 Index NComps_Cols() const
230 {
231 return ncomps_cols_;
232 }
233
235 bool Diagonal() const
236 {
237 return diagonal_;
238 }
240
242 CompoundMatrix* MakeNewCompoundMatrix() const;
243
246 virtual Matrix* MakeNew() const
247 {
248 return MakeNewCompoundMatrix();
249 }
250
251 private:
261 CompoundMatrixSpace();
262
264 CompoundMatrixSpace(const CompoundMatrixSpace&);
265
267 CompoundMatrixSpace& operator=(const CompoundMatrixSpace&);
269
271 Index ncomps_rows_;
272
274 Index ncomps_cols_;
275
277 mutable bool dimensions_set_;
278
280 std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
281
284 std::vector<std::vector< bool > > allocate_block_;
285
287 std::vector<Index> block_rows_;
288
290 std::vector<Index> block_cols_;
291
296 bool diagonal_;
297
300 bool DimensionsSet() const;
301 };
302
303 /* inline methods */
304 inline
305 Index CompoundMatrix::NComps_Rows() const
306 {
307 return owner_space_->NComps_Rows();
308 }
309
310 inline
311 Index CompoundMatrix::NComps_Cols() const
312 {
313 return owner_space_->NComps_Cols();
314 }
315
316 inline
317 const Matrix* CompoundMatrix::ConstComp(Index irow, Index jcol) const
318 {
319 DBG_ASSERT(irow < NComps_Rows());
320 DBG_ASSERT(jcol < NComps_Cols());
321 if (IsValid(comps_[irow][jcol])) {
322 return GetRawPtr(comps_[irow][jcol]);
323 }
324 else if (IsValid(const_comps_[irow][jcol])) {
325 return GetRawPtr(const_comps_[irow][jcol]);
326 }
327
328 return NULL;
329 }
330
331 inline
332 Matrix* CompoundMatrix::Comp(Index irow, Index jcol)
333 {
334 DBG_ASSERT(irow < NComps_Rows());
335 DBG_ASSERT(jcol < NComps_Cols());
336 return GetRawPtr(comps_[irow][jcol]);
337 }
338
339 } // namespace Ipopt
340 #endif
Ipopt::CompoundMatrixSpace::Diagonal
bool Diagonal() const
True if the blocks lie on the diagonal - can make some operations faster.
Definition: IpCompoundMatrix.hpp:235
Ipopt::CompoundMatrix::MultVectorImpl
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
Ipopt::IsValid
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:579
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
Ipopt::CompoundMatrix::PrintImpl
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.
IpUtils.hpp
Ipopt::CompoundMatrix::SetCompNonConst
void SetCompNonConst(Index irow, Index jcol, Matrix &matrix)
Method to set a non-const Matrix entry.
Ipopt::CompoundMatrixSpace::diagonal_
bool diagonal_
true if the CompoundMatrixSpace only has Matrix spaces along the diagonal.
Definition: IpCompoundMatrix.hpp:296
Ipopt::CompoundMatrix::GetComp
SmartPtr< const Matrix > GetComp(Index irow, Index jcol) const
Method for retrieving one block from the compound matrix as a const Matrix.
Definition: IpCompoundMatrix.hpp:67
Ipopt::CompoundMatrixSpace::~CompoundMatrixSpace
~CompoundMatrixSpace()
Destructor.
Definition: IpCompoundMatrix.hpp:182
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::CompoundMatrixSpace
This is the matrix space for CompoundMatrix.
Definition: IpCompoundMatrix.hpp:168
Ipopt::TaggedObject::ObjectChanged
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Definition: IpTaggedObject.hpp:117
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:47
Ipopt::CompoundMatrixSpace::GetCompSpace
SmartPtr< const MatrixSpace > GetCompSpace(Index irow, Index jcol) const
Obtain the component MatrixSpace in block row irow and block column jcol.
Definition: IpCompoundMatrix.hpp:214
Ipopt::CompoundMatrixSpace::NComps_Rows
Index NComps_Rows() const
Number of block rows.
Definition: IpCompoundMatrix.hpp:224
Ipopt::CompoundMatrix::MatricesValid
bool MatricesValid() const
Method to check whether or not the matrices are valid.
IpMatrix.hpp
Ipopt::CompoundMatrix::AddMSinvZImpl
virtual void AddMSinvZImpl(Number alpha, const Vector &S, const Vector &Z, Vector &X) const
X = beta*X + alpha*(Matrix S^{-1} Z).
Ipopt::CompoundMatrixSpace::SetCompSpace
void SetCompSpace(Index irow, Index jcol, const MatrixSpace &mat_space, bool auto_allocate=false)
Set the component MatrixSpace.
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:51
Ipopt::CompoundMatrix::Comp
Matrix * Comp(Index irow, Index jcol)
Definition: IpCompoundMatrix.hpp:332
Ipopt::CompoundMatrix::matrices_valid_
bool matrices_valid_
boolean indicating if the compound matrix is in a &quot;valid&quot; state
Definition: IpCompoundMatrix.hpp:153
Ipopt::CompoundMatrixSpace::operator=
CompoundMatrixSpace & operator=(const CompoundMatrixSpace &)
Overloaded Equals Operator.
Ipopt::CompoundMatrixSpace::GetBlockRows
Index GetBlockRows(Index irow) const
Get the number nrows of rows in row-block number irow.
Ipopt::CompoundMatrixSpace::SetBlockRows
void SetBlockRows(Index irow, Index nrows)
Set the number nrows of rows in row-block number irow.
Ipopt::CompoundMatrix::operator=
void operator=(const CompoundMatrix &)
Overloaded Equals Operator.
Ipopt::CompoundMatrix::CompoundMatrix
CompoundMatrix()
Default Constructor.
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::CompoundMatrix::CreateBlockFromSpace
void CreateBlockFromSpace(Index irow, Index jcol)
Method to create a new matrix from the space for this block.
Ipopt::CompoundMatrixSpace::comp_spaces_
std::vector< std::vector< SmartPtr< const MatrixSpace > > > comp_spaces_
2-dim std::vector of matrix spaces for the components
Definition: IpCompoundMatrix.hpp:280
Ipopt::CompoundMatrixSpace::ncomps_rows_
Index ncomps_rows_
Number of block rows.
Definition: IpCompoundMatrix.hpp:271
Ipopt::CompoundMatrix::SetComp
void SetComp(Index irow, Index jcol, const Matrix &matrix)
Method for setting an individual component at position (irow, icol) in the compound matrix...
Ipopt::CompoundMatrix::comps_
std::vector< std::vector< SmartPtr< Matrix > > > comps_
Matrix of matrix&#39;s containing the components.
Definition: IpCompoundMatrix.hpp:143
Ipopt::CompoundMatrixSpace::dimensions_set_
bool dimensions_set_
Store whether or not the dimensions are valid.
Definition: IpCompoundMatrix.hpp:277
Ipopt::GetRawPtr
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:560
Ipopt::CompoundMatrix::ConstComp
const Matrix * ConstComp(Index irow, Index jcol) const
Definition: IpCompoundMatrix.hpp:317
Ipopt::CompoundMatrixSpace::MakeNew
virtual Matrix * MakeNew() const
Overloaded MakeNew method for the MatrixSpace base class.
Definition: IpCompoundMatrix.hpp:246
Ipopt::Matrix
Matrix Base Class.
Definition: IpMatrix.hpp:27
Ipopt::CompoundMatrixSpace::allocate_block_
std::vector< std::vector< bool > > allocate_block_
2-dim std::vector of booleans deciding whether to allocate a new matrix for the blocks automagically ...
Definition: IpCompoundMatrix.hpp:284
Ipopt::CompoundMatrix::ComputeColAMaxImpl
virtual void ComputeColAMaxImpl(Vector &cols_norms, bool init) const
Compute the max-norm of the columns in the matrix.
Ipopt::CompoundMatrix::GetCompNonConst
SmartPtr< Matrix > GetCompNonConst(Index irow, Index jcol)
Method for retrieving one block from the compound matrix as a non-const Matrix.
Definition: IpCompoundMatrix.hpp:76
Ipopt::MatrixSpace
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:239
Ipopt::CompoundMatrix::~CompoundMatrix
virtual ~CompoundMatrix()
Destructor.
Ipopt::CompoundMatrix::TransMultVectorImpl
virtual void TransMultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix(transpose) vector multiply.
Ipopt::CompoundMatrixSpace::CompoundMatrixSpace
CompoundMatrixSpace()
Default constructor.
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
Ipopt::CompoundMatrixSpace::NComps_Cols
Index NComps_Cols() const
Number of block columns.
Definition: IpCompoundMatrix.hpp:229
Ipopt::CompoundMatrix::const_comps_
std::vector< std::vector< SmartPtr< const Matrix > > > const_comps_
Matrix of const matrix&#39;s containing the components.
Definition: IpCompoundMatrix.hpp:146
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
Ipopt::CompoundMatrix::NComps_Rows
Index NComps_Rows() const
Number of block rows of this compound matrix.
Definition: IpCompoundMatrix.hpp:305
Ipopt::CompoundMatrixSpace::SetBlockCols
void SetBlockCols(Index jcol, Index ncols)
Set the number ncols of columns in column-block number jcol.
Ipopt::CompoundMatrix::NComps_Cols
Index NComps_Cols() const
Number of block colmuns of this compound matrix.
Definition: IpCompoundMatrix.hpp:311
Ipopt::CompoundMatrixSpace::MakeNewCompoundMatrix
CompoundMatrix * MakeNewCompoundMatrix() const
Method for creating a new matrix of this specific type.
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:134
Ipopt::CompoundMatrixSpace::block_rows_
std::vector< Index > block_rows_
Vector of the number of rows in each comp column.
Definition: IpCompoundMatrix.hpp:287
Ipopt::CompoundMatrix::owner_space_
const CompoundMatrixSpace * owner_space_
Copy of the owner_space ptr as a CompoundMatrixSpace instead of MatrixSpace.
Definition: IpCompoundMatrix.hpp:150
Ipopt::CompoundMatrixSpace::block_cols_
std::vector< Index > block_cols_
Vector of the number of cols in each comp row.
Definition: IpCompoundMatrix.hpp:290
Ipopt::CompoundMatrix::ComputeRowAMaxImpl
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
Ipopt::CompoundMatrixSpace::DimensionsSet
bool DimensionsSet() const
Auxilliary function for debugging to set if all block dimensions have been set.
Ipopt::CompoundMatrixSpace::ncomps_cols_
Index ncomps_cols_
Number of block columns.
Definition: IpCompoundMatrix.hpp:274
Ipopt::CompoundMatrix
Class for Matrices consisting of other matrices.
Definition: IpCompoundMatrix.hpp:34
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:70
Ipopt::CompoundMatrixSpace::GetBlockCols
Index GetBlockCols(Index jcol) const
Set the number ncols of columns in column-block number jcol.
Ipopt::CompoundMatrix::SinvBlrmZMTdBrImpl
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).
Ipopt::CompoundMatrix::HasValidNumbersImpl
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).