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-2024 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file updatevector.h
26 * @brief Dense VectorBase<R> with semi-sparse VectorBase<R> for updates
27 */
28
29#ifndef _UPDATEVECTOR_H_
30#define _UPDATEVECTOR_H_
31
32#include <assert.h>
33
34
35#include "soplex/spxdefines.h"
36#include "soplex/ssvector.h"
37
38namespace soplex
39{
40
41/**@brief Dense Vector with semi-sparse Vector for updates
42 @ingroup Algebra
43
44 In many algorithms vectors are updated in every iteration, by
45 adding a multiple of another VectorBase<R> to it, i.e., given a VectorBase<R> \c
46 x, a scalar \f$\alpha\f$ and another VectorBase<R> \f$\delta\f$, the
47 update to \c x constists of substituting it by \f$x \leftarrow x +
48 \alpha\cdot\delta\f$.
49
50 While the update itself can easily be expressed with methods of
51 the class VectorBase<R>, it is often desirable to save the last update
52 VectorBase<R> \f$\delta\f$ and value \f$\alpha\f$. This is provided by
53 class UpdateVector<R>.
54
55 UpdateVectors are derived from VectorBase<R> and provide additional
56 methods for saving and setting the multiplicator \f$\alpha\f$ and
57 the update Vector \f$\delta\f$. Further, it allows for efficient
58 sparse updates, by providing an IdxSet idx() containing the
59 nonzero indices of \f$\delta\f$.
60*/
61template <class R>
62class UpdateVector : public VectorBase<R>
63{
64private:
65
66 //------------------------------------
67 /**@name Data */
68 ///@{
69 R theval; ///< update multiplicator
70 SSVectorBase<R> thedelta; ///< update vector
71 ///@}
72
73public:
74
75 //------------------------------------
76 /**@name Constructors / destructors */
77 ///@{
78 /// default constructor.
79 explicit
80 UpdateVector(int p_dim /*=0*/, std::shared_ptr<Tolerances> tols = nullptr)
81 : VectorBase<R> (p_dim)
82 , theval(0)
83 , thedelta(p_dim, tols)
84 {
85 assert(isConsistent());
86 }
87 ///
89 {}
90 /// copy constructor
92 /// assignment from VectorBase<R>
94 {
95 if(this != & rhs)
97
98 assert(isConsistent());
99
100 return *this;
101 }
102
103 /// assignment
105 ///@}
106
107 //------------------------------------
108 /**@name Access */
109 ///@{
110 /// update multiplicator \f$\alpha\f$, writeable
111 R& value()
112 {
113 return theval;
114 }
115 /// update multiplicator \f$\alpha\f$
116 R value() const
117 {
118 return theval;
119 }
120
121 /// update VectorBase<R> \f$\delta\f$, writeable
123 {
124 return thedelta;
125 }
126 /// update VectorBase<R> \f$\delta\f$
127 const SSVectorBase<R>& delta() const
128 {
129 return thedelta;
130 }
131
132 /// nonzero indices of update VectorBase<R> \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<R>. 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 this->multAdd(theval, thedelta);
150 }
151
152 /// clear VectorBase<R> and update vector
153 void clear()
154 {
156 clearUpdate();
157 }
158
159 /// clear \f$\delta\f$, \f$\alpha\f$
161 {
162 thedelta.clear();
163 theval = 0;
164 }
165
166 /// reset dimension
167 void reDim(int newdim)
168 {
169 VectorBase<R>::reDim(newdim);
170 thedelta.reDim(newdim);
171 }
172
173 /// set tolerances
174 void setTolerances(std::shared_ptr<Tolerances>& tolerances)
175 {
176 thedelta.setTolerances(tolerances);
177 }
178 ///@}
179
180 //------------------------------------
181 /**@name Consistency check */
182 ///@{
183 ///
184 bool isConsistent() const;
185 ///@}
186};
187
188
189} // namespace soplex
190
191// General templated functions
192#include "soplex/updatevector.hpp"
193
194#endif // _UPDATEVECTOR_H_
Set of indices.
Definition: idxset.h:66
Semi sparse vector.
Definition: ssvectorbase.h:57
Dense Vector with semi-sparse Vector for updates.
Definition: updatevector.h:63
R theval
update multiplicator
Definition: updatevector.h:69
UpdateVector(const UpdateVector< R > &)
copy constructor
const IdxSet & idx() const
nonzero indices of update VectorBase<R>
Definition: updatevector.h:133
bool isConsistent() const
SSVectorBase< R > thedelta
update vector
Definition: updatevector.h:70
SSVectorBase< R > & delta()
update VectorBase<R> , writeable
Definition: updatevector.h:122
UpdateVector(int p_dim, std::shared_ptr< Tolerances > tols=nullptr)
default constructor.
Definition: updatevector.h:80
UpdateVector< R > & operator=(const VectorBase< R > &rhs)
assignment from VectorBase<R>
Definition: updatevector.h:93
R value() const
update multiplicator
Definition: updatevector.h:116
void setTolerances(std::shared_ptr< Tolerances > &tolerances)
set tolerances
Definition: updatevector.h:174
void update()
Perform the update.
Definition: updatevector.h:147
void clear()
clear VectorBase<R> and update vector
Definition: updatevector.h:153
void reDim(int newdim)
reset dimension
Definition: updatevector.h:167
const SSVectorBase< R > & delta() const
update VectorBase<R>
Definition: updatevector.h:127
UpdateVector< R > & operator=(const UpdateVector< R > &rhs)
assignment
R & value()
update multiplicator , writeable
Definition: updatevector.h:111
void clearUpdate()
clear ,
Definition: updatevector.h:160
Dense vector.
Definition: vectorbase.h:86
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
Definition: vectorbase.h:157
void reDim(int newdim, const bool setZero=true)
Resets VectorBase's dimension to newdim.
Definition: vectorbase.h:541
void clear()
Set vector to contain all-zeros (keeping the same length)
Definition: vectorbase.h:308
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition: vectorbase.h:458
Everything should be within this namespace.
Debugging, floating point type and parameter definitions.
Semi sparse vector.