25 #define SOPLEX_DEBUG_SVSETBASE 62 class SVSetBase :
protected ClassArray < Nonzero<R> >
170 MSG_DEBUG( std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n" );
175 unusedMem -= ps->size();
177 numUnusedMemUpdates = 0;
180 MSG_DEBUG( std::cout <<
" --> NEW: unusedMem = " << unusedMem <<
"\n" );
188 numUnusedMemUpdates++;
190 if( unusedMem < 0 || unusedMem >
memSize() || numUnusedMemUpdates >= 1000000 )
211 if( list.
last() && shortenLast )
215 int unusedPsMem = ps->max() - ps->size();
216 assert(unusedPsMem >= 0);
220 ps->set_max(ps->size());
224 MSG_DEBUG( std::cout <<
"ensureMem, this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " << unusedPsMem <<
"\n" );
251 if( ps == list.
last() )
257 MSG_DEBUG( std::cout <<
"deleteVec (1), this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " << ps->max() - ps->size() <<
"\n" );
264 else if( ps != list.
first() )
267 int sz = prev->
size();
274 MSG_DEBUG( std::cout <<
"deleteVec (2), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " << ps->size() <<
"\n" );
285 MSG_DEBUG( std::cout <<
"deleteVec (3), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " << ps->size() <<
"\n" );
338 void add(
DataKey& nkey,
const S* rowValues,
const int* rowIndices,
int rowSize)
340 assert(rowSize <= 0 || rowIndices != 0);
341 assert(rowSize <= 0 || rowValues != 0);
349 new_svec->
assignArray(rowValues, rowIndices, rowSize);
362 for( i = len = 0; i < n; ++i )
363 len += svec[i].
size();
368 for( i = 0; i < n; ++i )
383 for(
int i =
num() - 1; --n; --i )
396 for( i = len = 0; i < n; ++i )
397 len += pset[i].
size();
402 for( i = 0; i < n; ++i )
422 nkey[--n] =
key(--i);
435 if(
memSize() == 0 && idxmax <= 0 )
477 if( svec.
max() < newmax )
484 if( ps == list.
last() )
499 MSG_DEBUG( std::cout <<
"xtend (1), this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " << ps->max() - sz <<
"\n" );
503 ps->setMem(newmax, ps->mem());
524 if( ps != list.
first() )
527 int prevsz = prev->
size();
534 MSG_DEBUG( std::cout <<
"xtend (2), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " << ps->size() <<
"\n" );
541 ps->setMem(newmax, newps.
mem());
568 svec.
add(n, idx, val);
581 svec.
add(n, idx, val);
596 set.remove(removekey);
602 void remove(
int removenum)
604 remove(
key(removenum));
621 void remove(
int perm[])
628 for(
int i = j - 1; i >= 0; --i )
645 remove(keys, n, perm.
get_ptr());
651 void remove(
const int nums[],
int n)
654 remove(nums, n, perm.
get_ptr());
658 void remove(
const DataKey keys[],
int n,
int* perm)
660 for(
int i =
num() - 1; i >= 0; --i )
664 perm[
number(*keys++)] = -1;
676 void remove(
const int nums[],
int n,
int* perm)
678 for(
int i =
num() - 1; i >= 0; --i )
692 if( minNewSize <= 0 )
706 numUnusedMemUpdates = 0;
766 return set.key(static_cast<const DLPSV*>(svec));
772 return set.number(k);
778 return set.number(static_cast<const DLPSV*>(svec));
796 return set.has(static_cast<const DLPSV*>(svec));
825 MSG_DEBUG( std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n" );
836 int l_max = ps->max();
840 ps->setMem(l_max, newmem);
849 numUnusedMemUpdates = 0;
852 MSG_DEBUG( std::cout <<
" --> NEW: unusedMem = " << unusedMem <<
" after memRemax(" << newmax <<
")\n" );
873 for( used = 0, ps = list.
first(); ps; ps = list.
next(ps) )
875 const int sz = ps->size();
880 for( j = 0; j < sz; ++j )
881 this->SVSetBaseArray::operator[](used + j) = ps->mem()[j];
883 ps->setMem(sz, &this->SVSetBaseArray::operator[](used));
893 MSG_DEBUG( std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n" );
894 MSG_DEBUG( std::cout <<
" --> NEW: unusedMem = " <<
memSize() - used <<
", zero after memPack() at memMax() = "<<
memMax() <<
"\n" );
905 numUnusedMemUpdates = 0;
923 #ifdef ENABLE_CONSISTENCY_CHECKS 929 if( !ps->isConsistent() )
935 next = list.
next(ps);
937 if( next && ps->mem() + ps->max() != next->mem() )
955 SVSetBase<R>(
int pmax = -1,
int pmemmax = -1,
double pfac = 1.1,
double pmemFac = 1.2)
956 : SVSetBaseArray(0, (pmemmax > 0) ? pmemmax : 8 * ((pmax > 0) ? pmax : 8), pmemFac)
957 ,
set((pmax > 0) ? pmax : 8)
959 , numUnusedMemUpdates(0)
986 ptrdiff_t delta =
reinterpret_cast<char*
>(delta0) - reinterpret_cast<char*>(delta1);
988 for( ps = rhs.list.first(); ps; ps = rhs.list.next(ps) )
990 newps = &
set[rhs.number(ps)];
992 newps->setMem(ps->max(),
993 reinterpret_cast<Nonzero<R>*
>(
reinterpret_cast<char*
>(ps->mem()) + delta));
994 newps->set_size(ps->size());
1005 template <
class S >
1012 if( rhs.size() > 0 )
1034 template <
class S >
1053 #ifdef SOPLEX_DEBUG_SVSETBASE 1054 #define SOPLEX_DEBUG 1055 #undef SOPLEX_DEBUG_SVSETBASE 1058 #endif // _SVSETBASE_H_ DataSet< DLPSV > set
set of SVectorBases
void clear(bool pDestroyElements=false)
removes all elements from an IsList.
void append(T *elem)
appends elem to end of list.
Sparse vector nonzero element.
SVSetBase< R > & operator=(const SVSetBase< R > &rhs)
Assignment operator.
int unusedMem
an estimate of the unused memory (the difference of max() and size() summed up over all vectors) due ...
Generic Real linked list.
Entry identifier class for items of a DataSet.
SVectorBase< R > & operator[](const DataKey &k)
Gets SVectorBase by DataKey, writeable.
void reMax(int newmax=0)
Resets maximum number of SVectorBases.
void ensurePSVec(int n)
Provides enough vector memory for n more SVectorBases.
void setMem(int n, Nonzero< R > *elmem)
Set the memory area where the nonzeros will be stored.
T * get_ptr()
get a C pointer to the data.
void deleteVec(DLPSV *ps)
Deleting a vector from the data array and the list.
int size() const
Number of used indices.
Generic Real linked list.Class IdList implements an intrusive Real linked list as a template class...
DataKey key(const SVectorBase< R > *svec) const
Gets DataKey of SVectorBase.
void set_size(int s)
Set size of the vector.
DLPSV *const & next() const
Next SVectorBase.
void move(ptrdiff_t delta)
adjusts list pointers to a new memory address.
int number(const DataKey &k) const
Gets vector number of DataKey.
void countUnusedMem()
count size of unused memory exactly
double memFactor
memory extension factor.
bool isConsistent() const
Consistency check.
int memSize() const
Used nonzero memory.
bool has(const SVectorBase< R > *svec) const
Is an SVectorBase in the set?
void add(DataKey &nkey, const S *rowValues, const int *rowIndices, int rowSize)
Adds svec to SVSetBase.
SVectorBase< R > * create(int idxmax=0)
Creates new SVectorBase in set.
void add(DataKey nkey[], const SVSetBase< S > &pset)
Adds all SVectorBases of pset to SVSetBase.
Nonzero< R > & last()
Reference to last element.
Nonzero< R > * mem() const
get pointer to internal memory.
Entry identifier class for items of a DataSet.Every item in a DataSet is assigned a DataKey by which ...
DataKey key(int n) const
Gets DataKey of vector number.
Save arrays of data objects.
Set of data objects.Class DataSet manages of sets of data objects of a template type DATA...
DLPSV * thenext
next SVectorBase
void add(DataKey nkey[], const SVectorBase< R > svec[], int n)
Adds n SVectorBases to SVSetBase.
bool has(int n) const
True iff SVSetBase contains a SVectorBase for vector number n.
void add(const SVectorBase< R > &svec)
Adds svec to the set.
int numUnusedMemUpdates
counter for how often unusedMem has been updated since last exact value
SVectorBase< R > * create(DataKey &nkey, int idxmax=-1)
Creates new SVectorBase in set.
ClassArray< Nonzero< R > > SVSetBaseArray
void updateUnusedMemEstimation(int change)
update estimation of unused memory
const SVectorBase< R > & operator[](int n) const
Gets SVectorBase by number.
int memMax() const
Length of nonzero memory.
SVectorBase< R > & operator[](int n)
Gets SVectorBase by number, writeable.
int size() const
Returns number of elements.
void remove(T *elem)
removes elem from list.
bool has(const DataKey &k) const
True iff SVSetBase contains a SVectorBase for DataKey k.
bool isConsistent() const
Consistency check.
double factor
sparse vector memory enlargment factor
SVectorBase with prev/next pointers.
void add(const SVectorBase< R > svec[], int n)
Adds all n SVectorBases in the array svec to the set.
Safe arrays of class objects.Class ClassArray provides safe arrays of general C++ objects (in contras...
DLPSV()
Default constructor.
DLPSV *& next()
Next SVectorBase.
int max() const
Returns maximum number of elements.
void add(DataKey &nkey, const SVectorBase< R > &svec)
Adds svec to SVSetBase.
void reSize(int newsize)
Resets size to newsize.
T * next(const T *elem) const
returns successor of elem or 0, if elem is the last element.
void memRemax(int newmax)
Reset length of nonzero memory.
void memPack()
Garbage collection in nonzero memory.
void add(int i, const R &v)
Append one nonzero (i,v).
Debugging, floating point type and parameter definitions.
ClassArray & operator=(const ClassArray &rhs)
Assignment operator.
bool isConsistent() const
Consistency check.
DLPSV * theprev
previous SVectorBase
SVSetBase< R > & operator=(const SVSetBase< S > &rhs)
Assignment operator.
Nonzero< R > * get_ptr()
Gets a C pointer to the data.
void removeLast(int m=1)
Removes m last elements.
Everything should be within this namespace.
int max() const
Maximal number of indices.
void clear()
Remove all indices.
void add2(SVectorBase< R > &svec, int n, const int idx[], const S val[])
Adds n nonzeros to svec of this SVSetBase.
Nonzero< R > & operator[](int n)
Reference to n 'th element.
DLPSV(const DLPSV ©)
Copy constructor.
ptrdiff_t reMax(int newMax=1, int newSize=-1)
Resets maximum number of elements.
SVectorBase< R > & assignArray(const S *rowValues, const int *rowIndices, int rowSize)
Assignment operator.
Nonzero< R > * data
the array of elements
void clear(int minNewSize=-1)
Removes all SVectorBases from set.
void ensureMem(int n, bool shortenLast=true)
Provides enough nonzero memory for n more Nonzeros.
DLPSV *& prev()
Previous SVectorBase.
void insert(int i, int n)
Inserts n uninitialized elements before i 'th element.
void add2(SVectorBase< R > &svec, int idx, R val)
Adds nonzero (idx, val) to svec of this SVSetBase.
void add2(SVectorBase< R > &svec, int n, const int idx[], const R val[])
Adds n nonzeros to svec of this SVSetBase.
void xtend(SVectorBase< R > &svec, int newmax)
Extends svec to fit newmax nonzeros.
bool isConsistent() const
consistency check.
void add(const SVSetBase< S > &pset)
Adds all SVectorBases in pset to SVSetBase.
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
DLPSV *const & prev() const
Previous SVectorBase.
#define MSGinconsistent(name)
const SVectorBase< R > & operator[](const DataKey &k) const
Gets SVectorBase by DataKey.
T * last() const
returns last element in list.
T * first() const
returns first element in list.
int max() const
Current maximum number of SVectorBases.
int num() const
Current number of SVectorBases.
IdList< DLPSV > list
doubly linked list for non-zero management
int number(const SVectorBase< R > *svec) const
Gets vector number of SVectorBase.
Sparse vector set.Class SVSetBase provides a set of sparse vectors SVectorBase. All SVectorBases in a...
void clear()
Removes all elements.