Scippy

SoPlex

Sequential object-oriented simPlex

DataArray< T > Class Template Reference

Safe arrays of data objects.Class DataArray provides safe arrays of Data Objects. For general C++ objects (in contrast to data objects) class Array is provided which manages memory in a C++ compliant way. More...

#include <dataarray.h>

Public Member Functions

T & operator[] (int n)
 reference n 'th element. More...
 
const T & operator[] (int n) const
 reference n 'th const element. More...
 
T & last ()
 reference last element. More...
 
const T & last () const
 reference last const element. More...
 
T * get_ptr ()
 get a C pointer to the data. More...
 
const T * get_const_ptr () const
 get a const C pointer to the data. More...
 
void append (const T &t)
 append element t. More...
 
void append (int n, const T &t)
 append n elements with value t. More...
 
void append (int n, const T t[])
 append n elements from t. More...
 
void append (const DataArray< T > &t)
 append all elements from t. More...
 
void insert (int i, int n)
 insert n uninitialized elements before i 'th element. More...
 
void insert (int i, int n, const T &t)
 insert n elements with value t before i 'the element. More...
 
void insert (int i, int n, const T t[])
 insert n elements from t before i 'the element. More...
 
void insert (int i, const DataArray< T > &t)
 insert all elements from t before i 'th element. More...
 
void remove (int n=0, int m=1)
 remove m elements starting at n. More...
 
void removeLast (int m=1)
 remove m last elements. More...
 
void clear ()
 remove all elements. More...
 
int size () const
 return nr. of elements. More...
 
void reSize (int newsize)
 reset size to newsize. More...
 
int max () const
 return maximum number of elements. More...
 
void reMax (int newMax=1, int newSize=-1)
 reset maximum number of elements. More...
 
DataArrayoperator= (const DataArray &rhs)
 assignment operator More...
 
bool isConsistent () const
 consistency check More...
 
 DataArray (const DataArray &old)
 copy constructor More...
 
 DataArray (int p_size=0, int p_max=0, Real p_fac=1.2)
 default constructor. More...
 
 ~DataArray ()
 destructor More...
 

Protected Attributes

Real memFactor
 memory extension factor. More...
 

Private Attributes

int thesize
 number of used elements in array data More...
 
int themax
 the length of array data and More...
 
T * data
 the array of elements More...
 

Detailed Description

template<class T>
class soplex::DataArray< T >

Safe arrays of data objects.

Class DataArray provides safe arrays of Data Objects. For general C++ objects (in contrast to data objects) class Array is provided which manages memory in a C++ compliant way.

The elements of an instance of DataArray can be accessed just like ordinary C++ array elements by means of the index operator[](). Safety is provided by

  • automatic memory management in constructor and destructor preventing memory leaks
  • checking of array bounds when accessing elements with the indexing operator[]() (only when compiled without -DNDEBUG).

Moreover, DataArrays may easily be extended by inserting or appending elements to the DataArray or shrunken by removing elements. Method reSize(int n) resets the DataArrays length to n thereby possibly appending elements or truncating the DataArray to the required size.

A DataArray may be used as arguments for standard C functions requiring pointers through the use of get_ptr() and get_const_ptr().

Internally, a DataArray object allocates a block of memory that fits up to max() elements, only size() of them are used. This makes extension and shrinking methods perform better.

See also
Array, Data Objects

Definition at line 63 of file dataarray.h.

Constructor & Destructor Documentation

◆ DataArray() [1/2]

DataArray ( const DataArray< T > &  old)

copy constructor

Definition at line 315 of file dataarray.h.

◆ DataArray() [2/2]

DataArray ( int  p_size = 0,
int  p_max = 0,
Real  p_fac = 1.2 
)
explicit

default constructor.

The constructor allocates an Array containing size uninitialized elements. The internal array is allocated to have max nonzeros, and the memory extension factor is set to fac.

Parameters
p_sizenumber of unitialised elements.
p_maxmaximum number of elements the array can hold.
p_facvalue for memFactor.

Definition at line 340 of file dataarray.h.

◆ ~DataArray()

~DataArray ( )

destructor

Definition at line 357 of file dataarray.h.

Member Function Documentation

◆ append() [1/4]

◆ append() [2/4]

void append ( int  n,
const T &  t 
)

append n elements with value t.

Definition at line 126 of file dataarray.h.

◆ append() [3/4]

void append ( int  n,
const T  t[] 
)

append n elements from t.

Definition at line 131 of file dataarray.h.

◆ append() [4/4]

void append ( const DataArray< T > &  t)

