Scippy

SoPlex

Sequential object-oriented simPlex

VectorBase< R > Class Template Reference

Dense vector.Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std::vector. More...

#include <dsvectorbase.h>

Public Member Functions

bool isConsistent () const
 Consistency check. More...
 
template<>
Rational operator* (const VectorBase< Rational > &vec) const
 Inner product. More...
 
Construction and assignment
 VectorBase ()
 Constructor. More...
 
 VectorBase (int dimen, R *p_val)
 
 VectorBase (int p_dimen)
 
template<typename S >
 VectorBase (const VectorBase< S > &vec)
 
 VectorBase (const VectorBase< R > &&vec) noexcept
 
 VectorBase (const VectorBase< R > &vec)
 
template<class S >
VectorBase< R > & operator= (const VectorBase< S > &vec)
 Assignment operator. More...
 
VectorBase< R > & operator= (const VectorBase< R > &vec)
 Assignment operator. More...
 
VectorBase< R > & operator= (const VectorBase< R > &&vec)
 Move assignment operator. More...
 
VectorBase< R > & scaleAssign (int scaleExp, const VectorBase< R > &vec)
 scale and assign More...
 
VectorBase< R > & scaleAssign (const int *scaleExp, const VectorBase< R > &vec, bool negateExp=false)
 scale and assign More...
 
template<class S >
VectorBase< R > & operator= (const SVectorBase< S > &vec)
 Assignment operator. More...
 
template<class S >
VectorBase< R > & operator= (const SSVectorBase< S > &vec)
 Assignment operator. More...
 
template<class S >
VectorBase< R > & assign (const SVectorBase< S > &vec)
 Assign values of vec. More...
 
template<class S >
VectorBase< R > & assign (const SSVectorBase< S > &vec)
 Assign values of vec. More...
 
Arithmetic operations
void clear ()
 Set vector to contain all-zeros (keeping the same length) More...
 
template<class S >
VectorBase< R > & operator+= (const VectorBase< S > &vec)
 Addition. More...
 
template<class S >
VectorBase< R > & operator+= (const SVectorBase< S > &vec)
 Addition. More...
 
template<class S >
VectorBase< R > & operator+= (const SSVectorBase< S > &vec)
 Addition. More...
 
template<class S >
VectorBase< R > & operator-= (const VectorBase< S > &vec)
 Subtraction. More...
 
template<class S >
VectorBase< R > & operator-= (const SVectorBase< S > &vec)
 Subtraction. More...
 
template<class S >
VectorBase< R > & operator-= (const SSVectorBase< S > &vec)
 Subtraction. More...
 
template<class S >
VectorBase< R > & operator*= (const S &x)
 Scaling. More...
 
template<class S >
VectorBase< R > & operator/= (const S &x)
 Division. More...
 
operator* (const VectorBase< R > &vec) const
 Inner product. More...
 
operator* (const SVectorBase< R > &vec) const
 Inner product. More...
 
operator* (const SSVectorBase< R > &vec) const
 Inner product. More...
 
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...
 
template<class S , class T >
VectorBase< R > & multAdd (const S &x, const VectorBase< T > &vec)
 Addition of scaled vector. More...
 
template<class S , class T >
VectorBase< R > & multAdd (const S &x, const SVectorBase< T > &vec)
 Addition of scaled vector. More...
 
template<class S , class T >
VectorBase< R > & multSub (const S &x, const SVectorBase< T > &vec)
 Subtraction of scaled vector. More...
 
template<class S , class T >
VectorBase< R > & multAdd (const S &x, const SSVectorBase< T > &vec)
 Addition of scaled vector. More...
 

Protected Attributes

Data
std::vector< R > val
 Values of vector. More...
 

Friends

template<typename S >
class VectorBase
 

Access

bool operator== (const VectorBase< R > &vec1, const VectorBase< R > &vec2)
 Equality operator. More...
 
int dim () const
 Dimension of vector. More...
 
R & operator[] (int n)
 Return n 'th value by reference. More...
 
const R & operator[] (int n) const
 Return n 'th value. More...
 
const std::vector< R > & vec ()
 Return underlying std::vector. More...
 

Utilities

VectorBase< R > operator- (const VectorBase< R > &vec)
 
R * get_ptr ()
 Conversion to C-style pointer. More...
 
const R * get_const_ptr () const
 Conversion to C-style pointer. More...
 
std::vector< R >::const_iterator begin () const
 
std::vector< R >::iterator begin ()
 
std::vector< R >::const_iterator end () const
 
std::vector< R >::iterator end ()
 
int memSize () const
 
void reDim (int newdim, const bool setZero=true)
 Resets VectorBase's dimension to newdim. More...
 
void reSize (int newsize)
 Resets VectorBase's memory size to newsize. More...
 
const VectorBase< R > operator- (const VectorBase< R > &vec) const
 
const VectorBase< R > operator+ (const VectorBase< R > &v) const
 

Detailed Description

