Scippy

SoPlex

Sequential object-oriented simPlex

slufactor.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 slufactor.h
26 * @brief Implementation of Sparse Linear Solver.
27 */
28#ifndef _SLUFACTOR_H_
29#define _SLUFACTOR_H_
30
31#include <assert.h>
32
33#include "soplex/spxdefines.h"
34#include "soplex/timerfactory.h"
35#include "soplex/slinsolver.h"
36#include "soplex/clufactor.h"
37
38namespace soplex
39{
40/// maximum nr. of factorization updates allowed before refactorization.
41#define SOPLEX_MAXUPDATES 1000
42
43/**@brief Implementation of Sparse Linear Solver.
44 * @ingroup Algo
45 *
46 * This class implements a SLinSolver interface by using the sparse LU
47 * factorization implemented in CLUFactor.
48 */
49template <class R>
50class SLUFactor : public SLinSolver<R>, protected CLUFactor<R>
51{
52public:
53
54 //--------------------------------
55 /**@name Types */
56 ///@{
57 /// Specifies how to perform \ref soplex::SLUFactor<R>::change "change" method.
59 {
60 ETA = 0, ///<
61 FOREST_TOMLIN ///<
62 };
63 /// for convenience
64 using Status = typename SLinSolver<R>::Status;
65 ///@}
66
67private:
68
69 //--------------------------------
70 /**@name Private data */
71 ///@{
72 VectorBase<R> vec; ///< Temporary VectorBase<R>
73 SSVectorBase<R> ssvec; ///< Temporary semi-sparse VectorBase<R>
74 ///@}
75
76protected:
77
78 //--------------------------------
79 /**@name Protected data */
80 ///@{
81 bool usetup; ///< TRUE iff update vector has been setup
82 UpdateType uptype; ///< the current \ref soplex::SLUFactor<R>::UpdateType "UpdateType".
85 forest; ///< ? Update VectorBase<R> set up by solveRight4update() and solve2right4update()
86 R lastThreshold; ///< pivoting threshold of last factorization
87 ///@}
88
89 //--------------------------------
90 /**@name Control Parameters */
91 ///@{
92 /// minimum threshold to use.
94 /// minimum stability to achieve by setting threshold.
96 /// Time spent in solves
99 /// Number of solves
101 ///@}
102
103protected:
104
105 //--------------------------------
106 /**@name Protected helpers */
107 ///@{
108 ///
109 void freeAll();
110 ///
112 ///@}
113
114
115public:
116
117 //--------------------------------
118 /**@name Update type */
119 ///@{
120 /// returns the current update type uptype.
122 {
123 return uptype;
124 }
125
126 /// sets update type.
127 /** The new UpdateType becomes valid only after the next call to
128 method load().
129 */
131 {
132 uptype = tp;
133 }
134
135 /// sets minimum Markowitz threshold.
136 void setMarkowitz(R m)
137 {
138 if(m < 0.0001)
139 m = 0.0001;
140
141 if(m > 0.9999)
142 m = 0.9999;
143
144 minThreshold = m;
145 lastThreshold = m;
146 }
147
148 /// returns Markowitz threshold.
150 {
151 return lastThreshold;
152 }
153 ///@}
154
155 //--------------------------------
156 /**@name Derived from SLinSolver
157 See documentation of \ref soplex::SLinSolver "SLinSolver" for a
158 documentation of these methods.
159 */
160 ///@{
161 ///
162 void clear();
163 ///
164 int dim() const
165 {
166 return this->thedim;
167 }
168 ///
169 int memory() const
170 {
171 return this->nzCnt + this->l.start[this->l.firstUnused];
172 }
173 ///
174 const char* getName() const
175 {
176 return (uptype == SLUFactor<R>::ETA) ? "SLU-Eta" : "SLU-Forest-Tomlin";
177 }
178 ///
180 {
181 return Status(this->stat);
182 }
183 ///
184 R stability() const;
185 /** return one of several matrix metrics based on the diagonal of U
186 * 0: condition number estimate by ratio of min/max
187 * 1: trace (sum of diagonal elements)
188 * 2: determinant (product of diagonal elements)
189 */
190 R matrixMetric(int type = 0) const;
191 ///
192 std::string statistics() const;
193 ///
195 ///@}
196
197public:
198
199 //--------------------------------
200 /**@name Solve */
201 ///@{
202 /// Solves \f$Ax=b\f$.
205 {
206 x.unSetup();
207 solveRight((VectorBase<R>&) x, (const VectorBase<R>&) b);
208 }
209 /// Solves \f$Ax=b\f$.
211 /// Solves \f$Ax=b\f$.
213 /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
215 SSVectorBase<R>& d);
216 /// Sparse version of solving two systems of equations
218 SSVectorBase<R>& d);
219 /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
222 /// sparse version of solving three systems of equations
225 /// sparse version of solving one system of equations with transposed basis matrix
228 {
229 x.unSetup();
230 solveLeft((VectorBase<R>&) x, (const VectorBase<R>&) b);
231 }
232 /// Solves \f$Ax=b\f$.
234 /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
236 /// sparse version of solving two systems of equations with transposed basis matrix
238 SSVectorBase<R>& rhs2);
239 /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
242 /// sparse version of solving three systems of equations with transposed basis matrix
245 ///
246 Status change(int idx, const SVectorBase<R>& subst, const SSVectorBase<R>* eta = 0);
247 ///@}
248
249 //--------------------------------
250 /**@name Miscellaneous */
251 ///@{
252 /// time spent in factorizations
253 // @todo fix the return type from of the type form Real to a cpp time (Refactoring) TODO
255 {
256 return this->factorTime->time();
257 }
258 /// reset FactorTime
260 {
261 this->factorTime->reset();
262 }
263 /// number of factorizations performed
264 int getFactorCount() const
265 {
266 return this->factorCount;
267 }
268 /// time spent in solves
269 // @todo fix the return type of time to a cpp time type TODO
271 {
272 return solveTime->time();
273 }
274 /// reset SolveTime
276 {
277 solveTime->reset();
278 }
279 /// number of solves performed
280 int getSolveCount() const
281 {
282 return solveCount;
283 }
284 /// reset timers and counters
286 {
287 this->factorTime->reset();
288 solveTime->reset();
289 this->factorCount = 0;
290 this->hugeValues = 0;
291 solveCount = 0;
292 }
293 void changeTimer(const Timer::TYPE ttype)
294 {
296 this->factorTime = TimerFactory::switchTimer(this->factorTime, ttype);
297 timerType = ttype;
298 }
299 /// prints the LU factorization to stdout.
300 void dump() const;
301
302 /// consistency check.
303 bool isConsistent() const;
304
305 /// set tolerances
306 virtual void setTolerances(std::shared_ptr<Tolerances> tolerances)
307 {
308 this->_tolerances = tolerances;
309 this->eta.setTolerances(tolerances);
310 this->forest.setTolerances(tolerances);
311 this->ssvec.setTolerances(tolerances);
312 }
313
314 ///@}
315
316 //------------------------------------
317 /**@name Constructors / Destructors */
318 ///@{
319 /// default constructor.
321 /// assignment operator.
323 /// copy constructor.
325 /// destructor.
326 virtual ~SLUFactor();
327 /// clone function for polymorphism
328 inline virtual SLinSolver<R>* clone() const
329 {
330 return new SLUFactor<R>(*this);
331 }
332 ///@}
333
334private:
335
336 //------------------------------------
337 /**@name Private helpers */
338 ///@{
339 /// used to implement the assignment operator
340 void assign(const SLUFactor<R>& old);
341 ///@}
342};
343
344} // namespace soplex
345
346#include "slufactor.hpp"
347#endif // _SLUFACTOR_H_
Implementation of sparse LU factorization.
Definition: clufactor.h:50
const std::shared_ptr< Tolerances > tolerances() const
get tolerances
Definition: clufactor.h:59
int factorCount
Number of factorizations.
Definition: clufactor.h:228
std::shared_ptr< Tolerances > _tolerances
Tolerances for the factorization.
Definition: clufactor.h:230
Timer * factorTime
Time spent in factorizations.
Definition: clufactor.h:227
L l
L matrix.
Definition: clufactor.h:221
int hugeValues
number of times huge values occurred during solve (only used in debug mode)
Definition: clufactor.h:229
SLinSolver< R >::Status stat
Status indicator.
Definition: clufactor.h:207
int thedim
dimension of factorized matrix
Definition: clufactor.h:209
int nzCnt
number of nonzeros in U
Definition: clufactor.h:210
Implementation of Sparse Linear Solver.
Definition: slufactor.h:51
UpdateType
Specifies how to perform change method.
Definition: slufactor.h:59
virtual ~SLUFactor()
destructor.
Timer * solveTime
Time spent in solves.
Definition: slufactor.h:97
void changeEta(int idx, SSVectorBase< R > &eta)
void solveLeft(SSVectorBase< R > &x, SSVectorBase< R > &two, const SVectorBase< R > &b, SSVectorBase< R > &rhs2)
sparse version of solving two systems of equations with transposed basis matrix
R minStability
minimum stability to achieve by setting threshold.
Definition: slufactor.h:95
Real getFactorTime() const
time spent in factorizations
Definition: slufactor.h:254
bool isConsistent() const
consistency check.
void solve2right4update(SSVectorBase< R > &x, SSVectorBase< R > &y, const SVectorBase< R > &b, SSVectorBase< R > &d)
Sparse version of solving two systems of equations.
SLUFactor< R > & operator=(const SLUFactor< R > &old)
assignment operator.
void resetSolveTime()
reset SolveTime
Definition: slufactor.h:275
void resetFactorTime()
reset FactorTime
Definition: slufactor.h:259
UpdateType utype() const
returns the current update type uptype.
Definition: slufactor.h:121
void solveLeft(SSVectorBase< R > &x, SSVectorBase< R > &y, SSVectorBase< R > &z, const SVectorBase< R > &b, SSVectorBase< R > &d, SSVectorBase< R > &e)
sparse version of solving three systems of equations with transposed basis matrix
SSVectorBase< R > forest
? Update VectorBase<R> set up by solveRight4update() and solve2right4update()
Definition: slufactor.h:85
void setUtype(UpdateType tp)
sets update type.
Definition: slufactor.h:130
void resetCounters()
reset timers and counters
Definition: slufactor.h:285
UpdateType uptype
the current UpdateType.
Definition: slufactor.h:82
void solveLeft(SSVectorBase< R > &x, const SSVectorBase< R > &b)
Definition: slufactor.h:227
int solveCount
Number of solves.
Definition: slufactor.h:100
Status change(int idx, const SVectorBase< R > &subst, const SSVectorBase< R > *eta=0)
const char * getName() const
Definition: slufactor.h:174
void solveLeft(SSVectorBase< R > &x, const SVectorBase< R > &b)
Solves .
bool usetup
TRUE iff update vector has been setup.
Definition: slufactor.h:81
R minThreshold
minimum threshold to use.
Definition: slufactor.h:93
Timer::TYPE timerType
Definition: slufactor.h:98
int memory() const
Definition: slufactor.h:169
void solve2right4update(SSVectorBase< R > &x, VectorBase< R > &y, const SVectorBase< R > &b, SSVectorBase< R > &d)
Solves and .
virtual SLinSolver< R > * clone() const
clone function for polymorphism
Definition: slufactor.h:328
void setMarkowitz(R m)
sets minimum Markowitz threshold.
Definition: slufactor.h:136
void solveRight(SSVectorBase< R > &x, const SSVectorBase< R > &b)
Definition: slufactor.h:204
void solveLeft(SSVectorBase< R > &x, VectorBase< R > &y, VectorBase< R > &z, const SVectorBase< R > &b, SSVectorBase< R > &d, SSVectorBase< R > &e)
Solves , and .
void assign(const SLUFactor< R > &old)
used to implement the assignment operator
void solveRight4update(SSVectorBase< R > &x, const SVectorBase< R > &b)
Solves .
SSVectorBase< R > eta
Definition: slufactor.h:83
typename SLinSolver< R >::Status Status
for convenience
Definition: slufactor.h:64
void solveRight(VectorBase< R > &x, const VectorBase< R > &b)
Solves .
SLUFactor()
default constructor.
int dim() const
Definition: slufactor.h:164
virtual void setTolerances(std::shared_ptr< Tolerances > tolerances)
set tolerances
Definition: slufactor.h:306
SSVectorBase< R > ssvec
Temporary semi-sparse VectorBase<R>
Definition: slufactor.h:73
SLUFactor(const SLUFactor< R > &old)
copy constructor.
int getSolveCount() const
number of solves performed
Definition: slufactor.h:280
void solveLeft(VectorBase< R > &x, const VectorBase< R > &b)
sparse version of solving one system of equations with transposed basis matrix
int getFactorCount() const
number of factorizations performed
Definition: slufactor.h:264
R lastThreshold
pivoting threshold of last factorization
Definition: slufactor.h:86
void solveLeft(SSVectorBase< R > &x, VectorBase< R > &y, const SVectorBase< R > &b, SSVectorBase< R > &d)
Solves and .
std::string statistics() const
R stability() const
Status status() const
Definition: slufactor.h:179
void changeTimer(const Timer::TYPE ttype)
Definition: slufactor.h:293
void solve3right4update(SSVectorBase< R > &x, VectorBase< R > &y, VectorBase< R > &z, const SVectorBase< R > &b, SSVectorBase< R > &d, SSVectorBase< R > &e)
Solves , and .
void solve3right4update(SSVectorBase< R > &x, SSVectorBase< R > &y, SSVectorBase< R > &z, const SVectorBase< R > &b, SSVectorBase< R > &d, SSVectorBase< R > &e)
sparse version of solving three systems of equations
Real getSolveTime() const
time spent in solves
Definition: slufactor.h:270
VectorBase< R > vec
Temporary VectorBase<R>
Definition: slufactor.h:72
R matrixMetric(int type=0) const
void dump() const
prints the LU factorization to stdout.
Status load(const SVectorBase< R > *vec[], int dim)
void solveRight(SSVectorBase< R > &x, const SVectorBase< R > &b)
Solves .
R markowitz()
returns Markowitz threshold.
Definition: slufactor.h:149
Sparse Linear Solver virtual base class.
Definition: slinsolver.h:53
Status
status flags of the SLinSolver class.
Definition: slinsolver.h:61
Semi sparse vector.
Definition: ssvectorbase.h:57
virtual void setTolerances(std::shared_ptr< Tolerances > newTolerances)
set the _tolerances member variable
Definition: ssvectorbase.h:114
void unSetup()
Makes SSVectorBase not setup.
Definition: ssvectorbase.h:139
Sparse vectors.
Definition: svectorbase.h:140
static Timer * switchTimer(Timer *timer, Timer::TYPE ttype)
Definition: timerfactory.h:81
Wrapper for the system time query methods.
Definition: timer.h:86
TYPE
types of timers
Definition: timer.h:109
virtual void reset()=0
initialize timer, set timing accounts to zero.
virtual Real time() const =0
Dense vector.
Definition: vectorbase.h:86
Implementation of sparse LU factorization.
Everything should be within this namespace.
double Real
Definition: spxdefines.h:269
Sparse Linear Solver virtual base class.
Debugging, floating point type and parameter definitions.
int * start
starting positions in val and idx
Definition: clufactor.h:188
int firstUnused
number of first unused L vector
Definition: clufactor.h:187
TimerFactory class.