Scippy

SoPlex

Sequential object-oriented simPlex

spxscaler.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-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.cpp
17  * @brief LP scaling base class.
18  */
19 
20 #include <cmath>
21 
22 #include <iostream>
23 #include <assert.h>
24 #include "soplex/spxscaler.h"
25 #include "soplex/spxlp.h"
26 #include "soplex/dsvector.h"
27 #include "soplex/dvector.h"
28 #include <limits>
29 
30 namespace soplex
31 {
32 
33 std::ostream& operator<<(std::ostream& s, const SPxScaler& sc)
34 {
35  const DataArray < int >& colscaleExp = *(sc.m_activeColscaleExp);
36  DataArray < int > rowccaleExp = *(sc.m_activeRowscaleExp);
37 
38  s << sc.getName() << " scaler:" << std::endl;
39  s << "colscale = [ ";
40  for(int ci = 0; ci < colscaleExp.size(); ++ci )
41  s << colscaleExp[ci] << " ";
42  s << "]" << std::endl;
43 
44  s << "rowscale = [ ";
45  for(int ri = 0; ri < rowccaleExp.size(); ++ri )
46  s << rowccaleExp[ri] << " ";
47  s << "]" << std::endl;
48 
49  return s;
50 }
51 
52 
54  const char* name,
55  bool colFirst,
56  bool doBoth,
57  SPxOut* outstream)
58  : m_name(name)
59  , m_activeColscaleExp(0)
60  , m_activeRowscaleExp(0)
61  , m_colFirst(colFirst)
62  , m_doBoth(doBoth)
63  , spxout(outstream)
64 {
65  assert(SPxScaler::isConsistent());
66 }
67 
69  : m_name(old.m_name)
72  , m_colFirst(old.m_colFirst)
73  , m_doBoth(old.m_doBoth)
74  , spxout(old.spxout)
75 {
76  assert(SPxScaler::isConsistent());
77 }
78 
80 {
81  m_name = 0;
82 }
83 
85 {
86  if (this != &rhs)
87  {
88  m_name = rhs.m_name;
91  m_colFirst = rhs.m_colFirst;
92  m_doBoth = rhs.m_doBoth;
93  spxout = rhs.spxout;
94 
95  assert(SPxScaler::isConsistent());
96  }
97  return *this;
98 }
99 
100 const char* SPxScaler::getName() const
101 {
102 
103  return m_name;
104 }
105 
106 void SPxScaler::setOrder(bool colFirst)
107 {
108 
109  m_colFirst = colFirst;
110 }
111 
112 void SPxScaler::setBoth(bool both)
113 {
114 
115  m_doBoth = both;
116 }
117 
118 void SPxScaler::setRealParam(Real param, const char* name)
119 {}
120 
121 void SPxScaler::setIntParam(int param, const char* name)
122 {}
123 
125 {
126  assert(lp.isConsistent());
127  m_activeColscaleExp = &lp.LPColSetBase<Real>::scaleExp;
128  m_activeRowscaleExp = &lp.LPRowSetBase<Real>::scaleExp;
129  m_activeColscaleExp->reSize(lp.nCols());
131 
132  for( int i = 0; i < lp.nCols(); ++i)
133  (*m_activeColscaleExp)[i] = 0;
134  for( int i = 0; i < lp.nRows(); ++i)
135  (*m_activeRowscaleExp)[i] = 0;
136 
137  lp.lp_scaler = this;
138 }
139 
140 int SPxScaler::computeScaleExp(const SVector& vec, const DataArray<int>& oldScaleExp) const
141 {
142  Real maxi = 0.0;
143 
144  // find largest absolute value after applying existing scaling factors
145  for( int i = 0; i < vec.size(); ++i )
146  {
147  Real x = spxAbs(spxLdexp(vec.value(i), oldScaleExp[vec.index(i)]));
148 
149  if( GT(x, maxi) )
150  maxi = x;
151  }
152  // empty rows/cols are possible
153  if( maxi == 0.0 )
154  return 0;
155  // get exponent corresponding to new scaling factor
156  else
157  {
158  int scaleExp;
159  spxFrexp(1.0 / maxi, &(scaleExp));
160  return scaleExp - 1;
161  }
162 }
163 
164 int SPxScaler::computeScaleExp(const SVectorBase<Rational>& vec, const DataArray<int>& oldScaleExp) const
165 {
166  return 0;
167 }
168 
170 {
171  assert(lp.nCols() == m_activeColscaleExp->size());
172  assert(lp.nRows() == m_activeRowscaleExp->size());
173 
174  DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
175  DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
176 
177  for( int i = 0; i < lp.nRows(); ++i )
178  {
179  SVector& vec = lp.rowVector_w(i);
180  int exp1;
181  int exp2 = rowscaleExp[i];
182 
183  for( int j = 0; j < vec.size(); ++j)
184  {
185  exp1 = colscaleExp[vec.index(j)];
186  vec.value(j) = spxLdexp(vec.value(j), exp1 + exp2);
187  }
188 
189  lp.maxRowObj_w(i) = spxLdexp(lp.maxRowObj(i), exp2);
190 
191  if( lp.rhs(i) < infinity )
192  lp.rhs_w(i) = spxLdexp(lp.rhs_w(i), exp2);
193 
194  if( lp.lhs(i) > -infinity )
195  lp.lhs_w(i) = spxLdexp(lp.lhs_w(i), exp2);
196 
197  MSG_DEBUG( std::cout << "DEBUG: rowscaleExp(" << i << "): " << exp2 << std::endl; )
198  }
199 
200  for( int i = 0; i < lp.nCols(); ++i )
201  {
202  SVector& vec = lp.colVector_w(i);
203  int exp1;
204  int exp2 = colscaleExp[i];
205 
206  for( int j = 0; j < vec.size(); ++j)
207  {
208  exp1 = rowscaleExp[vec.index(j)];
209  vec.value(j) = spxLdexp(vec.value(j), exp1 + exp2);
210  }
211 
212  lp.maxObj_w(i) = spxLdexp(lp.maxObj_w(i), exp2);
213 
214  if( lp.upper(i) < infinity )
215  lp.upper_w(i) = spxLdexp(lp.upper_w(i), -exp2);
216 
217  if( lp.lower(i) > -infinity )
218  lp.lower_w(i) = spxLdexp(lp.lower_w(i), -exp2);
219 
220  MSG_DEBUG( std::cout << "DEBUG: colscaleExp(" << i << "): " << exp2 << std::endl; )
221  }
222 
223  lp.setScalingInfo(true);
224  assert(lp.isConsistent());
225 }
226 
227 /// unscale SPxLP
229 {
230  assert(lp.isScaled());
231 
232  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
233  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
234 
235  for( int i = 0; i < lp.nRows(); ++i )
236  {
237  SVector& vec = lp.rowVector_w(i);
238 
239  int exp1;
240  int exp2 = rowscaleExp[i];
241 
242  for( int j = 0; j < vec.size(); ++j)
243  {
244  exp1 = colscaleExp[vec.index(j)];
245  vec.value(j) = spxLdexp(vec.value(j), -exp1 - exp2);
246  }
247 
248  lp.maxRowObj_w(i) = spxLdexp(lp.maxRowObj(i), -exp2);
249 
250  if( lp.rhs(i) < infinity )
251  lp.rhs_w(i) = spxLdexp(lp.rhs_w(i), -exp2);
252 
253  if( lp.lhs(i) > -infinity )
254  lp.lhs_w(i) = spxLdexp(lp.lhs_w(i), -exp2);
255  }
256 
257  for( int i = 0; i < lp.nCols(); ++i )
258  {
259  SVector& vec = lp.colVector_w(i);
260 
261  int exp1;
262  int exp2 = colscaleExp[i];
263 
264  for( int j = 0; j < vec.size(); ++j)
265  {
266  exp1 = rowscaleExp[vec.index(j)];
267  vec.value(j) = spxLdexp(vec.value(j), -exp1 - exp2);
268  }
269 
270  lp.maxObj_w(i) = spxLdexp(lp.maxObj_w(i), -exp2);
271 
272  if( lp.upper(i) < infinity )
273  lp.upper_w(i) = spxLdexp(lp.upper_w(i), exp2);
274 
275  if( lp.lower(i) > -infinity )
276  lp.lower_w(i) = spxLdexp(lp.lower_w(i), exp2);
277  }
278 
279  lp._isScaled = false;
280  assert(lp.isConsistent());
281 }
282 
283 /// returns scaling factor for column \p i
284 /// todo pass the LP?!
286 {
287  return (*m_activeColscaleExp)[i];
288 }
289 
290 /// returns scaling factor for row \p i
291 /// todo pass the LP?!
293 {
294  return (*m_activeRowscaleExp)[i];
295 }
296 
297 /// gets unscaled column \p i
298 void SPxScaler::getColUnscaled(const SPxLP& lp, int i, DSVector& vec) const
299 {
300  assert(lp.isScaled());
301  assert(i < lp.nCols());
302  assert(i >= 0);
303  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
304  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
305 
306  vec = lp.LPColSet::colVector(i);
307 
308  int exp1;
309  int exp2 = colscaleExp[i];
310 
311  const SVectorReal& col = lp.colVector(i);
312  vec.setMax(col.size());
313  vec.clear();
314 
315  for( int j = 0; j < col.size(); j++ )
316  {
317  exp1 = rowscaleExp[col.index(j)];
318  vec.add(col.index(j), spxLdexp(col.value(j), -exp1 - exp2));
319  }
320 }
321 
322 /// returns maximum absolute value of unscaled column \p i
324 {
325  assert(i < lp.nCols());
326  assert(i >= 0);
327 
328  DataArray < int >& colscaleExp = *m_activeColscaleExp;
329  DataArray < int >& rowscaleExp = *m_activeRowscaleExp;
330  const SVector& colVec = lp.LPColSet::colVector(i);
331 
332  Real max = 0.0;
333  int exp1;
334  int exp2 = colscaleExp[i];
335 
336  for( int j = 0; j < colVec.size(); j++ )
337  {
338  exp1 = rowscaleExp[colVec.index(j)];
339  Real abs = spxAbs(spxLdexp(colVec.value(j), -exp1 - exp2));
340  if( abs > max )
341  max = abs;
342  }
343 
344  return max;
345 }
346 
347 /// returns minimum absolute value of unscaled column \p i
349 {
350  assert(i < lp.nCols());
351  assert(i >= 0);
352 
353  DataArray < int >& colscaleExp = *m_activeColscaleExp;
354  DataArray < int >& rowscaleExp = *m_activeRowscaleExp;
355  const SVector& colVec = lp.LPColSet::colVector(i);
356 
357  Real min = infinity;
358  int exp1;
359  int exp2 = colscaleExp[i];
360 
361  for( int j = 0; j < colVec.size(); j++ )
362  {
363  exp1 = rowscaleExp[colVec.index(j)];
364  Real abs = spxAbs(spxLdexp(colVec.value(j), -exp1 - exp2));
365  if( abs < min )
366  min = abs;
367  }
368 
369  return min;
370 }
371 
372 
373 /// returns unscaled upper bound \p i
375 {
376  assert(lp.isScaled());
377  assert(i < lp.nCols());
378  assert(i >= 0);
379 
380  if( lp.LPColSet::upper(i) < infinity )
381  {
382  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
383  return spxLdexp(lp.LPColSet::upper(i) , colscaleExp[i]);
384  }
385  else
386  return lp.LPColSet::upper(i);
387 }
388 
389 
390 /// gets unscaled upper bound vector
392 {
393  assert(lp.isScaled());
394  assert(lp.LPColSet::upper().dim() == vec.dim());
395 
396  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
397 
398  for( int i = 0; i < lp.LPColSet::upper().dim(); i++)
399  vec[i] = spxLdexp(lp.LPColSet::upper()[i], colscaleExp[i]);
400 }
401 
402 
403 /// returns unscaled upper bound vector of \p lp
405 {
406  assert(lp.isScaled());
407  assert(i < lp.nCols());
408  assert(i >= 0);
409 
410  if( lp.LPColSet::lower(i) > -infinity )
411  {
412  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
413  return spxLdexp(lp.LPColSet::lower(i), colscaleExp[i]);
414  }
415  else
416  return lp.LPColSet::lower(i);
417 }
418 
419 
420 /// returns unscaled lower bound vector of \p lp
422 {
423  assert(lp.isScaled());
424  assert(lp.LPColSet::lower().dim() == vec.dim());
425 
426  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
427 
428  for( int i = 0; i < lp.LPColSet::lower().dim(); i++)
429  vec[i] = spxLdexp(lp.LPColSet::lower()[i], colscaleExp[i]);
430 }
431 
432 /// returns unscaled objective function coefficient of \p i
434 {
435  assert(lp.isScaled());
436  assert(i < lp.nCols());
437  assert(i >= 0);
438 
439  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
440 
441  return spxLdexp(lp.LPColSet::maxObj(i) , -colscaleExp[i]);
442 }
443 
444 
445 /// gets unscaled objective function coefficient of \p i
447 {
448  assert(lp.isScaled());
449  assert(lp.LPColSet::maxObj().dim() == vec.dim());
450 
451  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
452 
453  for( int i = 0; i < lp.LPColSet::maxObj().dim(); i++)
454  vec[i] = spxLdexp(lp.LPColSet::maxObj()[i], -colscaleExp[i]);
455 }
456 
457 /// gets unscaled row \p i
458 void SPxScaler::getRowUnscaled(const SPxLP& lp, int i, DSVector& vec) const
459 {
460  assert(lp.isScaled());
461  assert(i < lp.nRows());
462  assert(i >= 0);
463 
464  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
465  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
466  int exp1;
467  int exp2 = rowscaleExp[i];
468 
469  const SVectorReal& row = lp.rowVector(i);
470  vec.setMax(row.size());
471  vec.clear();
472 
473  for( int j = 0; j < row.size(); j++ )
474  {
475  exp1 = colscaleExp[row.index(j)];
476  vec.add(row.index(j), spxLdexp(row.value(j), -exp1 - exp2));
477  }
478 }
479 
480 /// returns maximum absolute value of unscaled row \p i
482 {
483  assert(i < lp.nRows());
484  assert(i >= 0);
485  DataArray < int >& colscaleExp = *m_activeColscaleExp;
486  DataArray < int >& rowscaleExp = *m_activeRowscaleExp;
487  const SVector& rowVec = lp.LPRowSet::rowVector(i);
488 
489  Real max = 0.0;
490 
491  int exp1;
492  int exp2 = rowscaleExp[i];
493 
494  for( int j = 0; j < rowVec.size(); j++ )
495  {
496  exp1 = colscaleExp[rowVec.index(j)];
497  Real abs = spxAbs(spxLdexp(rowVec.value(j), -exp1 - exp2));
498 
499  if( GT(abs, max) )
500  max = abs;
501  }
502 
503  return max;
504 }
505 
506 /// returns minimum absolute value of unscaled row \p i
508 {
509  assert(i < lp.nRows());
510  assert(i >= 0);
511  DataArray < int >& colscaleExp = *m_activeColscaleExp;
512  DataArray < int >& rowscaleExp = *m_activeRowscaleExp;
513  const SVector& rowVec = lp.LPRowSet::rowVector(i);
514 
515  Real min = infinity;
516 
517  int exp1;
518  int exp2 = rowscaleExp[i];
519 
520  for( int j = 0; j < rowVec.size(); j++ )
521  {
522  exp1 = colscaleExp[rowVec.index(j)];
523  Real abs = spxAbs(spxLdexp(rowVec.value(j), -exp1 - exp2));
524 
525  if( LT(abs, min) )
526  min = abs;
527  }
528 
529  return min;
530 }
531 
532 /// returns unscaled right hand side \p i
534 {
535  assert(lp.isScaled());
536  assert(i < lp.nRows());
537  assert(i >= 0);
538 
539  if( lp.LPRowSet::rhs(i) < infinity )
540  {
541  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
542  return spxLdexp(lp.LPRowSet::rhs(i) , -rowscaleExp[i]);
543  }
544  else
545  return lp.LPRowSet::rhs(i);
546 }
547 
548 
549 /// gets unscaled right hand side vector
551 {
552  assert(lp.isScaled());
553  assert(lp.LPRowSet::rhs().dim() == vec.dim());
554 
555  for( int i = 0; i < lp.LPRowSet::rhs().dim(); i++)
556  {
557  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
558  vec[i] = spxLdexp(lp.LPRowSet::rhs()[i], -rowscaleExp[i]);
559  }
560 }
561 
562 
563 /// returns unscaled left hand side \p i of \p lp
565 {
566  assert(lp.isScaled());
567  assert(i < lp.nRows());
568  assert(i >= 0);
569 
570  if( lp.LPRowSet::lhs(i) > -infinity )
571  {
572  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
573  return spxLdexp(lp.LPRowSet::lhs(i) , -rowscaleExp[i]);
574  }
575  else
576  return lp.LPRowSet::lhs(i);
577 }
578 
579 /// returns unscaled left hand side vector of \p lp
581 {
582  assert(lp.isScaled());
583  assert(lp.LPRowSet::lhs().dim() == vec.dim());
584 
585  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
586 
587  for( int i = 0; i < lp.LPRowSet::lhs().dim(); i++)
588  vec[i] = spxLdexp(lp.LPRowSet::lhs()[i], -rowscaleExp[i]);
589 }
590 
591 /// returns unscaled coefficient of \p lp
592 Real SPxScaler::getCoefUnscaled(const SPxLPBase<Real>& lp, int row, int col) const
593 {
594  assert(lp.isScaled());
595  assert(row < lp.nRows());
596  assert(col < lp.nCols());
597 
598  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
599  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
600 
601  return spxLdexp(lp.colVector(col)[row], - rowscaleExp[row] - colscaleExp[col]);
602 }
603 
605 {
606  assert(lp.isScaled());
607 
608  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
609 
610  assert(x.dim() == colscaleExp.size());
611 
612  for( int j = 0; j < x.dim(); ++j )
613  x[j] = spxLdexp(x[j], colscaleExp[j]);
614 }
615 
617 {
618  assert(lp.isScaled());
619 
620  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
621 
622  assert(s.dim() == rowscaleExp.size());
623 
624  for( int i = 0; i < s.dim(); ++i )
625  s[i] = spxLdexp(s[i], -rowscaleExp[i]);
626 }
627 
629 {
630  assert(lp.isScaled());
631 
632  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
633 
634  assert(pi.dim() == rowscaleExp.size());
635 
636  for( int i = 0; i < pi.dim(); ++i )
637  pi[i] = spxLdexp(pi[i], rowscaleExp[i]);
638 }
639 
641 {
642  assert(lp.isScaled());
643 
644  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
645 
646  assert(r.dim() == colscaleExp.size());
647 
648  for( int j = 0; j < r.dim(); ++j )
649  r[j] = spxLdexp(r[j], -colscaleExp[j]);
650 }
651 
653 {
654  assert(lp.isScaled());
655 
656  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
657 
658  assert(ray.dim() == colscaleExp.size());
659 
660  for( int j = 0; j < ray.dim(); ++j )
661  ray[j] = spxLdexp(ray[j], colscaleExp[j]);
662 }
663 
665 {
666  assert(lp.isScaled());
667 
668  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
669 
670  assert(ray.dim() == rowscaleExp.size());
671 
672  for( int i = 0; i < ray.dim(); ++i )
673  ray[i] = spxLdexp(ray[i], rowscaleExp[i]);
674 }
675 
676 void SPxScaler::scaleObj(const SPxLPBase<Real>& lp, VectorReal& origObj) const
677 {
678  assert(lp.isScaled());
679 
680  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
681 
682  for( int i = 0; i < origObj.dim(); ++i )
683  {
684  origObj[i] = spxLdexp(origObj[i], colscaleExp[i]);
685  }
686 }
687 
688 Real SPxScaler::scaleObj(const SPxLPBase<Real>& lp, int i, Real origObj) const
689 {
690  assert(lp.isScaled());
691  assert(i < lp.nCols());
692  assert(i >= 0);
693 
694  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
695  int exp = colscaleExp[i];
696 
697  return spxLdexp(origObj, exp);
698 }
699 
700 Real SPxScaler::scaleElement(const SPxLPBase<Real>& lp, int row, int col, Real val) const
701 {
702  assert(lp.isScaled());
703  assert(col < lp.nCols());
704  assert(col >= 0);
705  assert(row < lp.nRows());
706  assert(row >= 0);
707 
708  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
709  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
710 
711  return spxLdexp(val, colscaleExp[col] + rowscaleExp[row]);
712 }
713 
714 Real SPxScaler::scaleLower(const SPxLPBase<Real>& lp, int col, Real lower) const
715 {
716  assert(lp.isScaled());
717  assert(col < lp.nCols());
718  assert(col >= 0);
719 
720  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
721 
722  return spxLdexp(lower, -colscaleExp[col]);
723 }
724 
725 Real SPxScaler::scaleUpper(const SPxLPBase<Real>& lp, int col, Real upper) const
726 {
727  assert(lp.isScaled());
728  assert(col < lp.nCols());
729  assert(col >= 0);
730 
731  const DataArray < int >& colscaleExp = lp.LPColSetBase<Real>::scaleExp;
732 
733  return spxLdexp(upper, -colscaleExp[col]);
734 }
735 
736 Real SPxScaler::scaleLhs(const SPxLPBase<Real>& lp, int row, Real lhs) const
737 {
738  assert(lp.isScaled());
739  assert(row < lp.nRows());
740  assert(row >= 0);
741 
742  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
743 
744  return spxLdexp(lhs, rowscaleExp[row]);
745 }
746 
747 Real SPxScaler::scaleRhs(const SPxLPBase<Real>& lp, int row, Real rhs) const
748 {
749  assert(lp.isScaled());
750  assert(row < lp.nRows());
751  assert(row >= 0);
752 
753  const DataArray < int >& rowscaleExp = lp.LPRowSetBase<Real>::scaleExp;
754 
755  return spxLdexp(rhs, rowscaleExp[row]);
756 }
757 
759 {
760  const DataArray < int >& colscaleExp = *m_activeColscaleExp;
761 
762  Real mini = infinity;
763 
764  for( int i = 0; i < colscaleExp.size(); ++i )
765  if( spxAbs(spxLdexp(1.0, colscaleExp[i])) < mini )
766  mini = spxAbs(spxLdexp(1.0, colscaleExp[i]));
767 
768  return mini;
769 }
770 
772 {
773  const DataArray < int >& colscaleExp = *m_activeColscaleExp;
774 
775  Real maxi = 0.0;
776 
777  for( int i = 0; i < colscaleExp.size(); ++i )
778  if( spxAbs(spxLdexp(1.0, colscaleExp[i])) > maxi )
779  maxi = spxAbs(spxLdexp(1.0, colscaleExp[i]));
780 
781 
782  return maxi;
783 }
784 
786 {
787  const DataArray < int >& rowscaleExp = *m_activeRowscaleExp;
788 
789  int mini = std::numeric_limits<int>::max();
790 
791  for( int i = 0; i < rowscaleExp.size(); ++i )
792  if( rowscaleExp[i] < mini )
793  mini = rowscaleExp[i];
794 
795  return spxLdexp(1.0, mini);
796 }
797 
799 {
800  const DataArray < int >& rowscaleExp = *m_activeRowscaleExp;
801 
802  int maxi = std::numeric_limits<int>::min();
803 
804  for( int i = 0; i < rowscaleExp.size(); ++i )
805  if( rowscaleExp[i] > maxi )
806  maxi = rowscaleExp[i];
807 
808  return spxLdexp(1.0, maxi);
809 }
810 
811 /** \f$\max_{j\in\mbox{ cols}}
812  * \left(\frac{\max_{i\in\mbox{ rows}}|a_ij|}
813  * {\min_{i\in\mbox{ rows}}|a_ij|}\right)\f$
814  */
816 {
817 
818  Real pmax = 0.0;
819 
820  for(int i = 0; i < lp.nCols(); ++i )
821  {
822  const SVector& vec = lp.colVector(i);
823  Real mini = infinity;
824  Real maxi = 0.0;
825 
826  for(int j = 0; j < vec.size(); ++j)
827  {
828  Real x = spxAbs(vec.value(j));
829 
830  if( isZero(x) )
831  continue;
832  if( x < mini )
833  mini = x;
834  if( x > maxi )
835  maxi = x;
836  }
837 
838  if( mini == infinity )
839  continue;
840 
841  Real p = maxi / mini;
842 
843  if (p > pmax)
844  pmax = p;
845  }
846  return pmax;
847 }
848 
849 /** \f$\max_{i\in\mbox{ rows}}
850  * \left(\frac{\max_{j\in\mbox{ cols}}|a_ij|}
851  * {\min_{j\in\mbox{ cols}}|a_ij|}\right)\f$
852  */
854 {
855 
856  Real pmax = 0.0;
857 
858  for(int i = 0; i < lp.nRows(); ++i )
859  {
860  const SVector& vec = lp.rowVector(i);
861  Real mini = infinity;
862  Real maxi = 0.0;
863 
864  for(int j = 0; j < vec.size(); ++j)
865  {
866  Real x = spxAbs(vec.value(j));
867 
868  if( isZero(x) )
869  continue;
870  if( x < mini )
871  mini = x;
872  if( x > maxi )
873  maxi = x;
874  }
875 
876  if( mini == infinity )
877  continue;
878 
879  Real p = maxi / mini;
880 
881  if (p > pmax)
882  pmax = p;
883  }
884  return pmax;
885 }
886 
887 void SPxScaler::computeExpVec(const std::vector<Real>& vec, DataArray<int>& vecExp)
888 {
889  assert(vec.size() == unsigned(vecExp.size()));
890 
891  for( unsigned i = 0; i < vec.size(); ++i )
892  {
893  frexp(vec[i], &(vecExp[int(i)]));
894  vecExp[int(i)] -= 1;
895  }
896 }
897 
899 {
900 #ifdef ENABLE_CONSISTENCY_CHECKS
902 #else
903  return true;
904 #endif
905 }
906 
907 
908 } // namespace soplex
const VectorBase< R > & rhs() const
Returns right hand side vector.
Definition: spxlpbase.h:219
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:3908
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
bool isConsistent() const
consistency check
Definition: dataarray.h:288
virtual void unscalePrimal(const SPxLPBase< Real > &lp, Vector &x) const
unscale dense primal solution vector given in x.
Definition: spxscaler.cpp:604
const VectorBase< R > & upper() const
Returns upper bound vector.
Definition: spxlpbase.h:456
THREADLOCAL const Real infinity
Definition: spxdefines.cpp:26
bool _isScaled
true, if scaling has been performed
Definition: spxlpbase.h:113
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
R & maxObj_w(int i)
Returns objective value of column i for maximization problem.
Definition: spxlpbase.h:1938
int size() const
Number of used indices.
Definition: svectorbase.h:152
bool isScaled() const
Returns true if and only if the LP is scaled.
Definition: spxlpbase.h:139
bool LT(Real a, Real b, Real eps=Param::epsilon())
returns true iff a < b + eps
Definition: spxdefines.h:388
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
R & value(int n)
Reference to value of n &#39;th nonzero.
Definition: svectorbase.h:252
virtual ~SPxScaler()
destructor.
Definition: spxscaler.cpp:79
virtual bool isConsistent() const
consistency check
Definition: spxscaler.cpp:898
R & rhs_w(int i)
Returns right hand side of row i.
Definition: spxlpbase.h:1920
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
SVectorBase< R > & rowVector_w(int i)
Definition: spxlpbase.h:2165
Real spxFrexp(Real y, int *exp)
Definition: spxdefines.h:354
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:151
void add(const SVectorBase< S > &vec)
Append nonzeros of sv.
Definition: dsvectorbase.h:216
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
Real spxLdexp(Real x, int exp)
returns x * 2^exp
Definition: spxdefines.h:348
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
#define MSG_DEBUG(x)
Definition: spxdefines.h:132
virtual void unscale(SPxLPBase< Real > &lp)
unscale SPxLP
Definition: spxscaler.cpp:228
SPxOut * spxout
message handler
Definition: spxscaler.h:88
bool GT(Real a, Real b, Real eps=Param::epsilon())
returns true iff a > b + eps
Definition: spxdefines.h:400
int & index(int n)
Reference to index of n &#39;th nonzero.
Definition: svectorbase.h:234
std::ostream & operator<<(std::ostream &s, const VectorBase< R > &vec)
Output operator.
Definition: basevectors.h:1123
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
virtual void getLowerUnscaled(const SPxLPBase< Real > &lp, Vector &vec) const
gets unscaled lower bound vector
Definition: spxscaler.cpp:421
const VectorBase< R > & lhs() const
Returns left hand side vector.
Definition: spxlpbase.h:253
R & lower_w(int i)
Returns lower bound of column i.
Definition: spxlpbase.h:1950
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
LPColSetBase(int pmax=-1, int pmemmax=-1)
Default constructor.
Definition: lpcolsetbase.h:585
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
const VectorBase< R > & maxRowObj() const
Definition: spxlpbase.h:297
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
void setScalingInfo(bool scaled)
set whether the LP is scaled or not
Definition: spxlpbase.h:145
R & maxRowObj_w(int i)
Returns objective function value of row i.
Definition: spxlpbase.h:1932
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
int dim() const
Dimension of vector.
Definition: vectorbase.h:215
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
void clear()
Remove all indices.
Definition: svectorbase.h:422
virtual Real getColMinAbsUnscaled(const SPxLPBase< Real > &lp, int i) const
returns minumum absolute value of unscaled column i
Definition: spxscaler.cpp:348
R & upper_w(int i)
Returns upper bound of column i.
Definition: spxlpbase.h:1944
SPxScaler * lp_scaler
points to the scaler if the lp has been scaled, to 0 otherwise
Definition: spxlpbase.h:114
bool m_colFirst
do column scaling first
Definition: spxscaler.h:86
LP scaling base class.
SPxScaler(const char *name, bool colFirst=false, bool doBoth=true, SPxOut *spxout=NULL)
constructor
Definition: spxscaler.cpp:53
Saving LPs in a form suitable for SoPlex.
const SVectorBase< R > & rowVector(int i) const
Gets row vector of row i.
Definition: spxlpbase.h:204
Dynamic sparse vectors.
LP scaler abstract base class.Instances of classes derived from SPxScaler may be loaded to SoPlex in ...
Definition: spxscaler.h:76
LPRowSetBase(int pmax=-1, int pmemmax=-1)
Default constructor.
Definition: lprowsetbase.h:668
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
int size() const
return nr. of elements.
Definition: dataarray.h:211
bool isConsistent() const
Consistency check.
Definition: spxlpbase.h:1867
virtual int getRowScaleExp(int i) const
returns scaling factor for row i
Definition: spxscaler.cpp:292
const SVectorBase< R > & colVector(int i) const
Returns column vector of column i.
Definition: spxlpbase.h:373
virtual void getColUnscaled(const SPxLPBase< Real > &lp, int i, DSVector &vec) const
gets unscaled column i
Definition: spxscaler.cpp:298
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:157
virtual Real getCoefUnscaled(const SPxLPBase< Real > &lp, int row, int col) const
returns unscaled coefficient of lp
Definition: spxscaler.cpp:592
bool isZero(Real a, Real eps=Param::epsilon())
returns true iff |a| <= eps
Definition: spxdefines.h:412
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
SVectorBase< R > & colVector_w(int i)
Returns the LP as an LPRowSet.
Definition: spxlpbase.h:2159
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
void reSize(int newsize)
reset size to newsize.
Definition: dataarray.h:223
const char * m_name
Name of the scaler.
Definition: spxscaler.h:83
const VectorBase< R > & lower() const
Returns (internal and possibly scaled) lower bound vector.
Definition: spxlpbase.h:483
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
void setMax(int newmax=1)
Reset nonzero memory to >= newmax.
Definition: dsvectorbase.h:248
R & lhs_w(int i)
Returns left hand side of row i.
Definition: spxlpbase.h:1926