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-2015 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 public:
55 
56  //------------------------------------
57  /**@name Access */
58  //@{
59  /// returns value = 1
60  /**\pre \c n must be 0.
61  */
62  /* ARGSUSED n */
63  R value(int n) const
64  {
65  assert( n == 0 );
66  return 1;
67  }
68  //@}
69 
70  //------------------------------------
71  /**@name Constructors / destructors */
72  //@{
73  /// construct \c i 'th unit vector.
74  explicit
75  UnitVectorBase<R>(int i = 0)
76  : SVectorBase<R>(1, &themem)
77  {
78  SVectorBase<R>::add(i, 1.0);
79 
80  assert(isConsistent());
81  }
82  /// copy constructor
84  : SVectorBase<R>(1, &themem)
85  {
86  themem = rhs.themem;
87 
88  assert(isConsistent());
89  }
90  /// assignment
92  {
93  if ( this != &rhs )
94  {
95  themem = rhs.themem;
96 
97  assert(isConsistent());
98  }
99  return *this;
100  }
101  /// destructor
103  {}
104  //@}
105 
106  //------------------------------------
107  /**@name Miscellaneous */
108  //@{
109  /// consistency check
110  bool isConsistent() const
111  {
112 #ifdef ENABLE_CONSISTENCY_CHECKS
113  if (mem() != &themem)
114  return MSGinconsistent("UnitVectorBase");
115  if (size() != 1)
116  return MSGinconsistent("UnitVectorBase");
117  if (max() != 1)
118  return MSGinconsistent("UnitVectorBase");
119 
121 #else
122  return true;
123 #endif
124  }
125  //@}
126 };
127 
128 
129 } // namespace soplex
130 #endif // _UNITVECTORBASE_H_