append all elements from t.

Definition at line 136 of file dataarray.h.

◆ clear()

◆ get_const_ptr()

◆ get_ptr()

◆ insert() [1/4]

void insert ( int  i,
int  n 
)

insert n uninitialized elements before i 'th element.

move n elements in memory from insert position i to the back

Definition at line 142 of file dataarray.h.

Referenced by DataArray< const soplex::SVectorBase * >::append(), and DataArray< const soplex::SVectorBase * >::insert().

◆ insert() [2/4]

void insert ( int  i,
int  n,
const T &  t 
)

insert n elements with value t before i 'the element.

Definition at line 157 of file dataarray.h.

◆ insert() [3/4]

void insert ( int  i,
int  n,
const T  t[] 
)

insert n elements from t before i 'the element.

Definition at line 169 of file dataarray.h.

◆ insert() [4/4]

void insert ( int  i,
const DataArray< T > &  t 
)

insert all elements from t before i 'th element.

Definition at line 179 of file dataarray.h.

◆ isConsistent()

◆ last() [1/2]

T& last ( )

reference last element.

Definition at line 97 of file dataarray.h.

◆ last() [2/2]

const T& last ( ) const

reference last const element.

Definition at line 103 of file dataarray.h.

◆ max()

int max ( ) const

return maximum number of elements.

Even though the DataArray currently holds no more than size() elements, up to max() elements could be added without need to reallocated free store.

Definition at line 243 of file dataarray.h.

Referenced by DataArray< const soplex::SVectorBase * >::DataArray().

◆ operator=()

DataArray& operator= ( const DataArray< T > &  rhs)

assignment operator

Definition at line 284 of file dataarray.h.

◆ operator[]() [1/2]

T& operator[] ( int  n)

reference n 'th element.

Definition at line 82 of file dataarray.h.

◆ operator[]() [2/2]

const T& operator[] ( int  n) const

reference n 'th const element.

Definition at line 89 of file dataarray.h.

◆ reMax()

void reMax ( int  newMax = 1,
int  newSize = -1 
)

reset maximum number of elements.

The value of max() is reset to newMax thereby setting size() to newSize. However, if newSize has a value < 0 (as the default argument does) size() remains unchanged and max() is set to MIN(size(), newMax). Hence, calling reMax() without the default arguments, will reduce the memory consumption to a minimum. In no instance max() will be set to a value less than 1 (even if specified).

Definition at line 258 of file dataarray.h.

Referenced by DataArray< const soplex::SVectorBase * >::reSize(), SPxDevexPR::setType(), and SPxSteepPR::setType().

◆ remove()

void remove ( int  n = 0,
int  m = 1 
)

remove m elements starting at n.

Definition at line 189 of file dataarray.h.

◆ removeLast()

void removeLast ( int  m = 1)

remove m last elements.

Definition at line 202 of file dataarray.h.

Referenced by SoPlex::_removeColReal(), and SoPlex::_removeRowReal().

◆ reSize()

void reSize ( int  newsize)

reset size to newsize.

Resizing a DataArray to less than the previous size, involves discarding its last elements. Resizing to a larger value involves adding uninitialized elements (similar to append()). If neccessary, also memory will be reallocated.

Parameters
newsizethe new number of elements the array can hold.

Definition at line 226 of file dataarray.h.

