Scippy

SoPlex

Sequential object-oriented simPlex

spxscaler.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-2018 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 spxscaler.h
17  * @brief LP scaling base class.
18  */
19 #ifndef _SPXSCALER_H_
20 #define _SPXSCALER_H_
21 
22 #include <assert.h>
23 
24 #include "soplex/spxdefines.h"
25 #include "soplex/dataarray.h"
26 #include "soplex/vector.h"
27 #include "soplex/svector.h"
28 #include "soplex/svset.h"
29 #include "soplex/dsvector.h"
30 #include "soplex/dvector.h"
31 #include <vector>
32 
33 namespace soplex
34 {
35 
36 template < class R >
37 class SPxLPBase;
38 /**@brief LP scaler abstract base class.
39  @ingroup Algo
40 
41  Instances of classes derived from SPxScaler may be loaded to SoPlex in
42  order to scale LPs before solving them. SoPlex will load() itself to
43  the SPxScaler and then call #scale(). Generally any SPxLP can be
44  loaded to a SPxScaler for #scale()%ing it. The scaling can
45  be undone by calling unscale().
46 
47  Mathematically, the scaling of a constraint matrix A can be written
48  as \f$ A' = R A C \f$, with \f$ R \f$ and \f$ C \f$, being diagonal matrices
49  corresponding to the row and column scale factors, respectively. Besides the
50  constraints matrix, also the upper and lower bounds of both columns and rows
51  need to be scaled.
52 
53  Note that by default scaling is performed both before and after presolving and
54  the former scaling factors are retained during branch-and-bound (persistent scaling).
55  However, while within SoPlex the scaled problem is used, data accessed through
56  the soplex.cpp interface is provided w.r.t. the original problem (i.e., in unscaled form).
57  For instance, consider a scaled constraints matrix A' that is extended by artificial slack
58  variables to the matrix (A',I).
59  A basis \f$ B' = [(A',I)P]_{[1:m][1:m] }\f$ (with P being a permutation matrix)
60  for the scaled problem corresponds to the basis
61  \f$ B = R^{-1} [(A',I)P]_{[1:m][1:m]} [P^{T} \tilde{C}^{-1} P]_{[1:m][1:m] } \f$. In
62  this equation, \f$ \tilde{C} \f$is of the form
63 
64  \f[
65  \begin{array}{cc}
66  C & 0 \\
67  O & R^{-1}
68  \end{array}$
69  \f]
70 
71  Note that in SoPlex only scaling factors \f$ 2^k, k \in \mathbb{Z} \f$ are used.
72 
73 
74 */
75 
76 class SPxScaler
77 {
78 protected:
79 
80  //-------------------------------------
81  /**@name Data */
82  //@{
83  const char* m_name; ///< Name of the scaler
84  DataArray < int >* m_activeColscaleExp; ///< pointer to currently active column scaling factors
85  DataArray < int >* m_activeRowscaleExp; ///< pointer to currently active row scaling factors
86  bool m_colFirst; ///< do column scaling first
87  bool m_doBoth; ///< do columns and rows
88  SPxOut* spxout; ///< message handler
89  //@}
90 
91  //-------------------------------------
92  /**@name Protected helpers */
93  //@{
94 
95  /// clear and setup scaling arrays in the LP
96  virtual void setup(SPxLPBase<Real>& lp);
97  //@}
98 
99 public:
100 
101  /// compute a single scaling vector , e.g. of a newly added row
102  virtual int computeScaleExp(const SVector& vec, const DataArray<int>& oldScaleExp) const;
103 
104  virtual int computeScaleExp(const SVectorBase<Rational>& vec, const DataArray<int>& oldScaleExp) const;
105 
106  /// applies m_colscale and m_rowscale to the \p lp.
107  virtual void applyScaling(SPxLPBase<Real>& lp);
108 
109  friend std::ostream& operator<<(std::ostream& s, const SPxScaler& sc);
110 
111  //-------------------------------------
112  /**@name Construction / destruction */
113  //@{
114  /// constructor
115  explicit SPxScaler(const char* name, bool colFirst = false, bool doBoth = true, SPxOut* spxout = NULL);
116  /// copy constructor
117  SPxScaler(const SPxScaler& );
118  /// assignment operator
119  SPxScaler& operator=(const SPxScaler& );
120  /// destructor.
121  virtual ~SPxScaler();
122  /// clone function for polymorphism
123  virtual SPxScaler* clone() const = 0;
124  //@}
125 
126  //-------------------------------------
127  /**@name Access / modification */
128  //@{
129  /// get name of scaler
130  virtual const char* getName() const;
131  /// set scaling order
132  virtual void setOrder(bool colFirst);
133  /// set wether column and row scaling should be performed
134  virtual void setBoth(bool both);
135  /// set message handler
136  virtual void setOutstream(SPxOut& newOutstream)
137  {
138  spxout = &newOutstream;
139  }
140  /// set real parameter
141  virtual void setRealParam(Real param, const char* name = "realparam");
142  /// set int parameter
143  virtual void setIntParam(int param, const char* name = "intparam");
144  //@}
145 
146  //-------------------------------------
147  /**@name Scaling */
148  //@{
149  /// scale SPxLP.
150  virtual void scale(SPxLPBase<Real>& lp, bool persistent = true) = 0;
151  /// unscale SPxLP
152  virtual void unscale(SPxLPBase<Real>& lp);
153  /// returns scaling factor for column \p i
154  virtual int getColScaleExp(int i) const;
155  /// returns scaling factor for row \p i
156  virtual int getRowScaleExp(int i) const;
157  /// gets unscaled column \p i
158  virtual void getColUnscaled(const SPxLPBase<Real>& lp, int i, DSVector& vec) const;
159  /// returns maximum absolute value of unscaled column \p i
160  virtual Real getColMaxAbsUnscaled(const SPxLPBase<Real>& lp, int i) const;
161  /// returns minumum absolute value of unscaled column \p i
162  virtual Real getColMinAbsUnscaled(const SPxLPBase<Real>& lp, int i) const;
163  /// returns unscaled upper bound \p i
164  virtual Real upperUnscaled(const SPxLPBase<Real>& lp, int i) const;
165  /// returns unscaled upper bound vector of \p lp
166  virtual void getUpperUnscaled(const SPxLPBase<Real>& lp, Vector& vec) const;
167  /// returns unscaled lower bound \p i
168  virtual Real lowerUnscaled(const SPxLPBase<Real>& lp, int i) const;
169  /// gets unscaled lower bound vector
170  virtual void getLowerUnscaled(const SPxLPBase<Real>& lp, Vector& vec) const;
171  /// returns unscaled objective function coefficient of \p i
172  virtual Real maxObjUnscaled(const SPxLPBase<Real>& lp, int i) const;
173  /// gets unscaled objective function
174  virtual void getMaxObjUnscaled(const SPxLPBase<Real>& lp, Vector& vec) const;
175  /// returns unscaled row \p i
176  virtual void getRowUnscaled(const SPxLPBase<Real>& lp, int i, DSVector& vec) const;
177  /// returns maximum absolute value of unscaled row \p i
178  virtual Real getRowMaxAbsUnscaled(const SPxLPBase<Real>& lp, int i) const;
179  /// returns minimum absolute value of unscaled row \p i
180  virtual Real getRowMinAbsUnscaled(const SPxLPBase<Real>& lp, int i) const;
181  /// returns unscaled right hand side \p i
182  virtual Real rhsUnscaled(const SPxLPBase<Real>& lp, int i) const;
183  /// gets unscaled right hand side vector
184  virtual void getRhsUnscaled(const SPxLPBase<Real>& lp, Vector& vec) const;
185  /// returns unscaled left hand side \p i of \p lp
186  virtual Real lhsUnscaled(const SPxLPBase<Real>& lp, int i) const;
187  /// returns unscaled left hand side vector of \p lp
188  virtual void getLhsUnscaled(const SPxLPBase<Real>& lp, Vector& vec) const;
189  /// returns unscaled coefficient of \p lp
190  virtual Real getCoefUnscaled(const SPxLPBase<Real>& lp, int row, int col) const;
191  /// unscale dense primal solution vector given in \p x.
192  virtual void unscalePrimal(const SPxLPBase<Real>& lp, Vector& x) const;
193  /// unscale dense slack vector given in \p s.
194  virtual void unscaleSlacks(const SPxLPBase<Real>& lp, Vector& s) const;
195  /// unscale dense dual solution vector given in \p pi.
196  virtual void unscaleDual(const SPxLPBase<Real>& lp, Vector& pi) const;
197  /// unscale dense reduced cost vector given in \p r.
198  virtual void unscaleRedCost(const SPxLPBase<Real>& lp, Vector& r) const;
199  /// unscale primal ray given in \p ray.
200  virtual void unscalePrimalray(const SPxLPBase<Real>& lp, Vector& ray) const;
201  /// unscale dual ray given in \p ray.
202  virtual void unscaleDualray(const SPxLPBase<Real>& lp, Vector& ray) const;
203  /// apply scaling to objective function vector \p origObj.
204  virtual void scaleObj(const SPxLPBase<Real>& lp, VectorReal& origObj) const;
205  /// returns scaled objective function coefficient \p origObj.
206  virtual Real scaleObj(const SPxLPBase<Real>& lp, int i, Real origObj) const;
207  /// returns scaled LP element in \p row and \p col.
208  virtual Real scaleElement(const SPxLPBase<Real>& lp, int row, int col, Real val) const;
209  /// returns scaled lower bound of column \p col.
210  virtual Real scaleLower(const SPxLPBase<Real>& lp, int col, Real lower) const;
211  /// returns scaled upper bound of column \p col.
212  virtual Real scaleUpper(const SPxLPBase<Real>& lp, int col, Real upper) const;
213  /// returns scaled left hand side of row \p row.
214  virtual Real scaleLhs(const SPxLPBase<Real>& lp, int row, Real lhs) const;
215  /// returns scaled right hand side of row \p row.
216  virtual Real scaleRhs(const SPxLPBase<Real>& lp, int row, Real rhs) const;
217  /// absolute smallest column scaling factor
218  virtual Real minAbsColscale() const;
219  /// absolute biggest column scaling factor
220  virtual Real maxAbsColscale() const;
221  /// absolute smallest row scaling factor
222  virtual Real minAbsRowscale() const;
223  /// absolute biggest row scaling factor
224  virtual Real maxAbsRowscale() const;
225  /// maximum ratio between absolute biggest and smallest element in any column.
226  virtual Real maxColRatio(const SPxLPBase<Real>& lp) const;
227  /// maximum ratio between absolute biggest and smallest element in any row.
228  virtual Real maxRowRatio(const SPxLPBase<Real>& lp) const;
229  /// round vector entries to power of 2
230  void computeExpVec(const std::vector<Real>& vec, DataArray<int>& vecExp);
231  //@}
232 
233  //-------------------------------------
234  /**@name Debugging */
235  //@{
236  /// consistency check
237  virtual bool isConsistent() const;
238  //@}
239 };
240 } // namespace soplex
241 #endif // _SPXSCALER_H_
virtual void unscaleDualray(const SPxLPBase< Real > &lp, Vector &ray) const
unscale dual ray given in ray.
Definition: spxscaler.cpp:664
virtual void setup(SPxLPBase< Real > &lp)
clear and setup scaling arrays in the LP
Definition: spxscaler.cpp:124
virtual void setBoth(bool both)
set wether column and row scaling should be performed
Definition: spxscaler.cpp:112
virtual void setOrder(bool colFirst)
set scaling order
Definition: spxscaler.cpp:106
virtual void unscalePrimal(const SPxLPBase< Real > &lp, Vector &x) const
unscale dense primal solution vector given in x.
Definition: spxscaler.cpp:604
virtual Real lhsUnscaled(const SPxLPBase< Real > &lp, int i) const
returns unscaled left hand side i of lp
Definition: spxscaler.cpp:564
virtual void getRowUnscaled(const SPxLPBase< Real > &lp, int i, DSVector &vec) const
returns unscaled row i
Definition: spxscaler.cpp:458
virtual Real scaleElement(const SPxLPBase< Real > &lp, int row, int col, Real val) const
returns scaled LP element in row and col.
Definition: spxscaler.cpp:700
friend std::ostream & operator<<(std::ostream &s, const SPxScaler &sc)
Definition: spxscaler.cpp:33
virtual void getLhsUnscaled(const SPxLPBase< Real > &lp, Vector &vec) const
returns unscaled left hand side vector of lp
Definition: spxscaler.cpp:580
virtual void unscaleRedCost(const SPxLPBase< Real > &lp, Vector &r) const
unscale dense reduced cost vector given in r.
Definition: spxscaler.cpp:640
virtual Real maxRowRatio(const SPxLPBase< Real > &lp) const
maximum ratio between absolute biggest and smallest element in any row.
Definition: spxscaler.cpp:853
virtual void unscaleDual(const SPxLPBase< Real > &lp, Vector &pi) const
unscale dense dual solution vector given in pi.
Definition: spxscaler.cpp:628
virtual Real scaleUpper(const SPxLPBase< Real > &lp, int col, Real upper) const
returns scaled upper bound of column col.
Definition: spxscaler.cpp:725
virtual ~SPxScaler()
destructor.
Definition: spxscaler.cpp:79
virtual bool isConsistent() const
consistency check
Definition: spxscaler.cpp:898
virtual Real getRowMaxAbsUnscaled(const SPxLPBase< Real > &lp, int i) const
returns maximum absolute value of unscaled row i
Definition: spxscaler.cpp:481
virtual void getUpperUnscaled(const SPxLPBase< Real > &lp, Vector &vec) const
returns unscaled upper bound vector of lp
Definition: spxscaler.cpp:391
virtual Real scaleLhs(const SPxLPBase< Real > &lp, int row, Real lhs) const
returns scaled left hand side of row row.
Definition: spxscaler.cpp:736
Dense vector for linear algebra.
DataArray< int > * m_activeColscaleExp
pointer to currently active column scaling factors
Definition: spxscaler.h:84
virtual void applyScaling(SPxLPBase< Real > &lp)
applies m_colscale and m_rowscale to the lp.
Definition: spxscaler.cpp:169
virtual void setOutstream(SPxOut &newOutstream)
set message handler
Definition: spxscaler.h:136
virtual int computeScaleExp(const SVector &vec, const DataArray< int > &oldScaleExp) const
compute a single scaling vector , e.g. of a newly added row
Definition: spxscaler.cpp:140
double Real
Definition: spxdefines.h:218
virtual SPxScaler * clone() const =0
clone function for polymorphism
virtual void unscale(SPxLPBase< Real > &lp)
unscale SPxLP
Definition: spxscaler.cpp:228
SPxOut * spxout
message handler
Definition: spxscaler.h:88
virtual Real upperUnscaled(const SPxLPBase< Real > &lp, int i) const
returns unscaled upper bound i
Definition: spxscaler.cpp:374
Dynamic vectors.
Wrapper for several output streams. A verbosity level is used to decide which stream to use and wheth...
Definition: spxout.h:63
Sparse vectors.
virtual void getLowerUnscaled(const SPxLPBase< Real > &lp, Vector &vec) const
gets unscaled lower bound vector
Definition: spxscaler.cpp:421
virtual Real maxAbsColscale() const
absolute biggest column scaling factor
Definition: spxscaler.cpp:771
virtual int getColScaleExp(int i) const
returns scaling factor for column i
Definition: spxscaler.cpp:285
virtual void scaleObj(const SPxLPBase< Real > &lp, VectorReal &origObj) const
apply scaling to objective function vector origObj.
Definition: spxscaler.cpp:676
virtual void getRhsUnscaled(const SPxLPBase< Real > &lp, Vector &vec) const
gets unscaled right hand side vector
Definition: spxscaler.cpp:550
virtual Real minAbsColscale() const
absolute smallest column scaling factor
Definition: spxscaler.cpp:758
virtual void setRealParam(Real param, const char *name="realparam")
set real parameter
Definition: spxscaler.cpp:118
virtual Real maxObjUnscaled(const SPxLPBase< Real > &lp, int i) const
returns unscaled objective function coefficient of i
Definition: spxscaler.cpp:433
void computeExpVec(const std::vector< Real > &vec, DataArray< int > &vecExp)
round vector entries to power of 2
Definition: spxscaler.cpp:887
DataArray< int > * m_activeRowscaleExp
pointer to currently active row scaling factors
Definition: spxscaler.h:85
Debugging, floating point type and parameter definitions.
virtual const char * getName() const
get name of scaler
Definition: spxscaler.cpp:100
virtual Real minAbsRowscale() const
absolute smallest row scaling factor
Definition: spxscaler.cpp:785
virtual Real scaleLower(const SPxLPBase< Real > &lp, int col, Real lower) const
returns scaled lower bound of column col.
Definition: spxscaler.cpp:714
virtual void scale(SPxLPBase< Real > &lp, bool persistent=true)=0
scale SPxLP.
Everything should be within this namespace.
virtual Real lowerUnscaled(const SPxLPBase< Real > &lp, int i) const
returns unscaled lower bound i
Definition: spxscaler.cpp:404
virtual Real rhsUnscaled(const SPxLPBase< Real > &lp, int i) const
returns unscaled right hand side i
Definition: spxscaler.cpp:533
virtual Real getColMinAbsUnscaled(const SPxLPBase< Real > &lp, int i) const
returns minumum absolute value of unscaled column i
Definition: spxscaler.cpp:348
bool m_colFirst
do column scaling first
Definition: spxscaler.h:86
SPxScaler(const char *name, bool colFirst=false, bool doBoth=true, SPxOut *spxout=NULL)
constructor
Definition: spxscaler.cpp:53
Dynamic sparse vectors.
LP scaler abstract base class.Instances of classes derived from SPxScaler may be loaded to SoPlex in ...
Definition: spxscaler.h:76
virtual Real getRowMinAbsUnscaled(const SPxLPBase< Real > &lp, int i) const
returns minimum absolute value of unscaled row i
Definition: spxscaler.cpp:507
virtual Real maxAbsRowscale() const
absolute biggest row scaling factor
Definition: spxscaler.cpp:798
virtual int getRowScaleExp(int i) const
returns scaling factor for row i
Definition: spxscaler.cpp:292
Set of sparse vectors.
virtual void getColUnscaled(const SPxLPBase< Real > &lp, int i, DSVector &vec) const
gets unscaled column i
Definition: spxscaler.cpp:298
virtual Real getCoefUnscaled(const SPxLPBase< Real > &lp, int row, int col) const
returns unscaled coefficient of lp
Definition: spxscaler.cpp:592
bool m_doBoth
do columns and rows
Definition: spxscaler.h:87
virtual Real maxColRatio(const SPxLPBase< Real > &lp) const
maximum ratio between absolute biggest and smallest element in any column.
Definition: spxscaler.cpp:815
virtual Real scaleRhs(const SPxLPBase< Real > &lp, int row, Real rhs) const
returns scaled right hand side of row row.
Definition: spxscaler.cpp:747
Save arrays of data objects.
virtual void unscaleSlacks(const SPxLPBase< Real > &lp, Vector &s) const
unscale dense slack vector given in s.
Definition: spxscaler.cpp:616
virtual void unscalePrimalray(const SPxLPBase< Real > &lp, Vector &ray) const
unscale primal ray given in ray.
Definition: spxscaler.cpp:652
virtual Real getColMaxAbsUnscaled(const SPxLPBase< Real > &lp, int i) const
returns maximum absolute value of unscaled column i
Definition: spxscaler.cpp:323
virtual void getMaxObjUnscaled(const SPxLPBase< Real > &lp, Vector &vec) const
gets unscaled objective function
Definition: spxscaler.cpp:446
const char * m_name
Name of the scaler.
Definition: spxscaler.h:83
virtual void setIntParam(int param, const char *name="intparam")
set int parameter
Definition: spxscaler.cpp:121
SPxScaler & operator=(const SPxScaler &)
assignment operator
Definition: spxscaler.cpp:84