Scippy

SoPlex

Sequential object-oriented simPlex

SVSetBase< R > Class Template Reference

Sparse vector set.Class SVSetBase provides a set of sparse vectors SVectorBase. All SVectorBases in an SVSetBase share one big memory block for their nonzeros. This memory is reffered to as the nonzero memory. The SVectorBases themselves are saved in another memory block refered to as the vector memory. Both memory blocks will grow automatically if required, when adding more SVectorBases to the set or enlarging SVectorBases within the set. For controlling memory consumption, methods are provided to inquire and reset the size of the memory blocks used for vectors and nonzeros. More...

#include <svsetbase.h>

Inheritance diagram for SVSetBase< R >:

Classes

class  DLPSV
 SVectorBase with prev/next pointers. More...
 

Public Member Functions

Extension
void add (const SVectorBase< R > &svec)
 Adds svec to the set.
 
void add (DataKey &nkey, const SVectorBase< R > &svec)
 Adds svec to SVSetBase.
 
template<class S >
void add (DataKey &nkey, const S *rowValues, const int *rowIndices, int rowSize)
 Adds svec to SVSetBase.
 
void add (const SVectorBase< R > svec[], int n)
 Adds all n SVectorBases in the array svec to the set.
 
void add (DataKey nkey[], const SVectorBase< R > svec[], int n)
 Adds n SVectorBases to SVSetBase.
 
template<class S >
void add (const SVSetBase< S > &pset)
 Adds all SVectorBases in pset to SVSetBase.
 
template<class S >
void add (DataKey nkey[], const SVSetBase< S > &pset)
 Adds all SVectorBases of pset to SVSetBase.
 
SVectorBase< R > * create (int idxmax=0)
 Creates new SVectorBase in set.
 
SVectorBase< R > * create (DataKey &nkey, int idxmax=-1)
 Creates new SVectorBase in set.
 
void xtend (SVectorBase< R > &svec, int newmax)
 Extends svec to fit newmax nonzeros.
 
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.
 
template<class S >
void add2 (SVectorBase< R > &svec, int n, const int idx[], const S val[])
 Adds n nonzeros to svec of this SVSetBase.
 
Shrinking
void remove (const DataKey &removekey)
 Removes the vector with key removekey from the set.
 
void remove (int removenum)
 Removes the vector with number removenum from the set.
 
void remove (const SVectorBase< R > *svec)
 Removes one SVectorBase from set.
 
void remove (int perm[])
 Removes multiple elements.
 
void remove (const DataKey keys[], int n)
 Removes n SVectorBases from set.
 
void remove (const int nums[], int n)
 Removes n SVectorBases from set.
 
void remove (const DataKey keys[], int n, int *perm)
 
void remove (const int nums[], int n, int *perm)
 
void clear (int minNewSize=-1)
 Removes all SVectorBases from set.
 
Access
SVectorBase< R > & operator[] (int n)
 Gets SVectorBase by number, writeable.
 
const SVectorBase< R > & operator[] (int n) const
 Gets SVectorBase by number.
 
SVectorBase< R > & operator[] (const DataKey &k)
 Gets SVectorBase by DataKey, writeable.
 
const SVectorBase< R > & operator[] (const DataKey &k) const
 Gets SVectorBase by DataKey.
 
Inquiry
int num () const
 Current number of SVectorBases.
 
int max () const
 Current maximum number of SVectorBases.
 
DataKey key (int n) const
 Gets DataKey of vector number.
 
DataKey key (const SVectorBase< R > *svec) const
 Gets DataKey of SVectorBase.
 
int number (const DataKey &k) const
 Gets vector number of DataKey.
 
int number (const SVectorBase< R > *svec) const
 Gets vector number of SVectorBase.
 
bool has (const DataKey &k) const
 True iff SVSetBase contains a SVectorBase for DataKey k.
 
bool has (int n) const
 True iff SVSetBase contains a SVectorBase for vector number n.
 
bool has (const SVectorBase< R > *svec) const
 Is an SVectorBase in the set?
 
Memory Management
int memSize () const
 Used nonzero memory.
 
int memMax () const
 Length of nonzero memory.
 
void memRemax (int newmax)
 Reset length of nonzero memory.
 
void memPack ()
 Garbage collection in nonzero memory.
 
Miscellaneous
void reMax (int newmax=0)
 Resets maximum number of SVectorBases.
 
bool isConsistent () const
 Consistency check.
 
Constructors / destructors
 SVSetBase (int pmax=-1, int pmemmax=-1, double pfac=1.1, double pmemFac=1.2)
 Default constructor.
 
