SoPlex
Toggle main menu visibility
Loading...
Searching...
No Matches
src
soplex
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-2026 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
38
namespace
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
*/
61
template
<
class
R>
62
class
UpdateVector
:
public
VectorBase
<R>
63
{
64
private
:
65
66
//------------------------------------
67
/**@name Data */
68
///@{
69
R
theval
;
///< update multiplicator
70
SSVectorBase<R>
thedelta
;
///< update vector
71
///@}
72
73
public
:
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
///
88
~UpdateVector
()
89
{}
90
/// copy constructor
91
UpdateVector
(
const
UpdateVector<R>
&);
92
/// assignment from VectorBase<R>
93
UpdateVector<R>
&
operator=
(
const
VectorBase<R>
& rhs)
94
{
95
if
(
this
!= & rhs)
96
VectorBase<R>::operator=
(rhs);
97
98
assert(
isConsistent
());
99
100
return
*
this
;
101
}
102
103
/// assignment
104
UpdateVector<R>
&
operator=
(
const
UpdateVector<R>
& rhs);
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
122
SSVectorBase<R>
&
delta
()
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
{
155
VectorBase<R>::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
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_
soplex::IdxSet
Set of indices.
Definition
idxset.h:66
soplex::SSVectorBase
Semi sparse vector.
Definition
ssvectorbase.h:57
soplex::UpdateVector::theval
R theval
update multiplicator
Definition
updatevector.h:69
soplex::UpdateVector::UpdateVector
UpdateVector(const UpdateVector< R > &)
copy constructor
soplex::UpdateVector::idx
const IdxSet & idx() const
nonzero indices of update VectorBase<R>
Definition
updatevector.h:133
soplex::UpdateVector::isConsistent
bool isConsistent() const
soplex::UpdateVector::thedelta
SSVectorBase< R > thedelta
update vector
Definition
updatevector.h:70
soplex::UpdateVector::delta
SSVectorBase< R > & delta()
update VectorBase<R> , writeable
Definition
updatevector.h:122
soplex::UpdateVector::UpdateVector
UpdateVector(int p_dim, std::shared_ptr< Tolerances > tols=nullptr)
default constructor.
Definition
updatevector.h:80
soplex::UpdateVector::~UpdateVector
~UpdateVector()
Definition
updatevector.h:88
soplex::UpdateVector::operator=
UpdateVector< R > & operator=(const VectorBase< R > &rhs)
assignment from VectorBase<R>
Definition
updatevector.h:93
soplex::UpdateVector::value
R value() const
update multiplicator
Definition
updatevector.h:116
soplex::UpdateVector::setTolerances
void setTolerances(std::shared_ptr< Tolerances > &tolerances)
set tolerances
Definition
updatevector.h:174
soplex::UpdateVector::update
void update()
Perform the update.
Definition
updatevector.h:147
soplex::UpdateVector::clear
void clear()
clear VectorBase<R> and update vector
Definition
updatevector.h:153
soplex::UpdateVector::reDim
void reDim(int newdim)
reset dimension
Definition
updatevector.h:167
soplex::UpdateVector::delta
const SSVectorBase< R > & delta() const
update VectorBase<R>
Definition
updatevector.h:127
soplex::UpdateVector::operator=
UpdateVector< R > & operator=(const UpdateVector< R > &rhs)
assignment
soplex::UpdateVector::value
R & value()
update multiplicator , writeable
Definition
updatevector.h:111
soplex::UpdateVector::clearUpdate
void clearUpdate()
clear ,
Definition
updatevector.h:160
soplex::VectorBase::operator=
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
Definition
vectorbase.h:157
soplex::VectorBase::VectorBase
friend class VectorBase
Definition
vectorbase.h:91
soplex::VectorBase::reDim
void reDim(int newdim, const bool setZero=true)
Resets VectorBase's dimension to newdim.
Definition
vectorbase.h:541
soplex::VectorBase::clear
void clear()
Set vector to contain all-zeros (keeping the same length).
Definition
vectorbase.h:308
soplex::VectorBase::multAdd
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition
vectorbase.h:458
soplex
Everything should be within this namespace.
spxdefines.h
Debugging, floating point type and parameter definitions.
ssvector.h
Semi sparse vector.
Generated by
1.17.0