Scippy

SoPlex

Sequential object-oriented simPlex

slufactor_rational.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_rational.h
17  * @brief Implementation of Sparse Linear Solver with Rational precision.
18  */
19 #ifndef _SLUFACTOR_RATIONAL_H_
20 #define _SLUFACTOR_RATIONAL_H_
21 
22 #include <assert.h>
23 
24 #include "soplex/spxdefines.h"
25 #include "soplex/timerfactory.h"
26 #include "soplex/dvector.h"
29 #include "soplex/rational.h"
30 
31 namespace soplex
32 {
33 /// maximum nr. of factorization updates allowed before refactorization.
34 #define MAXUPDATES 1000
35 
36 /**@brief Implementation of Sparse Linear Solver with Rational precision.
37  * @ingroup Algo
38  *
39  * This class implements a SLinSolverRational interface by using the sparse LU
40  * factorization implemented in CLUFactorRational.
41  */
43 {
44 public:
45 
46  //--------------------------------
47  /**@name Types */
48  //@{
49  /// Specifies how to perform \ref soplex::SLUFactorRational::change "change" method.
51  {
52  ETA = 0, ///<
54  };
55  /// for convenience
57  //@}
58 
59 private:
60 
61  //--------------------------------
62  /**@name Private data */
63  //@{
64  DVectorRational vec; ///< Temporary vector
65  SSVectorRational ssvec; ///< Temporary semi-sparse vector
66  //@}
67 
68 protected:
69 
70  //--------------------------------
71  /**@name Protected data */
72  //@{
73  bool usetup; ///< TRUE iff update vector has been setup
74  UpdateType uptype; ///< the current \ref soplex::SLUFactor::UpdateType "UpdateType".
77  forest; ///< ? Update vector set up by solveRight4update() and solve2right4update()
78  Rational lastThreshold; ///< pivoting threshold of last factorization
79  //@}
80 
81  //--------------------------------
82  /**@name Control Parameters */
83  //@{
84  /// minimum threshold to use.
86  /// minimum stability to achieve by setting threshold.
88  /// Time spent in solves
91  /// Number of solves
93  //@}
94 
95 protected:
96 
97  //--------------------------------
98  /**@name Protected helpers */
99  //@{
100  ///
101  void freeAll();
102  ///
103  void changeEta(int idx, SSVectorRational& eta);
104  //@}
105 
106 
107 public:
108 
109  //--------------------------------
110  /**@name Update type */
111  //@{
112  /// returns the current update type uptype.
114  {
115  return uptype;
116  }
117 
118  /// sets update type.
119  /** The new UpdateType becomes valid only after the next call to
120  method load().
121  */
123  {
124  uptype = tp;
125  }
126 
127  /// sets minimum Markowitz threshold.
128  void setMarkowitz(const Rational& m)
129  {
130  if(m < 0.01)
131  {
132  minThreshold = 0.01;
133  lastThreshold = 0.01;
134  }
135  else if(m > 0.99)
136  {
137  minThreshold = 0.99;
138  lastThreshold = 0.99;
139  }
140  else
141  {
142  minThreshold = m;
143  lastThreshold = m;
144  }
145  }
146 
147  /// returns Markowitz threshold.
149  {
150  return lastThreshold;
151  }
152  //@}
153 
154  //--------------------------------
155  /**@name Derived from SLinSolverRational
156  See documentation of \ref soplex::SLinSolverRational "SLinSolverRational" for a
157  documentation of these methods.
158  */
159  //@{
160  ///
161  void clear();
162  ///
163  int dim() const
164  {
165  return thedim;
166  }
167  ///
168  int memory() const
169  {
170  return nzCnt + l.start[l.firstUnused];
171  }
172  ///
173  const char* getName() const
174  {
175  return (uptype == SLUFactorRational::ETA) ? "SLU-Eta" : "SLU-Forest-Tomlin";
176  }
177  ///
178  Status status() const
179  {
180  return Status(stat);
181  }
182  ///
183  Rational stability() const;
184  ///
185  std::string statistics() const;
186  ///
187  Status load(const SVectorRational* vec[], int dim);
188  //@}
189 
190 public:
191 
192  //--------------------------------
193  /**@name Solve */
194  //@{
195  /// Solves \f$Ax=b\f$.
196  void solveRight(VectorRational& x, const VectorRational& b);
197  /// Solves \f$Ax=b\f$.
198  void solveRight(SSVectorRational& x, const SVectorRational& b);
199  /// Solves \f$Ax=b\f$.
201  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
203  SSVectorRational& d);
204  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
207  /// Solves \f$Ax=b\f$.
208  void solveLeft(VectorRational& x, const VectorRational& b);
209  /// Solves \f$Ax=b\f$.
210  void solveLeft(SSVectorRational& x, const SVectorRational& b);
211  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
213  SSVectorRational& d);
214  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
217  ///
218  Status change(int idx, const SVectorRational& subst, const SSVectorRational* eta = 0);
219  //@}
220 
221  //--------------------------------
222  /**@name Miscellaneous */
223  //@{
224  /// time spent in factorizations
226  {
227  return factorTime->time();
228  }
229  /// set time limit on factorization
230  void setTimeLimit(const Real limit)
231  {
232  timeLimit = limit;
233  }
234  /// reset FactorTime
236  {
237  factorTime->reset();
238  }
239  /// number of factorizations performed
240  int getFactorCount() const
241  {
242  return factorCount;
243  }
244  /// time spent in solves
246  {
247  return solveTime->time();
248  }
249  /// reset SolveTime
251  {
252  solveTime->reset();
253  }
254  /// number of solves performed
255  int getSolveCount() const
256  {
257  return solveCount;
258  }
259  /// reset timers and counters
261  {
262  factorTime->reset();
263  solveTime->reset();
264  factorCount = 0;
265  solveCount = 0;
266  }
267  /// prints the LU factorization to stdout.
268  void dump() const;
269 
270  /// consistency check.
271  bool isConsistent() const;
272  //@}
273 
274  //------------------------------------
275  /**@name Constructors / Destructors */
276  //@{
277  /// default constructor.
279  /// assignment operator.
281  /// copy constructor.
283  /// destructor.
284  virtual ~SLUFactorRational();
285  /// clone function for polymorphism
286  inline virtual SLinSolverRational* clone() const
287  {
288  return new SLUFactorRational(*this);
289  }
290  //@}
291 
292 private:
293 
294  //------------------------------------
295  /**@name Private helpers */
296  //@{
297  /// used to implement the assignment operator
298  void assign(const SLUFactorRational& old);
299  //@}
300 };
301 
302 } // namespace soplex
303 #endif // _SLUFACTOR_RATIONAL_H_
void resetSolveTime()
reset SolveTime
Implementation of Sparse Linear Solver with Rational precision.This class implements a SLinSolverRati...
int firstUnused
number of first unused L vector
Implementation of sparse LU factorization with Rational precision.
void changeEta(int idx, SSVectorRational &eta)
int thedim
dimension of factorized matrix
int getFactorCount() const
number of factorizations performed
UpdateType utype() const
returns the current update type uptype.
int getSolveCount() const
number of solves performed
SLUFactorRational()
default constructor.
Real timeLimit
Time limit on factorization or solves.
Wrapper for GMP type mpq_class.We wrap mpq_class so that we can replace it by a double type if GMP is...
Definition: rational.h:44
Sparse Linear Solver virtual base class with Rational precision.
TimerFactory class.
SSVectorRational ssvec
Temporary semi-sparse vector.
UpdateType uptype
the current UpdateType.
void setMarkowitz(const Rational &m)
sets minimum Markowitz threshold.
void assign(const SLUFactorRational &old)
used to implement the assignment operator
Sparse Linear Solver virtual base class with Rational precision.Class SLinSolverRational provides a c...
Rational minStability
minimum stability to achieve by setting threshold.
SLinSolverRational::Status Status
for convenience
Rational minThreshold
minimum threshold to use.
Real getSolveTime() const
time spent in solves
double Real
Definition: spxdefines.h:218
virtual SLinSolverRational * clone() const
clone function for polymorphism
void setTimeLimit(const Real limit)
set time limit on factorization
Dynamic vectors.
void setUtype(UpdateType tp)
sets update type.
Wrapper for GMP types.
Rational lastThreshold
pivoting threshold of last factorization
void solveRight(VectorRational &x, const VectorRational &b)
Solves .
void solveRight4update(SSVectorRational &x, const SVectorRational &b)
Solves .
int solveCount
Number of solves.
SSVectorRational forest
? Update vector set up by solveRight4update() and solve2right4update()
virtual Real time() const =0
Timer * factorTime
Time spent in factorizations.
Status load(const SVectorRational *vec[], int dim)
bool isConsistent() const
consistency check.
const char * getName() const
virtual ~SLUFactorRational()
destructor.
bool usetup
TRUE iff update vector has been setup.
Debugging, floating point type and parameter definitions.
void dump() const
prints the LU factorization to stdout.
Real getFactorTime() const
time spent in factorizations
Status change(int idx, const SVectorRational &subst, const SSVectorRational *eta=0)
Implementation of sparse LU factorization with Rational precision.This class implements a sparse LU f...
Everything should be within this namespace.
TYPE
types of timers
Definition: timer.h:99
Timer * solveTime
Time spent in solves.
std::string statistics() const
int * start
starting positions in val and idx
UpdateType
Specifies how to perform change method.
int factorCount
Number of factorizations.
void solve3right4update(SSVectorRational &x, VectorRational &y, VectorRational &z, const SVectorRational &b, SSVectorRational &d, SSVectorRational &e)
Solves , and .
SLUFactorRational & operator=(const SLUFactorRational &old)
assignment operator.
void resetFactorTime()
reset FactorTime
virtual void reset()=0
initialize timer, set timing accounts to zero.
Rational markowitz()
returns Markowitz threshold.
void solveLeft(VectorRational &x, const VectorRational &b)
Solves .
Status
status flags of the SLinSolverRational class.
void resetCounters()
reset timers and counters
Wrapper for the system time query methods.
Definition: timer.h:76
int nzCnt
number of nonzeros in U
void solve2right4update(SSVectorRational &x, VectorRational &y, const SVectorRational &b, SSVectorRational &d)
Solves and .
DVectorRational vec
Temporary vector.
SLinSolverRational::Status stat
Status indicator.