|
SoPlex
|
Sparse vectors. More...
#include <svectorbase.h>
Public Types | |
| typedef Nonzero< R > | Element |
Public Member Functions | |
| SVectorBase< Real > & | operator= (const VectorBase< S > &vec) |
| Assignment operator (specialization for Real). | |
| Real | operator* (const SVectorBase< S > &w) const |
| specialization for inner product for sparse vectors | |
Access | |
| int | size () const |
| Number of used indices. | |
| int | max () const |
| Maximal number of indices. | |
| int | dim () const |
| Dimension of the vector defined as maximal index + 1. | |
| int | pos (int i) const |
Position of index i. | |
| R | operator[] (int i) const |
Value to index i. | |
| Nonzero< R > & | element (int n) |
Reference to the n 'th nonzero element. | |
| const Nonzero< R > & | element (int n) const |
The n 'th nonzero element. | |
| int & | index (int n) |
Reference to index of n 'th nonzero. | |
| int | index (int n) const |
Index of n 'th nonzero. | |
| R & | value (int n) |
Reference to value of n 'th nonzero. | |
| const R & | value (int n) const |
Value of n 'th nonzero. | |
| void | add (int i, const R &v) |
Append one nonzero (i,v). | |
| void | add (int i) |
| Append one uninitialized nonzero. | |
| void | add (const SVectorBase &sv) |
Append nonzeros of sv. | |
| void | add (int n, const int i[], const R v[]) |
Append n nonzeros. | |
| template<class S> | |
| void | add (int n, const int i[], const S v[]) |
Append n nonzeros. | |
| void | add (int n, const Nonzero< R > e[]) |
Append n nonzeros. | |
| void | remove (int n, int m) |
Remove nonzeros n thru m. | |
| void | remove (int n) |
Remove n 'th nonzero. | |
| void | clear () |
| Remove all indices. | |
| void | sort () |
| Sort nonzeros to increasing indices. | |
Arithmetic operations | |
| R | maxAbs () const |
| Maximum absolute value, i.e., infinity norm. | |
| R | minAbs () const |
| Minimum absolute value. | |
| R | length () const |
| Floating point approximation of euclidian norm (without any approximation guarantee). | |
| R | length2 () const |
| Squared norm. | |
| SVectorBase< R > & | operator*= (const R &x) |
| Scaling. | |
| R | operator* (const VectorBase< R > &w) const |
| Inner product. | |
| template<class S> | |
| R | operator* (const SVectorBase< S > &w) const |
| inner product for sparse vectors | |
Constructions, destruction, and assignment | |
| SVectorBase (int n=0, Nonzero< R > *p_mem=nullptr) | |
| Default constructor. | |
| SVectorBase (const SVectorBase< R > &sv)=default | |
| template<class S> | |
| SVectorBase< R > & | operator= (const VectorBase< S > &vec) |
| Assignment operator. | |
| SVectorBase< R > & | operator= (const SVectorBase< R > &sv) |
| Assignment operator. | |
| SVectorBase< R > & | operator= (const SVectorBase< R > &&sv) |
| move assignement operator. | |
| template<class S> | |
| SVectorBase< R > & | operator= (const SVectorBase< S > &sv) |
| Assignment operator. | |
| SVectorBase< Real > & | scaleAssign (int scaleExp, const SVectorBase< Real > &sv) |
| scale and assign | |
| SVectorBase< Real > & | scaleAssign (const int *scaleExp, const SVectorBase< Real > &sv, bool negateExp=false) |
| scale and assign | |
| template<class S> | |
| SVectorBase< R > & | assignArray (const S *rowValues, const int *rowIndices, int rowSize) |
| Assignment operator. | |
| template<class S> | |
| SVectorBase< R > & | operator= (const SSVectorBase< S > &sv) |
| Assignment operator. | |
Memory | |
| Nonzero< R > * | mem () const |
| get pointer to internal memory. | |
| void | set_size (int s) |
| Set size of the vector. | |
| void | set_max (int m) |
| Set the maximum number of nonzeros in the vector. | |
| void | setMem (int n, Nonzero< R > *elmem) |
| Set the memory area where the nonzeros will be stored. | |
Utilities | |
| bool | isConsistent () const |
| Consistency check. | |
| bool | hasNaNs () const |
| Checks whether the array contains any nan entries. | |
| bool | hasInfs () const |
| Checks whether the array contains any NaN entries. | |
Private Attributes | |
Data | |
| Nonzero< R > * | m_elem |
| int | memsize |
| int | memused |
Friends | |
| template<class S> | |
| class | SVectorBase |
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):
| Operation | Description |
< >
-=
subtraction
a -= b
+=
addition
a += b
*
skalar product
x = a * b
*=
scaling
a *= x
infinity norm
a.maxAbs() == \(\|a\|_{\infty}\)
eucledian norm
a.length() == \(\sqrt{a^2}\)
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.
Definition at line 138 of file svectorbase.h.
Definition at line 156 of file svectorbase.h.
|
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 623 of file svectorbase.h.
|
default |
| void add | ( | const SVectorBase< R > & | sv | ) |
Append nonzeros of sv.
Definition at line 312 of file svectorbase.h.
| void add | ( | int | i | ) |
Append one uninitialized nonzero.
Definition at line 299 of file svectorbase.h.
| void add | ( | int | i, |
| const R & | v ) |
Append one nonzero (i,v).
Definition at line 281 of file svectorbase.h.
Referenced by DSVectorBase< Real >::add(), DSVectorBase< Real >::add(), DSVectorBase< Real >::add(), DSVectorBase< Real >::add(), SVectorBase< Real >::add(), SVSetBase< Real >::add2(), SVSetBase< Real >::add2(), SVSetBase< Real >::add2(), and UnitVectorBase< Real >::UnitVectorBase().
| void add | ( | int | n, |
| const int | i[], | ||
| const R | v[] ) |
Append n nonzeros.
Definition at line 318 of file svectorbase.h.
| void add | ( | int | n, |
| const int | i[], | ||
| const S | v[] ) |
Append n nonzeros.
Definition at line 349 of file svectorbase.h.
| void add | ( | int | n, |
| const Nonzero< R > | e[] ) |
Append n nonzeros.
Definition at line 378 of file svectorbase.h.
| SVectorBase< R > & assignArray | ( | const S * | rowValues, |
| const int * | rowIndices, | ||
| int | rowSize ) |
Assignment operator.
Definition at line 765 of file svectorbase.h.
Referenced by SVSetBase< Real >::add().
| void clear | ( | ) |
Remove all indices.
Definition at line 441 of file svectorbase.h.
Referenced by DSVectorBase< Real >::add(), SPxLPBase< Real >::changeCol(), SPxLPBase< Real >::changeRow(), DSVectorBase< R >::operator=(), DSVectorBase< R >::operator=(), DSVectorBase< Real >::operator=(), DSVectorBase< Real >::operator=(), DSVectorBase< Real >::operator=(), and operator=().
| int dim | ( | ) | const |
Dimension of the vector defined as maximal index + 1.
Definition at line 177 of file svectorbase.h.
Referenced by SSVectorBase< R >::assign(), and SSVectorBase< Real >::assign().
| Nonzero< R > & element | ( | int | n | ) |
Reference to the n 'th nonzero element.
Definition at line 227 of file svectorbase.h.
Referenced by SSVectorBase< R >::assign2product1(), SSVectorBase< R >::assign2productAndSetup(), SSVectorBase< R >::assign2productFull(), SSVectorBase< R >::assign2productShort(), and SVectorBase< Real >::operator*().
| const Nonzero< R > & element | ( | int | n | ) | const |
The n 'th nonzero element.
Definition at line 236 of file svectorbase.h.
| bool hasInfs | ( | ) | const |
Checks whether the array contains any NaN entries.
Definition at line 880 of file svectorbase.h.
| bool hasNaNs | ( | ) | const |
Checks whether the array contains any nan entries.
Definition at line 859 of file svectorbase.h.
| int & index | ( | int | n | ) |
Reference to index of n 'th nonzero.
Definition at line 245 of file svectorbase.h.
Referenced by SPxLPBase< Real >::addCols(), SPxLPBase< Real >::addDualActivity(), SPxLPBase< Real >::added2Set(), SPxLPBase< Real >::addPrimalActivity(), SPxLPBase< Real >::addRows(), SSVectorBase< R >::assign(), SSVectorBase< Real >::assign(), SPxLPBase< Real >::changeCol(), SPxLPBase< Real >::changeRow(), SPxLPBase< Real >::doAddCol(), SPxLPBase< Real >::doAddCol(), SPxLPBase< Real >::doAddCols(), SPxLPBase< Real >::doAddRow(), SPxLPBase< Real >::doAddRow(), SPxLPBase< Real >::doAddRows(), SPxLPBase< Real >::doRemoveCol(), SPxLPBase< Real >::doRemoveCols(), SPxLPBase< Real >::doRemoveRow(), SPxLPBase< Real >::doRemoveRows(), SPxMainSM< R >::DuplicateRowsPS::DuplicateRowsPS(), SPxLPBase< Real >::isConsistent(), soplex::operator*(), soplex::operator<<(), SVectorBase< Real >::pos(), SVectorBase< Real >::scaleAssign(), SVectorBase< Real >::scaleAssign(), SoPlex_getRowVectorRational(), and SoPlex_getRowVectorReal().
| int index | ( | int | n | ) | const |
Index of n 'th nonzero.
Definition at line 254 of file svectorbase.h.
| bool isConsistent | ( | ) | const |
Consistency check.
Definition at line 830 of file svectorbase.h.
Referenced by UnitVectorBase< Real >::isConsistent(), SVectorBase< Real >::scaleAssign(), and SVectorBase< Real >::scaleAssign().
| R length | ( | ) | const |
Floating point approximation of euclidian norm (without any approximation guarantee).
Definition at line 517 of file svectorbase.h.
| R length2 | ( | ) | const |
Squared norm.
Definition at line 523 of file svectorbase.h.
Referenced by SVectorBase< Real >::length().
| int max | ( | ) | const |
Maximal number of indices.
Definition at line 170 of file svectorbase.h.
Referenced by SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::assignArray(), SVSetBase< Real >::deleteVec(), SVectorBase< Real >::element(), SVectorBase< Real >::isConsistent(), UnitVectorBase< Real >::isConsistent(), DSVectorBase< Real >::makeMem(), operator=(), SVectorBase< Real >::operator=(), SVectorBase< Real >::operator=(), SVectorBase< Real >::scaleAssign(), SVectorBase< Real >::scaleAssign(), DSVectorBase< Real >::setMax(), SVSetBase< Real >::xtend(), and DSVectorBase< Real >::~DSVectorBase().
| R maxAbs | ( | ) | const |
Maximum absolute value, i.e., infinity norm.
Definition at line 485 of file svectorbase.h.
| Nonzero< R > * mem | ( | ) | const |
get pointer to internal memory.
Definition at line 793 of file svectorbase.h.
Referenced by SVSetBase< Real >::deleteVec(), DSVectorBase< Real >::isConsistent(), UnitVectorBase< Real >::isConsistent(), and SVSetBase< Real >::xtend().
| R minAbs | ( | ) | const |
Minimum absolute value.
Definition at line 501 of file svectorbase.h.
| Real operator* | ( | const SVectorBase< S > & | w | ) | const |
specialization for inner product for sparse vectors
Definition at line 908 of file svectorbase.h.
inner product for sparse vectors
Definition at line 560 of file svectorbase.h.
| R operator* | ( | const VectorBase< R > & | w | ) | const |
Inner product.
Definition at line 1019 of file basevectors.h.
References Nonzero< R >::idx, m_elem, size(), and Nonzero< R >::val.
| SVectorBase< R > & operator*= | ( | const R & | x | ) |
Scaling.
Definition at line 539 of file svectorbase.h.
Assignment operator.
Definition at line 986 of file basevectors.h.
References Nonzero< R >::idx, SSVectorBase< R >::index(), m_elem, max(), set_size(), SSVectorBase< R >::size(), SVectorBase, and Nonzero< R >::val.
| SVectorBase< R > & operator= | ( | const SVectorBase< R > && | sv | ) |
move assignement operator.
Definition at line 665 of file svectorbase.h.
| SVectorBase< R > & operator= | ( | const SVectorBase< R > & | sv | ) |
Assignment operator.
Definition at line 635 of file svectorbase.h.
Assignment operator.
Definition at line 679 of file svectorbase.h.
| SVectorBase< Real > & operator= | ( | const VectorBase< S > & | vec | ) |
Assignment operator (specialization for Real).
Definition at line 954 of file basevectors.h.
Assignment operator.
Definition at line 922 of file basevectors.h.
References clear(), VectorBase< R >::dim(), m_elem, and SVectorBase.
Referenced by DSVectorBase< R >::DSVectorBase(), DSVectorBase< Real >::DSVectorBase(), DSVectorBase< Real >::DSVectorBase(), DSVectorBase< Real >::DSVectorBase(), DSVectorBase< R >::operator=(), DSVectorBase< R >::operator=(), DSVectorBase< Real >::operator=(), DSVectorBase< Real >::operator=(), DSVectorBase< Real >::operator=(), SVSetBase< R >::DLPSV::operator=(), and SVSetBase< R >::DLPSV::operator=().
| R operator[] | ( | int | i | ) | const |
Value to index i.
Definition at line 216 of file svectorbase.h.
| int pos | ( | int | i | ) | const |
Position of index i.
i in the index set. If no such index i is found, -1 is returned. Otherwise, index(pos(i)) == i holds. Definition at line 196 of file svectorbase.h.
Referenced by SPxLPBase< Real >::changeCol(), SPxLPBase< Real >::changeElement(), SPxLPBase< Real >::changeElement(), SPxLPBase< Real >::changeRow(), SPxLPBase< Real >::doRemoveCol(), SPxLPBase< Real >::doRemoveRow(), SPxLPBase< Real >::isConsistent(), and SVectorBase< Real >::operator[]().
| void remove | ( | int | n | ) |
Remove n 'th nonzero.
Definition at line 428 of file svectorbase.h.
| void remove | ( | int | n, |
| int | m ) |
Remove nonzeros n thru m.
Definition at line 404 of file svectorbase.h.
Referenced by SPxLPBase< Real >::changeCol(), SPxLPBase< Real >::changeElement(), SPxLPBase< Real >::changeElement(), SPxLPBase< Real >::changeRow(), SPxLPBase< Real >::doRemoveCol(), SPxLPBase< Real >::doRemoveCols(), SPxLPBase< Real >::doRemoveRow(), and SPxLPBase< Real >::doRemoveRows().
| SVectorBase< Real > & scaleAssign | ( | const int * | scaleExp, |
| const SVectorBase< Real > & | sv, | ||
| bool | negateExp = false ) |
scale and assign
Definition at line 730 of file svectorbase.h.
| SVectorBase< Real > & scaleAssign | ( | int | scaleExp, |
| const SVectorBase< Real > & | sv ) |
scale and assign
Definition at line 709 of file svectorbase.h.
| void set_max | ( | int | m | ) |
Set the maximum number of nonzeros in the vector.
Definition at line 806 of file svectorbase.h.
Referenced by SVectorBase< Real >::setMem().
| void set_size | ( | int | s | ) |
Set size of the vector.
Definition at line 799 of file svectorbase.h.
Referenced by SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::assignArray(), SVectorBase< Real >::clear(), SVSetBase< Real >::deleteVec(), operator=(), SVectorBase< Real >::operator=(), SVectorBase< Real >::operator=(), UnitVectorBase< Real >::operator=(), UnitVectorBase< Real >::operator=(), SVectorBase< Real >::remove(), SVectorBase< Real >::remove(), SVectorBase< Real >::scaleAssign(), SVectorBase< Real >::scaleAssign(), DSVectorBase< Real >::setMax(), SVectorBase< Real >::setMem(), UnitVectorBase< Real >::UnitVectorBase(), and SVSetBase< Real >::xtend().
| void setMem | ( | int | n, |
| Nonzero< R > * | elmem ) |
Set the memory area where the nonzeros will be stored.
Definition at line 813 of file svectorbase.h.
Referenced by DSVectorBase< Real >::allocMem(), SVSetBase< Real >::deleteVec(), DSVectorBase< Real >::setMax(), SVectorBase< Real >::SVectorBase(), and SVSetBase< Real >::xtend().
| int size | ( | ) | const |
Number of used indices.
Definition at line 163 of file svectorbase.h.
Referenced by DSVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVectorBase< Real >::add(), SVSetBase< Real >::add(), SVSetBase< Real >::add(), SVSetBase< Real >::add2(), SVSetBase< Real >::add2(), SVSetBase< Real >::add2(), SPxLPBase< Real >::addCols(), SPxLPBase< Real >::addDualActivity(), SPxLPBase< Real >::added2Set(), SPxLPBase< Real >::addPrimalActivity(), SPxLPBase< Real >::addRows(), SSVectorBase< R >::assign(), SSVectorBase< Real >::assign(), SSVectorBase< R >::assign2product1(), SSVectorBase< R >::assign2productAndSetup(), SSVectorBase< R >::assign2productFull(), SSVectorBase< R >::assign2productShort(), SPxLPBase< Real >::changeCol(), SPxLPBase< Real >::changeRow(), SPxBasisBase< Real >::coSolve(), SVSetBase< Real >::deleteVec(), SVectorBase< Real >::dim(), SPxLPBase< Real >::doAddCol(), SPxLPBase< Real >::doAddCol(), SPxLPBase< Real >::doAddCols(), SPxLPBase< Real >::doAddRow(), SPxLPBase< Real >::doAddRow(), SPxLPBase< Real >::doAddRows(), SPxLPBase< Real >::doRemoveCol(), SPxLPBase< Real >::doRemoveCols(), SPxLPBase< Real >::doRemoveRow(), SPxLPBase< Real >::doRemoveRows(), DSVectorBase< Real >::DSVectorBase(), DSVectorBase< Real >::DSVectorBase(), DSVectorBase< Real >::DSVectorBase(), SPxMainSM< R >::DuplicateRowsPS::DuplicateRowsPS(), SVectorBase< Real >::element(), SVectorBase< Real >::hasInfs(), SVectorBase< Real >::hasNaNs(), SVectorBase< Real >::index(), SVectorBase< Real >::index(), SPxLPBase< Real >::isConsistent(), SVectorBase< Real >::isConsistent(), UnitVectorBase< Real >::isConsistent(), SVectorBase< Real >::length2(), DSVectorBase< Real >::makeMem(), SVectorBase< Real >::maxAbs(), SVectorBase< Real >::minAbs(), soplex::operator*(), operator*(), SVectorBase< Real >::operator*(), SVectorBase< Real >::operator*=(), soplex::operator<<(), DSVectorBase< Real >::operator=(), DSVectorBase< Real >::operator=(), DSVectorBase< Real >::operator=(), SVectorBase< Real >::operator=(), SVectorBase< Real >::operator=(), SVectorBase< Real >::pos(), SVectorBase< Real >::remove(), SVectorBase< Real >::remove(), SVectorBase< Real >::scaleAssign(), SVectorBase< Real >::scaleAssign(), DSVectorBase< Real >::setMax(), SPxBasisBase< Real >::solve(), SPxBasisBase< Real >::solve4update(), SoPlex_getRowVectorRational(), SoPlex_getRowVectorReal(), SVectorBase< Real >::sort(), SVectorBase< Real >::value(), SVectorBase< Real >::value(), and SVSetBase< Real >::xtend().
| void sort | ( | ) |
Sort nonzeros to increasing indices.
Definition at line 447 of file svectorbase.h.
| R & value | ( | int | n | ) |
Reference to value of n 'th nonzero.
Definition at line 263 of file svectorbase.h.
Referenced by SPxLPBase< Real >::addCols(), SPxLPBase< Real >::addDualActivity(), SPxLPBase< Real >::added2Set(), SPxLPBase< Real >::addPrimalActivity(), SPxLPBase< Real >::addRows(), SSVectorBase< R >::assign(), SSVectorBase< Real >::assign(), SPxLPBase< Real >::changeCol(), SPxLPBase< Real >::changeElement(), SPxLPBase< Real >::changeElement(), SPxLPBase< Real >::changeRow(), SPxLPBase< Real >::doAddCol(), SPxLPBase< Real >::doAddCol(), SPxLPBase< Real >::doAddCols(), SPxLPBase< Real >::doAddRow(), SPxLPBase< Real >::doAddRow(), SPxLPBase< Real >::doAddRows(), SPxLPBase< Real >::isConsistent(), soplex::operator*(), soplex::operator<<(), SVectorBase< Real >::scaleAssign(), SVectorBase< Real >::scaleAssign(), SoPlex_getRowVectorRational(), and SoPlex_getRowVectorReal().
| const R & value | ( | int | n | ) | const |
Value of n 'th nonzero.
Definition at line 272 of file svectorbase.h.
|
friend |
Definition at line 140 of file svectorbase.h.
Referenced by SVSetBase< R >::DLPSV::DLPSV(), SVSetBase< R >::DLPSV::DLPSV(), SVSetBase< R >::DLPSV::DLPSV(), operator=(), and operator=().
|
private |
Definition at line 148 of file svectorbase.h.
Referenced by SVectorBase< Real >::add(), operator*(), operator=(), operator=(), SVectorBase< Real >::operator=(), and SVectorBase< Real >::operator=().
|
private |
Definition at line 149 of file svectorbase.h.
|
private |
Definition at line 150 of file svectorbase.h.