- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/SVN-release/Ipopt-3.2.1/Ipopt/src/LinAlg/IpCompoundSymMatrix.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2004, 2006 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Common Public License.
    00004 //
    00005 // $Id: IpCompoundSymMatrix.hpp 759 2006-07-07 03:07:08Z andreasw $
    00006 //
    00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
    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   /* forward declarations */
    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     // The following don't seem to be necessary
    00072     /* Number of block rows of this compound matrix. */
    00073     //    Index NComps_NRows() const { return NComps_Dim(); }
    00074
    00075     /* Number of block colmuns of this compound matrix. */
    00076     //    Index NComps_NCols() const { return NComps_Dim(); }
    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 PrintImpl(const Journalist& jnlst,
    00092                            EJournalLevel level,
    00093                            EJournalCategory category,
    00094                            const std::string& name,
    00095                            Index indent,
    00096                            const std::string& prefix) const;
    00098
    00099   private:
    00109     CompoundSymMatrix();
    00110
    00112     CompoundSymMatrix(const CompoundSymMatrix&);
    00113
    00115     void operator=(const CompoundSymMatrix&);
    00117
    00119     std::vector<std::vector<SmartPtr<Matrix> > > comps_;
    00120
    00122     std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
    00123
    00125     const CompoundSymMatrixSpace* owner_space_;
    00126
    00128     mutable bool matrices_valid_;
    00129
    00131     bool MatricesValid() const;
    00132
    00134     const Matrix* ConstComp(Index irow, Index jcol) const
    00135     {
    00136       DBG_ASSERT(irow < NComps_Dim());
    00137       DBG_ASSERT(jcol <= irow);
    00138       if (IsValid(comps_[irow][jcol])) {
    00139         return GetRawPtr(comps_[irow][jcol]);
    00140       }
    00141       else if (IsValid(const_comps_[irow][jcol])) {
    00142         return GetRawPtr(const_comps_[irow][jcol]);
    00143       }
    00144
    00145       return NULL;
    00146     }
    00147
    00149     Matrix* Comp(Index irow, Index jcol)
    00150     {
    00151       DBG_ASSERT(irow < NComps_Dim());
    00152       DBG_ASSERT(jcol <= irow);
    00153       // We shouldn't be asking for a non-const if this entry holds a
    00154       // const one...
    00155       DBG_ASSERT(IsNull(const_comps_[irow][jcol]));
    00156       if (IsValid(comps_[irow][jcol])) {
    00157         return GetRawPtr(comps_[irow][jcol]);
    00158       }
    00159
    00160       return NULL;
    00161     }
    00162   };
    00163
    00169   class CompoundSymMatrixSpace : public SymMatrixSpace
    00170   {
    00171   public:
    00177     CompoundSymMatrixSpace(Index ncomp_spaces, Index total_dim);
    00178
    00180     ~CompoundSymMatrixSpace()
    00181     {}
    00183
    00187     void SetBlockDim(Index irow_jcol, Index dim);
    00188
    00190     Index GetBlockDim(Index irow_jcol) const;
    00191
    00198     void SetCompSpace(Index irow, Index jcol,
    00199                       const MatrixSpace& mat_space,
    00200                       bool auto_allocate = false);
    00202
    00206     SmartPtr<const MatrixSpace> GetCompSpace(Index irow, Index jcol) const
    00207     {
    00208       DBG_ASSERT(irow<ncomp_spaces_);
    00209       DBG_ASSERT(jcol<=irow);
    00210       return comp_spaces_[irow][jcol];
    00211     }
    00212
    00215     Index NComps_Dim() const
    00216     {
    00217       return ncomp_spaces_;
    00218     }
    00220
    00222     CompoundSymMatrix* MakeNewCompoundSymMatrix() const;
    00223
    00226     virtual SymMatrix* MakeNewSymMatrix() const
    00227     {
    00228       return MakeNewCompoundSymMatrix();
    00229     }
    00230
    00231   private:
    00241     CompoundSymMatrixSpace();
    00242
    00244     CompoundSymMatrixSpace(const CompoundSymMatrix&);
    00245
    00247     CompoundSymMatrixSpace& operator=(const CompoundSymMatrixSpace&);
    00249
    00251     Index ncomp_spaces_;
    00252
    00257     std::vector<Index> block_dim_;
    00258
    00261     std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
    00262
    00265     std::vector<std::vector< bool > > allocate_block_;
    00266
    00268     mutable bool dimensions_set_;
    00269
    00271     bool DimensionsSet() const;
    00272   };
    00273
    00274   inline
    00275   SmartPtr<CompoundSymMatrix> CompoundSymMatrix::MakeNewCompoundSymMatrix() const
    00276   {
    00277     return owner_space_->MakeNewCompoundSymMatrix();
    00278   }
    00279
    00280 } // namespace Ipopt
    00281 #endif