1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2022 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 /**@file unitvector.h
17 * @brief Sparse vector \f$e_i\f$.
18 */
19
20 #ifndef _UNITVECTORBASE_H_
21 #define _UNITVECTORBASE_H_
22
23 #include <assert.h>
24 #include "soplex/spxdefines.h"
25 #include "soplex/svectorbase.h"
26
27 namespace soplex
28 {
29
30
31 /**@brief Sparse vector \f$e_i\f$.
32 @ingroup Algebra
33
34 A UnitVectorBase is an SVectorBase that can take only one nonzero value with
35 value 1 but arbitrary index.
36
37 \todo Several SVectorBase modification methods are still accessible for UnitVector.
38 They might be used to change the vector.
39
40 \todo UnitVectorBase memory management must be changed when SVectorBase is redesigned.
41 */
42
43 template < class R >
(1) Event missing_move_assignment: |
Class "soplex::UnitVectorBase<double>" may benefit from adding a move assignment operator. See other events which show the copy assignment operator being applied to rvalues, where a move assignment may be faster. |
Also see events: |
[copy_assignment] |
44 class UnitVectorBase : public SVectorBase<R>
45 {
46 private:
47
48 //------------------------------------
49 /**@name Data */
50 ///@{
51 typename SVectorBase<R>::Element themem; ///< memory for sparse vector entry
52 ///@}
53
54 using SVectorBase<R>::mem;
55
56 using SVectorBase<R>::size;
57
58 using SVectorBase<R>::max;
59
60 public:
61
62 //------------------------------------
63 /**@name Access */
64 ///@{
65 /// returns value = 1
66 /**\pre \c n must be 0.
67 */
68 /* ARGSUSED n */
69 R value(int n) const
70 {
71 assert(n == 0);
72 return 1;
73 }
74 ///@}
75
76 //------------------------------------
77 /**@name Constructors / destructors */
78 ///@{
79 /// construct \c i 'th unit vector.
80 explicit
81 UnitVectorBase<R>(int i = 0)
82 : SVectorBase<R>(1, &themem)
83 {
84 SVectorBase<R>::add(i, 1.0);
85
86 assert(isConsistent());
87 }
88 /// copy constructor
89 UnitVectorBase<R>(const UnitVectorBase<R>& rhs)
90 : SVectorBase<R>(1, &themem)
91 {
92 themem = rhs.themem;
93 this->set_size(1);
94
95 assert(isConsistent());
96 }
97 /// assignment
98 UnitVectorBase<R>& operator=(const UnitVectorBase<R>& rhs)
99 {
100 if(this != &rhs)
101 {
102 themem = rhs.themem;
103 this->set_size(1);
104
105 assert(isConsistent());
106 }
107
108 return *this;
109 }
110 /// destructor
111 ~UnitVectorBase<R>()
112 {}
113 ///@}
114
115 //------------------------------------
116 /**@name Miscellaneous */
117 ///@{
118 /// consistency check
119 bool isConsistent() const
120 {
121 #ifdef ENABLE_CONSISTENCY_CHECKS
122
123 if(mem() != &themem)
124 return MSGinconsistent("UnitVectorBase");
125
126 if(size() != 1)
127 return MSGinconsistent("UnitVectorBase");
128
129 if(max() != 1)
130 return MSGinconsistent("UnitVectorBase");
131
132 return SVectorBase<R>::isConsistent();
133 #else
134 return true;
135 #endif
136 }
137 ///@}
138 };
139
140
141 } // namespace soplex
142 #endif // _UNITVECTORBASE_H_
143