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