Scippy

SoPlex

Sequential object-oriented simPlex

updatevector.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 updatevector.h
17  * @brief Dense VectorBase<R> with semi-sparse VectorBase<R> for updates
18  */
19 
20 #ifndef _UPDATEVECTOR_H_
21 #define _UPDATEVECTOR_H_
22 
23 #include <assert.h>
24 
25 
26 #include "soplex/spxdefines.h"
27 #include "soplex/ssvector.h"
28 
29 namespace soplex
30 {
31 
32 /**@brief Dense Vector with semi-sparse Vector for updates
33  @ingroup Algebra
34 
35  In many algorithms vectors are updated in every iteration, by
36  adding a multiple of another VectorBase<R> to it, i.e., given a VectorBase<R> \c
37  x, a scalar \f$\alpha\f$ and another VectorBase<R> \f$\delta\f$, the
38  update to \c x constists of substituting it by \f$x \leftarrow x +
39  \alpha\cdot\delta\f$.
40 
41  While the update itself can easily be expressed with methods of
42  the class VectorBase<R>, it is often desirable to save the last update
43  VectorBase<R> \f$\delta\f$ and value \f$\alpha\f$. This is provided by
44  class UpdateVector<R>.
45 
46  UpdateVectors are derived from VectorBase<R> and provide additional
47  methods for saving and setting the multiplicator \f$\alpha\f$ and
48  the update Vector \f$\delta\f$. Further, it allows for efficient
49  sparse updates, by providing an IdxSet idx() containing the
50  nonzero indices of \f$\delta\f$.
51 */
52 template <class R>
53 class UpdateVector : public VectorBase<R>
54 {
55 private:
56 
57  //------------------------------------
58  /**@name Data */
59  ///@{
60  R theval; ///< update multiplicator
61  SSVectorBase<R> thedelta; ///< update vector
62  ///@}
63 
64 public:
65 
66  //------------------------------------
67  /**@name Constructors / destructors */
68  ///@{
69  /// default constructor.
70  explicit
71  UpdateVector<R>(int p_dim /*=0*/, R p_eps /*=1e-16*/)
72  : VectorBase<R> (p_dim)
73  , theval(0)
74  , thedelta(p_dim, p_eps)
75  {
76  assert(isConsistent());
77  }
78  ///
80  {}
81  /// copy constructor
83  /// assignment from VectorBase<R>
85  {
86  if(this != & rhs)
88 
89  assert(isConsistent());
90 
91  return *this;
92  }
93 
94  /// assignment
96  ///@}
97 
98  //------------------------------------
99  /**@name Access */
100  ///@{
101  /// update multiplicator \f$\alpha\f$, writeable
102  R& value()
103  {
104  return theval;
105  }
106  /// update multiplicator \f$\alpha\f$
107  R value() const
108  {
109  return theval;
110  }
111 
112  /// update VectorBase<R> \f$\delta\f$, writeable
114  {
115  return thedelta;
116  }
117  /// update VectorBase<R> \f$\delta\f$
118  const SSVectorBase<R>& delta() const
119  {
120  return thedelta;
121  }
122 
123  /// nonzero indices of update VectorBase<R> \f$\delta\f$
124  const IdxSet& idx() const
125  {
126  return thedelta.indices();
127  }
128  ///@}
129 
130  //------------------------------------
131  /**@name Modification */
132  ///@{
133  /// Perform the update
134  /** Add \c value() * \c delta() to the UpdateVector<R>. Only the indices
135  * in idx() are affected. For all other indices, delta() is asumed
136  * to be 0.
137  */
138  void update()
139  {
140  this->multAdd(theval, thedelta);
141  }
142 
143  /// clear VectorBase<R> and update vector
144  void clear()
145  {
147  clearUpdate();
148  }
149 
150  /// clear \f$\delta\f$, \f$\alpha\f$
151  void clearUpdate()
152  {
153  thedelta.clear();
154  theval = 0;
155  }
156 
157  /// reset dimension
158  void reDim(int newdim)
159  {
160  VectorBase<R>::reDim(newdim);
161  thedelta.reDim(newdim);
162  }
163  ///@}
164 
165  //------------------------------------
166  /**@name Consistency check */
167  ///@{
168  ///
169  bool isConsistent() const;
170  ///@}
171 };
172 
173 
174 } // namespace soplex
175 
176 // General templated functions
177 #include "soplex/updatevector.hpp"
178 
179 #endif // _UPDATEVECTOR_H_
void clearUpdate()
clear ,
Definition: updatevector.h:151
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
Definition: vectorbase.h:149
Dense vector.Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std...
Definition: dsvectorbase.h:28
void clear()
clear VectorBase<R> and update vector
Definition: updatevector.h:144
R value() const
update multiplicator
Definition: updatevector.h:107
void reDim(int newdim)
reset dimension
Definition: updatevector.h:158
Semi sparse vector.This class implements semi-sparse vectors. Such are VectorBases where the indices ...
Definition: dsvectorbase.h:29
SSVectorBase< R > & delta()
update VectorBase<R> , writeable
Definition: updatevector.h:113
R & value()
update multiplicator , writeable
Definition: updatevector.h:102
void update()
Perform the update.
Definition: updatevector.h:138
const IdxSet & indices() const
Returns indices.
Definition: ssvectorbase.h:306
Semi sparse vector.
void clear()
Clears vector.
Definition: ssvectorbase.h:604
Dense Vector with semi-sparse Vector for updatesIn many algorithms vectors are updated in every itera...
Definition: updatevector.h:53
void reDim(int newdim)
Resets dimension to newdim.
Definition: ssvectorbase.h:570
Debugging, floating point type and parameter definitions.
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition: vectorbase.h:450
Everything should be within this namespace.
const IdxSet & idx() const
nonzero indices of update VectorBase<R>
Definition: updatevector.h:124
const SSVectorBase< R > & delta() const
update VectorBase<R>
Definition: updatevector.h:118
void reDim(int newdim, const bool setZero=true)
Resets VectorBase&#39;s dimension to newdim.
Definition: vectorbase.h:533
void clear()
Set vector to contain all-zeros (keeping the same length)
Definition: vectorbase.h:300
bool isConsistent() const
R theval
update multiplicator
Definition: updatevector.h:60
SSVectorBase< R > thedelta
update vector
Definition: updatevector.h:61
UpdateVector< R > & operator=(const VectorBase< R > &rhs)
assignment from VectorBase<R>
Definition: updatevector.h:84
Set of indices.Class IdxSet provides a set of indices. At construction it must be given an array of i...
Definition: idxset.h:56