template<class R>
class soplex::VectorBase< R >

Dense vector.

Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std::vector.

After construction, the values of a VectorBase can be accessed with the subscript operator[](). Safety is provided by qchecking of array bound when accessing elements with the subscript operator[]() (only when compiled without -DNDEBUG).

A VectorBase is distinguished from a simple array of Reals or Rationals by providing a set of mathematical operations.

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

OperationDescription  
-= subtraction a -= b
+= addition a += b
* scalar product x = a * b
*= scaling a *= x
maxAbs() infinity norm a.maxAbs() == \(\|a\|_{\infty}\)
minAbs()

a.minAbs() == \(\min |a_i|\)

length() euclidian norm a.length() == \(\sqrt{a^2}\)
length2()square norm a.length2() == \(a^2\)
multAdd(x,b)add scaled vector a += x * b

When using any of these operations, the vectors involved must be of the same dimension. Also an SVectorBase b is allowed if it does not contain nonzeros with index greater than the dimension of a.q

Definition at line 28 of file dsvectorbase.h.

Constructor & Destructor Documentation

◆ VectorBase() [1/6]

Constructor.

There is no default constructor since the storage for a VectorBase must be provided externally. Storage must be passed as a memory block val at construction. It must be large enough to fit at least dimen values.

Definition at line 109 of file vectorbase.h.

◆ VectorBase() [2/6]

VectorBase ( int  dimen,
R *  p_val 
)

Definition at line 116 of file vectorbase.h.

◆ VectorBase() [3/6]

VectorBase ( int  p_dimen)
explicit

Definition at line 122 of file vectorbase.h.

◆ VectorBase() [4/6]

VectorBase ( const VectorBase< S > &  vec)

Definition at line 130 of file vectorbase.h.

◆ VectorBase() [5/6]

VectorBase ( const VectorBase< R > &&  vec)
noexcept

Definition at line 136 of file vectorbase.h.

◆ VectorBase() [6/6]

VectorBase ( const VectorBase< R > &  vec)

Definition at line 141 of file vectorbase.h.

Member Function Documentation

◆ assign() [1/2]

VectorBase< R > & assign ( const SVectorBase< S > &  vec)

Assign values of vec.

Assigns all nonzeros of vec to the vector. All other values remain unchanged.

Definition at line 78 of file basevectors.h.

Referenced by VectorBase< Rational >::scaleAssign(), and VectorBase< Rational >::VectorBase().

◆ assign() [2/2]

VectorBase< R > & assign ( const SSVectorBase< S > &  vec)

Assign values of vec.

Assigns all nonzeros of vec to the vector. All other values remain unchanged.

Definition at line 118 of file basevectors.h.

◆ begin() [1/2]

std::vector<R>::const_iterator begin ( ) const

Definition at line 501 of file vectorbase.h.

◆ begin() [2/2]

std::vector<R>::iterator begin ( )

Definition at line 506 of file vectorbase.h.

◆ clear()

◆ dim()

◆ end() [1/2]

std::vector<R>::const_iterator end ( ) const

Definition at line 512 of file vectorbase.h.

◆ end() [2/2]

std::vector<R>::iterator end ( )

Definition at line 517 of file vectorbase.h.

◆ get_const_ptr()

const R* get_const_ptr ( ) const

Conversion to C-style pointer.

This function serves for using a VectorBase in an C-style function. It returns a pointer to the first value of the array.

Definition at line 495 of file vectorbase.h.

Referenced by SPxWeightPR< R >::operator=(), and SPxWeightPR< R >::SPxWeightPR().

◆ get_ptr()

R* get_ptr ( )

Conversion to C-style pointer.

This function serves for using a VectorBase in an C-style function. It returns a pointer to the first value of the array.

Todo:
check whether this non-const c-style access should indeed be public

Definition at line 486 of file vectorbase.h.

Referenced by SSVectorBase< Rational >::get_ptr().

◆ isConsistent()

bool isConsistent ( ) const

Consistency check.

Definition at line 614 of file vectorbase.h.

Referenced by LPColSetBase< Rational >::isConsistent(), and SSVectorBase< Rational >::isConsistent().

◆ length()

R length ( ) const

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

Definition at line 437 of file vectorbase.h.

◆ length2()

R length2 ( ) const

Squared norm.

Definition at line 443 of file vectorbase.h.

Referenced by VectorBase< Rational >::length(), and SSVectorBase< Rational >::length2().

◆ maxAbs()

R maxAbs ( ) const

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

Definition at line 397 of file vectorbase.h.

Referenced by SSVectorBase< Rational >::maxAbs().

◆ memSize()

int memSize ( ) const

Definition at line 527 of file vectorbase.h.

◆ minAbs()

R minAbs ( ) const

Minimum absolute value.

Definition at line 417 of file vectorbase.h.

◆ multAdd() [1/3]

VectorBase<R>& multAdd ( const S &  x,
const VectorBase< T > &  vec 
)

◆ multAdd() [2/3]

