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-2020 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"
28 #include "soplex/rational.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 with Rational precision.
36  * @ingroup Algo
37  *
38  * This class implements a SLinSolverRational interface by using the sparse LU
39  * factorization implemented in CLUFactorRational.
40  */
42 {
43 public:
44 
45  //--------------------------------
46  /**@name Types */
47  ///@{
48  /// Specifies how to perform \ref soplex::SLUFactorRational::change "change" method.
50  {
51  ETA = 0, ///<
53  };
54  /// for convenience
56  ///@}
57 
58 private:
59 
60  //--------------------------------
61  /**@name Private data */
62  ///@{
63  VectorRational vec; ///< Temporary vector
64  SSVectorRational 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<R>::UpdateType "UpdateType".
76  forest; ///< ? Update vector set up by solveRight4update() and solve2right4update()
77  Rational 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  /// Time spent in solves
90  /// Number of solves
92  ///@}
93 
94 protected:
95 
96  //--------------------------------
97  /**@name Protected helpers */
98  ///@{
99  ///
100  void freeAll();
101  ///
102  void changeEta(int idx, SSVectorRational& eta);
103  ///@}
104 
105 
106 public:
107 
108  //--------------------------------
109  /**@name Update type */
110  ///@{
111  /// returns the current update type uptype.
113  {
114  return uptype;
115  }
116 
117  /// sets update type.
118  /** The new UpdateType becomes valid only after the next call to
119  method load().
120  */
122  {
123  uptype = tp;
124  }
125 
126  /// sets minimum Markowitz threshold.
127  void setMarkowitz(const Rational& m)
128  {
129  if(m < 0.01)
130  {
131  minThreshold = 0.01;
132  lastThreshold = 0.01;
133  }
134  else if(m > 0.99)
135  {
136  minThreshold = 0.99;
137  lastThreshold = 0.99;
138  }
139  else
140  {
141  minThreshold = m;
142  lastThreshold = m;
143  }
144  }
145 
146  /// returns Markowitz threshold.
148  {
149  return lastThreshold;
150  }
151  ///@}
152 
153  //--------------------------------
154  /**@name Derived from SLinSolverRational
155  See documentation of \ref soplex::SLinSolverRational "SLinSolverRational" for a
156  documentation of these methods.
157  */
158  ///@{
159  ///
160  void clear();
161  ///
162  int dim() const
163  {
164  return thedim;
165  }
166  ///
167  int memory() const
168  {
169  return nzCnt + l.start[l.firstUnused];
170  }
171  ///
172  const char* getName() const
173  {
174  return (uptype == SLUFactorRational::ETA) ? "SLU-Eta" : "SLU-Forest-Tomlin";
175  }
176  ///
177  Status status() const
178  {
179  return Status(stat);
180  }
181  ///
182  Rational stability() const;
183  ///
184  std::string statistics() const;
185  ///
186  Status load(const SVectorRational* vec[], int dim);
187  ///@}
188 
189 public:
190 
191  //--------------------------------
192  /**@name Solve */
193  ///@{
194  /// Solves \f$Ax=b\f$.
195  void solveRight(VectorRational& x, const VectorRational& b);
196  /// Solves \f$Ax=b\f$.
197  void solveRight(SSVectorRational& x, const SVectorRational& b);
198  /// Solves \f$Ax=b\f$.
200  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
202  SSVectorRational& d);
203  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
206  /// Solves \f$Ax=b\f$.
207  void solveLeft(VectorRational& x, const VectorRational& b);
208  /// Solves \f$Ax=b\f$.
209  void solveLeft(SSVectorRational& x, const SVectorRational& b);
210  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
212  SSVectorRational& d);
213  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
216  ///
217  Status change(int idx, const SVectorRational& subst, const SSVectorRational* eta = 0);
218  ///@}
219 
220  //--------------------------------
221  /**@name Miscellaneous */
222  ///@{
223  /// time spent in factorizations
225  {
226  return factorTime->time();
227  }
228  /// set time limit on factorization
229  void setTimeLimit(const Real limit)
230  {
231  timeLimit = limit;
232  }
233  /// reset FactorTime
235  {
236  factorTime->reset();
237  }
238  /// number of factorizations performed
239  int getFactorCount() const
240  {
241  return factorCount;
242  }
243  /// time spent in solves
245  {
246  return solveTime->time();
247  }
248  /// reset SolveTime
250  {
251  solveTime->reset();
252  }
253  /// number of solves performed
254  int getSolveCount() const
255  {
256  return solveCount;
257  }
258  /// reset timers and counters
260  {
261  factorTime->reset();
262  solveTime->reset();
263  factorCount = 0;
264  solveCount = 0;
265  }
266  /// prints the LU factorization to stdout.
267  void dump() const;
268 
269  /// consistency check.
270  bool isConsistent() const;
271  ///@}
272 
273  //------------------------------------
274  /**@name Constructors / Destructors */
275  ///@{
276  /// default constructor.
278  /// assignment operator.
280  /// copy constructor.
282  /// destructor.
283  virtual ~SLUFactorRational();
284  /// clone function for polymorphism
285  inline virtual SLinSolverRational* clone() const
286  {
287  return new SLUFactorRational(*this);
288  }
289  ///@}
290 
291 private:
292 
293  //------------------------------------
294  /**@name Private helpers */
295  ///@{
296  /// used to implement the assignment operator
297  void assign(const SLUFactorRational& old);
298  ///@}
299 };
300 
301 } // namespace soplex
302 #endif // _SLUFACTOR_RATIONAL_H_
void resetSolveTime()
reset SolveTime
VectorRational vec
Temporary vector.
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:62
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:227
virtual SLinSolverRational * clone() const
clone function for polymorphism
void setTimeLimit(const Real limit)
set time limit on factorization
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 .
SLinSolverRational::Status stat
Status indicator.