SoPlex Documentation
Loading...
Searching...
No Matches
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-2023 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file spxratiotester.h
26 * @brief Abstract ratio test base class.
27 */
28#ifndef _SPXRATIOTESTER_H_
29#define _SPXRATIOTESTER_H_
30
31
32#include <assert.h>
33
34#include "soplex/spxdefines.h"
35#include "soplex/spxsolver.h"
36
37namespace soplex
38{
39
40/**@brief Abstract ratio test base class.
41 @ingroup Algo
42
43 Class SPxRatioTester is the virtual base class for computing the ratio
44 test within the Simplex algorithm driven by SoPlex. After a SoPlex
45 solver has been #load()%ed to an SPxRatioTester, the solver calls
46 #selectLeave() for computing the ratio test for the entering simplex and
47 #selectEnter() for computing the ratio test in leaving simplex.
48*/
49template <class R>
51{
52protected:
53
54 //-------------------------------------
55 /**@name Data */
56 ///@{
57 /// the solver
59 /// name of the ratio tester
60 const char* m_name;
61 /// internal storage of type
63 /// allowed bound violation
65 ///@}
66
67public:
68
69 //-------------------------------------
70 /**@name Access / modification */
71 ///@{
72 /// get name of ratio tester.
73 virtual const char* getName() const
74 {
75 return m_name;
76 }
77 /// loads LP.
78 /** Load the solver and LP for which pricing steps are to be performed.
79 */
81 {
83 }
84
85 /// unloads LP.
86 virtual void clear()
87 {
88 thesolver = nullptr;
89 }
90
91 /// returns loaded LP solver.
92 virtual SPxSolverBase<R>* solver() const
93 {
94 return thesolver;
95 }
96
97 /// set allowed bound violation
98 virtual void setDelta(R newDelta)
99 {
102 else
103 delta = newDelta;
104 }
105
106 /// get allowed bound violation
107 virtual R getDelta()
108 {
109 return delta;
110 }
111 ///@}
112
113 //-------------------------------------
114 /**@name Entering / leaving */
115 ///@{
116 /// selects index to leave the basis.
117 /** Method #selectLeave() is called by the loaded SoPlex solver when
118 computing the entering simplex algorithm. Its task is to select and
119 return the index of the basis variable that is to leave the basis.
120 When being called,
121 \ref SPxSolverBase<R>::fVec() "fVec()" fullfills the basic bounds
122 \ref SPxSolverBase<R>::lbBound() "lbBound()" and
123 \ref SPxSolverBase<R>::ubBound() "ubBound()" within
124 \ref SPxSolverBase<R>::entertol() "entertol()".
125 fVec().delta() is the vector by
126 which fVec() will be updated in this simplex step. Its nonzero
127 indices are stored in sorted order in fVec().idx().
128
129 If \p val > 0, \p val is the maximum allowed update value for fVec(),
130 otherwise the minimum. Method #selectLeave() must chose \p val of the
131 same sign as passed, such that updating fVec() by \p val yields a
132 new vector that satisfies all basic bounds (within entertol). The
133 returned index, must be the index of an element of fVec(), that
134 reaches one of its bounds with this update.
135 */
136 virtual int selectLeave(R& val, R enterTest, bool polish = false) = 0;
137
138 /// selects variable Id to enter the basis.
139 /** Method #selectEnter() is called by the loaded SoPlex solver, when
140 computing the leaving simplex algorithm. It's task is to select and
141 return the Id of the basis variable that is to enter the basis.
142 When being called,
143 \ref SPxSolverBase<R>::pVec() "pVec()" fullfills the bounds
144 \ref SPxSolverBase<R>::lbBound() "lbBound()" and
145 \ref SPxSolverBase<R>::ubBound() "ubBound()" within
146 \ref SPxSolverBase<R>::leavetol() "leavetol()".
147 Similarly,
148 \ref SPxSolverBase<R>::coPvec() "coPvec()" fulfills the bounds
149 \ref SPxSolverBase<R>::lbBound() "lbBound()" and
150 \ref SPxSolverBase<R>::ubBound() "ubBound()" within
151 \ref SPxSolverBase<R>::leavetol() "leavetol()".
152 pVec().delta() and coPvec().delta() are
153 the vectors by which pVec() and coPvec() will be updated in this
154 simplex step. Their nonzero indices are stored in sorted order in
155 pVec().idx() and coPvec().idx().
156
157 If \p val > 0, \p val is the maximum allowed update value for pVec()
158 and coPvec(), otherwise the minimum. Method #selectEnter() must
159 chose \p val of the same sign as passed, such that updating pVec()
160 and coPvec() by \p val yields a new vector that satisfies all basic
161 bounds (within leavetol). The returned Id must be the Id of an
162 element of pVec() or coPvec(), that reaches one of its bounds
163 with this update.
164 */
165 virtual SPxId selectEnter(R& val, int leaveIdx, bool polish = false) = 0;
166
167 /// sets Simplex type.
168 /** Informs pricer about (a change of) the loaded SoPlex's Type. In
169 the sequel, only the corresponding select methods may be called.
170 */
171 virtual void setType(typename SPxSolverBase<R>::Type)
172 {}
173 ///@}
174
175 //-------------------------------------
176 /**@name Construction / destruction */
177 ///@{
178 /// default constructor
179 explicit SPxRatioTester(const char* name)
180 : thesolver(0)
181 , m_name(name)
182 , m_type(SPxSolverBase<R>::LEAVE)
183 , delta(1e-6)
184 {}
185 /// copy constructor
192 /// assignment operator
194 {
195 if(this != &rhs)
196 {
197 m_name = rhs.m_name;
198 thesolver = rhs.thesolver;
199 m_type = rhs.m_type;
200 delta = rhs.delta;
201 }
202
203 return *this;
204 }
205 /// destructor.
207 {
208 thesolver = nullptr;
209 m_name = nullptr;
210 }
211 /// clone function for polymorphism
212 virtual SPxRatioTester* clone() const = 0;
213 ///@}
214
215};
216
217
218} // namespace soplex
219#endif // _SPXRATIOTESTER_H_
Safe arrays of data objects.
Definition dataarray.h:75
Generic Ids for LP rows or columns.
Definition spxid.h:95
Abstract ratio test base class.
R delta
allowed bound violation
SPxRatioTester(const SPxRatioTester &old)
copy constructor
virtual void setDelta(R newDelta)
set allowed bound violation
virtual SPxId selectEnter(R &val, int leaveIdx, bool polish=false)=0
selects variable Id to enter the basis.
SPxRatioTester(const char *name)
default constructor
virtual void load(SPxSolverBase< R > *p_solver)
loads LP.
virtual const char * getName() const
get name of ratio tester.
SPxSolverBase< R >::Type m_type
internal storage of type
virtual SPxSolverBase< R > * solver() const
returns loaded LP solver.
virtual ~SPxRatioTester()
destructor.
virtual R getDelta()
get allowed bound violation
const char * m_name
name of the ratio tester
virtual void clear()
unloads LP.
virtual void setType(typename SPxSolverBase< R >::Type)
sets Simplex type.
virtual SPxRatioTester * clone() const =0
clone function for polymorphism
SPxSolverBase< R > * thesolver
the solver
virtual int selectLeave(R &val, R enterTest, bool polish=false)=0
selects index to leave the basis.
SPxRatioTester & operator=(const SPxRatioTester &rhs)
assignment operator
Sequential object-oriented SimPlex.
Definition spxsolver.h:104
Type
Algorithmic type.
Definition spxsolver.h:143
Everything should be within this namespace.
Debugging, floating point type and parameter definitions.
#define DEFAULT_EPS_ZERO
default allowed additive zero: 1.0 + EPS_ZERO == 1.0
Definition spxdefines.h:278
main LP solver class