Ipopt Documentation  
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 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPCOMPOUNDSYMMATRIX_HPP__
8 #define __IPCOMPOUNDSYMMATRIX_HPP__
9 
10 #include "IpUtils.hpp"
11 #include "IpSymMatrix.hpp"
12 
13 namespace Ipopt
14 {
15 
16 /* forward declarations */
17 class CompoundSymMatrixSpace;
18 
24 {
25 public:
26 
29 
36  const CompoundSymMatrixSpace* owner_space
37  );
38 
42 
50  void SetComp(
51  Index irow,
52  Index jcol,
53  const Matrix& matrix
54  );
55 
58  Index irow,
59  Index jcol,
60  Matrix& matrix
61  );
62 
69  Index irow,
70  Index jcol
71  ) const
72  {
73  return ConstComp(irow, jcol);
74  }
75 
83  Index irow,
84  Index jcol
85  )
86  {
87  ObjectChanged();
88  return Comp(irow, jcol);
89  }
90 
92  SmartPtr<CompoundSymMatrix> MakeNewCompoundSymMatrix() const;
93 
94  // The following don't seem to be necessary
95  /* Number of block rows of this compound matrix. */
96  // Index NComps_NRows() const { return NComps_Dim(); }
97  /* Number of block colmuns of this compound matrix. */
98  // Index NComps_NCols() const { return NComps_Dim(); }
99 
101  Index NComps_Dim() const;
102 
103 protected:
106  virtual void MultVectorImpl(
107  Number alpha,
108  const Vector& x,
109  Number beta,
110  Vector& y
111  ) const;
112 
113  virtual bool HasValidNumbersImpl() const;
114 
115  virtual void ComputeRowAMaxImpl(
116  Vector& rows_norms,
117  bool init
118  ) const;
119 
120  virtual void PrintImpl(
121  const Journalist& jnlst,
122  EJournalLevel level,
123  EJournalCategory category,
124  const std::string& name,
125  Index indent,
126  const std::string& prefix
127  ) const;
129 
130 private:
139 
141 
144  const CompoundSymMatrix&
145  );
146 
148  void operator=(
149  const CompoundSymMatrix&
150  );
152 
154  std::vector<std::vector<SmartPtr<Matrix> > > comps_;
155 
157  std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
158 
161 
163  mutable bool matrices_valid_;
164 
166  bool MatricesValid() const;
167 
170  Index irow,
171  Index jcol
172  ) const
173  {
174  DBG_ASSERT(irow < NComps_Dim());
175  DBG_ASSERT(jcol <= irow);
176  if( IsValid(comps_[irow][jcol]) )
177  {
178  return GetRawPtr(comps_[irow][jcol]);
179  }
180  else if( IsValid(const_comps_[irow][jcol]) )
181  {
182  return GetRawPtr(const_comps_[irow][jcol]);
183  }
184 
185  return NULL;
186  }
187 
190  Index irow,
191  Index jcol
192  )
193  {
194  DBG_ASSERT(irow < NComps_Dim());
195  DBG_ASSERT(jcol <= irow);
196  // We shouldn't be asking for a non-const if this entry holds a
197  // const one...
198  DBG_ASSERT(IsNull(const_comps_[irow][jcol]));
199  if( IsValid(comps_[irow][jcol]) )
200  {
201  return GetRawPtr(comps_[irow][jcol]);
202  }
203 
204  return NULL;
205  }
206 };
207 
215 {
216 public:
219 
223  Index ncomp_spaces,
224  Index total_dim
225  );
226 
229  { }
231 
234 
236  Index irow_jcol,
237  Index dim
238  );
239 
242  Index irow_jcol
243  ) const;
244 
254  Index irow,
255  Index jcol,
256  const MatrixSpace& mat_space,
257  bool auto_allocate = false
258  );
260 
265  Index irow,
266  Index jcol
267  ) const
268  {
269  DBG_ASSERT(irow < ncomp_spaces_);
270  DBG_ASSERT(jcol <= irow);
271  return comp_spaces_[irow][jcol];
272  }
273 
277  {
278  return ncomp_spaces_;
279  }
281 
284 
285  virtual SymMatrix* MakeNewSymMatrix() const
286  {
287  return MakeNewCompoundSymMatrix();
288  }
289 
290 private:
299 
301 
304  const CompoundSymMatrix&
305  );
306 
310  );
312 
315 
322  std::vector<Index> block_dim_;
323 
328  std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
329 
333  std::vector<std::vector<bool> > allocate_block_;
334 
336  mutable bool dimensions_set_;
337 
339  bool DimensionsSet() const;
340 };
341 
343 {
345 }
346 
347 } // namespace Ipopt
348 #endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
This is the matrix space for CompoundSymMatrix.
CompoundSymMatrixSpace(const CompoundSymMatrix &)
Copy Constructor.
CompoundSymMatrixSpace()
Default constructor.
Index ncomp_spaces_
Number of components per row and column.
void SetBlockDim(Index irow_jcol, Index dim)
Set the dimension dim for block row (or column) irow_jcol.
bool dimensions_set_
boolean indicating if the compound matrix space is in a "valid" state
CompoundSymMatrixSpace(Index ncomp_spaces, Index total_dim)
Constructor, given the number of blocks (same for rows and columns), as well as the total dimension o...
void SetCompSpace(Index irow, Index jcol, const MatrixSpace &mat_space, bool auto_allocate=false)
Set the component SymMatrixSpace.
std::vector< std::vector< bool > > allocate_block_
2-dim std::vector of booleans deciding whether to allocate a new matrix for the blocks automagically
Index GetBlockDim(Index irow_jcol) const
Get the dimension dim for block row (or column) irow_jcol.
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.
std::vector< Index > block_dim_
Vector of the number of rows in each comp column.
virtual SymMatrix * MakeNewSymMatrix() const
Pure virtual method for creating a new matrix of this specific type.
CompoundSymMatrix * MakeNewCompoundSymMatrix() const
Method for creating a new matrix of this specific type.
bool DimensionsSet() const
Method to check whether or not the spaces are valid.
CompoundSymMatrixSpace & operator=(const CompoundSymMatrixSpace &)
Default Assignment Operator.
Class for symmetric matrices consisting of other matrices.
SmartPtr< CompoundSymMatrix > MakeNewCompoundSymMatrix() const
Method for creating a new matrix of this specific type.
void SetCompNonConst(Index irow, Index jcol, Matrix &matrix)
Non const version of the same method.
Index NComps_Dim() const
Number of block rows and columns.
virtual void ComputeRowAMaxImpl(Vector &rows_norms, bool init) const
Compute the max-norm of the rows in the matrix.
Matrix * Comp(Index irow, Index jcol)
Internal method to return a non-const pointer to one of the comps.
std::vector< std::vector< SmartPtr< const Matrix > > > const_comps_
Vector of vectors containing the const components.
CompoundSymMatrix()
Default Constructor.
virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const
Matrix-vector multiply.
void SetComp(Index irow, Index jcol, const Matrix &matrix)
Method for setting an individual component at position (irow, icol) in the compound matrix.
SmartPtr< Matrix > GetCompNonConst(Index irow, Index jcol)
Non const version of GetComp.
void operator=(const CompoundSymMatrix &)
Default Assignment 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.
std::vector< std::vector< SmartPtr< Matrix > > > comps_
Vector of vectors containing the components.
const CompoundSymMatrixSpace * owner_space_
Copy of the owner_space ptr as a CompoundSymMatrixSpace.
CompoundSymMatrix(const CompoundSymMatrixSpace *owner_space)
Constructor, taking only the number for block components into the row and column direction.
SmartPtr< const Matrix > GetComp(Index irow, Index jcol) const
Method for retrieving one block from the compound matrix.
CompoundSymMatrix(const CompoundSymMatrix &)
Copy Constructor.
bool MatricesValid() const
method to check wether or not the matrices are valid
~CompoundSymMatrix()
Destructor.
const Matrix * ConstComp(Index irow, Index jcol) const
Internal method to return a const pointer to one of the comps.
bool matrices_valid_
boolean indicating if the compound matrix is in a "valid" state
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
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
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
SymMatrixSpace base class, corresponding to the SymMatrix base class.
Definition: IpSymMatrix.hpp:86
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:21
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)
Definition: IpSmartPtr.hpp:674
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
EJournalCategory
Category Selection Enum.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
EJournalLevel
Print Level Enum.
bool IsNull(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:682
double Number
Type of all numbers.
Definition: IpTypes.hpp:15