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());
68 assert(isConsistent());
82 for(
int i = vec.
size() - 1; i >= 0; --i)
84 assert(vec.
index(i) < dim());
88 assert(isConsistent());
124 assert(vec.
dim() <= dim());
130 for(
int i = vec.
size() - 1; i >= 0; --i)
132 val[*idx] = vec.
val[*idx];
150 for(
int i = vec.
size() - 1; i >= 0; --i)
152 assert(vec.
index(i) >= 0);
153 assert(vec.
index(i) < dim());
168 assert(dim() == vec.
dim());
172 for(
int i = vec.
size() - 1; i >= 0 ; --i)
177 for(
int i = dim() - 1; i >= 0; --i)
192 for(
int i = vec.
size() - 1; i >= 0; --i)
194 assert(vec.
index(i) >= 0);
195 assert(vec.
index(i) < dim());
210 assert(dim() == vec.
dim());
214 for(
int i = vec.
size() - 1; i >= 0; --i)
219 for(
int i = dim() - 1; i >= 0; --i)
233 assert(dim() >= vec.
dim());
237 for(
int i = vec.
size() - 1; i >= 0; --i)
250 assert(dim() == vec.
dim());
258 for(
int i = vec.
size() - 1; i >= 0; --i)
260 x += val[*idx] * vec.
val[*idx];
274 template <
class S,
class T >
278 for(
int i = vec.
size() - 1; i >= 0; --i)
280 assert(vec.
index(i) < dim());
291 template <
class S,
class T >
295 for(
int i = vec.
size() - 1; i >= 0; --i)
297 assert(vec.
index(i) < dim());
308 template <
class S,
class T >
312 assert(vec.
dim() <= dim());
318 for(
int i = vec.
size() - 1; i >= 0; --i)
319 val[idx[i]] += x * vec[idx[i]];
323 assert(vec.
dim() == dim());
325 for(
int i = dim() - 1; i >= 0; --i)
326 val[i] += x * vec.
val[i];
353 assert(isConsistent());
407 template <
class S,
class T >
418 for(
int i = vec.
size() - 1; i >= 0; --i)
424 x = v[j] + xx * vec.
value(i);
436 x = xx * vec.
value(i);
450 int* endptr = idx + num;
452 for(; iptr < endptr; ++iptr)
462 num = int(iiptr - idx);
468 assert(isConsistent());
476 template <
class S,
class T >
481 assert(dim() == x.
dim());
482 assert(x.
dim() == y.
dim());
491 int n = x.
size() - 1;
492 int m = y.
size() - 1;
500 while(i < n && j < m)
516 while(i < n && xi != yj)
519 while(j < m && xi != yj)
528 assert(isConsistent());
537 template <
class S,
class T >
541 assert(A.
num() == dim());
547 for(
int i = dim() - 1; i >= 0; --i)
558 assert(isConsistent());
566 #define shortProductFactor 0.5 568 template <
class S,
class T >
573 assert(A.
num() == x.
dim());
579 assign2product1(A, x);
584 assign2productShort(A, x);
589 assign2productFull(A, x);
593 assert(isConsistent());
602 template <
class S,
class T >
607 assert(x.
size() == 1);
610 const int nzidx = x.
idx[0];
611 const T nzval = x.
val[nzidx];
621 for(
int j = num - 1; j >= 0; --j)
629 assert(isConsistent());
638 template <
class S,
class T >
652 int curidx = x.
idx[0];
653 const T x0 = x.
val[curidx];
656 int xsize = x.
size();
661 if(
isZero(x0, epsilon) || num == 0)
668 for(
int j = 0; j < num; ++j)
671 const R product = x0 * elt.
val;
674 idx[nonzero_idx] = elt.
idx;
684 for(
int i = 1; i < xsize; ++i)
687 const T xi = x.
val[curidx];
693 if(
isNotZero(xi, epsilon) || Aisize == 0)
696 for(
int j = 0; j < Aisize; ++j)
699 idx[nonzero_idx] = elt.
idx;
711 oldval += xi * elt.
val;
728 for(
int i = 0; i < nonzero_idx; ++i)
736 idx[nz_counter] = curidx;
743 assert(isConsistent());
752 template <
class S,
class T >
765 bool A_is_zero =
true;
766 int xsize = x.
size();
769 for(
int i = 0; i < xsize; ++i)
771 const int curidx = x.
idx[i];
772 const T xi = x.
val[curidx];
776 if(A_is_zero && Aisize > 0)
779 for(
int j = 0; j < Aisize; ++j)
796 template <
class S,
class T >
801 return assign2product4setup(A, x);
815 for(
int i = 0; i < end; ++i)
827 x.
idx[ nzcount++ ] = i;
829 for(
int j = Ai.
size() - 1; j >= 0; --j)
846 assert(isConsistent());
864 for(
int i = 0; i < s; ++i)
866 int k = rhs.
index(i);
880 assert(isConsistent());
898 for(
int i = 0; i < s; ++i)
900 int k = rhs.
index(i);
914 assert(isConsistent());
951 for(
int i = vec.
dim() - 1; i >= 0; --i)
982 for(
int i = vec.
dim() - 1; i >= 0; --i)
1003 template <
class R >
1004 template <
class S >
1009 assert(max() >= sv.
size());
1016 for(
int i = 0; i < nnz; ++i)
1020 if(sv.
value(idx) != 0.0)
1037 template <
class R >
1044 for(
int i = size() - 1; i >= 0; --i)
1062 template <
class R >
1063 template <
class S >
1068 allocMem((vec.
dim() < 1) ? 2 : vec.
dim());
1071 assert(isConsistent());
1077 template <
class R >
1078 template <
class S >
1083 allocMem(old.
size() < 1 ? 2 : old.
size());
1086 assert(isConsistent());
1092 template <
class R >
1093 template <
class S >
1103 assert(isConsistent());
1111 template <
class R >
1112 template <
class S >
1116 assert(
this != &vec);
1119 makeMem(vec.
size());
1134 template <
class R >
1136 std::ostream& operator<<(std::ostream& s, const VectorBase<R>& vec)
1142 for(i = 0; i < vec.dim() - 1; ++i)
1143 s << vec[i] <<
", ";
1153 template <
class R >
1159 for(
int i = 0; i < res.dim(); ++i)
1168 template <
class R >
1172 assert(v.
dim() == w.
dim());
1176 for(
int i = 0; i < res.dim(); ++i)
1177 res[i] = v[i] + w[i];
1185 template <
class R >
1199 template <
class R >
1209 template <
class R >
1213 assert(v.
dim() == w.
dim());
1217 for(
int i = 0; i < res.dim(); ++i)
1218 res[i] = v[i] - w[i];
1226 template <
class R >
1240 template <
class R >
1246 for(
int i = 0; i < res.dim(); ++i)
1257 template <
class R >
1263 for(
int i = 0; i < res.dim(); ++i)
1272 template <
class R >
1282 template <
class R >
1288 for(
int i = 0; i < v.
size(); ++i)
1297 template <
class R >
1307 template <
class R >
1315 while(s.get(c).good())
1317 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1329 if(i >= vec.
dim() - 1)
1334 while(s.get(c).good())
1336 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1359 template <
class R >
1361 std::ostream& operator<<(std::ostream& os, const SVectorBase<R>& v)
1363 for(
int i = 0, j = 0; i < v.size(); ++i)
1368 os <<
" - " << -v.value(i);
1370 os <<
" + " << v.value(i);
1375 os <<
" x" << v.index(i);
1378 if((i + 1) % 4 == 0)
1388 template <
class R >
1390 std::ostream& operator<<(std::ostream& os, const SVSetBase<R>& s)
1392 for(
int i = 0; i < s.num(); ++i)
1401 #ifdef SOPLEX_DEBUG_BASEVECTORS 1402 #define SOPLEX_DEBUG 1403 #undef SOPLEX_DEBUG_BASEVECTORS 1406 #endif // _BASEVECTORS_H_ DVectorBase< R > & operator=(const VectorBase< R > &vec)
Assignment operator.
bool isNotZero(Real a, Real eps=Param::epsilon())
returns true iff |a| > eps
SSVectorBase< R > & assign2productFull(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
int * idx
array of indices
bool isSetup() const
Returns setup status.
Sparse vector nonzero element.
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase's dimension to newdim.
std::istream & operator>>(std::istream &s, DVectorBase< R > &vec)
Input operator.
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
Dynamic dense vectors.Class DVectorBase is a derived class of VectorBase adding automatic memory mana...
Dense vector.Class VectorBase provides dense linear algebra vectors. It does not provide memory manag...
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.
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.
Wrapper for GMP type mpq_class.We wrap mpq_class so that we can replace it by a double type if GMP is...
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 DVectorBases where the indices...
void add(const SVectorBase< S > &vec)
Append nonzeros of sv.
int dim() const
Dimension of VectorBase.
SSVectorBase< R > & assign2productAndSetup(const SVSetBase< S > &A, SSVectorBase< T > &x)
Assigns SSVectorBase to thereby setting up x.
DVectorBase< R > operator-(const SVectorBase< R > &v, const VectorBase< R > &w)
Subtraction.
DVectorBase< R > operator+(const SVectorBase< R > &v, const VectorBase< R > &w)
Addition.
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.
DVectorBase< R > operator*(const VectorBase< R > &v, R x)
Scaling.
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.
R operator*(const VectorBase< R > &vec) const
Inner product.
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.
bool isZero(Real a, Real eps=Param::epsilon())
returns true iff |a| <= eps
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.
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.
SSVectorBase< R > & assign2product4setup(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assigns SSVectorBase to for a setup x.