Referenced by SoPlex::_computeBasisInverseRational(), SoPlex::_decompResolveWithoutPreprocessing(), SoPlex::_evaluateSolutionDecomp(), SoPlex::_factorizeColumnRational(), SoPlex::_formDecompReducedProblem(), SoPlex::_optimizeRational(), SoPlex::_project(), SoPlex::_recomputeRangeTypesRational(), SoPlex::_recomputeRangeTypesReal(), SoPlex::_removeColsReal(), SoPlex::_removeRowsReal(), SoPlex::_resolveWithoutPreprocessing(), SoPlex::_solveDecompositionDualSimplex(), SoPlex::_solveRealForRational(), SoPlex::_storeSolutionReal(), SoPlex::_storeSolutionRealFromPresol(), SoPlex::_untransformEquality(), SoPlex::_untransformFeasibility(), SoPlex::_untransformUnbounded(), SoPlex::_updateDecompReducedProblem(), SoPlex::_writeOriginalProblemBasis(), LPColSetBase< Rational >::add(), LPRowSetBase< Real >::add(), SoPlex::computeBasisInverseRational(), LPColSetBase< Rational >::create(), LPRowSetBase< Real >::create(), SPxLPBase< Real >::doAddCols(), SPxLPBase< Real >::doAddRows(), SPxWeightST::generate(), SPxSolver::init(), DataArray< const soplex::SVectorBase * >::insert(), DataArray< const soplex::SVectorBase * >::operator=(), SoPlex::readBasisFile(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::reMax(), LPColSetBase< Rational >::reMax(), LPRowSetBase< Real >::reMax(), LPColSetBase< Rational >::remove(), LPRowSetBase< Real >::remove(), SoPlex::removeColRational(), SoPlex::removeColReal(), SoPlex::removeColsRational(), SoPlex::removeColsReal(), SoPlex::removeRowRational(), SoPlex::removeRowReal(), SoPlex::removeRowsRational(), SoPlex::removeRowsReal(), SPxBasis::Desc::reSize(), SoPlex::setBasis(), SPxSolver::setIntegralityInformation(), SPxScaler::setup(), SPxMainSM::simplify(), SPxMainSM::SPxMainSM(), and SPxMainSM::unsimplify().

◆ size()

int size ( ) const

return nr. of elements.

Definition at line 214 of file dataarray.h.

Referenced by SoPlex::_completeRangeTypesRational(), SoPlex::_computeBasisInverseRational(), SoPlex::_decompResolveWithoutPreprocessing(), SoPlex::_decompSimplifyAndSolve(), SoPlex::_ensureRealLPLoaded(), SoPlex::_evaluateSolutionDecomp(), SoPlex::_factorizeColumnRational(), SoPlex::_isConsistent(), SoPlex::_optimizeRational(), SoPlex::_performOptIRStable(), SoPlex::_preprocessAndSolveReal(), SoPlex::_removeColReal(), SoPlex::_removeRowReal(), SoPlex::_resolveWithoutPreprocessing(), SoPlex::_solveDecompositionDualSimplex(), SoPlex::_solveRealForRational(), SoPlex::_storeSolutionReal(), SoPlex::_storeSolutionRealFromPresol(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::add(), SPxScaler::applyScaling(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::autoHashSize(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::autoHashSizeold(), SoPlex::basisColStatus(), SoPlex::basisRowStatus(), SPxDevexPR::buildBestPriceVectorEnterCoDim(), SPxSteepPR::buildBestPriceVectorEnterCoDim(), SPxDevexPR::buildBestPriceVectorEnterDim(), SPxSteepPR::buildBestPriceVectorEnterDim(), SPxDevexPR::buildBestPriceVectorLeave(), SPxSteepPR::buildBestPriceVectorLeave(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::clear(), SPxBasis::Desc::coDim(), SPxScaler::computeExpVec(), SPxBasis::Desc::dim(), SPxWeightST::generate(), SoPlex::getBasis(), SPxMainSM::getBasis(), SoPlex::getBasisInd(), SoPlex::getBasisIndRational(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::index(), soplex::initPrefs(), DataArray< const soplex::SVectorBase * >::insert(), SPxSolver::isBasisValid(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::isConsistent(), SPxScaler::maxAbsColscale(), SPxScaler::maxAbsRowscale(), SPxScaler::minAbsColscale(), SPxScaler::minAbsRowscale(), SPxBasis::Desc::nCols(), SPxBasis::Desc::nRows(), soplex::operator<<(), DataArray< const soplex::SVectorBase * >::operator=(), SPxMainSM::operator=(), SPxSolver::performSolutionPolishing(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::reMax(), DataArray< const soplex::SVectorBase * >::remove(), DataArray< const soplex::SVectorBase * >::removeLast(), SPxBasis::Desc::reSize(), SPxFastRT::selectEnter(), SPxFastRT::selectLeave(), SPxVectorST::setupWeights(), SPxMainSM::simplify(), SPxMainSM::unsimplify(), SoPlex::writeBasisFile(), and SPxMainSM::~SPxMainSM().

Member Data Documentation

◆ data

◆ memFactor

Real memFactor
protected

memory extension factor.

When a DataArray is reSize()d to more than max() elements, the new value for max() is not just set to the new size but rather to memFactor * size. This makes reSizeing perform better in codes where a DataArray is extended often by a small number of elements only.

Definition at line 77 of file dataarray.h.

◆ themax

int themax
private

the length of array data and

Definition at line 67 of file dataarray.h.

Referenced by DataArray< const soplex::SVectorBase * >::max().

◆ thesize

int thesize
private

number of used elements in array data

Definition at line 66 of file dataarray.h.

Referenced by DataArray< const soplex::SVectorBase * >::insert(), and DataArray< const soplex::SVectorBase * >::size().