20 #ifndef _BASEVECTORS_H_ 21 #define _BASEVECTORS_H_ 25 #define SOPLEX_DEBUG_BASEVECTORS 39 #define SOPLEX_VECTOR_MARKER 1e-100 62 for(
int i = 0; i < vec.
size(); ++i)
64 assert(vec.
index(i) < dim());
80 for(
int i = vec.
size() - 1; i >= 0; --i)
82 assert(vec.
index(i) < dim());
120 assert(vec.
dim() <= dim());
126 for(
int i = vec.
size() - 1; i >= 0; --i)
128 val[*idx] = vec.
val[*idx];
146 for(
int i = vec.
size() - 1; i >= 0; --i)
148 assert(vec.
index(i) >= 0);
149 assert(vec.
index(i) < dim());
164 assert(dim() == vec.
dim());
168 for(
int i = vec.
size() - 1; i >= 0 ; --i)
173 for(
int i = dim() - 1; i >= 0; --i)
188 for(
int i = vec.
size() - 1; i >= 0; --i)
190 assert(vec.
index(i) >= 0);
191 assert(vec.
index(i) < dim());
206 assert(dim() == vec.
dim());
210 for(
int i = vec.
size() - 1; i >= 0; --i)
215 for(
int i = dim() - 1; i >= 0; --i)
229 assert(dim() >= vec.
dim());
233 for(
int i = vec.
size() - 1; i >= 0; --i)
246 assert(dim() == vec.
dim());
254 for(
int i = vec.
size() - 1; i >= 0; --i)
256 x += val[*idx] * vec.
val[*idx];
270 template <
class S,
class T >
274 for(
int i = vec.
size() - 1; i >= 0; --i)
276 assert(vec.
index(i) < dim());
287 template <
class S,
class T >
291 for(
int i = vec.
size() - 1; i >= 0; --i)
293 assert(vec.
index(i) < dim());
304 template <
class S,
class T >
308 assert(vec.
dim() <= dim());
314 for(
int i = vec.
size() - 1; i >= 0; --i)
315 val[idx[i]] += x * vec[idx[i]];
319 assert(vec.
dim() == dim());
321 for(
int i = dim() - 1; i >= 0; --i)
322 val[i] += x * vec.
val[i];
379 template <
class S,
class T >
390 for(
int i = vec.
size() - 1; i >= 0; --i)
396 x = v[j] + xx * vec.
value(i);
398 if(isNotZero(x, epsilon))
408 x = xx * vec.
value(i);
410 if(isNotZero(x, epsilon))
422 int* endptr = idx + num;
424 for(; iptr < endptr; ++iptr)
428 if(isNotZero(x, epsilon))
434 num = int(iiptr - idx);
440 assert(isConsistent());
448 template <
class S,
class T >
453 assert(dim() == x.
dim());
454 assert(x.
dim() == y.
dim());
463 int n = x.
size() - 1;
464 int m = y.
size() - 1;
472 while(i < n && j < m)
488 while(i < n && xi != yj)
491 while(j < m && xi != yj)
500 assert(isConsistent());
509 template <
class S,
class T >
513 assert(A.
num() == dim());
519 for(
int i = dim() - 1; i >= 0; --i)
523 if(isNotZero(y, epsilon))
530 assert(isConsistent());
538 #define shortProductFactor 0.5 540 template <
class S,
class T >
545 int& nCallsSparse,
int& nCallsFull
548 assert(A.
num() == x.
dim());
557 assign2product1(A, x);
570 assign2productShort(A, x);
583 assign2productFull(A, x);
592 assert(isConsistent());
601 template <
class S,
class T >
606 assert(x.
size() == 1);
609 const int nzidx = x.
idx[0];
610 const T nzval = x.
val[nzidx];
614 if(isZero(nzval, epsilon) || Ai.
size() == 0)
620 for(
int j = num - 1; j >= 0; --j)
628 assert(isConsistent());
637 template <
class S,
class T >
651 int curidx = x.
idx[0];
652 const T x0 = x.
val[curidx];
655 int xsize = x.
size();
660 if(isZero(x0, epsilon) || num == 0)
667 for(
int j = 0; j < num; ++j)
670 const R product = x0 * elt.
val;
673 idx[nonzero_idx] = elt.
idx;
683 for(
int i = 1; i < xsize; ++i)
686 const T xi = x.
val[curidx];
692 if(isNotZero(xi, epsilon) || Aisize == 0)
695 for(
int j = 0; j < Aisize; ++j)
698 idx[nonzero_idx] = elt.
idx;
710 oldval += xi * elt.
val;
727 for(
int i = 0; i < nonzero_idx; ++i)
735 idx[nz_counter] = curidx;
742 assert(isConsistent());
751 template <
class S,
class T >
764 bool A_is_zero =
true;
765 int xsize = x.
size();
768 for(
int i = 0; i < xsize; ++i)
770 const int curidx = x.
idx[i];
771 const T xi = x.
val[curidx];
775 if(A_is_zero && Aisize > 0)
778 for(
int j = 0; j < Aisize; ++j)
795 template <
class S,
class T >
813 for(
int i = 0; i < end; ++i)
822 if(isNotZero(xval, epsilon))
825 x.
idx[ nzcount++ ] = i;
827 for(
int j = Ai.
size() - 1; j >= 0; --j)
844 assert(isConsistent());
862 for(
int i = 0; i < s; ++i)
864 int k = rhs.
index(i);
867 if(isZero(v, epsilon))
878 assert(isConsistent());
896 for(
int i = 0; i < s; ++i)
898 int k = rhs.
index(i);
912 assert(isConsistent());
949 for(
int i = vec.
dim() - 1; i >= 0; --i)
980 for(
int i = vec.
dim() - 1; i >= 0; --i)
1001 template <
class R >
1002 template <
class S >
1007 assert(max() >= sv.
size());
1014 for(
int i = 0; i < nnz; ++i)
1018 if(sv.
value(idx) != 0.0)
1035 template <
class R >
1042 for(
int i = size() - 1; i >= 0; --i)
1060 template <
class R >
1061 template <
class S >
1066 allocMem((vec.
dim() < 1) ? 2 : vec.
dim());
1069 assert(isConsistent());
1075 template <
class R >
1076 template <
class S >
1081 allocMem(old.
size() < 1 ? 2 : old.
size());
1084 assert(isConsistent());
1090 template <
class R >
1091 template <
class S >
1101 assert(isConsistent());
1109 template <
class R >
1110 template <
class S >
1114 assert(
this != &vec);
1117 makeMem(vec.
size());
1132 template <
class R >
1134 std::ostream& operator<<(std::ostream& s, const VectorBase<R>& vec)
1140 for(i = 0; i < vec.dim() - 1; ++i)
1141 s << vec[i] <<
", ";
1151 template <
class R >
1157 for(
int i = 0; i < res.dim(); ++i)
1169 template <
class R >
1175 for(
int i = 0; i < v.
size(); ++i)
1184 template <
class R >
1193 template <
class R >
1201 while(s.get(c).good())
1203 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1215 if(i >= vec.
dim() - 1)
1220 while(s.get(c).good())
1222 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1245 template <
class R >
1247 std::ostream& operator<<(std::ostream& os, const SVectorBase<R>& v)
1249 for(
int i = 0, j = 0; i < v.size(); ++i)
1254 os <<
" - " << -v.value(i);
1256 os <<
" + " << v.value(i);
1261 os <<
" x" << v.index(i);
1264 if((i + 1) % 4 == 0)
1274 template <
class R >
1276 std::ostream& operator<<(std::ostream& os, const SVSetBase<R>& s)
1278 for(
int i = 0; i < s.num(); ++i)
1287 #ifdef SOPLEX_DEBUG_BASEVECTORS 1288 #define SOPLEX_DEBUG 1289 #undef SOPLEX_DEBUG_BASEVECTORS 1292 #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.
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
#define shortProductFactor
Assigns SSVectorBase to for a setup x.
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.