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-2015 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 "spxdefines.h"
25 #include "timerfactory.h"
26 #include "dvector.h"
27 #include "slinsolver_rational.h"
28 #include "clufactor_rational.h"
29 #include "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".
76  SSVectorRational 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  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
205  /// Solves \f$Ax=b\f$.
206  void solveLeft(VectorRational& x, const VectorRational& b);
207  /// Solves \f$Ax=b\f$.
208  void solveLeft(SSVectorRational& x, const SVectorRational& b);
209  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
211  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
214  ///
215  Status change(int idx, const SVectorRational& subst, const SSVectorRational* eta = 0);
216  //@}
217 
218  //--------------------------------
219  /**@name Miscellaneous */
220  //@{
221  /// time spent in factorizations
223  {
224  return factorTime->time();
225  }
226  /// set time limit on factorization
227  void setTimeLimit(const Real limit)
228  {
229  timeLimit = limit;
230  }
231  /// reset FactorTime
233  {
234  factorTime->reset();
235  }
236  /// number of factorizations performed
237  int getFactorCount() const
238  {
239  return factorCount;
240  }
241  /// time spent in solves
243  {
244  return solveTime->time();
245  }
246  /// reset SolveTime
248  {
249  solveTime->reset();
250  }
251  /// number of solves performed
252  int getSolveCount() const
253  {
254  return solveCount;
255  }
256  /// reset timers and counters
258  {
259  factorTime->reset();
260  solveTime->reset();
261  factorCount = 0;
262  solveCount = 0;
263  }
264  /// prints the LU factorization to stdout.
265  void dump() const;
266 
267  /// consistency check.
268  bool isConsistent() const;
269  //@}
270 
271  //------------------------------------
272  /**@name Constructors / Destructors */
273  //@{
274  /// default constructor.
276  /// assignment operator.
278  /// copy constructor.
280  /// destructor.
281  virtual ~SLUFactorRational();
282  /// clone function for polymorphism
283  inline virtual SLinSolverRational* clone() const
284  {
285  return new SLUFactorRational(*this);
286  }
287  //@}
288 
289 private:
290 
291  //------------------------------------
292  /**@name Private helpers */
293  //@{
294  /// used to implement the assignment operator
295  void assign(const SLUFactorRational& old);
296  //@}
297 };
298 
299 } // namespace soplex
300 #endif // _SLUFACTOR_RATIONAL_H_