virtual ~SVSetBase ()
 Destructor.
 
SVSetBase< R > & operator= (const SVSetBase< R > &rhs)
 Assignment operator.
 
template<class S >
SVSetBase< R > & operator= (const SVSetBase< S > &rhs)
 Assignment operator.
 
 SVSetBase (const SVSetBase< R > &old)
 Copy constructor.
 
template<class S >
 SVSetBase (const SVSetBase< S > &old)
 Copy constructor.
 

Private Types

typedef ClassArray< Nonzero< R > > SVSetBaseArray
 

Private Member Functions

Helpers
void countUnusedMem ()
 count size of unused memory exactly
 
void updateUnusedMemEstimation (int change)
 update estimation of unused memory
 
void ensurePSVec (int n)
 Provides enough vector memory for n more SVectorBases.
 
void ensureMem (int n, bool shortenLast=true)
 Provides enough nonzero memory for n more Nonzeros.
 
void deleteVec (DLPSV *ps)
 Deleting a vector from the data array and the list.
 

Private Attributes

Data
DataSet< DLPSVset
 set of SVectorBases
 
IdList< DLPSVlist
 doubly linked list for non-zero management
 
int unusedMem
 an estimate of the unused memory (the difference of max() and size() summed up over all vectors) due to deleteVec() and xtend()
 
int numUnusedMemUpdates
 counter for how often unusedMem has been updated since last exact value
 
Control Parameters
double factor
 sparse vector memory enlargment factor
 

Friends

template<class S >
class SVSetBase
 

Additional Inherited Members

- Protected Member Functions inherited from ClassArray< Nonzero< R > >
Nonzero< R > & operator[] (int n)
 Reference to n 'th element.
 
const Nonzero< R > & operator[] (int n) const
 Reference to n 'th const element.
 
Nonzero< R > & last ()
 Reference to last element.
 
const Nonzero< R > & last () const
 Reference to last const element.
 
Nonzero< R > * get_ptr ()
 Gets a C pointer to the data.
 
const Nonzero< R > * get_const_ptr () const
 Gets a const C pointer to the data.
 
void append (const Nonzero< R > &t)
 Appends element t.
 
void append (int n, const Nonzero< R >t[])
 Appends n elements from t.
 
void append (const ClassArray< Nonzero< R > > &t)
 Appends all elements from t.
 
void insert (int i, int n)
 Inserts n uninitialized elements before i 'th element.
 
void insert (int i, int n, const Nonzero< R >t[])
 Inserts n elements from t before i 'the element.
 
void insert (int i, const ClassArray< Nonzero< R > > &t)
 Inserts all elements from t before i 'th element.
 
void remove (int n=0, int m=1)
 Removes m elements starting at n.
 
void removeLast (int m=1)
 Removes m last elements.
 
void clear ()
 Removes all elements.
 
int size () const
 Returns number of elements.
 
void reSize (int newsize)
 Resets size to newsize.
 
int max () const
 Returns maximum number of elements.
 
ptrdiff_t reMax (int newMax=1, int newSize=-1)
 Resets maximum number of elements.
 
ClassArrayoperator= (const ClassArray &rhs)
 Assignment operator.
 
bool isConsistent () const
 Consistency check.
 
 ClassArray (const ClassArray &old)
 Copy constructor.
 
 ClassArray (int p_size=0, int p_max=0, double p_fac=1.2)
 Default constructor.
 
virtual ~ClassArray ()
 Destructor.
 

Detailed Description

template<class R>
class soplex::SVSetBase< R >

Sparse vector set.

Class SVSetBase provides a set of sparse vectors SVectorBase. All SVectorBases in an SVSetBase share one big memory block for their nonzeros. This memory is reffered to as the nonzero memory. The SVectorBases themselves are saved in another memory block refered to as the vector memory. Both memory blocks will grow automatically if required, when adding more SVectorBases to the set or enlarging SVectorBases within the set. For controlling memory consumption, methods are provided to inquire and reset the size of the memory blocks used for vectors and nonzeros.

SVectorBases in an SVSetBase are numbered from 0 thru num()-1. They can be accessed using the index operator[](). When removing SVectorBases of a SVSetBase the remaining ones will be renumbered. However, all SVectorBase with a smaller number than the lowest number of the removed SVectorBases will remain unchanged.

For providing a uniform access to SVectorBases in a set even if others are removed or added, SVSetBase assigns a DataKey to each SVectorBase in the set. Such a DataKey remains unchanged as long as the corresponding SVectorBase is in the SVSetBase, no matter what other SVectorBases are added to or removed from the SVSetBase. Methods are provided for getting the DataKey to a SVectorBase or its number and vice versa. Further, each add() method for enlarging an SVSetBase is provided with two signatures. One of them returns the DataKeys assigned to the SVectorBases added to the SVSetBase.

