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-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 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/dvector.h"
27 #include "soplex/slinsolver.h"
28 #include "soplex/clufactor.h"
29 
30 namespace soplex
31 {
32 /// maximum nr. of factorization updates allowed before refactorization.
33 #define MAXUPDATES 1000
34 
35 /**@brief Implementation of Sparse Linear Solver.
36  * @ingroup Algo
37  *
38  * This class implements a SLinSolver interface by using the sparse LU
39  * factorization implemented in CLUFactor.
40  */
41 class SLUFactor : public SLinSolver, protected CLUFactor
42 {
43 public:
44 
45  //--------------------------------
46  /**@name Types */
47  //@{
48  /// Specifies how to perform \ref soplex::SLUFactor::change "change" method.
50  {
51  ETA = 0, ///<
53  };
54  /// for convenience
56  //@}
57 
58 private:
59 
60  //--------------------------------
61  /**@name Private data */
62  //@{
63  DVector vec; ///< Temporary vector
64  SSVector ssvec; ///< Temporary semi-sparse vector
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::UpdateType "UpdateType".
74  SSVector eta; ///<
75  SSVector
76  forest; ///< ? Update vector set up by solveRight4update() and solve2right4update()
77  Real 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, SSVector& 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.
130  {
131  if(m < 0.01)
132  m = 0.01;
133 
134  if(m > 0.99)
135  m = 0.99;
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 thedim;
160  }
161  ///
162  int memory() const
163  {
164  return nzCnt + l.start[l.firstUnused];
165  }
166  ///
167  const char* getName() const
168  {
169  return (uptype == SLUFactor::ETA) ? "SLU-Eta" : "SLU-Forest-Tomlin";
170  }
171  ///
172  Status status() const
173  {
174  return Status(stat);
175  }
176  ///
177  Real stability() const;
178  /// return condition number estimate based on the diagonal of U
179  Real conditionEstimate(int type = 0) const;
180  ///
181  std::string statistics() const;
182  ///
183  Status load(const SVector* vec[], int dim);
184  //@}
185 
186 public:
187 
188  //--------------------------------
189  /**@name Solve */
190  //@{
191  /// Solves \f$Ax=b\f$.
192  void solveRight(Vector& x, const Vector& b);
193  void solveRight(SSVector& x, const SSVector& b)
194  {
195  x.unSetup();
196  solveRight((Vector&) x, (const Vector&) b);
197  }
198  /// Solves \f$Ax=b\f$.
199  void solveRight(SSVector& x, const SVector& b);
200  /// Solves \f$Ax=b\f$.
201  void solveRight4update(SSVector& x, const SVector& b);
202  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
203  void solve2right4update(SSVector& x, Vector& y, const SVector& b, SSVector& d);
204  /// Sparse version of solving two systems of equations
205  void solve2right4update(SSVector& x, SSVector& y, const SVector& b, SSVector& d);
206  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
207  void solve3right4update(SSVector& x, Vector& y, Vector& z,
208  const SVector& b, SSVector& d, SSVector& e);
209  /// sparse version of solving three systems of equations
211  const SVector& b, SSVector& d, SSVector& e);
212  /// sparse version of solving one system of equations with transposed basis matrix
213  void solveLeft(Vector& x, const Vector& b);
214  void solveLeft(SSVector& x, const SSVector& b)
215  {
216  x.unSetup();
217  solveLeft((Vector&) x, (const Vector&) b);
218  }
219  /// Solves \f$Ax=b\f$.
220  void solveLeft(SSVector& x, const SVector& b);
221  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
222  void solveLeft(SSVector& x, Vector& y, const SVector& b, SSVector& d);
223  /// sparse version of solving two systems of equations with transposed basis matrix
224  void solveLeft(SSVector& x, SSVector& two, const SVector& b, SSVector& rhs2);
225  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
226  void solveLeft(SSVector& x, Vector& y, Vector& z,
227  const SVector& b, SSVector& d, SSVector& e);
228  /// sparse version of solving three systems of equations with transposed basis matrix
229  void solveLeft(SSVector& x, SSVector& y, SSVector& z,
230  const SVector& b, SSVector& d, SSVector& e);
231  ///
232  Status change(int idx, const SVector& subst, const SSVector* eta = 0);
233  //@}
234 
235  //--------------------------------
236  /**@name Miscellaneous */
237  //@{
238  /// time spent in factorizations
240  {
241  return factorTime->time();
242  }
243  /// reset FactorTime
245  {
246  factorTime->reset();
247  }
248  /// number of factorizations performed
249  int getFactorCount() const
250  {
251  return factorCount;
252  }
253  /// time spent in solves
255  {
256  return solveTime->time();
257  }
258  /// reset SolveTime
260  {
261  solveTime->reset();
262  }
263  /// number of solves performed
264  int getSolveCount() const
265  {
266  return solveCount;
267  }
268  /// reset timers and counters
270  {
271  factorTime->reset();
272  solveTime->reset();
273  factorCount = 0;
274  solveCount = 0;
275  }
276  /// prints the LU factorization to stdout.
277  void dump() const;
278 
279  /// consistency check.
280  bool isConsistent() const;
281  //@}
282 
283  //------------------------------------
284  /**@name Constructors / Destructors */
285  //@{
286  /// default constructor.
287  SLUFactor();
288  /// assignment operator.
289  SLUFactor& operator=(const SLUFactor& old);
290  /// copy constructor.
291  SLUFactor(const SLUFactor& old);
292  /// destructor.
293  virtual ~SLUFactor();
294  /// clone function for polymorphism
295  inline virtual SLinSolver* clone() const
296  {
297  return new SLUFactor(*this);
298  }
299  //@}
300 
301 private:
302 
303  //------------------------------------
304  /**@name Private helpers */
305  //@{
306  /// used to implement the assignment operator
307  void assign(const SLUFactor& old);
308  //@}
309 };
310 
311 } // namespace soplex
312 #endif // _SLUFACTOR_H_
void resetSolveTime()
reset SolveTime
Definition: slufactor.h:259
int getSolveCount() const
number of solves performed
Definition: slufactor.h:264
DVector vec
Temporary vector.
Definition: slufactor.h:63
UpdateType
Specifies how to perform change method.
Definition: slufactor.h:49
void solve2right4update(SSVector &x, Vector &y, const SVector &b, SSVector &d)
Solves and .
Definition: slufactor.cpp:109
Timer::TYPE timerType
Definition: slufactor.h:91
std::string statistics() const
Definition: slufactor.cpp:655
Status load(const SVector *vec[], int dim)
Definition: slufactor.cpp:1357
UpdateType uptype
the current UpdateType.
Definition: slufactor.h:73
void resetCounters()
reset timers and counters
Definition: slufactor.h:269
SSVector ssvec
Temporary semi-sparse vector.
Definition: slufactor.h:64
void solveLeft(Vector &x, const Vector &b)
sparse version of solving one system of equations with transposed basis matrix
Definition: slufactor.cpp:370
Real epsilon
|x| < epsililon is considered to be 0.
Definition: slufactor.h:88
void setUtype(UpdateType tp)
sets update type.
Definition: slufactor.h:123
const char * getName() const
Definition: slufactor.h:167
Real minStability
minimum stability to achieve by setting threshold.
Definition: slufactor.h:86
Real getFactorTime() const
time spent in factorizations
Definition: slufactor.h:239
void unSetup()
Makes SSVectorBase not setup.
Definition: ssvectorbase.h:127
virtual ~SLUFactor()
destructor.
Definition: slufactor.cpp:1331
void solveRight4update(SSVector &x, const SVector &b)
Solves .
Definition: slufactor.cpp:67
Real lastThreshold
pivoting threshold of last factorization
Definition: slufactor.h:77
int getFactorCount() const
number of factorizations performed
Definition: slufactor.h:249
L l
L matrix.
Definition: clufactor.h:198
virtual SLinSolver * clone() const
clone function for polymorphism
Definition: slufactor.h:295
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: slinsolver.h:43
void solveRight(Vector &x, const Vector &b)
Solves .
Definition: slufactor.cpp:41
TimerFactory class.
Real minThreshold
minimum threshold to use.
Definition: slufactor.h:84
void changeEta(int idx, SSVector &eta)
Definition: slufactor.cpp:667
void resetFactorTime()
reset FactorTime
Definition: slufactor.h:244
Status status() const
Definition: slufactor.h:172
SLUFactor()
default constructor.
Definition: slufactor.cpp:1060
double Real
Definition: spxdefines.h:218
int solveCount
Number of solves.
Definition: slufactor.h:93
void setMarkowitz(Real m)
sets minimum Markowitz threshold.
Definition: slufactor.h:129
bool isConsistent() const
consistency check.
Definition: slufactor.cpp:1493
SLinSolver::Status stat
Status indicator.
Definition: clufactor.h:184
Dynamic vectors.
int factorCount
Number of factorizations.
Definition: clufactor.h:205
int firstUnused
number of first unused L vector
Definition: clufactor.h:164
Real conditionEstimate(int type=0) const
return condition number estimate based on the diagonal of U
Definition: slufactor.cpp:602
SLUFactor & operator=(const SLUFactor &old)
assignment operator.
Definition: slufactor.cpp:1028
virtual Real time() const =0
int thedim
dimension of factorized matrix
Definition: clufactor.h:186
void solveRight(SSVector &x, const SSVector &b)
Definition: slufactor.h:193
bool usetup
TRUE iff update vector has been setup.
Definition: slufactor.h:72
SSVector eta
Definition: slufactor.h:74
Real markowitz()
returns Markowitz threshold.
Definition: slufactor.h:142
Debugging, floating point type and parameter definitions.
Real stability() const
Definition: slufactor.cpp:590
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:37
Everything should be within this namespace.
void assign(const SLUFactor &old)
used to implement the assignment operator
Definition: slufactor.cpp:829
TYPE
types of timers
Definition: timer.h:99
void solve3right4update(SSVector &x, Vector &y, Vector &z, const SVector &b, SSVector &d, SSVector &e)
Solves , and .
Definition: slufactor.cpp:228
Timer * factorTime
Time spent in factorizations.
Definition: clufactor.h:204
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
void solveLeft(SSVector &x, const SSVector &b)
Definition: slufactor.h:214
Real getSolveTime() const
time spent in solves
Definition: slufactor.h:254
void dump() const
prints the LU factorization to stdout.
Definition: slufactor.cpp:1502
int nzCnt
number of nonzeros in U
Definition: clufactor.h:187
int * start
starting positions in val and idx
Definition: clufactor.h:165
virtual void reset()=0
initialize timer, set timing accounts to zero.
Status
status flags of the SLinSolver class.
Definition: slinsolver.h:51
Status change(int idx, const SVector &subst, const SSVector *eta=0)
Definition: slufactor.cpp:676
int dim() const
Definition: slufactor.h:157
SSVector forest
? Update vector set up by solveRight4update() and solve2right4update()
Definition: slufactor.h:76
Wrapper for the system time query methods.
Definition: timer.h:76
SLinSolver::Status Status
for convenience
Definition: slufactor.h:55