Scippy

SoPlex

Sequential object-oriented simPlex

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