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

- File List
- File Members

# /home/coin/SVN-release/Clp-1.5.0/CoinUtils/src/CoinPackedVectorBase.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2000, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 #ifndef CoinPackedVectorBase_H
    00004 #define CoinPackedVectorBase_H
    00005
    00006 #if defined(_MSC_VER)
    00007 // Turn off compiler warning about long names
    00008 #  pragma warning(disable:4786)
    00009 #endif
    00010
    00011 #include <set>
    00012 #include <map>
    00013 #include "CoinError.hpp"
    00014 #include "CoinFloatEqual.hpp"
    00015
    00016 class CoinPackedVector;
    00017
    00025 class CoinPackedVectorBase  {
    00026
    00027 public:
    00030
    00031    virtual int getNumElements() const = 0;
    00033    virtual const int * getIndices() const = 0;
    00035    virtual const double * getElements() const = 0;
    00037
    00053    void setTestForDuplicateIndex(bool test) const;
    00062    void setTestForDuplicateIndexWhenTrue(bool test) const;
    00065    bool testForDuplicateIndex() const { return testForDuplicateIndex_; }
    00067
    00075    double * denseVector(int denseSize) const;
    00083    double operator[](int i) const;
    00085
    00088
    00089    int getMaxIndex() const;
    00091    int getMinIndex() const;
    00092
    00094    void duplicateIndex(const char* methodName = NULL,
    00095                        const char * className = NULL) const;
    00096
    00099    bool isExistingIndex(int i) const;
    00100
    00103    int findIndex(int i) const;
    00104
    00106
    00111    bool operator==(const CoinPackedVectorBase & rhs) const;
    00113    bool operator!=(const CoinPackedVectorBase & rhs) const;
    00114
    00122    template <class FloatEqual> bool
    00123    isEquivalent(const CoinPackedVectorBase& rhs, const FloatEqual& eq) const
    00124    {
    00125       if (getNumElements() != rhs.getNumElements())
    00126          return false;
    00127
    00128       duplicateIndex("equivalent", "CoinPackedVector");
    00129       rhs.duplicateIndex("equivalent", "CoinPackedVector");
    00130
    00131       std::map<int,double> mv;
    00132       const int * inds = getIndices();
    00133       const double * elems = getElements();
    00134       int i;
    00135       for ( i = getNumElements() - 1; i >= 0; --i) {
    00136          mv.insert(std::make_pair(inds[i], elems[i]));
    00137       }
    00138
    00139       std::map<int,double> mvRhs;
    00140       inds = rhs.getIndices();
    00141       elems = rhs.getElements();
    00142       for ( i = getNumElements() - 1; i >= 0; --i) {
    00143          mvRhs.insert(std::make_pair(inds[i], elems[i]));
    00144       }
    00145
    00146       std::map<int,double>::const_iterator mvI = mv.begin();
    00147       std::map<int,double>::const_iterator mvIlast = mv.end();
    00148       std::map<int,double>::const_iterator mvIrhs = mvRhs.begin();
    00149       while (mvI != mvIlast) {
    00150          if (mvI->first != mvIrhs->first || ! eq(mvI->second, mvIrhs->second))
    00151             return false;
    00152          ++mvI;
    00153          ++mvIrhs;
    00154       }
    00155       return true;
    00156    }
    00157    bool isEquivalent(const CoinPackedVectorBase& rhs) const
    00158    {
    00159       return isEquivalent(rhs,  CoinRelFltEq());
    00160    }
    00162
    00163
    00166
    00167    double dotProduct(const double* dense) const;
    00168
    00170    double oneNorm() const;
    00171
    00173    double normSquare() const;
    00174
    00176    inline double twoNorm() const { return sqrt(normSquare()); }
    00177
    00179    double infNorm() const;
    00180
    00182    double sum() const;
    00184
    00185 protected:
    00186
    00192    CoinPackedVectorBase();
    00193
    00194 public:
    00196    virtual ~CoinPackedVectorBase();
    00198
    00199 private:
    00208    CoinPackedVectorBase(const CoinPackedVectorBase&);
    00211    CoinPackedVectorBase& operator=(const CoinPackedVectorBase&);
    00213
    00214 protected:
    00215
    00218
    00219    void findMaxMinIndices() const;
    00220
    00222    std::set<int> * indexSet(const char* methodName = NULL,
    00223                             const char * className = NULL) const;
    00224
    00226    void clearIndexSet() const;
    00227    void clearBase() const;
    00228    void copyMaxMinIndex(const CoinPackedVectorBase & x) const {
    00229       maxIndex_ = x.maxIndex_;
    00230       minIndex_ = x.minIndex_;
    00231    }
    00233
    00234 private:
    00237
    00238    mutable int maxIndex_;
    00240    mutable int minIndex_;
    00244    mutable std::set<int> * indexSetPtr_;
    00247    mutable bool testForDuplicateIndex_;
    00250    mutable bool testedDuplicateIndex_;
    00252 };
    00253
    00254 #endif