Cgl  0.60.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Friends | List of all members
CoinIndexedVector Class Reference

Indexed Vector. More...

#include <CoinIndexedVector.hpp>

+ Inheritance diagram for CoinIndexedVector:

Public Member Functions

Get methods.
int getNumElements () const
 Get the size. More...
 
const int * getIndices () const
 Get indices of elements. More...
 
int * getIndices ()
 Get element values. More...
 
double * denseVector () const
 Get the vector as a dense vector. More...
 
void setDenseVector (double *array)
 For very temporary use when user needs to borrow a dense vector. More...
 
void setIndexVector (int *array)
 For very temporary use when user needs to borrow an index vector. More...
 
double & operator[] (int i) const
 Access the i'th element of the full storage vector. More...
 
Set methods
void setNumElements (int value)
 Set the size. More...
 
void clear ()
 Reset the vector (as if were just created an empty vector). This leaves arrays! More...
 
void empty ()
 Reset the vector (as if were just created an empty vector) More...
 
void reallyClear ()
 Clear even if in a bad way. More...
 
CoinIndexedVectoroperator= (const CoinIndexedVector &)
 Assignment operator. More...
 
CoinIndexedVectoroperator= (const CoinPackedVectorBase &rhs)
 Assignment operator from a CoinPackedVectorBase. More...
 
void copy (const CoinIndexedVector &rhs, double multiplier=1.0)
 Copy the contents of one vector into another. More...
 
void borrowVector (int size, int numberIndices, int *inds, double *elems)
 Borrow ownership of the arguments to this vector. More...
 
void returnVector ()
 Return ownership of the arguments to this vector. More...
 
void setVector (int numberIndices, const int *inds, const double *elems)
 Set vector numberIndices, indices, and elements. More...
 
void setVector (int size, int numberIndices, const int *inds, const double *elems)
 Set vector size, indices, and elements. More...
 
void setConstant (int size, const int *inds, double elems)
 Elements set to have the same scalar value. More...
 
void setFull (int size, const double *elems)
 Indices are not specified and are taken to be 0,1,...,size-1. More...
 
void setElement (int index, double element)
 Set an existing element in the indexed vector The first argument is the "index" into the elements() array. More...
 
void insert (int index, double element)
 Insert an element into the vector. More...
 
void quickInsert (int index, double element)
 Insert a nonzero element into the vector. More...
 
void add (int index, double element)
 Insert or if exists add an element into the vector Any resulting zero elements will be made tiny. More...
 
void quickAdd (int index, double element)
 Insert or if exists add an element into the vector Any resulting zero elements will be made tiny. More...
 
void quickAddNonZero (int index, double element)
 Insert or if exists add an element into the vector Any resulting zero elements will be made tiny. More...
 
void zero (int index)
 Makes nonzero tiny. More...
 
int clean (double tolerance)
 set all small values to zero and return number remaining More...
 
int cleanAndPack (double tolerance)
 Same but packs down. More...
 
int cleanAndPackSafe (double tolerance)
 Same but packs down and is safe (i.e. if order is odd) More...
 
void setPacked ()
 Mark as packed. More...
 
void checkClear ()
 For debug check vector is clear i.e. no elements. More...
 
void checkClean ()
 For debug check vector is clean i.e. elements match indices. More...
 
int scan ()
 Scan dense region and set up indices (returns number found) More...
 
int scan (int start, int end)
 Scan dense region from start to < end and set up indices returns number found. More...
 
int scan (double tolerance)
 Scan dense region and set up indices (returns number found). More...
 
int scan (int start, int end, double tolerance)
 Scan dense region from start to < end and set up indices returns number found. More...
 
int scanAndPack ()
 These are same but pack down. More...
 
int scanAndPack (int start, int end)
 
int scanAndPack (double tolerance)
 
int scanAndPack (int start, int end, double tolerance)
 
void createPacked (int number, const int *indices, const double *elements)
 Create packed array. More...
 
