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