VectorBase< R > & multAdd ( const S &  x,
const SVectorBase< T > &  vec 
)

Addition of scaled vector.

Definition at line 272 of file basevectors.h.

◆ multAdd() [3/3]

VectorBase< R > & multAdd ( const S &  x,
const SSVectorBase< T > &  vec 
)

Addition of scaled vector.

Definition at line 306 of file basevectors.h.

◆ multSub()

VectorBase< R > & multSub ( const S &  x,
const SVectorBase< T > &  vec 
)

Subtraction of scaled vector.

Definition at line 289 of file basevectors.h.

Referenced by SPxLPBase< R >::subDualActivity().

◆ operator*() [1/4]

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

Inner product.

Definition at line 378 of file vectorbase.h.

◆ operator*() [2/4]

R operator* ( const SVectorBase< R > &  vec) const

Inner product.

Definition at line 227 of file basevectors.h.

◆ operator*() [3/4]

R operator* ( const SSVectorBase< R > &  vec) const

Inner product.

Definition at line 244 of file basevectors.h.

◆ operator*() [4/4]

Rational operator* ( const VectorBase< Rational > &  vec) const

Inner product.

Definition at line 624 of file vectorbase.h.

◆ operator*=()

VectorBase<R>& operator*= ( const S &  x)

Scaling.

Definition at line 352 of file vectorbase.h.

◆ operator+()

const VectorBase<R> operator+ ( const VectorBase< R > &  v) const

Definition at line 580 of file vectorbase.h.

◆ operator+=() [1/3]

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

Addition.

Definition at line 308 of file vectorbase.h.

Referenced by VectorBase< Rational >::operator+=(), and SSVectorBase< Rational >::operator+=().

◆ operator+=() [2/3]

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

Addition.

Definition at line 144 of file basevectors.h.

◆ operator+=() [3/3]

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

Addition.

Definition at line 162 of file basevectors.h.

◆ operator-()

const VectorBase<R> operator- ( const VectorBase< R > &  vec) const

Definition at line 563 of file vectorbase.h.

◆ operator-=() [1/3]

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

Subtraction.

Definition at line 330 of file vectorbase.h.

Referenced by VectorBase< Rational >::operator-=(), and SSVectorBase< Rational >::operator-=().

◆ operator-=() [2/3]

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

Subtraction.

Definition at line 186 of file basevectors.h.

◆ operator-=() [3/3]

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

Subtraction.

Definition at line 204 of file basevectors.h.

◆ operator/=()

VectorBase<R>& operator/= ( const S &  x)

Division.

Definition at line 365 of file vectorbase.h.

◆ operator=() [1/5]

◆ operator=() [2/5]

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

Assignment operator.

Definition at line 166 of file vectorbase.h.

◆ operator=() [3/5]

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

Move assignment operator.

Definition at line 179 of file vectorbase.h.

◆ operator=() [4/5]

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

Assignment operator.

Assigning an SVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is diffent in method assign().

Assigning an SVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is different in method assign().

Definition at line 58 of file basevectors.h.

◆ operator=() [5/5]

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

Assignment operator.

Assigning an SSVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is diffent in method assign().

Todo:
do we need this also in non-template version, because SSVectorBase can be automatically cast to VectorBase?

Assigning an SSVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is different in method assign().

Definition at line 98 of file basevectors.h.

◆ operator[]() [1/2]

R& operator[] ( int  n)

Return n 'th value by reference.

Definition at line 268 of file vectorbase.h.

◆ operator[]() [2/2]

const R& operator[] ( int  n) const

Return n 'th value.

Definition at line 275 of file vectorbase.h.

◆ reDim()

◆ reSize()

void reSize ( int  newsize)

Resets VectorBase's memory size to newsize.

Definition at line 552 of file vectorbase.h.

Referenced by LPColSetBase< Rational >::reMax(), LPRowSetBase< R >::reMax(), and SSVectorBase< Rational >::reMem().

◆ scaleAssign() [1/2]

VectorBase<R>& scaleAssign ( int  scaleExp,
const VectorBase< R > &  vec 
)

scale and assign

Definition at line 186 of file vectorbase.h.

◆ scaleAssign() [2/2]

VectorBase<R>& scaleAssign ( const int *  scaleExp,
const VectorBase< R > &  vec,
bool  negateExp = false 
)

scale and assign

Definition at line 203 of file vectorbase.h.

◆ vec()

const std::vector<R>& vec ( )

Friends And Related Function Documentation

◆ operator-

VectorBase<R> operator- ( const VectorBase< R > &  vec)
friend

Definition at line 597 of file vectorbase.h.

◆ operator==

bool operator== ( const VectorBase< R > &  vec1,
const VectorBase< R > &  vec2 
)
friend

Equality operator.

Definition at line 282 of file vectorbase.h.

◆ VectorBase

friend class VectorBase
friend

Definition at line 83 of file vectorbase.h.

Member Data Documentation

◆ val