25 #define SOPLEX_DEBUG_SVSETBASE 63 class SVSetBase :
protected ClassArray < Nonzero<R> >
182 MSG_DEBUG(std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
183 ", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n");
189 unusedMem -= ps->size();
191 numUnusedMemUpdates = 0;
194 MSG_DEBUG(std::cout <<
" --> NEW: unusedMem = " << unusedMem <<
"\n");
202 numUnusedMemUpdates++;
204 if(unusedMem < 0 || unusedMem >
memSize() || numUnusedMemUpdates >= 1000000)
225 if(list.
last() && shortenLast)
229 int unusedPsMem = ps->max() - ps->size();
230 assert(unusedPsMem >= 0);
234 ps->set_max(ps->size());
238 MSG_DEBUG(std::cout <<
"ensureMem, this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " <<
239 unusedPsMem <<
"\n");
248 if(missingMem > 0 && missingMem <= unusedMem
268 if(ps == list.
last())
274 MSG_DEBUG(std::cout <<
"deleteVec (1), this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " 275 << ps->max() - ps->size() <<
"\n");
282 else if(ps != list.
first())
285 int sz = prev->
size();
292 MSG_DEBUG(std::cout <<
"deleteVec (2), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " 293 << ps->size() <<
"\n");
304 MSG_DEBUG(std::cout <<
"deleteVec (3), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " 305 << ps->size() <<
"\n");
358 void add(
DataKey& nkey,
const S* rowValues,
const int* rowIndices,
int rowSize)
360 assert(rowSize <= 0 || rowIndices != 0);
361 assert(rowSize <= 0 || rowValues != 0);
369 new_svec->
assignArray(rowValues, rowIndices, rowSize);
382 for(i = len = 0; i < n; ++i)
383 len += svec[i].
size();
388 for(i = 0; i < n; ++i)
403 for(
int i =
num() - 1; --n; --i)
417 for(i = len = 0; i < n; ++i)
418 len += pset[i].
size();
423 for(i = 0; i < n; ++i)
443 nkey[--n] =
key(--i);
456 if(
memSize() == 0 && idxmax <= 0)
498 if(svec.
max() < newmax)
505 if(ps == list.
last())
520 MSG_DEBUG(std::cout <<
"xtend (1), this = " << (
void*)
this <<
": updateUnusedMemEstimation -= " <<
521 ps->max() - sz <<
"\n");
525 ps->setMem(newmax, ps->mem());
548 if(ps != list.
first())
551 int prevsz = prev->
size();
558 MSG_DEBUG(std::cout <<
"xtend (2), this = " << (
void*)
this <<
": updateUnusedMemEstimation += " <<
566 ps->setMem(newmax, newps.
mem());
593 svec.
add(n, idx, val);
606 svec.
add(n, idx, val);
621 set.remove(removekey);
627 void remove(
int removenum)
629 remove(
key(removenum));
646 void remove(
int perm[])
653 for(
int i = j - 1; i >= 0; --i)
670 remove(keys, n, perm.
get_ptr());
676 void remove(
const int nums[],
int n)
679 remove(nums, n, perm.
get_ptr());
683 void remove(
const DataKey keys[],
int n,
int* perm)
685 for(
int i =
num() - 1; i >= 0; --i)
689 perm[
number(*keys++)] = -1;
701 void remove(
const int nums[],
int n,
int* perm)
703 for(
int i =
num() - 1; i >= 0; --i)
731 numUnusedMemUpdates = 0;
791 return set.key(static_cast<const DLPSV*>(svec));
797 return set.number(k);
803 return set.number(static_cast<const DLPSV*>(svec));
821 return set.has(static_cast<const DLPSV*>(svec));
850 MSG_DEBUG(std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
851 ", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n");
863 int l_max = ps->max();
867 ps->setMem(l_max, newmem);
876 numUnusedMemUpdates = 0;
879 MSG_DEBUG(std::cout <<
" --> NEW: unusedMem = " << unusedMem <<
" after memRemax(" <<
901 for(used = 0, ps = list.
first(); ps; ps = list.
next(ps))
903 const int sz = ps->size();
908 for(j = 0; j < sz; ++j)
909 this->SVSetBaseArray::operator[](used + j) = ps->mem()[j];
911 ps->setMem(sz, &this->SVSetBaseArray::operator[](used));
921 MSG_DEBUG(std::cout <<
"counting unused memory (unusedMem = " << unusedMem <<
922 ", numUnusedMemUpdates = " << numUnusedMemUpdates <<
", this = " << (
void*)
this <<
")\n");
924 ", zero after memPack() at memMax() = " <<
memMax() <<
"\n");
935 numUnusedMemUpdates = 0;
953 #ifdef ENABLE_CONSISTENCY_CHECKS 959 if(!ps->isConsistent())
965 next = list.
next(ps);
967 if(next && ps->mem() + ps->max() != next->mem())
985 SVSetBase<R>(
int pmax = -1,
int pmemmax = -1,
double pfac = 1.1,
double pmemFac = 1.2)
986 : SVSetBaseArray(0, (pmemmax > 0) ? pmemmax : 8 * ((pmax > 0) ? pmax : 8), pmemFac)
987 ,
set((pmax > 0) ? pmax : 8)
989 , numUnusedMemUpdates(0)
1016 ptrdiff_t delta =
reinterpret_cast<char*
>(delta0) - reinterpret_cast<char*>(delta1);
1018 for(ps = rhs.list.first(); ps; ps = rhs.list.next(ps))
1020 newps = &
set[rhs.number(ps)];
1022 newps->setMem(ps->max(),
1023 reinterpret_cast<Nonzero<R>*
>(
reinterpret_cast<char*
>(ps->mem()) + delta));
1024 newps->set_size(ps->size());
1035 template <
class S >
1064 template <
class S >
1083 #ifdef SOPLEX_DEBUG_SVSETBASE 1084 #define SOPLEX_DEBUG 1085 #undef SOPLEX_DEBUG_SVSETBASE 1088 #endif // _SVSETBASE_H_ 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.
ClassSet< DLPSV > set
set of SVectorBases
SVSetBase< R > & operator=(const SVSetBase< R > &rhs)
Assignment operator.
SVectorBase< R > & operator=(const VectorBase< S > &vec)
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.
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
DLPSV & operator=(DLPSV &&rhs)
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.
Set of class objects.Class ClassSet manages of sets of class objects of a template type T...
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.