Definition at line 62 of file svsetbase.h.

Member Typedef Documentation

typedef ClassArray< Nonzero<R> > SVSetBaseArray
private

Definition at line 68 of file svsetbase.h.

Constructor & Destructor Documentation

SVSetBase ( int  pmax = -1,
int  pmemmax = -1,
double  pfac = 1.1,
double  pmemFac = 1.2 
)
explicit

Default constructor.

Definition at line 951 of file svsetbase.h.

virtual ~SVSetBase ( )
virtual

Destructor.

Definition at line 962 of file svsetbase.h.

SVSetBase ( const SVSetBase< R > &  old)

Copy constructor.

Definition at line 1018 of file svsetbase.h.

SVSetBase ( const SVSetBase< S > &  old)

Copy constructor.

Definition at line 1031 of file svsetbase.h.

Member Function Documentation

void add ( const SVectorBase< R > &  svec)

Adds svec to the set.

This includes copying its nonzeros to the sets nonzero memory and creating an additional SVectorBase entry in vector memory. If neccessary, the memory blocks are enlarged appropriately.

Definition at line 305 of file svsetbase.h.

Referenced by LPColSetBase< Real >::add(), LPRowSetBase< Real >::add(), SVSetBase< Real >::add(), and SVSetBase< Real >::operator=().

void add ( DataKey nkey,
const SVectorBase< R > &  svec 
)

Adds svec to SVSetBase.

Adds SVectorBase svec to the set. This includes copying its nonzeros to the sets nonzero memory and creating an additional SVectorBase entry in vector memory. If neccessary, the memory blocks are enlarged appropriately.

Returns
nkey contains the DataKey, that the SVSetBase has assosicated to the new SVectorBase.

Definition at line 321 of file svsetbase.h.

void add ( DataKey nkey,
const S *  rowValues,
const int *  rowIndices,
int  rowSize 
)

Adds svec to SVSetBase.

Adds SVectorBase svec to the set. This includes copying its nonzeros to the sets nonzero memory and creating an additional SVectorBase entry in vector memory. If neccessary, the memory blocks are enlarged appropriately.

Returns
nkey contains the DataKey, that the SVSetBase has assosicated to the new SVectorBase.

Definition at line 338 of file svsetbase.h.

void add ( const SVectorBase< R >  svec[],
int  n 
)

Adds all n SVectorBases in the array svec to the set.

Precondition
svec must hold at least n entries.

Definition at line 355 of file svsetbase.h.

void add ( DataKey  nkey[],
const SVectorBase< R >  svec[],
int  n 
)

Adds n SVectorBases to SVSetBase.

Adds all n SVectorBases in the array svec to the set.

Returns
nkey contains the DataKeys, that the SVSetBase has assosicated to the new SVectorBases.
Precondition
nkey must be large enough to fit n DataKeys.

Definition at line 379 of file svsetbase.h.

void add ( const SVSetBase< S > &  pset)

Adds all SVectorBases in pset to SVSetBase.

Definition at line 389 of file svsetbase.h.

void add ( DataKey  nkey[],
const SVSetBase< S > &  pset 
)

Adds all SVectorBases of pset to SVSetBase.

Adds all n SVectorBases in the pset to an SVSetBase.

Returns
nkey contains the DataKeys, that the SVSetBase has assosicated to the new SVectorBases.
Precondition
nkey must be large enough to fit pset.num() DataKeys.

Definition at line 414 of file svsetbase.h.

void add2 ( SVectorBase< R > &  svec,
int  idx,
val 
)

Adds nonzero (idx, val) to svec of this SVSetBase.

Adds one nonzero (idx, val) to SVectorBase svec in the SVSetBase. If svec is not large enough to hold the additional nonzero, it will be automatically enlarged within the set.

Precondition
svec must be an SVectorBase of the SVSetBase.

Definition at line 549 of file svsetbase.h.

Referenced by LPColSetBase< Real >::add2(), and LPRowSetBase< Real >::add2().

void add2 ( SVectorBase< R > &  svec,
int  n,
const int  idx[],
const R  val[] 
)

Adds n nonzeros to svec of this SVSetBase.

Adds n nonzeros to SVectorBase svec in the SVSetBase. If svec is not large enough to hold the additional nonzeros, it will be automatically enlarged within the set.

Precondition
svec must be an SVectorBase of the SVSetBase.

Definition at line 561 of file svsetbase.h.