void createUnpacked (int number, const int *indices, const double *elements)
 Create unpacked array. More...
 
void createOneUnpackedElement (int index, double element)
 Create unpacked singleton. More...
 
void expand ()
 This is mainly for testing - goes from packed to indexed. More...
 
void append (const CoinPackedVectorBase &caboose)
 Append a CoinPackedVector to the end. More...
 
void append (const CoinIndexedVector &caboose)
 Append a CoinIndexedVector to the end (with extra space) More...
 
void append (CoinIndexedVector &other, int adjustIndex, bool zapElements=false)
 Append a CoinIndexedVector to the end and modify indices. More...
 
void swap (int i, int j)
 Swap values in positions i and j of indices and elements. More...
 
void truncate (int newSize)
 Throw away all entries in rows >= newSize. More...
 
void print () const
 Print out. More...
 
Arithmetic operators.
void operator+= (double value)
 add value to every entry More...
 
void operator-= (double value)
 subtract value from every entry More...
 
void operator*= (double value)
 multiply every entry by value More...
 
void operator/= (double value)
 divide every entry by value (** 0 vanishes) More...
 
Comparison operators on two indexed vectors
bool operator== (const CoinPackedVectorBase &rhs) const
 Equal. More...
 
bool operator!= (const CoinPackedVectorBase &rhs) const
 Not equal. More...
 
bool operator== (const CoinIndexedVector &rhs) const
 Equal. More...
 
bool operator!= (const CoinIndexedVector &rhs) const
 Not equal. More...
 
int isApproximatelyEqual (const CoinIndexedVector &rhs, double tolerance=1.0e-8) const
 Equal with a tolerance (returns -1 or position of inequality). More...
 
Index methods
int getMaxIndex () const
 Get value of maximum index. More...
 
int getMinIndex () const
 Get value of minimum index. More...
 
Sorting
void sort ()
 Sort the indexed storage vector (increasing indices). More...
 
void sortIncrIndex ()
 
void sortDecrIndex ()
 
void sortIncrElement ()
 
void sortDecrElement ()
 
void sortPacked ()
 
Arithmetic operators on packed vectors.

NOTE: These methods operate on those positions where at least one of the arguments has a value listed.

At those positions the appropriate operation is executed, Otherwise the result of the operation is considered 0.
NOTE 2: Because these methods return an object (they can't return a reference, though they could return a pointer...) they are very inefficient...

CoinIndexedVector operator+ (const CoinIndexedVector &op2)
 Return the sum of two indexed vectors. More...
 
CoinIndexedVector operator- (const CoinIndexedVector &op2)
 Return the difference of two indexed vectors. More...
 
CoinIndexedVector operator* (const CoinIndexedVector &op2)
 Return the element-wise product of two indexed vectors. More...
 
CoinIndexedVector operator/ (const CoinIndexedVector &op2)
 Return the element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes) More...
 
void operator+= (const CoinIndexedVector &op2)
 The sum of two indexed vectors. More...
 
void operator-= (const CoinIndexedVector &op2)
 The difference of two indexed vectors. More...
 
void operator*= (const CoinIndexedVector &op2)
 The element-wise product of two indexed vectors. More...
 
void operator/= (const CoinIndexedVector &op2)
 The element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes) More...
 
Memory usage
void reserve (int n)
 Reserve space. More...
 
int capacity () const
 capacity returns the size which could be accomodated without having to reallocate storage. More...
 
void setCapacity (int value)
 
void setPackedMode (bool yesNo)
 Sets packed mode. More...
 
bool packedMode () const
 Gets packed mode. More...
 
