/home/coin/SVN-release/CoinAll-1.1.0/Ipopt/src/LinAlg/IpCompoundMatrix.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2007 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpCompoundMatrix.hpp 1001 2007-06-18 20:36:53Z 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     ~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 PrintImpl(const Journalist& jnlst,
00112                            EJournalLevel level,
00113                            EJournalCategory category,
00114                            const std::string& name,
00115                            Index indent,
00116                            const std::string& prefix) const;
00118 
00119   private:
00129     CompoundMatrix();
00130 
00132     CompoundMatrix(const CompoundMatrix&);
00133 
00135     void operator=(const CompoundMatrix&);
00137 
00139     std::vector<std::vector<SmartPtr<Matrix> > > comps_;
00140 
00142     std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
00143 
00146     const CompoundMatrixSpace* owner_space_;
00147 
00149     mutable bool matrices_valid_;
00150 
00152     bool MatricesValid() const;
00153 
00154     inline const Matrix* ConstComp(Index irow, Index jcol) const;
00155 
00156     inline Matrix* Comp(Index irow, Index jcol);
00157   };
00158 
00164   class CompoundMatrixSpace : public MatrixSpace
00165   {
00166   public:
00172     CompoundMatrixSpace(Index ncomps_rows,
00173                         Index ncomps_cols,
00174                         Index total_nRows,
00175                         Index total_nCols);
00176 
00178     ~CompoundMatrixSpace()
00179     {}
00181 
00185     void SetBlockRows(Index irow, Index nrows);
00186 
00188     void SetBlockCols(Index jcol, Index ncols);
00189 
00191     Index GetBlockRows(Index irow) const;
00192 
00194     Index GetBlockCols(Index jcol) const;
00195 
00202     void SetCompSpace(Index irow, Index jcol,
00203                       const MatrixSpace& mat_space,
00204                       bool auto_allocate = false);
00206 
00210     SmartPtr<const MatrixSpace> GetCompSpace(Index irow, Index jcol) const
00211     {
00212       DBG_ASSERT(irow<NComps_Rows());
00213       DBG_ASSERT(jcol<NComps_Cols());
00214       return comp_spaces_[irow][jcol];
00215     }
00216 
00220     Index NComps_Rows() const
00221     {
00222       return ncomps_rows_;
00223     }
00225     Index NComps_Cols() const
00226     {
00227       return ncomps_cols_;
00228     }
00229 
00231     bool Diagonal() const
00232     {
00233       return diagonal_;
00234     }
00236 
00238     CompoundMatrix* MakeNewCompoundMatrix() const;
00239 
00242     virtual Matrix* MakeNew() const
00243     {
00244       return MakeNewCompoundMatrix();
00245     }
00246 
00247   private:
00257     CompoundMatrixSpace();
00258 
00260     CompoundMatrixSpace(const CompoundMatrixSpace&);
00261 
00263     CompoundMatrixSpace& operator=(const CompoundMatrixSpace&);
00265 
00267     Index ncomps_rows_;
00268 
00270     Index ncomps_cols_;
00271 
00273     mutable bool dimensions_set_;
00274 
00276     std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
00277 
00280     std::vector<std::vector< bool > > allocate_block_;
00281 
00283     std::vector<Index> block_rows_;
00284 
00286     std::vector<Index> block_cols_;
00287 
00292     bool diagonal_;
00293 
00296     bool DimensionsSet() const;
00297   };
00298 
00299   /* inline methods */
00300   inline
00301   Index CompoundMatrix::NComps_Rows() const
00302   {
00303     return owner_space_->NComps_Rows();
00304   }
00305 
00306   inline
00307   Index CompoundMatrix::NComps_Cols() const
00308   {
00309     return owner_space_->NComps_Cols();
00310   }
00311 
00312   inline
00313   const Matrix* CompoundMatrix::ConstComp(Index irow, Index jcol) const
00314   {
00315     DBG_ASSERT(irow < NComps_Rows());
00316     DBG_ASSERT(jcol < NComps_Cols());
00317     if (IsValid(comps_[irow][jcol])) {
00318       return GetRawPtr(comps_[irow][jcol]);
00319     }
00320     else if (IsValid(const_comps_[irow][jcol])) {
00321       return GetRawPtr(const_comps_[irow][jcol]);
00322     }
00323 
00324     return NULL;
00325   }
00326 
00327   inline
00328   Matrix* CompoundMatrix::Comp(Index irow, Index jcol)
00329   {
00330     DBG_ASSERT(irow < NComps_Rows());
00331     DBG_ASSERT(jcol < NComps_Cols());
00332     return GetRawPtr(comps_[irow][jcol]);
00333   }
00334 
00335 } // namespace Ipopt
00336 #endif

Generated on Sun Nov 14 14:06:36 2010 for Coin-All by  doxygen 1.4.7