- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# CoinPackedVector Class Reference

Sparse Vector. More...

`#include <CoinPackedVector.hpp>`

Inheritance diagram for CoinPackedVector:

[legend]
Collaboration diagram for CoinPackedVector:

[legend]
List of all members.

## Public Member Functions
Get methods.
virtual int | getNumElements () const
| Get the size.
virtual const int * | getIndices () const
| Get indices of elements.
virtual const double * | getElements () const
| Get element values.
int * | getIndices ()
| Get indices of elements.
double * | getElements ()
| Get element values.
const int * | getOriginalPosition () const
| Get pointer to int * vector of original postions.
Set methods
void | clear ()
| Reset the vector (as if were just created an empty vector).
CoinPackedVector & | operator= (const CoinPackedVector &)
| Assignment operator.
CoinPackedVector & | operator= (const CoinPackedVectorBase &rhs)
| Assignment operator from a CoinPackedVectorBase.
void | assignVector (int size, int *&inds, double *&elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Assign the ownership of the arguments to this vector.
void | setVector (int size, const int *inds, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Set vector size, indices, and elements.
void | setConstant (int size, const int *inds, double elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Elements set to have the same scalar value.
void | setFull (int size, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Indices are not specified and are taken to be 0,1,.
void | setFullNonZero (int size, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Indices are not specified and are taken to be 0,1,.
void | setElement (int index, double element)
| Set an existing element in the packed vector The first argument is the "index" into the elements() array.
void | insert (int index, double element)
| Insert an element into the vector.
void | append (const CoinPackedVectorBase &caboose)
| Append a CoinPackedVector to the end.
void | swap (int i, int j)
| Swap values in positions i and j of indices and elements.
void | truncate (int newSize)
| Resize the packed vector to be the first newSize elements.
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`
Sorting
template<class CoinCompare3>
void | sort (const CoinCompare3 &tc)
| Sort the packed storage vector.
void | sortIncrIndex ()
| Sort the packed storage vector.
void | sortDecrIndex ()
| Sort the packed storage vector.
void | sortIncrElement ()
| Sort the packed storage vector.
void | sortDecrElement ()
| Sort the packed storage vector.
void | sortOriginalOrder ()
| Sort in original order.
Memory usage
void | reserve (int n)
| Reserve space.
int | capacity () const
| capacity returns the size which could be accomodated without having to reallocate storage.
Constructors and destructors
| CoinPackedVector (bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Default constructor.
| CoinPackedVector (int size, const int *inds, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Alternate Constructors - set elements to vector of doubles.
| CoinPackedVector (int capacity, int size, int *&inds, double *&elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Alternate Constructors - set elements to vector of doubles.
| CoinPackedVector (int size, const int *inds, double element, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Alternate Constructors - set elements to same scalar value.
| CoinPackedVector (int size, const double *elements, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
| Alternate Constructors - construct full storage with indices 0 through size-1.
| CoinPackedVector (const CoinPackedVector &)
| Copy constructor.
| CoinPackedVector (const CoinPackedVectorBase &rhs)
| Copy constructor from a PackedVectorBase.
virtual | ~CoinPackedVector ()
| Destructor.
## Private Member Functions
Private methods
void | gutsOfSetVector (int size, const int *inds, const double *elems, bool testForDuplicateIndex, const char *method)
| Copy internal date.
void | gutsOfSetConstant (int size, const int *inds, double value, bool testForDuplicateIndex, const char *method)
| Copy internal date.
## Private Attributes
Private member data
int * | indices_
| Vector indices.
double * | elements_
| Vector elements.
int | nElements_
| Size of indices and elements vectors.
int * | origIndices_
| original unsorted indices
int | capacity_
| Amount of memory allocated for indices_, origIndices_, and elements_.
## Friends
void | CoinPackedVectorUnitTest ()
| A function that tests the methods in the CoinPackedVector class.

## Detailed Description

Sparse Vector.

Stores vector of indices and associated element values. Supports sorting of vector while maintaining the original indices.

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
        CoinPackedVector 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 original position of index
        assert( r.originalPosition()[0]==0 );
        assert( r.originalPosition()[1]==1 );
        assert( r.originalPosition()[2]==2 );
        assert( r.originalPosition()[3]==3 );

        // 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.indices ()[0]== 0  );
        assert( r.elements()[0]== 1. );
        assert( r.indices ()[1]== 1  );
        assert( r.elements()[1]==10. );
        assert( r.indices ()[2]== 4  );
        assert( r.elements()[2]==40. );
        assert( r.indices ()[3]== 2  );
        assert( r.elements()[3]==50. );

        // access original position of index
        assert( r.originalPosition()[0]==2 );
        assert( r.originalPosition()[1]==0 );
        assert( r.originalPosition()[2]==1 );
        assert( r.originalPosition()[3]==3 );

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

        // Restore orignal sort order
        r.sortOriginalOrder();

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

        // Tests for equality and equivalence
        CoinPackedVector r1;
        r1=r;
        assert( r==r1 );
        assert( r.equivalent(r1) );
        r.sortIncrElement();
        assert( r!=r1 );
        assert( r.equivalent(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 117 of file CoinPackedVector.hpp.

## Constructor & Destructor Documentation

CoinPackedVector::CoinPackedVector | ( | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` | ) |

Default constructor.

CoinPackedVector::CoinPackedVector | ( | int | size,
|  | const int * | inds,
|  | const double * | elems,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

Alternate Constructors - set elements to vector of doubles.

This constructor copies the vectors provided as parameters.

CoinPackedVector::CoinPackedVector | ( | int | capacity,
|  | int | size,
|  | int *& | inds,
|  | double *& | elems,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

Alternate Constructors - set elements to vector of doubles.

This constructor takes ownership of the vectors passed as parameters. `inds` and `elems` will be NULL on return.

CoinPackedVector::CoinPackedVector | ( | int | size,
|  | const int * | inds,
|  | double | element,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

Alternate Constructors - set elements to same scalar value.

CoinPackedVector::CoinPackedVector | ( | int | size,
|  | const double * | elements,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

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

CoinPackedVector::CoinPackedVector | ( | const CoinPackedVector & |  | ) |

Copy constructor.

CoinPackedVector::CoinPackedVector | ( | const CoinPackedVectorBase & | rhs | ) |

Copy constructor from a PackedVectorBase.

virtual CoinPackedVector::~CoinPackedVector | ( |  | ) | `[virtual]`

Destructor.

## Member Function Documentation

virtual int CoinPackedVector::getNumElements | ( |  | ) | const`[inline, virtual]`

Get the size.

Implements CoinPackedVectorBase.

Definition at line 124 of file CoinPackedVector.hpp.

References nElements_.

Referenced by OsiColCut::infeasible(), operator-(), operator/(), and sparseDotProduct().

virtual const int* CoinPackedVector::getIndices | ( |  | ) | const`[inline, virtual]`

Get indices of elements.

Implements CoinPackedVectorBase.

Definition at line 126 of file CoinPackedVector.hpp.

References indices_.

Referenced by OsiColCut::infeasible().

virtual const double* CoinPackedVector::getElements | ( |  | ) | const`[inline, virtual]`

Get element values.

Implements CoinPackedVectorBase.

Definition at line 128 of file CoinPackedVector.hpp.

References elements_.

Referenced by OsiColCut::infeasible(), operator-(), operator/(), and sparseDotProduct().

int* CoinPackedVector::getIndices | ( |  | ) | `[inline]`

Get indices of elements.

Definition at line 130 of file CoinPackedVector.hpp.

References indices_.

double* CoinPackedVector::getElements | ( |  | ) | `[inline]`

Get element values.

Definition at line 132 of file CoinPackedVector.hpp.

References elements_.

const int* CoinPackedVector::getOriginalPosition | ( |  | ) | const`[inline]`

Get pointer to int * vector of original postions.

If the packed vector has not been sorted then this function returns the vector: 0, 1, 2, ..., size()-1.

Definition at line 136 of file CoinPackedVector.hpp.

References origIndices_.

void CoinPackedVector::clear | ( |  | ) |

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

Referenced by binaryOp().

CoinPackedVector& CoinPackedVector::operator= | ( | const CoinPackedVector & |  | ) |

Assignment operator.

NOTE: This operator keeps the current `testForDuplicateIndex` setting, and affter copying the data it acts accordingly.

CoinPackedVector& CoinPackedVector::operator= | ( | const CoinPackedVectorBase & | rhs | ) |

Assignment operator from a CoinPackedVectorBase.

NOTE: This operator keeps the current `testForDuplicateIndex` setting, and affter copying the data it acts accordingly.

Reimplemented from CoinPackedVectorBase.

void CoinPackedVector::assignVector | ( | int | size,
|  | int *& | inds,
|  | double *& | elems,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

Assign the ownership of the arguments to this vector.

Size is the length of both the indices and elements vectors. The indices and elements vectors are copied into this class instance's member data. The last argument indicates whether this vector will have to be tested for duplicate indices.

void CoinPackedVector::setVector | ( | int | size,
|  | const int * | inds,
|  | const double * | elems,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

Set vector size, indices, and elements.

Size is the length of both the indices and elements vectors. The indices and elements vectors are copied into this class instance's member data. The last argument specifies whether this vector will have to be checked for duplicate indices whenever that can happen.

Referenced by OsiColCut::setLbs(), and OsiColCut::setUbs().

void CoinPackedVector::setConstant | ( | int | size,
|  | const int * | inds,
|  | double | elems,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

Elements set to have the same scalar value.

void CoinPackedVector::setFull | ( | int | size,
|  | const double * | elems,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

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

..,size-1

void CoinPackedVector::setFullNonZero | ( | int | size,
|  | const double * | elems,
|  | bool | testForDuplicateIndex = `COIN_DEFAULT_VALUE_FOR_DUPLICATE` |
| ) |  |  |

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

..,size-1, but only where non zero

void CoinPackedVector::setElement | ( | int | index,
|  | double | element |
| ) |  |  |

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

void CoinPackedVector::insert | ( | int | index,
|  | double | element |
| ) |  |  |

Insert an element into the vector.

Referenced by binaryOp().

void CoinPackedVector::append | ( | const CoinPackedVectorBase & | caboose | ) |

Append a CoinPackedVector to the end.

void CoinPackedVector::swap | ( | int | i,
|  | int | j |
| ) |  |  |

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

void CoinPackedVector::truncate | ( | int | newSize | ) |

Resize the packed vector to be the first newSize elements.

Problem with truncate: what happens with origIndices_ ???

void CoinPackedVector::operator+= | ( | double | value | ) |

add `value` to every entry

void CoinPackedVector::operator-= | ( | double | value | ) |

subtract `value` from every entry

void CoinPackedVector::operator *= | ( | double | value | ) |

multiply every entry by `value`

void CoinPackedVector::operator/= | ( | double | value | ) |

divide every entry by `value`

template<class CoinCompare3>

void CoinPackedVector::sort | ( | const CoinCompare3 & | tc | ) | `[inline]`

Sort the packed storage vector.

Typcical usages:

           packedVector.sort(CoinIncrIndexOrdered());   //increasing indices
           packedVector.sort(CoinIncrElementOrdered()); // increasing elements

Definition at line 227 of file CoinPackedVector.hpp.

References CoinSort_3(), elements_, indices_, nElements_, and origIndices_.

void CoinPackedVector::sortIncrIndex | ( |  | ) | `[inline]`

Sort the packed storage vector.

Typcical usages:

           packedVector.sort(CoinIncrIndexOrdered());   //increasing indices
           packedVector.sort(CoinIncrElementOrdered()); // increasing elements

Definition at line 231 of file CoinPackedVector.hpp.

References CoinSort_3(), elements_, indices_, nElements_, and origIndices_.

Referenced by OsiRowCut::sortIncrIndex().

void CoinPackedVector::sortDecrIndex | ( |  | ) | `[inline]`

Sort the packed storage vector.

Typcical usages:

           packedVector.sort(CoinIncrIndexOrdered());   //increasing indices
           packedVector.sort(CoinIncrElementOrdered()); // increasing elements

Definition at line 235 of file CoinPackedVector.hpp.

References CoinSort_3(), elements_, indices_, nElements_, and origIndices_.

void CoinPackedVector::sortIncrElement | ( |  | ) | `[inline]`

Sort the packed storage vector.

Typcical usages:

           packedVector.sort(CoinIncrIndexOrdered());   //increasing indices
           packedVector.sort(CoinIncrElementOrdered()); // increasing elements

Definition at line 239 of file CoinPackedVector.hpp.

References CoinSort_3(), elements_, indices_, nElements_, and origIndices_.

void CoinPackedVector::sortDecrElement | ( |  | ) | `[inline]`

Sort the packed storage vector.

Typcical usages:

           packedVector.sort(CoinIncrIndexOrdered());   //increasing indices
           packedVector.sort(CoinIncrElementOrdered()); // increasing elements

Definition at line 243 of file CoinPackedVector.hpp.

References CoinSort_3(), elements_, indices_, nElements_, and origIndices_.

void CoinPackedVector::sortOriginalOrder | ( |  | ) |

Sort in original order.

If the vector has been sorted, then this method restores to its orignal sort order.

void CoinPackedVector::reserve | ( | int | n | ) |

Reserve space.

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

Referenced by binaryOp().

int CoinPackedVector::capacity | ( |  | ) | const`[inline]`

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

Definition at line 265 of file CoinPackedVector.hpp.

References capacity_.

void CoinPackedVector::gutsOfSetVector | ( | int | size,
|  | const int * | inds,
|  | const double * | elems,
|  | bool | testForDuplicateIndex,
|  | const char * | method |
| ) |  |  | `[private]`

Copy internal date.

void CoinPackedVector::gutsOfSetConstant | ( | int | size,
|  | const int * | inds,
|  | double | value,
|  | bool | testForDuplicateIndex,
|  | const char * | method |
| ) |  |  | `[private]`

Copy internal date.

## Friends And Related Function Documentation

void CoinPackedVectorUnitTest | ( |  | ) | `[friend]`

A function that tests the methods in the CoinPackedVector 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* CoinPackedVector::indices_`[private]`

Vector indices.

Definition at line 318 of file CoinPackedVector.hpp.

Referenced by getIndices(), sort(), sortDecrElement(), sortDecrIndex(), sortIncrElement(), and sortIncrIndex().

double* CoinPackedVector::elements_`[private]`

Vector elements.

Definition at line 320 of file CoinPackedVector.hpp.

Referenced by getElements(), sort(), sortDecrElement(), sortDecrIndex(), sortIncrElement(), and sortIncrIndex().

int CoinPackedVector::nElements_`[private]`

Size of indices and elements vectors.

Definition at line 322 of file CoinPackedVector.hpp.

Referenced by getNumElements(), sort(), sortDecrElement(), sortDecrIndex(), sortIncrElement(), and sortIncrIndex().

int* CoinPackedVector::origIndices_`[private]`

original unsorted indices

Definition at line 324 of file CoinPackedVector.hpp.

Referenced by getOriginalPosition(), sort(), sortDecrElement(), sortDecrIndex(), sortIncrElement(), and sortIncrIndex().

int CoinPackedVector::capacity_`[private]`

Amount of memory allocated for indices_, origIndices_, and elements_.

Definition at line 326 of file CoinPackedVector.hpp.

Referenced by capacity().

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

- /home/coin/SVN-release/Blis-0.91.0/CoinUtils/src/CoinPackedVector.hpp