Constructors and destructors
 CoinIndexedVector ()
 Default constructor. More...
 
 CoinIndexedVector (int size, const int *inds, const double *elems)
 Alternate Constructors - set elements to vector of doubles. More...
 
 CoinIndexedVector (int size, const int *inds, double element)
 Alternate Constructors - set elements to same scalar value. More...
 
 CoinIndexedVector (int size, const double *elements)
 Alternate Constructors - construct full storage with indices 0 through size-1. More...
 
 CoinIndexedVector (int size)
 Alternate Constructors - just size. More...
 
 CoinIndexedVector (const CoinIndexedVector &)
 Copy constructor. More...
 
 CoinIndexedVector (const CoinIndexedVector *)
 Copy constructor.2. More...
 
 CoinIndexedVector (const CoinPackedVectorBase &rhs)
 Copy constructor from a PackedVectorBase. More...
 
 ~CoinIndexedVector ()
 Destructor. More...
 

Protected Attributes

Private member data
int * indices_
 Vector indices. More...
 
double * elements_
 Vector elements. More...
 
int nElements_
 Size of indices and packed elements vectors. More...
 
int capacity_
 Amount of memory allocated for indices_, and elements_. More...
 
int offset_
 Offset to get where new allocated array. More...
 
bool packedMode_
 If true then is operating in packed mode. More...
 

Private Member Functions

Private methods
void gutsOfSetVector (int size, const int *inds, const double *elems)
 Copy internal data. More...
 
void gutsOfSetVector (int size, int numberIndices, const int *inds, const double *elems)
 
void gutsOfSetPackedVector (int size, int numberIndices, const int *inds, const double *elems)
 
void gutsOfSetConstant (int size, const int *inds, double value)
 

Friends

void CoinIndexedVectorUnitTest ()
 A function that tests the methods in the CoinIndexedVector class. More...
 

Detailed Description

Indexed Vector.

This stores values unpacked but apart from that is a bit like CoinPackedVector. It is designed to be lightweight in normal use.

It now has a "packed" mode when it is even more like CoinPackedVector

Indices array has capacity_ extra chars which are zeroed and can be used for any purpose - but must be re-zeroed

Stores vector of indices and associated element values. Supports sorting of indices.

Does not support negative indices.

Does NOT support testing for duplicates

getElements is no longer supported

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 valuex1
    CoinIndexedVector r(ne,inx,el);

    // 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.);

    // sort Elements in increasing order
    r.sortIncrElement();

    // access each index and element
    assert( r.getIndices ()[0]== 0  );
    assert( r.getIndices ()[1]== 1  );
    assert( r.getIndices ()[2]== 4  );
    assert( r.getIndices ()[3]== 2  );

    // 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
    CoinIndexedVector r1;
    r1=r;
    assert( r==r1 );
    assert( r.equivalent(r1) );
    r.sortIncrElement();
    assert( r!=r1 );
    assert( r.equivalent(r1) );

    // Add indexed vectors.
    // Similarly for subtraction, multiplication,
    // and division.
    CoinIndexedVector 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 104 of file CoinIndexedVector.hpp.

Constructor & Destructor Documentation

CoinIndexedVector::CoinIndexedVector ( )

Default constructor.

CoinIndexedVector::CoinIndexedVector ( int  size,
const int *  inds,
const double *  elems 
)

Alternate Constructors - set elements to vector of doubles.

CoinIndexedVector::CoinIndexedVector ( int  size,
const int *  inds,
double  element 
)

Alternate Constructors - set elements to same scalar value.

CoinIndexedVector::CoinIndexedVector ( int  size,
const double *  elements 
)

Alternate Constructors - construct full storage with indices 0 through size-1.

CoinIndexedVector::CoinIndexedVector ( int  size)

Alternate Constructors - just size.

CoinIndexedVector::CoinIndexedVector ( const CoinIndexedVector )

Copy constructor.

CoinIndexedVector::CoinIndexedVector ( const CoinIndexedVector )

Copy constructor.2.

CoinIndexedVector::CoinIndexedVector ( const CoinPackedVectorBase rhs)

Copy constructor from a PackedVectorBase.

CoinIndexedVector::~CoinIndexedVector ( )

Destructor.

Member Function Documentation

int CoinIndexedVector::getNumElements ( ) const
inline

Get the size.

