Scippy

SoPlex

Sequential object-oriented simPlex

SVectorBase< R > Class Template Reference

Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors, with a storage scheme that keeps all data in one contiguous block of memory. This is best suited for using them for parallel computing on a distributed memory multiprocessor. More...

#include <ssvectorbase.h>

Public Types

typedef Nonzero< R > Element
 

Public Member Functions

template<>
SVectorBase< Real > & operator= (const VectorBase< S > &vec)
 Assignment operator (specialization for Real). More...
 
template<>
Real operator* (const SVectorBase< S > &w) const
 specialization for inner product for sparse vectors More...
 
Access
int size () const
 Number of used indices. More...
 
int max () const
 Maximal number of indices. More...
 
int dim () const
 Dimension of the vector defined as maximal index + 1. More...
 
int pos (int i) const
 Position of index i. More...
 
operator[] (int i) const
 Value to index i. More...
 
Nonzero< R > & element (int n)
 Reference to the n 'th nonzero element. More...
 
const Nonzero< R > & element (int n) const
 The n 'th nonzero element. More...
 
int & index (int n)
 Reference to index of n 'th nonzero. More...
 
int index (int n) const
 Index of n 'th nonzero. More...
 
R & value (int n)
 Reference to value of n 'th nonzero. More...
 
const R & value (int n) const
 Value of n 'th nonzero. More...
 
void add (int i, const R &v)
 Append one nonzero (i,v). More...
 
void add (int i)
 Append one uninitialized nonzero. More...
 
void add (const SVectorBase &sv)
 Append nonzeros of sv. More...
 
void add (int n, const int i[], const R v[])
 Append n nonzeros. More...
 
template<class S >
void add (int n, const int i[], const S v[])
 Append n nonzeros. More...
 
void add (int n, const Nonzero< R > e[])
 Append n nonzeros. More...
 
void remove (int n, int m)
 Remove nonzeros n thru m. More...
 
void remove (int n)
 Remove n 'th nonzero. More...
 
void clear ()
 Remove all indices. More...
 
void sort ()
 Sort nonzeros to increasing indices. More...
 
Arithmetic operations
maxAbs () const
 Maximum absolute value, i.e., infinity norm. More...
 
minAbs () const
 Minimum absolute value. More...
 
length () const
 Floating point approximation of euclidian norm (without any approximation guarantee). More...
 
length2 () const
 Squared norm. More...
 
SVectorBase< R > & operator*= (const R &x)
 Scaling. More...
 
operator* (const VectorBase< R > &w) const
 Inner product. More...
 
template<class S >
operator* (const SVectorBase< S > &w) const
 inner product for sparse vectors More...
 
Constructions, destruction, and assignment
 SVectorBase (int n=0, Nonzero< R > *p_mem=0)
 Default constructor. More...
 
 SVectorBase (const SVectorBase< R > &sv)=default
 
template<class S >
SVectorBase< R > & operator= (const VectorBase< S > &vec)
 Assignment operator. More...
 
SVectorBase< R > & operator= (const SVectorBase< R > &sv)
 Assignment operator. More...
 
SVectorBase< R > & operator= (const SVectorBase< R > &&sv)
 move assignement operator. More...
 
template<class S >
SVectorBase< R > & operator= (const SVectorBase< S > &sv)
 Assignment operator. More...
 
SVectorBase< Real > & scaleAssign (int scaleExp, const SVectorBase< Real > &sv)
 scale and assign More...
 
SVectorBase< Real > & scaleAssign (const int *scaleExp, const SVectorBase< Real > &sv, bool negateExp=false)
 scale and assign More...
 
template<class S >
SVectorBase< R > & assignArray (const S *rowValues, const int *rowIndices, int rowSize)
 Assignment operator. More...
 
template<class S >
SVectorBase< R > & operator= (const SSVectorBase< S > &sv)
 Assignment operator. More...
 
Memory
Nonzero< R > * mem () const
 get pointer to internal memory. More...
 
void set_size (int s)
 Set size of the vector. More...
 
void set_max (int m)
 Set the maximum number of nonzeros in the vector. More...
 
void setMem (int n, Nonzero< R > *elmem)
 Set the memory area where the nonzeros will be stored. More...
 
