- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Vol-1.2.0/CoinUtils/src/CoinPackedVectorBase.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinPackedVectorBase.hpp 1191 2009-07-25 08:38:12Z forrest $ */
    00002 // Copyright (C) 2000, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 #ifndef CoinPackedVectorBase_H
    00005 #define CoinPackedVectorBase_H
    00006
    00007 #if defined(_MSC_VER)
    00008 // Turn off compiler warning about long names
    00009 #  pragma warning(disable:4786)
    00010 #endif
    00011
    00012 #include <set>
    00013 #include <map>
    00014 #include "CoinError.hpp"
    00015 #include "CoinFloatEqual.hpp"
    00016
    00017 class CoinPackedVector;
    00018
    00026 class CoinPackedVectorBase  {
    00027
    00028 public:
    00031
    00032    virtual int getNumElements() const = 0;
    00034    virtual const int * getIndices() const = 0;
    00036    virtual const double * getElements() const = 0;
    00038
    00054    void setTestForDuplicateIndex(bool test) const;
    00063    void setTestForDuplicateIndexWhenTrue(bool test) const;
    00066    bool testForDuplicateIndex() const { return testForDuplicateIndex_; }
    00068    inline void setTestsOff() const
    00069    { testForDuplicateIndex_=false; testedDuplicateIndex_=false;}
    00071
    00079    double * denseVector(int denseSize) const;
    00087    double operator[](int i) const;
    00089
    00092
    00093    int getMaxIndex() const;
    00095    int getMinIndex() const;
    00096
    00098    void duplicateIndex(const char* methodName = NULL,
    00099                        const char * className = NULL) const;
    00100
    00103    bool isExistingIndex(int i) const;
    00104
    00107    int findIndex(int i) const;
    00108
    00110
    00115    bool operator==(const CoinPackedVectorBase & rhs) const;
    00117    bool operator!=(const CoinPackedVectorBase & rhs) const;
    00118
    00119 #if 0
    00120    // LL: This should be implemented eventually. It is useful to have.
    00124    int lexCompare(const CoinPackedVectorBase& rhs);
    00125 #endif
    00126
    00133    int compare(const CoinPackedVectorBase& rhs) const;
    00134
    00142    template <class FloatEqual> bool
    00143    isEquivalent(const CoinPackedVectorBase& rhs, const FloatEqual& eq) const
    00144    {
    00145       if (getNumElements() != rhs.getNumElements())
    00146          return false;
    00147
    00148       duplicateIndex("equivalent", "CoinPackedVector");
    00149       rhs.duplicateIndex("equivalent", "CoinPackedVector");
    00150
    00151       std::map<int,double> mv;
    00152       const int * inds = getIndices();
    00153       const double * elems = getElements();
    00154       int i;
    00155       for ( i = getNumElements() - 1; i >= 0; --i) {
    00156          mv.insert(std::make_pair(inds[i], elems[i]));
    00157       }
    00158
    00159       std::map<int,double> mvRhs;
    00160       inds = rhs.getIndices();
    00161       elems = rhs.getElements();
    00162       for ( i = getNumElements() - 1; i >= 0; --i) {
    00163          mvRhs.insert(std::make_pair(inds[i], elems[i]));
    00164       }
    00165
    00166       std::map<int,double>::const_iterator mvI = mv.begin();
    00167       std::map<int,double>::const_iterator mvIlast = mv.end();
    00168       std::map<int,double>::const_iterator mvIrhs = mvRhs.begin();
    00169       while (mvI != mvIlast) {
    00170          if (mvI->first != mvIrhs->first || ! eq(mvI->second, mvIrhs->second))
    00171             return false;
    00172          ++mvI;
    00173          ++mvIrhs;
    00174       }
    00175       return true;
    00176    }
    00177    bool isEquivalent(const CoinPackedVectorBase& rhs) const
    00178    {
    00179       return isEquivalent(rhs,  CoinRelFltEq());
    00180    }
    00182
    00183
    00186
    00187    double dotProduct(const double* dense) const;
    00188
    00190    double oneNorm() const;
    00191
    00193    double normSquare() const;
    00194
    00196    inline double twoNorm() const { return sqrt(normSquare()); }
    00197
    00199    double infNorm() const;
    00200
    00202    double sum() const;
    00204
    00205 protected:
    00206
    00212    CoinPackedVectorBase();
    00213
    00214 public:
    00216    virtual ~CoinPackedVectorBase();
    00218
    00219 private:
    00228    CoinPackedVectorBase(const CoinPackedVectorBase&);
    00231    CoinPackedVectorBase& operator=(const CoinPackedVectorBase&);
    00233
    00234 protected:
    00235
    00238
    00239    void findMaxMinIndices() const;
    00240
    00242    std::set<int> * indexSet(const char* methodName = NULL,
    00243                             const char * className = NULL) const;
    00244
    00246    void clearIndexSet() const;
    00247    void clearBase() const;
    00248    void copyMaxMinIndex(const CoinPackedVectorBase & x) const {
    00249       maxIndex_ = x.maxIndex_;
    00250       minIndex_ = x.minIndex_;
    00251    }
    00253
    00254 private:
    00257
    00258    mutable int maxIndex_;
    00260    mutable int minIndex_;
    00264    mutable std::set<int> * indexSetPtr_;
    00267    mutable bool testForDuplicateIndex_;
    00270    mutable bool testedDuplicateIndex_;
    00272 };
    00273
    00274 #endif