Ipopt Documentation  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
28 
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:
105  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:
138 
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:
218 
223  Index ncomp_spaces,
224  Index total_dim
225  );
226 
229  { }
231 
233 
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 
275  Index NComps_Dim() const
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:
298 
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
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:674
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.
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.
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
Vector Base Class.
Definition: IpVector.hpp:47
bool IsNull(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:682
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.
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.
Class for symmetric matrices consisting of other matrices.
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:20
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
Matrix Base Class.
Definition: IpMatrix.hpp:27
MatrixSpace base class, corresponding to the Matrix base class.
Definition: IpMatrix.hpp:326
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:17
This is the matrix space for CompoundSymMatrix.
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
virtual SymMatrix * MakeNewSymMatrix() const
Pure virtual method for creating a new matrix of this specific type.
#define IPOPTLIB_EXPORT
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:85
Index ncomp_spaces_
Number of components per row and column.
Class responsible for all message output.
std::vector< std::vector< bool > > allocate_block_
2-dim std::vector of booleans deciding whether to allocate a new matrix for the blocks automagically ...
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.