#include <CoinPackedVectorBase.hpp>
Inheritance diagram for CoinPackedVectorBase:
Constructors, destructor | |
NOTE: All constructors are protected. There's no need to expose them, after all, this is an abstract class. | |
virtual | ~CoinPackedVectorBase () |
CoinPackedVectorBase () | |
Public Member Functions | |
Virtual methods that the derived classes must provide | |
virtual int | getNumElements () const=0 |
Get length of indices and elements vectors. | |
virtual const int * | getIndices () const=0 |
Get indices of elements. | |
virtual const double * | getElements () const=0 |
Get element values. | |
Methods related to whether duplicate-index checking is performed. | |
If the checking for duplicate indices is turned off, then some CoinPackedVector methods may not work correctly if there are duplicate indices. Turning off the checking for duplicate indices may result in better run time performance. | |
void | setTestForDuplicateIndex (bool test) const |
bool | testForDuplicateIndex () const |
Methods for getting info on the packed vector as a full vector | |
double * | denseVector (int denseSize) const throw (CoinError) |
double | operator[] (int i) const throw (CoinError) |
Index methods | |
int | getMaxIndex () const |
Get value of maximum index. | |
int | getMinIndex () const |
Get value of minimum index. | |
void | duplicateIndex (const char *methodName=NULL, const char *className=NULL) const throw (CoinError) |
Throw an exception if there are duplicate indices. | |
bool | isExistingIndex (int i) const |
int | findIndex (int i) const |
Comparison operators on two packed vectors | |
bool | operator== (const CoinPackedVectorBase &rhs) const |
bool | operator!= (const CoinPackedVectorBase &rhs) const |
Not equal. | |
template<class FloatEqual> bool | isEquivalent (const CoinPackedVectorBase &rhs, const FloatEqual &eq) const throw (CoinError) |
bool | isEquivalent (const CoinPackedVectorBase &rhs) const |
Arithmetic operators. | |
double | dotProduct (const double *dense) const |
Create the dot product with a full vector. | |
double | oneNorm () const |
Return the 1-norm of the vector. | |
double | normSquare () const |
Return the square of the 2-norm of the vector. | |
double | twoNorm () const |
Return the 2-norm of the vector. | |
double | infNorm () const |
Return the infinity-norm of the vector. | |
double | sum () const |
Sum elements of vector. | |
Protected Member Functions | |
Protected methods | |
void | findMaxMinIndices () const |
Find Maximum and Minimum Indices. | |
std::set< int > * | indexSet (const char *methodName=NULL, const char *className=NULL) const throw (CoinError) |
Return indexSetPtr_ (create it if necessary). | |
void | clearIndexSet () const |
Delete the indexSet. | |
void | clearBase () const |
void | copyMaxMinIndex (const CoinPackedVectorBase &x) const |
Private Member Functions | |
Disabled methods | |
CoinPackedVectorBase (const CoinPackedVectorBase &) | |
CoinPackedVectorBase & | operator= (const CoinPackedVectorBase &) |
Private Attributes | |
Protected member data | |
int | maxIndex_ |
Contains max index value or -infinity. | |
int | minIndex_ |
Contains minimum index value or infinity. | |
std::set< int > * | indexSetPtr_ |
bool | testForDuplicateIndex_ |
bool | testedDuplicateIndex_ |
Since this class is abstract, no object of this type can be created. The sole purpose of this class is to provide access to a constant packed vector. All members of this class are const methods, they can't change the object.
Definition at line 25 of file CoinPackedVectorBase.hpp.
|
Default constructor. Definition at line 200 of file CoinPackedVectorBase.cpp.
00200 : 00201 maxIndex_(/*std::numeric_limits<int>::max()*/INT_MIN/*0*/), 00202 minIndex_(/*std::numeric_limits<int>::min()*/INT_MAX/*0*/), 00203 indexSetPtr_(NULL), 00204 testForDuplicateIndex_(true), 00205 testedDuplicateIndex_(false) {} |
|
Destructor Definition at line 209 of file CoinPackedVectorBase.cpp. References indexSetPtr_.
00210 { 00211 delete indexSetPtr_; 00212 } |
|
The copy constructor. |
|
Get the vector as a dense vector. The argument specifies how long this dense vector is. Definition at line 17 of file CoinPackedVectorBase.cpp.
00018 { 00019 if (getMaxIndex() >= denseSize) 00020 throw CoinError("Dense vector size is less than max index", 00021 "denseVector", "CoinPackedVectorBase"); 00022 00023 double * dv = new double[denseSize]; 00024 CoinFillN(dv, denseSize, 0.0); 00025 const int s = getNumElements(); 00026 const int * inds = getIndices(); 00027 const double * elems = getElements(); 00028 for (int i = 0; i < s; ++i) 00029 dv[inds[i]] = elems[i]; 00030 return dv; 00031 } |
|
Return the position of the i'th element of the full storage vector. If index does not exist then -1 is returned Definition at line 114 of file CoinPackedVectorBase.cpp. References getIndices(), and getNumElements().
00115 { 00116 const int * inds = getIndices(); 00117 int retVal = std::find(inds, inds + getNumElements(), i) - inds; 00118 if (retVal == getNumElements() ) retVal = -1; 00119 return retVal; 00120 } |
|
equivalent - If shallow packed vector A & B are equivalent, then they are still equivalent no matter how they are sorted. In this method the FloatEqual function operator can be specified. The default equivalence test is that the entries are relatively equal. Definition at line 110 of file CoinPackedVectorBase.hpp. References duplicateIndex(), getElements(), getIndices(), and getNumElements().
00112 { 00113 if (getNumElements() != rhs.getNumElements()) 00114 return false; 00115 00116 duplicateIndex("equivalent", "CoinPackedVector"); 00117 rhs.duplicateIndex("equivalent", "CoinPackedVector"); 00118 00119 std::map<int,double> mv; 00120 const int * inds = getIndices(); 00121 const double * elems = getElements(); 00122 int i; 00123 for ( i = getNumElements() - 1; i >= 0; --i) { 00124 mv.insert(std::make_pair(inds[i], elems[i])); 00125 } 00126 00127 std::map<int,double> mvRhs; 00128 inds = rhs.getIndices(); 00129 elems = rhs.getElements(); 00130 for ( i = getNumElements() - 1; i >= 0; --i) { 00131 mvRhs.insert(std::make_pair(inds[i], elems[i])); 00132 } 00133 00134 std::map<int,double>::const_iterator mvI = mv.begin(); 00135 std::map<int,double>::const_iterator mvIlast = mv.end(); 00136 std::map<int,double>::const_iterator mvIrhs = mvRhs.begin(); 00137 while (mvI != mvIlast) { 00138 if (mvI->first != mvIrhs->first || ! eq(mvI->second, mvIrhs->second)) 00139 return false; 00140 ++mvI; 00141 ++mvIrhs; 00142 } 00143 return true; 00144 } |
|
Return true if the i'th element of the full storage vector exists in the packed storage vector. Definition at line 103 of file CoinPackedVectorBase.cpp. References duplicateIndex(), indexSet(), and testedDuplicateIndex_.
00104 { 00105 if (! testedDuplicateIndex_) 00106 duplicateIndex("indexExists", "CoinPackedVectorBase"); 00107 00108 const std::set<int> & sv = *indexSet("indexExists", "CoinPackedVectorBase"); 00109 return sv.find(i) != sv.end(); 00110 } |
|
This class provides const access to packed vectors, so there's no need to provide an assignment operator. Reimplemented in CoinPackedVector, and CoinShallowPackedVector. |
|
Equal. Returns true if vectors have same length and corresponding element of each vector is equal. Definition at line 125 of file CoinPackedVectorBase.cpp. References getElements(), getIndices(), and getNumElements().
00126 { 00127 return (getNumElements()==rhs.getNumElements() && 00128 std::equal(getIndices(), getIndices() + getNumElements(), 00129 rhs.getIndices()) && 00130 std::equal(getElements(), getElements() + getNumElements(), 00131 rhs.getElements())); 00132 } |
|
Access the i'th element of the full storage vector. If the i'th is not stored, then zero is returned. The initial use of this method has some computational and storage overhead associated with it. Definition at line 36 of file CoinPackedVectorBase.cpp.
00037 { 00038 if (! testedDuplicateIndex_) 00039 duplicateIndex("operator[]", "CoinPackedVectorBase"); 00040 00041 // Get a reference to a map of full storage indices to 00042 // packed storage location. 00043 const std::set<int> & sv = *indexSet("operator[]", "CoinPackedVectorBase"); 00044 #if 1 00045 if (sv.find(i) == sv.end()) 00046 return 0.0; 00047 return getElements()[findIndex(i)]; 00048 #else 00049 // LL: suggested change, somthing is wrong with this 00050 const size_t ind = std::distance(sv.begin(), sv.find(i)); 00051 return (ind == sv.size()) ? 0.0 : getElements()[ind]; 00052 #endif 00053 00054 } |
|
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur. Definition at line 59 of file CoinPackedVectorBase.cpp. References duplicateIndex(), testedDuplicateIndex_, and testForDuplicateIndex_. Referenced by CoinPackedVector::assignVector(), CoinPackedVector::CoinPackedVector(), CoinShallowPackedVector::CoinShallowPackedVector(), CoinPackedVector::gutsOfSetVector(), CoinPackedVector::setFull(), CoinPackedVector::setFullNonZero(), and CoinShallowPackedVector::setVector().
00060 { 00061 if (test == true) { 00062 testForDuplicateIndex_ = true; 00063 duplicateIndex("setTestForDuplicateIndex", "CoinPackedVectorBase"); 00064 } else { 00065 testForDuplicateIndex_ = false; 00066 testedDuplicateIndex_ = false; 00067 } 00068 } |
|
Returns true if the vector should be tested for duplicate indices when they can occur. Definition at line 52 of file CoinPackedVectorBase.hpp. References testForDuplicateIndex_. Referenced by CoinPackedVector::operator=().
00052 { return testForDuplicateIndex_; } |
|
Store the indices in a set. This set is only created if it is needed. Its primary use is testing for duplicate indices. Definition at line 233 of file CoinPackedVectorBase.hpp. Referenced by clearIndexSet(), findMaxMinIndices(), and ~CoinPackedVectorBase(). |
|
True if the vector has already been tested for duplicate indices. Most of the operations in CoinPackedVector preserves this flag. Definition at line 239 of file CoinPackedVectorBase.hpp. Referenced by isExistingIndex(), and setTestForDuplicateIndex(). |
|
True if the vector should be tested for duplicate indices when they can occur. Definition at line 236 of file CoinPackedVectorBase.hpp. Referenced by setTestForDuplicateIndex(), and testForDuplicateIndex(). |