Dip
0.92.4
|
Abstract base class for various sparse vectors. More...
#include <CoinPackedVectorBase.hpp>
Public Member Functions | |
Virtual methods that the derived classes must provide | |
virtual int | getNumElements () const =0 |
Get length of indices and elements vectors. More... | |
virtual const int * | getIndices () const =0 |
Get indices of elements. More... | |
virtual const double * | getElements () const =0 |
Get element values. More... | |
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 |
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur. More... | |
void | setTestForDuplicateIndexWhenTrue (bool test) const |
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur BUT we know that right now the vector has no duplicate indices. More... | |
bool | testForDuplicateIndex () const |
Returns true if the vector should be tested for duplicate indices when they can occur. More... | |
void | setTestsOff () const |
Just sets test stuff false without a try etc. More... | |
Methods for getting info on the packed vector as a full vector | |
double * | denseVector (int denseSize) const |
Get the vector as a dense vector. More... | |
double | operator[] (int i) const |
Access the i'th element of the full storage vector. More... | |
Index methods | |
int | getMaxIndex () const |
Get value of maximum index. More... | |
int | getMinIndex () const |
Get value of minimum index. More... | |
void | duplicateIndex (const char *methodName=NULL, const char *className=NULL) const |
Throw an exception if there are duplicate indices. More... | |
bool | isExistingIndex (int i) const |
Return true if the i'th element of the full storage vector exists in the packed storage vector. More... | |
int | findIndex (int i) const |
Return the position of the i'th element of the full storage vector. More... | |
Comparison operators on two packed vectors | |
bool | operator== (const CoinPackedVectorBase &rhs) const |
Equal. More... | |
bool | operator!= (const CoinPackedVectorBase &rhs) const |
Not equal. More... | |
int | compare (const CoinPackedVectorBase &rhs) const |
This method establishes an ordering on packed vectors. More... | |
template<class FloatEqual > | |
bool | isEquivalent (const CoinPackedVectorBase &rhs, const FloatEqual &eq) const |
equivalent - If shallow packed vector A & B are equivalent, then they are still equivalent no matter how they are sorted. More... | |
bool | isEquivalent (const CoinPackedVectorBase &rhs) const |
Equal. More... | |
Arithmetic operators. | |
double | dotProduct (const double *dense) const |
Create the dot product with a full vector. More... | |
double | oneNorm () const |
Return the 1-norm of the vector. More... | |
double | normSquare () const |
Return the square of the 2-norm of the vector. More... | |
double | twoNorm () const |
Return the 2-norm of the vector. More... | |
double | infNorm () const |
Return the infinity-norm of the vector. More... | |
double | sum () const |
Sum elements of vector. More... | |
Protected Member Functions | |
Protected methods | |
void | findMaxMinIndices () const |
Find Maximum and Minimum Indices. More... | |
std::set< int > * | indexSet (const char *methodName=NULL, const char *className=NULL) const |
Return indexSetPtr_ (create it if necessary). More... | |
void | clearIndexSet () const |
Delete the indexSet. More... | |
void | clearBase () const |
Find Maximum and Minimum Indices. More... | |
void | copyMaxMinIndex (const CoinPackedVectorBase &x) const |
Find Maximum and Minimum Indices. More... | |
Private Member Functions | |
Disabled methods | |
CoinPackedVectorBase (const CoinPackedVectorBase &) | |
The copy constructor. More... | |
CoinPackedVectorBase & | operator= (const CoinPackedVectorBase &) |
This class provides const access to packed vectors, so there's no need to provide an assignment operator. More... | |
Private Attributes | |
Protected member data | |
int | maxIndex_ |
Contains max index value or -infinity. More... | |
int | minIndex_ |
Contains minimum index value or infinity. More... | |
std::set< int > * | indexSetPtr_ |
Store the indices in a set. More... | |
bool | testForDuplicateIndex_ |
True if the vector should be tested for duplicate indices when they can occur. More... | |
bool | testedDuplicateIndex_ |
True if the vector has already been tested for duplicate indices. More... | |
Constructors, destructor | |
NOTE: All constructors are protected. There's no need to expose them, after all, this is an abstract class. | |
virtual | ~CoinPackedVectorBase () |
Destructor. More... | |
CoinPackedVectorBase () | |
Default constructor. More... | |
Abstract base class for various sparse vectors.
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 23 of file CoinPackedVectorBase.hpp.
|
protected |
Default constructor.
|
virtual |
Destructor.
|
private |
The copy constructor.
This must be at least protected, but we make it private. The reason is that when, say, a shallow packed vector is created, first the underlying class, it this one is constructed. However, at that point we don't know how much of the data members of this class we need to copy over. Therefore the copy constructor is not used.
|
pure virtual |
Get length of indices and elements vectors.
Implemented in CoinPackedVector, and CoinShallowPackedVector.
Referenced by binaryOp(), isEquivalent(), and sortedSparseDotProduct().
|
pure virtual |
Get indices of elements.
Implemented in CoinPackedVector, and CoinShallowPackedVector.
Referenced by binaryOp(), isEquivalent(), and sortedSparseDotProduct().
|
pure virtual |
Get element values.
Implemented in CoinPackedVector, and CoinShallowPackedVector.
Referenced by binaryOp(), isEquivalent(), and sortedSparseDotProduct().
void CoinPackedVectorBase::setTestForDuplicateIndex | ( | bool | test | ) | const |
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur.
Calling this method with test
set to true will trigger an immediate check for duplicate indices.
Referenced by binaryOp(), operator*(), operator+(), operator-(), and operator/().
void CoinPackedVectorBase::setTestForDuplicateIndexWhenTrue | ( | bool | test | ) | const |
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur BUT we know that right now the vector has no duplicate indices.
Calling this method with test
set to true will not trigger an immediate check for duplicate indices; instead, it's assumed that the result of the test will be true.
|
inline |
Returns true if the vector should be tested for duplicate indices when they can occur.
Definition at line 63 of file CoinPackedVectorBase.hpp.
References testForDuplicateIndex_.
|
inline |
Just sets test stuff false without a try etc.
Definition at line 65 of file CoinPackedVectorBase.hpp.
References testedDuplicateIndex_, and testForDuplicateIndex_.
double* CoinPackedVectorBase::denseVector | ( | int | denseSize | ) | const |
Get the vector as a dense vector.
The argument specifies how long this dense vector is.
NOTE: The user needs to delete[]
this pointer after it's not needed anymore.
double CoinPackedVectorBase::operator[] | ( | int | i | ) | const |
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.
NOTE: This is very expensive. It is probably much better to use denseVector()
.
int CoinPackedVectorBase::getMaxIndex | ( | ) | const |
Get value of maximum index.
Referenced by OsiColCut::consistent().
int CoinPackedVectorBase::getMinIndex | ( | ) | const |
Get value of minimum index.
Referenced by OsiColCut::consistent().
void CoinPackedVectorBase::duplicateIndex | ( | const char * | methodName = NULL , |
const char * | className = NULL |
||
) | const |
Throw an exception if there are duplicate indices.
Referenced by OsiColCut::consistent(), and isEquivalent().
bool CoinPackedVectorBase::isExistingIndex | ( | int | i | ) | const |
Return true if the i'th element of the full storage vector exists in the packed storage vector.
Referenced by binaryOp(), and OsiColCut::infeasible().
int CoinPackedVectorBase::findIndex | ( | int | i | ) | const |
Return the position of the i'th element of the full storage vector.
If index does not exist then -1 is returned
Referenced by binaryOp().
bool CoinPackedVectorBase::operator== | ( | const CoinPackedVectorBase & | rhs | ) | const |
Equal.
Returns true if vectors have same length and corresponding element of each vector is equal.
bool CoinPackedVectorBase::operator!= | ( | const CoinPackedVectorBase & | rhs | ) | const |
Not equal.
int CoinPackedVectorBase::compare | ( | const CoinPackedVectorBase & | rhs | ) | const |
This method establishes an ordering on packed vectors.
It is complete ordering, but not the same as lexicographic ordering. However, it is quick and dirty to compute and thus it is useful to keep packed vectors in a heap when all we care is to quickly check whether a particular vector is already in the heap or not. Returns negative/0/positive depending on whether this
is smaller/equal.greater than rhs
.
|
inline |
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.
NOTE: This is a relatively expensive method as it sorts the two shallow packed vectors.
Definition at line 144 of file CoinPackedVectorBase.hpp.
References duplicateIndex(), getElements(), getIndices(), and getNumElements().
Referenced by DecompVar::isEquivalent(), and CoinPackedMatrix::isEquivalent().
bool CoinPackedVectorBase::isEquivalent | ( | const CoinPackedVectorBase & | rhs | ) | const |
Equal.
Returns true if vectors have same length and corresponding element of each vector is equal.
double CoinPackedVectorBase::dotProduct | ( | const double * | dense | ) | const |
Create the dot product with a full vector.
double CoinPackedVectorBase::oneNorm | ( | ) | const |
Return the 1-norm of the vector.
double CoinPackedVectorBase::normSquare | ( | ) | const |
Return the square of the 2-norm of the vector.
double CoinPackedVectorBase::twoNorm | ( | ) | const |
Return the 2-norm of the vector.
Referenced by DecompVar::calcNorm().
double CoinPackedVectorBase::infNorm | ( | ) | const |
Return the infinity-norm of the vector.
double CoinPackedVectorBase::sum | ( | ) | const |
Sum elements of vector.
|
private |
This class provides const access to packed vectors, so there's no need to provide an assignment operator.
|
protected |
Find Maximum and Minimum Indices.
|
protected |
Return indexSetPtr_ (create it if necessary).
|
protected |
Delete the indexSet.
|
protected |
Find Maximum and Minimum Indices.
|
inlineprotected |
Find Maximum and Minimum Indices.
Definition at line 244 of file CoinPackedVectorBase.hpp.
|
mutableprivate |
Contains max index value or -infinity.
Definition at line 255 of file CoinPackedVectorBase.hpp.
Referenced by copyMaxMinIndex().
|
mutableprivate |
Contains minimum index value or infinity.
Definition at line 257 of file CoinPackedVectorBase.hpp.
Referenced by copyMaxMinIndex().
|
mutableprivate |
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 261 of file CoinPackedVectorBase.hpp.
|
mutableprivate |
True if the vector should be tested for duplicate indices when they can occur.
Definition at line 264 of file CoinPackedVectorBase.hpp.
Referenced by setTestsOff(), and testForDuplicateIndex().
|
mutableprivate |
True if the vector has already been tested for duplicate indices.
Most of the operations in CoinPackedVector preserves this flag.
Definition at line 267 of file CoinPackedVectorBase.hpp.
Referenced by setTestsOff().