Go to the documentation of this file.
6 #ifndef CoinIndexedVector_H
7 #define CoinIndexedVector_H
11 # pragma warning(disable:4786)
24 #define COIN_INDEXED_TINY_ELEMENT 1.0e-50
25 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-100
27 #define COIN_INDEXED_TINY_ELEMENT 1.0e-35
28 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-39
148 #ifndef CLP_NO_VECTOR
160 void borrowVector(
int size,
int numberIndices,
int* inds,
double* elems);
171 void setVector(
int numberIndices,
const int * inds,
const double * elems);
177 void setVector(
int size,
int numberIndices,
const int * inds,
const double * elems);
202 void add(
int index,
double element);
279 int scan(
int start,
int end,
double tolerance);
287 const double * elements);
290 const double * elements);
295 #ifndef CLP_NO_VECTOR
326 #ifndef CLP_NO_VECTOR
448 #ifndef CLP_NO_VECTOR
461 const int * inds,
const double * elems);
463 const int * inds,
const double * elems);
465 const int * inds,
const double * elems);
468 const int * inds,
double value);
526 {
return size_!=-1; }
576 {
array_=
new char [size];}
629 {
return reinterpret_cast<double *
> ((
size_>-2) ?
array_ : NULL); }
737 {
return reinterpret_cast<long double *
> ((
size_>-2) ?
array_ : NULL); }
791 {
return reinterpret_cast<int *
> ((
size_>-2) ?
array_ : NULL); }
899 {
return reinterpret_cast<unsigned int *
> ((
size_>-2) ?
array_ : NULL); }
953 {
return reinterpret_cast<void **
> ((
size_>-2) ?
array_ : NULL); }
1007 {
return reinterpret_cast<void **
> ((
size_>-2) ?
array_ : NULL); }
1012 inline void setSize(
int value)
1060 #ifndef COIN_PARTITIONS
1061 #define COIN_PARTITIONS 8
1116 int scan(
int partition,
double tolerance=0.0);
CoinFactorizationLongDoubleArrayWithLength & operator=(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Assignment operator.
int isApproximatelyEqual(const CoinIndexedVector &rhs, double tolerance=1.0e-8) const
Equal with a tolerance (returns -1 or position of inequality).
CoinIntArrayWithLength(const CoinIntArrayWithLength &rhs)
Copy constructor.
int offset_
Offset to get where new allocated array.
CoinIndexedVector(int size)
Alternate Constructors - just size.
CoinIndexedVector(const CoinIndexedVector &)
Copy constructor.
int scanAndPack(double tolerance)
void clearPartition(int partition)
Clear a partition.
int cleanAndPackSafe(double tolerance)
Same but packs down and is safe (i.e. if order is odd)
void setPackedMode(bool yesNo)
Sets packed mode.
int * getIndices()
Get element values.
void zero(int index)
Makes nonzero tiny.
int scan(int start, int end, double tolerance)
Scan dense region from start to < end and set up indices returns number found.
void allocate(const CoinArrayWithLength &rhs, int numberBytes)
Assignment with length - does not copy.
CoinArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size mode>0 size_ set to size and zeroe...
void switchOff()
Set the size to -1.
int numberPartitions_
Number of partitions (0 means off)
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength *rhs)
Copy constructor.2.
double * denseVector() const
Get the vector as a dense vector.
CoinFactorizationLongDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinFactorizationDoubleArrayWithLength & operator=(const CoinFactorizationDoubleArrayWithLength &rhs)
Assignment operator.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength &rhs)
Copy constructor.
int getSize() const
Get the size.
void clear()
Reset the vector (as if were just created an empty vector). This leaves arrays!
void setCapacity()
Set the capacity to >=0 if <=-2.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength *rhs)
Copy constructor.2.
CoinArrayWithLength & operator=(const CoinArrayWithLength &rhs)
Assignment operator.
CoinArrayWithLength()
Default constructor - NULL.
CoinDoubleArrayWithLength()
Default constructor - NULL.
int getSize() const
Get the size.
CoinArbitraryArrayWithLength(int length, int size)
Alternate Constructor - length in bytes - size_ -1.
void setSize(int value)
Set the size.
CoinArbitraryArrayWithLength & operator=(const CoinArbitraryArrayWithLength &rhs)
Assignment operator.
friend void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
int nElements_
Size of indices and packed elements vectors.
double CoinFactorizationDouble
void insert(int index, double element)
Insert an element into the vector.
void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
CoinIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinArrayWithLength(const CoinArrayWithLength *rhs)
Copy constructor.2.
bool packedMode_
If true then is operating in packed mode.
void operator*=(double value)
multiply every entry by value
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinPartitionedVector()
Default constructor.
CoinIntArrayWithLength(const CoinIntArrayWithLength *rhs)
Copy constructor.2.
CoinVoidStarArrayWithLength()
Default constructor - NULL.
CoinFactorizationDouble * conditionalNew(int sizeWanted)
Conditionally gets new array.
int getMinIndex() const
Get value of minimum index.
void setNumElements(int value)
Set the size.
void operator/=(double value)
divide every entry by value (** 0 vanishes)
void setSize(int value)
Set the size.
CoinDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
int scan(double tolerance)
Scan dense region and set up indices (returns number found).
~CoinIndexedVector()
Destructor.
void setNumElementsPartition(int partition, int value)
Set the size of a partition.
CoinArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinIndexedVector operator-(const CoinIndexedVector &op2)
Return the difference of two indexed vectors.
void truncate(int newSize)
Throw away all entries in rows >= newSize.
void ** array() const
Get Array.
double * array() const
Get Array.
CoinPartitionedVector(int size, const int *inds, const double *elems)
Alternate Constructors - set elements to vector of doubles.
CoinIndexedVector(int size, const double *elements)
Alternate Constructors - construct full storage with indices 0 through size-1.
~CoinPartitionedVector()
Destructor.
CoinFactorizationDouble * array() const
Get Array.
int getSize() const
Get the size.
void print() const
Scan dense region from start to < end and set up indices returns number found.
int clean(double tolerance)
set all small values to zero and return number remaining
void setPartitions(int number, const int *starts)
Setup partitions (needs end as well)
void setSize(int value)
Set the size.
int getSize() const
Get the size.
CoinFactorizationDoubleArrayWithLength()
Default constructor - NULL.
void quickAddNonZero(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.
CoinPartitionedVector(const CoinPartitionedVector &)
Copy constructor.
const double COIN_DBL_MIN
CoinIndexedVector(const CoinPackedVectorBase &rhs)
Copy constructor from a PackedVectorBase.
void setVector(int numberIndices, const int *inds, const double *elems)
Set vector numberIndices, indices, and elements.
void operator/=(const CoinIndexedVector &op2)
The element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes)
void operator+=(double value)
add value to every entry
bool operator==(const CoinIndexedVector &rhs) const
Equal.
double & operator[](int i) const
Access the i'th element of the full storage vector.
CoinPartitionedVector(const CoinPartitionedVector *)
Copy constructor.2.
CoinUnsignedIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
int getMaxIndex() const
Get value of maximum index.
int scanAndPack(int start, int end, double tolerance)
void gutsOfSetPackedVector(int size, int numberIndices, const int *inds, const double *elems)
int * array() const
Get Array.
void gutsOfSetConstant(int size, const int *inds, double value)
CoinFactorizationLongDouble * version.
void operator+=(const CoinIndexedVector &op2)
The sum of two indexed vectors.
CoinIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
int getNumPartitions() const
Get number of partitions.
CoinArbitraryArrayWithLength(int length=1)
Default constructor - NULL.
CoinPartitionedVector(int size, const int *inds, double element)
Alternate Constructors - set elements to same scalar value.
void setSize(int value)
Set the size.
void gutsOfSetVector(int size, const int *inds, const double *elems)
Copy internal data.
CoinBigIndexArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinIndexedVector operator+(const CoinIndexedVector &op2)
Return the sum of two indexed vectors.
int getSize() const
Get the size.
CoinBigIndexArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
void createUnpacked(int number, const int *indices, const double *elements)
Create unpacked array.
Pointer with length in bytes.
void computeNumberElements()
Add up number of elements in partitions.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength *rhs)
Copy constructor.2.
void checkClear()
For debug check vector is clear i.e. no elements.
CoinIndexedVector(int size, const int *inds, double element)
Alternate Constructors - set elements to same scalar value.
#define CoinSizeofAsInt(type)
Cube Root.
unsigned int * array() const
Get Array.
CoinBigIndex * array() const
Get Array.
int offset_
Offset of array.
void append(const CoinPackedVectorBase &caboose)
Append a CoinPackedVector to the end.
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 setSize(int value)
Set the size.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength &rhs)
Copy constructor.
char * conditionalNew(long sizeWanted)
Conditionally gets new array.
CoinPartitionedVector(int size, const double *elements)
Alternate Constructors - construct full storage with indices 0 through size-1.
void checkClean()
For debug check vector is clean i.e. elements match indices.
CoinIndexedVector & operator=(const CoinPackedVectorBase &rhs)
Assignment operator from a CoinPackedVectorBase.
CoinPartitionedVector & operator=(const CoinPartitionedVector &)
Assignment operator.
CoinVoidStarArrayWithLength & operator=(const CoinVoidStarArrayWithLength &rhs)
Assignment operator.
CoinVoidStarArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
int alignment_
Alignment wanted (power of 2)
void switchOn(int alignment=3)
Set the size to -2 and alignment.
int getSize() const
Get the size.
CoinPartitionedVector(int size)
Alternate Constructors - just size.
int getSize() const
Get the size.
void returnVector()
Return ownership of the arguments to this vector.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength *rhs)
Copy constructor.2.
void ** conditionalNew(int sizeWanted)
Conditionally gets new array.
void setIndexVector(int *array)
For very temporary use when user needs to borrow an index vector.
void setPacked()
Mark as packed.
double * elements_
Vector elements.
CoinUnsignedIntArrayWithLength & operator=(const CoinUnsignedIntArrayWithLength &rhs)
Assignment operator.
CoinArrayWithLength(const CoinArrayWithLength &rhs)
Copy constructor.
void setPersistence(int flag, int currentLength)
Does what is needed to set persistence.
CoinFactorizationDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
void append(CoinIndexedVector &other, int adjustIndex, bool zapElements=false)
Append a CoinIndexedVector to the end and modify indices.
bool switchedOn() const
See if persistence already on.
int cleanAndPack(double tolerance)
Same but packs down.
CoinDoubleArrayWithLength & operator=(const CoinDoubleArrayWithLength &rhs)
Assignment operator.
CoinIndexedVector()
Default constructor.
int * conditionalNew(int sizeWanted)
Conditionally gets new array.
int numberElementsPartition_[COIN_PARTITIONS]
Size of indices in a partition.
void createPacked(int number, const int *indices, const double *elements)
Create packed array.
void sort()
Sort the indexed storage vector (increasing indices).
void clear()
Zero out array.
void compact()
Add up number of elements in partitions and pack and get rid of partitions.
void getArray(int size)
Get array with alignment.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength &rhs)
Copy constructor.
void swap(int i, int j)
Swap values in positions i and j of indices and elements.
void borrowVector(int size, int numberIndices, int *inds, double *elems)
Borrow ownership of the arguments to this vector.
void checkClear()
For debug check vector is clear i.e. no elements.
void copy(const CoinArrayWithLength &rhs, int numberBytes=-1)
Assignment with length (if -1 use internal length)
void reallyFreeArray()
Really get rid of array with alignment.
Abstract base class for various sparse vectors.
void setSize(int value)
Set the size.
CoinIndexedVector & operator=(const CoinIndexedVector &)
Assignment operator.
void setDenseVector(double *array)
For very temporary use when user needs to borrow a dense vector.
void getCapacity(int numberBytes, int numberIfNeeded=-1)
Get enough space (if more needed then do at least needed)
void operator-=(double value)
subtract value from every entry
void setSize(int value)
Set the size.
CoinUnsignedIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void operator*=(const CoinIndexedVector &op2)
The element-wise product of two indexed vectors.
bool operator==(const CoinPackedVectorBase &rhs) const
Equal.
CoinIndexedVector operator*(const CoinIndexedVector &op2)
Return the element-wise product of two indexed vectors.
CoinFactorizationLongDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void expand()
This is mainly for testing - goes from packed to indexed.
void ** array() const
Get Array.
void setTempNumElementsPartition(int partition, int value)
Set the size of a partition (just for a tiny while)
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Copy constructor.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength &rhs)
Copy constructor.
int startPartition(int partition) const
Get starts.
CoinIntArrayWithLength()
Default constructor - NULL.
CoinFactorizationDouble * version.
CoinBigIndexArrayWithLength()
Default constructor - NULL.
const int * getIndices() const
Get indices of elements.
void swap(CoinArrayWithLength &other)
Swaps memory between two members.
unsigned int * conditionalNew(int sizeWanted)
Conditionally gets new array.
bool operator!=(const CoinIndexedVector &rhs) const
Not equal.
void operator-=(const CoinIndexedVector &op2)
The difference of two indexed vectors.
int getSize() const
Get the size.
int scan()
Scan dense region and set up indices (returns number found)
void quickAdd(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.
int capacity_
Amount of memory allocated for indices_, and elements_.
void empty()
Reset the vector (as if were just created an empty vector)
void setCapacity(int value)
int getNumElements() const
Get the size.
CoinIntArrayWithLength & operator=(const CoinIntArrayWithLength &rhs)
Assignment operator.
void conditionalDelete()
Conditionally deletes.
CoinVoidStarArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinFactorizationLongDoubleArrayWithLength()
Default constructor - NULL.
int capacity() const
capacity returns the size which could be accomodated without having to reallocate storage.
void setFull(int size, const double *elems)
Indices are not specified and are taken to be 0,1,...,size-1.
int rawSize() const
Get the size.
char * conditionalNew(int length, int sizeWanted)
Conditionally gets new array.
void createOneUnpackedElement(int index, double element)
Create unpacked singleton.
const int * startPartitions() const
Get starts.
int scanAndPack()
These are same but pack down.
CoinIndexedVector operator/(const CoinIndexedVector &op2)
Return the element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes)
#define COIN_INDEXED_TINY_ELEMENT
void clearAndKeep()
Reset the vector (as if were just created an empty vector). Keeps partitions.
void print() const
Print out.
bool operator!=(const CoinPackedVectorBase &rhs) const
Not equal.
void checkClean()
For debug check vector is clean i.e. elements match indices.
void setSize(int value)
Set the size.
void reserve(int n)
Reserve space.
CoinBigIndex * conditionalNew(int sizeWanted)
Conditionally gets new array.
void sort()
Sort the indexed storage vector (increasing indices).
double * conditionalNew(int sizeWanted)
Conditionally gets new array.
void setSize(int value)
Set the size.
CoinIndexedVector(int size, const int *inds, const double *elems)
Alternate Constructors - set elements to vector of doubles.
void gutsOfSetVector(int size, int numberIndices, const int *inds, const double *elems)
CoinBigIndex size_
Size of array in bytes.
int capacity() const
Get the capacity (just read it)
CoinBigIndexArrayWithLength & operator=(const CoinBigIndexArrayWithLength &rhs)
Assignment operator.
CoinIndexedVector(const CoinIndexedVector *)
Copy constructor.2.
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinFactorizationDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
int scanAndPack(int start, int end)
int scan(int start, int end)
Scan dense region from start to < end and set up indices returns number found.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength *rhs)
Copy constructor.2.
int * indices_
Vector indices.
int lengthInBytes_
Length in bytes.
int startPartition_[COIN_PARTITIONS+1]
Starts.
bool packedMode() const
Gets packed mode.
void extend(int newSize)
Extend a persistent array keeping data (size in bytes)
void setVector(int size, int numberIndices, const int *inds, const double *elems)
Set vector size, indices, and elements.
void reserve(int n)
Reserve space.
void setConstant(int size, const int *inds, double elems)
Elements set to have the same scalar value.
CoinUnsignedIntArrayWithLength()
Default constructor - NULL.
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength &rhs)
Copy constructor.
void copy(const CoinIndexedVector &rhs, double multiplier=1.0)
Copy the contents of one vector into another.
long double * conditionalNew(int sizeWanted)
Conditionally gets new array.
int getSize() const
Get the size.
const char * array() const
Get Array.
CoinDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
void quickInsert(int index, double element)
Insert a nonzero element into the vector.
void clearAndReset()
Reset the vector (as if were just created an empty vector). Gets rid of partitions.
void setElement(int index, double element)
Set an existing element in the indexed vector The first argument is the "index" into the elements() a...
long double * array() const
Get Array.
CoinArbitraryArrayWithLength(int length, int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
int getNumElements() const
Get the size.
~CoinArrayWithLength()
Destructor.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength &rhs)
Copy constructor.