Scippy

SoPlex

Sequential object-oriented simPlex

spxfastrt.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-2016 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 spxfastrt.h
17  * @brief Fast shifting ratio test.
18  */
19 #ifndef _SPXFASTRT_H_
20 #define _SPXFASTRT_H_
21 
22 #include <assert.h>
23 
24 #include "spxdefines.h"
25 #include "spxratiotester.h"
26 
27 namespace soplex
28 {
29 
30 /**@brief Fast shifting ratio test.
31  @ingroup Algo
32 
33  Class SPxFastRT is an implementation class of SPxRatioTester providing
34  fast and stable ratio test. Stability is achieved by allowing some
35  infeasibility to ensure numerical stability such as the Harris procedure.
36  Performance is achieved by skipping the second phase if the first phase
37  already shows a stable enough pivot.
38 
39  See SPxRatioTester for a class documentation.
40 */
41 class SPxFastRT : public SPxRatioTester
42 {
43 protected:
44  //-------------------------------------
45  /**@name Data */
46  //@{
47  /// parameter for computing minimum stability requirement
49  /// |value| < epsilon is considered 0.
51  /// currently allowed infeasibility.
53  /// flag used in methods minSelect/maxSelect to retrieve correct basis status
54  bool iscoid;
55  //@}
56 
57  //-------------------------------------
58  /**@name Private helpers */
59  //@{
60  /// resets tolerances (epsilon).
61  void resetTols();
62  /// relaxes stability requirements.
63  void relax();
64  /// tightens stability requirements.
65  void tighten();
66  /// Compute stability requirement
67  Real minStability(Real maxabs);
68 
69  /// Max phase 1 value.
70  /** Computes the maximum value \p val that could be used for updating \p update
71  such that it would still fulfill the upper and lower bounds \p upBound and
72  \p lowBound, respectively, within #delta. Return value is the index where the
73  maximum value is encountered. At the same time the maximum absolute value
74  of \p update.delta() is computed and returned in \p maxabs. Internally all
75  loops are started at \p start and incremented by \p incr.
76  */
77  int maxDelta(Real& val, Real& maxabs, UpdateVector& update,
78  const Vector& lowBound, const Vector& upBound, int start, int incr) const;
79 
80  ///
81  int maxDelta(Real& val, Real& maxabs);
82 
83  ///
84  SPxId maxDelta(int& nr, Real& val, Real& maxabs);
85 
86  /// Min phase 1 value.
87  /** Computes the minimum value \p val that could be used for updating \p update
88  such that it would still fulfill the upper and lower bounds \p upBound and
89  \p lowBound, respectively, within #delta. Return value is the index where the
90  minimum value is encountered. At the same time the maximum absolute value
91  of \p update.delta() is computed and returned in \p maxabs. Internally all
92  loops are started at \p start and incremented by \p incr.
93  */
94  int minDelta(Real& val, Real& maxabs, UpdateVector& update,
95  const Vector& lowBound, const Vector& upBound, int start, int incr) const;
96 
97  ///
98  int minDelta(Real& val, Real& maxabs);
99 
100  ///
101  SPxId minDelta(int& nr, Real& val, Real& maxabs);
102 
103  /// selects stable index for maximizing ratio test.
104  /** Selects from all update values \p val < \p max the one with the largest
105  value of \p upd.delta() which must be greater than \p stab and is
106  returned in \p stab. The index is returned as well as the corresponding
107  update value \p val. Internally all loops are started at \p start and
108  incremented by \p incr.
109  */
110  int maxSelect(Real& val, Real& stab, Real& best, Real& bestDelta,
111  Real max, const UpdateVector& upd, const Vector& low,
112  const Vector& up, int start = 0, int incr = 1) const;
113  ///
114  int maxSelect(Real& val, Real& stab, Real& bestDelta, Real max);
115  ///
116  SPxId maxSelect(int& nr, Real& val, Real& stab,
117  Real& bestDelta, Real max);
118 
119  /// selects stable index for minimizing ratio test.
120  /** Select from all update values \p val > \p max the one with the largest
121  value of \p upd.delta() which must be greater than \p stab and is
122  returned in \p stab. The index is returned as well as the corresponding
123  update value \p val. Internally all loops are started at \p start and
124  incremented by \p incr.
125  */
126  int minSelect(Real& val, Real& stab, Real& best, Real& bestDelta,
127  Real max, const UpdateVector& upd, const Vector& low,
128  const Vector& up, int start = 0, int incr = 1) const;
129  ///
130  int minSelect(Real& val, Real& stab,
131  Real& bestDelta, Real max);
132  ///
133  SPxId minSelect(int& nr, Real& val, Real& stab,
134  Real& bestDelta, Real max);
135 
136  /// tests for stop after phase 1.
137  /** Tests whether a shortcut after phase 1 is feasible for the
138  selected leave pivot. In this case return the update value in \p sel.
139  */
140  bool minShortLeave(Real& sel, int leave, Real maxabs);
141  ///
142  bool maxShortLeave(Real& sel, int leave, Real maxabs);
143 
144  /// numerical stability tests.
145  /** Tests whether the selected leave index needs to be discarded (and do so)
146  and the ratio test is to be recomputed.
147  */
148  bool minReLeave(Real& sel, int leave, Real maxabs);
149  ///
150  bool maxReLeave(Real& sel, int leave, Real maxabs);
151 
152  /// numerical stability check.
153  /** Tests whether the selected enter \p id needs to be discarded (and do so)
154  and the ratio test is to be recomputed.
155  */
156  bool minReEnter(Real& sel, Real maxabs, const SPxId& id, int nr);
157  ///
158  bool maxReEnter(Real& sel, Real maxabs, const SPxId& id, int nr);
159 
160  /// Tests and returns whether a shortcut after phase 1 is feasible for the
161  /// selected enter pivot.
162  bool shortEnter(const SPxId& enterId, int nr, Real max, Real maxabs) const;
163  //@}
164 
165 public:
166 
167  //-------------------------------------
168  /**@name Construction / destruction */
169  //@{
170  /// default constructor
172  : SPxRatioTester("Fast")
173  , minStab(DEFAULT_BND_VIOL)
174  , epsilon(DEFAULT_EPS_ZERO)
175  , fastDelta(DEFAULT_BND_VIOL)
176  , iscoid(false)
177  {}
178  /// copy constructor
179  SPxFastRT(const SPxFastRT& old)
180  : SPxRatioTester(old)
181  , minStab(old.minStab)
182  , epsilon(old.epsilon)
183  , fastDelta(old.fastDelta)
184  , iscoid(false)
185  {}
186  /// assignment operator
188  {
189  if(this != &rhs)
190  {
192  minStab = rhs.minStab;
193  epsilon = rhs.epsilon;
194  fastDelta = rhs.fastDelta;
195  iscoid = false;
196  }
197 
198  return *this;
199  }
200  /// bound flipping constructor
201  SPxFastRT(const char* name)
202  : SPxRatioTester(name)
203  , minStab(DEFAULT_BND_VIOL)
204  , epsilon(DEFAULT_EPS_ZERO)
205  , fastDelta(DEFAULT_BND_VIOL)
206  , iscoid(false)
207  {}
208  /// destructor
209  virtual ~SPxFastRT()
210  {}
211  /// clone function for polymorphism
212  inline virtual SPxRatioTester* clone() const
213  {
214  return new SPxFastRT(*this);
215  }
216  //@}
217 
218  //-------------------------------------
219  /**@name Access / modification */
220  //@{
221  ///
222  virtual void load(SPxSolver* solver);
223  ///
224  virtual int selectLeave(Real& val, Real);
225  ///
226  virtual SPxId selectEnter(Real& val, int);
227  ///
228  virtual void setType(SPxSolver::Type type);
229  ///
230  virtual void setDelta(Real newDelta)
231  {
232  if( newDelta <= DEFAULT_EPS_ZERO )
233  newDelta = DEFAULT_EPS_ZERO;
234  delta = newDelta;
235  fastDelta = newDelta;
236  }
237  ///
238  virtual Real getDelta()
239  {
240  return fastDelta;
241  }
242  //@}
243 };
244 } // namespace soplex
245 #endif // _SPXFASTRT_H_
bool maxReEnter(Real &sel, Real maxabs, const SPxId &id, int nr)
Definition: spxfastrt.cpp:971
virtual ~SPxFastRT()
destructor
Definition: spxfastrt.h:209
#define DEFAULT_BND_VIOL
default allowed bound violation
Definition: spxdefines.h:208
Type
Algorithmic type.
Definition: spxsolver.h:124
bool maxShortLeave(Real &sel, int leave, Real maxabs)
Definition: spxfastrt.cpp:735
Real delta
allowed bound violation
SPxFastRT(const SPxFastRT &old)
copy constructor
Definition: spxfastrt.h:179
Real fastDelta
currently allowed infeasibility.
Definition: spxfastrt.h:52
Abstract ratio test base class.
virtual void setDelta(Real newDelta)
Definition: spxfastrt.h:230
Abstract ratio test base class.Class SPxRatioTester is the virtual base class for computing the ratio...
Real epsilon
|value| < epsilon is considered 0.
Definition: spxfastrt.h:50
virtual void setType(SPxSolver::Type type)
Definition: spxfastrt.cpp:1316
void relax()
relaxes stability requirements.
Definition: spxfastrt.cpp:80
bool maxReLeave(Real &sel, int leave, Real maxabs)
Definition: spxfastrt.cpp:779
int maxDelta(Real &val, Real &maxabs, UpdateVector &update, const Vector &lowBound, const Vector &upBound, int start, int incr) const
Max phase 1 value.
Definition: spxfastrt.cpp:101
SPxFastRT()
default constructor
Definition: spxfastrt.h:171
virtual int selectLeave(Real &val, Real)
Definition: spxfastrt.cpp:849
Real minStability(Real maxabs)
Compute stability requirement.
Definition: spxfastrt.cpp:87
Generic Ids for LP rows or columns.Both SPxColIds and SPxRowIds may be treated uniformly as SPxIds: ...
Definition: spxid.h:85
void resetTols()
resets tolerances (epsilon).
Definition: spxfastrt.cpp:48
Fast shifting ratio test.Class SPxFastRT is an implementation class of SPxRatioTester providing fast ...
Definition: spxfastrt.h:41
int minSelect(Real &val, Real &stab, Real &best, Real &bestDelta, Real max, const UpdateVector &upd, const Vector &low, const Vector &up, int start=0, int incr=1) const
selects stable index for minimizing ratio test.
Definition: spxfastrt.cpp:488
double Real
SOPLEX_DEBUG.
Definition: spxdefines.h:200
bool minReLeave(Real &sel, int leave, Real maxabs)
numerical stability tests.
Definition: spxfastrt.cpp:814
virtual SPxRatioTester * clone() const
clone function for polymorphism
Definition: spxfastrt.h:212
#define DEFAULT_EPS_ZERO
default allowed additive zero: 1.0 + EPS_ZERO == 1.0
Definition: spxdefines.h:212
Dense vector with semi-sparse vector for updatesIn many algorithms vectors are updated in every itera...
Definition: updatevector.h:53
SPxRatioTester & operator=(const SPxRatioTester &rhs)
assignment operator
int maxSelect(Real &val, Real &stab, Real &best, Real &bestDelta, Real max, const UpdateVector &upd, const Vector &low, const Vector &up, int start=0, int incr=1) const
selects stable index for maximizing ratio test.
Definition: spxfastrt.cpp:567
virtual Real getDelta()
Definition: spxfastrt.h:238
Debugging, floating point type and parameter definitions.
Sequential object-oriented SimPlex.SPxSolver is an LP solver class using the revised Simplex algorith...
Definition: spxsolver.h:84
Everything should be within this namespace.
void tighten()
tightens stability requirements.
Definition: spxfastrt.cpp:58
SPxFastRT(const char *name)
bound flipping constructor
Definition: spxfastrt.h:201
bool iscoid
flag used in methods minSelect/maxSelect to retrieve correct basis status
Definition: spxfastrt.h:54
bool minShortLeave(Real &sel, int leave, Real maxabs)
tests for stop after phase 1.
Definition: spxfastrt.cpp:757
int minDelta(Real &val, Real &maxabs, UpdateVector &update, const Vector &lowBound, const Vector &upBound, int start, int incr) const
Min phase 1 value.
Definition: spxfastrt.cpp:256
virtual void load(SPxSolver *solver)
Definition: spxfastrt.cpp:1310
SPxFastRT & operator=(const SPxFastRT &rhs)
assignment operator
Definition: spxfastrt.h:187
virtual SPxId selectEnter(Real &val, int)
Definition: spxfastrt.cpp:1183
bool shortEnter(const SPxId &enterId, int nr, Real max, Real maxabs) const
Tests and returns whether a shortcut after phase 1 is feasible for the selected enter pivot...
Definition: spxfastrt.cpp:1153
Real minStab
parameter for computing minimum stability requirement
Definition: spxfastrt.h:48
bool minReEnter(Real &sel, Real maxabs, const SPxId &id, int nr)
numerical stability check.
Definition: spxfastrt.cpp:1063
virtual SPxSolver * solver() const
returns loaded LP solver.