00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __IPCOMPOUNDSYMMATRIX_HPP__
00010 #define __IPCOMPOUNDSYMMATRIX_HPP__
00011
00012 #include "IpUtils.hpp"
00013 #include "IpSymMatrix.hpp"
00014
00015 namespace Ipopt
00016 {
00017
00018
00019 class CompoundSymMatrixSpace;
00020
00024 class CompoundSymMatrix : public SymMatrix
00025 {
00026 public:
00027
00030
00036 CompoundSymMatrix(const CompoundSymMatrixSpace* owner_space);
00037
00039 ~CompoundSymMatrix();
00041
00046 void SetComp(Index irow, Index jcol, const Matrix& matrix);
00047
00049 void SetCompNonConst(Index irow, Index jcol, Matrix& matrix);
00050
00054 SmartPtr<const Matrix> GetComp(Index irow, Index jcol) const
00055 {
00056 return ConstComp(irow,jcol);
00057 }
00058
00062 SmartPtr<Matrix> GetCompNonConst(Index irow, Index jcol)
00063 {
00064 ObjectChanged();
00065 return Comp(irow,jcol);
00066 }
00067
00069 SmartPtr<CompoundSymMatrix> MakeNewCompoundSymMatrix() const;
00070
00071
00072
00073
00074
00075
00076
00077
00079 Index NComps_Dim() const;
00080
00081 protected:
00084 virtual void MultVectorImpl(Number alpha, const Vector& x,
00085 Number beta, Vector& y) const;
00086
00089 virtual bool HasValidNumbersImpl() const;
00090
00091 virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
00092
00093 virtual void PrintImpl(const Journalist& jnlst,
00094 EJournalLevel level,
00095 EJournalCategory category,
00096 const std::string& name,
00097 Index indent,
00098 const std::string& prefix) const;
00100
00101 private:
00111 CompoundSymMatrix();
00112
00114 CompoundSymMatrix(const CompoundSymMatrix&);
00115
00117 void operator=(const CompoundSymMatrix&);
00119
00121 std::vector<std::vector<SmartPtr<Matrix> > > comps_;
00122
00124 std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
00125
00127 const CompoundSymMatrixSpace* owner_space_;
00128
00130 mutable bool matrices_valid_;
00131
00133 bool MatricesValid() const;
00134
00136 const Matrix* ConstComp(Index irow, Index jcol) const
00137 {
00138 DBG_ASSERT(irow < NComps_Dim());
00139 DBG_ASSERT(jcol <= irow);
00140 if (IsValid(comps_[irow][jcol])) {
00141 return GetRawPtr(comps_[irow][jcol]);
00142 }
00143 else if (IsValid(const_comps_[irow][jcol])) {
00144 return GetRawPtr(const_comps_[irow][jcol]);
00145 }
00146
00147 return NULL;
00148 }
00149
00151 Matrix* Comp(Index irow, Index jcol)
00152 {
00153 DBG_ASSERT(irow < NComps_Dim());
00154 DBG_ASSERT(jcol <= irow);
00155
00156
00157 DBG_ASSERT(IsNull(const_comps_[irow][jcol]));
00158 if (IsValid(comps_[irow][jcol])) {
00159 return GetRawPtr(comps_[irow][jcol]);
00160 }
00161
00162 return NULL;
00163 }
00164 };
00165
00171 class CompoundSymMatrixSpace : public SymMatrixSpace
00172 {
00173 public:
00179 CompoundSymMatrixSpace(Index ncomp_spaces, Index total_dim);
00180
00182 ~CompoundSymMatrixSpace()
00183 {}
00185
00189 void SetBlockDim(Index irow_jcol, Index dim);
00190
00192 Index GetBlockDim(Index irow_jcol) const;
00193
00200 void SetCompSpace(Index irow, Index jcol,
00201 const MatrixSpace& mat_space,
00202 bool auto_allocate = false);
00204
00208 SmartPtr<const MatrixSpace> GetCompSpace(Index irow, Index jcol) const
00209 {
00210 DBG_ASSERT(irow<ncomp_spaces_);
00211 DBG_ASSERT(jcol<=irow);
00212 return comp_spaces_[irow][jcol];
00213 }
00214
00217 Index NComps_Dim() const
00218 {
00219 return ncomp_spaces_;
00220 }
00222
00224 CompoundSymMatrix* MakeNewCompoundSymMatrix() const;
00225
00228 virtual SymMatrix* MakeNewSymMatrix() const
00229 {
00230 return MakeNewCompoundSymMatrix();
00231 }
00232
00233 private:
00243 CompoundSymMatrixSpace();
00244
00246 CompoundSymMatrixSpace(const CompoundSymMatrix&);
00247
00249 CompoundSymMatrixSpace& operator=(const CompoundSymMatrixSpace&);
00251
00253 Index ncomp_spaces_;
00254
00259 std::vector<Index> block_dim_;
00260
00263 std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
00264
00267 std::vector<std::vector< bool > > allocate_block_;
00268
00270 mutable bool dimensions_set_;
00271
00273 bool DimensionsSet() const;
00274 };
00275
00276 inline
00277 SmartPtr<CompoundSymMatrix> CompoundSymMatrix::MakeNewCompoundSymMatrix() const
00278 {
00279 return owner_space_->MakeNewCompoundSymMatrix();
00280 }
00281
00282 }
00283 #endif