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-2015 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 "spxdefines.h"
25 #include "dataarray.h"
26 #include "spxlp.h"
27 
28 namespace soplex
29 {
30 /**@brief LP scaler abstract base class.
31  @ingroup Algo
32 
33  Instances of classes derived from SPxScaler may be loaded to SoPlex in
34  order to scale LPs before solving them. SoPlex will load() itself to
35  the SPxScaler and then call #scale(). Generally any SPxLP can be
36  loaded to a SPxScaler for #scale()%ing it. The scaling can
37  be undone by calling unscale().
38 */
39 class SPxScaler
40 {
41 protected:
42 
43  //-------------------------------------
44  /**@name Data */
45  //@{
46  const char* m_name; ///< Name of the scaler
47  DataArray < Real > m_colscale; ///< column scaling factors
48  DataArray < Real > m_rowscale; ///< row scaling factors
49  bool m_colFirst; ///< do column scaling first
50  bool m_doBoth; ///< do columns and rows
51  SPxOut* spxout; ///< message handler
52  //@}
53 
54  //-------------------------------------
55  /**@name Protected helpers */
56  //@{
57  /// setup scale array for the LP.
58  virtual void setup(SPxLP& lp);
59  /// computes scaling value for a minimum and maximum pair.
60  virtual Real computeScale(Real mini, Real maxi) const;
61  /// iterates through vecset and calls computeScale() for each vector.
62  /**@return maximum ratio between absolute biggest and smallest element for any vector.
63  */
64  virtual Real computeScalingVecs( const SVSet* vecset,
65  const DataArray<Real>& coScaleval,
66  DataArray<Real>& scaleval );
67  /// applies m_colscale and m_rowscale to the \p lp.
68  virtual void applyScaling(SPxLP& lp);
69  //@}
70 
71 public:
72 
73  friend std::ostream& operator<<(std::ostream& s, const SPxScaler& sc);
74 
75  //-------------------------------------
76  /**@name Construction / destruction */
77  //@{
78  /// constructor
79  explicit SPxScaler(const char* name, bool colFirst = false, bool doBoth = true, SPxOut* spxout = NULL);
80  /// copy constructor
81  SPxScaler(const SPxScaler& );
82  /// assignment operator
83  SPxScaler& operator=(const SPxScaler& );
84  /// destructor.
85  virtual ~SPxScaler();
86  /// clone function for polymorphism
87  virtual SPxScaler* clone() const = 0;
88  //@}
89 
90  //-------------------------------------
91  /**@name Access / modification */
92  //@{
93  /// get name of scaler.
94  virtual const char* getName() const;
95  /// set scaling order.
96  virtual void setOrder(bool colFirst);
97  /// set wether column and row scaling should be performed.
98  virtual void setBoth(bool both);
99  /// set message handler
100  virtual void setOutstream(SPxOut& newOutstream)
101  {
102  spxout = &newOutstream;
103  }
104  //@}
105 
106  //-------------------------------------
107  /**@name Scaling */
108  //@{
109  /// scale SPxLP.
110  virtual void scale(SPxLP& lp) = 0;
111  /// unscale dense primal solution vector given in \p x.
112  virtual void unscalePrimal(Vector& x) const;
113  /// unscale dense slack vector given in \p s.
114  virtual void unscaleSlacks(Vector& s) const;
115  /// unscale dense dual solution vector given in \p pi.
116  virtual void unscaleDual(Vector& pi) const;
117  /// unscale dense reduced cost vector given in \p r.
118  virtual void unscaleRedCost(Vector& r) const;
119 
120  /// absolute smallest column scaling factor
121  virtual Real minAbsColscale() const;
122  /// absolute biggest column scaling factor
123  virtual Real maxAbsColscale() const;
124  /// absolute smallest row scaling factor
125  virtual Real minAbsRowscale() const;
126  /// absolute biggest row scaling factor
127  virtual Real maxAbsRowscale() const;
128  /// maximum ratio between absolute biggest and smallest element in any column.
129  virtual Real maxColRatio(const SPxLP& lp) const;
130  /// maximum ratio between absolute biggest and smallest element in any row.
131  virtual Real maxRowRatio(const SPxLP& lp) const;
132  //@}
133 
134  //-------------------------------------
135  /**@name Debugging */
136  //@{
137  /// consistency check
138  virtual bool isConsistent() const;
139  //@}
140 };
141 } // namespace soplex
142 #endif // _SPXSCALER_H_