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