CoinIndexedVector

Indexed Vector.

Indexed Vector.

Derived classes: CoinPartitionedVector

Description

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

Public Methods

getNumElements

Get the size.

int getNumElements()

getIndices

Get indices of elements.

const int * getIndices()

getIndices

Get element values.

int * getIndices()

denseVector

Get the vector as a dense vector.

double * denseVector()

setDenseVector

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

void setDenseVector(double * array)

Parameters:

setIndexVector

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

void setIndexVector(int * array)

Parameters:

operator[]

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

double & operator[](int i)

Parameters:

setNumElements

Set the size.

void setNumElements(int value)

Parameters:

clear

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

void clear()

empty

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

void empty()

reallyClear

Clear even if in a bad way.

void reallyClear()

operator=

Assignment operator.

CoinIndexedVector & operator=(const CoinIndexedVector & )

Parameters:

operator=

Assignment operator from a CoinPackedVectorBase.

CoinIndexedVector & operator=(const CoinPackedVectorBase & rhs)

Parameters:

copy

Copy the contents of one vector into another.

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

Parameters:

borrowVector

Borrow ownership of the arguments to this vector.

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

Parameters:

returnVector

Return ownership of the arguments to this vector.

void returnVector()

setVector

Set vector numberIndices, indices, and elements.

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

Parameters:

setVector

Set vector size, indices, and elements.

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

Parameters:

setConstant

Elements set to have the same scalar value.

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

Parameters:

setFull

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

void setFull(int size, const double * elems)

Parameters:

setElement

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

void setElement(int index, double element)

Parameters:

insert

Insert an element into the vector.

void insert(int index, double element)

Parameters:

quickInsert

Insert a nonzero element into the vector.

void quickInsert(int index, double element)

Parameters:

add

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

void add(int index, double element)

Parameters:

quickAdd

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

void quickAdd(int index, double element)

Parameters:

quickAddNonZero

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

void quickAddNonZero(int index, double element)

Parameters:

zero

Makes nonzero tiny.

void zero(int index)

Parameters:

clean

set all small values to zero and return number remaining

int clean(double tolerance)

Parameters:

cleanAndPack

Same but packs down.

int cleanAndPack(double tolerance)

Parameters:

cleanAndPackSafe

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

int cleanAndPackSafe(double tolerance)

Parameters:

setPacked

Mark as packed.

void setPacked()

checkClear

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

void checkClear()

checkClean

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

void checkClean()

scan

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

int scan()

scan

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

int scan(int start, int end)

Parameters:

scan

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

int scan(double tolerance)

Parameters:

scan

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

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

Parameters:

scanAndPack

These are same but pack down.

int scanAndPack()

scanAndPack

int scanAndPack(int start, int end)

Parameters:

scanAndPack

int scanAndPack(double tolerance)

Parameters:

scanAndPack

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

Parameters:

createPacked

Create packed array.

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

Parameters:

createUnpacked

Create unpacked array.

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

Parameters:

createOneUnpackedElement

Create unpacked singleton.

void createOneUnpackedElement(int index, double element)

Parameters:

expand

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

void expand()

append

Append a CoinPackedVector to the end.

void append(const CoinPackedVectorBase & caboose)

Parameters:

append

Append a CoinIndexedVector to the end (with extra space)

void append(const CoinIndexedVector & caboose)

Parameters:

append

Append a CoinIndexedVector to the end and modify indices.

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

Parameters:

swap

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

void swap(int i, int j)

Parameters:

truncate

Throw away all entries in rows >= newSize.

void truncate(int newSize)

Parameters:

print

Print out.

void print()

operator+=

add value to every entry

void operator+=(double value)

Parameters:

operator-=

subtract value from every entry

void operator-=(double value)

Parameters:

operator*=

multiply every entry by value

void operator*=(double value)

Parameters:

operator/=

divide every entry by value (** 0 vanishes)

void operator/=(double value)

Parameters:

operator==

Equal.

bool operator==(const CoinPackedVectorBase & rhs)

Parameters:

operator!=

Not equal.

bool operator!=(const CoinPackedVectorBase & rhs)

Parameters:

operator==

Equal.

bool operator==(const CoinIndexedVector & rhs)

Parameters:

operator!=

Not equal.

bool operator!=(const CoinIndexedVector & rhs)

Parameters:

isApproximatelyEqual

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

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

Parameters:

getMaxIndex

Get value of maximum index.

int getMaxIndex()

getMinIndex

Get value of minimum index.

int getMinIndex()

sort

Sort the indexed storage vector (increasing indices).

void sort()

sortIncrIndex

void sortIncrIndex()

sortDecrIndex

void sortDecrIndex()

sortIncrElement

void sortIncrElement()

sortDecrElement

void sortDecrElement()

sortPacked

void sortPacked()

operator+

Return the sum of two indexed vectors.

CoinIndexedVector operator+(const CoinIndexedVector & op2)

Parameters:

operator-

Return the difference of two indexed vectors.

CoinIndexedVector operator-(const CoinIndexedVector & op2)

Parameters:

operator*

Return the element-wise product of two indexed vectors.

CoinIndexedVector operator*(const CoinIndexedVector & op2)

Parameters:

operator/

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

CoinIndexedVector operator/(const CoinIndexedVector & op2)

Parameters:

operator+=

The sum of two indexed vectors.

void operator+=(const CoinIndexedVector & op2)

Parameters:

operator-=

The difference of two indexed vectors.

void operator-=(const CoinIndexedVector & op2)

Parameters:

operator*=

The element-wise product of two indexed vectors.

void operator*=(const CoinIndexedVector & op2)

Parameters:

operator/=

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

void operator/=(const CoinIndexedVector & op2)

Parameters:

reserve

Reserve space.

void reserve(int n)

Parameters:

capacity

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

int capacity()

setCapacity

void setCapacity(int value)

Parameters:

setPackedMode

Sets packed mode.

void setPackedMode(bool yesNo)

Parameters:

packedMode

Gets packed mode.

bool packedMode()

CoinIndexedVector

Default constructor.

 CoinIndexedVector()

CoinIndexedVector

Alternate Constructors - set elements to vector of doubles.

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

Parameters:

CoinIndexedVector

Alternate Constructors - set elements to same scalar value.

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

Parameters:

CoinIndexedVector

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

 CoinIndexedVector(int size, const double * elements)

Parameters:

CoinIndexedVector

Alternate Constructors - just size.

 CoinIndexedVector(int size)

Parameters:

CoinIndexedVector

Copy constructor.

 CoinIndexedVector(const CoinIndexedVector & )

Parameters:

CoinIndexedVector

Copy constructor.2.

 CoinIndexedVector(const CoinIndexedVector * )

Parameters:

CoinIndexedVector

Copy constructor from a PackedVectorBase.

 CoinIndexedVector(const CoinPackedVectorBase & rhs)

Parameters:

~CoinIndexedVector

Destructor.

 ~CoinIndexedVector()

Source

Header: layer-0/CoinUtils/src/CoinIndexedVector.hpp