void add2 ( SVectorBase< R > &  svec,
int  n,
const int  idx[],
const S  val[] 
)

Adds n nonzeros to svec of this SVSetBase.

Adds n nonzeros to SVectorBase svec in the SVSetBase. If svec is not large enough to hold the additional nonzeros, it will be automatically enlarged within the set.

Precondition
svec must be an SVectorBase of the SVSetBase.

Definition at line 574 of file svsetbase.h.

void clear ( int  minNewSize = -1)

Removes all SVectorBases from set.

Definition at line 684 of file svsetbase.h.

void countUnusedMem ( )
private

count size of unused memory exactly

Definition at line 167 of file svsetbase.h.

Referenced by SVSetBase< Real >::updateUnusedMemEstimation().

SVectorBase<R>* create ( int  idxmax = 0)

Creates new SVectorBase in set.

The new SVectorBase will be ready to fit at least idxmax nonzeros.

Definition at line 428 of file svsetbase.h.

Referenced by SVSetBase< Real >::add(), LPColSetBase< Real >::create(), SVSetBase< Real >::create(), and LPRowSetBase< Real >::create().

SVectorBase<R>* create ( DataKey nkey,
int  idxmax = -1 
)

Creates new SVectorBase in set.

The new SVectorBase will be ready to fit at least idxmax nonzeros.

Returns
nkey contains the DataKey associated to the new SVectorBase.

Definition at line 463 of file svsetbase.h.

void deleteVec ( DLPSV ps)
private

Deleting a vector from the data array and the list.

Definition at line 248 of file svsetbase.h.

Referenced by SVSetBase< Real >::remove().

void ensureMem ( int  n,
bool  shortenLast = true 
)
private

Provides enough nonzero memory for n more Nonzeros.

Todo:
use an independent parameter "memwastefactor" here

Definition at line 206 of file svsetbase.h.

Referenced by SVSetBase< Real >::add(), SVSetBase< Real >::create(), and SVSetBase< Real >::xtend().

void ensurePSVec ( int  n)
private

Provides enough vector memory for n more SVectorBases.

Definition at line 195 of file svsetbase.h.

Referenced by SVSetBase< Real >::add(), and SVSetBase< Real >::create().

bool has ( const DataKey k) const

True iff SVSetBase contains a SVectorBase for DataKey k.

Definition at line 778 of file svsetbase.h.

Referenced by LPColSetBase< Real >::has(), LPRowSetBase< Real >::has(), and SVSetBase< Real >::xtend().

bool has ( int  n) const

True iff SVSetBase contains a SVectorBase for vector number n.

Definition at line 784 of file svsetbase.h.

bool has ( const SVectorBase< R > *  svec) const

Is an SVectorBase in the set?

Definition at line 790 of file svsetbase.h.

bool isConsistent ( ) const
DataKey key ( const SVectorBase< R > *  svec) const

Gets DataKey of SVectorBase.

Definition at line 760 of file svsetbase.h.

int max ( ) const

Current maximum number of SVectorBases.

Definition at line 748 of file svsetbase.h.

Referenced by SVSetBase< Real >::ensurePSVec(), LPColSetBase< Real >::max(), and LPRowSetBase< Real >::max().

int memMax ( ) const
void memPack ( )

Garbage collection in nonzero memory.

Pack the svectors together as tightly as possible. This removes all additional unused memory, i.e., size = max for every svector after the call.

Note: do not call isConsistent() here, because the following might happen: In SPxLP::doAddRows(const LPRowSet& p_set), when adding rows, the sizes of the vectors for the columns of the LP are increased (without yet filling in the data) to recieve the additional entries. This is done by calling xtend() above. xtend() in turn might call this method, which checks the yet unfilled positions, i.e., isConsistent() is likely to fail. In general, isConsistent() should not be called within this class, but in classes further up in the hierarchy.

Definition at line 863 of file svsetbase.h.

Referenced by SVSetBase< Real >::ensureMem(), LPColSetBase< Real >::memPack(), and LPRowSetBase< Real >::memPack().

void memRemax ( int  newmax)

Reset length of nonzero memory.

Definition at line 814 of file svsetbase.h.

Referenced by SVSetBase< Real >::ensureMem(), LPColSetBase< Real >::memRemax(), and LPRowSetBase< Real >::memRemax().

int number ( const DataKey k) const
int number ( const SVectorBase< R > *  svec) const

Gets vector number of SVectorBase.

Definition at line 772 of file svsetbase.h.

SVSetBase<R>& operator= ( const SVSetBase< R > &  rhs)

Assignment operator.