Definition at line 111 of file CoinIndexedVector.hpp.

const int* CoinIndexedVector::getIndices ( ) const
inline

Get indices of elements.

Definition at line 113 of file CoinIndexedVector.hpp.

int* CoinIndexedVector::getIndices ( )
inline

Get element values.

Get indices of elements

Definition at line 117 of file CoinIndexedVector.hpp.

double* CoinIndexedVector::denseVector ( ) const
inline

Get the vector as a dense vector.

This is normal storage method. The user should not not delete [] this.

Definition at line 121 of file CoinIndexedVector.hpp.

void CoinIndexedVector::setDenseVector ( double *  array)
inline

For very temporary use when user needs to borrow a dense vector.

Definition at line 123 of file CoinIndexedVector.hpp.

void CoinIndexedVector::setIndexVector ( int *  array)
inline

For very temporary use when user needs to borrow an index vector.

Definition at line 128 of file CoinIndexedVector.hpp.

double& CoinIndexedVector::operator[] ( int  i) const

Access the i'th element of the full storage vector.

void CoinIndexedVector::setNumElements ( int  value)
inline

Set the size.

Definition at line 144 of file CoinIndexedVector.hpp.

void CoinIndexedVector::clear ( )

Reset the vector (as if were just created an empty vector). This leaves arrays!

void CoinIndexedVector::empty ( )

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

void CoinIndexedVector::reallyClear ( )

Clear even if in a bad way.

CoinIndexedVector& CoinIndexedVector::operator= ( const CoinIndexedVector )

Assignment operator.

CoinIndexedVector& CoinIndexedVector::operator= ( const CoinPackedVectorBase rhs)

Assignment operator from a CoinPackedVectorBase.


NOTE: This assumes no duplicates

void CoinIndexedVector::copy ( const CoinIndexedVector rhs,
double  multiplier = 1.0 
)

Copy the contents of one vector into another.

If multiplier is 1 It is the equivalent of = but if vectors are same size does not re-allocate memory just clears and copies

void CoinIndexedVector::borrowVector ( int  size,
int  numberIndices,
int *  inds,
double *  elems 
)

Borrow ownership of the arguments to this vector.

Size is the length of the unpacked elements vector.

void CoinIndexedVector::returnVector ( )

Return ownership of the arguments to this vector.

State after is empty .

void CoinIndexedVector::setVector ( int  numberIndices,
const int *  inds,
const double *  elems 
)

Set vector numberIndices, indices, and elements.

NumberIndices is the length of both the indices and elements vectors. The indices and elements vectors are copied into this class instance's member data. Assumed to have no duplicates

void CoinIndexedVector::setVector ( int  size,
int  numberIndices,
const int *  inds,
const double *  elems 
)

Set vector size, indices, and elements.

Size is the length of the unpacked elements vector. The indices and elements vectors are copied into this class instance's member data. We do not check for duplicate indices

void CoinIndexedVector::setConstant ( int  size,
const int *  inds,
double  elems 
)

Elements set to have the same scalar value.

void CoinIndexedVector::setFull ( int  size,
const double *  elems 
)

Indices are not specified and are taken to be 0,1,...,size-1.

void CoinIndexedVector::setElement ( int  index,
double  element 
)

Set an existing element in the indexed vector The first argument is the "index" into the elements() array.

void CoinIndexedVector::insert ( int  index,
double  element 
)

Insert an element into the vector.

void CoinIndexedVector::quickInsert ( int  index,
double  element 
)
inline

Insert a nonzero element into the vector.

Definition at line 203 of file CoinIndexedVector.hpp.

void CoinIndexedVector::add ( int  index,
double  element 
)

Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.

void CoinIndexedVector::quickAdd ( int  index,
double  element 
)
inline

Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.

This version does no checking

Definition at line 216 of file CoinIndexedVector.hpp.

void CoinIndexedVector::quickAddNonZero ( int  index,
double  element 
)
inline

Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.

This knows element is nonzero This version does no checking

