28 #ifndef _BASEVECTORS_H_ 29 #define _BASEVECTORS_H_ 33 #define SOPLEX_DEBUG_BASEVECTORS 47 #define SOPLEX_VECTOR_MARKER 1e-100 70 for(
int i = 0; i < vec.
size(); ++i)
72 assert(vec.
index(i) < dim());
88 for(
int i = vec.
size() - 1; i >= 0; --i)
90 assert(vec.
index(i) < dim());
128 assert(vec.
dim() <= dim());
134 for(
int i = vec.
size() - 1; i >= 0; --i)
136 val[*idx] = vec.
val[*idx];
154 for(
int i = vec.
size() - 1; i >= 0; --i)
156 assert(vec.
index(i) >= 0);
157 assert(vec.
index(i) < dim());
172 assert(dim() == vec.
dim());
176 for(
int i = vec.
size() - 1; i >= 0 ; --i)
181 for(
int i = dim() - 1; i >= 0; --i)
196 for(
int i = vec.
size() - 1; i >= 0; --i)
198 assert(vec.
index(i) >= 0);
199 assert(vec.
index(i) < dim());
214 assert(dim() == vec.
dim());
218 for(
int i = vec.
size() - 1; i >= 0; --i)
223 for(
int i = dim() - 1; i >= 0; --i)
237 assert(dim() >= vec.
dim());
241 for(
int i = vec.
size() - 1; i >= 0; --i)
254 assert(dim() == vec.
dim());
262 for(
int i = vec.
size() - 1; i >= 0; --i)
264 x += val[*idx] * vec.
val[*idx];
278 template <
class S,
class T >
282 for(
int i = vec.
size() - 1; i >= 0; --i)
284 assert(vec.
index(i) < dim());
295 template <
class S,
class T >
299 for(
int i = vec.
size() - 1; i >= 0; --i)
301 assert(vec.
index(i) < dim());
312 template <
class S,
class T >
316 assert(vec.
dim() <= dim());
322 for(
int i = vec.
size() - 1; i >= 0; --i)
323 val[idx[i]] += x * vec[idx[i]];
327 assert(vec.
dim() == dim());
329 for(
int i = dim() - 1; i >= 0; --i)
330 val[i] += x * vec.
val[i];
387 template <
class S,
class T >
398 for(
int i = vec.
size() - 1; i >= 0; --i)
404 x = v[j] + xx * vec.
value(i);
406 if(isNotZero(x, this->tolerances()->epsilon()))
416 x = xx * vec.
value(i);
418 if(isNotZero(x, this->tolerances()->epsilon()))
430 int* endptr = idx + num;
432 for(; iptr < endptr; ++iptr)
436 if(isNotZero(x, this->tolerances()->epsilon()))
442 num = int(iiptr - idx);
448 assert(isConsistent());
456 template <
class S,
class T >
461 assert(dim() == x.
dim());
462 assert(x.
dim() == y.
dim());
471 int n = x.
size() - 1;
472 int m = y.
size() - 1;
480 while(i < n && j < m)
496 while(i < n && xi != yj)
499 while(j < m && xi != yj)
508 assert(isConsistent());
517 template <
class S,
class T >
521 assert(A.
num() == dim());
527 for(
int i = dim() - 1; i >= 0; --i)
531 if(isNotZero(y, this->tolerances()->epsilon()))
538 assert(isConsistent());
546 #define SOPLEX_SHORTPRODUCT_FACTOR 0.5 548 template <
class S,
class T >
553 int& nCallsSparse,
int& nCallsFull
556 assert(A.
num() == x.
dim());
565 assign2product1(A, x);
579 assign2productShort(A, x);
592 assign2productFull(A, x);
601 assert(isConsistent());
610 template <
class S,
class T >
615 assert(x.
size() == 1);
618 const int nzidx = x.
idx[0];
619 const T nzval = x.
val[nzidx];
623 if(isZero(nzval, this->tolerances()->epsilon()) || Ai.
size() == 0)
629 for(
int j = num - 1; j >= 0; --j)
637 assert(isConsistent());
646 template <
class S,
class T >
660 int curidx = x.
idx[0];
661 const T x0 = x.
val[curidx];
664 int xsize = x.
size();
669 if(isZero(x0, this->tolerances()->epsilon()) || num == 0)
676 for(
int j = 0; j < num; ++j)
679 const R product = x0 * elt.
val;
682 idx[nonzero_idx] = elt.
idx;
692 for(
int i = 1; i < xsize; ++i)
695 const T xi = x.
val[curidx];
701 if(isNotZero(xi, this->tolerances()->epsilon()) || Aisize == 0)
704 for(
int j = 0; j < Aisize; ++j)
707 idx[nonzero_idx] = elt.
idx;
719 oldval += xi * elt.
val;
736 for(
int i = 0; i < nonzero_idx; ++i)
744 idx[nz_counter] = curidx;
751 assert(isConsistent());
760 template <
class S,
class T >
773 bool A_is_zero =
true;
774 int xsize = x.
size();
777 for(
int i = 0; i < xsize; ++i)
779 const int curidx = x.
idx[i];
780 const T xi = x.
val[curidx];
784 if(A_is_zero && Aisize > 0)
787 for(
int j = 0; j < Aisize; ++j)
804 template <
class S,
class T >
822 for(
int i = 0; i < end; ++i)
831 if(isNotZero(xval, this->tolerances()->epsilon()))
834 x.
idx[ nzcount++ ] = i;
836 for(
int j = Ai.
size() - 1; j >= 0; --j)
853 assert(isConsistent());
871 for(
int i = 0; i < s; ++i)
873 int k = rhs.
index(i);
876 if(isZero(v, this->tolerances()->epsilon()))
887 assert(isConsistent());
905 for(
int i = 0; i < s; ++i)
907 int k = rhs.
index(i);
921 assert(isConsistent());
958 for(
int i = vec.
dim() - 1; i >= 0; --i)
989 for(
int i = vec.
dim() - 1; i >= 0; --i)
1010 template <
class R >
1011 template <
class S >
1016 assert(max() >= sv.
size());
1023 for(
int i = 0; i < nnz; ++i)
1027 if(sv.
value(idx) != 0.0)
1044 template <
class R >
1051 for(
int i = size() - 1; i >= 0; --i)
1069 template <
class R >
1070 template <
class S >
1075 allocMem((vec.
dim() < 1) ? 2 : vec.
dim());
1078 assert(isConsistent());
1084 template <
class R >
1085 template <
class S >
1090 allocMem(old.
size() < 1 ? 2 : old.
size());
1093 assert(isConsistent());
1099 template <
class R >
1100 template <
class S >
1110 assert(isConsistent());
1118 template <
class R >
1119 template <
class S >
1123 assert(
this != &vec);
1126 makeMem(vec.
size());
1141 template <
class R >
1143 std::ostream& operator<<(std::ostream& s, const VectorBase<R>& vec)
1149 for(i = 0; i < vec.dim() - 1; ++i)
1150 s << vec[i] <<
", ";
1160 template <
class R >
1166 for(
int i = 0; i < res.dim(); ++i)
1178 template <
class R >
1184 for(
int i = 0; i < v.
size(); ++i)
1193 template <
class R >
1202 template <
class R >
1210 while(s.get(c).good())
1212 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1224 if(i >= vec.
dim() - 1)
1229 while(s.get(c).good())
1231 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1254 template <
class R >
1256 std::ostream& operator<<(std::ostream& os, const SVectorBase<R>& v)
1258 for(
int i = 0, j = 0; i < v.size(); ++i)
1263 os <<
" - " << -v.value(i);
1265 os <<
" + " << v.value(i);
1270 os <<
" x" << v.index(i);
1273 if((i + 1) % 4 == 0)
1283 template <
class R >
1285 std::ostream& operator<<(std::ostream& os, const SVSetBase<R>& s)
1287 for(
int i = 0; i < s.num(); ++i)
1296 #ifdef SOPLEX_DEBUG_BASEVECTORS 1297 #define SOPLEX_DEBUG 1298 #undef SOPLEX_DEBUG_BASEVECTORS 1301 #endif // _BASEVECTORS_H_ SSVectorBase< R > & assign2productFull(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
int * idx
array of indices
bool isSetup() const
Returns setup status.
number< gmp_rational, et_off > Rational
Sparse vector nonzero element.
std::istream & operator>>(std::istream &s, VectorBase< R > &vec)
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
Dense vector.Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std...
int size() const
Number of used indices.
SSVectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
Nonzero< R > & element(int n)
Reference to the n 'th nonzero element.
VectorBase< R > operator-(const SVectorBase< R > &v, const VectorBase< R > &w)
Subtraction.
SSVectorBase< R > & assign2product1(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
#define SOPLEX_VECTOR_MARKER
Dynamic sparse vectors.Class DSVectorBase implements dynamic sparse vectors, i.e. SVectorBases with a...
int memSize() const
Used nonzero memory.
R & value(int n)
Reference to value of n 'th nonzero.
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.
bool setupStatus
Is the SSVectorBase set up?
int idx
Index of nonzero element.
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
void addIdx(int i)
appends index i.
Semi sparse vector.This class implements semi-sparse vectors. Such are VectorBases where the indices ...
void add(const SVectorBase< S > &vec)
Append nonzeros of sv.
virtual void start()=0
start timer, resume accounting user, system and real time.
int dim() const
Dimension of VectorBase.
virtual Real stop()=0
stop timer, return accounted user time.
SSVectorBase< R > & assign2productAndSetup(const SVSetBase< S > &A, SSVectorBase< T > &x)
Assigns SSVectorBase to thereby setting up x.
DSVectorBase< R > operator*(const SVectorBase< R > &v, R x)
Scaling.
SSVectorBase< R > & assign2product(const SSVectorBase< S > &x, const SVSetBase< T > &A)
Assigns to SSVectorBase.
int & index(int n)
Reference to index of n 'th nonzero.
SSVectorBase< R > & multAdd(S xx, const SVectorBase< T > &vec)
Addition of a scaled vector.
int index(int n) const
Returns index of the n 'th nonzero element.
const int * indexMem() const
Returns array indices.
Debugging, floating point type and parameter definitions.
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
int dim() const
Dimension of vector.
int size() const
Returns the number of nonzeros.
Everything should be within this namespace.
int dim() const
Dimension of the vector defined as maximal index + 1.
SSVectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
void reDim(int newdim, const bool setZero=true)
Resets VectorBase's dimension to newdim.
#define SOPLEX_SHORTPRODUCT_FACTOR
Assigns SSVectorBase to for a setup x.
R operator*(const VectorBase< R > &vec) const
Inner product.
std::vector< R > val
Values of vector.
R val
Value of nonzero element.
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
SSVectorBase< R > & assignPWproduct4setup(const SSVectorBase< S > &x, const SSVectorBase< T > &y)
Assigns pair wise vector product to SSVectorBase.
VectorBase< R > & assign(const SVectorBase< S > &vec)
Assign values of vec.
int num
number of used indices
SSVectorBase< R > & assign2productShort(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
Wrapper for the system time query methods.
int num() const
Current number of SVectorBases.
DSVectorBase< R > operator*(R x, const SVectorBase< R > &v)
Scaling.
Sparse vector set.Class SVSetBase provides a set of sparse vectors SVectorBase. All SVectorBases in a...
VectorBase< R > & multSub(const S &x, const SVectorBase< T > &vec)
Subtraction of scaled vector.
R value(int n) const
Returns value of the n 'th nonzero element.