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
DataSet< 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 34 of file ssvectorbase.h.

Member Typedef Documentation

◆ SVSetBaseArray

typedef ClassArray< Nonzero<R> > SVSetBaseArray
private

Definition at line 68 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 973 of file svsetbase.h.

◆ ~SVSetBase()

virtual ~SVSetBase ( )
virtual

Destructor.

Definition at line 984 of file svsetbase.h.

◆ SVSetBase() [2/3]

SVSetBase ( const SVSetBase< R > &  old)

Copy constructor.

Definition at line 1040 of file svsetbase.h.

◆ SVSetBase() [3/3]

SVSetBase ( const SVSetBase< S > &  old)

Copy constructor.

Definition at line 1053 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 313 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::add(), and LPRowSetBase< Real >::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 329 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 346 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 363 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 387 of file svsetbase.h.

◆ add() [6/7]

void add ( const SVSetBase< S > &  pset)

Adds all SVectorBases in pset to SVSetBase.

Definition at line 397 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 423 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 566 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::add2(), and LPRowSetBase< Real >::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 578 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 591 of file svsetbase.h.

◆ clear()

void clear ( int  minNewSize = -1)

Removes all SVectorBases from set.

Definition at line 701 of file svsetbase.h.

◆ countUnusedMem()

void countUnusedMem ( )
private

count size of unused memory exactly

Definition at line 167 of file svsetbase.h.

Referenced by SVSetBase< Rational >::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 437 of file svsetbase.h.

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

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

◆ deleteVec()

void deleteVec ( DLPSV ps)
private

Deleting a vector from the data array and the list.

Definition at line 253 of file svsetbase.h.

Referenced by SVSetBase< Rational >::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 208 of file svsetbase.h.

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

◆ ensurePSVec()

void ensurePSVec ( int  n)
private

Provides enough vector memory for n more SVectorBases.

Definition at line 197 of file svsetbase.h.

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

◆ has() [1/3]

bool has ( const DataKey k) const

◆ has() [2/3]

bool has ( int  n) const

True iff SVSetBase contains a SVectorBase for vector number n.

Definition at line 801 of file svsetbase.h.

◆ has() [3/3]

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

Is an SVectorBase in the set?

Definition at line 807 of file svsetbase.h.

◆ isConsistent()

bool isConsistent ( ) const

◆ key() [1/2]

◆ key() [2/2]

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

Gets DataKey of SVectorBase.

Definition at line 777 of file svsetbase.h.

◆ max()

int max ( ) const

Current maximum number of SVectorBases.

Definition at line 765 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::max(), and LPRowSetBase< Real >::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 883 of file svsetbase.h.

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

◆ memRemax()

void memRemax ( int  newmax)

Reset length of nonzero memory.

Definition at line 831 of file svsetbase.h.

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

◆ memSize()

◆ num()

◆ number() [1/2]

int number ( const DataKey k) const

Gets vector number of DataKey.

Definition at line 783 of file svsetbase.h.

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

◆ number() [2/2]

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

Gets vector number of SVectorBase.

Definition at line 789 of file svsetbase.h.

◆ operator=() [1/2]

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

Assignment operator.

Definition at line 988 of file svsetbase.h.

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

◆ operator=() [2/2]

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

Assignment operator.

Definition at line 1024 of file svsetbase.h.

◆ operator[]() [1/4]

◆ operator[]() [2/4]

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

Gets SVectorBase by number.

Definition at line 735 of file svsetbase.h.

◆ operator[]() [3/4]

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

Gets SVectorBase by DataKey, writeable.

Definition at line 741 of file svsetbase.h.

◆ operator[]() [4/4]

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

Gets SVectorBase by DataKey.

Definition at line 747 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 606 of file svsetbase.h.

Referenced by LPColSetBase< Rational >::remove(), and LPRowSetBase< Real >::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 615 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 623 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 634 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 655 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 664 of file svsetbase.h.

◆ remove() [7/8]

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

Definition at line 671 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 689 of file svsetbase.h.

◆ updateUnusedMemEstimation()

void updateUnusedMemEstimation ( int  change)
private

update estimation of unused memory

Definition at line 187 of file svsetbase.h.

Referenced by SVSetBase< Rational >::deleteVec(), SVSetBase< Rational >::ensureMem(), and SVSetBase< Rational >::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 484 of file svsetbase.h.

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

Friends And Related Function Documentation

◆ SVSetBase

friend class SVSetBase
friend

Definition at line 64 of file svsetbase.h.

Member Data Documentation

◆ factor

double factor
private

sparse vector memory enlargment factor

Definition at line 158 of file svsetbase.h.

◆ list

IdList< DLPSV > list
private

doubly linked list for non-zero management

Definition at line 148 of file svsetbase.h.

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

◆ numUnusedMemUpdates

int numUnusedMemUpdates
private

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

Definition at line 150 of file svsetbase.h.

◆ set

DataSet< DLPSV > set
private

set of SVectorBases

Definition at line 147 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 149 of file svsetbase.h.