/build/buildd/coinor-ipopt-3.10.1/Ipopt/src/LinAlg/IpCompoundMatrix.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2004, 2009 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Eclipse Public License.
00004 //
00005 // $Id: IpCompoundMatrix.hpp 1861 2010-12-21 21:34:47Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPCOMPOUNDMATRIX_HPP__
00010 #define __IPCOMPOUNDMATRIX_HPP__
00011 
00012 #include "IpUtils.hpp"
00013 #include "IpMatrix.hpp"
00014 
00015 namespace Ipopt
00016 {
00017 
00018   /* forward declarations */
00019   class CompoundMatrixSpace;
00020 
00034   class CompoundMatrix : public Matrix
00035   {
00036   public:
00037 
00040 
00047     CompoundMatrix(const CompoundMatrixSpace* owner_space);
00048 
00050     virtual ~CompoundMatrix();
00052 
00056     void SetComp(Index irow, Index jcol, const Matrix& matrix);
00057 
00059     void SetCompNonConst(Index irow, Index jcol, Matrix& matrix);
00060 
00062     void CreateBlockFromSpace(Index irow, Index jcol);
00063 
00067     SmartPtr<const Matrix> GetComp(Index irow, Index jcol) const
00068     {
00069       return ConstComp(irow, jcol);
00070     }
00071 
00076     SmartPtr<Matrix> GetCompNonConst(Index irow, Index jcol)
00077     {
00078       ObjectChanged();
00079       return Comp(irow, jcol);
00080     }
00081 
00083     inline Index NComps_Rows() const;
00085     inline Index NComps_Cols() const;
00086 
00087   protected:
00090     virtual void MultVectorImpl(Number alpha, const Vector& x,
00091                                 Number beta, Vector& y) const;
00092 
00093     virtual void TransMultVectorImpl(Number alpha, const Vector& x,
00094                                      Number beta, Vector& y) const;
00095 
00098     virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
00099                                Vector& X) const;
00100 
00103     virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
00104                                     const Vector& R, const Vector& Z,
00105                                     const Vector& D, Vector& X) const;
00106 
00109     virtual bool HasValidNumbersImpl() const;
00110 
00111     virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
00112 
00113     virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const;
00114 
00115     virtual void PrintImpl(const Journalist& jnlst,
00116                            EJournalLevel level,
00117                            EJournalCategory category,
00118                            const std::string& name,
00119                            Index indent,
00120                            const std::string& prefix) const;
00122 
00123   private:
00133     CompoundMatrix();
00134 
00136     CompoundMatrix(const CompoundMatrix&);
00137 
00139     void operator=(const CompoundMatrix&);
00141 
00143     std::vector<std::vector<SmartPtr<Matrix> > > comps_;
00144 
00146     std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
00147 
00150     const CompoundMatrixSpace* owner_space_;
00151 
00153     mutable bool matrices_valid_;
00154 
00156     bool MatricesValid() const;
00157 
00158     inline const Matrix* ConstComp(Index irow, Index jcol) const;
00159 
00160     inline Matrix* Comp(Index irow, Index jcol);
00161   };
00162 
00168   class CompoundMatrixSpace : public MatrixSpace
00169   {
00170   public:
00176     CompoundMatrixSpace(Index ncomps_rows,
00177                         Index ncomps_cols,
00178                         Index total_nRows,
00179                         Index total_nCols);
00180 
00182     ~CompoundMatrixSpace()
00183     {}
00185 
00189     void SetBlockRows(Index irow, Index nrows);
00190 
00192     void SetBlockCols(Index jcol, Index ncols);
00193 
00195     Index GetBlockRows(Index irow) const;
00196 
00198     Index GetBlockCols(Index jcol) const;
00199 
00206     void SetCompSpace(Index irow, Index jcol,
00207                       const MatrixSpace& mat_space,
00208                       bool auto_allocate = false);
00210 
00214     SmartPtr<const MatrixSpace> GetCompSpace(Index irow, Index jcol) const
00215     {
00216       DBG_ASSERT(irow<NComps_Rows());
00217       DBG_ASSERT(jcol<NComps_Cols());
00218       return comp_spaces_[irow][jcol];
00219     }
00220 
00224     Index NComps_Rows() const
00225     {
00226       return ncomps_rows_;
00227     }
00229     Index NComps_Cols() const
00230     {
00231       return ncomps_cols_;
00232     }
00233 
00235     bool Diagonal() const
00236     {
00237       return diagonal_;
00238     }
00240 
00242     CompoundMatrix* MakeNewCompoundMatrix() const;
00243 
00246     virtual Matrix* MakeNew() const
00247     {
00248       return MakeNewCompoundMatrix();
00249     }
00250 
00251   private:
00261     CompoundMatrixSpace();
00262 
00264     CompoundMatrixSpace(const CompoundMatrixSpace&);
00265 
00267     CompoundMatrixSpace& operator=(const CompoundMatrixSpace&);
00269 
00271     Index ncomps_rows_;
00272 
00274     Index ncomps_cols_;
00275 
00277     mutable bool dimensions_set_;
00278 
00280     std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
00281 
00284     std::vector<std::vector< bool > > allocate_block_;
00285 
00287     std::vector<Index> block_rows_;
00288 
00290     std::vector<Index> block_cols_;
00291 
00296     bool diagonal_;
00297 
00300     bool DimensionsSet() const;
00301   };
00302 
00303   /* inline methods */
00304   inline
00305   Index CompoundMatrix::NComps_Rows() const
00306   {
00307     return owner_space_->NComps_Rows();
00308   }
00309 
00310   inline
00311   Index CompoundMatrix::NComps_Cols() const
00312   {
00313     return owner_space_->NComps_Cols();
00314   }
00315 
00316   inline
00317   const Matrix* CompoundMatrix::ConstComp(Index irow, Index jcol) const
00318   {
00319     DBG_ASSERT(irow < NComps_Rows());
00320     DBG_ASSERT(jcol < NComps_Cols());
00321     if (IsValid(comps_[irow][jcol])) {
00322       return GetRawPtr(comps_[irow][jcol]);
00323     }
00324     else if (IsValid(const_comps_[irow][jcol])) {
00325       return GetRawPtr(const_comps_[irow][jcol]);
00326     }
00327 
00328     return NULL;
00329   }
00330 
00331   inline
00332   Matrix* CompoundMatrix::Comp(Index irow, Index jcol)
00333   {
00334     DBG_ASSERT(irow < NComps_Rows());
00335     DBG_ASSERT(jcol < NComps_Cols());
00336     return GetRawPtr(comps_[irow][jcol]);
00337   }
00338 
00339 } // namespace Ipopt
00340 #endif