Cbc  2.10.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Friends | List of all members
CoinShallowPackedVector Class Reference

Shallow Sparse Vector. More...

#include <CoinShallowPackedVector.hpp>

+ Inheritance diagram for CoinShallowPackedVector:
+ Collaboration diagram for CoinShallowPackedVector:

Public Member Functions

Get methods
virtual int getNumElements () const
 Get length of indices and elements vectors. More...
 
virtual const int * getIndices () const
 Get indices of elements. More...
 
virtual const double * getElements () const
 Get element values. More...
 
Set methods
void clear ()
 Reset the vector (as if were just created an empty vector) More...
 
CoinShallowPackedVectoroperator= (const CoinShallowPackedVector &x)
 Assignment operator. More...
 
CoinShallowPackedVectoroperator= (const CoinPackedVectorBase &x)
 Assignment operator from a CoinPackedVectorBase. More...
 
void setVector (int size, const int *indices, const double *elements, bool testForDuplicateIndex=true)
 just like the explicit constructor More...
 
Methods to create, set and destroy
 CoinShallowPackedVector (bool testForDuplicateIndex=true)
 Default constructor. More...
 
 CoinShallowPackedVector (int size, const int *indices, const double *elements, bool testForDuplicateIndex=true)
 Explicit Constructor. More...
 
 CoinShallowPackedVector (const CoinPackedVectorBase &)
 Copy constructor from the base class. More...
 
 CoinShallowPackedVector (const CoinShallowPackedVector &)
 Copy constructor. More...
 
virtual ~CoinShallowPackedVector ()
 Destructor. More...
 
void print ()
 Print vector information. More...
 
- Public Member Functions inherited from CoinPackedVectorBase
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...
 
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...
 
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...
 
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
 
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...
 
virtual ~CoinPackedVectorBase ()
 Destructor. More...
 

Private Attributes

Private member data
const int * indices_
 Vector indices. More...
 
const double * elements_
 Vector elements. More...
 
int nElements_
 Size of indices and elements vectors. More...
 

Friends

void CoinShallowPackedVectorUnitTest ()
 A function that tests the methods in the CoinShallowPackedVector class. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CoinPackedVectorBase
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
 
 CoinPackedVectorBase ()
 Default constructor. More...
 

Detailed Description

Shallow Sparse Vector.

This class is for sparse vectors where the indices and elements are stored elsewhere. This class only maintains pointers to the indices and elements. Since this class does not own the index and element data it provides read only access to to the data. An CoinSparsePackedVector must be used when the sparse vector's data will be altered.

This class stores pointers to the vectors. It does not actually contain the vectors.

Here is a sample usage:

   const int ne = 4; 
   int inx[ne] =   {  1,   4,  0,   2 }; 
   double el[ne] = { 10., 40., 1., 50. }; 
 
   // Create vector and set its value 
   CoinShallowPackedVector r(ne,inx,el); 
 
   // access each index and element 
   assert( r.indices ()[0]== 1  ); 
   assert( r.elements()[0]==10. ); 
   assert( r.indices ()[1]== 4  ); 
   assert( r.elements()[1]==40. ); 
   assert( r.indices ()[2]== 0  ); 
   assert( r.elements()[2]== 1. ); 
   assert( r.indices ()[3]== 2  ); 
   assert( r.elements()[3]==50. ); 
 
   // access as a full storage vector 
   assert( r[ 0]==1. ); 
   assert( r[ 1]==10.); 
   assert( r[ 2]==50.); 
   assert( r[ 3]==0. ); 
   assert( r[ 4]==40.); 
 
   // Tests for equality and equivalence
   CoinShallowPackedVector r1; 
   r1=r; 
   assert( r==r1 ); 
   r.sort(CoinIncrElementOrdered()); 
   assert( r!=r1 ); 
 
   // Add packed vectors. 
   // Similarly for subtraction, multiplication, 
   // and division. 
   CoinPackedVector add = r + r1; 
   assert( add[0] ==  1.+ 1. ); 
   assert( add[1] == 10.+10. ); 
   assert( add[2] == 50.+50. ); 
   assert( add[3] ==  0.+ 0. ); 
   assert( add[4] == 40.+40. ); 
   assert( r.sum() == 10.+40.+1.+50. ); 

Definition at line 74 of file CoinShallowPackedVector.hpp.

Constructor & Destructor Documentation

CoinShallowPackedVector::CoinShallowPackedVector ( bool  testForDuplicateIndex = true)

Default constructor.

CoinShallowPackedVector::CoinShallowPackedVector ( int  size,
const int *  indices,
const double *  elements,
bool  testForDuplicateIndex = true 
)

Explicit Constructor.

Set vector size, indices, and elements. Size is the length of both the indices and elements vectors. The indices and elements vectors are not copied into this class instance. The ShallowPackedVector only maintains the pointers to the indices and elements vectors.
The last argument specifies whether the creator of the object knows in advance that there are no duplicate indices.

CoinShallowPackedVector::CoinShallowPackedVector ( const CoinPackedVectorBase )

Copy constructor from the base class.

CoinShallowPackedVector::CoinShallowPackedVector ( const CoinShallowPackedVector )

Copy constructor.

virtual CoinShallowPackedVector::~CoinShallowPackedVector ( )
inlinevirtual

Destructor.

Definition at line 121 of file CoinShallowPackedVector.hpp.

Member Function Documentation

virtual int CoinShallowPackedVector::getNumElements ( ) const
inlinevirtual

Get length of indices and elements vectors.

Implements CoinPackedVectorBase.

Definition at line 81 of file CoinShallowPackedVector.hpp.

virtual const int* CoinShallowPackedVector::getIndices ( ) const
inlinevirtual

Get indices of elements.

Implements CoinPackedVectorBase.

Definition at line 83 of file CoinShallowPackedVector.hpp.

virtual const double* CoinShallowPackedVector::getElements ( ) const
inlinevirtual

Get element values.

Implements CoinPackedVectorBase.

Definition at line 85 of file CoinShallowPackedVector.hpp.

void CoinShallowPackedVector::clear ( )

Reset the vector (as if were just created an empty vector)

CoinShallowPackedVector& CoinShallowPackedVector::operator= ( const CoinShallowPackedVector x)

Assignment operator.

CoinShallowPackedVector& CoinShallowPackedVector::operator= ( const CoinPackedVectorBase x)

Assignment operator from a CoinPackedVectorBase.

void CoinShallowPackedVector::setVector ( int  size,
const int *  indices,
const double *  elements,
bool  testForDuplicateIndex = true 
)

just like the explicit constructor

void CoinShallowPackedVector::print ( )

Print vector information.

Friends And Related Function Documentation

void CoinShallowPackedVectorUnitTest ( )
friend

A function that tests the methods in the CoinShallowPackedVector class.

The only reason for it not to be a member method is that this way it doesn't have to be compiled into the library. And that's a gain, because the library should be compiled with optimization on, but this method should be compiled with debugging.

Member Data Documentation

const int* CoinShallowPackedVector::indices_
private

Vector indices.

Definition at line 130 of file CoinShallowPackedVector.hpp.

const double* CoinShallowPackedVector::elements_
private

Vector elements.

Definition at line 132 of file CoinShallowPackedVector.hpp.

int CoinShallowPackedVector::nElements_
private

Size of indices and elements vectors.

Definition at line 134 of file CoinShallowPackedVector.hpp.


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