28#ifndef _BASEVECTORS_H_
29#define _BASEVECTORS_H_
33#define SOPLEX_DEBUG_BASEVECTORS
66 const int n =
vec.size();
70 for(
int i = 0; i < n; ++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());
132 const int* idx =
vec.indexMem();
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());
258 const int* idx =
vec.indexMem();
262 for(
int i =
vec.size() - 1; i >= 0; --i)
264 x +=
val[*idx] *
vec.val[*idx];
278template <
class S,
class T >
282 for(
int i =
vec.size() - 1; i >= 0; --i)
284 assert(
vec.index(i) <
dim());
295template <
class S,
class T >
299 for(
int i =
vec.size() - 1; i >= 0; --i)
301 assert(
vec.index(i) <
dim());
312template <
class S,
class T >
316 assert(
vec.dim() <=
dim());
320 const int* idx =
vec.indexMem();
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)
387template <
class S,
class T >
398 for(
int i =
vec.size() - 1; i >= 0; --i)
401 x = v[j] + xx *
vec.value(i);
403 if(isNotZero(x, this->getEpsilon()))
425 for(; iptr < endptr; ++iptr)
429 if(isNotZero(x, this->getEpsilon()))
447template <
class S,
class T >
455 assert(x.
dim() == y.
dim());
458 const int n = x.
size() - 1;
459 const 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());
509template <
class S,
class T >
520 for(
int i =
dim() - 1; i >= 0; --i)
524 if(isNotZero(y, this->getEpsilon()))
539#define SOPLEX_SHORTPRODUCT_FACTOR 0.5
541template <
class S,
class T >
546 int& nCallsSparse,
int& nCallsFull
549 assert(A.
num() == x.
dim());
555 if(timeSparse !=
nullptr)
561 if(timeSparse !=
nullptr)
569 if(timeSparse !=
nullptr)
575 if(timeSparse !=
nullptr)
582 if(timeFull !=
nullptr)
588 if(timeFull !=
nullptr)
603template <
class S,
class T >
608 assert(x.
size() == 1);
611 const int nzidx = x.
idx[0];
612 const T nzval = x.
val[nzidx];
616 if(isZero(nzval, this->getEpsilon()) || Ai.
size() == 0)
622 for(
int j =
num - 1; j >= 0; --j)
639template <
class S,
class T >
653 int curidx = x.
idx[0];
654 const T x0 = x.
val[curidx];
656 const int xsize = x.
size();
660 if(isNotZero(x0, this->getEpsilon()))
664 for(
int j = 0; j < Aisize; ++j)
667 const R product = x0 * elt.
val;
680 for(
int i = 1; i < xsize; ++i)
683 const T xi = x.
val[curidx];
689 for(
int j = 0; j < Aisize; ++j)
693 const R newval = oldval + xi * elt.
val;
711 for(
int i = 0; i <
num; ++i)
718 idx[nz_counter++] = curidx;
732template <
class S,
class T >
746 const int xsize = x.
size();
747 bool A_is_zero =
true;
750 for(
int i = 0; i < xsize; ++i)
752 const int curidx = x.
idx[i];
753 const T xi = x.
val[curidx];
757 if(A_is_zero && Aisize > 0)
760 for(
int j = 0; j < Aisize; ++j)
777template <
class S,
class T >
782 assert(!x.isSetup());
796 for(
int i = 0; i <
end; ++i)
803 if(isNotZero(x.
val[i], this->getEpsilon()))
805 const T xval = x.
val[i];
807 x.
idx[ nzcount++ ] = i;
809 for(
int j = Ai.
size() - 1; j >= 0; --j)
840 const int s = rhs.
size();
843 for(
int i = 0; i < s; ++i)
845 int k = rhs.
index(i);
848 if(isZero(v, this->getEpsilon()))
873 const int s = rhs.
size();
876 for(
int i = 0; i < s; ++i)
878 int k = rhs.
index(i);
924 const int d = vec.
dim();
930 for(
int i = 0; i < d; ++i)
956 const int d = vec.
dim();
962 for(
int i = 0; i < d; ++i)
988 assert(sv.isSetup());
989 const int n = sv.
size();
996 for(
int i = 0; i < n; ++i)
1024 for(
int i =
size() - 1; i >= 0; --i)
1096 assert(
this != &vec);
1118 const int d = vec.
dim() - 1;
1123 for(i = 0; i < d; ++i)
1124 s << vec[i] <<
", ";
1138 const int d = w.
dim();
1141 for(
int i = 0; i < d; ++i)
1157 const int n = v.
size();
1160 for(
int i = 0; i < n; ++i)
1186 while(s.get(c).good())
1188 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1200 if(i >= vec.
dim() - 1)
1205 while(s.get(c).good())
1207 if(c !=
' ' && c !=
'\t' && c !=
'\n')
1234 const int n = v.
size();
1236 for(
int i = 0, j = 0; i < n; ++i)
1241 os <<
" - " << -v.
value(i);
1243 os <<
" + " << v.
value(i);
1248 os <<
" x" << v.
index(i);
1251 if((i + 1) % 4 == 0)
1265 for(
int i = 0; i < s.
num(); ++i)
1274#ifdef SOPLEX_DEBUG_BASEVECTORS
1276#undef SOPLEX_DEBUG_BASEVECTORS
#define SOPLEX_SHORTPRODUCT_FACTOR
Assigns SSVectorBase to for a setup x.
void makeMem(int n)
Ensure there is room for n new nonzeros.
bool isConsistent() const
Consistency check.
void allocMem(int n)
Allocate memory for n nonzeros.
DSVectorBase(int n=8)
Default constructor.
void add(const SVectorBase< R > &vec)
Append nonzeros of vec.
void setMax(int newmax=1)
Reset nonzero memory to >= newmax.
DSVectorBase< R > & operator=(const SVectorBase< S > &vec)
Assignment operator.
Nonzero< R > * theelem
Memory.
void addIdx(int i)
appends index i.
int max() const
returns the maximal number of indices which can be stored in IdxSet.
int num
number of used indices
int * idx
array of indices
int len
length of array idx
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.
bool isConsistent() const
consistency check.
SSVectorBase(int p_dim, std::shared_ptr< Tolerances > tol=nullptr)
Default constructor.
SSVectorBase< R > & assign2product(const SSVectorBase< S > &x, const SVSetBase< T > &A)
Assigns to SSVectorBase.
SSVectorBase< R > & assignPWproduct4setup(const SSVectorBase< S > &x, const SSVectorBase< T > &y)
Assigns pair wise vector product to SSVectorBase.
SSVectorBase< R > & operator=(const SSVectorBase< S > &rhs)
Assignment operator.
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.
void clear()
Clears vector.
SSVectorBase< R > & assign2productFull(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
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.
R operator*(const VectorBase< R > &w) const
Inner product.
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.
std::vector< R >::const_iterator end() const
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.
const std::vector< R > & vec()
Return underlying std::vector.
void clear()
Set vector to contain all-zeros (keeping the same length).
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.
std::istream & operator>>(std::istream &s, VectorBase< R > &vec)
std::ostream & operator<<(std::ostream &s, const VectorBase< R > &vec)
Output operator.
VectorBase< R > operator-(const SVectorBase< R > &v, const VectorBase< R > &w)
Subtraction.
DSVectorBase< R > operator*(const SVectorBase< R > &v, R x)
Scaling.
bool isPlusZero(R x)
detects whether value is positive zero
SPxDefaultRT & operator=(const SPxDefaultRT &rhs)
assignment operator
Debugging, floating point type and parameter definitions.