/home/coin/SVN-release/CoinAll-1.1.0/Ipopt/src/LinAlg/IpDenseVector.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: IpDenseVector.hpp 920 2007-03-04 17:34:28Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPDENSEVECTOR_HPP__
00010 #define __IPDENSEVECTOR_HPP__
00011 
00012 #include "IpUtils.hpp"
00013 #include "IpVector.hpp"
00014 
00015 namespace Ipopt
00016 {
00017 
00018   /* forward declarations */
00019   class DenseVectorSpace;
00020 
00034   class DenseVector : public Vector
00035   {
00036   public:
00037 
00042     DenseVector(const DenseVectorSpace* owner_space);
00043 
00046     virtual ~DenseVector();
00048 
00052     SmartPtr<DenseVector> MakeNewDenseVector() const;
00053 
00055     void SetValues(const Number *x);
00056 
00062     inline Number* Values();
00063 
00072     inline const Number* Values() const;
00073 
00077     const Number* ExpandedValues() const;
00078 
00081     inline Number* ExpandedValues()
00082     {
00083       return Values();
00084     }
00085 
00088     bool IsHomogeneous() const
00089     {
00090       return homogeneous_;
00091     }
00092 
00094     Number Scalar() const
00095     {
00096       DBG_ASSERT(homogeneous_);
00097       return scalar_;
00098     }
00100 
00106     void CopyToPos(Index Pos, const Vector& x);
00110     void CopyFromPos(Index Pos, Vector& x) const;
00112 
00113   protected:
00117     virtual void CopyImpl(const Vector& x);
00118 
00120     virtual void ScalImpl(Number alpha);
00121 
00123     virtual void AxpyImpl(Number alpha, const Vector &x);
00124 
00126     virtual Number DotImpl(const Vector &x) const;
00127 
00129     virtual Number Nrm2Impl() const;
00130 
00132     virtual Number AsumImpl() const;
00133 
00135     virtual Number AmaxImpl() const;
00136 
00138     virtual void SetImpl(Number value);
00139 
00141     virtual void ElementWiseDivideImpl(const Vector& x);
00142 
00144     virtual void ElementWiseMultiplyImpl(const Vector& x);
00145 
00147     virtual void ElementWiseMaxImpl(const Vector& x);
00148 
00150     virtual void ElementWiseMinImpl(const Vector& x);
00151 
00153     virtual void ElementWiseReciprocalImpl();
00154 
00156     virtual void ElementWiseAbsImpl();
00157 
00159     virtual void ElementWiseSqrtImpl();
00160 
00162     virtual void ElementWiseSgnImpl();
00163 
00165     virtual void AddScalarImpl(Number scalar);
00166 
00168     virtual Number MaxImpl() const;
00169 
00171     virtual Number MinImpl() const;
00172 
00174     virtual Number SumImpl() const;
00175 
00177     virtual Number SumLogsImpl() const;
00178 
00183     void AddTwoVectorsImpl(Number a, const Vector& v1,
00184                            Number b, const Vector& v2, Number c);
00186     Number FracToBoundImpl(const Vector& delta, Number tau) const;
00188     void AddVectorQuotientImpl(Number a, const Vector& z, const Vector& s,
00189                                Number c);
00191 
00194     /* Print the entire vector with padding */
00195     virtual void PrintImpl(const Journalist& jnlst,
00196                            EJournalLevel level,
00197                            EJournalCategory category,
00198                            const std::string& name,
00199                            Index indent,
00200                            const std::string& prefix) const;
00202 
00203   private:
00213     DenseVector();
00214 
00216     DenseVector(const DenseVector&);
00217 
00219     void operator=(const DenseVector&);
00221 
00225     const DenseVectorSpace* owner_space_;
00226 
00228     Number* values_;
00229 
00231     mutable Number* expanded_values_;
00232 
00235     Number* values_allocated();
00236 
00239     bool initialized_;
00240 
00245     bool homogeneous_;
00246 
00249     Number scalar_;
00250 
00253     void set_values_from_scalar();
00254   };
00255 
00258   class DenseVectorSpace : public VectorSpace
00259   {
00260   public:
00266     DenseVectorSpace(Index dim)
00267         :
00268         VectorSpace(dim)
00269     {}
00270 
00272     ~DenseVectorSpace()
00273     {}
00275 
00277     DenseVector* MakeNewDenseVector() const
00278     {
00279       return new DenseVector(this);
00280     }
00281 
00285     virtual Vector* MakeNew() const
00286     {
00287       return MakeNewDenseVector();
00288     }
00289 
00296     Number* AllocateInternalStorage() const;
00297 
00299     void FreeInternalStorage(Number* values) const;
00301   };
00302 
00303   // inline functions
00304   inline Number* DenseVector::Values()
00305   {
00306     // Here we assume that every time someone requests this direct raw
00307     // pointer, the data is going to change and the Tag for this
00308     // vector has to be updated.
00309 
00310     if (initialized_ && homogeneous_) {
00311       // If currently the vector is a homogeneous vector, set all elements
00312       // explicitly to this value
00313       set_values_from_scalar();
00314     }
00315     ObjectChanged();
00316     initialized_= true;
00317     homogeneous_ = false;
00318     return values_allocated();
00319   }
00320 
00321   inline const Number* DenseVector::Values() const
00322   {
00323     DBG_ASSERT(initialized_ && (Dim()==0 || values_));
00324     return values_;
00325   }
00326 
00327   inline Number* DenseVector::values_allocated()
00328   {
00329     if (values_==NULL) {
00330       values_ = owner_space_->AllocateInternalStorage();
00331     }
00332     return values_;
00333   }
00334 
00335   inline
00336   Number* DenseVectorSpace::AllocateInternalStorage() const
00337   {
00338     if (Dim()>0) {
00339       return new Number[Dim()];
00340     }
00341     else {
00342       return NULL;
00343     }
00344   }
00345 
00346   inline
00347   void DenseVectorSpace::FreeInternalStorage(Number* values) const
00348   {
00349     delete [] values;
00350   }
00351 
00352   inline
00353   SmartPtr<DenseVector> DenseVector::MakeNewDenseVector() const
00354   {
00355     return owner_space_->MakeNewDenseVector();
00356   }
00357 
00358 } // namespace Ipopt
00359 #endif

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