Ipopt  3.12.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 2269 2013-05-05 11:32:40Z stefan $
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
bool matrices_valid_
boolean indicating if the compound matrix is in a &quot;valid&quot; state
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:579
Number * x
Input: Starting point Output: Optimal solution.
bool dimensions_set_
boolean indicating if the compound matrix space is in a &quot;valid&quot; state
std::vector< std::vector< SmartPtr< const Matrix > > > const_comps_
Vector of vectors containing the const components.
std::vector< std::vector< bool > > allocate_block_
2-dim std::vector of booleans deciding whether to allocate a new matrix for the blocks automagically ...
bool DimensionsSet() const
Method to check whether or not the spaces are valid.
SmartPtr< Matrix > GetCompNonConst(Index irow, Index jcol)
Non const version of GetComp.
Matrix * Comp(Index irow, Index jcol)
Internal method to return a non-const pointer to one of the comps.
~CompoundSymMatrix()
Destructor.
void SetCompNonConst(Index irow, Index jcol, Matrix &matrix)
Non const version of the same method.
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Vector Base Class.
Definition: IpVector.hpp:47
bool IsNull(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:585
CompoundSymMatrix * MakeNewCompoundSymMatrix() const
Method for creating a new matrix of this specific type.
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...
CompoundSymMatrix()
Default Constructor.
SmartPtr< const Matrix > GetComp(Index irow, Index jcol) const
Method for retrieving one block from the compound matrix.
const Matrix * ConstComp(Index irow, Index jcol) const
Internal method to return a const pointer to one of the comps.
EJournalLevel
Print Level Enum.
bool MatricesValid() const
method to check wether or not the matrices are valid
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Class for symmetric matrices consisting of other matrices.
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:23
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Index NComps_Dim() const
Number of block rows and columns.
CompoundSymMatrixSpace()
Default constructor.
void SetBlockDim(Index irow_jcol, Index dim)
Set the dimension dim for block row (or column) irow_jcol.
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:560
Matrix Base Class.
Definition: IpMatrix.hpp:27
void SetCompSpace(Index irow, Index jcol, const MatrixSpace &mat_space, bool auto_allocate=false)
Set the component SymMatrixSpace.
Index GetBlockDim(Index irow_jcol) const
Get the dimension dim for block row (or column) irow_jcol.
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:239
SmartPtr< CompoundSymMatrix > MakeNewCompoundSymMatrix() const
Method for creating a new matrix of this specific type.
std::vector< std::vector< SmartPtr< Matrix > > > comps_
Vector of vectors containing the components.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
This is the matrix space for CompoundSymMatrix.
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
virtual SymMatrix * MakeNewSymMatrix() const
Overloaded MakeNew method for the SymMatrixSpace base class.
const CompoundSymMatrixSpace * owner_space_
Copy of the owner_space ptr as a CompoundSymMatrixSpace.
SymMatrixSpace base class, corresponding to the SymMatrix base class.
Definition: IpSymMatrix.hpp:81
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
Index ncomp_spaces_
Number of components per row and column.
Class responsible for all message output.
CompoundSymMatrixSpace & operator=(const CompoundSymMatrixSpace &)
Overloaded Equals Operator.
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.
void SetComp(Index irow, Index jcol, const Matrix &matrix)
Method for setting an individual component at position (irow, icol) in the compound matrix...
void operator=(const CompoundSymMatrix &)
Overloaded Equals Operator.
EJournalCategory
Category Selection Enum.
std::vector< std::vector< SmartPtr< const MatrixSpace > > > comp_spaces_
2-dim std::vector of matrix spaces for the components.
SmartPtr< const MatrixSpace > GetCompSpace(Index irow, Index jcol) const
Obtain the component MatrixSpace in block row irow and block column jcol.