SoPlex
Loading...
Searching...
No Matches
spxpricer.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-2026 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
26/**@file spxpricer.h
27 * @brief Abstract pricer base class.
28 */
29#ifndef _SPXPRICE_H_
30#define _SPXPRICE_H_
31
32#include <assert.h>
33
34#include "soplex/spxdefines.h"
35#include "soplex/spxsolver.h"
36#include "soplex/sorter.h"
37
38namespace soplex
39{
40
41/**@brief Abstract pricer base class.
42 @ingroup Algo
43
44 Class SPxPricer is a pure virtual class defining the interface for pricer
45 classes to be used by SoPlex. The pricer's task is to select a vector to
46 enter or leave the simplex basis, depending on the chosen simplex type.
47
48 An SPxPricer first #load%s the SoPlex object for which pricing is to
49 be performed. Then, depending of the SPxSolverBase<R>::Type, methods
50 #selectEnter() and #entered4() (for entering Simplex) or #selectLeave()
51 and #left4() (for leaving Simplex) are called by SoPlex. The SPxPricer
52 object is informed of a change of the SPxSolverBase<R>::Type by calling method
53 #setType().
54*/
55template <class R>
57{
58protected:
59
60 //-------------------------------------
61 /**@name Data */
62 ///@{
63 /// name of the pricer
64 const char* m_name;
65 /// the solver
66
68 thesolver; //@todo The template type should be identified? Do I have to defined two of them?
69 /// violation bound
71 /// tolerances used by the solver
72 std::shared_ptr<Tolerances> _tolerances;
73 ///@}
74
75
77 {
78 int idx;
79 R val;
80 };
81
82 /// Compare class to sort idx/val pairs, used for hypersparse pricing leaving
84 {
85 public:
86 /// constructor
88 {}
89
91 const IdxElement& a,
92 const IdxElement& b
93 ) const
94 {
95 if(a.val > b.val)
96 return -1;
97
98 if(a.val < b.val)
99 return 1;
100
101 return 0;
102 }
103 };
104
106
107public:
108
109 // violation types used for (hyper) sparse pricing
116
117 //-------------------------------------
118 /**@name Initialization */
119 ///@{
120 /// get name of pricer.
121 virtual const char* getName() const
122 {
123 return m_name;
124 }
125
126 /// loads LP.
127 /** Loads the solver and LP for which pricing steps are to be performed.
128 */
129 virtual void load(SPxSolverBase<R>* p_solver)
130 {
131 thesolver = p_solver;
132 }
133
134 /// unloads LP.
135 virtual void clear()
136 {
137 thesolver = nullptr;
138 }
139
140 /// returns loaded SPxSolverBase object.
141 virtual SPxSolverBase<R>* solver() const
142 {
143 return thesolver;
144 }
145
146 /// sets pricing tolerance.
147 /** Inequality violations are accepted, if their size is less than \p tol.
148 */
149 virtual void setPricingTolerance(R tol)
150 {
151 assert(tol >= 0.0);
152
153 thetolerance = tol;
154 }
155 /// returns the pricing tolerance
156 virtual R pricingTolerance() const
157 {
158 return thetolerance;
159 }
160
161
162 /// set the _tolerances member variable
163 virtual void setTolerances(std::shared_ptr<Tolerances> newTolerances)
164 {
165 this->_tolerances = newTolerances;
166 }
167
168 /// sets pricing type.
169 /** Informs pricer about (a change of) the loaded SoPlex's Type. In
170 the sequel, only the corresponding select methods may be called.
171 */
172 virtual void setType(typename SPxSolverBase<R>::Type)
173 {
174 this->thesolver->weights.reDim(0);
175 this->thesolver->coWeights.reDim(0);
176 this->thesolver->weightsAreSetup = false;
177 }
178
179 /// sets basis representation.
180 /** Informs pricer about (a change of) the loaded SoPlex's
181 Representation.
182 */
184 {}
185 ///@}
186
187 //-------------------------------------
188 /**@name Pivoting */
189 ///@{
190 /// returns selected index to leave basis.
191 /** Selects the index of a vector to leave the basis. The selected index
192 i, say, must be in the range 0 <= i < solver()->dim() and its
193 tested value must fullfill solver()->test()[i] < -#pricingTolerance().
194 */
195 virtual int selectLeave() = 0;
196
197 /// performs leaving pivot.
198 /** Method #left4() is called after each simplex iteration in LEAVE
199 mode. It informs the SPxPricer that the \p n 'th variable has left
200 the basis for \p id to come in at this position. When being called,
201 all vectors of SoPlex involved in such an entering update are
202 setup correctly and may be accessed via the corresponding methods
203 (\ref SPxSolverBase<R>::fVec() "fVec()", \ref SPxSolverBase<R>::pVec() "pVec()",
204 etc.). In general, argument \p n will be the one returned by the
205 SPxPricer at the previous call to #selectLeave(). However, one can not
206 rely on this.
207 */
208 virtual void left4(int /*n*/, SPxId /*id*/) {}
209
210 /// selects Id to enter basis.
211 /** Selects the SPxId of a vector to enter the basis. The selected
212 id, must not represent a basic index (i.e. solver()->isBasic(id) must
213 be false). However, the corresponding test value needs not to be less
214 than -#pricingTolerance(). If not, SoPlex will discard the pivot.
215
216 Note:
217 When method #selectEnter() is called by the loaded SoPlex
218 object, all values from \ref SPxSolverBase<R>::coTest() "coTest()" are
219 up to date. However, whether the elements of
220 \ref SPxSolverBase<R>::test() "test()" are up to date depends on the
221 SPxSolverBase<R>::Pricing type.
222 */
223 virtual SPxId selectEnter() = 0;
224
225 /// performs entering pivot.
226 /** Method #entered4() is called after each simplex iteration in ENTER
227 mode. It informs the SPxPricer that variable \p id has entered
228 at the \p n 'th position. When being called, all vectors of SoPlex
229 involved in such an entering update are setup correctly and may be
230 accessed via the corresponding methods
231 (\ref SPxSolverBase<R>::fVec() "fVec()", \ref SPxSolverBase<R>::pVec() "pVec()",
232 etc.). In general, argument \p id will be the one returned by the
233 SPxPricer at the previous call to #selectEnter(). However, one can not
234 rely on this.
235 */
236 virtual void entered4(SPxId /*id*/, int /*n*/)
237 {}
238 ///@}
239
240
241 //-------------------------------------
242 /**@name Extension */
243 ///@{
244 /// \p n vectors have been added to loaded LP.
245 virtual void addedVecs(int /*n*/)
246 {}
247 /// \p n covectors have been added to loaded LP.
248 virtual void addedCoVecs(int /*n*/)
249 {}
250 ///@}
251
252 //-------------------------------------
253 /**@name Shrinking */
254 ///@{
255 /// vector \p i was removed from loaded LP.
256 virtual void removedVec(int /*i*/)
257 {}
258 /// vectors given by \p perm have been removed from loaded LP.
259 virtual void removedVecs(const int* /*perm*/)
260 {}
261 /// covector \p i was removed from loaded LP.
262 virtual void removedCoVec(int /*i*/)
263 {}
264 /// covectors given by \p perm have been removed from loaded LP.
265 virtual void removedCoVecs(const int* /*perm*/)
266 {}
267 ///@}
268
269 //-------------------------------------
270 /**@name Debugging */
271 ///@{
272 virtual bool isConsistent() const
273 {
274#ifdef ENABLE_CONSISTENCY_CHECKS
275 return thesolver != nullptr;
276#else
277 return true;
278#endif
279 }
280 ///@}
281
282 //-------------------------------------
283 /**@name Constructors / Destructors */
284 ///@{
285 /// constructor
286 explicit SPxPricer(const char* p_name)
287 : m_name(p_name)
288 , thesolver(nullptr)
289 , thetolerance(0.0)
290 {}
291
292 /// copy constructor
294 : m_name(old.m_name)
295 , thesolver(old.thesolver)
297 {}
298
299 /// assignment operator
301 {
302 if(this != &rhs)
303 {
304 m_name = rhs.m_name;
305 thesolver = rhs.thesolver;
307 assert(isConsistent());
308 }
309
310 return *this;
311 }
312
313 /// destructor.
314 virtual ~SPxPricer()
315 {
316 m_name = nullptr;
317 thesolver = nullptr;
318 }
319
320 /// clone function for polymorphism
321 virtual SPxPricer* clone() const = 0;
322 ///@}
323
324};
325
326
327} // namespace soplex
328#endif // _SPXPRICER_H_
Generic Ids for LP rows or columns.
Definition spxid.h:95
virtual void removedCoVecs(const int *)
covectors given by perm have been removed from loaded LP.
Definition spxpricer.h:265
virtual void removedVecs(const int *)
vectors given by perm have been removed from loaded LP.
Definition spxpricer.h:259
virtual void setPricingTolerance(R tol)
sets pricing tolerance.
Definition spxpricer.h:149
virtual void entered4(SPxId, int)
performs entering pivot.
Definition spxpricer.h:236
SPxPricer(const SPxPricer &old)
copy constructor
Definition spxpricer.h:293
virtual void addedVecs(int)
n vectors have been added to loaded LP.
Definition spxpricer.h:245
virtual SPxPricer * clone() const =0
clone function for polymorphism
R thetolerance
violation bound
Definition spxpricer.h:70
virtual void setTolerances(std::shared_ptr< Tolerances > newTolerances)
set the _tolerances member variable
Definition spxpricer.h:163
virtual void load(SPxSolverBase< R > *p_solver)
loads LP.
Definition spxpricer.h:129
virtual const char * getName() const
get name of pricer.
Definition spxpricer.h:121
virtual SPxSolverBase< R > * solver() const
returns loaded SPxSolverBase object.
Definition spxpricer.h:141
std::shared_ptr< Tolerances > _tolerances
tolerances used by the solver
Definition spxpricer.h:72
virtual void removedCoVec(int)
covector i was removed from loaded LP.
Definition spxpricer.h:262
virtual bool isConsistent() const
Definition spxpricer.h:272
virtual ~SPxPricer()
destructor.
Definition spxpricer.h:314
const char * m_name
name of the pricer
Definition spxpricer.h:64
virtual void clear()
unloads LP.
Definition spxpricer.h:135
virtual void setType(typename SPxSolverBase< R >::Type)
sets pricing type.
Definition spxpricer.h:172
SPxSolverBase< R > * thesolver
the solver
Definition spxpricer.h:68
SPxPricer(const char *p_name)
constructor
Definition spxpricer.h:286
virtual void setRep(typename SPxSolverBase< R >::Representation)
sets basis representation.
Definition spxpricer.h:183
SPxPricer & operator=(const SPxPricer &rhs)
assignment operator
Definition spxpricer.h:300
virtual void removedVec(int)
vector i was removed from loaded LP.
Definition spxpricer.h:256
IdxCompare compare
Definition spxpricer.h:105
virtual SPxId selectEnter()=0
selects Id to enter basis.
virtual void left4(int, SPxId)
performs leaving pivot.
Definition spxpricer.h:208
virtual void addedCoVecs(int)
n covectors have been added to loaded LP.
Definition spxpricer.h:248
virtual R pricingTolerance() const
returns the pricing tolerance
Definition spxpricer.h:156
virtual int selectLeave()=0
returns selected index to leave basis.
Sequential object-oriented SimPlex.
Definition spxsolver.h:104
Type
Algorithmic type.
Definition spxsolver.h:143
Representation
LP basis representation.
Definition spxsolver.h:124
Everything should be within this namespace.
Generic QuickSort implementation.
Debugging, floating point type and parameter definitions.
main LP solver class
Compare class to sort idx/val pairs, used for hypersparse pricing leaving.
Definition spxpricer.h:84
int operator()(const IdxElement &a, const IdxElement &b) const
Definition spxpricer.h:90