CoinUtils  2.11.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members
CoinPackedVectorBase Class Referenceabstract

Abstract base class for various sparse vectors. More...

#include <CoinPackedVectorBase.hpp>

+ Inheritance diagram for CoinPackedVectorBase:
+ Collaboration diagram for CoinPackedVectorBase:

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
 
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
 
void copyMaxMinIndex (const CoinPackedVectorBase &x) const
 

Private Member Functions

Disabled methods
 CoinPackedVectorBase (const CoinPackedVectorBase &)
 The copy constructor. More...
 
CoinPackedVectorBaseoperator= (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

CoinPackedVectorBase::CoinPackedVectorBase ( )
protected

Default constructor.

virtual CoinPackedVectorBase::~CoinPackedVectorBase ( )
virtual

Destructor.

CoinPackedVectorBase::CoinPackedVectorBase ( const CoinPackedVectorBase )
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.

Member Function Documentation

virtual int CoinPackedVectorBase::getNumElements ( ) const
pure virtual

Get length of indices and elements vectors.

Implemented in CoinPackedVector, and CoinShallowPackedVector.

virtual const int* CoinPackedVectorBase::getIndices ( ) const
pure virtual

Get indices of elements.

Implemented in CoinPackedVector, and CoinShallowPackedVector.

virtual const double* CoinPackedVectorBase::getElements ( ) const
pure virtual

Get element values.

Implemented in CoinPackedVector, and CoinShallowPackedVector.

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.

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.

bool CoinPackedVectorBase::testForDuplicateIndex ( ) const
inline

Returns true if the vector should be tested for duplicate indices when they can occur.

Definition at line 63 of file CoinPackedVectorBase.hpp.

void CoinPackedVectorBase::setTestsOff ( ) const
inline

Just sets test stuff false without a try etc.

Definition at line 65 of file CoinPackedVectorBase.hpp.

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.

int CoinPackedVectorBase::getMinIndex ( ) const

Get value of minimum index.

void CoinPackedVectorBase::duplicateIndex ( const char *  methodName = NULL,
const char *  className = NULL 
) const

Throw an exception if there are duplicate indices.

bool CoinPackedVectorBase::isExistingIndex ( int  i) const

Return true if the i'th element of the full storage vector exists in the packed storage vector.

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

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.

template<class FloatEqual >
bool CoinPackedVectorBase::isEquivalent ( const CoinPackedVectorBase rhs,
const FloatEqual &  eq 
) const
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.

bool CoinPackedVectorBase::isEquivalent ( const CoinPackedVectorBase rhs) const
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.

double CoinPackedVectorBase::infNorm ( ) const

Return the infinity-norm of the vector.

double CoinPackedVectorBase::sum ( ) const

Sum elements of vector.

CoinPackedVectorBase& CoinPackedVectorBase::operator= ( const CoinPackedVectorBase )
private

This class provides const access to packed vectors, so there's no need to provide an assignment operator.

void CoinPackedVectorBase::findMaxMinIndices ( ) const
protected

Find Maximum and Minimum Indices.

std::set< int >* CoinPackedVectorBase::indexSet ( const char *  methodName = NULL,
const char *  className = NULL 
) const
protected

Return indexSetPtr_ (create it if necessary).

void CoinPackedVectorBase::clearIndexSet ( ) const
protected

Delete the indexSet.

void CoinPackedVectorBase::clearBase ( ) const
protected
void CoinPackedVectorBase::copyMaxMinIndex ( const CoinPackedVectorBase x) const
inlineprotected

Definition at line 244 of file CoinPackedVectorBase.hpp.

Member Data Documentation

int CoinPackedVectorBase::maxIndex_
mutableprivate

Contains max index value or -infinity.

Definition at line 255 of file CoinPackedVectorBase.hpp.

int CoinPackedVectorBase::minIndex_
mutableprivate

Contains minimum index value or infinity.

Definition at line 257 of file CoinPackedVectorBase.hpp.

std::set< int >* CoinPackedVectorBase::indexSetPtr_
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.

bool CoinPackedVectorBase::testForDuplicateIndex_
mutableprivate

True if the vector should be tested for duplicate indices when they can occur.

Definition at line 264 of file CoinPackedVectorBase.hpp.

bool CoinPackedVectorBase::testedDuplicateIndex_
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.


The documentation for this class was generated from the following file: