Scippy

SoPlex

Sequential object-oriented simPlex

unitvectorbase.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-2024 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 unitvector.h
26 * @brief Sparse vector \f$e_i\f$.
27 */
28
29#ifndef _UNITVECTORBASE_H_
30#define _UNITVECTORBASE_H_
31
32#include <assert.h>
33#include "soplex/spxdefines.h"
34#include "soplex/svectorbase.h"
35
36namespace soplex
37{
38
39
40/**@brief Sparse vector \f$e_i\f$.
41 @ingroup Algebra
42
43 A UnitVectorBase is an SVectorBase that can take only one nonzero value with
44 value 1 but arbitrary index.
45
46 \todo Several SVectorBase modification methods are still accessible for UnitVector.
47 They might be used to change the vector.
48
49 \todo UnitVectorBase memory management must be changed when SVectorBase is redesigned.
50*/
51
52template < class R >
53class UnitVectorBase : public SVectorBase<R>
54{
55private:
56
57 //------------------------------------
58 /**@name Data */
59 ///@{
60 typename SVectorBase<R>::Element themem; ///< memory for sparse vector entry
61 ///@}
62
64
66
68
69public:
70
71 //------------------------------------
72 /**@name Access */
73 ///@{
74 /// returns value = 1
75 /**\pre \c n must be 0.
76 */
77 /* ARGSUSED n */
78 R value(int n) const
79 {
80 assert(n == 0);
81 return 1;
82 }
83 ///@}
84
85 //------------------------------------
86 /**@name Constructors / destructors */
87 ///@{
88 /// construct \c i 'th unit vector.
89 explicit
90 UnitVectorBase(int i = 0)
91 : SVectorBase<R>(1, &themem)
92 {
93 // coverity[callee_ptr_arith]
94 SVectorBase<R>::add(i, 1.0);
95
96 assert(isConsistent());
97 }
98 /// copy constructor
100 : SVectorBase<R>(1, &themem)
101 {
102 themem = rhs.themem;
103 this->set_size(1);
104
105 assert(isConsistent());
106 }
107 /// assignment
109 {
110 if(this != &rhs)
111 {
112 themem = rhs.themem;
113 this->set_size(1);
114
115 assert(isConsistent());
116 }
117
118 return *this;
119 }
120 /// move assignment
122 {
123 if(this != &rhs)
124 {
125 themem = std::move(rhs.themem);
126 this->set_size(1);
127
128 assert(isConsistent());
129 }
130
131 return *this;
132 }
133 /// destructor
135 {}
136 ///@}
137
138 //------------------------------------
139 /**@name Miscellaneous */
140 ///@{
141 /// consistency check
142 bool isConsistent() const
143 {
144#ifdef ENABLE_CONSISTENCY_CHECKS
145
146 if(mem() != &themem)
147 return SPX_MSG_INCONSISTENT("UnitVectorBase");
148
149 if(size() != 1)
150 return SPX_MSG_INCONSISTENT("UnitVectorBase");
151
152 if(max() != 1)
153 return SPX_MSG_INCONSISTENT("UnitVectorBase");
154
156#else
157 return true;
158#endif
159 }
160 ///@}
161};
162
163
164} // namespace soplex
165#endif // _UNITVECTORBASE_H_
Sparse vector nonzero element.
Definition: svectorbase.h:47
Sparse vectors.
Definition: svectorbase.h:140
bool isConsistent() const
Consistency check.
Definition: svectorbase.h:830
void add(int i, const R &v)
Append one nonzero (i,v).
Definition: svectorbase.h:282
int max() const
Maximal number of indices.
Definition: svectorbase.h:171
void set_size(int s)
Set size of the vector.
Definition: svectorbase.h:799
Nonzero< R > * mem() const
get pointer to internal memory.
Definition: svectorbase.h:793
int size() const
Number of used indices.
Definition: svectorbase.h:164
UnitVectorBase< R > & operator=(const UnitVectorBase< R > &rhs)
assignment
SVectorBase< R >::Element themem
memory for sparse vector entry
UnitVectorBase(int i=0)
construct i 'th unit vector.
bool isConsistent() const
consistency check
R value(int n) const
returns value = 1
UnitVectorBase(const UnitVectorBase< R > &rhs)
copy constructor
UnitVectorBase< R > & operator=(UnitVectorBase< R > &&rhs)
move assignment
Everything should be within this namespace.
Debugging, floating point type and parameter definitions.
#define SPX_MSG_INCONSISTENT(name)
Definition: spxdefines.h:175
Sparse vectors.