CoinIndexedVector Class Reference

Indexed Vector. More...

#include <CoinIndexedVector.hpp>

List of all members.

Public Member Functions

Get methods.



int getNumElements () const
 Get the size.
const int * getIndices () const
 Get indices of elements.
int * getIndices ()
 Get element values.
double * denseVector () const
 Get the vector as a dense vector.
void setDenseVector (double *array)
 For very temporary use when user needs to borrow a dense vector.
void setIndexVector (int *array)
 For very temporary use when user needs to borrow an index vector.
double & operator[] (int i) const
 Access the i'th element of the full storage vector.
Set methods



void setNumElements (int value)
 Set the size.
void clear ()
 Reset the vector (as if were just created an empty vector). This leaves arrays!
void empty ()
 Reset the vector (as if were just created an empty vector).
CoinIndexedVectoroperator= (const CoinIndexedVector &)
 Assignment operator.
CoinIndexedVectoroperator= (const CoinPackedVectorBase &rhs)
 Assignment operator from a CoinPackedVectorBase.
void copy (const CoinIndexedVector &rhs, double multiplier=1.0)
 Copy the contents of one vector into another.
void borrowVector (int size, int numberIndices, int *inds, double *elems)
 Borrow ownership of the arguments to this vector.
void returnVector ()
 Return ownership of the arguments to this vector.
void setVector (int numberIndices, const int *inds, const double *elems)
 Set vector numberIndices, indices, and elements.
void setVector (int size, int numberIndices, const int *inds, const double *elems)
 Set vector size, indices, and elements.
void setConstant (int size, const int *inds, double elems)
 Elements set to have the same scalar value.
void setFull (int size, const double *elems)
 Indices are not specified and are taken to be 0,1,.
void setElement (int index, double element)
 Set an existing element in the indexed vector The first argument is the "index" into the elements() array.
void insert (int index, double element)
 Insert an element into the vector.
void add (int index, double element)
 Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.
void quickAdd (int index, double element)
 Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.
void zero (int index)
 Makes nonzero tiny.
int clean (double tolerance)
 set all small values to zero and return number remaining

  • < tolerance => 0.0

int cleanAndPack (double tolerance)
 Same but packs down.
int cleanAndPackSafe (double tolerance)
 Same but packs down and is safe (i.e. if order is odd).
void setPacked ()
 Mark as packed.
void checkClear ()
 For debug check vector is clear i.e. no elements.
void checkClean ()
 For debug check vector is clean i.e. elements match indices.
int scan ()
 Scan dense region and set up indices (returns number found).
int scan (int start, int end)
 Scan dense region from start to < end and set up indices returns number found.
int scan (double tolerance)
 Scan dense region and set up indices (returns number found).
int scan (int start, int end, double tolerance)
 Scan dense region from start to < end and set up indices returns number found.
int scanAndPack ()
 These are same but pack down.
int scanAndPack (int start, int end)
 Set the size.
int scanAndPack (double tolerance)
 Set the size.
int scanAndPack (int start, int end, double tolerance)
 Set the size.
void createPacked (int number, const int *indices, const double *elements)
 Create packed array.
void expand ()
 This is mainly for testing - goes from packed to indexed.
void append (const CoinPackedVectorBase &caboose)
 Append a CoinPackedVector to the end.
void append (const CoinIndexedVector &caboose)
 Append a CoinIndexedVector to the end.
void swap (int i, int j)
 Swap values in positions i and j of indices and elements.
void truncate (int newSize)
 Throw away all entries in rows >= newSize.
void print () const
 Print out.
Arithmetic operators.



void operator+= (double value)
 add value to every entry
void operator-= (double value)
 subtract value from every entry
void operator*= (double value)
 multiply every entry by value
void operator/= (double value)
 divide every entry by value (** 0 vanishes)
Comparison operators on two indexed vectors



bool operator== (const CoinPackedVectorBase &rhs) const
 Equal.
bool operator!= (const CoinPackedVectorBase &rhs) const
 Not equal.
bool operator== (const CoinIndexedVector &rhs) const
 Equal.
bool operator!= (const CoinIndexedVector &rhs) const
 Not equal.
Index methods



int getMaxIndex () const
 Get value of maximum index.
int getMinIndex () const
 Get value of minimum index.
Sorting



void sort ()
 Sort the indexed storage vector (increasing indices).
void sortIncrIndex ()
 Sort the indexed storage vector (increasing indices).
void sortDecrIndex ()
 Sort the indexed storage vector (increasing indices).
void sortIncrElement ()
 Sort the indexed storage vector (increasing indices).
