25 #define SOPLEX_DEBUG_SVSETBASE 62 class SVSetBase :
protected ClassArray < Nonzero<R> >
170 MSG_DEBUG(std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
171 ", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n");
177 unusedMem -= ps->size();
179 numUnusedMemUpdates = 0;
182 MSG_DEBUG(std::cout <<
" --> NEW: unusedMem = " << unusedMem <<
"\n");
190 numUnusedMemUpdates++;
192 if(unusedMem < 0 || unusedMem >
memSize() || numUnusedMemUpdates >= 1000000)
213 if(list.
last() && shortenLast)
217 int unusedPsMem = ps->max() - ps->size();
218 assert(unusedPsMem >= 0);
222 ps->set_max(ps->size());
226 MSG_DEBUG(std::cout <<
"ensureMem, this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " <<
227 unusedPsMem <<
"\n");
236 if(missingMem > 0 && missingMem <= unusedMem
256 if(ps == list.
last())
262 MSG_DEBUG(std::cout <<
"deleteVec (1), this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " 263 << ps->max() - ps->size() <<
"\n");
270 else if(ps != list.
first())
273 int sz = prev->
size();
280 MSG_DEBUG(std::cout <<
"deleteVec (2), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " 281 << ps->size() <<
"\n");
292 MSG_DEBUG(std::cout <<
"deleteVec (3), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " 293 << ps->size() <<
"\n");
346 void add(
DataKey& nkey,
const S* rowValues,
const int* rowIndices,
int rowSize)
348 assert(rowSize <= 0 || rowIndices != 0);
349 assert(rowSize <= 0 || rowValues != 0);
357 new_svec->
assignArray(rowValues, rowIndices, rowSize);
370 for(i = len = 0; i < n; ++i)
371 len += svec[i].
size();
376 for(i = 0; i < n; ++i)
391 for(
int i =
num() - 1; --n; --i)
405 for(i = len = 0; i < n; ++i)
406 len += pset[i].
size();
411 for(i = 0; i < n; ++i)
431 nkey[--n] =
key(--i);
444 if(
memSize() == 0 && idxmax <= 0)
486 if(svec.
max() < newmax)
493 if(ps == list.
last())
508 MSG_DEBUG(std::cout <<
"xtend (1), this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " <<
509 ps->max() - sz <<
"\n");
513 ps->setMem(newmax, ps->mem());
536 if(ps != list.
first())
539 int prevsz = prev->
size();
546 MSG_DEBUG(std::cout <<
"xtend (2), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " <<
554 ps->setMem(newmax, newps.
mem());
581 svec.
add(n, idx, val);
594 svec.
add(n, idx, val);
609 set.remove(removekey);
615 void remove(
int removenum)
617 remove(
key(removenum));
634 void remove(
int perm[])
641 for(
int i = j - 1; i >= 0; --i)
658 remove(keys, n, perm.
get_ptr());
664 void remove(
const int nums[],
int n)
667 remove(nums, n, perm.
get_ptr());
671 void remove(
const DataKey keys[],
int n,
int* perm)
673 for(
int i =
num() - 1; i >= 0; --i)
677 perm[
number(*keys++)] = -1;
689 void remove(
const int nums[],
int n,
int* perm)
691 for(
int i =
num() - 1; i >= 0; --i)
719 numUnusedMemUpdates = 0;
779 return set.key(static_cast<const DLPSV*>(svec));
785 return set.number(k);
791 return set.number(static_cast<const DLPSV*>(svec));
809 return set.has(static_cast<const DLPSV*>(svec));
838 MSG_DEBUG(std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
839 ", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n");
851 int l_max = ps->max();
855 ps->setMem(l_max, newmem);
864 numUnusedMemUpdates = 0;
867 MSG_DEBUG(std::cout <<
" --> NEW: unusedMem = " << unusedMem <<
" after memRemax(" <<
889 for(used = 0, ps = list.
first(); ps; ps = list.
next(ps))
891 const int sz = ps->size();
896 for(j = 0; j < sz; ++j)
897 this->SVSetBaseArray::operator[](used + j) = ps->mem()[j];
899 ps->setMem(sz, &this->SVSetBaseArray::operator[](used));
909 MSG_DEBUG(std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
910 ", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n");
912 ", zero after memPack() at memMax() = " <<
memMax() <<
"\n");
923 numUnusedMemUpdates = 0;
941 #ifdef ENABLE_CONSISTENCY_CHECKS 947 if(!ps->isConsistent())
953 next = list.
next(ps);
955 if(next && ps->mem() + ps->max() != next->mem())
973 SVSetBase<R>(
int pmax = -1,
int pmemmax = -1,
double pfac = 1.1,
double pmemFac = 1.2)
974 : SVSetBaseArray(0, (pmemmax > 0) ? pmemmax : 8 * ((pmax > 0) ? pmax : 8), pmemFac)
975 ,
set((pmax > 0) ? pmax : 8)
977 , numUnusedMemUpdates(0)
1004 ptrdiff_t delta =
reinterpret_cast<char*
>(delta0) - reinterpret_cast<char*>(delta1);
1006 for(ps = rhs.list.first(); ps; ps = rhs.list.next(ps))
1008 newps = &
set[rhs.number(ps)];
1010 newps->setMem(ps->max(),
1011 reinterpret_cast<Nonzero<R>*
>(
reinterpret_cast<char*
>(ps->mem()) + delta));
1012 newps->set_size(ps->size());
1023 template <
class S >
1052 template <
class S >
1071 #ifdef SOPLEX_DEBUG_SVSETBASE 1072 #define SOPLEX_DEBUG 1073 #undef SOPLEX_DEBUG_SVSETBASE 1076 #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.