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 referred to as the nonzero memory. The SVectorBases themselves are saved in another memory block referred 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 <ssvectorbase.h>

Classes

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

Public Member Functions

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

Private Types

typedef ClassArray< Nonzero< R > > SVSetBaseArray
 

Private Member Functions

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

Private Attributes

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

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

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 referred to as the nonzero memory. The SVectorBases themselves are saved in another memory block referred 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 43 of file ssvectorbase.h.

Member Typedef Documentation

◆ SVSetBaseArray

typedef ClassArray< Nonzero<R> > SVSetBaseArray
private

Definition at line 78 of file svsetbase.h.

Constructor & Destructor Documentation

◆ SVSetBase() [1/3]

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

Default constructor.

Definition at line 1015 of file svsetbase.h.

◆ ~SVSetBase()

virtual ~SVSetBase ( )
virtual

Destructor.

Definition at line 1026 of file svsetbase.h.

◆ SVSetBase() [2/3]

SVSetBase ( const SVSetBase< R > &  old)

Copy constructor.

Definition at line 1082 of file svsetbase.h.

◆ SVSetBase() [3/3]

SVSetBase ( const SVSetBase< S > &  old)

Copy constructor.

Definition at line 1095 of file svsetbase.h.

Member Function Documentation

◆ add() [1/7]

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 352 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::add(), and LPRowSetBase< R >::add().

◆ add() [2/7]

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 368 of file svsetbase.h.

◆ add() [3/7]

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 385 of file svsetbase.h.

◆ add() [4/7]

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 402 of file svsetbase.h.

◆ add() [5/7]

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 426 of file svsetbase.h.

◆ add() [6/7]

void add ( const SVSetBase< S > &  pset)

Adds all SVectorBases in pset to SVSetBase.

Definition at line 436 of file svsetbase.h.

◆ add() [7/7]

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 462 of file svsetbase.h.

◆ add2() [1/3]

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 605 of file svsetbase.h.

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

◆ add2() [2/3]

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 617 of file svsetbase.h.

◆ add2() [3/3]

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 630 of file svsetbase.h.

◆ clear()

void clear ( int  minNewSize = -1)

Removes all SVectorBases from set.

Definition at line 740 of file svsetbase.h.

◆ countUnusedMem()

void countUnusedMem ( )
private

count size of unused memory exactly

Definition at line 205 of file svsetbase.h.

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

◆ create() [1/2]

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 476 of file svsetbase.h.

Referenced by SVSetBase< BP >::add(), LPColSetBase< Rational >::create(), LPRowSetBase< R >::create(), and SVSetBase< BP >::create().

◆ create() [2/2]

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 511 of file svsetbase.h.

◆ deleteVec()

void deleteVec ( DLPSV ps)
private

Deleting a vector from the data array and the list.

Definition at line 292 of file svsetbase.h.

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

◆ ensureMem()

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 247 of file svsetbase.h.

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

◆ ensurePSVec()

void ensurePSVec ( int  n)
private

Provides enough vector memory for n more SVectorBases.

Definition at line 236 of file svsetbase.h.

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

◆ has() [1/3]

bool has ( const DataKey k) const

True iff SVSetBase contains a SVectorBase for DataKey k.

Definition at line 834 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::has(), LPRowSetBase< R >::has(), and SVSetBase< BP >::xtend().

◆ has() [2/3]

bool has ( int  n) const

True iff SVSetBase contains a SVectorBase for vector number n.

Definition at line 840 of file svsetbase.h.

◆ has() [3/3]

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

Is an SVectorBase in the set?

Definition at line 846 of file svsetbase.h.

◆ isConsistent()

bool isConsistent ( ) const

◆ key() [1/2]

DataKey key ( int  n) const

◆ key() [2/2]

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

Gets DataKey of SVectorBase.

Definition at line 816 of file svsetbase.h.

◆ max()

int max ( ) const

Current maximum number of SVectorBases.

Definition at line 804 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::max(), and LPRowSetBase< R >::max().

◆ memMax()

int memMax ( ) const

◆ memPack()

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 923 of file svsetbase.h.

Referenced by SVSetBase< BP >::ensureMem(), LPColSetBase< Rational >::memPack(), and LPRowSetBase< R >::memPack().

◆ memRemax()

void memRemax ( int  newmax)

Reset length of nonzero memory.

Definition at line 870 of file svsetbase.h.

Referenced by SVSetBase< BP >::ensureMem(), LPColSetBase< Rational >::memRemax(), and LPRowSetBase< R >::memRemax().

◆ memSize()

◆ num()

◆ number() [1/2]

int number ( const DataKey k) const

Gets vector number of DataKey.

Definition at line 822 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::number(), LPRowSetBase< R >::number(), and SVSetBase< BP >::remove().

◆ number() [2/2]

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

Gets vector number of SVectorBase.

Definition at line 828 of file svsetbase.h.

◆ operator=() [1/2]

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

Assignment operator.

Definition at line 1030 of file svsetbase.h.

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

◆ operator=() [2/2]

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

Assignment operator.

Definition at line 1066 of file svsetbase.h.

◆ operator[]() [1/4]

◆ operator[]() [2/4]

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

Gets SVectorBase by number.

Definition at line 774 of file svsetbase.h.

◆ operator[]() [3/4]

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

Gets SVectorBase by DataKey, writeable.

Definition at line 780 of file svsetbase.h.

◆ operator[]() [4/4]

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

Gets SVectorBase by DataKey.

Definition at line 786 of file svsetbase.h.

◆ reMax()

void reMax ( int  newmax = 0)

◆ remove() [1/8]

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 645 of file svsetbase.h.

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

◆ remove() [2/8]

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 654 of file svsetbase.h.

◆ remove() [3/8]

void remove ( const SVectorBase< R > *  svec)

Removes one SVectorBase from set.

Precondition
svec must be from SVSetBase

Definition at line 662 of file svsetbase.h.

◆ remove() [4/8]

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 673 of file svsetbase.h.

◆ remove() [5/8]

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 694 of file svsetbase.h.

◆ remove() [6/8]

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 703 of file svsetbase.h.

◆ remove() [7/8]

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

Definition at line 710 of file svsetbase.h.

◆ remove() [8/8]

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 728 of file svsetbase.h.

◆ updateUnusedMemEstimation()

void updateUnusedMemEstimation ( int  change)
private

update estimation of unused memory

Definition at line 226 of file svsetbase.h.

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

◆ 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 523 of file svsetbase.h.

Referenced by SVSetBase< BP >::add2(), LPColSetBase< Rational >::xtend(), and LPRowSetBase< R >::xtend().

Friends And Related Function Documentation

◆ SVSetBase

friend class SVSetBase
friend

Definition at line 74 of file svsetbase.h.

Member Data Documentation

◆ factor

double factor
private

sparse vector memory enlargment factor

Definition at line 196 of file svsetbase.h.

◆ list

IdList< DLPSV > list
private

doubly linked list for non-zero management

Definition at line 186 of file svsetbase.h.

◆ numUnusedMemUpdates

int numUnusedMemUpdates
private

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

Definition at line 188 of file svsetbase.h.

◆ set

ClassSet< DLPSV > set
private

set of SVectorBases

Definition at line 185 of file svsetbase.h.

◆ unusedMem

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 187 of file svsetbase.h.