Scippy

SoPlex

Sequential object-oriented simPlex

spxweightpr.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 spxweightpr.h
17  * @brief Weighted pricing.
18  */
19 #ifndef _SPXWEIGHTPR_H_
20 #define _SPXWEIGHTPR_H_
21 
22 #include "soplex/spxdefines.h"
23 #include "soplex/spxpricer.h"
24 
25 namespace soplex
26 {
27 
28 /**@brief Weighted pricing.
29  @ingroup Algo
30 
31  Class SPxWeightPR is an implemantation class of SPxPricer that uses
32  weights for columns and rows for selecting the Simplex pivots. The weights
33  are computed by methods #computeCP() and #computeRP() which may be
34  overridden by derived classes.
35 
36  The weights are interpreted as follows: The higher a value is, the more
37  likely the corresponding row or column is set on one of its bounds.
38 
39  See SPxPricer for a class documentation.
40 */
41 template <class R>
42 class SPxWeightPR : public SPxPricer<R>
43 {
44 private:
45 
46  //-------------------------------------
47  /**@name Data */
48  ///@{
49  /// column penalties
51  /// row penalties
53  /// penalties for leaving alg
55  ///
56  const R* penalty;
57  ///
58  const R* coPenalty;
59  /// length of objective vector.
61  ///@}
62 
63  //-------------------------------------
64  /**@name Private helpers */
65  ///@{
66  /// compute leave penalties.
67  void computeLeavePenalty(int start, int end);
68  /// compute weights for columns.
69  void computeCP(int start, int end);
70  /// compute weights for rows.
71  void computeRP(int start, int end);
72  ///@}
73 
74 public:
75 
76  //-------------------------------------
77  /**@name Construction / destruction */
78  ///@{
79  /// default constructor
81  : SPxPricer<R>("Weight")
82  , penalty(0)
83  , coPenalty(0)
84  , objlength(0)
85  {}
86  /// copy constructor
88  : SPxPricer<R>(old)
89  , cPenalty(old.cPenalty)
90  , rPenalty(old.rPenalty)
91  , leavePenalty(old.leavePenalty)
92  , penalty(0)
93  , coPenalty(0)
94  , objlength(old.objlength)
95  {
96  if(old.penalty == old.rPenalty.get_const_ptr())
97  {
98  penalty = rPenalty.get_const_ptr();
99  coPenalty = cPenalty.get_const_ptr();
100  }
101  else if(old.penalty == old.cPenalty.get_const_ptr())
102  {
103  penalty = cPenalty.get_const_ptr();
104  coPenalty = rPenalty.get_const_ptr();
105  }
106 
107  // otherwise, old.penalty and old.coPenalty are not set and do not have to be copied
108  }
109  /// assignment operator
111  {
112  if(this != &rhs)
113  {
115  cPenalty = rhs.cPenalty;
116  rPenalty = rhs.rPenalty;
117  leavePenalty = rhs.leavePenalty;
118  objlength = rhs.objlength;
119 
120  if(rhs.penalty == rhs.rPenalty.get_const_ptr())
121  {
122  penalty = rPenalty.get_const_ptr();
123  coPenalty = cPenalty.get_const_ptr();
124  }
125  else if(rhs.penalty == rhs.cPenalty.get_const_ptr())
126  {
127  penalty = cPenalty.get_const_ptr();
128  coPenalty = rPenalty.get_const_ptr();
129  }
130 
131  // otherwise, old.penalty and old.coPenalty are not set and do not have to be copied
132  }
133 
134  return *this;
135  }
136  /// destructor
137  virtual ~SPxWeightPR()
138  {}
139  /// clone function for polymorphism
140  inline virtual SPxPricer<R>* clone() const
141  {
142  return new SPxWeightPR(*this);
143  }
144  ///@}
145 
146  //-------------------------------------
147  /**@name Access / modification */
148  ///@{
149  /// sets the solver
150  virtual void load(SPxSolverBase<R>* base);
151  /// set entering/leaving algorithm
152  void setType(typename SPxSolverBase<R>::Type tp);
153  /// set row/column representation
154  void setRep(typename SPxSolverBase<R>::Representation rep);
155  ///
156  virtual int selectLeave();
157  ///
158  virtual SPxId selectEnter();
159  /// \p n vectors have been added to the loaded LP.
160  virtual void addedVecs(int n);
161  /// \p n covectors have been added to the loaded LP.
162  virtual void addedCoVecs(int n);
163  /// \p the i'th vector has been removed from the loaded LP.
164  virtual void removedVec(int i);
165  /// \p the i'th covector has been removed from the loaded LP.
166  virtual void removedCoVec(int i);
167  /// \p n vectors have been removed from the loaded LP.
168  virtual void removedVecs(const int perm[]);
169  /// \p n covectors have been removed from the loaded LP.
170  virtual void removedCoVecs(const int perm[]);
171  ///@}
172 
173  //-------------------------------------
174  /**@name Consistency check */
175  ///@{
176  /// checks for consistency
177  virtual bool isConsistent() const;
178  ///@}
179 };
180 } // namespace soplex
181 
182 // For general templated functions
183 #include "spxweightpr.hpp"
184 
185 #endif // _SPXWEIGHTPR_H_
Representation
LP basis representation.
Definition: spxsolver.h:116
void setType(typename SPxSolverBase< R >::Type tp)
set entering/leaving algorithm
Dense vector.Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std...
Definition: dsvectorbase.h:28
Abstract pricer base class.
virtual void load(SPxSolverBase< R > *base)
sets the solver
virtual int selectLeave()
Sequential object-oriented SimPlex.SPxSolverBase is an LP solver class using the revised Simplex algo...
Definition: spxbasis.h:49
SPxPricer & operator=(const SPxPricer &rhs)
assignment operator
Definition: spxpricer.h:281
VectorBase< R > cPenalty
column penalties
Definition: spxweightpr.h:50
void setRep(typename SPxSolverBase< R >::Representation rep)
set row/column representation
void computeCP(int start, int end)
compute weights for columns.
virtual void removedCoVec(int i)
the i&#39;th covector has been removed from the loaded LP.
virtual void addedCoVecs(int n)
n covectors have been added to the loaded LP.
const R * get_const_ptr() const
Conversion to C-style pointer.
Definition: vectorbase.h:495
Generic Ids for LP rows or columns.Both SPxColIds and SPxRowIds may be treated uniformly as SPxIds: ...
Definition: spxid.h:85
Weighted pricing.Class SPxWeightPR is an implemantation class of SPxPricer that uses weights for colu...
Definition: spxweightpr.h:42
virtual SPxPricer< R > * clone() const
clone function for polymorphism
Definition: spxweightpr.h:140
SPxWeightPR(const SPxWeightPR &old)
copy constructor
Definition: spxweightpr.h:87
virtual ~SPxWeightPR()
destructor
Definition: spxweightpr.h:137
Abstract pricer base class.Class SPxPricer is a pure virtual class defining the interface for pricer ...
Definition: spxpricer.h:47
VectorBase< R > leavePenalty
penalties for leaving alg
Definition: spxweightpr.h:54
Debugging, floating point type and parameter definitions.
virtual void removedVec(int i)
the i&#39;th vector has been removed from the loaded LP.
const R * coPenalty
Definition: spxweightpr.h:58
virtual bool isConsistent() const
checks for consistency
Everything should be within this namespace.
virtual void removedVecs(const int perm[])
n vectors have been removed from the loaded LP.
void computeLeavePenalty(int start, int end)
compute leave penalties.
virtual void addedVecs(int n)
n vectors have been added to the loaded LP.
void computeRP(int start, int end)
compute weights for rows.
VectorBase< R > rPenalty
row penalties
Definition: spxweightpr.h:52
SPxWeightPR & operator=(const SPxWeightPR &rhs)
assignment operator
Definition: spxweightpr.h:110
virtual SPxId selectEnter()
SPxWeightPR()
default constructor
Definition: spxweightpr.h:80
Type
Algorithmic type.
Definition: spxsolver.h:135
R objlength
length of objective vector.
Definition: spxweightpr.h:60
virtual void removedCoVecs(const int perm[])
n covectors have been removed from the loaded LP.