Scippy

SoPlex

Sequential object-oriented simPlex

spxequilisc.cpp
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-2017 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 spxequilisc.cpp
17  * @brief Equilibrium row/column scaling.
18  */
19 #include <assert.h>
20 
21 #include "spxequilisc.h"
22 #include "spxout.h"
23 #include "spxlpbase.h"
24 #include "spxlp.h"
25 #include "soplex.h"
26 
27 namespace soplex
28 {
29 static const char* makename(bool doBoth)
30 {
31  return doBoth ? "bi-Equilibrium" : "uni-Equilibrium";
32 }
33 
35  const SVSet* vecset,
36  const DataArray<int>& coScaleExp,
37  DataArray<int>& scaleExp)
38  {
39  for( int i = 0; i < vecset->num(); ++i )
40  {
41  const SVector& vec = (*vecset)[i];
42 
43  Real maxi = 0.0;
44 
45  for( int j = 0; j < vec.size(); ++j )
46  {
47  Real x = spxAbs(spxLdexp(vec.value(j), coScaleExp[vec.index(j)]));
48 
49  if( GT(x, maxi) )
50  maxi = x;
51  }
52  // empty rows/cols are possible
53  if( maxi == 0.0 )
54  maxi = 1.0;
55 
56  assert(maxi > 0.0);
57 
58  spxFrexp(1.0 / maxi, &(scaleExp[i]));
59 
60  scaleExp[i] -= 1;
61  }
62  }
63 
65  : SPxScaler(makename(doBoth), false, doBoth)
66 {}
67 
69  : SPxScaler(old)
70 {}
71 
73 {
74  if(this != &rhs)
75  {
77  }
78 
79  return *this;
80 }
81 
82 
83 void SPxEquiliSC::scale(SPxLP& lp, bool persistent)
84 {
85 
86  MSG_INFO1( (*spxout), (*spxout) << "Equilibrium scaling LP" << (persistent ? " (persistent)" : "") << std::endl; )
87 
88  setup(lp);
89 
90  /* We want to do the direction first, which has a lower maximal ratio,
91  * since the lowest value in the scaled matrix is bounded from below by
92  * the inverse of the maximum ratio of the direction that is done first
93  * Example:
94  * Rowratio
95  * 0.1 1 10
96  * 10 1 10
97  *
98  * Colratio 100 1
99  *
100  * Row first => Col next =>
101  * 0.1 1 0.1 1
102  * 1 0.1 1 0.1
103  *
104  * Col first => Row next =>
105  * 0.01 1 0.01 1
106  * 1 1 1 1
107  *
108  */
109  Real colratio = maxColRatio(lp);
110  Real rowratio = maxRowRatio(lp);
111 
112  bool colFirst = colratio < rowratio;
113 
114  MSG_INFO2( (*spxout), (*spxout) << "before scaling:"
115  << " min= " << lp.minAbsNzo()
116  << " max= " << lp.maxAbsNzo()
117  << " col-ratio= " << colratio
118  << " row-ratio= " << rowratio
119  << std::endl; )
120 
121  if (colFirst)
122  {
124 
125  if (m_doBoth)
127  }
128  else
129  {
131 
132  if (m_doBoth)
134  }
135 
136  /* scale */
137  applyScaling(lp);
138 
139  MSG_INFO3( (*spxout), (*spxout) << "Row scaling min= " << minAbsRowscale()
140  << " max= " << maxAbsRowscale()
141  << std::endl
142  << "Col scaling min= " << minAbsColscale()
143  << " max= " << maxAbsColscale()
144  << std::endl; )
145 
146  MSG_INFO2( (*spxout), (*spxout) << "after scaling: "
147  << " min= " << lp.minAbsNzo(false)
148  << " max= " << lp.maxAbsNzo(false)
149  << " col-ratio= " << maxColRatio(lp)
150  << " row-ratio= " << maxRowRatio(lp)
151  << std::endl; )
152 
153 }
154 
155 } // namespace soplex
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:3909
virtual void setup(SPxLPBase< Real > &lp)
clear and setup scaling arrays in the LP
Definition: spxscaler.cpp:124
virtual void scale(SPxLPBase< Real > &lp, bool persistent=false)
Scale the loaded SPxLP.
Definition: spxequilisc.cpp:83
virtual R minAbsNzo(bool unscaled=true) const
Absolute smallest non-zero element in (possibly scaled) LP.
static const char * makename(bool doBoth)
Definition: spxequilisc.cpp:29
int size() const
Number of used indices.
Definition: svectorbase.h:152
virtual Real maxRowRatio(const SPxLPBase< Real > &lp) const
maximum ratio between absolute biggest and smallest element in any row.
Definition: spxscaler.cpp:854
R & value(int n)
Reference to value of n &#39;th nonzero.
Definition: svectorbase.h:254
SPxEquiliSC(bool doBoth=true)
default constructor (this scaler makes no use of inherited member m_colFirst)
Definition: spxequilisc.cpp:64
Saving LPs in a form suitable for SoPlex.
Real spxFrexp(Real y, int *exp)
Definition: spxdefines.h:353
Wrapper for different output streams and verbosity levels.
DataArray< int > * m_activeColscaleExp
pointer to currently active column scaling factors
Definition: spxscaler.h:83
virtual void applyScaling(SPxLPBase< Real > &lp)
applies m_colscale and m_rowscale to the lp.
Definition: spxscaler.cpp:171
Real spxLdexp(Real x, int exp)
returns x * 2^exp
Definition: spxdefines.h:347
double Real
Definition: spxdefines.h:215
SPxOut * spxout
message handler
Definition: spxscaler.h:87
bool GT(Real a, Real b, Real eps=Param::epsilon())
returns true iff a > b + eps
Definition: spxdefines.h:399
int & index(int n)
Reference to index of n &#39;th nonzero.
Definition: svectorbase.h:236
#define MSG_INFO2(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO2.
Definition: spxdefines.h:117
virtual Real maxAbsColscale() const
absolute biggest column scaling factor
Definition: spxscaler.cpp:776
virtual Real minAbsColscale() const
absolute smallest column scaling factor
Definition: spxscaler.cpp:763
Preconfigured SoPlex LP solver.
#define MSG_INFO3(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO3.
Definition: spxdefines.h:119
DataArray< int > * m_activeRowscaleExp
pointer to currently active row scaling factors
Definition: spxscaler.h:84
virtual Real minAbsRowscale() const
absolute smallest row scaling factor
Definition: spxscaler.cpp:790
Everything should be within this namespace.
Saving LPs in a form suitable for SoPlex.
LP scaler abstract base class.Instances of classes derived from SPxScaler may be loaded to SoPlex in ...
Definition: spxscaler.h:75
virtual Real maxAbsRowscale() const
absolute biggest row scaling factor
Definition: spxscaler.cpp:803
#define MSG_INFO1(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO1.
Definition: spxdefines.h:115
SPxEquiliSC & operator=(const SPxEquiliSC &)
assignment operator
Definition: spxequilisc.cpp:72
const SVSetBase< R > * colSet() const
Returns the complete SVSetBase.
Definition: lpcolsetbase.h:68
bool m_doBoth
do columns and rows
Definition: spxscaler.h:86
virtual Real maxColRatio(const SPxLPBase< Real > &lp) const
maximum ratio between absolute biggest and smallest element in any column.
Definition: spxscaler.cpp:820
LP equilibrium scaling.
const SVSetBase< R > * rowSet() const
Returns the complete SVSet.
Definition: lprowsetbase.h:69
Equilibrium row/column scaling.This SPxScaler implementation performs equilibrium scaling of the LPs ...
Definition: spxequilisc.h:35
static void computeScalingExpVec(const SVSet *vecset, const DataArray< int > &coScaleExp, DataArray< int > &scaleExp)
Definition: spxequilisc.cpp:34
int num() const
Current number of SVectorBases.
Definition: svsetbase.h:746
virtual R maxAbsNzo(bool unscaled=true) const
Absolute biggest non-zero element in (in rational case possibly scaled) LP.
SPxScaler & operator=(const SPxScaler &)
assignment operator
Definition: spxscaler.cpp:84