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  assert(vec.isSetup());
360  for( int i = vec.size() - 1; i >= 0; --i )
361  VectorBase<R>::val[vec.index(i)] += vec.value(i);
362 
363  if( isSetup() )
364  {
365  setupStatus = false;
366  setup();
367  }
368 
369  return *this;
370  }
371 
372  /// Subtraction.
373  template < class S >
375  {
377 
378  if( isSetup() )
379  {
380  setupStatus = false;
381  setup();
382  }
383 
384  return *this;
385  }
386 
387  /// Subtraction.
388  template < class S >
390 
391  /// Subtraction.
392  template < class S >
394  {
395  if( vec.isSetup() )
396  {
397  for( int i = vec.size() - 1; i >= 0; --i )
398  VectorBase<R>::val[vec.index(i)] -= vec.value(i);
399  }
400  else
402 
403  if( isSetup() )
404  {
405  setupStatus = false;
406  setup();
407  }
408 
409  return *this;
410  }
411 
412  /// Scaling.
413  template < class S >
415  {
416  assert(isSetup());
417  assert(x != S(0));
418 
419  for( int i = size() - 1; i >= 0; --i )
420  VectorBase<R>::val[index(i)] *= x;
421 
422  assert(isConsistent());
423 
424  return *this;
425  }
426 
427  // Inner product.
428  template < class S >
430  {
431  setup();
432 
433  R x = R(0);
434  int i = size() - 1;
435  int j = w.size() - 1;
436 
437  // both *this and w non-zero vectors?
438  if( i >= 0 && j >= 0 )
439  {
440  int vi = index(i);
441  int wj = w.index(j);
442 
443  while( i != 0 && j != 0 )
444  {
445  if( vi == wj )
446  {
447  x += VectorBase<R>::val[vi] * R(w.val[wj]);
448  vi = index(--i);
449  wj = w.index(--j);
450  }
451  else if( vi > wj )
452  vi = index(--i);
453  else
454  wj = w.index(--j);
455  }
456 
457  /* check remaining indices */
458 
459  while( i != 0 && vi != wj )
460  vi = index(--i);
461 
462  while( j != 0 && vi != wj )
463  wj = w.index(--j);
464 
465  if( vi == wj )
466  x += VectorBase<R>::val[vi] * R(w.val[wj]);
467  }
468 
469  return x;
470  }
471 
472  /// Addition of a scaled vector.
473  ///@todo SSVectorBase::multAdd() should be rewritten without pointer arithmetic.
474  template < class S, class T >
475  SSVectorBase<R>& multAdd(S xx, const SVectorBase<T>& vec);
476 
477  /// Addition of a scaled vector.
478  template < class S, class T >
480  {
481  VectorBase<R>::multAdd(x, vec);
482 
483  if( isSetup() )
484  {
485  setupStatus = false;
486  setup();
487  }
488 
489  return *this;
490  }
491 
492  /// Assigns pair wise vector product to SSVectorBase.
493  template < class S, class T >
495 
496  /// Assigns \f$x^T \cdot A\f$ to SSVectorBase.
497  template < class S, class T >
499 
500  /// Assigns SSVectorBase to \f$A \cdot x\f$ for a setup \p x.
501  template < class S, class T >
503 
504 public:
505 
506  /// Assigns SSVectorBase to \f$A \cdot x\f$ thereby setting up \p x.
507  template < class S, class T >
509 
510  /// Maximum absolute value, i.e., infinity norm.
511  R maxAbs() const
512  {
513  if( isSetup() )
514  {
515  R maxabs = 0;
516 
517  for( int i = 0; i < num; ++i )
518  {
519  R x = spxAbs(VectorBase<R>::val[idx[i]]);
520 
521  if( x > maxabs )
522  maxabs = x;
523  }
524 
525  return maxabs;
526  }
527  else
528  return VectorBase<R>::maxAbs();
529  }
530 
531  /// Squared euclidian norm.
532  R length2() const
533  {
534  R x = 0;
535 
536  if( isSetup() )
537  {
538  for( int i = 0; i < num; ++i )
540  }
541  else
543 
544  return x;
545  }
546 
547  /// Floating point approximation of euclidian norm (without any approximation guarantee).
548  Real length() const
549  {
550  return spxSqrt((Real)length2());
551  }
552 
553  //@}
554 
555  // ------------------------------------------------------------------------------------------------------------------
556  /**@name Miscellaneous */
557  //@{
558 
559  /// Dimension of VectorBase.
560  int dim() const
561  {
562  return VectorBase<R>::dimen;
563  }
564 
565  /// Resets dimension to \p newdim.
566  void reDim(int newdim)
567  {
568  for( int i = IdxSet::size() - 1; i >= 0; --i )
569  {
570  if( index(i) >= newdim )
571  remove(i);
572  }
573 
574  DVectorBase<R>::reDim(newdim);
576 
577  assert(isConsistent());
578  }
579 
580  /// Sets number of nonzeros (thereby unSetup SSVectorBase).
581  void setSize(int n)
582  {
583  assert(n >= 0);
584  assert(n <= IdxSet::max());
585 
586  unSetup();
587  num = n;
588  }
589 
590  /// Resets memory consumption to \p newsize.
591  void reMem(int newsize)
592  {
593  DVectorBase<R>::reSize(newsize);
594  assert(isConsistent());
595 
597  }
598 
599  /// Clears vector.
600  void clear()
601  {
602  if( isSetup() )
603  {
604  for( int i = 0; i < num; ++i )
605  VectorBase<R>::val[idx[i]] = 0;
606  }
607  else
609 
610  IdxSet::clear();
611  setupStatus = true;
612 
613  assert(isConsistent());
614  }
615 
616  /// consistency check.
617  bool isConsistent() const
618  {
619 #ifdef ENABLE_CONSISTENCY_CHECKS
620  if( VectorBase<R>::dim() > IdxSet::max() )
621  return MSGinconsistent("SSVectorBase");
622 
623  if( VectorBase<R>::dim() < IdxSet::dim() )
624  return MSGinconsistent("SSVectorBase");
625 
626  if( isSetup() )
627  {
628  for( int i = 0; i < VectorBase<R>::dim(); ++i )
629  {
630  int j = pos(i);
631 
632  if( j < 0 && spxAbs(VectorBase<R>::val[i]) > 0 )
633  {
634  MSG_ERROR( std::cerr << "ESSVEC01 i = " << i
635  << "\tidx = " << j
636  << "\tval = " << std::setprecision(16) << VectorBase<R>::val[i]
637  << std::endl; )
638 
639  return MSGinconsistent("SSVectorBase");
640  }
641  }
642  }
643 
645 #else
646  return true;
647 #endif
648  }
649 
650  //@}
651 
652  // ------------------------------------------------------------------------------------------------------------------
653  /**@name Constructors / Destructors */
654  //@{
655 
656  /// Default constructor.
657  explicit SSVectorBase<R>(int p_dim, R p_eps = Param::epsilon())
658  : DVectorBase<R>(p_dim)
659  , IdxSet()
660  , setupStatus(true)
661  , epsilon(p_eps)
662  {
663  len = (p_dim < 1) ? 1 : p_dim;
664  spx_alloc(idx, len);
666 
667  assert(isConsistent());
668  }
669 
670  /// Copy constructor.
671  template < class S >
673  : DVectorBase<R>(vec)
674  , IdxSet()
675  , setupStatus(vec.setupStatus)
676  , epsilon(vec.epsilon)
677  {
678  len = (vec.dim() < 1) ? 1 : vec.dim();
679  spx_alloc(idx, len);
680  IdxSet::operator=(vec);
681 
682  assert(isConsistent());
683  }
684 
685  /// Copy constructor.
686  /** The redundancy with the copy constructor below is necessary since otherwise the compiler doesn't realize that it
687  * could use the more general one with S = R and generates a shallow copy constructor.
688  */
690  : DVectorBase<R>(vec)
691  , IdxSet()
692  , setupStatus(vec.setupStatus)
693  , epsilon(vec.epsilon)
694  {
695  len = (vec.dim() < 1) ? 1 : vec.dim();
696  spx_alloc(idx, len);
697  IdxSet::operator=(vec);
698 
699  assert(isConsistent());
700  }
701 
702  /// Constructs nonsetup copy of \p vec.
703  template < class S >
704  explicit SSVectorBase<R>(const VectorBase<S>& vec, R eps = Param::epsilon())
705  : DVectorBase<R>(vec)
706  , IdxSet()
707  , setupStatus(false)
708  , epsilon(eps)
709  {
710  len = (vec.dim() < 1) ? 1 : vec.dim();
711  spx_alloc(idx, len);
712 
713  assert(isConsistent());
714  }
715 
716  /// Sets up \p rhs vector, and assigns it.
717  template < class S >
719  {
720  clear();
721  epsilon = rhs.epsilon;
722  setMax(rhs.max());
723  DVectorBase<R>::reDim(rhs.dim());
724 
725  if( rhs.isSetup() )
726  {
727  IdxSet::operator=(rhs);
728 
729  for( int i = size() - 1; i >= 0; --i )
730  {
731  int j = index(i);
732  VectorBase<R>::val[j] = rhs.val[j];
733  }
734  }
735  else
736  {
737  int d = rhs.dim();
738  num = 0;
739 
740  for( int i = 0; i < d; ++i )
741  {
742  if( rhs.val[i] != 0 )
743  {
744  if( spxAbs(rhs.val[i]) > epsilon )
745  {
746  rhs.idx[num] = i;
747  idx[num] = i;
748  VectorBase<R>::val[i] = rhs.val[i];
749  num++;
750  }
751  else
752  rhs.val[i] = 0;
753  }
754  }
755 
756  rhs.num = num;
757  rhs.setupStatus = true;
758  }
759 
760  setupStatus = true;
761 
762  assert(rhs.isConsistent());
763  assert(isConsistent());
764  }
765 
766  /// Assigns only the elements of \p rhs.
767  template < class S >
769 
770  /// Assignment operator.
771  template < class S >
773  {
774  assert(rhs.isConsistent());
775 
776  if( this != &rhs )
777  {
778  clear();
779  epsilon = rhs.epsilon;
780  setMax(rhs.max());
781  DVectorBase<R>::reDim(rhs.dim());
782 
783  if( rhs.isSetup() )
784  {
785  IdxSet::operator=(rhs);
786 
787  for( int i = size() - 1; i >= 0; --i )
788  {
789  int j = index(i);
790  VectorBase<R>::val[j] = rhs.val[j];
791  }
792  }
793  else
794  {
795  int d = rhs.dim();
796  num = 0;
797 
798  for( int i = 0; i < d; ++i )
799  {
800  if( spxAbs(rhs.val[i]) > epsilon )
801  {
802  VectorBase<R>::val[i] = rhs.val[i];
803  idx[num] = i;
804  num++;
805  }
806  }
807  }
808 
809  setupStatus = true;
810  }
811 
812  assert(isConsistent());
813 
814  return *this;
815  }
816 
817  /// Assignment operator.
819  {
820  assert(rhs.isConsistent());
821 
822  if( this != &rhs )
823  {
824  clear();
825  epsilon = rhs.epsilon;
826  setMax(rhs.max());
827  DVectorBase<R>::reDim(rhs.dim());
828 
829  if( rhs.isSetup() )
830  {
831  IdxSet::operator=(rhs);
832 
833  for( int i = size() - 1; i >= 0; --i )
834  {
835  int j = index(i);
836  VectorBase<R>::val[j] = rhs.val[j];
837  }
838  }
839  else
840  {
841  num = 0;
842 
843  for( int i = 0; i < rhs.dim(); ++i )
844  {
845  if( spxAbs(rhs.val[i]) > epsilon )
846  {
847  VectorBase<R>::val[i] = rhs.val[i];
848  idx[num] = i;
849  num++;
850  }
851  }
852  }
853 
854  setupStatus = true;
855  }
856 
857  assert(isConsistent());
858 
859  return *this;
860  }
861 
862  /// Assignment operator.
863  template < class S >
865 
866  /// Assignment operator.
867  template < class S >
869  {
870  unSetup();
872 
873  assert(isConsistent());
874 
875  return *this;
876  }
877 
878  /// destructor
880  {
881  if( idx )
882  spx_free(idx);
883  }
884 
885  //@}
886 
887 private:
888 
889  // ------------------------------------------------------------------------------------------------------------------
890  /**@name Private helpers */
891  //@{
892 
893  /// Assignment helper.
894  template < class S, class T >
896 
897  /// Assignment helper.
898  template < class S, class T >
900 
901  /// Assignment helper.
902  template < class S, class T >
904 
905  //@}
906 };
907 
908 } // namespace soplex
909 #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:511
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:374
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:818
void reMem(int newsize)
Resets memory consumption to newsize.
Definition: ssvectorbase.h:591
SSVectorBase< R > & operator*=(S x)
Scaling.
Definition: ssvectorbase.h:414
IdxSet()
default constructor.
Definition: idxset.h:91
SSVectorBase< R > & multAdd(S x, const VectorBase< T > &vec)
Addition of a scaled vector.
Definition: ssvectorbase.h:479
R operator*(const SSVectorBase< S > &w)
Definition: ssvectorbase.h:429
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:560
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:352
double Real
Definition: spxdefines.h:218
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:114
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:334
void clear()
Clears vector.
Definition: ssvectorbase.h:600
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:617
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:393
const int * indexMem() const
Returns array indices.
Definition: ssvectorbase.h:293
void reDim(int newdim)
Resets dimension to newdim.
Definition: ssvectorbase.h:566
Debugging, floating point type and parameter definitions.
void setSize(int n)
Sets number of nonzeros (thereby unSetup SSVectorBase).
Definition: ssvectorbase.h:581
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:532
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:718
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:772
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:868
Real length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
Definition: ssvectorbase.h:548
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:126
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