Definition at line 966 of file svsetbase.h.

Referenced by LPColSetBase< Real >::operator=(), and LPRowSetBase< Real >::operator=().

SVSetBase<R>& operator= ( const SVSetBase< S > &  rhs)

Assignment operator.

Definition at line 1002 of file svsetbase.h.

const SVectorBase<R>& operator[] ( int  n) const

Gets SVectorBase by number.

Definition at line 718 of file svsetbase.h.

SVectorBase<R>& operator[] ( const DataKey k)

Gets SVectorBase by DataKey, writeable.

Definition at line 724 of file svsetbase.h.

const SVectorBase<R>& operator[] ( const DataKey k) const

Gets SVectorBase by DataKey.

Definition at line 730 of file svsetbase.h.

void reMax ( int  newmax = 0)
void remove ( const DataKey removekey)

Removes the vector with key removekey from the set.

Precondition
removekey must be a key from SVSetBase

Definition at line 589 of file svsetbase.h.

Referenced by LPColSetBase< Real >::remove(), and LPRowSetBase< Real >::remove().

void remove ( int  removenum)

Removes the vector with number removenum from the set.

Precondition
removenum must be a valid vector number from SVSetBase

Definition at line 598 of file svsetbase.h.

void remove ( const SVectorBase< R > *  svec)

Removes one SVectorBase from set.

Precondition
svec must be from SVSetBase

Definition at line 606 of file svsetbase.h.

void remove ( int  perm[])

Removes multiple elements.

Removes all SVectorBases for the SVSetBase with an index i such that perm[i] < 0. Upon completion, perm[i] >= 0 indicates the new index where the i 'th SVectorBase has been moved to due to this removal.

Precondition
perm must point to an array of at least num() integers.

Definition at line 617 of file svsetbase.h.

void remove ( const DataKey  keys[],
int  n 
)

Removes n SVectorBases from set.

Precondition
keys must be at least of size n and valid keys

Definition at line 638 of file svsetbase.h.

void remove ( const int  nums[],
int  n 
)

Removes n SVectorBases from set.

Precondition
nums must be at least of size n and valid vector numbers

Definition at line 647 of file svsetbase.h.

void remove ( const DataKey  keys[],
int  n,
int *  perm 
)

Definition at line 654 of file svsetbase.h.

void remove ( const int  nums[],
int  n,
int *  perm 
)

Removes n SVectorBases from set.

Precondition
nums must be at least of size n
perm must be at least of size num()
Returns
perm is the permutations resulting from this removal: perm[i] < 0 indicates that the element to index i has been removed. Otherwise, perm[i] is the new index of the element with index i before the removal.

Definition at line 672 of file svsetbase.h.

void updateUnusedMemEstimation ( int  change)
private

update estimation of unused memory

Definition at line 185 of file svsetbase.h.

Referenced by SVSetBase< Real >::deleteVec(), SVSetBase< Real >::ensureMem(), and SVSetBase< Real >::xtend().

void xtend ( SVectorBase< R > &  svec,
int  newmax 
)

Extends svec to fit newmax nonzeros.

Precondition
svec must be an SVectorBase of the SVSetBase.

Definition at line 475 of file svsetbase.h.

Referenced by SVSetBase< Real >::add2(), LPColSetBase< Real >::xtend(), and LPRowSetBase< Real >::xtend().

Friends And Related Function Documentation

friend class SVSetBase
friend

Definition at line 64 of file svsetbase.h.

Member Data Documentation

double factor
private

sparse vector memory enlargment factor

Definition at line 158 of file svsetbase.h.

Referenced by SVSetBase< Real >::ensurePSVec().

int numUnusedMemUpdates
private

counter for how often unusedMem has been updated since last exact value

Definition at line 150 of file svsetbase.h.

Referenced by SVSetBase< Real >::clear(), SVSetBase< Real >::countUnusedMem(), SVSetBase< Real >::memPack(), SVSetBase< Real >::memRemax(), and SVSetBase< Real >::updateUnusedMemEstimation().

DataSet< DLPSV > set
private

set of SVectorBases

Definition at line 147 of file svsetbase.h.

Referenced by SVSetBase< Real >::operator=().

int unusedMem
private

an estimate of the unused memory (the difference of max() and size() summed up over all vectors) due to deleteVec() and xtend()

Definition at line 149 of file svsetbase.h.

Referenced by SVSetBase< Real >::clear(), SVSetBase< Real >::countUnusedMem(), SVSetBase< Real >::memPack(), SVSetBase< Real >::memRemax(), and SVSetBase< Real >::updateUnusedMemEstimation().