Definition at line 235 of file CoinIndexedVector.hpp.

void CoinIndexedVector::zero ( int  index)
inline

Makes nonzero tiny.

This version does no checking

Definition at line 253 of file CoinIndexedVector.hpp.

int CoinIndexedVector::clean ( double  tolerance)

set all small values to zero and return number remaining

  • < tolerance => 0.0
int CoinIndexedVector::cleanAndPack ( double  tolerance)

Same but packs down.

int CoinIndexedVector::cleanAndPackSafe ( double  tolerance)

Same but packs down and is safe (i.e. if order is odd)

void CoinIndexedVector::setPacked ( )
inline

Mark as packed.

Definition at line 266 of file CoinIndexedVector.hpp.

void CoinIndexedVector::checkClear ( )

For debug check vector is clear i.e. no elements.

void CoinIndexedVector::checkClean ( )

For debug check vector is clean i.e. elements match indices.

int CoinIndexedVector::scan ( )

Scan dense region and set up indices (returns number found)

int CoinIndexedVector::scan ( int  start,
int  end 
)

Scan dense region from start to < end and set up indices returns number found.

int CoinIndexedVector::scan ( double  tolerance)

Scan dense region and set up indices (returns number found).

Only ones >= tolerance

int CoinIndexedVector::scan ( int  start,
int  end,
double  tolerance 
)

Scan dense region from start to < end and set up indices returns number found.

Only >= tolerance

int CoinIndexedVector::scanAndPack ( )

These are same but pack down.

int CoinIndexedVector::scanAndPack ( int  start,
int  end 
)
int CoinIndexedVector::scanAndPack ( double  tolerance)
int CoinIndexedVector::scanAndPack ( int  start,
int  end,
double  tolerance 
)
void CoinIndexedVector::createPacked ( int  number,
const int *  indices,
const double *  elements 
)

Create packed array.

void CoinIndexedVector::createUnpacked ( int  number,
const int *  indices,
const double *  elements 
)

Create unpacked array.

void CoinIndexedVector::createOneUnpackedElement ( int  index,
double  element 
)

Create unpacked singleton.

void CoinIndexedVector::expand ( )

This is mainly for testing - goes from packed to indexed.

void CoinIndexedVector::append ( const CoinPackedVectorBase caboose)

Append a CoinPackedVector to the end.

void CoinIndexedVector::append ( const CoinIndexedVector caboose)

Append a CoinIndexedVector to the end (with extra space)

void CoinIndexedVector::append ( CoinIndexedVector other,
int  adjustIndex,
bool  zapElements = false 
)

Append a CoinIndexedVector to the end and modify indices.

void CoinIndexedVector::swap ( int  i,
int  j 
)

Swap values in positions i and j of indices and elements.

void CoinIndexedVector::truncate ( int  newSize)

Throw away all entries in rows >= newSize.

void CoinIndexedVector::print ( ) const

Print out.

void CoinIndexedVector::operator+= ( double  value)

add value to every entry

void CoinIndexedVector::operator-= ( double  value)

subtract value from every entry

void CoinIndexedVector::operator*= ( double  value)

multiply every entry by value

void CoinIndexedVector::operator/= ( double  value)

divide every entry by value (** 0 vanishes)

bool CoinIndexedVector::operator== ( const CoinPackedVectorBase rhs) const

Equal.

Returns true if vectors have same length and corresponding element of each vector is equal.

bool CoinIndexedVector::operator!= ( const CoinPackedVectorBase rhs) const

Not equal.

bool CoinIndexedVector::operator== ( const CoinIndexedVector rhs) const

Equal.

Returns true if vectors have same length and corresponding element of each vector is equal.

bool CoinIndexedVector::operator!= ( const CoinIndexedVector rhs) const

Not equal.

int CoinIndexedVector::isApproximatelyEqual ( const CoinIndexedVector rhs,
double  tolerance = 1.0e-8 
) const

Equal with a tolerance (returns -1 or position of inequality).

