Ipopt  3.11.9
IpCompoundSymMatrix.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: IpCompoundSymMatrix.hpp 1861 2010-12-21 21:34:47Z andreasw $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPCOMPOUNDSYMMATRIX_HPP__
10 #define __IPCOMPOUNDSYMMATRIX_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpSymMatrix.hpp"
14 
15 namespace Ipopt
16 {
17 
18  /* forward declarations */
19  class CompoundSymMatrixSpace;
20 
25  {
26  public:
27 
30 
36  CompoundSymMatrix(const CompoundSymMatrixSpace* owner_space);
37 
41 
46  void SetComp(Index irow, Index jcol, const Matrix& matrix);
47 
49  void SetCompNonConst(Index irow, Index jcol, Matrix& matrix);
50 
55  {
56  return ConstComp(irow,jcol);
57  }
58 
63  {
64  ObjectChanged();
65  return Comp(irow,jcol);
66  }
67 
70 
71  // The following don't seem to be necessary
72  /* Number of block rows of this compound matrix. */
73  // Index NComps_NRows() const { return NComps_Dim(); }
74 
75  /* Number of block colmuns of this compound matrix. */
76  // Index NComps_NCols() const { return NComps_Dim(); }
77 
79  Index NComps_Dim() const;
80 
81  protected:
84  virtual void MultVectorImpl(Number alpha, const Vector& x,
85  Number beta, Vector& y) const;
86 
89  virtual bool HasValidNumbersImpl() const;
90 
91  virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
92 
93  virtual void PrintImpl(const Journalist& jnlst,
94  EJournalLevel level,
95  EJournalCategory category,
96  const std::string& name,
97  Index indent,
98  const std::string& prefix) const;
100 
101  private:
112 
115 
117  void operator=(const CompoundSymMatrix&);
119 
121  std::vector<std::vector<SmartPtr<Matrix> > > comps_;
122 
124  std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
125 
128 
130  mutable bool matrices_valid_;
131 
133  bool MatricesValid() const;
134 
136  const Matrix* ConstComp(Index irow, Index jcol) const
137  {
138  DBG_ASSERT(irow < NComps_Dim());
139  DBG_ASSERT(jcol <= irow);
140  if (IsValid(comps_[irow][jcol])) {
141  return GetRawPtr(comps_[irow][jcol]);
142  }
143  else if (IsValid(const_comps_[irow][jcol])) {
144  return GetRawPtr(const_comps_[irow][jcol]);
145  }
146 
147  return NULL;
148  }
149 
151  Matrix* Comp(Index irow, Index jcol)
152  {
153  DBG_ASSERT(irow < NComps_Dim());
154  DBG_ASSERT(jcol <= irow);
155  // We shouldn't be asking for a non-const if this entry holds a
156  // const one...
157  DBG_ASSERT(IsNull(const_comps_[irow][jcol]));
158  if (IsValid(comps_[irow][jcol])) {
159  return GetRawPtr(comps_[irow][jcol]);
160  }
161 
162  return NULL;
163  }
164  };
165 
172  {
173  public:
179  CompoundSymMatrixSpace(Index ncomp_spaces, Index total_dim);
180 
183  {}
185 
189  void SetBlockDim(Index irow_jcol, Index dim);
190 
192  Index GetBlockDim(Index irow_jcol) const;
193 
200  void SetCompSpace(Index irow, Index jcol,
201  const MatrixSpace& mat_space,
202  bool auto_allocate = false);
204 
209  {
211  DBG_ASSERT(jcol<=irow);
212  return comp_spaces_[irow][jcol];
213  }
214 
218  {
219  return ncomp_spaces_;
220  }
222 
225 
228  virtual SymMatrix* MakeNewSymMatrix() const
229  {
230  return MakeNewCompoundSymMatrix();
231  }
232 
233  private:
244 
247 
251 
254 
259  std::vector<Index> block_dim_;
260 
263  std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
264 
267  std::vector<std::vector< bool > > allocate_block_;
268 
270  mutable bool dimensions_set_;
271 
273  bool DimensionsSet() const;
274  };
275 
276  inline
278  {
280  }
281 
282 } // namespace Ipopt
283 #endif
Ipopt::CompoundSymMatrixSpace::SetCompSpace
void SetCompSpace(Index irow, Index jcol, const MatrixSpace &mat_space, bool auto_allocate=false)
Set the component SymMatrixSpace.
IpUtils.hpp
Ipopt::CompoundSymMatrix
Class for symmetric matrices consisting of other matrices.
Definition: IpCompoundSymMatrix.hpp:24
Ipopt::CompoundSymMatrixSpace::MakeNewCompoundSymMatrix
CompoundSymMatrix * MakeNewCompoundSymMatrix() const
Method for creating a new matrix of this specific type.
Ipopt::MatrixSpace
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:239
Ipopt::CompoundSymMatrix::NComps_Dim
Index NComps_Dim() const
Number of block rows and columns.
Ipopt::CompoundSymMatrix::CompoundSymMatrix
CompoundSymMatrix()
Default Constructor.
Ipopt::CompoundSymMatrix::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::CompoundSymMatrixSpace::dimensions_set_
bool dimensions_set_
boolean indicating if the compound matrix space is in a "valid" state
Definition: IpCompoundSymMatrix.hpp:270
Ipopt::CompoundSymMatrixSpace::DimensionsSet
bool DimensionsSet() const
Method to check whether or not the spaces are valid.
Ipopt::CompoundSymMatrixSpace::NComps_Dim
Index NComps_Dim() const
Definition: IpCompoundSymMatrix.hpp:217
Ipopt
Definition: matlabjournal.hpp:14
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::Matrix
Matrix Base Class.
Definition: IpMatrix.hpp:27
Ipopt::CompoundSymMatrix::MatricesValid
bool MatricesValid() const
method to check wether or not the matrices are valid
Ipopt::CompoundSymMatrix::GetComp
SmartPtr< const Matrix > GetComp(Index irow, Index jcol) const
Method for retrieving one block from the compound matrix.
Definition: IpCompoundSymMatrix.hpp:54
Ipopt::CompoundSymMatrix::GetCompNonConst
SmartPtr< Matrix > GetCompNonConst(Index irow, Index jcol)
Non const version of GetComp.
Definition: IpCompoundSymMatrix.hpp:62
Ipopt::TaggedObject::ObjectChanged
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Definition: IpTaggedObject.hpp:116
Ipopt::CompoundSymMatrixSpace
This is the matrix space for CompoundSymMatrix.
Definition: IpCompoundSymMatrix.hpp:171
Ipopt::CompoundSymMatrix::owner_space_
const CompoundSymMatrixSpace * owner_space_
Copy of the owner_space ptr as a CompoundSymMatrixSpace.
Definition: IpCompoundSymMatrix.hpp:127
Ipopt::CompoundSymMatrix::MakeNewCompoundSymMatrix
SmartPtr< CompoundSymMatrix > MakeNewCompoundSymMatrix() const
Method for creating a new matrix of this specific type.
Definition: IpCompoundSymMatrix.hpp:277
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:51
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
Ipopt::CompoundSymMatrixSpace::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: IpCompoundSymMatrix.hpp:267
Ipopt::CompoundSymMatrixSpace::comp_spaces_
std::vector< std::vector< SmartPtr< const MatrixSpace > > > comp_spaces_
2-dim std::vector of matrix spaces for the components.
Definition: IpCompoundSymMatrix.hpp:263
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
Ipopt::GetRawPtr
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:570
Ipopt::CompoundSymMatrix::comps_
std::vector< std::vector< SmartPtr< Matrix > > > comps_
Vector of vectors containing the components.
Definition: IpCompoundSymMatrix.hpp:121
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:182
Ipopt::CompoundSymMatrixSpace::GetCompSpace
SmartPtr< const MatrixSpace > GetCompSpace(Index irow, Index jcol) const
Obtain the component MatrixSpace in block row irow and block column jcol.
Definition: IpCompoundSymMatrix.hpp:208
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:70
Ipopt::CompoundSymMatrix::ComputeRowAMaxImpl
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
Ipopt::CompoundSymMatrix::operator=
void operator=(const CompoundSymMatrix &)
Overloaded Equals Operator.
Ipopt::CompoundSymMatrixSpace::CompoundSymMatrixSpace
CompoundSymMatrixSpace()
Default constructor.
Ipopt::CompoundSymMatrix::SetCompNonConst
void SetCompNonConst(Index irow, Index jcol, Matrix &matrix)
Non const version of the same method.
IpSymMatrix.hpp
Ipopt::CompoundSymMatrix::matrices_valid_
bool matrices_valid_
boolean indicating if the compound matrix is in a "valid" state
Definition: IpCompoundSymMatrix.hpp:130
Ipopt::CompoundSymMatrixSpace::block_dim_
std::vector< Index > block_dim_
Vector of the number of rows in each comp column, Since this is symmetric, this is also the number of...
Definition: IpCompoundSymMatrix.hpp:259
Ipopt::CompoundSymMatrixSpace::ncomp_spaces_
Index ncomp_spaces_
Number of components per row and column.
Definition: IpCompoundSymMatrix.hpp:253
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:134
Ipopt::CompoundSymMatrixSpace::GetBlockDim
Index GetBlockDim(Index irow_jcol) const
Get the dimension dim for block row (or column) irow_jcol.
Ipopt::SymMatrix
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:23
Ipopt::CompoundSymMatrixSpace::MakeNewSymMatrix
virtual SymMatrix * MakeNewSymMatrix() const
Overloaded MakeNew method for the SymMatrixSpace base class.
Definition: IpCompoundSymMatrix.hpp:228
Ipopt::CompoundSymMatrix::MultVectorImpl
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
Ipopt::CompoundSymMatrix::const_comps_
std::vector< std::vector< SmartPtr< const Matrix > > > const_comps_
Vector of vectors containing the const components.
Definition: IpCompoundSymMatrix.hpp:124
Ipopt::SymMatrixSpace
SymMatrixSpace base class, corresponding to the SymMatrix base class.
Definition: IpSymMatrix.hpp:81
Ipopt::CompoundSymMatrixSpace::SetBlockDim
void SetBlockDim(Index irow_jcol, Index dim)
Set the dimension dim for block row (or column) irow_jcol.
Ipopt::IsValid
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:589
Ipopt::CompoundSymMatrix::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.
Ipopt::IsNull
bool IsNull(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:595
Ipopt::CompoundSymMatrix::ConstComp
const Matrix * ConstComp(Index irow, Index jcol) const
Internal method to return a const pointer to one of the comps.
Definition: IpCompoundSymMatrix.hpp:136
Ipopt::CompoundSymMatrixSpace::~CompoundSymMatrixSpace
~CompoundSymMatrixSpace()
Destructor.
Definition: IpCompoundSymMatrix.hpp:182
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
Ipopt::CompoundSymMatrix::~CompoundSymMatrix
~CompoundSymMatrix()
Destructor.
Ipopt::CompoundSymMatrixSpace::operator=
CompoundSymMatrixSpace & operator=(const CompoundSymMatrixSpace &)
Overloaded Equals Operator.
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:47
Ipopt::CompoundSymMatrix::HasValidNumbersImpl
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Ipopt::CompoundSymMatrix::Comp
Matrix * Comp(Index irow, Index jcol)
Internal method to return a non-const pointer to one of the comps.
Definition: IpCompoundSymMatrix.hpp:151