Utilities
bool isConsistent () const
 Consistency check. More...
 

Private Attributes

Data
Nonzero< R > * m_elem
 
int memsize
 
int memused
 

Friends

template<class S >
class SVectorBase
 

Detailed Description

template<class R>
class soplex::SVectorBase< R >

Sparse vectors.

Class SVectorBase provides packed sparse vectors. Such are a sparse vectors, with a storage scheme that keeps all data in one contiguous block of memory. This is best suited for using them for parallel computing on a distributed memory multiprocessor.

SVectorBase does not provide any memory management (this will be done by class DSVectorBase). This means, that the constructor of SVectorBase expects memory where to save the nonzeros. Further, adding nonzeros to an SVectorBase may fail if no more memory is available for saving them (see also DSVectorBase).

When nonzeros are added to an SVectorBase, they are appended to the set of nonzeros, i.e., they recieve numbers size(), size()+1 ... . An SVectorBase can hold atmost max() nonzeros, where max() is given in the constructor. When removing nonzeros, the remaining nonzeros are renumbered. However, only the numbers greater than the number of the first removed nonzero are affected.

The following mathematical operations are provided by class SVectorBase (SVectorBase a, b, c; R x):

OperationDescription  
-= subtraction a -= b
+= addition a += b
* skalar product x = a * b
*= scaling a *= x
maxAbs() infinity norm a.maxAbs() == \(\|a\|_{\infty}\)
length() eucledian norm a.length() == \(\sqrt{a^2}\)
length2()square norm a.length2() == \(a^2\)

Operators += and -= should be used with caution, since no efficient implementation is available. One should think of assigning the left handside vector to a dense VectorBase first and perform the addition on it. The same applies to the scalar product *.

There are two numberings of the nonzeros of an SVectorBase. First, an SVectorBase is supposed to act like a linear algebra VectorBase. An index refers to this view of an SVectorBase: operator[]() is provided which returns the value at the given index of the vector, i.e., 0 for all indices which are not in the set of nonzeros. The other view of SVectorBases is that of a set of nonzeros. The nonzeros are numbered from 0 to size()-1. The methods index(int n) and value(int n) allow to access the index and value of the n 'th nonzero. n is referred to as the number of a nonzero.

Todo:
SVectorBase should get a new implementation. There maybe a lot of memory lost due to padding the Nonzero structure. A better idea seems to be class SVectorBase { int size; int used; int* idx; R* val; }; which for several reasons could be faster or slower. If SVectorBase is changed, also DSVectorBase and SVSet have to be modified.

Definition at line 34 of file ssvectorbase.h.

Member Typedef Documentation

◆ Element

typedef Nonzero<R> Element

Definition at line 148 of file svectorbase.h.

Constructor & Destructor Documentation

◆ SVectorBase() [1/2]

SVectorBase ( int  n = 0,
Nonzero< R > *  p_mem = 0 
)
explicit

Default constructor.

The constructor expects one memory block where to store the nonzero elements. This must be passed to the constructor, where the number of Nonzeros needs that fit into the memory must be given and a pointer to the beginning of the memory block. Once this memory has been passed, it shall not be modified until the SVectorBase is no longer used.

Definition at line 616 of file svectorbase.h.

◆ SVectorBase() [2/2]

SVectorBase ( const SVectorBase< R > &  sv)
default

Member Function Documentation

◆ add() [1/6]

void add ( int  i,
const R &  v 
)

◆ add() [2/6]

void add ( int  i)

Append one uninitialized nonzero.

Definition at line 291 of file svectorbase.h.

◆ add() [3/6]

void add ( const SVectorBase< R > &  sv)

Append nonzeros of sv.

Definition at line 305 of file svectorbase.h.

◆ add() [4/6]

void add ( int  n,
const int  i[],
const R  v[] 
)

Append n nonzeros.

Definition at line 311 of file svectorbase.h.

◆ add() [5/6]

void add ( int  n,
const int  i[],
const S  v[] 
)

Append n nonzeros.

Definition at line 342 of file svectorbase.h.

◆ add() [6/6]

void add ( int  n,
const Nonzero< R >  e[] 
)

Append n nonzeros.

Definition at line 371 of file svectorbase.h.

