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);
180 void setConstant(
int size,
const int * inds,
double elems);
183 void setFull(
int size,
const double * elems);
191 void insert(
int index,
double element);
202 void add(
int index,
double element);
250 int clean(
double tolerance);
272 int scan(
int start,
int end);
275 int scan(
double tolerance);
279 int scan(
int start,
int end,
double tolerance);
284 int scanAndPack(
int start,
int end,
double tolerance);
287 const double * elements);
290 const double * elements);
295 #ifndef CLP_NO_VECTOR 305 void swap(
int i,
int j);
326 #ifndef CLP_NO_VECTOR 448 #ifndef CLP_NO_VECTOR 459 void gutsOfSetVector(
int size,
461 const int * inds,
const double * elems);
462 void gutsOfSetVector(
int size,
int numberIndices,
463 const int * inds,
const double * elems);
464 void gutsOfSetPackedVector(
int size,
int numberIndices,
465 const int * inds,
const double * elems);
467 void gutsOfSetConstant(
int size,
468 const int * inds,
double value);
518 inline int getSize()
const 526 {
return size_!=-1; }
529 {
return (size_>-2) ? size_ : (-size_)-2; }
532 {
if (size_<=-2) size_ = (-size_)-2; }
535 {
return (size_>-2) ? array_ : NULL; }
540 inline void setSize(
int value)
548 { size_ = -2; alignment_=alignment;}
550 void setPersistence(
int flag,
int currentLength);
556 void extend(
int newSize);
561 char * conditionalNew(
long sizeWanted);
564 void conditionalDelete();
571 : array_(NULL),size_(-1),
offset_(0),alignment_(0)
575 : size_(-1),
offset_(0),alignment_(0)
576 { array_=
new char [size];}
597 void getArray(
int size);
599 void reallyFreeArray();
601 void getCapacity(
int numberBytes,
int numberIfNeeded=-1);
624 inline int getSize()
const 629 {
return reinterpret_cast<double *
> ((size_>-2) ? array_ : NULL); }
634 inline void setSize(
int value)
641 inline double * conditionalNew(
int sizeWanted)
650 { array_=NULL; size_=-1;}
678 inline int getSize()
const 688 inline void setSize(
int value)
704 { array_=NULL; size_=-1;}
732 inline int getSize()
const 737 {
return reinterpret_cast<long double *
> ((size_>-2) ? array_ : NULL); }
742 inline void setSize(
int value)
749 inline long double * conditionalNew(
int sizeWanted)
758 { array_=NULL; size_=-1;}
786 inline int getSize()
const 791 {
return reinterpret_cast<int *
> ((size_>-2) ? array_ : NULL); }
796 inline void setSize(
int value)
803 inline int * conditionalNew(
int sizeWanted)
812 { array_=NULL; size_=-1;}
840 inline int getSize()
const 845 {
return reinterpret_cast<CoinBigIndex *
> ((size_>-2) ? array_ : NULL); }
850 inline void setSize(
int value)
866 { array_=NULL; size_=-1;}
894 inline int getSize()
const 899 {
return reinterpret_cast<unsigned int *
> ((size_>-2) ? array_ : NULL); }
904 inline void setSize(
int value)
911 inline unsigned int * conditionalNew(
int sizeWanted)
920 { array_=NULL; size_=-1;}
948 inline int getSize()
const 953 {
return reinterpret_cast<void **
> ((size_>-2) ? array_ : NULL); }
958 inline void setSize(
int value)
965 inline void ** conditionalNew(
int sizeWanted)
974 { array_=NULL; size_=-1;}
1002 inline int getSize()
const 1004 {
return size_/lengthInBytes_; }
1007 {
return reinterpret_cast<void **
> ((size_>-2) ? array_ : NULL); }
1012 inline void setSize(
int value)
1014 { size_ = value*lengthInBytes_; }
1019 inline char * conditionalNew(
int length,
int sizeWanted)
1022 ((sizeWanted)*lengthInBytes_) : -1)); }
1029 { array_=NULL; size_=-1;lengthInBytes_=length;}
1032 { array_=
new char [size*length]; size_=-1; lengthInBytes_=length;}
1060 #ifndef COIN_PARTITIONS 1061 #define COIN_PARTITIONS 8 1067 return numberElementsPartition_[partition]; }
1070 {
return numberPartitions_; }
1075 return startPartition_[partition]; }
1078 {
return startPartition_; }
1086 inline void setNumElementsPartition(
int partition,
int value) { assert (partition<
COIN_PARTITIONS);
1088 if (numberPartitions_) numberElementsPartition_[partition]=value; }
1091 numberElementsPartition_[partition]=value; }
1093 void computeNumberElements();
1100 void setPartitions(
int number,
const int * starts);
1102 void clearAndReset();
1104 void clearAndKeep();
1106 void clearPartition(
int partition);
1116 int scan(
int partition,
double tolerance=0.0);
CoinDoubleArrayWithLength()
Default constructor - NULL.
int capacity() const
capacity returns the size which could be accomodated without having to reallocate storage...
int alignment_
Alignment wanted (power of 2)
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength *rhs)
Copy constructor.2.
int startPartition(int partition) const
Get starts.
CoinFactorizationDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
Pointer with length in bytes.
void setVector(int numberIndices, const int *inds, const double *elems)
Set vector numberIndices, indices, and elements.
void quickAddNonZero(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny...
CoinIndexedVector operator-(const CoinIndexedVector &op2)
Return the difference of two indexed vectors.
CoinIntArrayWithLength(const CoinIntArrayWithLength &rhs)
Copy constructor.
void reserve(int n)
Reserve space.
const int * startPartitions() const
Get starts.
void setConstant(int size, const int *inds, double elems)
Elements set to have the same scalar value.
double & operator[](int i) const
Access the i'th element of the full storage vector.
void operator+=(double value)
add value to every entry
int * indices_
Vector indices.
int getNumElements() const
Get the size.
int getMaxIndex() const
Get value of maximum index.
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Copy constructor.
char * conditionalNew(long sizeWanted)
Conditionally gets new array.
bool switchedOn() const
See if persistence already on.
void copy(const CoinIndexedVector &rhs, double multiplier=1.0)
Copy the contents of one vector into another.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength &rhs)
Copy constructor.
CoinArbitraryArrayWithLength(int length, int size)
Alternate Constructor - length in bytes - size_ -1.
void switchOff()
Set the size to -1.
void setElement(int index, double element)
Set an existing element in the indexed vector The first argument is the "index" into the elements() a...
int offset_
Offset to get where new allocated array.
CoinFactorizationDouble * array() const
Get Array.
int isApproximatelyEqual(const CoinIndexedVector &rhs, double tolerance=1.0e-8) const
Equal with a tolerance (returns -1 or position of inequality).
CoinFactorizationDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
int numberPartitions_
Number of partitions (0 means off)
CoinUnsignedIntArrayWithLength & operator=(const CoinUnsignedIntArrayWithLength &rhs)
Assignment operator.
void add(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny...
CoinIndexedVector operator+(const CoinIndexedVector &op2)
Return the sum of two indexed vectors.
void checkClear()
For debug check vector is clear i.e. no elements.
void zero(int index)
Makes nonzero tiny.
CoinArbitraryArrayWithLength & operator=(const CoinArbitraryArrayWithLength &rhs)
Assignment operator.
CoinBigIndexArrayWithLength()
Default constructor - NULL.
long double * array() const
Get Array.
int rawSize() const
Get the size.
void setCapacity()
Set the capacity to >=0 if <=-2.
CoinUnsignedIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
void setPackedMode(bool yesNo)
Sets packed mode.
void setIndexVector(int *array)
For very temporary use when user needs to borrow an index vector.
double * elements_
Vector elements.
bool packedMode_
If true then is operating in packed mode.
CoinBigIndex * array() const
Get Array.
double * denseVector() const
Get the vector as a dense vector.
void returnVector()
Return ownership of the arguments to this vector.
CoinFactorizationLongDoubleArrayWithLength()
Default constructor - NULL.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength *rhs)
Copy constructor.2.
void operator*=(double value)
multiply every entry by value
int * array() const
Get Array.
const double COIN_DBL_MIN
CoinArbitraryArrayWithLength(int length=1)
Default constructor - NULL.
int nElements_
Size of indices and packed elements vectors.
Abstract base class for various sparse vectors.
void setNumElements(int value)
Set the size.
CoinUnsignedIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void swap(int i, int j)
Swap values in positions i and j of indices and elements.
CoinIntArrayWithLength(const CoinIntArrayWithLength *rhs)
Copy constructor.2.
void borrowVector(int size, int numberIndices, int *inds, double *elems)
Borrow ownership of the arguments to this vector.
void operator-=(double value)
subtract value from every entry
int cleanAndPack(double tolerance)
Same but packs down.
~CoinIndexedVector()
Destructor.
#define CoinSizeofAsInt(type)
Cube Root.
double CoinFactorizationDouble
CoinVoidStarArrayWithLength()
Default constructor - NULL.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength &rhs)
Copy constructor.
CoinIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void expand()
This is mainly for testing - goes from packed to indexed.
CoinBigIndexArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
int clean(double tolerance)
set all small values to zero and return number remaining
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength &rhs)
Copy constructor.
int scan()
Scan dense region and set up indices (returns number found)
CoinIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
int capacity_
Amount of memory allocated for indices_, and elements_.
CoinVoidStarArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinArrayWithLength & operator=(const CoinArrayWithLength &rhs)
Assignment operator.
double * array() const
Get Array.
void createOneUnpackedElement(int index, double element)
Create unpacked singleton.
void createUnpacked(int number, const int *indices, const double *elements)
Create unpacked array.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength *rhs)
Copy constructor.2.
int getNumElements() const
Get the size.
CoinIndexedVector operator/(const CoinIndexedVector &op2)
Return the element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes) ...
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength *rhs)
Copy constructor.2.
CoinIntArrayWithLength & operator=(const CoinIntArrayWithLength &rhs)
Assignment operator.
void empty()
Reset the vector (as if were just created an empty vector)
CoinBigIndex size_
Size of array in bytes.
void append(const CoinPackedVectorBase &caboose)
Append a CoinPackedVector to the end.
CoinVoidStarArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void setFull(int size, const double *elems)
Indices are not specified and are taken to be 0,1,...,size-1.
void sort()
Sort the indexed storage vector (increasing indices).
bool operator!=(const CoinPackedVectorBase &rhs) const
Not equal.
CoinFactorizationLongDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
void print() const
Print out.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength *rhs)
Copy constructor.2.
CoinArrayWithLength()
Default constructor - NULL.
int offset_
Offset of array.
CoinDoubleArrayWithLength & operator=(const CoinDoubleArrayWithLength &rhs)
Assignment operator.
CoinIntArrayWithLength()
Default constructor - NULL.
const char * array() const
Get Array.
void checkClean()
For debug check vector is clean i.e. elements match indices.
CoinDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void ** array() const
Get Array.
CoinFactorizationDoubleArrayWithLength()
Default constructor - NULL.
CoinUnsignedIntArrayWithLength()
Default constructor - NULL.
unsigned int * array() const
Get Array.
CoinVoidStarArrayWithLength & operator=(const CoinVoidStarArrayWithLength &rhs)
Assignment operator.
void quickInsert(int index, double element)
Insert a nonzero element into the vector.
void switchOn(int alignment=3)
Set the size to -2 and alignment.
CoinFactorizationDouble * version.
bool packedMode() const
Gets packed mode.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength &rhs)
Copy constructor.
void setPacked()
Mark as packed.
CoinFactorizationLongDouble * version.
CoinFactorizationLongDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void createPacked(int number, const int *indices, const double *elements)
Create packed array.
int * getIndices()
Get element values.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength &rhs)
Copy constructor.
CoinIndexedVector()
Default constructor.
CoinFactorizationDoubleArrayWithLength & operator=(const CoinFactorizationDoubleArrayWithLength &rhs)
Assignment operator.
int cleanAndPackSafe(double tolerance)
Same but packs down and is safe (i.e. if order is odd)
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...
void setTempNumElementsPartition(int partition, int value)
Set the size of a partition (just for a tiny while)
CoinDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
CoinBigIndexArrayWithLength & operator=(const CoinBigIndexArrayWithLength &rhs)
Assignment operator.
CoinIndexedVector operator*(const CoinIndexedVector &op2)
Return the element-wise product of two indexed vectors.
CoinIndexedVector & operator=(const CoinIndexedVector &)
Assignment operator.
int capacity() const
Get the capacity (just read it)
void quickAdd(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny...
CoinFactorizationLongDoubleArrayWithLength & operator=(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Assignment operator.
bool operator==(const CoinPackedVectorBase &rhs) const
Equal.
void clear()
Reset the vector (as if were just created an empty vector). This leaves arrays!
void setDenseVector(double *array)
For very temporary use when user needs to borrow a dense vector.
const int * getIndices() const
Get indices of elements.
void setCapacity(int value)
#define COIN_INDEXED_TINY_ELEMENT
void operator/=(double value)
divide every entry by value (** 0 vanishes)
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength &rhs)
Copy constructor.
int getNumPartitions() const
Get number of partitions.
friend void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
void insert(int index, double element)
Insert an element into the vector.
void ** array() const
Get Array.
CoinBigIndexArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
int scanAndPack()
These are same but pack down.
int getMinIndex() const
Get value of minimum index.
void truncate(int newSize)
Throw away all entries in rows >= newSize.