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-2019 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 
94  assert(isConsistent());
95  }
96  /// assignment
98  {
99  if(this != &rhs)
100  {
101  themem = rhs.themem;
102 
103  assert(isConsistent());
104  }
105 
106  return *this;
107  }
108  /// destructor
110  {}
111  //@}
112 
113  //------------------------------------
114  /**@name Miscellaneous */
115  //@{
116  /// consistency check
117  bool isConsistent() const
118  {
119 #ifdef ENABLE_CONSISTENCY_CHECKS
120 
121  if(mem() != &themem)
122  return MSGinconsistent("UnitVectorBase");
123 
124  if(size() != 1)
125  return MSGinconsistent("UnitVectorBase");
126 
127  if(max() != 1)
128  return MSGinconsistent("UnitVectorBase");
129 
131 #else
132  return true;
133 #endif
134  }
135  //@}
136 };
137 
138 
139 } // namespace soplex
140 #endif // _UNITVECTORBASE_H_
Sparse vector nonzero element.
Definition: svectorbase.h:36
int size() const
Number of used indices.
Definition: svectorbase.h:153
Nonzero< R > * mem() const
get pointer to internal memory.
Definition: svectorbase.h:766
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:271
Debugging, floating point type and parameter definitions.
bool isConsistent() const
Consistency check.
Definition: svectorbase.h:803
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:160
Sparse vectors.
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
Definition: dvectorbase.h:31
#define MSGinconsistent(name)
Definition: spxdefines.h:126