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-2017 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 "spxdefines.h"
25 #include "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  return *this;
106  }
107  /// destructor
109  {}
110  //@}
111 
112  //------------------------------------
113  /**@name Miscellaneous */
114  //@{
115  /// consistency check
116  bool isConsistent() const
117  {
118 #ifdef ENABLE_CONSISTENCY_CHECKS
119  if (mem() != &themem)
120  return MSGinconsistent("UnitVectorBase");
121  if (size() != 1)
122  return MSGinconsistent("UnitVectorBase");
123  if (max() != 1)
124  return MSGinconsistent("UnitVectorBase");
125 
127 #else
128  return true;
129 #endif
130  }
131  //@}
132 };
133 
134 
135 } // namespace soplex
136 #endif // _UNITVECTORBASE_H_
Sparse vector nonzero element.
Definition: svectorbase.h:35
int size() const
Number of used indices.
Definition: svectorbase.h:152
Nonzero< R > * mem() const
get pointer to internal memory.
Definition: svectorbase.h:704
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:272
Debugging, floating point type and parameter definitions.
bool isConsistent() const
Consistency check.
Definition: svectorbase.h:741
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:159
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:123