void sortDecrElement ()
 Sort the indexed storage vector (increasing indices).
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.
CoinIndexedVector operator- (const CoinIndexedVector &op2)
 Return the difference of two indexed vectors.
CoinIndexedVector operator* (const CoinIndexedVector &op2)
 Return the element-wise product of two indexed vectors.
CoinIndexedVector operator/ (const CoinIndexedVector &op2)
 Return the element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes).
void operator+= (const CoinIndexedVector &op2)
 The sum of two indexed vectors.
void operator-= (const CoinIndexedVector &op2)
 The difference of two indexed vectors.
void operator*= (const CoinIndexedVector &op2)
 The element-wise product of two indexed vectors.
void operator/= (const CoinIndexedVector &op2)
 The element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes).
Memory usage



void reserve (int n)
 Reserve space.
int capacity () const
 capacity returns the size which could be accomodated without having to reallocate storage.
void setPackedMode (bool yesNo)
 Sets packed mode.
bool packedMode () const
 Gets packed mode.
Constructors and destructors



 CoinIndexedVector ()
 Default constructor.
 CoinIndexedVector (int size, const int *inds, const double *elems)
 Alternate Constructors - set elements to vector of doubles.
 CoinIndexedVector (int size, const int *inds, double element)
 Alternate Constructors - set elements to same scalar value.
 CoinIndexedVector (int size, const double *elements)
 Alternate Constructors - construct full storage with indices 0 through size-1.
 CoinIndexedVector (int size)
 Alternate Constructors - just size.
 CoinIndexedVector (const CoinIndexedVector &)
 Copy constructor.
 CoinIndexedVector (const CoinIndexedVector *)
 Copy constructor.2.
 CoinIndexedVector (const CoinPackedVectorBase &rhs)
 Copy constructor from a PackedVectorBase.
 ~CoinIndexedVector ()
 Destructor.

Private Member Functions

Private methods



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

Private Attributes

Private member data



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

Friends

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

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 99 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 106 of file CoinIndexedVector.hpp.

const int* CoinIndexedVector::getIndices (  )  const [inline]

Get indices of elements.

Definition at line 108 of file CoinIndexedVector.hpp.

int* CoinIndexedVector::getIndices (  )  [inline]

Get element values.

Get indices of elements

Definition at line 112 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 116 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 118 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 121 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 135 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).

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::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 193 of file CoinIndexedVector.hpp.

void CoinIndexedVector::zero ( int  index  )  [inline]

Makes nonzero tiny.

This version does no checking

Definition at line 210 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 223 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 
)

Set the size.

int CoinIndexedVector::scanAndPack ( double  tolerance  ) 

Set the size.

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

Set the size.

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

Create packed array.

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.

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::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 307 of file CoinIndexedVector.hpp.

void CoinIndexedVector::sortIncrIndex (  )  [inline]

Sort the indexed storage vector (increasing indices).

Definition at line 310 of file CoinIndexedVector.hpp.

void CoinIndexedVector::sortDecrIndex (  ) 

Sort the indexed storage vector (increasing indices).

void CoinIndexedVector::sortIncrElement (  ) 

Sort the indexed storage vector (increasing indices).

void CoinIndexedVector::sortDecrElement (  ) 

Sort the indexed storage vector (increasing indices).

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 372 of file CoinIndexedVector.hpp.

void CoinIndexedVector::setPackedMode ( bool  yesNo  )  [inline]

Sets packed mode.

Definition at line 374 of file CoinIndexedVector.hpp.

bool CoinIndexedVector::packedMode (  )  const [inline]

Gets packed mode.

Definition at line 377 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]

Copy internal data.

void CoinIndexedVector::gutsOfSetPackedVector ( int  size,
int  numberIndices,
const int *  inds,
const double *  elems 
) [private]

Copy internal data.

void CoinIndexedVector::gutsOfSetConstant ( int  size,
const int *  inds,
double  value 
) [private]

Copy internal data.


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

Vector indices.

Definition at line 425 of file CoinIndexedVector.hpp.

double* CoinIndexedVector::elements_ [private]

Vector elements.

Definition at line 427 of file CoinIndexedVector.hpp.

Size of indices and packed elements vectors.

Definition at line 429 of file CoinIndexedVector.hpp.

Amount of memory allocated for indices_, and elements_.

Definition at line 431 of file CoinIndexedVector.hpp.

Offset to get where new allocated array.

Definition at line 433 of file CoinIndexedVector.hpp.

If true then is operating in packed mode.

Definition at line 435 of file CoinIndexedVector.hpp.


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

Generated on 15 Mar 2015 for Coin-All by  doxygen 1.6.1