/home/coin/SVN-release/CoinAll-1.1.0/Ipopt/src/LinAlg/IpCompoundVector.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: IpCompoundVector.hpp 735 2006-06-04 06:10:05Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPCOMPOUNDVECTOR_HPP__
00010 #define __IPCOMPOUNDVECTOR_HPP__
00011 
00012 #include "IpUtils.hpp"
00013 #include "IpVector.hpp"
00014 #include <vector>
00015 
00016 namespace Ipopt
00017 {
00018 
00019   /* forward declarations */
00020   class CompoundVectorSpace;
00021 
00030   class CompoundVector : public Vector
00031   {
00032   public:
00045     CompoundVector(const CompoundVectorSpace* owner_space, bool create_new);
00046 
00048     virtual ~CompoundVector();
00050 
00054     void SetComp(Index icomp, const Vector& vec);
00055 
00059     void SetCompNonConst(Index icomp, Vector& vec);
00060 
00062     inline Index NComps() const;
00063 
00065     bool IsCompConst(Index i) const
00066     {
00067       DBG_ASSERT(i > 0 && i < NComps());
00068       DBG_ASSERT(IsValid(comps_[i]) || IsValid(const_comps_[i]));
00069       if (IsValid(const_comps_[i])) {
00070         return true;
00071       }
00072       return false;
00073     }
00074 
00076     bool IsCompNull(Index i) const
00077     {
00078       DBG_ASSERT(i >= 0 && i < NComps());
00079       if (IsValid(comps_[i]) || IsValid(const_comps_[i])) {
00080         return false;
00081       }
00082       return true;
00083     }
00084 
00086     SmartPtr<const Vector> GetComp(Index i) const
00087     {
00088       return ConstComp(i);
00089     }
00090 
00096     SmartPtr<Vector> GetCompNonConst(Index i)
00097     {
00098       ObjectChanged();
00099       return Comp(i);
00100     }
00101 
00102   protected:
00106     virtual void CopyImpl(const Vector& x);
00107 
00109     virtual void ScalImpl(Number alpha);
00110 
00112     virtual void AxpyImpl(Number alpha, const Vector &x);
00113 
00115     virtual Number DotImpl(const Vector &x) const;
00116 
00118     virtual Number Nrm2Impl() const;
00119 
00121     virtual Number AsumImpl() const;
00122 
00124     virtual Number AmaxImpl() const;
00125 
00127     virtual void SetImpl(Number value);
00128 
00130     virtual void ElementWiseDivideImpl(const Vector& x);
00131 
00133     virtual void ElementWiseMultiplyImpl(const Vector& x);
00134 
00136     virtual void ElementWiseMaxImpl(const Vector& x);
00137 
00139     virtual void ElementWiseMinImpl(const Vector& x);
00140 
00142     virtual void ElementWiseReciprocalImpl();
00143 
00145     virtual void ElementWiseAbsImpl();
00146 
00148     virtual void ElementWiseSqrtImpl();
00149 
00151     virtual void ElementWiseSgnImpl();
00152 
00154     virtual void AddScalarImpl(Number scalar);
00155 
00157     virtual Number MaxImpl() const;
00158 
00160     virtual Number MinImpl() const;
00161 
00163     virtual Number SumImpl() const;
00164 
00166     virtual Number SumLogsImpl() const;
00167 
00172     void AddTwoVectorsImpl(Number a, const Vector& v1,
00173                            Number b, const Vector& v2, Number c);
00175     Number FracToBoundImpl(const Vector& delta, Number tau) const;
00177     void AddVectorQuotientImpl(Number a, const Vector& z, const Vector& s,
00178                                Number c);
00180 
00183     virtual bool HasValidNumbersImpl() const;
00184 
00187     /* Print the entire vector with padding */
00188     virtual void PrintImpl(const Journalist& jnlst,
00189                            EJournalLevel level,
00190                            EJournalCategory category,
00191                            const std::string& name,
00192                            Index indent,
00193                            const std::string& prefix) const;
00195 
00196   private:
00207     CompoundVector();
00208 
00210     CompoundVector(const CompoundVector&);
00211 
00213     void operator=(const CompoundVector&);
00215 
00219     std::vector< SmartPtr<Vector> > comps_;
00220     std::vector< SmartPtr<const Vector> > const_comps_;
00221 
00222     const CompoundVectorSpace* owner_space_;
00223 
00224     bool vectors_valid_;
00225 
00226     bool VectorsValid();
00227 
00228     inline const Vector* ConstComp(Index i) const;
00229 
00230     inline Vector* Comp(Index i);
00231   };
00232 
00239   class CompoundVectorSpace : public VectorSpace
00240   {
00241   public:
00246     CompoundVectorSpace(Index ncomp_spaces, Index total_dim);
00247 
00249     ~CompoundVectorSpace()
00250     {}
00252 
00254     virtual void SetCompSpace(Index icomp                   ,
00255                               const VectorSpace& vec_space 
00256                              );
00257 
00259     SmartPtr<const VectorSpace> GetCompSpace(Index icomp) const;
00260 
00262     Index NCompSpaces() const
00263     {
00264       return ncomp_spaces_;
00265     }
00266 
00268     virtual CompoundVector* MakeNewCompoundVector(bool create_new = true) const
00269     {
00270       return new CompoundVector(this, create_new);
00271     }
00272 
00275     virtual Vector* MakeNew() const
00276     {
00277       return MakeNewCompoundVector();
00278     }
00279 
00280   private:
00290     CompoundVectorSpace();
00291 
00293     CompoundVectorSpace(const CompoundVectorSpace&);
00294 
00296     CompoundVectorSpace& operator=(const CompoundVectorSpace&);
00298 
00300     const Index ncomp_spaces_;
00301 
00303     std::vector< SmartPtr<const VectorSpace> > comp_spaces_;
00304   };
00305 
00306   /* inline methods */
00307   inline
00308   Index CompoundVector::NComps() const
00309   {
00310     return owner_space_->NCompSpaces();
00311   }
00312 
00313   inline
00314   const Vector* CompoundVector::ConstComp(Index i) const
00315   {
00316     DBG_ASSERT(i < NComps());
00317     DBG_ASSERT(IsValid(comps_[i]) || IsValid(const_comps_[i]));
00318     if (IsValid(comps_[i])) {
00319       return GetRawPtr(comps_[i]);
00320     }
00321     else if (IsValid(const_comps_[i])) {
00322       return GetRawPtr(const_comps_[i]);
00323     }
00324 
00325     DBG_ASSERT(false && "shouldn't be here");
00326     return NULL;
00327   }
00328 
00329   inline
00330   Vector* CompoundVector::Comp(Index i)
00331   {
00332     DBG_ASSERT(i < NComps());
00333     DBG_ASSERT(IsValid(comps_[i]));
00334     return GetRawPtr(comps_[i]);
00335   }
00336 
00337 } // namespace Ipopt
00338 
00339 #endif

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