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 
36  const CompoundSymMatrixSpace* owner_space
37  );
38 
42 
50  void SetComp(
51  Index irow,
52  Index jcol,
53  const Matrix& matrix
54  );
55 
57  void SetCompNonConst(
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:
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:
223  Index ncomp_spaces,
224  Index total_dim
225  );
226 
229  { }
231 
235  void SetBlockDim(
236  Index irow_jcol,
237  Index dim
238  );
239 
241  Index GetBlockDim(
242  Index irow_jcol
243  ) const;
244 
253  void SetCompSpace(
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 
283  CompoundSymMatrix* MakeNewCompoundSymMatrix() const;
284 
285  virtual SymMatrix* MakeNewSymMatrix() const
286  {
287  return MakeNewCompoundSymMatrix();
288  }
289 
290 private:
301 
304  const CompoundSymMatrix&
305  );
306 
308  CompoundSymMatrixSpace& operator=(
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
IpUtils.hpp
Ipopt::CompoundSymMatrix
Class for symmetric matrices consisting of other matrices.
Definition: IpCompoundSymMatrix.hpp:23
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:326
Ipopt::CompoundSymMatrixSpace::dimensions_set_
bool dimensions_set_
boolean indicating if the compound matrix space is in a "valid" state
Definition: IpCompoundSymMatrix.hpp:336
Ipopt::CompoundSymMatrixSpace::NComps_Dim
Index NComps_Dim() const
Definition: IpCompoundSymMatrix.hpp:276
Ipopt
This file contains a base class for all exceptions and a set of macros to help with exceptions.
Definition: IpInexactAlgBuilder.hpp:13
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
Ipopt::Matrix
Matrix Base Class.
Definition: IpMatrix.hpp:27
Ipopt::CompoundSymMatrix::GetComp
SmartPtr< const Matrix > GetComp(Index irow, Index jcol) const
Method for retrieving one block from the compound matrix.
Definition: IpCompoundSymMatrix.hpp:68
Ipopt::CompoundSymMatrix::GetCompNonConst
SmartPtr< Matrix > GetCompNonConst(Index irow, Index jcol)
Non const version of GetComp.
Definition: IpCompoundSymMatrix.hpp:82
Ipopt::CompoundSymMatrixSpace
This is the matrix space for CompoundSymMatrix.
Definition: IpCompoundSymMatrix.hpp:214
Ipopt::CompoundSymMatrix::owner_space_
const CompoundSymMatrixSpace * owner_space_
Copy of the owner_space ptr as a CompoundSymMatrixSpace.
Definition: IpCompoundSymMatrix.hpp:160
Ipopt::CompoundSymMatrix::MakeNewCompoundSymMatrix
SmartPtr< CompoundSymMatrix > MakeNewCompoundSymMatrix() const
Method for creating a new matrix of this specific type.
Definition: IpCompoundSymMatrix.hpp:342
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:31
IPOPTLIB_EXPORT
#define IPOPTLIB_EXPORT
Definition: config_default.h:16
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:328
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
Ipopt::GetRawPtr
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
Ipopt::CompoundSymMatrix::comps_
std::vector< std::vector< SmartPtr< Matrix > > > comps_
Vector of vectors containing the components.
Definition: IpCompoundSymMatrix.hpp:154
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
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:264
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:51
IpSymMatrix.hpp
Ipopt::CompoundSymMatrix::matrices_valid_
bool matrices_valid_
boolean indicating if the compound matrix is in a "valid" state
Definition: IpCompoundSymMatrix.hpp:163
Ipopt::CompoundSymMatrixSpace::block_dim_
std::vector< Index > block_dim_
Vector of the number of rows in each comp column.
Definition: IpCompoundSymMatrix.hpp:322
Ipopt::CompoundSymMatrixSpace::ncomp_spaces_
Index ncomp_spaces_
Number of components per row and column.
Definition: IpCompoundSymMatrix.hpp:314
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:116
Ipopt::SymMatrix
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:20
Ipopt::CompoundSymMatrixSpace::MakeNewSymMatrix
virtual SymMatrix * MakeNewSymMatrix() const
Pure virtual method for creating a new matrix of this specific type.
Definition: IpCompoundSymMatrix.hpp:285
Ipopt::CompoundSymMatrix::const_comps_
std::vector< std::vector< SmartPtr< const Matrix > > > const_comps_
Vector of vectors containing the const components.
Definition: IpCompoundSymMatrix.hpp:157
Ipopt::SymMatrixSpace
SymMatrixSpace base class, corresponding to the SymMatrix base class.
Definition: IpSymMatrix.hpp:85
Ipopt::IsValid
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
Ipopt::IsNull
bool IsNull(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:682
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:169
Ipopt::CompoundSymMatrixSpace::~CompoundSymMatrixSpace
~CompoundSymMatrixSpace()
Destructor.
Definition: IpCompoundSymMatrix.hpp:228
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:28
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:333
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:47
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:189