CoinUtils
trunk
|
00001 /* $Id$ */ 00002 // Copyright (C) 2000, International Business Machines 00003 // Corporation and others. All Rights Reserved. 00004 // This code is licensed under the terms of the Eclipse Public License (EPL). 00005 00006 #ifndef CoinIndexedVector_H 00007 #define CoinIndexedVector_H 00008 00009 #if defined(_MSC_VER) 00010 // Turn off compiler warning about long names 00011 # pragma warning(disable:4786) 00012 #endif 00013 00014 #include <map> 00015 #include "CoinFinite.hpp" 00016 #ifndef CLP_NO_VECTOR 00017 #include "CoinPackedVectorBase.hpp" 00018 #endif 00019 #include "CoinSort.hpp" 00020 #include "CoinHelperFunctions.hpp" 00021 #include <cassert> 00022 00023 #ifndef COIN_FLOAT 00024 #define COIN_INDEXED_TINY_ELEMENT 1.0e-50 00025 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-100 00026 #else 00027 #define COIN_INDEXED_TINY_ELEMENT 1.0e-35 00028 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-39 00029 #endif 00030 00104 class CoinIndexedVector { 00105 friend void CoinIndexedVectorUnitTest(); 00106 00107 public: 00110 00111 inline int getNumElements() const { return nElements_; } 00113 inline const int * getIndices() const { return indices_; } 00115 // ** No longer supported virtual const double * getElements() const ; 00117 inline int * getIndices() { return indices_; } 00121 inline double * denseVector() const { return elements_; } 00123 inline void setDenseVector(double * array) 00124 { elements_ = array;} 00126 inline void setIndexVector(int * array) 00127 { indices_ = array;} 00130 double & operator[](int i) const; 00131 00133 00134 //------------------------------------------------------------------- 00135 // Set indices and elements 00136 //------------------------------------------------------------------- 00139 00140 inline void setNumElements(int value) { nElements_ = value; 00141 if (!nElements_) packedMode_=false;} 00143 void clear(); 00145 void empty(); 00147 CoinIndexedVector & operator=(const CoinIndexedVector &); 00148 #ifndef CLP_NO_VECTOR 00149 00151 CoinIndexedVector & operator=(const CoinPackedVectorBase & rhs); 00152 #endif 00153 00156 void copy(const CoinIndexedVector & rhs, double multiplier=1.0); 00157 00160 void borrowVector(int size, int numberIndices, int* inds, double* elems); 00161 00165 void returnVector(); 00166 00171 void setVector(int numberIndices, const int * inds, const double * elems); 00172 00177 void setVector(int size, int numberIndices, const int * inds, const double * elems); 00178 00180 void setConstant(int size, const int * inds, double elems); 00181 00183 void setFull(int size, const double * elems); 00184 00188 void setElement(int index, double element); 00189 00191 void insert(int index, double element); 00193 inline void quickInsert(int index, double element) 00194 { 00195 assert (!elements_[index]); 00196 indices_[nElements_++] = index; 00197 assert (nElements_<=capacity_); 00198 elements_[index] = element; 00199 } 00202 void add(int index, double element); 00206 inline void quickAdd(int index, double element) 00207 { 00208 if (elements_[index]) { 00209 element += elements_[index]; 00210 if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) { 00211 elements_[index] = element; 00212 } else { 00213 elements_[index] = 1.0e-100; 00214 } 00215 } else if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) { 00216 indices_[nElements_++] = index; 00217 assert (nElements_<=capacity_); 00218 elements_[index] = element; 00219 } 00220 } 00225 inline void quickAddNonZero(int index, double element) 00226 { 00227 assert (element); 00228 if (elements_[index]) { 00229 element += elements_[index]; 00230 if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) { 00231 elements_[index] = element; 00232 } else { 00233 elements_[index] = COIN_DBL_MIN; 00234 } 00235 } else { 00236 indices_[nElements_++] = index; 00237 assert (nElements_<=capacity_); 00238 elements_[index] = element; 00239 } 00240 } 00243 inline void zero(int index) 00244 { 00245 if (elements_[index]) 00246 elements_[index] = COIN_DBL_MIN; 00247 } 00250 int clean(double tolerance); 00252 int cleanAndPack(double tolerance); 00254 int cleanAndPackSafe(double tolerance); 00256 inline void setPacked() 00257 { packedMode_ = true;} 00259 void checkClear(); 00261 void checkClean(); 00263 int scan(); 00267 int scan(int start, int end); 00270 int scan(double tolerance); 00274 int scan(int start, int end, double tolerance); 00276 int scanAndPack(); 00277 int scanAndPack(int start, int end); 00278 int scanAndPack(double tolerance); 00279 int scanAndPack(int start, int end, double tolerance); 00281 void createPacked(int number, const int * indices, 00282 const double * elements); 00284 void createUnpacked(int number, const int * indices, 00285 const double * elements); 00287 void createOneUnpackedElement(int index, double element); 00289 void expand(); 00290 #ifndef CLP_NO_VECTOR 00291 00292 void append(const CoinPackedVectorBase & caboose); 00293 #endif 00294 00295 void append(const CoinIndexedVector & caboose); 00297 void append(CoinIndexedVector & other,int adjustIndex,bool zapElements=false); 00298 00300 void swap(int i, int j); 00301 00303 void truncate(int newSize); 00305 void print() const; 00307 00309 00310 void operator+=(double value); 00312 void operator-=(double value); 00314 void operator*=(double value); 00316 void operator/=(double value); 00318 00321 #ifndef CLP_NO_VECTOR 00322 00324 bool operator==(const CoinPackedVectorBase & rhs) const; 00326 bool operator!=(const CoinPackedVectorBase & rhs) const; 00327 #endif 00328 00330 bool operator==(const CoinIndexedVector & rhs) const; 00332 bool operator!=(const CoinIndexedVector & rhs) const; 00334 int isApproximatelyEqual(const CoinIndexedVector & rhs, double tolerance=1.0e-8) const; 00336 00339 00340 int getMaxIndex() const; 00342 int getMinIndex() const; 00344 00345 00349 void sort() 00350 { std::sort(indices_,indices_+nElements_); } 00351 00352 void sortIncrIndex() 00353 { std::sort(indices_,indices_+nElements_); } 00354 00355 void sortDecrIndex(); 00356 00357 void sortIncrElement(); 00358 00359 void sortDecrElement(); 00360 void sortPacked(); 00361 00363 00364 //############################################################################# 00365 00377 00378 CoinIndexedVector operator+( 00379 const CoinIndexedVector& op2); 00380 00382 CoinIndexedVector operator-( 00383 const CoinIndexedVector& op2); 00384 00386 CoinIndexedVector operator*( 00387 const CoinIndexedVector& op2); 00388 00390 CoinIndexedVector operator/( 00391 const CoinIndexedVector& op2); 00393 void operator+=(const CoinIndexedVector& op2); 00394 00396 void operator-=( const CoinIndexedVector& op2); 00397 00399 void operator*=(const CoinIndexedVector& op2); 00400 00402 void operator/=(const CoinIndexedVector& op2); 00404 00411 void reserve(int n); 00415 int capacity() const { return capacity_; } 00417 inline void setPackedMode(bool yesNo) 00418 { packedMode_=yesNo;} 00420 inline bool packedMode() const 00421 { return packedMode_;} 00423 00427 CoinIndexedVector(); 00429 CoinIndexedVector(int size, const int * inds, const double * elems); 00431 CoinIndexedVector(int size, const int * inds, double element); 00434 CoinIndexedVector(int size, const double * elements); 00436 CoinIndexedVector(int size); 00438 CoinIndexedVector(const CoinIndexedVector &); 00440 CoinIndexedVector(const CoinIndexedVector *); 00441 #ifndef CLP_NO_VECTOR 00442 00443 CoinIndexedVector(const CoinPackedVectorBase & rhs); 00444 #endif 00445 00446 ~CoinIndexedVector (); 00448 00449 private: 00452 00453 void gutsOfSetVector(int size, 00454 const int * inds, const double * elems); 00455 void gutsOfSetVector(int size, int numberIndices, 00456 const int * inds, const double * elems); 00457 void gutsOfSetPackedVector(int size, int numberIndices, 00458 const int * inds, const double * elems); 00460 void gutsOfSetConstant(int size, 00461 const int * inds, double value); 00463 00464 protected: 00467 00468 int * indices_; 00470 double * elements_; 00472 int nElements_; 00474 int capacity_; 00476 int offset_; 00478 bool packedMode_; 00480 }; 00481 00482 //############################################################################# 00488 void 00489 CoinIndexedVectorUnitTest(); 00506 class CoinArrayWithLength { 00507 00508 public: 00511 00512 inline int getSize() const 00513 { return size_; } 00515 inline int rawSize() const 00516 { return size_; } 00518 inline bool switchedOn() const 00519 { return size_!=-1; } 00521 inline int capacity() const 00522 { return (size_>-2) ? size_ : (-size_)-2; } 00524 inline void setCapacity() 00525 { if (size_<=-2) size_ = (-size_)-2; } 00527 inline const char * array() const 00528 { return (size_>-2) ? array_ : NULL; } 00530 00533 00534 inline void setSize(int value) 00535 { size_ = value; } 00537 inline void switchOff() 00538 { size_ = -1; } 00540 inline void switchOn(int alignment=3) 00541 { size_ = -2; alignment_=alignment;} 00543 void setPersistence(int flag,int currentLength); 00545 void clear(); 00547 void swap(CoinArrayWithLength & other); 00549 void extend(int newSize); 00551 00554 00555 char * conditionalNew(long sizeWanted); 00557 void conditionalDelete(); 00559 00563 inline CoinArrayWithLength() 00564 : array_(NULL),size_(-1),offset_(0),alignment_(0) 00565 { } 00567 inline CoinArrayWithLength(int size) 00568 : size_(-1),offset_(0),alignment_(0) 00569 { array_=new char [size];} 00576 CoinArrayWithLength(int size, int mode); 00578 CoinArrayWithLength(const CoinArrayWithLength & rhs); 00580 CoinArrayWithLength(const CoinArrayWithLength * rhs); 00582 CoinArrayWithLength& operator=(const CoinArrayWithLength & rhs); 00584 void copy(const CoinArrayWithLength & rhs, int numberBytes=-1); 00586 void allocate(const CoinArrayWithLength & rhs, int numberBytes); 00588 ~CoinArrayWithLength (); 00590 void getArray(int size); 00592 void reallyFreeArray(); 00594 void getCapacity(int numberBytes,int numberIfNeeded=-1); 00596 00597 protected: 00600 00601 char * array_; 00603 CoinBigIndex size_; 00605 int offset_; 00607 int alignment_; 00609 }; 00611 00612 class CoinDoubleArrayWithLength : public CoinArrayWithLength { 00613 00614 public: 00617 00618 inline int getSize() const 00619 { return size_/CoinSizeofAsInt(double); } 00621 inline double * array() const 00622 { return reinterpret_cast<double *> ((size_>-2) ? array_ : NULL); } 00624 00627 00628 inline void setSize(int value) 00629 { size_ = value*CoinSizeofAsInt(double); } 00631 00634 00635 inline double * conditionalNew(int sizeWanted) 00636 { return reinterpret_cast<double *> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> ((sizeWanted)*CoinSizeofAsInt(double)) : -1)); } 00638 00642 inline CoinDoubleArrayWithLength() 00643 { array_=NULL; size_=-1;} 00645 inline CoinDoubleArrayWithLength(int size) 00646 { array_=new char [size*CoinSizeofAsInt(double)]; size_=-1;} 00651 inline CoinDoubleArrayWithLength(int size, int mode) 00652 : CoinArrayWithLength(size*CoinSizeofAsInt(double),mode) {} 00654 inline CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength & rhs) 00655 : CoinArrayWithLength(rhs) {} 00657 inline CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength * rhs) 00658 : CoinArrayWithLength(rhs) {} 00660 inline CoinDoubleArrayWithLength& operator=(const CoinDoubleArrayWithLength & rhs) 00661 { CoinArrayWithLength::operator=(rhs); return *this;} 00663 }; 00665 00666 class CoinFactorizationDoubleArrayWithLength : public CoinArrayWithLength { 00667 00668 public: 00671 00672 inline int getSize() const 00673 { return size_/CoinSizeofAsInt(CoinFactorizationDouble); } 00675 inline CoinFactorizationDouble * array() const 00676 { return reinterpret_cast<CoinFactorizationDouble *> ((size_>-2) ? array_ : NULL); } 00678 00681 00682 inline void setSize(int value) 00683 { size_ = value*CoinSizeofAsInt(CoinFactorizationDouble); } 00685 00688 00689 inline CoinFactorizationDouble * conditionalNew(int sizeWanted) 00690 { return reinterpret_cast<CoinFactorizationDouble *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(CoinFactorizationDouble)) : -1)); } 00692 00696 inline CoinFactorizationDoubleArrayWithLength() 00697 { array_=NULL; size_=-1;} 00699 inline CoinFactorizationDoubleArrayWithLength(int size) 00700 { array_=new char [size*CoinSizeofAsInt(CoinFactorizationDouble)]; size_=-1;} 00705 inline CoinFactorizationDoubleArrayWithLength(int size, int mode) 00706 : CoinArrayWithLength(size*CoinSizeofAsInt(CoinFactorizationDouble),mode) {} 00708 inline CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength & rhs) 00709 : CoinArrayWithLength(rhs) {} 00711 inline CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength * rhs) 00712 : CoinArrayWithLength(rhs) {} 00714 inline CoinFactorizationDoubleArrayWithLength& operator=(const CoinFactorizationDoubleArrayWithLength & rhs) 00715 { CoinArrayWithLength::operator=(rhs); return *this;} 00717 }; 00719 00720 class CoinFactorizationLongDoubleArrayWithLength : public CoinArrayWithLength { 00721 00722 public: 00725 00726 inline int getSize() const 00727 { return size_/CoinSizeofAsInt(long double); } 00729 inline long double * array() const 00730 { return reinterpret_cast<long double *> ((size_>-2) ? array_ : NULL); } 00732 00735 00736 inline void setSize(int value) 00737 { size_ = value*CoinSizeofAsInt(long double); } 00739 00742 00743 inline long double * conditionalNew(int sizeWanted) 00744 { return reinterpret_cast<long double *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(long double)) : -1)); } 00746 00750 inline CoinFactorizationLongDoubleArrayWithLength() 00751 { array_=NULL; size_=-1;} 00753 inline CoinFactorizationLongDoubleArrayWithLength(int size) 00754 { array_=new char [size*CoinSizeofAsInt(long double)]; size_=-1;} 00759 inline CoinFactorizationLongDoubleArrayWithLength(int size, int mode) 00760 : CoinArrayWithLength(size*CoinSizeofAsInt(long double),mode) {} 00762 inline CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength & rhs) 00763 : CoinArrayWithLength(rhs) {} 00765 inline CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength * rhs) 00766 : CoinArrayWithLength(rhs) {} 00768 inline CoinFactorizationLongDoubleArrayWithLength& operator=(const CoinFactorizationLongDoubleArrayWithLength & rhs) 00769 { CoinArrayWithLength::operator=(rhs); return *this;} 00771 }; 00773 00774 class CoinIntArrayWithLength : public CoinArrayWithLength { 00775 00776 public: 00779 00780 inline int getSize() const 00781 { return size_/CoinSizeofAsInt(int); } 00783 inline int * array() const 00784 { return reinterpret_cast<int *> ((size_>-2) ? array_ : NULL); } 00786 00789 00790 inline void setSize(int value) 00791 { size_ = value*CoinSizeofAsInt(int); } 00793 00796 00797 inline int * conditionalNew(int sizeWanted) 00798 { return reinterpret_cast<int *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(int)) : -1)); } 00800 00804 inline CoinIntArrayWithLength() 00805 { array_=NULL; size_=-1;} 00807 inline CoinIntArrayWithLength(int size) 00808 { array_=new char [size*CoinSizeofAsInt(int)]; size_=-1;} 00813 inline CoinIntArrayWithLength(int size, int mode) 00814 : CoinArrayWithLength(size*CoinSizeofAsInt(int),mode) {} 00816 inline CoinIntArrayWithLength(const CoinIntArrayWithLength & rhs) 00817 : CoinArrayWithLength(rhs) {} 00819 inline CoinIntArrayWithLength(const CoinIntArrayWithLength * rhs) 00820 : CoinArrayWithLength(rhs) {} 00822 inline CoinIntArrayWithLength& operator=(const CoinIntArrayWithLength & rhs) 00823 { CoinArrayWithLength::operator=(rhs); return *this;} 00825 }; 00827 00828 class CoinBigIndexArrayWithLength : public CoinArrayWithLength { 00829 00830 public: 00833 00834 inline int getSize() const 00835 { return size_/CoinSizeofAsInt(CoinBigIndex); } 00837 inline CoinBigIndex * array() const 00838 { return reinterpret_cast<CoinBigIndex *> ((size_>-2) ? array_ : NULL); } 00840 00843 00844 inline void setSize(int value) 00845 { size_ = value*CoinSizeofAsInt(CoinBigIndex); } 00847 00850 00851 inline CoinBigIndex * conditionalNew(int sizeWanted) 00852 { return reinterpret_cast<CoinBigIndex *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(CoinBigIndex)) : -1)); } 00854 00858 inline CoinBigIndexArrayWithLength() 00859 { array_=NULL; size_=-1;} 00861 inline CoinBigIndexArrayWithLength(int size) 00862 { array_=new char [size*CoinSizeofAsInt(CoinBigIndex)]; size_=-1;} 00867 inline CoinBigIndexArrayWithLength(int size, int mode) 00868 : CoinArrayWithLength(size*CoinSizeofAsInt(CoinBigIndex),mode) {} 00870 inline CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength & rhs) 00871 : CoinArrayWithLength(rhs) {} 00873 inline CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength * rhs) 00874 : CoinArrayWithLength(rhs) {} 00876 inline CoinBigIndexArrayWithLength& operator=(const CoinBigIndexArrayWithLength & rhs) 00877 { CoinArrayWithLength::operator=(rhs); return *this;} 00879 }; 00881 00882 class CoinUnsignedIntArrayWithLength : public CoinArrayWithLength { 00883 00884 public: 00887 00888 inline int getSize() const 00889 { return size_/CoinSizeofAsInt(unsigned int); } 00891 inline unsigned int * array() const 00892 { return reinterpret_cast<unsigned int *> ((size_>-2) ? array_ : NULL); } 00894 00897 00898 inline void setSize(int value) 00899 { size_ = value*CoinSizeofAsInt(unsigned int); } 00901 00904 00905 inline unsigned int * conditionalNew(int sizeWanted) 00906 { return reinterpret_cast<unsigned int *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(unsigned int)) : -1)); } 00908 00912 inline CoinUnsignedIntArrayWithLength() 00913 { array_=NULL; size_=-1;} 00915 inline CoinUnsignedIntArrayWithLength(int size) 00916 { array_=new char [size*CoinSizeofAsInt(unsigned int)]; size_=-1;} 00921 inline CoinUnsignedIntArrayWithLength(int size, int mode) 00922 : CoinArrayWithLength(size*CoinSizeofAsInt(unsigned int),mode) {} 00924 inline CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength & rhs) 00925 : CoinArrayWithLength(rhs) {} 00927 inline CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength * rhs) 00928 : CoinArrayWithLength(rhs) {} 00930 inline CoinUnsignedIntArrayWithLength& operator=(const CoinUnsignedIntArrayWithLength & rhs) 00931 { CoinArrayWithLength::operator=(rhs); return *this;} 00933 }; 00935 00936 class CoinVoidStarArrayWithLength : public CoinArrayWithLength { 00937 00938 public: 00941 00942 inline int getSize() const 00943 { return size_/CoinSizeofAsInt(void *); } 00945 inline void ** array() const 00946 { return reinterpret_cast<void **> ((size_>-2) ? array_ : NULL); } 00948 00951 00952 inline void setSize(int value) 00953 { size_ = value*CoinSizeofAsInt(void *); } 00955 00958 00959 inline void ** conditionalNew(int sizeWanted) 00960 { return reinterpret_cast<void **> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> ((sizeWanted)*CoinSizeofAsInt(void *)) : -1)); } 00962 00966 inline CoinVoidStarArrayWithLength() 00967 { array_=NULL; size_=-1;} 00969 inline CoinVoidStarArrayWithLength(int size) 00970 { array_=new char [size*CoinSizeofAsInt(void *)]; size_=-1;} 00975 inline CoinVoidStarArrayWithLength(int size, int mode) 00976 : CoinArrayWithLength(size*CoinSizeofAsInt(void *),mode) {} 00978 inline CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength & rhs) 00979 : CoinArrayWithLength(rhs) {} 00981 inline CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength * rhs) 00982 : CoinArrayWithLength(rhs) {} 00984 inline CoinVoidStarArrayWithLength& operator=(const CoinVoidStarArrayWithLength & rhs) 00985 { CoinArrayWithLength::operator=(rhs); return *this;} 00987 }; 00989 00990 class CoinArbitraryArrayWithLength : public CoinArrayWithLength { 00991 00992 public: 00995 00996 inline int getSize() const 00997 { return size_/lengthInBytes_; } 00999 inline void ** array() const 01000 { return reinterpret_cast<void **> ((size_>-2) ? array_ : NULL); } 01002 01005 01006 inline void setSize(int value) 01007 { size_ = value*lengthInBytes_; } 01009 01012 01013 inline char * conditionalNew(int length, int sizeWanted) 01014 { lengthInBytes_=length;return reinterpret_cast<char *> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> 01015 ((sizeWanted)*lengthInBytes_) : -1)); } 01017 01021 inline CoinArbitraryArrayWithLength(int length=1) 01022 { array_=NULL; size_=-1;lengthInBytes_=length;} 01024 inline CoinArbitraryArrayWithLength(int length, int size) 01025 { array_=new char [size*length]; size_=-1; lengthInBytes_=length;} 01030 inline CoinArbitraryArrayWithLength(int length, int size, int mode) 01031 : CoinArrayWithLength(size*length,mode) {lengthInBytes_=length;} 01033 inline CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength & rhs) 01034 : CoinArrayWithLength(rhs) {} 01036 inline CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength * rhs) 01037 : CoinArrayWithLength(rhs) {} 01039 inline CoinArbitraryArrayWithLength& operator=(const CoinArbitraryArrayWithLength & rhs) 01040 { CoinArrayWithLength::operator=(rhs); return *this;} 01042 01043 protected: 01046 01047 int lengthInBytes_; 01049 }; 01050 class CoinPartitionedVector : public CoinIndexedVector { 01051 01052 public: 01053 #ifndef COIN_PARTITIONS 01054 #define COIN_PARTITIONS 8 01055 #endif 01056 01058 01059 inline int getNumElements(int partition) const { assert (partition<COIN_PARTITIONS); 01060 return numberElementsPartition_[partition]; } 01062 inline int getNumPartitions() const 01063 { return numberPartitions_; } 01065 inline int getNumElements() const { return nElements_; } 01067 inline int startPartition(int partition) const { assert (partition<=COIN_PARTITIONS); 01068 return startPartition_[partition]; } 01070 inline const int * startPartitions() const 01071 { return startPartition_; } 01073 01074 //------------------------------------------------------------------- 01075 // Set indices and elements 01076 //------------------------------------------------------------------- 01079 01080 inline void setNumElementsPartition(int partition, int value) { assert (partition<COIN_PARTITIONS); 01081 if (numberPartitions_) numberElementsPartition_[partition]=value; } 01083 inline void setTempNumElementsPartition(int partition, int value) { assert (partition<COIN_PARTITIONS); 01084 numberElementsPartition_[partition]=value; } 01086 void computeNumberElements(); 01088 void compact(); 01091 void reserve(int n); 01093 void setPartitions(int number,const int * starts); 01095 void clearAndReset(); 01097 void clearAndKeep(); 01099 void clearPartition(int partition); 01100 #ifndef NDEBUG 01101 01102 void checkClear(); 01104 void checkClean(); 01105 #else 01106 inline void checkClear() {}; 01107 inline void checkClean() {}; 01108 #endif 01109 01110 int scan(int partition, double tolerance=0.0); 01114 01115 void print() const; 01117 01121 void sort(); 01123 01127 CoinPartitionedVector(); 01129 CoinPartitionedVector(int size, const int * inds, const double * elems); 01131 CoinPartitionedVector(int size, const int * inds, double element); 01134 CoinPartitionedVector(int size, const double * elements); 01136 CoinPartitionedVector(int size); 01138 CoinPartitionedVector(const CoinPartitionedVector &); 01140 CoinPartitionedVector(const CoinPartitionedVector *); 01142 CoinPartitionedVector & operator=(const CoinPartitionedVector &); 01144 ~CoinPartitionedVector (); 01146 protected: 01149 01150 int startPartition_[COIN_PARTITIONS+1]; 01152 int numberElementsPartition_[COIN_PARTITIONS]; 01154 int numberPartitions_; 01156 }; 01157 #endif