◆ assignArray()

SVectorBase<R>& assignArray ( const S *  rowValues,
const int *  rowIndices,
int  rowSize 
)

Assignment operator.

Definition at line 756 of file svectorbase.h.

Referenced by SVSetBase< Rational >::add().

◆ clear()

◆ dim()

int dim ( ) const

Dimension of the vector defined as maximal index + 1.

Definition at line 169 of file svectorbase.h.

Referenced by SSVectorBase< Rational >::assign(), VectorBase< Rational >::operator*(), and SSVectorBase< Rational >::SSVectorBase().

◆ element() [1/2]

◆ element() [2/2]

const Nonzero<R>& element ( int  n) const

The n 'th nonzero element.

Definition at line 228 of file svectorbase.h.

◆ index() [1/2]

◆ index() [2/2]

int index ( int  n) const

Index of n 'th nonzero.

Definition at line 246 of file svectorbase.h.

◆ isConsistent()

bool isConsistent ( ) const

◆ length()

R length ( ) const

Floating point approximation of euclidian norm (without any approximation guarantee).

Definition at line 510 of file svectorbase.h.

◆ length2()

R length2 ( ) const

Squared norm.

Definition at line 516 of file svectorbase.h.

◆ max()

int max ( ) const

◆ maxAbs()

R maxAbs ( ) const

Maximum absolute value, i.e., infinity norm.

Definition at line 478 of file svectorbase.h.

◆ mem()

Nonzero<R>* mem ( ) const

get pointer to internal memory.

Definition at line 784 of file svectorbase.h.

Referenced by SVSetBase< Rational >::deleteVec(), UnitVectorBase< R >::isConsistent(), and SVSetBase< Rational >::xtend().

◆ minAbs()

R minAbs ( ) const

Minimum absolute value.

Definition at line 494 of file svectorbase.h.

◆ operator*() [1/3]

R operator* ( const VectorBase< R > &  w) const

Inner product.

Definition at line 1037 of file basevectors.h.

◆ operator*() [2/3]

R operator* ( const SVectorBase< S > &  w) const

inner product for sparse vectors

Definition at line 553 of file svectorbase.h.

◆ operator*() [3/3]

Real operator* ( const SVectorBase< S > &  w) const

specialization for inner product for sparse vectors

Definition at line 857 of file svectorbase.h.

◆ operator*=()

SVectorBase<R>& operator*= ( const R &  x)

Scaling.

Definition at line 532 of file svectorbase.h.

◆ operator=() [1/6]

SVectorBase< R > & operator= ( const VectorBase< S > &  vec)

◆ operator=() [2/6]

SVectorBase<R>& operator= ( const SVectorBase< R > &  sv)

Assignment operator.

Definition at line 628 of file svectorbase.h.

◆ operator=() [3/6]

SVectorBase<R>& operator= ( const SVectorBase< R > &&  sv)

move assignement operator.

Definition at line 659 of file svectorbase.h.

◆ operator=() [4/6]

SVectorBase<R>& operator= ( const SVectorBase< S > &  sv)

Assignment operator.

Definition at line 673 of file svectorbase.h.

◆ operator=() [5/6]

SVectorBase< R > & operator= ( const SSVectorBase< S > &  sv)

Assignment operator.

Definition at line 1004 of file basevectors.h.

◆ operator=() [6/6]

SVectorBase< Real > & operator= ( const VectorBase< S > &  vec)

Assignment operator (specialization for Real).

Definition at line 973 of file basevectors.h.

◆ operator[]()

R operator[] ( int  i) const

Value to index i.

Definition at line 208 of file svectorbase.h.

◆ pos()

int pos ( int  i) const

Position of index i.

Returns
Finds the position of the first index i in the index set. If no such index i is found, -1 is returned. Otherwise, index(pos(i)) == i holds.

Definition at line 188 of file svectorbase.h.

Referenced by SPxLPBase< R >::changeCol(), SPxLPBase< R >::changeElement(), SPxLPBase< R >::changeRow(), SPxLPBase< R >::doRemoveCol(), SPxLPBase< R >::doRemoveRow(), and SPxLPBase< R >::isConsistent().

◆ remove() [1/2]

◆ remove() [2/2]

void remove ( int  n)

