28#ifndef _BASEVECTORS_H_
29#define _BASEVECTORS_H_
33#define SOPLEX_DEBUG_BASEVECTORS
68 for(
int i = 0; i < vec.
size(); ++i)
70 assert(vec.
index(i) < dim());
86 for(
int i = vec.
size() - 1; i >= 0; --i)
88 assert(vec.
index(i) < dim());
126 assert(vec.
dim() <= dim());
132 for(
int i = vec.
size() - 1; i >= 0; --i)
134 val[*idx] = vec.
val[*idx];
152 for(
int i = vec.
size() - 1; i >= 0; --i)
154 assert(vec.
index(i) >= 0);
155 assert(vec.
index(i) < dim());
170 assert(dim() == vec.
dim());
174 for(
int i = vec.
size() - 1; i >= 0 ; --i)
179 for(
int i = dim() - 1; i >= 0; --i)
194 for(
int i = vec.
size() - 1; i >= 0; --i)
196 assert(vec.
index(i) >= 0);
197 assert(vec.
index(i) < dim());
212 assert(dim() == vec.
dim());
216 for(
int i = vec.
size() - 1; i >= 0; --i)
221 for(
int i = dim() - 1; i >= 0; --i)
235 assert(dim() >= vec.
dim());
239 for(
int i = vec.
size() - 1; i >= 0; --i)
252 assert(dim() == vec.
dim());
260 for(
int i = vec.
size() - 1; i >= 0; --i)
262 x += val[*idx] * vec.
val[*idx];
269 return operator*(
static_cast<const VectorBase<R>&
>(vec));
276template <
class S,
class T >
280 for(
int i = vec.
size() - 1; i >= 0; --i)
282 assert(vec.
index(i) < dim());
293template <
class S,
class T >
297 for(
int i = vec.
size() - 1; i >= 0; --i)
299 assert(vec.
index(i) < dim());
310template <
class S,
class T >
314 assert(vec.
dim() <= dim());
320 for(
int i = vec.
size() - 1; i >= 0; --i)
321 val[idx[i]] += x * vec[idx[i]];
325 assert(vec.
dim() == dim());
327 for(
int i = dim() - 1; i >= 0; --i)
328 val[i] += x * vec.
val[i];
385template <
class S,
class T >
396 for(
int i = vec.
size() - 1; i >= 0; --i)
401 if(isNotZero(x, this->getEpsilon()))
421 int* endptr = idx + num;
423 for(; iptr < endptr; ++iptr)
427 if(isNotZero(x, this->getEpsilon()))
431 num = int(iiptr - idx);
437 assert(isConsistent());
445template <
class S,
class T >
450 assert(dim() == x.
dim());
451 assert(x.
dim() == y.
dim());
460 int n = x.
size() - 1;
461 int m = y.
size() - 1;
469 while(i < n && j < m)
485 while(i < n && xi != yj)
488 while(j < m && xi != yj)
497 assert(isConsistent());
506template <
class S,
class T >
510 assert(A.
num() == dim());
516 for(
int i = dim() - 1; i >= 0; --i)
520 if(isNotZero(y, this->getEpsilon()))
527 assert(isConsistent());
535#define SOPLEX_SHORTPRODUCT_FACTOR 0.5
537template <
class S,
class T >
542 int& nCallsSparse,
int& nCallsFull
545 assert(A.
num() == x.
dim());
551 if(timeSparse !=
nullptr)
554 assign2product1(A, x);
557 if(timeSparse !=
nullptr)
565 if(timeSparse !=
nullptr)
568 assign2productShort(A, x);
571 if(timeSparse !=
nullptr)
578 if(timeFull !=
nullptr)
581 assign2productFull(A, x);
584 if(timeFull !=
nullptr)
590 assert(isConsistent());
599template <
class S,
class T >
604 assert(x.
size() == 1);
607 const int nzidx = x.
idx[0];
608 const T nzval = x.
val[nzidx];
612 if(isZero(nzval, this->getEpsilon()) || Ai.
size() == 0)
618 for(
int j = num - 1; j >= 0; --j)
626 assert(isConsistent());
635template <
class S,
class T >
648 int curidx = x.
idx[0];
649 const T x0 = x.
val[curidx];
651 int xsize = x.
size();
655 if(isNotZero(x0, this->getEpsilon()))
659 for(
int j = 0; j < Aisize; ++j)
662 const R product = x0 * elt.
val;
668 idx[num++] = elt.
idx;
675 for(
int i = 1; i < xsize; ++i)
678 const T xi = x.
val[curidx];
684 for(
int j = 0; j < Aisize; ++j)
688 const R newval = oldval + xi * elt.
val;
694 idx[num++] = elt.
idx;
706 for(
int i = 0; i < num; ++i)
713 idx[nz_counter++] = curidx;
718 assert(isConsistent());
727template <
class S,
class T >
740 bool A_is_zero =
true;
741 int xsize = x.
size();
744 for(
int i = 0; i < xsize; ++i)
746 const int curidx = x.
idx[i];
747 const T xi = x.
val[curidx];
751 if(A_is_zero && Aisize > 0)
754 for(
int j = 0; j < Aisize; ++j)
771template <
class S,
class T >
789 for(
int i = 0; i < end; ++i)
798 if(isNotZero(xval, this->getEpsilon()))
801 x.
idx[ nzcount++ ] = i;
803 for(
int j = Ai.
size() - 1; j >= 0; --j)
820 assert(isConsistent());
838 for(
int i = 0; i < s; ++i)
840 int k = rhs.
index(i);
843 if(isZero(v, this->getEpsilon()))
854 assert(isConsistent());
872 for(
int i = 0; i < s; ++i)
874 int k = rhs.
index(i);
888 assert(isConsistent());
925 for(
int i = vec.
dim() - 1; i >= 0; --i)
956 for(
int i = vec.
dim() - 1; i >= 0; --i)
983 assert(max() >= sv.
size());
990 for(
int i = 0; i < nnz; ++i)
994 if(sv.
value(idx) != 0)
1018 for(
int i = size() - 1; i >= 0; --i)
1077 assert(isConsistent());
1090 assert(
this != &vec);
1093 makeMem(vec.
size());
1116 for(i = 0; i < vec.
dim() - 1; ++i)
1117 s << vec[i] <<
", ";
1133 for(
int i = 0; i < res.
dim(); ++i)
1151 for(
int i = 0; i < v.
size(); ++i)
1177 while(s.get(c).good())
1179 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1191 if(i >= vec.
dim() - 1)
1196 while(s.get(c).good())
1198 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1225 for(
int i = 0, j = 0; i < v.
size(); ++i)
1230 os <<
" - " << -v.
value(i);
1232 os <<
" + " << v.
value(i);
1237 os <<
" x" << v.
index(i);
1240 if((i + 1) % 4 == 0)
1254 for(
int i = 0; i < s.
num(); ++i)
1263#ifdef SOPLEX_DEBUG_BASEVECTORS
1265#undef SOPLEX_DEBUG_BASEVECTORS
#define SOPLEX_SHORTPRODUCT_FACTOR
Assigns SSVectorBase to for a setup x.
bool isConsistent() const
Consistency check.
void allocMem(int n)
Allocate memory for n nonzeros.
void add(const SVectorBase< S > &vec)
Append nonzeros of sv.
DSVectorBase(int n=8)
Default constructor.
DSVectorBase< R > & operator=(const SVectorBase< S > &vec)
Assignment operator.
void addIdx(int i)
appends index i.
int num
number of used indices
int * idx
array of indices
Sparse vector nonzero element.
int idx
Index of nonzero element.
R val
Value of nonzero element.
SSVectorBase< R > & assign2productShort(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
SSVectorBase< R > & assign2product1(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
bool setupStatus
Is the SSVectorBase set up?
SSVectorBase< R > & multAdd(S xx, const SVectorBase< T > &vec)
Addition of a scaled vector.
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
SSVectorBase< R > & assign2product4setup(const SVSetBase< S > &A, const SSVectorBase< T > &x, Timer *timeSparse, Timer *timeFull, int &nCallsSparse, int &nCallsFull)
Assigns SSVectorBase to for a setup x.
SSVectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
SSVectorBase< R > & assign2product(const SSVectorBase< S > &x, const SVSetBase< T > &A)
Assigns to SSVectorBase.
R value(int n) const
Returns value of the n 'th nonzero element.
SSVectorBase< R > & assignPWproduct4setup(const SSVectorBase< S > &x, const SSVectorBase< T > &y)
Assigns pair wise vector product to SSVectorBase.
int index(int n) const
Returns index of the n 'th nonzero element.
int dim() const
Dimension of VectorBase.
SSVectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
const int * indexMem() const
Returns array indices.
SSVectorBase< R > & assign2productFull(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
bool isSetup() const
Returns setup status.
SSVectorBase< R > & assign2productAndSetup(const SVSetBase< S > &A, SSVectorBase< T > &x)
Assigns SSVectorBase to thereby setting up x.
int size() const
Returns the number of nonzeros.
int memSize() const
Used nonzero memory.
int num() const
Current number of SVectorBases.
Nonzero< R > & element(int n)
Reference to the n 'th nonzero element.
int & index(int n)
Reference to index of n 'th nonzero.
R & value(int n)
Reference to value of n 'th nonzero.
int dim() const
Dimension of the vector defined as maximal index + 1.
SVectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
void clear()
Remove all indices.
int size() const
Number of used indices.
Wrapper for the system time query methods.
virtual void start()=0
start timer, resume accounting user, system and real time.
virtual Real stop()=0
stop timer, return accounted user time.
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
VectorBase< R > & assign(const SVectorBase< S > &vec)
Assign values of vec.
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
void reDim(int newdim, const bool setZero=true)
Resets VectorBase's dimension to newdim.
int dim() const
Dimension of vector.
std::vector< R > val
Values of vector.
VectorBase< R > & multSub(const S &x, const SVectorBase< T > &vec)
Subtraction of scaled vector.
R operator*(const VectorBase< R > &vec) const
Inner product.
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Everything should be within this namespace.
DSVectorBase< R > operator*(R x, const SVectorBase< R > &v)
Scaling.
VectorBase< R > operator-(const SVectorBase< R > &v, const VectorBase< R > &w)
Subtraction.
std::ostream & operator<<(std::ostream &s, const VectorBase< R > &vec)
Output operator.
DSVectorBase< R > operator*(const SVectorBase< R > &v, R x)
Scaling.
std::istream & operator>>(std::istream &s, VectorBase< R > &vec)
bool isPlusZero(R x)
detects whether value is positive zero
Debugging, floating point type and parameter definitions.