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