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