Remove n 'th nonzero.

Definition at line 421 of file svectorbase.h.

◆ scaleAssign() [1/2]

SVectorBase<Real>& scaleAssign ( int  scaleExp,
const SVectorBase< Real > &  sv 
)

scale and assign

Definition at line 704 of file svectorbase.h.

◆ scaleAssign() [2/2]

SVectorBase<Real>& scaleAssign ( const int *  scaleExp,
const SVectorBase< Real > &  sv,
bool  negateExp = false 
)

scale and assign

Definition at line 723 of file svectorbase.h.

◆ set_max()

void set_max ( int  m)

Set the maximum number of nonzeros in the vector.

Definition at line 797 of file svectorbase.h.

◆ set_size()

◆ setMem()

void setMem ( int  n,
Nonzero< R > *  elmem 
)

Set the memory area where the nonzeros will be stored.

Definition at line 804 of file svectorbase.h.

Referenced by DSVectorBase< Rational >::allocMem(), SVSetBase< Rational >::deleteVec(), DSVectorBase< Rational >::setMax(), and SVSetBase< Rational >::xtend().

◆ size()

int size ( ) const

Number of used indices.

Definition at line 155 of file svectorbase.h.

Referenced by DSVectorBase< Rational >::add(), SVectorBase< Rational >::add(), SVSetBase< Rational >::add(), SVSetBase< Rational >::add2(), SPxLPBase< R >::addCols(), SPxLPBase< R >::addDualActivity(), SPxLPBase< R >::added2Set(), SPxLPBase< R >::addPrimalActivity(), SPxLPBase< R >::addRows(), VectorBase< Rational >::assign(), SSVectorBase< Rational >::assign(), SSVectorBase< Rational >::assign2product1(), SSVectorBase< Rational >::assign2productAndSetup(), SSVectorBase< Rational >::assign2productFull(), SSVectorBase< Rational >::assign2productShort(), SPxLPBase< R >::changeCol(), SPxLPBase< R >::changeRow(), SPxBasisBase< R >::coSolve(), SVSetBase< Rational >::deleteVec(), SPxLPBase< R >::doAddCol(), SPxLPBase< R >::doAddCols(), SPxLPBase< R >::doAddRow(), SPxLPBase< R >::doAddRows(), SPxLPBase< R >::doRemoveCol(), SPxLPBase< R >::doRemoveCols(), SPxLPBase< R >::doRemoveRow(), SPxLPBase< R >::doRemoveRows(), SPxMainSM< R >::DuplicateRowsPS::DuplicateRowsPS(), SPxMainSM< R >::ForceConstraintPS::ForceConstraintPS(), SPxMainSM< R >::FreeZeroObjVariablePS::FreeZeroObjVariablePS(), Presol< R >::getBasis(), UnitVectorBase< R >::isConsistent(), SPxLPBase< R >::isConsistent(), VectorBase< Rational >::multAdd(), SSVectorBase< Rational >::multAdd(), VectorBase< Rational >::multSub(), VectorBase< Rational >::operator*(), SVectorBase< Rational >::operator*(), soplex::operator*(), VectorBase< Rational >::operator+=(), VectorBase< Rational >::operator-=(), DSVectorBase< Rational >::operator=(), VectorBase< Rational >::operator=(), SVectorBase< Rational >::operator=(), SVectorBase< Rational >::scaleAssign(), DSVectorBase< Rational >::setMax(), SPxBasisBase< R >::solve(), SPxBasisBase< R >::solve4update(), and SVSetBase< Rational >::xtend().

◆ sort()

void sort ( )

Sort nonzeros to increasing indices.

Definition at line 440 of file svectorbase.h.

◆ value() [1/2]

◆ value() [2/2]

const R& value ( int  n) const

Value of n 'th nonzero.

Definition at line 264 of file svectorbase.h.

Friends And Related Function Documentation

◆ SVectorBase

friend class SVectorBase
friend

Definition at line 132 of file svectorbase.h.

Member Data Documentation

◆ m_elem

Nonzero<R>* m_elem
private

◆ memsize

int memsize
private

Definition at line 141 of file svectorbase.h.

◆ memused

int memused
private

Definition at line 142 of file svectorbase.h.