int CoinIndexedVector::getMaxIndex ( ) const

Get value of maximum index.

int CoinIndexedVector::getMinIndex ( ) const

Get value of minimum index.

void CoinIndexedVector::sort ( )
inline

Sort the indexed storage vector (increasing indices).

Definition at line 365 of file CoinIndexedVector.hpp.

void CoinIndexedVector::sortIncrIndex ( )
inline

Definition at line 370 of file CoinIndexedVector.hpp.

void CoinIndexedVector::sortDecrIndex ( )
void CoinIndexedVector::sortIncrElement ( )
void CoinIndexedVector::sortDecrElement ( )
void CoinIndexedVector::sortPacked ( )
CoinIndexedVector CoinIndexedVector::operator+ ( const CoinIndexedVector op2)

Return the sum of two indexed vectors.

CoinIndexedVector CoinIndexedVector::operator- ( const CoinIndexedVector op2)

Return the difference of two indexed vectors.

CoinIndexedVector CoinIndexedVector::operator* ( const CoinIndexedVector op2)

Return the element-wise product of two indexed vectors.

CoinIndexedVector CoinIndexedVector::operator/ ( const CoinIndexedVector op2)

Return the element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes)

void CoinIndexedVector::operator+= ( const CoinIndexedVector op2)

The sum of two indexed vectors.

void CoinIndexedVector::operator-= ( const CoinIndexedVector op2)

The difference of two indexed vectors.

void CoinIndexedVector::operator*= ( const CoinIndexedVector op2)

The element-wise product of two indexed vectors.

void CoinIndexedVector::operator/= ( const CoinIndexedVector op2)

The element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes)

void CoinIndexedVector::reserve ( int  n)

Reserve space.

If one knows the eventual size of the indexed vector, then it may be more efficient to reserve the space.

int CoinIndexedVector::capacity ( ) const
inline

capacity returns the size which could be accomodated without having to reallocate storage.

Definition at line 435 of file CoinIndexedVector.hpp.

void CoinIndexedVector::setCapacity ( int  value)
inline

Definition at line 436 of file CoinIndexedVector.hpp.

void CoinIndexedVector::setPackedMode ( bool  yesNo)
inline

Sets packed mode.

Definition at line 441 of file CoinIndexedVector.hpp.

bool CoinIndexedVector::packedMode ( ) const
inline

Gets packed mode.

Definition at line 446 of file CoinIndexedVector.hpp.

void CoinIndexedVector::gutsOfSetVector ( int  size,
const int *  inds,
const double *  elems 
)
private

Copy internal data.

void CoinIndexedVector::gutsOfSetVector ( int  size,
int  numberIndices,
const int *  inds,
const double *  elems 
)
private
void CoinIndexedVector::gutsOfSetPackedVector ( int  size,
int  numberIndices,
const int *  inds,
const double *  elems 
)
private
void CoinIndexedVector::gutsOfSetConstant ( int  size,
const int *  inds,
double  value 
)
private

Friends And Related Function Documentation

void CoinIndexedVectorUnitTest ( )
friend

A function that tests the methods in the CoinIndexedVector 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

int* CoinIndexedVector::indices_
protected

Vector indices.

Definition at line 496 of file CoinIndexedVector.hpp.

double* CoinIndexedVector::elements_
protected

Vector elements.

Definition at line 498 of file CoinIndexedVector.hpp.

int CoinIndexedVector::nElements_
protected

Size of indices and packed elements vectors.

Definition at line 500 of file CoinIndexedVector.hpp.

int CoinIndexedVector::capacity_
protected

Amount of memory allocated for indices_, and elements_.

Definition at line 502 of file CoinIndexedVector.hpp.

int CoinIndexedVector::offset_
protected

Offset to get where new allocated array.

Definition at line 504 of file CoinIndexedVector.hpp.

bool CoinIndexedVector::packedMode_
protected

If true then is operating in packed mode.

Definition at line 506 of file CoinIndexedVector.hpp.


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