SoPlex Documentation
Loading...
Searching...
No Matches
basevectors.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-2023 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file basevectors.h
26 * @brief Collection of dense, sparse, and semi-sparse vectors.
27 */
28#ifndef _BASEVECTORS_H_
29#define _BASEVECTORS_H_
30
31/* undefine SOPLEX_DEBUG flag from including files; if SOPLEX_DEBUG should be defined in this file, do so below */
32#ifdef SOPLEX_DEBUG
33#define SOPLEX_DEBUG_BASEVECTORS
34#undef SOPLEX_DEBUG
35#endif
36
37#include "soplex/spxdefines.h"
38#include "soplex/rational.h"
39#include "soplex/vectorbase.h"
40#include "soplex/ssvectorbase.h"
41#include "soplex/svectorbase.h"
42#include "soplex/dsvectorbase.h"
44#include "soplex/svsetbase.h"
45#include "soplex/timer.h"
46
47#define SOPLEX_VECTOR_MARKER 1e-100
48
49namespace soplex
50{
51
52// ---------------------------------------------------------------------------------------------------------------------
53// Methods of VectorBase
54// ---------------------------------------------------------------------------------------------------------------------
55
56/// Assignment operator.
57/** Assigning an SVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of \p vec.
58 * This is different in method assign().
59 */
60
61
62
63template < class R >
64template < class S >
65inline
67{
68 clear();
69
70 for(int i = 0; i < vec.size(); ++i)
71 {
72 assert(vec.index(i) < dim());
73 val[vec.index(i)] = vec.value(i);
74 }
75
76 return *this;
77}
78
79
80
81/// Assign values of \p vec.
82/** Assigns all nonzeros of \p vec to the vector. All other values remain unchanged. */
83template < class R >
84template < class S >
85inline
87{
88 for(int i = vec.size() - 1; i >= 0; --i)
89 {
90 assert(vec.index(i) < dim());
91 val[vec.index(i)] = vec.value(i);
92 }
93
94 return *this;
95}
96
97
98
99/// Assignment operator.
100/** Assigning an SSVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of \p vec.
101 * This is different in method assign().
102 */
103template < class R >
104template < class S >
105inline
107{
108 if(vec.isSetup())
109 {
110 clear();
111 assign(vec);
112 }
113 else
114 operator=(static_cast<const VectorBase<R>&>(vec));
115
116 return *this;
117}
118
119
120
121/// Assign values of \p vec.
122/** Assigns all nonzeros of \p vec to the vector. All other values remain unchanged. */
123template < class R >
124template < class S >
125inline
127{
128 assert(vec.dim() <= dim());
129
130 if(vec.isSetup())
131 {
132 const int* idx = vec.indexMem();
133
134 for(int i = vec.size() - 1; i >= 0; --i)
135 {
136 val[*idx] = vec.val[*idx];
137 idx++;
138 }
139 }
140 else
141 operator=(static_cast<const VectorBase<R>&>(vec));
142
143 return *this;
144}
145
146
147
148/// Addition.
149template < class R >
150template < class S >
151inline
153{
154 for(int i = vec.size() - 1; i >= 0; --i)
155 {
156 assert(vec.index(i) >= 0);
157 assert(vec.index(i) < dim());
158 val[vec.index(i)] += vec.value(i);
159 }
160
161 return *this;
162}
163
164
165
166/// Addition.
167template < class R >
168template < class S >
169inline
171{
172 assert(dim() == vec.dim());
173
174 if(vec.isSetup())
175 {
176 for(int i = vec.size() - 1; i >= 0 ; --i)
177 val[vec.index(i)] += vec.value(i);
178 }
179 else
180 {
181 for(int i = dim() - 1; i >= 0; --i)
182 val[i] += vec[i];
183 }
184
185 return *this;
186}
187
188
189
190/// Subtraction.
191template < class R >
192template < class S >
193inline
195{
196 for(int i = vec.size() - 1; i >= 0; --i)
197 {
198 assert(vec.index(i) >= 0);
199 assert(vec.index(i) < dim());
200 val[vec.index(i)] -= vec.value(i);
201 }
203 return *this;
204}
205
207
208/// Subtraction.
209template < class R >
210template < class S >
211inline
213{
214 assert(dim() == vec.dim());
215
216 if(vec.isSetup())
217 {
218 for(int i = vec.size() - 1; i >= 0; --i)
219 val[vec.index(i)] -= vec.value(i);
220 }
221 else
222 {
223 for(int i = dim() - 1; i >= 0; --i)
224 val[i] -= vec[i];
225 }
226
227 return *this;
228}
229
230
231
232/// Inner product.
233template < class R >
234inline
236{
237 assert(dim() >= vec.dim());
238
240
241 for(int i = vec.size() - 1; i >= 0; --i)
242 x += val[vec.index(i)] * vec.value(i);
244 return x;
245}
246
247
248
249/// Inner product.
250template < class R >
251inline
253{
254 assert(dim() == vec.dim());
255
256 if(vec.isSetup())
257 {
258 const int* idx = vec.indexMem();
259
262 for(int i = vec.size() - 1; i >= 0; --i)
263 {
264 x += val[*idx] * vec.val[*idx];
265 idx++;
266 }
267
268 return x;
269 }
270 else
271 return operator*(static_cast<const VectorBase<R>&>(vec));
272}
273
274
275
276/// Addition of scaled vector.
277template < class R >
278template < class S, class T >
279inline
281{
282 for(int i = vec.size() - 1; i >= 0; --i)
283 {
284 assert(vec.index(i) < dim());
285 val[vec.index(i)] += x * vec.value(i);
286 }
287
288 return *this;
289}
290
291
292
293/// Subtraction of scaled vector.
294template < class R >
295template < class S, class T >
296inline
298{
299 for(int i = vec.size() - 1; i >= 0; --i)
300 {
301 assert(vec.index(i) < dim());
302 val[vec.index(i)] -= x * vec.value(i);
303 }
304
305 return *this;
306}
307
308
309
310/// Addition of scaled vector.
311template < class R >
312template < class S, class T >
313inline
315{
316 assert(vec.dim() <= dim());
317
318 if(vec.isSetup())
319 {
320 const int* idx = vec.indexMem();
321
322 for(int i = vec.size() - 1; i >= 0; --i)
323 val[idx[i]] += x * vec[idx[i]];
324 }
325 else
326 {
327 assert(vec.dim() == dim());
328
329 for(int i = dim() - 1; i >= 0; --i)
330 val[i] += x * vec.val[i];
331 }
332
333 return *this;
335
336
337
338
339
340// ---------------------------------------------------------------------------------------------------------------------
341// Methods of SSVectorBase
342// ---------------------------------------------------------------------------------------------------------------------
343
344
345
346/// Addition.
347template < class R >
348template < class S >
349inline
351{
353
354 if(isSetup())
355 {
356 setupStatus = false;
357 setup();
358 }
359
360 return *this;
361}
362
363
365/// Subtraction.
366template < class R >
367template < class S >
368inline
370{
372
373 if(isSetup())
374 {
375 setupStatus = false;
376 setup();
377 }
378
379 return *this;
380}
381
382
383
384/// Addition of a scaled vector.
385///@todo SSVectorBase::multAdd() should be rewritten without pointer arithmetic.
386template < class R >
387template < class S, class T >
388inline
390{
391 if(isSetup())
392 {
393 R* v = VectorBase<R>::val.data();
394 R x;
395 bool adjust = false;
396 int j;
397
398 for(int i = vec.size() - 1; i >= 0; --i)
400 j = vec.index(i);
402 if(v[j] != 0)
403 {
404 x = v[j] + xx * vec.value(i);
405
406 if(isNotZero(x, epsilon))
407 v[j] = x;
408 else
409 {
410 adjust = true;
412 }
413 }
414 else
415 {
416 x = xx * vec.value(i);
417
418 if(isNotZero(x, epsilon))
419 {
420 v[j] = x;
421 addIdx(j);
422 }
423 }
424 }
425
426 if(adjust)
427 {
428 int* iptr = idx;
429 int* iiptr = idx;
430 int* endptr = idx + num;
431
432 for(; iptr < endptr; ++iptr)
433 {
434 x = v[*iptr];
435
436 if(isNotZero(x, epsilon))
437 *iiptr++ = *iptr;
438 else
439 v[*iptr] = 0;
440 }
441
442 num = int(iiptr - idx);
443 }
444 }
445 else
447
449
450 return *this;
451}
452
453
454/// Assigns pair wise vector product of setup x and setup y to SSVectorBase.
455template < class R >
456template < class S, class T >
457inline
459 const SSVectorBase<T>& y)
460{
461 assert(dim() == x.dim());
462 assert(x.dim() == y.dim());
463 assert(x.isSetup());
464 assert(y.isSetup());
465
466 clear();
467 setupStatus = false;
468
469 int i = 0;
470 int j = 0;
471 int n = x.size() - 1;
472 int m = y.size() - 1;
473
474 /* both x and y non-zero vectors? */
475 if(m >= 0 && n >= 0)
477 int xi = x.index(i);
478 int yj = y.index(j);
479
480 while(i < n && j < m)
481 {
482 if(xi == yj)
483 {
484 VectorBase<R>::val[xi] = R(x.val[xi]) * R(y.val[xi]);
485 xi = x.index(++i);
486 yj = y.index(++j);
488 else if(xi < yj)
489 xi = x.index(++i);
490 else
491 yj = y.index(++j);
492 }
493
494 /* check (possible) remaining indices */
495
496 while(i < n && xi != yj)
497 xi = x.index(++i);
498
499 while(j < m && xi != yj)
500 yj = y.index(++j);
501
502 if(xi == yj)
503 VectorBase<R>::val[xi] = R(x.val[xi]) * R(y.val[xi]);
504 }
505
506 setup();
507
509
510 return *this;
511}
512
513
515/// Assigns \f$x^T \cdot A\f$ to SSVectorBase.
516template < class R >
517template < class S, class T >
518inline
520{
521 assert(A.num() == dim());
522
523 R y;
524
525 clear();
526
527 for(int i = dim() - 1; i >= 0; --i)
528 {
529 y = A[i] * x;
530
531 if(isNotZero(y, epsilon))
532 {
535 }
536 }
537
539
540 return *this;
541}
542
543
544
545/// Assigns SSVectorBase to \f$A \cdot x\f$ for a setup \p x.
546#define shortProductFactor 0.5
547template < class R >
548template < class S, class T >
549inline
551 const SSVectorBase<T>& x,
553 int& nCallsSparse, int& nCallsFull
554 )
555{
556 assert(A.num() == x.dim());
557 assert(x.isSetup());
559
560 if(x.size() == 1)
561 {
562 if(timeSparse != 0)
563 timeSparse->start();
564
565 assign2product1(A, x);
566 setupStatus = true;
567
568 if(timeSparse != 0)
569 timeSparse->stop();
570
571 ++nCallsSparse;
572 }
573 else if(isSetup() && (double(x.size()) * A.memSize() <= shortProductFactor * dim() * A.num()))
574 {
575 if(timeSparse != 0)
576 timeSparse->start();
577
578 assign2productShort(A, x);
579 setupStatus = true;
580
581 if(timeSparse != 0)
582 timeSparse->stop();
583
584 ++nCallsSparse;
585 }
586 else
587 {
588 if(timeFull != 0)
589 timeFull->start();
590
591 assign2productFull(A, x);
592 setupStatus = false;
593
594 if(timeFull != 0)
595 timeFull->stop();
596
597 ++nCallsFull;
598 }
599
601
602 return *this;
603}
604
605
606
607/// Assignment helper.
608template < class R >
609template < class S, class T >
610inline
612{
613 assert(x.isSetup());
614 assert(x.size() == 1);
615
616 // get the nonzero value of x and the corresponding vector in A:
617 const int nzidx = x.idx[0];
618 const T nzval = x.val[nzidx];
619 const SVectorBase<S>& Ai = A[nzidx];
620
621 // compute A[nzidx] * nzval:
622 if(isZero(nzval, epsilon) || Ai.size() == 0)
623 clear(); // this := zero vector
624 else
625 {
626 num = Ai.size();
627
628 for(int j = num - 1; j >= 0; --j)
629 {
630 const Nonzero<S>& Aij = Ai.element(j);
631 idx[j] = Aij.idx;
632 VectorBase<R>::val[Aij.idx] = nzval * Aij.val;
633 }
635
637
638 return *this;
639}
640
641
642
643/// Assignment helper.
644template < class R >
645template < class S, class T >
646inline
648 const SSVectorBase<T>& x)
649{
650 assert(x.isSetup());
651
652 if(x.size() == 0) // x can be setup but have size 0 => this := zero vector
653 {
654 clear();
655 return *this;
656 }
657
658 // compute x[0] * A[0]
659 int curidx = x.idx[0];
660 const T x0 = x.val[curidx];
661 const SVectorBase<S>& A0 = A[curidx];
662 int nonzero_idx = 0;
663 int xsize = x.size();
664 int Aisize;
665
666 num = A0.size();
667
668 if(isZero(x0, epsilon) || num == 0)
669 {
670 // A[0] == 0 or x[0] == 0 => this := zero vector
671 clear();
672 }
673 else
674 {
675 for(int j = 0; j < num; ++j)
676 {
677 const Nonzero<S>& elt = A0.element(j);
678 const R product = x0 * elt.val;
679
680 // store the value in any case
681 idx[nonzero_idx] = elt.idx;
683
684 // count only non-zero values; not 'isNotZero(product, epsilon)'
685 if(product != 0)
686 ++nonzero_idx;
687 }
688 }
689
690 // Compute the other x[i] * A[i] and add them to the existing vector.
691 for(int i = 1; i < xsize; ++i)
692 {
693 curidx = x.idx[i];
694 const T xi = x.val[curidx];
695 const SVectorBase<S>& Ai = A[curidx];
696
697 // If A[i] == 0 or x[i] == 0, do nothing.
698 Aisize = Ai.size();
699
700 if(isNotZero(xi, epsilon) || Aisize == 0)
701 {
702 // Compute x[i] * A[i] and add it to the existing vector.
703 for(int j = 0; j < Aisize; ++j)
704 {
705 const Nonzero<S>& elt = Ai.element(j);
706 idx[nonzero_idx] = elt.idx;
708
709 // An old value of exactly 0 means the position is still unused.
710 // It will be used now (either by a new nonzero or by a SOPLEX_VECTOR_MARKER),
711 // so increase the counter. If oldval != 0, we just
712 // change an existing NZ-element, so don't increase the counter.
713 if(oldval == 0)
714 ++nonzero_idx;
715
716 // Add the current product x[i] * A[i][j]; if oldval was
717 // SOPLEX_VECTOR_MARKER before, it does not hurt because SOPLEX_VECTOR_MARKER is really small.
718 oldval += xi * elt.val;
719
720 // If the new value is exactly 0, mark the index as used
721 // by setting a value which is nearly 0; otherwise, store
722 // the value. Values below epsilon will be removed later.
723 if(oldval == 0)
725 else
727 }
728 }
729 }
730
731 // Clean up by shifting all nonzeros (w.r.t. epsilon) to the front of idx,
732 // zeroing all values which are nearly 0, and setting #num# appropriately.
733 int nz_counter = 0;
734
735 for(int i = 0; i < nonzero_idx; ++i)
736 {
737 curidx = idx[i];
738
739 if(isZero(VectorBase<R>::val[curidx], epsilon))
741 else
742 {
743 idx[nz_counter] = curidx;
744 ++nz_counter;
745 }
746
747 num = nz_counter;
748 }
749
751
752 return *this;
753}
754
755
756
757/// Assignment helper.
758template < class R >
759template < class S, class T >
760inline
762 const SSVectorBase<T>& x)
763{
764 assert(x.isSetup());
765
766 if(x.size() == 0) // x can be setup but have size 0 => this := zero vector
767 {
768 clear();
769 return *this;
770 }
771
772 bool A_is_zero = true;
773 int xsize = x.size();
774 int Aisize;
775
776 for(int i = 0; i < xsize; ++i)
777 {
778 const int curidx = x.idx[i];
779 const T xi = x.val[curidx];
780 const SVectorBase<S>& Ai = A[curidx];
781 Aisize = Ai.size();
783 if(A_is_zero && Aisize > 0)
784 A_is_zero = false;
785
786 for(int j = 0; j < Aisize; ++j)
787 {
788 const Nonzero<S>& elt = Ai.element(j);
789 VectorBase<R>::val[elt.idx] += xi * elt.val;
790 }
791 }
792
793 if(A_is_zero)
794 clear(); // case x != 0 but A == 0
795
796 return *this;
797}
798
799
800
801/// Assigns SSVectorBase to \f$A \cdot x\f$ thereby setting up \p x.
802template < class R >
803template < class S, class T >
804inline
806{
807 assert(!x.isSetup());
808
809 if(x.dim() == 0)
810 {
811 // x == 0 => this := zero vector
812 clear();
813 x.num = 0;
814 }
815 else
816 {
817 // x is not setup, so walk through its value vector
818 int nzcount = 0;
819 int end = x.dim();
820
821 for(int i = 0; i < end; ++i)
822 {
823 // advance to the next element != 0
824 T& xval = x.val[i];
825
826 if(xval != 0)
827 {
828 // If x[i] is really nonzero, compute A[i] * x[i] and adapt x.idx,
829 // otherwise set x[i] to 0.
830 if(isNotZero(xval, epsilon))
831 {
832 const SVectorBase<S>& Ai = A[i];
833 x.idx[ nzcount++ ] = i;
834
835 for(int j = Ai.size() - 1; j >= 0; --j)
836 {
837 const Nonzero<S>& elt = Ai.element(j);
838 VectorBase<R>::val[elt.idx] += xval * elt.val;
839 }
840 }
841 else
842 xval = 0;
843 }
844 }
845
846 x.num = nzcount;
847 setupStatus = false;
848 }
849
850 x.setupStatus = true;
851
853
854 return *this;
855}
856
857
858
859/// Assigns only the elements of \p rhs.
860template < class R >
861template < class S >
862inline
864{
865 assert(rhs.dim() <= VectorBase<R>::dim());
866
867 int s = rhs.size();
868 num = 0;
869
870 for(int i = 0; i < s; ++i)
871 {
872 int k = rhs.index(i);
873 S v = rhs.value(i);
874
875 if(isZero(v, epsilon))
877 else
880 idx[num++] = k;
881 }
882 }
883
884 setupStatus = true;
885
887
888 return *this;
889}
890
891
892
893/// Assigns only the elements of \p rhs.
894template < >
895template < >
896inline
898{
899 assert(rhs.dim() <= VectorBase<Rational>::dim());
900
901 int s = rhs.size();
902 num = 0;
903
904 for(int i = 0; i < s; ++i)
905 {
906 int k = rhs.index(i);
907 const Rational& v = rhs.value(i);
908
909 if(v == 0)
911 else
912 {
914 idx[num++] = k;
915 }
916 }
918 setupStatus = true;
919
921
922 return *this;
923}
924
925
926
927/// Assignment operator.
928template < class R >
929template < class S >
930inline
932{
933 clear();
934
935 return assign(rhs);
936}
937
938
939
940// ---------------------------------------------------------------------------------------------------------------------
941// Methods of SVectorBase
942// ---------------------------------------------------------------------------------------------------------------------
943
944
945
946/// Assignment operator.
947template < class R >
948template < class S >
949inline
951{
952 int n = 0;
953 Nonzero<R>* e = m_elem;
954
955 clear();
956
957 for(int i = vec.dim() - 1; i >= 0; --i)
958 {
959 if(vec[i] != 0)
960 {
961 assert(n < max());
962
963 e->idx = i;
964 e->val = vec[i];
965 ++e;
966 ++n;
967 }
968 }
969
970 set_size(n);
971
972 return *this;
973}
974
975
976
977/// Assignment operator (specialization for Real).
978template <>
979template < class S >
980inline
982{
983 int n = 0;
984 Nonzero<Real>* e = m_elem;
985
986 clear();
987
988 for(int i = vec.dim() - 1; i >= 0; --i)
989 {
990 if(vec[i] != 0)
991 {
992 assert(n < max());
993
994 e->idx = i;
995 e->val = Real(vec[i]);
996 ++e;
997 ++n;
998 }
999 }
1000
1001 set_size(n);
1002
1003 return *this;
1004}
1005
1006
1007
1008/// Assignment operator.
1009template < class R >
1010template < class S >
1011inline
1013{
1014 assert(sv.isSetup());
1015 assert(max() >= sv.size());
1016
1017 int nnz = 0;
1018 int idx;
1019
1020 Nonzero<R>* e = m_elem;
1021
1022 for(int i = 0; i < nnz; ++i)
1023 {
1024 idx = sv.index(i);
1025
1026 if(sv.value(idx) != 0.0)
1027 {
1028 e->idx = idx;
1029 e->val = sv[idx];
1030 ++e;
1031 ++nnz;
1032 }
1033 }
1034
1035 set_size(nnz);
1036
1037 return *this;
1038}
1039
1040
1041
1042/// Inner product.
1043template < class R >
1044inline
1046{
1048 Nonzero<R>* e = m_elem;
1049
1050 for(int i = size() - 1; i >= 0; --i)
1051 {
1052 x += e->val * w[e->idx];
1053 e++;
1054 }
1055
1056 return x;
1057}
1058
1059
1060
1061// ---------------------------------------------------------------------------------------------------------------------
1062// Methods of DSVectorBase
1063// ---------------------------------------------------------------------------------------------------------------------
1064
1065
1066
1067/// Copy constructor.
1068template < class R >
1069template < class S >
1070inline
1072 : theelem(0)
1073{
1074 allocMem((vec.dim() < 1) ? 2 : vec.dim());
1075 *this = vec;
1076
1078}
1079
1080
1081
1082/// Copy constructor.
1083template < class R >
1084template < class S >
1085inline
1087 : theelem(0)
1088{
1089 allocMem(old.size() < 1 ? 2 : old.size());
1091
1093}
1094
1095
1096
1097/// Assignment operator.
1098template < class R >
1099template < class S >
1100inline
1102{
1103 assert(this != (const DSVectorBase<R>*)(&vec));
1104
1106 setMax(vec.dim());
1108
1110
1111 return *this;
1112}
1113
1114
1115
1116/// Assignment operator.
1117template < class R >
1118template < class S >
1119inline
1121{
1122 assert(this != &vec);
1123
1125 makeMem(vec.size());
1127
1128 return *this;
1129}
1130
1131
1132
1133// ---------------------------------------------------------------------------------------------------------------------
1134// Operators
1135// ---------------------------------------------------------------------------------------------------------------------
1136
1137
1138
1139/// Output operator.
1140template < class R >
1141inline
1142std::ostream& operator<<(std::ostream& s, const VectorBase<R>& vec)
1143{
1144 int i;
1145
1146 s << '(';
1147
1148 for(i = 0; i < vec.dim() - 1; ++i)
1149 s << vec[i] << ", ";
1150
1151 s << vec[i] << ')';
1152
1153 return s;
1154}
1155
1156
1157
1158/// Subtraction.
1159template < class R >
1160inline
1162{
1163 VectorBase<R> res(w.dim());
1164
1165 for(int i = 0; i < res.dim(); ++i)
1166 res[i] = -w[i];
1167
1168 res += v;
1169
1170 return res;
1171}
1172
1173
1174
1175
1176/// Scaling.
1177template < class R >
1178inline
1180{
1182
1183 for(int i = 0; i < v.size(); ++i)
1184 res.add(v.index(i), v.value(i) * x);
1185
1186 return res;
1187}
1188
1189
1190
1191/// Scaling.
1192template < class R >
1193inline
1195{
1196 return v * x;
1197}
1198
1199
1200
1201template < class R >
1202inline
1203std::istream& operator>>(std::istream& s, VectorBase<R>& vec)
1204{
1205 char c;
1206 R val;
1207 int i = 0;
1208
1209 while(s.get(c).good())
1210 {
1211 if(c != ' ' && c != '\t' && c != '\n')
1212 break;
1213 }
1214
1215 if(c != '(')
1216 s.putback(c);
1217 else
1218 {
1219 do
1220 {
1221 s >> val;
1222
1223 if(i >= vec.dim() - 1)
1224 vec.reDim(i + 16);
1225
1226 vec[i++] = val;
1227
1228 while(s.get(c).good())
1229 {
1230 if(c != ' ' && c != '\t' && c != '\n')
1231 break;
1232 }
1233
1234 if(c != ',')
1235 {
1236 if(c != ')')
1237 s.putback(c);
1238
1239 break;
1240 }
1241 }
1242 while(s.good());
1243 }
1244
1245 vec.reDim(i);
1246
1247 return s;
1248}
1249
1250
1251
1252/// Output operator.
1253template < class R >
1254inline
1255std::ostream& operator<<(std::ostream& os, const SVectorBase<R>& v)
1256{
1257 for(int i = 0, j = 0; i < v.size(); ++i)
1258 {
1259 if(j)
1260 {
1261 if(v.value(i) < 0)
1262 os << " - " << -v.value(i);
1263 else
1264 os << " + " << v.value(i);
1265 }
1266 else
1267 os << v.value(i);
1268
1269 os << " x" << v.index(i);
1270 j = 1;
1271
1272 if((i + 1) % 4 == 0)
1273 os << "\n\t";
1274 }
1275
1276 return os;
1277}
1278
1279
1280
1281/// Output operator.
1282template < class R >
1283inline
1284std::ostream& operator<<(std::ostream& os, const SVSetBase<R>& s)
1285{
1286 for(int i = 0; i < s.num(); ++i)
1287 os << s[i] << "\n";
1288
1289 return os;
1290}
1291}
1292
1293/* reset the SOPLEX_DEBUG flag to its original value */
1294#undef SOPLEX_DEBUG
1295#ifdef SOPLEX_DEBUG_BASEVECTORS
1296#define SOPLEX_DEBUG
1297#undef SOPLEX_DEBUG_BASEVECTORS
1298#endif
1299
1300#endif // _BASEVECTORS_H_
#define SOPLEX_VECTOR_MARKER
Definition basevectors.h:47
#define shortProductFactor
Assigns SSVectorBase to for a setup x.
Dynamic sparse vectors.
bool isConsistent() const
Consistency check.
void allocMem(int n)
Allocate memory for n nonzeros.
Safe arrays of data objects.
Definition dataarray.h:75
bool isConsistent() const
consistency check
Definition dataarray.h:311
DataArray & operator=(const DataArray &rhs)
assignment operator
Definition dataarray.h:297
DataArray(const DataArray &old)
copy constructor
Definition dataarray.h:328
int max() const
return maximum number of elements.
Definition dataarray.h:256
void clear()
remove all elements.
Definition dataarray.h:221
int size() const
return nr. of elements.
Definition dataarray.h:227
void addIdx(int i)
appends index i.
Definition idxset.h:174
Semi sparse vector.
Sparse vectors.
SVectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
void clear()
Remove all indices.
Wrapper for the system time query methods.
Definition timer.h:86
Dense vector.
Definition vectorbase.h:86
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
Definition vectorbase.h:316
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
Definition vectorbase.h:338
std::vector< R > val
Values of vector.
Definition vectorbase.h:101
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition vectorbase.h:458
Dynamic sparse vectors.
Everything should be within this namespace.
std::istream & operator>>(std::istream &s, VectorBase< R > &vec)
VectorBase< R > operator-(const SVectorBase< R > &v, const VectorBase< R > &w)
Subtraction.
double Real
Definition spxdefines.h:266
DSVectorBase< R > operator*(const SVectorBase< R > &v, R x)
Scaling.
Debugging, floating point type and parameter definitions.
Semi sparse vector.
Sparse vectors.
Set of sparse vectors.
Timer class.
Dense vector.