SoPlex Documentation
Loading...
Searching...
No Matches
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-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 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
63 using SVectorBase<R>::mem;
64
65 using SVectorBase<R>::size;
66
67 using SVectorBase<R>::max;
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<R>(int i = 0)
91 : SVectorBase<R>(1, &themem)
92 {
93 // coverity[callee_ptr_arith]
95
97 }
98 /// copy constructor
99 UnitVectorBase<R>(const UnitVectorBase<R>& rhs)
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
116 }
117
118 return *this;
119 }
120 /// destructor
122 {}
123 ///@}
124
125 //------------------------------------
126 /**@name Miscellaneous */
127 ///@{
128 /// consistency check
129 bool isConsistent() const
130 {
131#ifdef ENABLE_CONSISTENCY_CHECKS
132
133 if(mem() != &themem)
134 return MSGinconsistent("UnitVectorBase");
135
136 if(size() != 1)
137 return MSGinconsistent("UnitVectorBase");
138
139 if(max() != 1)
140 return MSGinconsistent("UnitVectorBase");
141
143#else
144 return true;
145#endif
146 }
147 ///@}
148};
149
150
151} // namespace soplex
152#endif // _UNITVECTORBASE_H_
Safe arrays of data objects.
Definition dataarray.h:75
Sparse vectors.
bool isConsistent() const
Consistency check.
friend class SVectorBase
void add(int i, const R &v)
Append one nonzero (i,v).
int max() const
Maximal number of indices.
void set_size(int s)
Set size of the vector.
Nonzero< R > * mem() const
get pointer to internal memory.
int size() const
Number of used indices.
UnitVectorBase< R > & operator=(const UnitVectorBase< R > &rhs)
assignment
SVectorBase< R >::Element themem
memory for sparse vector entry
bool isConsistent() const
consistency check
R value(int n) const
returns value = 1
Everything should be within this namespace.
Debugging, floating point type and parameter definitions.
#define MSGinconsistent(name)
Definition spxdefines.h:174
Sparse vectors.