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-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 >
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 
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
90  : SVectorBase<R>(1, &themem)
91  {
92  themem = rhs.themem;
93  this->set_size(1);
94 
95  assert(isConsistent());
96  }
97  /// assignment
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
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 
133 #else
134  return true;
135 #endif
136  }
137  ///@}
138 };
139 
140 
141 } // namespace soplex
142 #endif // _UNITVECTORBASE_H_
Sparse vector nonzero element.
Definition: svectorbase.h:37
int size() const
Number of used indices.
Definition: svectorbase.h:155
void set_size(int s)
Set size of the vector.
Definition: svectorbase.h:790
Nonzero< R > * mem() const
get pointer to internal memory.
Definition: svectorbase.h:784
bool isConsistent() const
consistency check
UnitVectorBase< R > & operator=(const UnitVectorBase< R > &rhs)
assignment
R value(int n) const
returns value = 1
Sparse vector .A UnitVectorBase is an SVectorBase that can take only one nonzero value with value 1 b...
void add(int i, const R &v)
Append one nonzero (i,v).
Definition: svectorbase.h:273
Debugging, floating point type and parameter definitions.
bool isConsistent() const
Consistency check.
Definition: svectorbase.h:821
SVectorBase< R >::Element themem
memory for sparse vector entry
Everything should be within this namespace.
int max() const
Maximal number of indices.
Definition: svectorbase.h:162
Sparse vectors.
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
Definition: ssvectorbase.h:34
#define MSGinconsistent(name)
Definition: spxdefines.h:164