Scippy

SoPlex

Sequential object-oriented simPlex

ssvectorbase.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 
17 /**@file ssvectorbase.h
18  * @brief Semi sparse vector.
19  */
20 #ifndef _SSVECTORBASE_H_
21 #define _SSVECTORBASE_H_
22 
23 #include <assert.h>
24 
25 #include "soplex/spxdefines.h"
26 #include "soplex/dvectorbase.h"
27 #include "soplex/idxset.h"
28 #include "soplex/spxalloc.h"
29 #include "soplex/stablesum.h"
30 
31 namespace soplex
32 {
33 template < class R > class SVectorBase;
34 template < class R > class SVSetBase;
35 
36 /**@brief Semi sparse vector.
37  * @ingroup Algebra
38  *
39  * This class implements semi-sparse vectors. Such are #DVectorBase%s where the indices of its nonzero elements can be
40  * stored in an extra IdxSet. Only elements with absolute value > #epsilon are considered to be nonzero. Since really
41  * storing the nonzeros is not always convenient, an SSVectorBase provides two different stati: setup and not setup.
42  * An SSVectorBase being setup means that the nonzero indices are available, otherwise an SSVectorBase is just an
43  * ordinary DVectorBase with an empty IdxSet. Note that due to arithmetic operation, zeros can slip in, i.e., it is
44  * only guaranteed that at least every non-zero is in the IdxSet.
45  */
46 template < class R >
47 class SSVectorBase : public DVectorBase<R>, protected IdxSet
48 {
49 private:
50 
51  friend class DVectorBase<R>;
52  friend class VectorBase<R>;
53  template < class S > friend class DSVectorBase;
54 
55  // ------------------------------------------------------------------------------------------------------------------
56  /**@name Data */
57  //@{
58 
59  /// Is the SSVectorBase set up?
61 
62  /// A value x with |x| < epsilon is considered zero.
64 
65  /// Allocates enough space to accommodate \p newmax values.
66  void setMax(int newmax)
67  {
68  assert(idx != 0);
69  assert(newmax != 0);
70  assert(newmax >= IdxSet::size());
71 
72  len = newmax;
74  }
75 
76  //@}
77 
78 public:
79 
80  // ------------------------------------------------------------------------------------------------------------------
81  /**@name Status of an SSVectorBase
82  *
83  * An SSVectorBase can be set up or not. In case it is set up, its IdxSet correctly contains all indices of nonzero
84  * elements of the SSVectorBase. Otherwise, it does not contain any useful data. Whether or not an SSVectorBase is
85  * setup can be determined with the method \ref soplex::SSVectorBase::isSetup() "isSetup()".
86  *
87  * There are three methods for directly affecting the setup status of an SSVectorBase:
88  *
89  * - unSetup(): This method sets the status to ``not setup''.
90  *
91  * - setup(): This method initializes the IdxSet to the SSVectorBase's nonzero indices and sets the status to
92  * ``setup''.
93  *
94  * - forceSetup(): This method sets the status to ``setup'' without verifying that the IdxSet correctly contains all
95  * nonzero indices. It may be used when the nonzero indices have been computed externally.
96  */
97  //@{
98 
99  /// Only used in slufactor.cpp.
100  R* get_ptr()
101  {
102  return DVectorBase<R>::get_ptr();
103  }
104  /// Returns the non-zero epsilon used.
105  R getEpsilon() const
106  {
107  return epsilon;
108  }
109 
110  /// Changes the non-zero epsilon, invalidating the setup. */
111  void setEpsilon(R eps)
112  {
113  if(eps != epsilon)
114  {
115  epsilon = eps;
116  setupStatus = false;
117  }
118  }
119 
120  /// Returns setup status.
121  bool isSetup() const
122  {
123  return setupStatus;
124  }
125 
126  /// Makes SSVectorBase not setup.
127  void unSetup()
128  {
129  setupStatus = false;
130  }
131 
132  /// Initializes nonzero indices for elements with absolute values above #epsilon and sets all other elements to 0.
133  void setup()
134  {
135  if(!isSetup())
136  {
137  IdxSet::clear();
138 
139  int d = dim();
140  num = 0;
141 
142  for(int i = 0; i < d; ++i)
143  {
144  if(VectorBase<R>::val[i] != R(0))
145  {
146  if(spxAbs(VectorBase<R>::val[i]) <= epsilon)
147  VectorBase<R>::val[i] = R(0);
148  else
149  {
150  idx[num] = i;
151  num++;
152  }
153  }
154  }
155 
156  setupStatus = true;
157 
158  assert(isConsistent());
159  }
160  }
161 
162  /// Forces setup status.
163  void forceSetup()
164  {
165  setupStatus = true;
166  }
167 
168  //@}
169 
170  // ------------------------------------------------------------------------------------------------------------------
171  /**@name Methods for setup SSVectorBases */
172  //@{
173 
174  /// Returns index of the \p n 'th nonzero element.
175  int index(int n) const
176  {
177  assert(isSetup());
178 
179  return IdxSet::index(n);
180  }
181 
182  /// Returns value of the \p n 'th nonzero element.
183  R value(int n) const
184  {
185  assert(isSetup());
186  assert(n >= 0 && n < size());
187 
188  return VectorBase<R>::val[idx[n]];
189  }
190 
191  /// Finds the position of index \p i in the #IdxSet, or -1 if \p i doesn't exist.
192  int pos(int i) const
193  {
194  assert(isSetup());
195 
196  return IdxSet::pos(i);
197  }
198 
199  /// Returns the number of nonzeros.
200  int size() const
201  {
202  assert(isSetup());
203 
204  return IdxSet::size();
205  }
206 
207  /// Adds nonzero (\p i, \p x) to SSVectorBase.
208  /** No nonzero with index \p i must exist in the SSVectorBase. */
209  void add(int i, R x)
210  {
211  assert(VectorBase<R>::val[i] == R(0));
212  assert(pos(i) < 0);
213 
214  addIdx(i);
215  VectorBase<R>::val[i] = x;
216  }
217 
218  /// Sets \p i 'th element to \p x.
219  void setValue(int i, R x)
220  {
221  assert(i >= 0);
222  assert(i < DVectorBase<R>::dim());
223 
224  if(isSetup())
225  {
226  int n = pos(i);
227 
228  if(n < 0)
229  {
230  if(spxAbs(x) > epsilon)
231  IdxSet::add(1, &i);
232  }
233  else if(x == R(0))
234  clearNum(n);
235  }
236 
237  VectorBase<R>::val[i] = x;
238 
239  assert(isConsistent());
240  }
241 
242  /// Scale \p i 'th element by a
243  void scaleValue(int i, int scaleExp)
244  {
245  assert(i >= 0);
246  assert(i < DVectorBase<R>::dim());
247 
249 
250  assert(isConsistent());
251  }
252 
253  /// Clears element \p i.
254  void clearIdx(int i)
255  {
256  if(isSetup())
257  {
258  int n = pos(i);
259 
260  if(n >= 0)
261  remove(n);
262  }
263 
264  VectorBase<R>::val[i] = 0;
265 
266  assert(isConsistent());
267  }
268 
269  /// Sets \p n 'th nonzero element to 0 (index \p n must exist).
270  void clearNum(int n)
271  {
272  assert(isSetup());
273  assert(index(n) >= 0);
274 
275  VectorBase<R>::val[index(n)] = 0;
276  remove(n);
277 
278  assert(isConsistent());
279  }
280 
281  //@}
282 
283  // ------------------------------------------------------------------------------------------------------------------
284  /**@name Methods independent of the Status */
285  //@{
286 
287  /// Returns \p i 'th value.
288  R operator[](int i) const
289  {
290  return VectorBase<R>::val[i];
291  }
292 
293  /// Returns array indices.
294  const int* indexMem() const
295  {
296  return idx;
297  }
298 
299  /// Returns array values.
300  const R* values() const
301  {
302  return VectorBase<R>::val;
303  }
304 
305  /// Returns indices.
306  const IdxSet& indices() const
307  {
308  return *this;
309  }
310 
311  /// Returns array indices.
312  int* altIndexMem()
313  {
314  unSetup();
315  return idx;
316  }
317 
318  /// Returns array values.
320  {
321  unSetup();
322  return VectorBase<R>::val;
323  }
324 
325  /// Returns indices.
327  {
328  unSetup();
329  return *this;
330  }
331 
332  //@}
333 
334  // ------------------------------------------------------------------------------------------------------------------
335  /**@name Arithmetic operations */
336  //@{
337 
338  /// Addition.
339  template < class S >
341  {
343 
344  if(isSetup())
345  {
346  setupStatus = false;
347  setup();
348  }
349 
350  return *this;
351  }
352 
353  /// Addition.
354  template < class S >
356 
357  /// Addition.
358  template < class S >
360  {
361  assert(vec.isSetup());
362 
363  for(int i = vec.size() - 1; i >= 0; --i)
364  VectorBase<R>::val[vec.index(i)] += vec.value(i);
365 
366  if(isSetup())
367  {
368  setupStatus = false;
369  setup();
370  }
371 
372  return *this;
373  }
374 
375  /// Subtraction.
376  template < class S >
378  {
380 
381  if(isSetup())
382  {
383  setupStatus = false;
384  setup();
385  }
386 
387  return *this;
388  }
389 
390  /// Subtraction.
391  template < class S >
393 
394  /// Subtraction.
395  template < class S >
397  {
398  if(vec.isSetup())
399  {
400  for(int i = vec.size() - 1; i >= 0; --i)
401  VectorBase<R>::val[vec.index(i)] -= vec.value(i);
402  }
403  else
405 
406  if(isSetup())
407  {
408  setupStatus = false;
409  setup();
410  }
411 
412  return *this;
413  }
414 
415  /// Scaling.
416  template < class S >
418  {
419  assert(isSetup());
420  assert(x != S(0));
421 
422  for(int i = size() - 1; i >= 0; --i)
423  VectorBase<R>::val[index(i)] *= x;
424 
425  assert(isConsistent());
426 
427  return *this;
428  }
429 
430  // Inner product.
431  template < class S >
433  {
434  setup();
435 
436  StableSum<R> x;
437  int i = size() - 1;
438  int j = w.size() - 1;
439 
440  // both *this and w non-zero vectors?
441  if(i >= 0 && j >= 0)
442  {
443  int vi = index(i);
444  int wj = w.index(j);
445 
446  while(i != 0 && j != 0)
447  {
448  if(vi == wj)
449  {
450  x += VectorBase<R>::val[vi] * R(w.val[wj]);
451  vi = index(--i);
452  wj = w.index(--j);
453  }
454  else if(vi > wj)
455  vi = index(--i);
456  else
457  wj = w.index(--j);
458  }
459 
460  /* check remaining indices */
461 
462  while(i != 0 && vi != wj)
463  vi = index(--i);
464 
465  while(j != 0 && vi != wj)
466  wj = w.index(--j);
467 
468  if(vi == wj)
469  x += VectorBase<R>::val[vi] * R(w.val[wj]);
470  }
471 
472  return x;
473  }
474 
475  /// Addition of a scaled vector.
476  ///@todo SSVectorBase::multAdd() should be rewritten without pointer arithmetic.
477  template < class S, class T >
478  SSVectorBase<R>& multAdd(S xx, const SVectorBase<T>& vec);
479 
480  /// Addition of a scaled vector.
481  template < class S, class T >
483  {
484  VectorBase<R>::multAdd(x, vec);
485 
486  if(isSetup())
487  {
488  setupStatus = false;
489  setup();
490  }
491 
492  return *this;
493  }
494 
495  /// Assigns pair wise vector product to SSVectorBase.
496  template < class S, class T >
498 
499  /// Assigns \f$x^T \cdot A\f$ to SSVectorBase.
500  template < class S, class T >
502 
503  /// Assigns SSVectorBase to \f$A \cdot x\f$ for a setup \p x.
504  template < class S, class T >
506 
507 public:
508 
509  /// Assigns SSVectorBase to \f$A \cdot x\f$ thereby setting up \p x.
510  template < class S, class T >
512 
513  /// Maximum absolute value, i.e., infinity norm.
514  R maxAbs() const
515  {
516  if(isSetup())
517  {
518  R maxabs = 0;
519 
520  for(int i = 0; i < num; ++i)
521  {
522  R x = spxAbs(VectorBase<R>::val[idx[i]]);
523 
524  if(x > maxabs)
525  maxabs = x;
526  }
527 
528  return maxabs;
529  }
530  else
531  return VectorBase<R>::maxAbs();
532  }
533 
534  /// Squared euclidian norm.
535  R length2() const
536  {
537  R x = 0;
538 
539  if(isSetup())
540  {
541  for(int i = 0; i < num; ++i)
543  }
544  else
546 
547  return x;
548  }
549 
550  /// Floating point approximation of euclidian norm (without any approximation guarantee).
551  Real length() const
552  {
553  return spxSqrt((Real)length2());
554  }
555 
556  //@}
557 
558  // ------------------------------------------------------------------------------------------------------------------
559  /**@name Miscellaneous */
560  //@{
561 
562  /// Dimension of VectorBase.
563  int dim() const
564  {
565  return VectorBase<R>::dimen;
566  }
567 
568  /// Resets dimension to \p newdim.
569  void reDim(int newdim)
570  {
571  for(int i = IdxSet::size() - 1; i >= 0; --i)
572  {
573  if(index(i) >= newdim)
574  remove(i);
575  }
576 
577  DVectorBase<R>::reDim(newdim);
579 
580  assert(isConsistent());
581  }
582 
583  /// Sets number of nonzeros (thereby unSetup SSVectorBase).
584  void setSize(int n)
585  {
586  assert(n >= 0);
587  assert(n <= IdxSet::max());
588 
589  unSetup();
590  num = n;
591  }
592 
593  /// Resets memory consumption to \p newsize.
594  void reMem(int newsize)
595  {
596  DVectorBase<R>::reSize(newsize);
597  assert(isConsistent());
598 
600  }
601 
602  /// Clears vector.
603  void clear()
604  {
605  if(isSetup())
606  {
607  for(int i = 0; i < num; ++i)
608  VectorBase<R>::val[idx[i]] = 0;
609  }
610  else
612 
613  IdxSet::clear();
614  setupStatus = true;
615 
616  assert(isConsistent());
617  }
618 
619  /// consistency check.
620  bool isConsistent() const
621  {
622 #ifdef ENABLE_CONSISTENCY_CHECKS
623 
625  return MSGinconsistent("SSVectorBase");
626 
628  return MSGinconsistent("SSVectorBase");
629 
630  if(isSetup())
631  {
632  for(int i = 0; i < VectorBase<R>::dim(); ++i)
633  {
634  int j = pos(i);
635 
636  if(j < 0 && spxAbs(VectorBase<R>::val[i]) > 0)
637  {
638  MSG_ERROR(std::cerr << "ESSVEC01 i = " << i
639  << "\tidx = " << j
640  << "\tval = " << std::setprecision(16) << VectorBase<R>::val[i]
641  << std::endl;)
642 
643  return MSGinconsistent("SSVectorBase");
644  }
645  }
646  }
647 
649 #else
650  return true;
651 #endif
652  }
653 
654  //@}
655 
656  // ------------------------------------------------------------------------------------------------------------------
657  /**@name Constructors / Destructors */
658  //@{
659 
660  /// Default constructor.
661  explicit SSVectorBase<R>(int p_dim, R p_eps = Param::epsilon())
662  : DVectorBase<R>(p_dim)
663  , IdxSet()
664  , setupStatus(true)
665  , epsilon(p_eps)
666  {
667  len = (p_dim < 1) ? 1 : p_dim;
668  spx_alloc(idx, len);
670 
671  assert(isConsistent());
672  }
673 
674  /// Copy constructor.
675  template < class S >
677  : DVectorBase<R>(vec)
678  , IdxSet()
679  , setupStatus(vec.setupStatus)
680  , epsilon(vec.epsilon)
681  {
682  len = (vec.dim() < 1) ? 1 : vec.dim();
683  spx_alloc(idx, len);
684  IdxSet::operator=(vec);
685 
686  assert(isConsistent());
687  }
688 
689  /// Copy constructor.
690  /** The redundancy with the copy constructor below is necessary since otherwise the compiler doesn't realize that it
691  * could use the more general one with S = R and generates a shallow copy constructor.
692  */
694  : DVectorBase<R>(vec)
695  , IdxSet()
696  , setupStatus(vec.setupStatus)
697  , epsilon(vec.epsilon)
698  {
699  len = (vec.dim() < 1) ? 1 : vec.dim();
700  spx_alloc(idx, len);
701  IdxSet::operator=(vec);
702 
703  assert(isConsistent());
704  }
705 
706  /// Constructs nonsetup copy of \p vec.
707  template < class S >
708  explicit SSVectorBase<R>(const VectorBase<S>& vec, R eps = Param::epsilon())
709  : DVectorBase<R>(vec)
710  , IdxSet()
711  , setupStatus(false)
712  , epsilon(eps)
713  {
714  len = (vec.dim() < 1) ? 1 : vec.dim();
715  spx_alloc(idx, len);
716 
717  assert(isConsistent());
718  }
719 
720  /// Sets up \p rhs vector, and assigns it.
721  template < class S >
723  {
724  clear();
725  epsilon = rhs.epsilon;
726  setMax(rhs.max());
727  DVectorBase<R>::reDim(rhs.dim());
728 
729  if(rhs.isSetup())
730  {
731  IdxSet::operator=(rhs);
732 
733  for(int i = size() - 1; i >= 0; --i)
734  {
735  int j = index(i);
736  VectorBase<R>::val[j] = rhs.val[j];
737  }
738  }
739  else
740  {
741  int d = rhs.dim();
742  num = 0;
743 
744  for(int i = 0; i < d; ++i)
745  {
746  if(rhs.val[i] != 0)
747  {
748  if(spxAbs(rhs.val[i]) > epsilon)
749  {
750  rhs.idx[num] = i;
751  idx[num] = i;
752  VectorBase<R>::val[i] = rhs.val[i];
753  num++;
754  }
755  else
756  rhs.val[i] = 0;
757  }
758  }
759 
760  rhs.num = num;
761  rhs.setupStatus = true;
762  }
763 
764  setupStatus = true;
765 
766  assert(rhs.isConsistent());
767  assert(isConsistent());
768  }
769 
770  /// Assigns only the elements of \p rhs.
771  template < class S >
773 
774  /// Assignment operator.
775  template < class S >
777  {
778  assert(rhs.isConsistent());
779 
780  if(this != &rhs)
781  {
782  clear();
783  epsilon = rhs.epsilon;
784  setMax(rhs.max());
785  DVectorBase<R>::reDim(rhs.dim());
786 
787  if(rhs.isSetup())
788  {
789  IdxSet::operator=(rhs);
790 
791  for(int i = size() - 1; i >= 0; --i)
792  {
793  int j = index(i);
794  VectorBase<R>::val[j] = rhs.val[j];
795  }
796  }
797  else
798  {
799  int d = rhs.dim();
800  num = 0;
801 
802  for(int i = 0; i < d; ++i)
803  {
804  if(spxAbs(rhs.val[i]) > epsilon)
805  {
806  VectorBase<R>::val[i] = rhs.val[i];
807  idx[num] = i;
808  num++;
809  }
810  }
811  }
812 
813  setupStatus = true;
814  }
815 
816  assert(isConsistent());
817 
818  return *this;
819  }
820 
821  /// Assignment operator.
823  {
824  assert(rhs.isConsistent());
825 
826  if(this != &rhs)
827  {
828  clear();
829  epsilon = rhs.epsilon;
830  setMax(rhs.max());
831  DVectorBase<R>::reDim(rhs.dim());
832 
833  if(rhs.isSetup())
834  {
835  IdxSet::operator=(rhs);
836 
837  for(int i = size() - 1; i >= 0; --i)
838  {
839  int j = index(i);
840  VectorBase<R>::val[j] = rhs.val[j];
841  }
842  }
843  else
844  {
845  num = 0;
846 
847  for(int i = 0; i < rhs.dim(); ++i)
848  {
849  if(spxAbs(rhs.val[i]) > epsilon)
850  {
851  VectorBase<R>::val[i] = rhs.val[i];
852  idx[num] = i;
853  num++;
854  }
855  }
856  }
857 
858  setupStatus = true;
859  }
860 
861  assert(isConsistent());
862 
863  return *this;
864  }
865 
866  /// Assignment operator.
867  template < class S >
869 
870  /// Assignment operator.
871  template < class S >
873  {
874  unSetup();
876 
877  assert(isConsistent());
878 
879  return *this;
880  }
881 
882  /// destructor
884  {
885  if(idx)
886  spx_free(idx);
887  }
888 
889  //@}
890 
891 private:
892 
893  // ------------------------------------------------------------------------------------------------------------------
894  /**@name Private helpers */
895  //@{
896 
897  /// Assignment helper.
898  template < class S, class T >
900 
901  /// Assignment helper.
902  template < class S, class T >
904 
905  /// Assignment helper.
906  template < class S, class T >
908 
909  //@}
910 };
911 
912 } // namespace soplex
913 #endif // _SSVECTORBASE_H_
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:4102
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
Definition: ssvectorbase.h:514
void add(int n)
appends n uninitialized indices.
Definition: idxset.h:149
SSVectorBase< R > & assign2productFull(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
Definition: basevectors.h:754
int * idx
array of indices
Definition: idxset.h:65
bool isSetup() const
Returns setup status.
Definition: ssvectorbase.h:121
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase&#39;s dimension to newdim.
Definition: dvectorbase.h:253
bool isConsistent() const
Consistency check.
Definition: dvectorbase.h:307
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
Definition: vectorbase.h:112
Memory allocation routines.
int max() const
returns the maximal number of indices which can be stored in IdxSet.
Definition: idxset.h:129
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
Definition: basevectors.h:857
R length2() const
Squared norm.
Definition: vectorbase.h:405
Dynamic dense vectors.Class DVectorBase is a derived class of VectorBase adding automatic memory mana...
Definition: dvectorbase.h:48
Dense vector.Class VectorBase provides dense linear algebra vectors. It does not provide memory manag...
Definition: dsvectorbase.h:28
int pos(int i) const
Finds the position of index i in the IdxSet, or -1 if i doesn&#39;t exist.
Definition: ssvectorbase.h:192
Set of indices.
SSVectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
Definition: ssvectorbase.h:377
SSVectorBase< R > & operator+=(const SSVectorBase< S > &vec)
Addition.
Definition: ssvectorbase.h:359
SSVectorBase< R > & assign2product1(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
Definition: basevectors.h:604
Dynamic sparse vectors.Class DSVectorBase implements dynamic sparse vectors, i.e. SVectorBases with a...
Definition: dsvectorbase.h:42
void unSetup()
Makes SSVectorBase not setup.
Definition: ssvectorbase.h:127
void setValue(int i, R x)
Sets i &#39;th element to x.
Definition: ssvectorbase.h:219
void clear()
removes all indices.
Definition: idxset.h:184
SSVectorBase< R > & operator=(const SSVectorBase< R > &rhs)
Assignment operator.
Definition: ssvectorbase.h:822
void reMem(int newsize)
Resets memory consumption to newsize.
Definition: ssvectorbase.h:594
SSVectorBase< R > & operator*=(S x)
Scaling.
Definition: ssvectorbase.h:417
IdxSet()
default constructor.
Definition: idxset.h:91
SSVectorBase< R > & multAdd(S x, const VectorBase< T > &vec)
Addition of a scaled vector.
Definition: ssvectorbase.h:482
R operator*(const SSVectorBase< S > &w)
Definition: ssvectorbase.h:432
int * altIndexMem()
Returns array indices.
Definition: ssvectorbase.h:312
bool setupStatus
Is the SSVectorBase set up?
Definition: ssvectorbase.h:60
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
Definition: vectorbase.h:273
void addIdx(int i)
appends index i.
Definition: idxset.h:165
Semi sparse vector.This class implements semi-sparse vectors. Such are DVectorBases where the indices...
Definition: dsvectorbase.h:29
bool isConsistent() const
consistency check.
Definition: idxset.cpp:117
int dim() const
Dimension of VectorBase.
Definition: ssvectorbase.h:563
SSVectorBase< R > & assign2productAndSetup(const SVSetBase< S > &A, SSVectorBase< T > &x)
Assigns SSVectorBase to thereby setting up x.
Definition: basevectors.h:798
void spx_alloc(T &p, int n=1)
Allocate memory.
Definition: spxalloc.h:48
R * altValues()
Returns array values.
Definition: ssvectorbase.h:319
R * get_ptr()
Conversion to C-style pointer.
Definition: vectorbase.h:446
void reSize(int newsize)
Resets DVectorBase&#39;s memory size to newsize.
Definition: dvectorbase.h:270
Real spxLdexp(Real x, int exp)
returns x * 2^exp
Definition: spxdefines.h:348
double Real
Definition: spxdefines.h:218
const R * values() const
Returns array values.
Definition: ssvectorbase.h:300
SSVectorBase< R > & assign2product(const SSVectorBase< S > &x, const SVSetBase< T > &A)
Assigns to SSVectorBase.
Definition: basevectors.h:539
int pos(int i) const
returns the position of index i.
Definition: idxset.cpp:32
int size() const
returns the number of used indices.
Definition: idxset.h:124
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:114
int len
length of array idx
Definition: idxset.h:64
const IdxSet & indices() const
Returns indices.
Definition: ssvectorbase.h:306
void clearNum(int n)
Sets n &#39;th nonzero element to 0 (index n must exist).
Definition: ssvectorbase.h:270
IdxSet & operator=(const IdxSet &set)
assignment operator.
Definition: idxset.cpp:71
R operator[](int i) const
Returns i &#39;th value.
Definition: ssvectorbase.h:288
Real spxSqrt(Real a)
returns square root
Definition: spxdefines.h:332
void clear()
Clears vector.
Definition: ssvectorbase.h:603
IdxSet & altIndices()
Returns indices.
Definition: ssvectorbase.h:326
R * val
Values of vector.
Definition: vectorbase.h:88
void setEpsilon(R eps)
Changes the non-zero epsilon, invalidating the setup. */.
Definition: ssvectorbase.h:111
bool isConsistent() const
consistency check.
Definition: ssvectorbase.h:620
SSVectorBase< R > & multAdd(S xx, const SVectorBase< T > &vec)
Addition of a scaled vector.
Definition: basevectors.h:409
int index(int n) const
Returns index of the n &#39;th nonzero element.
Definition: ssvectorbase.h:175
SSVectorBase< R > & operator-=(const SSVectorBase< S > &vec)
Subtraction.
Definition: ssvectorbase.h:396
const int * indexMem() const
Returns array indices.
Definition: ssvectorbase.h:294
void reDim(int newdim)
Resets dimension to newdim.
Definition: ssvectorbase.h:569
Debugging, floating point type and parameter definitions.
void setSize(int n)
Sets number of nonzeros (thereby unSetup SSVectorBase).
Definition: ssvectorbase.h:584
static Real epsilon()
Definition: spxdefines.cpp:45
void clearIdx(int i)
Clears element i.
Definition: ssvectorbase.h:254
R * get_ptr()
Only used in slufactor.cpp.
Definition: ssvectorbase.h:100
void spx_realloc(T &p, int n)
Change amount of allocated memory.
Definition: spxalloc.h:79
R length2() const
Squared euclidian norm.
Definition: ssvectorbase.h:535
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition: vectorbase.h:412
void setup_and_assign(SSVectorBase< S > &rhs)
Sets up rhs vector, and assigns it.
Definition: ssvectorbase.h:722
int size() const
Returns the number of nonzeros.
Definition: ssvectorbase.h:200
Everything should be within this namespace.
int dim() const
Dimension of the vector defined as maximal index + 1.
Definition: svectorbase.h:167
void setMax(int newmax)
Allocates enough space to accommodate newmax values.
Definition: ssvectorbase.h:66
R getEpsilon() const
Returns the non-zero epsilon used.
Definition: ssvectorbase.h:105
SSVectorBase< R > & operator=(const SSVectorBase< S > &rhs)
Assignment operator.
Definition: ssvectorbase.h:776
SSVectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
Definition: ssvectorbase.h:340
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
Definition: vectorbase.h:294
void setup()
Initializes nonzero indices for elements with absolute values above epsilon and sets all other elemen...
Definition: ssvectorbase.h:133
void clear()
Set vector to 0.
Definition: vectorbase.h:262
void forceSetup()
Forces setup status.
Definition: ssvectorbase.h:163
SSVectorBase< R > & operator=(const VectorBase< S > &rhs)
Assignment operator.
Definition: ssvectorbase.h:872
Real length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
Definition: ssvectorbase.h:551
int dim() const
returns the maximal index.
Definition: idxset.cpp:21
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
Definition: dvectorbase.h:31
SSVectorBase< R > & assignPWproduct4setup(const SSVectorBase< S > &x, const SSVectorBase< T > &y)
Assigns pair wise vector product to SSVectorBase.
Definition: basevectors.h:478
#define MSGinconsistent(name)
Definition: spxdefines.h:126
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
Definition: vectorbase.h:357
R epsilon
A value x with |x| < epsilon is considered zero.
Definition: ssvectorbase.h:63
int index(int n) const
access n &#39;th index.
Definition: idxset.h:118
int num
number of used indices
Definition: idxset.h:63
void add(int i, R x)
Adds nonzero (i, x) to SSVectorBase.
Definition: ssvectorbase.h:209
SSVectorBase< R > & assign2productShort(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
Definition: basevectors.h:640
Set of indices.Class IdxSet provides a set of indices. At construction it must be given an array of i...
Definition: idxset.h:56
void spx_free(T &p)
Release memory.
Definition: spxalloc.h:110
Sparse vector set.Class SVSetBase provides a set of sparse vectors SVectorBase. All SVectorBases in a...
Definition: ssvectorbase.h:34
void scaleValue(int i, int scaleExp)
Scale i &#39;th element by a.
Definition: ssvectorbase.h:243
R value(int n) const
Returns value of the n &#39;th nonzero element.
Definition: ssvectorbase.h:183
Dynamic dense vectors.
SSVectorBase< R > & assign2product4setup(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assigns SSVectorBase to for a setup x.
Definition: basevectors.h:570