Scippy

SoPlex

Sequential object-oriented simPlex

spxratiotester.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-2017 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 spxratiotester.h
17  * @brief Abstract ratio test base class.
18  */
19 #ifndef _SPXRATIOTESTER_H_
20 #define _SPXRATIOTESTER_H_
21 
22 
23 #include <assert.h>
24 
25 #include "spxdefines.h"
26 #include "spxsolver.h"
27 
28 namespace soplex
29 {
30 
31 /**@brief Abstract ratio test base class.
32  @ingroup Algo
33 
34  Class SPxRatioTester is the virtual base class for computing the ratio
35  test within the Simplex algorithm driven by SoPlex. After a SoPlex
36  solver has been #load()%ed to an SPxRatioTester, the solver calls
37  #selectLeave() for computing the ratio test for the entering simplex and
38  #selectEnter() for computing the ratio test in leaving simplex.
39 */
41 {
42 protected:
43 
44  //-------------------------------------
45  /**@name Data */
46  //@{
47  /// the solver
49  /// name of the ratio tester
50  const char* m_name;
51  /// internal storage of type
53  /// allowed bound violation
55  //@}
56 
57 public:
58 
59  //-------------------------------------
60  /**@name Access / modification */
61  //@{
62  /// get name of ratio tester.
63  virtual const char* getName() const
64  {
65  return m_name;
66  }
67  /// loads LP.
68  /** Load the solver and LP for which pricing steps are to be performed.
69  */
70  virtual void load(SPxSolver* p_solver)
71  {
72  thesolver = p_solver;
73  }
74 
75  /// unloads LP.
76  virtual void clear()
77  {
78  thesolver = 0;
79  }
80 
81  /// returns loaded LP solver.
82  virtual SPxSolver* solver() const
83  {
84  return thesolver;
85  }
86 
87  /// set allowed bound violation
88  virtual void setDelta( Real newDelta )
89  {
90  if( newDelta <= DEFAULT_EPS_ZERO )
91  delta = DEFAULT_EPS_ZERO;
92  else
93  delta = newDelta;
94  }
95 
96  /// get allowed bound violation
97  virtual Real getDelta()
98  {
99  return delta;
100  }
101  //@}
102 
103  //-------------------------------------
104  /**@name Entering / leaving */
105  //@{
106  /// selects index to leave the basis.
107  /** Method #selectLeave() is called by the loaded SoPlex solver when
108  computing the entering simplex algorithm. Its task is to select and
109  return the index of the basis variable that is to leave the basis.
110  When being called,
111  \ref SPxSolver::fVec() "fVec()" fullfills the basic bounds
112  \ref SPxSolver::lbBound() "lbBound()" and
113  \ref SPxSolver::ubBound() "ubBound()" within
114  \ref SPxSolver::entertol() "entertol()".
115  fVec().delta() is the vector by
116  which fVec() will be updated in this simplex step. Its nonzero
117  indices are stored in sorted order in fVec().idx().
118 
119  If \p val > 0, \p val is the maximum allowed update value for fVec(),
120  otherwise the minimum. Method #selectLeave() must chose \p val of the
121  same sign as passed, such that updating fVec() by \p val yields a
122  new vector that satisfies all basic bounds (within entertol). The
123  returned index, must be the index of an element of fVec(), that
124  reaches one of its bounds with this update.
125  */
126  virtual int selectLeave(Real& val, Real enterTest, bool polish = false) = 0;
127 
128  /// selects variable Id to enter the basis.
129  /** Method #selectEnter() is called by the loaded SoPlex solver, when
130  computing the leaving simplex algorithm. It's task is to select and
131  return the Id of the basis variable that is to enter the basis.
132  When being called,
133  \ref SPxSolver::pVec() "pVec()" fullfills the bounds
134  \ref SPxSolver::lbBound() "lbBound()" and
135  \ref SPxSolver::ubBound() "ubBound()" within
136  \ref SPxSolver::leavetol() "leavetol()".
137  Similarly,
138  \ref SPxSolver::coPvec() "coPvec()" fulfills the bounds
139  \ref SPxSolver::lbBound() "lbBound()" and
140  \ref SPxSolver::ubBound() "ubBound()" within
141  \ref SPxSolver::leavetol() "leavetol()".
142  pVec().delta() and coPvec().delta() are
143  the vectors by which pVec() and coPvec() will be updated in this
144  simplex step. Their nonzero indices are stored in sorted order in
145  pVec().idx() and coPvec().idx().
146 
147  If \p val > 0, \p val is the maximum allowed update value for pVec()
148  and coPvec(), otherwise the minimum. Method #selectEnter() must
149  chose \p val of the same sign as passed, such that updating pVec()
150  and coPvec() by \p val yields a new vector that satisfies all basic
151  bounds (within leavetol). The returned Id must be the Id of an
152  element of pVec() or coPvec(), that reaches one of its bounds
153  with this update.
154  */
155  virtual SPxId selectEnter(Real& val, int leaveIdx, bool polish = false) = 0;
156 
157  /// sets Simplex type.
158  /** Informs pricer about (a change of) the loaded SoPlex's Type. In
159  the sequel, only the corresponding select methods may be called.
160  */
161  virtual void setType(SPxSolver::Type)
162  {}
163  //@}
164 
165  //-------------------------------------
166  /**@name Construction / destruction */
167  //@{
168  /// default constructor
169  explicit SPxRatioTester(const char* name)
170  : thesolver(0)
171  , m_name(name)
172  , m_type(SPxSolver::LEAVE)
173  , delta(1e-6)
174  {}
175  /// copy constructor
177  : thesolver(old.thesolver)
178  , m_name(old.m_name)
179  , m_type(old.m_type)
180  , delta(old.delta)
181  {}
182  /// assignment operator
184  {
185  if(this != &rhs)
186  {
187  m_name = rhs.m_name;
188  thesolver = rhs.thesolver;
189  m_type = rhs.m_type;
190  delta = rhs.delta;
191  }
192 
193  return *this;
194  }
195  /// destructor.
196  virtual ~SPxRatioTester()
197  {
198  thesolver = 0;
199  m_name = 0;
200  }
201  /// clone function for polymorphism
202  virtual SPxRatioTester* clone() const = 0;
203  //@}
204 
205 };
206 
207 
208 } // namespace soplex
209 #endif // _SPXRATIOTESTER_H_
virtual void setType(SPxSolver::Type)
sets Simplex type.
virtual Real getDelta()
get allowed bound violation
Type
Algorithmic type.
Definition: spxsolver.h:124
Real delta
allowed bound violation
SPxRatioTester(const SPxRatioTester &old)
copy constructor
Abstract ratio test base class.Class SPxRatioTester is the virtual base class for computing the ratio...
virtual SPxId selectEnter(Real &val, int leaveIdx, bool polish=false)=0
selects variable Id to enter the basis.
virtual SPxRatioTester * clone() const =0
clone function for polymorphism
Generic Ids for LP rows or columns.Both SPxColIds and SPxRowIds may be treated uniformly as SPxIds: ...
Definition: spxid.h:85
virtual ~SPxRatioTester()
destructor.
double Real
Definition: spxdefines.h:218
main LP solver class
#define DEFAULT_EPS_ZERO
default allowed additive zero: 1.0 + EPS_ZERO == 1.0
Definition: spxdefines.h:230
const char * m_name
name of the ratio tester
SPxRatioTester & operator=(const SPxRatioTester &rhs)
assignment operator
SPxRatioTester(const char *name)
default constructor
virtual void load(SPxSolver *p_solver)
loads LP.
virtual void setDelta(Real newDelta)
set allowed bound violation
virtual const char * getName() const
get name of ratio tester.
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
SPxSolver * thesolver
the solver
Everything should be within this namespace.
virtual SPxSolver * solver() const
returns loaded LP solver.
virtual int selectLeave(Real &val, Real enterTest, bool polish=false)=0
selects index to leave the basis.
virtual void clear()
unloads LP.
SPxSolver::Type m_type
internal storage of type