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