Scippy

SoPlex

Sequential object-oriented simPlex

spxlpbase.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 spxlpbase.h
17  * @brief Saving LPs in a form suitable for SoPlex.
18  */
19 #ifndef _SPXLPBASE_H_
20 #define _SPXLPBASE_H_
21 
22 /* undefine SOPLEX_DEBUG flag from including files; if SOPLEX_DEBUG should be defined in this file, do so below */
23 #ifdef SOPLEX_DEBUG
24 #define SOPLEX_DEBUG_SPXLPBASE
25 #undef SOPLEX_DEBUG
26 #endif
27 
28 #include <assert.h>
29 #include <iostream>
30 #include <iomanip>
31 #include <typeinfo>
32 
33 #include "soplex/spxdefines.h"
34 #include "soplex/basevectors.h"
35 #include "soplex/dataarray.h"
36 #include "soplex/datakey.h"
37 #include "soplex/spxid.h"
38 #include "soplex/lprowbase.h"
39 #include "soplex/lpcolbase.h"
40 #include "soplex/lprowsetbase.h"
41 #include "soplex/lpcolsetbase.h"
42 #include "soplex/nameset.h"
43 #include "soplex/didxset.h"
44 #include "soplex/spxfileio.h"
45 #include "soplex/spxscaler.h"
46 
47 
48 namespace soplex
49 {
50 class SPxSolver;
51 
52 /**@brief Saving LPs in a form suitable for SoPlex.
53  * @ingroup Algo
54  *
55  * Class SPxLPBase provides the data structures required for saving a linear program in the form
56  * \f[
57  * \begin{array}{rl}
58  * \hbox{max} & c^T x \\
59  * \hbox{s.t.} & l_r \le Ax \le u_r \\
60  * & l_c \le x \le u_c
61  * \end{array}
62  * \f]
63  * suitable for solving with SoPlex. This includes:
64  * - SVSetBase%s for both columns and rows
65  * - objective Vector
66  * - upper and lower bound Vectors for variables (\f$l_c\f$ and \f$u_c\f$)
67  * - upper and lower bound Vectors for inequalities (\f$l_r\f$ and \f$u_r\f$)
68  *
69  * Note, that the optimization sense is not saved directly. Instead, the objective function are multiplied by -1 to
70  * transform the LP to our standard form maximizing the objective function. However, the sense of the loaded LP can be
71  * retrieved with method #spxSense().
72  *
73  * Further, equality constraints are modeled by \f$l_r = u_r\f$. Analogously, fixed variables have \f$l_c = u_c\f$.
74  *
75  * #SPxLPBase%s are saved as an SVSet, both for columns and rows. Note that this is redundant but eases the access.
76  */
77 
78 
79 template < class R >
80 class SPxLPBase : protected LPRowSetBase<R>, protected LPColSetBase<R>
81 {
82  template < class S > friend class SPxLPBase;
83  friend class SPxBasis;
84  friend class SPxScaler;
85  friend class SPxEquiliSC;
86  friend class SPxLeastSqSC;
87  friend class SPxGeometSC;
88  friend class SPxMainSM;
89 
90 public:
91 
92  // ------------------------------------------------------------------------------------------------------------------
93  /**@name Types */
94  //@{
95 
96  /// Optimization sense.
97  enum SPxSense
98  {
99  MAXIMIZE = 1,
100  MINIMIZE = -1
101  };
102 
103  //@}
104 
105 private:
106 
107  // ------------------------------------------------------------------------------------------------------------------
108  /**@name Data */
109  //@{
110 
111  SPxSense thesense; ///< optimization sense.
112  R offset; ///< offset computed, e.g., in simplification step
113  bool _isScaled; ///< true, if scaling has been performed
114  SPxScaler* lp_scaler; ///< points to the scaler if the lp has been scaled, to 0 otherwise
115 
116  //@}
117 
118 public:
119 
120  // message handler
122 
123 public:
124 
125  void setOutstream(SPxOut& newOutstream)
126  {
127  spxout = &newOutstream;
128  }
129 
130  // ------------------------------------------------------------------------------------------------------------------
131 
132  /// unscales the lp and clears basis
133  void unscaleLP();
134 
135  /**@name Inquiry */
136  //@{
137 
138  /// Returns true if and only if the LP is scaled
139  bool isScaled() const
140  {
141  return _isScaled;
142  }
143 
144  /// set whether the LP is scaled or not
145  void setScalingInfo(bool scaled)
146  {
147  _isScaled = scaled;
148  }
149 
150  /// Returns number of rows in LP.
151  int nRows() const
152  {
153  return LPRowSetBase<R>::num();
154  }
155 
156  /// Returns number of columns in LP.
157  int nCols() const
158  {
159  return LPColSetBase<R>::num();
160  }
161 
162  /// Returns number of nonzeros in LP.
163  int nNzos() const
164  {
165 
166  int n = 0;
167  for( int i = 0; i < nCols(); ++i )
168  n += colVector(i).size();
169 
170  return n;
171  }
172 
173  /// Absolute smallest non-zero element in (possibly scaled) LP.
174  virtual R minAbsNzo(bool unscaled = true) const;
175 
176  /// Absolute biggest non-zero element in (in rational case possibly scaled) LP.
177  virtual R maxAbsNzo(bool unscaled = true) const;
178 
179  /// Gets \p i 'th row.
180  void getRow(int i, LPRowBase<R>& row) const
181  {
182  row.setLhs(lhs(i));
183  row.setRhs(rhs(i));
184  row.setObj(rowObj(i));
186  }
187 
188  /// Gets row with identifier \p id.
189  void getRow(const SPxRowId& id, LPRowBase<R>& row) const
190  {
191  getRow(number(id), row);
192  }
193 
194  /// Gets rows \p start, ... \p end.
195  void getRows(int start, int end, LPRowSetBase<R>& set) const
196  {
197  set.clear();
198 
199  for( int i = start; i <= end; i++ )
200  set.add(lhs(i), rowVector(i), rhs(i), rowObj(i));
201  }
202 
203  /// Gets row vector of row \p i.
204  const SVectorBase<R>& rowVector(int i) const
205  {
206  return LPRowSetBase<R>::rowVector(i);
207  }
208 
209  /// Gets row vector of row with identifier \p id.
210  const SVectorBase<R>& rowVector(const SPxRowId& id) const
211  {
212  return LPRowSetBase<R>::rowVector(id);
213  }
214 
215  /// Gets unscaled row vector of row \p i.
216  void getRowVectorUnscaled(int i, DSVectorBase<Real>& vec) const;
217 
218  /// Returns right hand side vector.
219  const VectorBase<R>& rhs() const
220  {
221  return LPRowSetBase<R>::rhs();
222  }
223 
224  /// Returns right hand side of row number \p i.
225  const R& rhs(int i) const
226  {
227  return LPRowSetBase<R>::rhs(i);
228  }
229 
230 
231  /// Returns right hand side of row with identifier \p id.
232  const R& rhs(const SPxRowId& id) const
233  {
234  return LPRowSetBase<R>::rhs(id);
235  }
236 
237  /// Gets (internal and possibly scaled) right hand side vector.
238  void getRhs(VectorBase<R>& vec) const
239  {
240  vec = LPRowSetBase<R>::rhs();
241  }
242 
243  /// Gets unscaled right hand side vector.
244  void getRhsUnscaled(VectorBase<Real>& vec) const;
245 
246  /// Returns unscaled right hand side of row number \p i.
247  R rhsUnscaled(int i) const;
248 
249  /// Returns unscaled right hand side of row with identifier \p id.
250  R rhsUnscaled(const SPxRowId& id) const;
251 
252  /// Returns left hand side vector.
253  const VectorBase<R>& lhs() const
254  {
255  return LPRowSetBase<R>::lhs();
256  }
257 
258  /// Returns left hand side of row number \p i.
259  const R& lhs(int i) const
260  {
261  return LPRowSetBase<R>::lhs(i);
262  }
263 
264  /// Returns left hand side of row with identifier \p id.
265  const R& lhs(const SPxRowId& id) const
266  {
267  return LPRowSetBase<R>::lhs(id);
268  }
269 
270  /// Gets row objective function vector.
271  void getRowObj(VectorBase<R>& prowobj) const
272  {
273  prowobj = LPRowSetBase<R>::obj();
274  if( spxSense() == MINIMIZE )
275  prowobj *= -1.0;
276  }
277 
278  ///
279  R rowObj(int i) const
280  {
281  if( spxSense() == MINIMIZE )
282  return -maxRowObj(i);
283  else
284  return maxRowObj(i);
285  }
286 
287  /// Returns row objective function value of row with identifier \p id.
288  R rowObj(const SPxRowId& id) const
289  {
290  if( spxSense() == MINIMIZE )
291  return -maxRowObj(id);
292  else
293  return maxRowObj(id);
294  }
295 
296  ///
297  const VectorBase<R>& maxRowObj() const
298  {
299  return LPRowSetBase<R>::obj();
300  }
301 
302  ///
303  const R& maxRowObj(int i) const
304  {
305  return LPRowSetBase<R>::obj(i);
306  }
307 
308  /// Returns row objective function value of row with identifier \p id.
309  const R& maxRowObj(const SPxRowId& id) const
310  {
311  return LPRowSetBase<R>::obj(id);
312  }
313 
314  /// Returns unscaled left hand side vector.
315  void getLhsUnscaled(VectorBase<Real>& vec) const;
316 
317  /// Returns unscaled left hand side of row number \p i.
318  R lhsUnscaled(int i) const;
319 
320  /// Returns left hand side of row with identifier \p id.
321  R lhsUnscaled(const SPxRowId& id) const;
322 
323  /// Returns the inequality type of the \p i'th LPRow.
324  typename LPRowBase<R>::Type rowType(int i) const
325  {
326  return LPRowSetBase<R>::type(i);
327  }
328 
329  /// Returns the inequality type of the row with identifier \p key.
330  typename LPRowBase<R>::Type rowType(const SPxRowId& id) const
331  {
332  return LPRowSetBase<R>::type(id);
333  }
334 
335  /// Gets \p i 'th column.
336  void getCol(int i, LPColBase<R>& col) const
337  {
338  col.setUpper(upper(i));
339  col.setLower(lower(i));
340  col.setObj(obj(i));
341  col.setColVector(colVector(i));
342  }
343 
344  /// Gets column with identifier \p id.
345  void getCol(const SPxColId& id, LPColBase<R>& col) const
346  {
347  getCol(number(id), col);
348  }
349 
350  /// Gets columns \p start, ..., \p end.
351  void getCols(int start, int end, LPColSetBase<R>& set) const
352  {
353  if( _isScaled)
354  {
355  LPColBase<R> lpcol;
356 
357  for( int i = start; i <= end; i++ )
358  {
359  getCol(i, lpcol);
360  set.add(lpcol);
361  }
362 
363  }
364  else
365  {
366  set.clear();
367  for( int i = start; i <= end; i++ )
368  set.add(obj(i), lower(i), colVector(i), upper(i));
369  }
370  }
371 
372  /// Returns column vector of column \p i.
373  const SVectorBase<R>& colVector(int i) const
374  {
375  return LPColSetBase<R>::colVector(i);
376  }
377 
378  /// Returns column vector of column with identifier \p id.
379  const SVectorBase<R>& colVector(const SPxColId& id) const
380  {
381  return LPColSetBase<R>::colVector(id);
382  }
383 
384  /// Gets column vector of column \p i.
385  void getColVectorUnscaled(int i, DSVectorBase<Real>& vec) const;
386 
387  /// Gets column vector of column with identifier \p id.
388  void getColVectorUnscaled(const SPxColId& id, DSVectorBase<Real>& vec) const;
389 
390  /// Gets unscaled objective vector.
391  void getObjUnscaled(VectorBase<Real>& pobj) const;
392 
393  /// Gets objective vector.
394  void getObj(VectorBase<R>& pobj) const
395  {
396  pobj = LPColSetBase<R>::maxObj();
397 
398  if( spxSense() == MINIMIZE )
399  pobj *= -1.0;
400  }
401 
402  /// Returns objective value of column \p i.
403  R obj(int i) const
404  {
405  R res = maxObj(i);
406 
407  if( spxSense() == MINIMIZE )
408  res *= -1;
409  return res;
410  }
411 
412  /// Returns objective value of column with identifier \p id.
413  R obj(const SPxColId& id) const
414  {
415  return obj(number(id));
416  }
417 
418  /// Returns unscaled objective value of column \p i.
419  R objUnscaled(int i) const;
420 
421  /// Returns unscaled objective value of column with identifier \p id.
422  R objUnscaled(const SPxColId& id) const;
423 
424  /// Returns objective vector for maximization problem.
425  /** Methods #maxObj() return the objective vector or its elements, after transformation to a maximization
426  * problem. Since this is how SPxLPBase internally stores any LP these methods are generally faster. The following
427  * condition holds: #obj() = #spxSense() * maxObj().
428  */
429  const VectorBase<R>& maxObj() const
430  {
431  return LPColSetBase<R>::maxObj();
432  }
433 
434  /// Returns objective value of column \p i for maximization problem.
435  const R& maxObj(int i) const
436  {
437  return LPColSetBase<R>::maxObj(i);
438  }
439 
440  /// Returns objective value of column with identifier \p id for maximization problem.
441  const R& maxObj(const SPxColId& id) const
442  {
443  return maxObj(number(id));
444  }
445 
446  /// Returns unscaled objective vector for maximization problem.
447  void maxObjUnscaled(VectorBase<Real>& vec) const;
448 
449  /// Returns unscaled objective value of column \p i for maximization problem.
450  R maxObjUnscaled(int i) const;
451 
452  /// Returns unscaled objective value of column with identifier \p id for maximization problem.
453  R maxObjUnscaled(const SPxColId& id) const;
454 
455  /// Returns upper bound vector.
456  const VectorBase<R>& upper() const
457  {
458  return LPColSetBase<R>::upper();
459  }
460 
461  /// Returns upper bound of column \p i.
462  const R& upper(int i) const
463  {
464  return LPColSetBase<R>::upper(i);
465  }
466 
467  /// Returns upper bound of column with identifier \p id.
468  const R& upper(const SPxColId& id) const
469  {
470  return LPColSetBase<R>::upper(id);
471  }
472 
473  /// Gets unscaled upper bound vector
474  void getUpperUnscaled(DVector& vec) const;
475 
476  /// Returns unscaled upper bound of column \p i.
477  R upperUnscaled(int i) const;
478 
479  /// Returns unscaled upper bound of column with identifier \p id.
480  R upperUnscaled(const SPxColId& id) const;
481 
482  /// Returns (internal and possibly scaled) lower bound vector.
483  const VectorBase<R>& lower() const
484  {
485  return LPColSetBase<R>::lower();
486  }
487 
488  /// Returns (internal and possibly scaled) lower bound of column \p i.
489  const R& lower(int i) const
490  {
491  return LPColSetBase<R>::lower(i);
492  }
493 
494  /// Returns (internal and possibly scaled) lower bound of column with identifier \p id.
495  const R& lower(const SPxColId& id) const
496  {
497  return LPColSetBase<R>::lower(id);
498  }
499 
500  /// Gets unscaled lower bound vector.
501  void getLowerUnscaled(DVector& vec) const;
502 
503  /// Returns unscaled lower bound of column \p i.
504  R lowerUnscaled(int i) const;
505 
506  /// Returns unscaled lower bound of column with identifier \p id.
507  R lowerUnscaled(const SPxColId& id) const;
508 
509  /// Returns the optimization sense.
511  {
512  return thesense;
513  }
514 
515  /// Returns the objective function value offset
516  const R& objOffset() const
517  {
518  return offset;
519  }
520 
521  /// Returns the row number of the row with identifier \p id.
522  int number(const SPxRowId& id) const
523  {
524  return LPRowSetBase<R>::number(id);
525  }
526 
527  /// Returns the column number of the column with identifier \p id.
528  int number(const SPxColId& id) const
529  {
530  return LPColSetBase<R>::number(id);
531  }
532 
533  /// Returns the row or column number for identifier \p id.
534  int number(const SPxId& id) const
535  {
536  return (id.type() == SPxId::COL_ID)
539  }
540 
541  /// Returns the row number of the row with identifier \p id.
542  bool has(const SPxRowId& id) const
543  {
544  return LPRowSetBase<R>::has(id);
545  }
546 
547  /// Returns the column number of the column with identifier \p id.
548  bool has(const SPxColId& id) const
549  {
550  return LPColSetBase<R>::has(id);
551  }
552 
553  /// Returns the row or column number for identifier \p id.
554  bool has(const SPxId& id) const
555  {
556  return (id.type() == SPxId::COL_ID)
558  : LPRowSetBase<R>::has(id);
559  }
560 
561  /// Returns the row identifier for row \p n.
562  SPxRowId rId(int n) const
563  {
564  return SPxRowId(LPRowSetBase<R>::key(n));
565  }
566 
567  /// Returns the column identifier for column \p n.
568  SPxColId cId(int n) const
569  {
570  return SPxColId(LPColSetBase<R>::key(n));
571  }
572 
573  //@}
574 
575  // ------------------------------------------------------------------------------------------------------------------
576  /**@name Extension */
577  //@{
578 
579  ///
580  virtual void addRow(const LPRowBase<R>& row, bool scale = false)
581  {
582  doAddRow(row, scale);
583  }
584 
585  ///
586  virtual void addRow(const R& lhsValue, const SVectorBase<R>& rowVec, const R& rhsValue, bool scale = false)
587  {
588  doAddRow(lhsValue, rowVec, rhsValue, scale);
589  }
590 
591  ///
592  template < class S >
593  void addRow(const S* lhsValue, const S* rowValues, const int* rowIndices, int rowSize, const S* rhsValue)
594  {
595  assert(lhsValue != 0);
596  assert(rowSize <= 0 || rowValues != 0);
597  assert(rowSize <= 0 || rowIndices != 0);
598  assert(rhsValue != 0);
599 
600  int idx = nRows();
601  int oldColNumber = nCols();
602 
603  LPRowSetBase<R>::add(lhsValue, rowValues, rowIndices, rowSize, rhsValue);
604 
605  // now insert nonzeros to column file also
606  for( int j = rowSize - 1; j >= 0; --j )
607  {
608  const S& val = rowValues[j];
609  int i = rowIndices[j];
610 
611  // create new columns if required
612  if( i >= nCols() )
613  {
614  LPColBase<R> empty;
615  for( int k = nCols(); k <= i; ++k )
616  LPColSetBase<R>::add(empty);
617  }
618 
619  assert(i < nCols());
620  LPColSetBase<R>::add2(i, 1, &idx, &val);
621  }
622 
623  addedRows(1);
624  addedCols(nCols() - oldColNumber);
625  }
626 
627  /// Adds \p row to LPRowSetBase.
628  virtual void addRow(SPxRowId& id, const LPRowBase<R>& row, bool scale = false)
629  {
630  addRow(row, scale);
631  id = rId(nRows() - 1);
632  }
633 
634  ///
635  virtual void addRows(const LPRowSetBase<R>& pset, bool scale = false)
636  {
637  doAddRows(pset, scale);
638  }
639 
640  ///
641  template < class S >
642  void addRows(const S* lhsValues, const S* rowValues, const int* rowIndices, const int* rowStarts, const int* rowLengths, const int numRows, const int numValues, const S* rhsValues)
643  {
644  assert(lhsValues != 0);
645  assert(numValues <= 0 || rowValues != 0);
646  assert(numValues <= 0 || rowIndices != 0);
647  assert(numValues <= 0 || rowStarts != 0);
648  assert(numValues <= 0 || rowLengths != 0);
649  assert(rhsValues != 0);
650 
651  int i, j, k, idx;
652  SVectorBase<R>* col;
653  DataArray < int > newCols(nCols());
654  int oldRowNumber = nRows();
655  int oldColNumber = nCols();
656 
657  LPRowSetBase<R>::memRemax(oldRowNumber + numRows);
658  for( i = 0; i < numRows; i++ )
659  {
660  assert(numValues <= 0 || rowStarts[i] + rowLengths[i] <= numValues);
661  if( numValues <= 0 )
662  LPRowSetBase<R>::add(&(lhsValues[i]), (S*)0, (int*)0, 0, &(rhsValues[i]));
663  else
664  LPRowSetBase<R>::add(&(lhsValues[i]), &(rowValues[rowStarts[i]]), &(rowIndices[rowStarts[i]]), rowLengths[i], &(rhsValues[i]));
665  }
666 
669 
670  // count additional nonzeros per column
671  for( i = nCols() - 1; i >= 0; --i )
672  newCols[i] = 0;
673  if( numValues > 0 )
674  {
675  for( i = 0; i < numRows; i++ )
676  {
677  for( j = rowStarts[i]; j < rowStarts[i] + rowLengths[i]; j++ )
678  {
679  ///@todo implement the addition of new columns as in doAddRows()
680  assert(rowIndices[j] >= 0);
681  assert(rowIndices[j] < oldColNumber);
682  newCols[rowIndices[j]]++;
683  }
684  }
685  }
686 
687  // extend columns as required (backward because of memory efficiency reasons)
688  for( i = nCols() - 1; i >= 0; --i )
689  {
690  if( newCols[i] > 0 )
691  {
692  int len = newCols[i] + colVector(i).size();
693  LPColSetBase<R>::xtend(i, len);
694 
695  /* preset the sizes: beware that this can irritate a consistency check call from xtend(). We need to set the
696  * sizes here, because a possible garbage collection called from xtend might destroy the sizes again. */
697  colVector_w(i).set_size( len );
698  }
699  }
700 
701  // insert new elements to column file
702  for( i = nRows() - 1; i >= oldRowNumber; --i )
703  {
704  const SVectorBase<R>& vec = rowVector(i);
705 
706  for( j = vec.size() - 1; j >= 0; --j )
707  {
708  k = vec.index(j);
709  col = &colVector_w(k);
710  idx = col->size() - newCols[k];
711  assert(newCols[k] > 0);
712  assert(idx >= 0);
713  newCols[k]--;
714  col->index(idx) = i;
715  col->value(idx) = vec.value(j);
716  }
717  }
718 
719 #ifndef NDEBUG
720  for( i = 0; i < nCols(); ++i )
721  assert( newCols[i] == 0 );
722 #endif
723 
724  assert(SPxLPBase<R>::isConsistent());
725 
726  assert( numRows == nRows() - oldRowNumber );
727  addedRows( nRows() - oldRowNumber );
728  addedCols( nCols() - oldColNumber );
729  }
730 
731  /// adds all LPRowBase%s of \p pset to LPRowSetBase.
732  virtual void addRows(SPxRowId id[], const LPRowSetBase<R>& set, bool scale = false)
733  {
734  int i = nRows();
735  addRows(set, scale);
736  for( int j = 0; i < nRows(); ++i, ++j )
737  id[j] = rId(i);
738  }
739 
740  ///
741  virtual void addCol(const LPColBase<R>& col, bool scale = false)
742  {
743  doAddCol(col, scale);
744  }
745 
746  ///
747  virtual void addCol(const R& objValue, const R& lowerValue, const SVectorBase<R>& colVec, const R& upperValue, bool scale = false)
748  {
749  doAddCol(objValue, lowerValue, colVec, upperValue, scale);
750  }
751 
752  ///
753  template < class S >
754  void addCol(const S* objValue, const S* lowerValue, const S* colValues, const int* colIndices, int colSize, const S* upperValue)
755  {
756  int idx = nCols();
757  int oldRowNumber = nRows();
758 
759  LPColSetBase<R>::add(objValue, lowerValue, colValues, colIndices, colSize, upperValue);
760  if( thesense != MAXIMIZE )
761  LPColSetBase<R>::maxObj_w(idx) *= -1;
762 
763  // now insert nonzeros to column file also
764  for( int j = colSize - 1; j >= 0; --j )
765  {
766  const S& val = colValues[j];
767  int i = colIndices[j];
768 
769  // create new rows if required
770  if( i >= nRows() )
771  {
772  LPRowBase<R> empty;
773  for( int k = nRows(); k <= i; ++k )
774  LPRowSetBase<R>::add(empty);
775  }
776 
777  assert(i < nRows());
778  LPRowSetBase<R>::add2(i, 1, &idx, &val);
779  }
780 
781  addedCols(1);
782  addedRows(nRows() - oldRowNumber);
783  }
784 
785  /// Adds \p col to LPColSetVBase.
786  virtual void addCol(SPxColId& id, const LPColBase<R>& col, bool scale = false)
787  {
788  addCol(col, scale);
789  id = cId(nCols() - 1);
790  }
791 
792  ///
793  virtual void addCols(const LPColSetBase<R>& pset, bool scale = false)
794  {
795  doAddCols(pset, scale);
796  }
797 
798  ///
799  template < class S >
800  void addCols(const S* objValue, const S* lowerValues, const S* colValues, const int* colIndices, const int* colStarts, const int* colLengths, const int numCols, const int numValues, const S* upperValues)
801  {
802  assert(lowerValues != 0);
803  assert(numValues <= 0 || colValues != 0);
804  assert(numValues <= 0 || colIndices != 0);
805  assert(numValues <= 0 || colStarts != 0);
806  assert(numValues <= 0 || colLengths != 0);
807  assert(upperValues != 0);
808 
809  int i, j, k, idx;
810  SVectorBase<R>* row;
811  DataArray < int > newRows(nRows());
812  int oldColNumber = nCols();
813  int oldRowNumber = nRows();
814  idx = nCols();
815 
816  LPColSetBase<R>::memRemax(oldColNumber + numCols);
817  for( i = 0; i < numCols; i++ )
818  {
819  assert(numValues <= 0 || colStarts[i] + colLengths[i] <= numValues);
820  if( numValues <= 0 )
821  LPColSetBase<R>::add(&(objValue[i]), &(lowerValues[i]), (S*)0, (int*)0, 0, &(upperValues[i]));
822  else
823  LPColSetBase<R>::add(&(objValue[i]), &(lowerValues[i]), &(colValues[colStarts[i]]), &(colIndices[colStarts[i]]), colLengths[i], &(upperValues[i]));
824 
825  if( thesense != MAXIMIZE )
826  LPColSetBase<R>::maxObj_w(idx + i) *= -1;
827  }
828 
831 
832  // count additional nonzeros per rows
833  for( i = nRows() - 1; i >= 0; --i )
834  newRows[i] = 0;
835  for( i = numValues - 1; i >= 0; --i )
836  {
837  ///@todo implement the addition of new rows as in doAddCols()
838  assert(colIndices[i] >= 0);
839  assert(colIndices[i] < oldRowNumber);
840  newRows[colIndices[i]]++;
841  }
842 
843  // extend rows as required (backward because of memory efficiency reasons)
844  for( i = nRows() - 1; i >= 0; --i )
845  {
846  if( newRows[i] > 0 )
847  {
848  int len = newRows[i] + rowVector(i).size();
849  LPRowSetBase<R>::xtend(i, len);
850 
851  /* preset the sizes: beware that this can irritate a consistency check call from xtend(). We need to set the
852  * sizes here, because a possible garbage collection called from xtend might destroy the sizes again. */
853  rowVector_w(i).set_size( len );
854  }
855  }
856 
857  // insert new elements to row file
858  for( i = nCols() - 1; i >= oldColNumber; --i )
859  {
860  const SVectorBase<R>& vec = colVector(i);
861 
862  for( j = vec.size() - 1; j >= 0; --j )
863  {
864  k = vec.index(j);
865  row = &rowVector_w(k);
866  idx = row->size() - newRows[k];
867  assert(newRows[k] > 0);
868  assert(idx >= 0);
869  newRows[k]--;
870  row->index(idx) = i;
871  row->value(idx) = vec.value(j);
872  }
873  }
874 
875 #ifndef NDEBUG
876  for( i = 0; i < nRows(); ++i )
877  assert( newRows[i] == 0 );
878 #endif
879 
880  assert(SPxLPBase<R>::isConsistent());
881 
882  assert( numCols == nCols() - oldColNumber );
883  addedCols( nCols() - oldColNumber );
884  addedRows( nRows() - oldRowNumber );
885  }
886 
887  /// Adds all LPColBase%s of \p set to LPColSetBase.
888  virtual void addCols(SPxColId id[], const LPColSetBase<R>& set, bool scale = false)
889  {
890 
891  int i = nCols();
892  addCols(set, scale);
893  for( int j = 0; i < nCols(); ++i, ++j )
894  id[j] = cId(i);
895  }
896 
897  //@}
898 
899  // ------------------------------------------------------------------------------------------------------------------
900  /**@name Shrinking */
901  //@{
902 
903  /// Removes \p i 'th row.
904  virtual void removeRow(int i)
905  {
906  if( i < 0 )
907  return;
908 
909  doRemoveRow(i);
910  }
911 
912  /// Removes row with identifier \p id.
913  virtual void removeRow(SPxRowId id)
914  {
915  removeRow(number(id));
916  }
917 
918  /// Removes multiple rows.
919  /** This method removes all LPRowBase%s from the SPxLPBase with an index \p i such that \p perm[i] < 0. Upon
920  * completion, \p perm[i] >= 0 indicates the new index where the \p i'th LPRow has been moved to due to this
921  * removal. Note that \p perm must point to an array of at least #nRows() ints.
922  */
923  virtual void removeRows(int perm[])
924  {
925  doRemoveRows(perm);
926  }
927 
928  ///
929  virtual void removeRows(SPxRowId id[], int n, int perm[] = 0)
930  {
931 
932  if( perm == 0 )
933  {
935  removeRows(id, n, p.get_ptr());
936  return;
937  }
938 
939  for( int i = nRows() - 1; i >= 0; --i )
940  perm[i] = i;
941 
942  while( n-- )
943  perm[number(id[n])] = -1;
944 
945  removeRows(perm);
946  }
947 
948  /// Removes \p n LPRowBase%s.
949  /** Removing multiple rows with one method invocation is available in two flavours. An array \p perm can be passed as
950  * third argument or not. If given, \p perm must be an array at least of size #nRows(). It is used to return the
951  * permutations resulting from this removal: \p perm[i] < 0 indicates, that the element to index \p i has been
952  * removed. Otherwise, \p perm[i] is the new index of the element with index \p i before the removal.
953  */
954  virtual void removeRows(int nums[], int n, int perm[] = 0)
955  {
956 
957  if( perm == 0 )
958  {
960  removeRows(nums, n, p.get_ptr());
961  return;
962  }
963 
964  for( int i = nRows() - 1; i >= 0; --i )
965  perm[i] = i;
966 
967  while( n-- )
968  perm[nums[n]] = -1;
969 
970  removeRows(perm);
971  }
972 
973  /// Removes rows from \p start to \p end (including both).
974  virtual void removeRowRange(int start, int end, int perm[] = 0)
975  {
976 
977  if( perm == 0 )
978  {
979  int i = end - start + 1;
980  DataArray < int > p(i);
981 
982  while( --i >= 0 )
983  p[i] = start + i;
984 
985  removeRows(p.get_ptr(), end - start + 1);
986  return;
987  }
988 
989  int i;
990  for( i = 0; i < start; ++i )
991  perm[i] = i;
992  for( ; i <= end; ++i )
993  perm[i] = -1;
994  for( ; i < nRows(); ++i )
995  perm[i] = i;
996 
997  removeRows(perm);
998  }
999 
1000  /// Removes \p i 'th column.
1001  virtual void removeCol(int i)
1002  {
1003  if( i < 0 )
1004  return;
1005 
1006  doRemoveCol(i);
1007  }
1008 
1009  /// Removes column with identifier \p id.
1010  virtual void removeCol(SPxColId id)
1011  {
1012  removeCol(number(id));
1013  }
1014 
1015  /// Removes multiple columns.
1016  /** This method removes all LPColBase%s from the SPxLPBase with an index \p i such that \p perm[i] < 0. Upon
1017  * completion, \p perm[i] >= 0 indicates the new index where the \p i 'th LPColBase has been moved to due to this
1018  * removal. Note, that \p perm must point to an array of at least #nCols() ints.
1019  */
1020  virtual void removeCols(int perm[])
1021  {
1022  doRemoveCols(perm);
1023  }
1024 
1025  ///
1026  virtual void removeCols(SPxColId id[], int n, int perm[] = 0)
1027  {
1028 
1029  if( perm == 0 )
1030  {
1031  DataArray < int > p(nCols());
1032  removeCols(id, n, p.get_ptr());
1033  return;
1034  }
1035 
1036  for( int i = nCols() - 1; i >= 0; --i )
1037  perm[i] = i;
1038 
1039  while( n-- )
1040  perm[number(id[n])] = -1;
1041 
1042  removeCols(perm);
1043  }
1044 
1045  /// Removes \p n LPCols.
1046  /** Removing multiple columns with one method invocation is available in two flavours. An array \p perm can be passed
1047  * as third argument or not. If given, \p perm must be an array at least of size #nCols(). It is used to return the
1048  * permutations resulting from this removal: \p perm[i] < 0 indicates, that the element to index \p i has been
1049  * removed. Otherwise, \p perm[i] is the new index of the element with index \p i before the removal.
1050  */
1051  virtual void removeCols(int nums[], int n, int perm[] = 0)
1052  {
1053 
1054  if( perm == 0 )
1055  {
1056  DataArray < int > p(nCols());
1057  removeCols(nums, n, p.get_ptr());
1058  return;
1059  }
1060 
1061  for( int i = nCols() - 1; i >= 0; --i )
1062  perm[i] = i;
1063 
1064  while( n-- )
1065  perm[nums[n]] = -1;
1066 
1067  removeCols(perm);
1068  }
1069 
1070  /// Removes columns from \p start to \p end (including both).
1071  virtual void removeColRange(int start, int end, int perm[] = 0)
1072  {
1073 
1074  if( perm == 0 )
1075  {
1076  int i = end - start + 1;
1077  DataArray < int > p(i);
1078 
1079  while( --i >= 0 )
1080  p[i] = start + i;
1081 
1082  removeCols(p.get_ptr(), end - start + 1);
1083  return;
1084  }
1085 
1086  int i;
1087  for( i = 0; i < start; ++i )
1088  perm[i] = i;
1089  for( ; i <= end; ++i )
1090  perm[i] = -1;
1091  for( ; i < nCols(); ++i )
1092  perm[i] = i;
1093 
1094  removeCols(perm);
1095  }
1096 
1097  /// clears the LP.
1098  virtual void clear()
1099  {
1100 
1103  thesense = MAXIMIZE;
1104  offset = 0;
1105  _isScaled = false;
1106  lp_scaler = 0;
1109  }
1110 
1111  //@}
1112 
1113  // ------------------------------------------------------------------------------------------------------------------
1114  /**@name IO */
1115  //@{
1116 
1117  /// Reads LP in LP format from input stream \p in.
1118  virtual bool readLPF(std::istream& in, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0);
1119 
1120  /// Reads an LP in MPS format from input stream \p in.
1121  virtual bool readMPS(std::istream& in, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0);
1122 
1123  /// Reads LP in LP or MPS format from input stream \p in.
1124  /**@param in input stream.
1125  * @param rowNames contains after the call the names of the constraints (rows) in the same order as the rows in the
1126  * LP. Constraints without a name (only possible with LPF files) are automatically assigned a name.
1127  * Maybe 0 if the names are not needed.
1128  * @param colNames contains after the call the names of the variables (columns) in the same order as the columns in
1129  * the LP. Maybe 0 if the names are not needed.
1130  * @param intVars contains after the call the indices of those variables that where marked as beeing integer in the
1131  * file. Maybe 0 if the information is not needed.
1132  * @todo Make sure the Id's in the NameSet%s are the same as in the LP.
1133  */
1134  virtual bool read(std::istream& in, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0)
1135  {
1136  bool ok;
1137  char c;
1138 
1139  in.get(c);
1140  in.putback(c);
1141 
1142  /* MPS starts either with a comment mark '*' or with the keyword 'NAME' at the first column. LPF starts either
1143  * with blanks, a comment mark '\' or with the keyword "MAX" or "MIN" in upper or lower case. There is no
1144  * possible valid LPF file starting with a '*' or 'N'.
1145  */
1146  ok = ((c == '*') || (c == 'N'))
1147  ? readMPS(in, rowNames, colNames, intVars)
1148  : readLPF(in, rowNames, colNames, intVars);
1149 
1150  return ok;
1151  }
1152 
1153  /// Reads LP from a file.
1154  virtual bool readFile(const char* filename, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0)
1155  {
1156 
1157  spxifstream file(filename);
1158 
1159  if( !file )
1160  return false;
1161 
1162  return read(file, rowNames, colNames, intVars);
1163  }
1164 
1165  /** Writes a file in LP format to \p out. If \p rowNames and \p colNames are \c NULL, default names are used for the
1166  * constraints and variables. If \p intVars is not \c NULL, the variables contained in it are marked as integer in
1167  * the output.
1168  */
1169  virtual void writeLPF(std::ostream& out, const NameSet* rowNames, const NameSet* colNames, const DIdxSet* p_intvars = 0) const;
1170 
1171  /// Writes a file in MPS format to \p out.
1172  virtual void writeMPS(std::ostream& out, const NameSet* rowNames, const NameSet* colNames, const DIdxSet* p_intvars = 0) const;
1173 
1174  /// Write loaded LP to \p filename.
1175  virtual void writeFile(const char* filename, const NameSet* rowNames = 0, const NameSet* colNames = 0, const DIdxSet* p_intvars = 0) const
1176  {
1177 
1178  std::ofstream tmp(filename);
1179  size_t len_f = strlen(filename);
1180 
1181  if( len_f > 4 && filename[len_f-1] == 's' && filename[len_f-2] == 'p' && filename[len_f-3] == 'm' && filename[len_f-4] == '.' )
1182  {
1183  writeMPS(tmp, rowNames, colNames, p_intvars);
1184  }
1185  else
1186  {
1187  writeLPF(tmp, rowNames, colNames, p_intvars);
1188  }
1189  }
1190 
1191  /** prints problem statistics */
1192  void printProblemStatistics(std::ostream& os)
1193  {
1194  int countLower = 0;
1195  int countUpper = 0;
1196  int countBoxed = 0;
1197  int countFreeCol = 0;
1198 
1199  int countEqual = 0;
1200  int countLhs = 0;
1201  int countRhs = 0;
1202  int countRanged = 0;
1203  int countFreeRow = 0;
1204 
1205  for( int i = 0; i < nCols(); i++ )
1206  {
1207  bool hasLower = false;
1208  bool hasUpper = false;
1209 
1210  if( lower(i) > -infinity )
1211  {
1212  countLower++;
1213  hasLower = true;
1214  }
1215 
1216  if( upper(i) < infinity )
1217  {
1218  countUpper++;
1219  hasUpper = true;
1220  }
1221 
1222  if( hasUpper && hasLower )
1223  {
1224  countBoxed++;
1225  countLower--;
1226  countUpper--;
1227  }
1228 
1229  if( !hasUpper && !hasLower )
1230  countFreeCol++;
1231  }
1232 
1233  for( int i = 0; i < nRows(); i++)
1234  {
1235  bool hasRhs = false;
1236  bool hasLhs = false;
1237 
1238  if( lhs(i) > -infinity )
1239  {
1240  countLhs++;
1241  hasLhs = true;
1242  }
1243 
1244  if( rhs(i) < infinity )
1245  {
1246  countRhs++;
1247  hasRhs = true;
1248  }
1249 
1250  if( hasRhs && hasLhs )
1251  {
1252  if( EQ(lhs(i), rhs(i)) )
1253  countEqual++;
1254  else
1255  countRanged++;
1256  countLhs--;
1257  countRhs--;
1258  }
1259 
1260  if( !hasRhs && !hasLhs )
1261  countFreeRow++;
1262  }
1263 
1264  SPxOut::setFixed(os);
1265  os << " Columns : " << nCols() << "\n"
1266  << " boxed : " << countBoxed << "\n"
1267  << " lower bound : " << countLower << "\n"
1268  << " upper bound : " << countUpper << "\n"
1269  << " free : " << countFreeCol << "\n"
1270  << " Rows : " << nRows() << "\n"
1271  << " equal : " << countEqual << "\n"
1272  << " ranged : " << countRanged << "\n"
1273  << " lhs : " << countLhs << "\n"
1274  << " rhs : " << countRhs << "\n"
1275  << " free : " << countFreeRow << "\n"
1276  << " Nonzeros : " << nNzos() << "\n"
1277  << " per column : " << Real(nNzos()) / Real(nCols()) << "\n"
1278  << " per row : " << Real(nNzos()) / Real(nRows()) << "\n"
1279  << " sparsity : " << Real(nNzos()) / Real(nCols()) / Real(nRows()) << "\n"
1280  << " min. abs. value : " << Real(minAbsNzo()) << "\n"
1281  << " max. abs. value : " << Real(maxAbsNzo()) << "\n";
1282  }
1283 
1284  //@}
1285 
1286  // ------------------------------------------------------------------------------------------------------------------
1287  /**@name Manipulation */
1288  //@{
1289 
1290  /// Changes objective vector to \p newObj. \p scale determines whether the new data should be scaled
1291  virtual void changeObj(const VectorBase<R>& newObj, bool scale = false)
1292  {
1293  changeMaxObj(newObj, scale);
1294  if( spxSense() == MINIMIZE )
1295  LPColSetBase<R>::maxObj_w() *= -1;
1296  }
1297 
1298  /// changes \p i 'th objective vector element to \p newVal. \p scale determines whether the new data should be scaled
1299  virtual void changeObj(int i, const R& newVal, bool scale = false)
1300  {
1301  changeMaxObj(i, newVal, scale);
1302  if( spxSense() == MINIMIZE )
1303  LPColSetBase<R>::maxObj_w(i) *= -1;
1304  }
1305 
1306  /// changes \p i 'th objective vector element to \p newVal.
1307  template < class S >
1308  void changeObj(int i, const S* newVal)
1309  {
1310  LPColSetBase<R>::maxObj_w(i) = *newVal;
1311  if( spxSense() == MINIMIZE )
1312  LPColSetBase<R>::maxObj_w(i) *= -1;
1313  assert(isConsistent());
1314  }
1315 
1316  /// Changes objective value of column with identifier \p id to \p newVal. \p scale determines whether the new data should be scaled
1317  virtual void changeObj(SPxColId id, const R& newVal, bool scale = false)
1318  {
1319  changeObj(number(id), newVal, scale);
1320  }
1321 
1322  /// Changes objective vector to \p newObj. \p scale determines whether the new data should be scaled
1323  virtual void changeMaxObj(const VectorBase<R>& newObj, bool scale = false)
1324  {
1325  assert(scale == false);
1326  assert(maxObj().dim() == newObj.dim());
1327  LPColSetBase<R>::maxObj_w() = newObj;
1328  assert(isConsistent());
1329  }
1330 
1331  /// changes \p i 'th objective vector element to \p newVal. \p scale determines whether the new data should be scaled
1332  virtual void changeMaxObj(int i, const R& newVal, bool scale = false)
1333  {
1334  if( scale )
1335  {
1336  assert(_isScaled);
1337  assert(lp_scaler);
1338  LPColSetBase<R>::maxObj_w(i) = lp_scaler->scaleObj(*this, i, newVal);
1339  }
1340  else
1341  LPColSetBase<R>::maxObj_w(i) = newVal;
1342  assert(isConsistent());
1343  }
1344 
1345  /// changes \p i 'th objective vector element to \p newVal.
1346  template < class S >
1347  void changeMaxObj(int i, const S* newVal)
1348  {
1349  LPColSetBase<R>::maxObj_w(i) = *newVal;
1350  assert(isConsistent());
1351  }
1352 
1353  /// Changes objective value of column with identifier \p id to \p newVal. \p scale determines whether the new data should be scaled
1354  virtual void changeMaxObj(SPxColId id, const R& newVal, bool scale = false)
1355  {
1356  changeMaxObj(number(id), newVal, scale);
1357  }
1358 
1359  /// Changes vector of lower bounds to \p newLower. \p scale determines whether the new data should be scaled
1360  virtual void changeLower(const VectorBase<R>& newLower, bool scale = false)
1361  {
1362  assert(scale == false);
1363  assert(lower().dim() == newLower.dim());
1364  LPColSetBase<R>::lower_w() = newLower;
1365  assert(isConsistent());
1366  }
1367 
1368  /// changes \p i 'th lower bound to \p newLower. \p scale determines whether the new data should be scaled
1369  virtual void changeLower(int i, const R& newLower, bool scale = false)
1370  {
1371  if( scale && newLower > -infinity)
1372  {
1373  assert(_isScaled);
1374  assert(lp_scaler);
1375  LPColSetBase<R>::lower_w(i) = lp_scaler->scaleLower(*this, i, newLower);
1376  }
1377  else
1378  LPColSetBase<R>::lower_w(i) = newLower;
1379  assert(isConsistent());
1380  }
1381 
1382  /// changes \p i 'th lower bound to \p newLower.
1383  template < class S >
1384  void changeLower(int i, const S* newLower)
1385  {
1386  LPColSetBase<R>::lower_w(i) = *newLower;
1387  assert(isConsistent());
1388  }
1389 
1390  /// changes lower bound of column with identifier \p id to \p newLower. \p scale determines whether the new data should be scaled
1391  virtual void changeLower(SPxColId id, const R& newLower, bool scale = false)
1392  {
1393  changeLower(number(id), newLower, scale);
1394  }
1395 
1396  /// Changes vector of upper bounds to \p newUpper. \p scale determines whether the new data should be scaled
1397  virtual void changeUpper(const VectorBase<R>& newUpper, bool scale = false)
1398  {
1399  assert(scale == false);
1400  assert(upper().dim() == newUpper.dim());
1401  LPColSetBase<R>::upper_w() = newUpper;
1402  assert(isConsistent());
1403  }
1404 
1405  /// Changes \p i 'th upper bound to \p newUpper. \p scale determines whether the new data should be scaled
1406  virtual void changeUpper(int i, const R& newUpper, bool scale = false)
1407  {
1408  if( scale && newUpper < infinity )
1409  {
1410  assert(_isScaled);
1411  assert(lp_scaler);
1412  LPColSetBase<R>::upper_w(i) = lp_scaler->scaleUpper(*this, i, newUpper);
1413  }
1414  else
1415  LPColSetBase<R>::upper_w(i) = newUpper;
1416  assert(isConsistent());
1417  }
1418 
1419  /// Changes \p i 'th upper bound to \p newUpper.
1420  template < class S >
1421  void changeUpper(int i, const S* newUpper)
1422  {
1423  LPColSetBase<R>::upper_w(i) = *newUpper;
1424  assert(isConsistent());
1425  }
1426 
1427  /// Changes upper bound of column with identifier \p id to \p newLower. \p scale determines whether the new data should be scaled
1428  virtual void changeUpper(SPxColId id, const R& newUpper, bool scale = false)
1429  {
1430  changeUpper(number(id), newUpper, scale);
1431  }
1432 
1433  /// Changes variable bounds to \p newLower and \p newUpper. \p scale determines whether the new data should be scaled
1434  virtual void changeBounds(const VectorBase<R>& newLower, const VectorBase<R>& newUpper, bool scale = false)
1435  {
1436  changeLower(newLower, scale);
1437  changeUpper(newUpper, scale);
1438  assert(isConsistent());
1439  }
1440 
1441  /// Changes bounds of column \p i to \p newLower and \p newUpper. \p scale determines whether the new data should be scaled
1442  virtual void changeBounds(int i, const R& newLower, const R& newUpper, bool scale = false)
1443  {
1444  changeLower(i, newLower, scale);
1445  changeUpper(i, newUpper, scale);
1446  assert(isConsistent());
1447  }
1448 
1449  /// Changes bounds of column \p i to \p newLower and \p newUpper.
1450  template < class S >
1451  void changeBounds(int i, const S* newLower, const S* newUpper)
1452  {
1453  LPColSetBase<R>::lower_w(i) = *newLower;
1454  LPColSetBase<R>::upper_w(i) = *newUpper;
1455  assert(isConsistent());
1456  }
1457 
1458  /// Changes bounds of column with identifier \p id. \p scale determines whether the new data should be scaled
1459  virtual void changeBounds(SPxColId id, const R& newLower, const R& newUpper, bool scale = false)
1460  {
1461  changeBounds(number(id), newLower, newUpper, scale);
1462  }
1463 
1464  /// Changes left hand side vector for constraints to \p newLhs. \p scale determines whether the new data should be scaled
1465  virtual void changeLhs(const VectorBase<R>& newLhs, bool scale = false)
1466  {
1467  assert(scale == false);
1468  assert(lhs().dim() == newLhs.dim());
1469  LPRowSetBase<R>::lhs_w() = newLhs;
1470  assert(isConsistent());
1471  }
1472 
1473  /// Changes \p i 'th left hand side value to \p newLhs. \p scale determines whether the new data should be scaled
1474  virtual void changeLhs(int i, const R& newLhs, bool scale = false)
1475  {
1476  if( scale && newLhs > -infinity )
1477  {
1478  assert(_isScaled);
1479  assert(lp_scaler);
1480  LPRowSetBase<R>::lhs_w(i) = lp_scaler->scaleLhs(*this, i, newLhs);
1481  }
1482  else
1483  LPRowSetBase<R>::lhs_w(i) = newLhs;
1484  assert(isConsistent());
1485  }
1486 
1487  /// Changes \p i 'th left hand side value to \p newLhs.
1488  template < class S >
1489  void changeLhs(int i, const S* newLhs)
1490  {
1491  LPRowSetBase<R>::lhs_w(i) = *newLhs;
1492  assert(isConsistent());
1493  }
1494 
1495  /// Changes left hand side value for row with identifier \p id. \p scale determines whether the new data should be scaled
1496  virtual void changeLhs(SPxRowId id, const R& newLhs, bool scale = false)
1497  {
1498  changeLhs(number(id), newLhs, scale);
1499  }
1500 
1501  /// Changes right hand side vector for constraints to \p newRhs. \p scale determines whether the new data should be scaled
1502  virtual void changeRhs(const VectorBase<R>& newRhs, bool scale = false)
1503  {
1504  assert(scale == false);
1505  assert(rhs().dim() == newRhs.dim());
1506  LPRowSetBase<R>::rhs_w() = newRhs;
1507  assert(isConsistent());
1508  }
1509 
1510  /// Changes \p i 'th right hand side value to \p newRhs. \p scale determines whether the new data should be scaled
1511  virtual void changeRhs(int i, const R& newRhs, bool scale = false)
1512  {
1513  if( scale && newRhs < infinity )
1514  {
1515  assert(_isScaled);
1516  assert(lp_scaler);
1517  LPRowSetBase<R>::rhs_w(i) = lp_scaler->scaleRhs(*this, i, newRhs);
1518  }
1519  else
1520  LPRowSetBase<R>::rhs_w(i) = newRhs;
1521  assert(isConsistent());
1522  }
1523 
1524  /// Changes right hand side value for row with identifier \p id. \p scale determines whether the new data should be scaled
1525  virtual void changeRhs(SPxRowId id, const R& newRhs, bool scale = false)
1526  {
1527  changeRhs(number(id), newRhs, scale);
1528  }
1529 
1530  /// Changes left and right hand side vectors. \p scale determines whether the new data should be scaled
1531  virtual void changeRange(const VectorBase<R>& newLhs, const VectorBase<R>& newRhs, bool scale = false)
1532  {
1533  changeLhs(newLhs, scale);
1534  changeRhs(newRhs, scale);
1535  assert(isConsistent());
1536  }
1537 
1538  /// Changes left and right hand side of row \p i. \p scale determines whether the new data should be scaled
1539  virtual void changeRange(int i, const R& newLhs, const R& newRhs, bool scale = false)
1540  {
1541  changeLhs(i, newLhs, scale);
1542  changeRhs(i, newRhs, scale);
1543  assert(isConsistent());
1544  }
1545 
1546  /// Changes left and right hand side of row \p i.
1547  template < class S >
1548  void changeRange(int i, const S* newLhs, const S* newRhs)
1549  {
1550  LPRowSetBase<R>::lhs_w(i) = *newLhs;
1551  LPRowSetBase<R>::rhs_w(i) = *newRhs;
1552  assert(isConsistent());
1553  }
1554 
1555  /// Changes left and right hand side of row with identifier \p id. \p scale determines whether the new data should be scaled
1556  virtual void changeRange(SPxRowId id, const R& newLhs, const R& newRhs, bool scale = false)
1557  {
1558  changeRange(number(id), newLhs, newRhs, scale);
1559  }
1560 
1561  /// Changes row objective function vector to \p newRowObj. \p scale determines whether the new data should be scaled
1562  virtual void changeRowObj(const VectorBase<R>& newRowObj, bool scale = false)
1563  {
1564  assert(maxRowObj().dim() == newRowObj.dim());
1565  LPRowSetBase<R>::obj_w() = newRowObj;
1566  if( spxSense() == MINIMIZE )
1567  LPRowSetBase<R>::obj_w() *= -1;
1568  assert(isConsistent());
1569  }
1570 
1571  /// Changes \p i 'th row objective function value to \p newRowObj. \p scale determines whether the new data should be scaled
1572  virtual void changeRowObj(int i, const R& newRowObj, bool scale = false)
1573  {
1574  LPRowSetBase<R>::obj_w(i) = newRowObj;
1575  if( spxSense() == MINIMIZE )
1576  LPRowSetBase<R>::obj_w(i) *= -1;
1577  assert(isConsistent());
1578  }
1579 
1580  /// Changes row objective function value for row with identifier \p id. \p scale determines whether the new data should be scaled
1581  virtual void changeRowObj(SPxRowId id, const R& newRowObj, bool scale = false)
1582  {
1583  changeRowObj(number(id), newRowObj, scale);
1584  }
1585 
1586  /// Clears row objective function values for all rows
1587  virtual void clearRowObjs()
1588  {
1589  LPRowSetBase<R>::obj_w().clear();
1590  }
1591 
1592  /// Replaces \p i 'th row of LP with \p newRow. \p scale determines whether the new data should be scaled
1593  virtual void changeRow(int n, const LPRowBase<R>& newRow, bool scale = false)
1594  {
1595  if( n < 0 )
1596  return;
1597 
1598  int j;
1599  SVectorBase<R>& row = rowVector_w(n);
1600  for( j = row.size() - 1; j >= 0; --j )
1601  {
1602  SVectorBase<R>& col = colVector_w(row.index(j));
1603  int position = col.pos(n);
1604 
1605  assert(position != -1);
1606 
1607  if( position >= 0 )
1608  col.remove(position);
1609  }
1610 
1611  row.clear();
1612 
1613  changeLhs(n, newRow.lhs(), scale);
1614  changeRhs(n, newRow.rhs(), scale);
1615  changeRowObj(n, newRow.obj(), scale);
1616 
1617  const SVectorBase<R>& newrow = newRow.rowVector();
1618  for( j = newrow.size() - 1; j >= 0; --j )
1619  {
1620  int idx = newrow.index(j);
1621  R val = newrow.value(j);
1622  if( scale )
1624  LPRowSetBase<R>::add2(n, 1, &idx, &val);
1625  LPColSetBase<R>::add2(idx, 1, &n, &val);
1626  }
1627 
1628  assert(isConsistent());
1629  }
1630 
1631  /// Replaces row with identifier \p id with \p newRow. \p scale determines whether the new data should be scaled
1632  virtual void changeRow(SPxRowId id, const LPRowBase<R>& newRow, bool scale = false)
1633  {
1634  changeRow(number(id), newRow, scale);
1635  }
1636 
1637  /// Replaces \p i 'th column of LP with \p newCol. \p scale determines whether the new data should be scaled
1638  virtual void changeCol(int n, const LPColBase<R>& newCol, bool scale = false)
1639  {
1640  if( n < 0 )
1641  return;
1642 
1643  int j;
1644  SVectorBase<R>& col = colVector_w(n);
1645  for( j = col.size() - 1; j >= 0; --j )
1646  {
1647  SVectorBase<R>& row = rowVector_w(col.index(j));
1648  int position = row.pos(n);
1649 
1650  assert(position != -1);
1651 
1652  if( position >= 0 )
1653  row.remove(position);
1654  }
1655 
1656  col.clear();
1657 
1658  changeUpper(n, newCol.upper(), scale);
1659  changeLower(n, newCol.lower(), scale);
1660  changeObj(n, newCol.obj(), scale);
1661 
1662  const SVectorBase<R>& newcol = newCol.colVector();
1663  for( j = newcol.size() - 1; j >= 0; --j )
1664  {
1665  int idx = newcol.index(j);
1666  R val = newcol.value(j);
1667  if( scale )
1669  LPColSetBase<R>::add2(n, 1, &idx, &val);
1670  LPRowSetBase<R>::add2(idx, 1, &n, &val);
1671  }
1672 
1673  assert(isConsistent());
1674  }
1675 
1676  /// Replaces column with identifier \p id with \p newCol. \p scale determines whether the new data should be scaled
1677  virtual void changeCol(SPxColId id, const LPColBase<R>& newCol, bool scale = false)
1678  {
1679  changeCol(number(id), newCol, scale);
1680  }
1681 
1682  /// Changes LP element (\p i, \p j) to \p val. \p scale determines whether the new data should be scaled
1683  virtual void changeElement(int i, int j, const R& val, bool scale = false)
1684  {
1685  if( i < 0 || j < 0 )
1686  return;
1687 
1688  SVectorBase<R>& row = rowVector_w(i);
1689  SVectorBase<R>& col = colVector_w(j);
1690 
1691  if( val != R(0) )
1692  {
1693  Real newVal;
1694 
1695  if( scale )
1696  {
1697  assert(_isScaled);
1698  assert(lp_scaler);
1699  newVal = lp_scaler->scaleElement(*this, i, j, val);
1700  }
1701  else
1702  newVal = val;
1703 
1704  if( row.pos(j) >= 0 && col.pos(i) >= 0 )
1705  {
1706  row.value(row.pos(j)) = newVal;
1707  col.value(col.pos(i)) = newVal;
1708  }
1709  else
1710  {
1711  LPRowSetBase<R>::add2(i, 1, &j, &newVal);
1712  LPColSetBase<R>::add2(j, 1, &i, &newVal);
1713  }
1714  }
1715  else if( row.pos(j) >= 0 && col.pos(i) >= 0 )
1716  {
1717  row.remove(row.pos(j));
1718  col.remove(col.pos(i));
1719  }
1720 
1721  assert(isConsistent());
1722  }
1723 
1724  /// Changes LP element (\p i, \p j) to \p val.
1725  template < class S >
1726  void changeElement(int i, int j, const S* val)
1727  {
1728  if( i < 0 || j< 0 )
1729  return;
1730 
1731  SVectorBase<R>& row = rowVector_w(i);
1732  SVectorBase<R>& col = colVector_w(j);
1733 
1734  if( mpq_get_d(*val) != R(0) )
1735  {
1736  if( row.pos(j) >= 0 && col.pos(i) >= 0 )
1737  {
1738  row.value(row.pos(j)) = *val;
1739  col.value(col.pos(i)) = *val;
1740  }
1741  else
1742  {
1743  LPRowSetBase<R>::add2(i, 1, &j, val);
1744  LPColSetBase<R>::add2(j, 1, &i, val);
1745  }
1746  }
1747  else if( row.pos(j) >= 0 && col.pos(i) >= 0 )
1748  {
1749  row.remove(row.pos(j));
1750  col.remove(col.pos(i));
1751  }
1752 
1753  assert(isConsistent());
1754  }
1755 
1756  /// Changes LP element identified by (\p rid, \p cid) to \p val. \p scale determines whether the new data should be scaled
1757  virtual void changeElement(SPxRowId rid, SPxColId cid, const R& val, bool scale = false)
1758  {
1759  changeElement(number(rid), number(cid), val, scale);
1760  }
1761 
1762  /// Changes optimization sense to \p sns.
1763  virtual void changeSense(SPxSense sns)
1764  {
1765  if( sns != thesense )
1766  {
1767  LPColSetBase<R>::maxObj_w() *= -1;
1768  LPRowSetBase<R>::obj_w() *= -1;
1769  }
1770  thesense = sns;
1771  }
1772 
1773  virtual void changeObjOffset(const R& o)
1774  {
1775  offset = o;
1776  }
1777 
1778  /// Computes activity of the rows for a given primal vector; activity does not need to be zero
1779  /// @throw SPxInternalCodeException if the dimension of primal vector does not match number of columns or if the
1780  /// dimension of the activity vector does not match the number of rows
1781  /// \p unscaled determines whether the returned data should be unscaled (if scaling was applied prior)
1782  virtual void computePrimalActivity(const VectorBase<R>& primal, VectorBase<R>& activity, const bool unscaled = true) const;
1783 
1784  /// Updates activity of the rows for a given primal vector; activity does not need to be zero
1785  /// @throw SPxInternalCodeException if the dimension of primal vector does not match number of columns or if the
1786  /// dimension of the activity vector does not match the number of rows
1787  virtual void addPrimalActivity(const SVectorBase<R>& primal, VectorBase<R>& activity) const
1788  {
1789  if( activity.dim() != nRows() )
1790  {
1791  throw SPxInternalCodeException("XSPXLP03 Activity vector computing row activity has wrong dimension");
1792  }
1793 
1794  for( int i = primal.size() - 1; i >= 0; i-- )
1795  {
1796  assert(primal.index(i) >= 0);
1797  assert(primal.index(i) < nCols());
1798  activity.multAdd(primal.value(i), colVector(primal.index(i)));
1799  }
1800  }
1801 
1802  /// Computes "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need to be zero
1803  /// @throw SPxInternalCodeException if dimension of dual vector does not match number of rows or if the dimension of
1804  /// the activity vector does not match the number of columns
1805  virtual void computeDualActivity(const VectorBase<R>& dual, VectorBase<R>& activity, const bool unscaled = true) const;
1806 
1807  /// Updates "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need to be zero
1808  /// @throw SPxInternalCodeException if dimension of dual vector does not match number of rows or if the dimension of
1809  /// the activity vector does not match the number of columns
1810  virtual void addDualActivity(const SVectorBase<R>& dual, VectorBase<R>& activity) const
1811  {
1812  if( activity.dim() != nCols() )
1813  {
1814  throw SPxInternalCodeException("XSPXLP04 Activity vector computing dual activity has wrong dimension");
1815  }
1816 
1817  for( int i = dual.size() - 1; i >= 0; i-- )
1818  {
1819  assert(dual.index(i) >= 0);
1820  assert(dual.index(i) < nRows());
1821  activity.multAdd(dual.value(i), rowVector(dual.index(i)));
1822  }
1823  }
1824 
1825  /// Updates "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need to be zero
1826  /// @throw SPxInternalCodeException if dimension of dual vector does not match number of rows or if the dimension of
1827  /// the activity vector does not match the number of columns
1828  virtual void subDualActivity(const VectorBase<R>& dual, VectorBase<R>& activity) const
1829  {
1830  if( dual.dim() != nRows() )
1831  {
1832  throw SPxInternalCodeException("XSPXLP02 Dual vector for computing dual activity has wrong dimension");
1833  }
1834 
1835  if( activity.dim() != nCols() )
1836  {
1837  throw SPxInternalCodeException("XSPXLP04 Activity vector computing dual activity has wrong dimension");
1838  }
1839 
1840  for( int r = 0; r < nRows(); r++ )
1841  {
1842  if( dual[r] != 0 )
1843  activity.multSub(dual[r], rowVector(r));
1844  }
1845  }
1846 
1847  //@}
1848 
1849  // ------------------------------------------------------------------------------------------------------------------
1850  /**@name Construction of dual problem */
1851  //@{
1852 
1853  /// Building the dual problem from a given LP
1854  /// @note primalRows must be as large as the number of unranged primal rows + 2 * the number of ranged primal rows.
1855  /// dualCols must have the identical size to the primal rows.
1856  virtual void buildDualProblem(SPxLPBase<R>& dualLP, SPxRowId primalRowIds[] = 0, SPxColId primalColIds[] = 0,
1857  SPxRowId dualRowIds[] = 0, SPxColId dualColIds[] = 0, int* nprimalrows = 0, int* nprimalcols = 0,
1858  int* ndualrows = 0, int* ndualcols = 0);
1859 
1860  //@}
1861 
1862  // ------------------------------------------------------------------------------------------------------------------
1863  /**@name Miscellaneous */
1864  //@{
1865 
1866  /// Consistency check.
1867  bool isConsistent() const
1868  {
1869 #ifdef ENABLE_CONSISTENCY_CHECKS
1870 
1871  for( int i = nCols() - 1; i >= 0; --i )
1872  {
1873  const SVectorBase<R>& v = colVector(i);
1874 
1875  for( int j = v.size() - 1; j >= 0; --j )
1876  {
1877  const SVectorBase<R>& w = rowVector(v.index(j));
1878  int n = w.pos(i);
1879 
1880  if( n < 0 )
1881  return MSGinconsistent("SPxLPBase");
1882 
1883  if( v.value(j) != w.value(n) )
1884  return MSGinconsistent("SPxLPBase");
1885  }
1886  }
1887 
1888  for( int i = nRows() - 1; i >= 0; --i )
1889  {
1890  const SVectorBase<R>& v = rowVector(i);
1891 
1892  for( int j = v.size() - 1; j >= 0; --j )
1893  {
1894  const SVectorBase<R>& w = colVector(v.index(j));
1895  int n = w.pos(i);
1896 
1897  if( n < 0 )
1898  return MSGinconsistent("SPxLPBase");
1899 
1900  if( v.value(j) != w.value(n) )
1901  return MSGinconsistent("SPxLPBase");
1902  }
1903  }
1904 
1906 #else
1907  return true;
1908 #endif
1909  }
1910 
1911  //@}
1912 
1913 protected:
1914 
1915  // ------------------------------------------------------------------------------------------------------------------
1916  /**@name Protected write access */
1917  //@{
1918 
1919  /// Returns right hand side of row \p i.
1920  R& rhs_w(int i)
1921  {
1922  return LPRowSetBase<R>::rhs_w(i);
1923  }
1924 
1925  /// Returns left hand side of row \p i.
1926  R& lhs_w(int i)
1927  {
1928  return LPRowSetBase<R>::lhs_w(i);
1929  }
1930 
1931  /// Returns objective function value of row \p i.
1932  R& maxRowObj_w(int i)
1933  {
1934  return LPRowSetBase<R>::obj_w(i);
1935  }
1936 
1937  /// Returns objective value of column \p i for maximization problem.
1938  R& maxObj_w(int i)
1939  {
1940  return LPColSetBase<R>::maxObj_w(i);
1941  }
1942 
1943  /// Returns upper bound of column \p i.
1944  R& upper_w(int i)
1945  {
1946  return LPColSetBase<R>::upper_w(i);
1947  }
1948 
1949  /// Returns lower bound of column \p i.
1950  R& lower_w(int i)
1951  {
1952  return LPColSetBase<R>::lower_w(i);
1953  }
1954 
1955  //@}
1956 
1957  // ------------------------------------------------------------------------------------------------------------------
1958  /**@name Protected helpers */
1959  //@{
1960 
1961  /// Returns the LP as an LPRowSetBase.
1962  const LPRowSetBase<R>* lprowset() const
1963  {
1964  return static_cast<const LPRowSetBase<R>*>(this);
1965  }
1966 
1967  /// Returns the LP as an LPColSetBase.
1968  const LPColSetBase<R>* lpcolset() const
1969  {
1970  return static_cast<const LPColSetBase<R>*>(this);
1971  }
1972 
1973  /// Internal helper method.
1974  virtual void doRemoveRow(int j)
1975  {
1976 
1977  const SVectorBase<R>& vec = rowVector(j);
1978 
1979  // remove row vector from column file
1980  for( int i = vec.size() - 1; i >= 0; --i )
1981  {
1982  SVectorBase<R>& remvec = colVector_w(vec.index(i));
1983  int position = remvec.pos(j);
1984  if( position >= 0 )
1985  remvec.remove(position);
1986  }
1987 
1988  // move last row to removed position
1989  int idx = nRows() - 1;
1990  if( j != idx )
1991  {
1992  const SVectorBase<R>& l_vec = rowVector(idx);
1993  for( int i = l_vec.size() - 1; i >= 0; --i )
1994  {
1995  SVectorBase<R>& movevec = colVector_w(l_vec.index(i));
1996  int position = movevec.pos(idx);
1997 
1998  assert(position != -1);
1999 
2000  if( position >= 0 )
2001  movevec.index(position) = j;
2002  }
2003  }
2004 
2006  }
2007 
2008  /// Internal helper method.
2009  virtual void doRemoveRows(int perm[])
2010  {
2011  int j = nCols();
2012 
2014 
2015  for( int i = 0; i < j; ++i )
2016  {
2017  SVectorBase<R>& vec = colVector_w(i);
2018  for( int k = vec.size() - 1; k >= 0; --k )
2019  {
2020  int idx = vec.index(k);
2021  if( perm[idx] < 0 )
2022  vec.remove(k);
2023  else
2024  vec.index(k) = perm[idx];
2025  }
2026  }
2027  }
2028 
2029  /// Internal helper method.
2030  virtual void doRemoveCol(int j)
2031  {
2032 
2033  const SVectorBase<R>& vec = colVector(j);
2034  int i;
2035 
2036  // remove column vector from row file
2037  for( i = vec.size() - 1; i >= 0; --i )
2038  {
2039  SVectorBase<R>& remvec = rowVector_w(vec.index(i));
2040  int position = remvec.pos(j);
2041 
2042  assert(position != -1);
2043 
2044  if( position >= 0 )
2045  remvec.remove(position);
2046  }
2047 
2048  // move last column to removed position
2049  int idx = nCols() - 1;
2050  if( j != idx )
2051  {
2052  const SVectorBase<R>& l_vec = colVector(idx);
2053  for( i = l_vec.size() - 1; i >= 0; --i )
2054  {
2055  SVectorBase<R>& movevec = rowVector_w(l_vec.index(i));
2056  int position = movevec.pos(idx);
2057 
2058  assert(position != -1);
2059 
2060  if( position >= 0 )
2061  movevec.index(position) = j;
2062  }
2063  }
2064 
2066  }
2067 
2068  /// Internal helper method.
2069  virtual void doRemoveCols(int perm[])
2070  {
2071  int nrows = nRows();
2072 
2074 
2075  for( int i = 0; i < nrows; ++i )
2076  {
2077  SVectorBase<R>& vec = rowVector_w(i);
2078 
2079  for( int k = vec.size() - 1; k >= 0; --k )
2080  {
2081  int idx = vec.index(k);
2082  if( perm[idx] < 0 )
2083  vec.remove(k);
2084  else
2085  vec.index(k) = perm[idx];
2086  }
2087  }
2088  }
2089 
2090  /// Called after the last \p n rows have just been added.
2091  virtual void addedRows(int newrows)
2092  {}
2093 
2094  /// Called after the last \p n columns have just been added.
2095  virtual void addedCols(int newcols)
2096  {}
2097 
2098  ///
2099  void added2Set(SVSetBase<R>& set, const SVSetBase<R>& addset, int n)
2100  {
2101 
2102  if( n == 0 )
2103  return;
2104 
2105  DataArray<int> moreArray(set.num());
2106  int* more = moreArray.get_ptr();
2107 
2108  for( int i = set.num() - 1; i >= 0; --i )
2109  more[i] = 0;
2110 
2111  int tot = 0;
2112  int end = addset.num();
2113 
2114  for( int i = addset.num() - n; i < end; ++i )
2115  {
2116  const SVectorBase<R>& vec = addset[i];
2117 
2118  tot += vec.size();
2119  for( int j = vec.size() - 1; j >= 0; --j )
2120  more[vec.index(j)]++;
2121  }
2122 
2123  if( set.memMax() < tot )
2124  set.memRemax(tot);
2125 
2126  for( int i = set.num() - 1; i >= 0; --i )
2127  {
2128  int j = set[i].size();
2129  set.xtend(set[i], j + more[i]);
2130  set[i].set_size( j + more[i] );
2131  more[i] = j;
2132  }
2133 
2134  for( int i = addset.num() - n; i < addset.num(); ++i)
2135  {
2136  const SVectorBase<R>& vec = addset[i];
2137 
2138  for( int j = vec.size() - 1; j >= 0; --j )
2139  {
2140  int k = vec.index(j);
2141  int m = more[k]++;
2142  SVectorBase<R>& l_xtend = set[k];
2143  l_xtend.index(m) = i;
2144  l_xtend.value(m) = vec.value(j);
2145  }
2146  }
2147  }
2148 
2149  //@}
2150 
2151 
2152 private:
2153 
2154  // ------------------------------------------------------------------------------------------------------------------
2155  /**@name Private helpers */
2156  //@{
2157 
2158  /// Returns the LP as an LPRowSet.
2160  {
2161  return LPColSetBase<R>::colVector_w(i);
2162  }
2163 
2164  ///
2166  {
2167  return LPRowSetBase<R>::rowVector_w(i);
2168  }
2169 
2170  ///
2171  void doAddRow (const LPRowBase<R>& row, bool scale = false)
2172  {
2173  int idx = nRows();
2174  int oldColNumber = nCols();
2175  int newRowScaleExp = 0;
2176 
2177  LPRowSetBase<R>::add(row);
2178 
2179  SVectorBase<R>& vec = rowVector_w(idx);
2180 
2182 
2183  // compute new row scaling factor and apply it to the sides
2184  if( scale )
2185  {
2186  newRowScaleExp = lp_scaler->computeScaleExp(vec, colscaleExp);
2187 
2188  if( rhs(idx) < infinity )
2189  rhs_w(idx) = spxLdexp(rhs_w(idx), newRowScaleExp);
2190  if( lhs(idx) > -infinity )
2191  lhs_w(idx) = spxLdexp(lhs_w(idx), newRowScaleExp);
2192 
2193  maxRowObj_w(idx) = spxLdexp(maxRowObj_w(idx), newRowScaleExp);
2194 
2195  LPRowSetBase<R>::scaleExp[idx] = newRowScaleExp;
2196  }
2197 
2198  // now insert nonzeros to column file also
2199  for( int j = vec.size() - 1; j >= 0; --j )
2200  {
2201  int i = vec.index(j);
2202 
2203  // apply new row and existing column scaling factors to new values in RowSet
2204  if( scale )
2205  vec.value(j) = spxLdexp(vec.value(j), newRowScaleExp + colscaleExp[i]);
2206 
2207  R val = vec.value(j);
2208 
2209  // create new columns if required
2210  if( i >= nCols() )
2211  {
2212  LPColBase<R> empty;
2213  for( int k = nCols(); k <= i; ++k )
2214  LPColSetBase<R>::add(empty);
2215  }
2216 
2217  assert(i < nCols());
2218  LPColSetBase<R>::add2(i, 1, &idx, &val);
2219  }
2220 
2221  addedRows(1);
2222  addedCols(nCols() - oldColNumber);
2223  }
2224 
2225  ///
2226  void doAddRow (const R& lhsValue, const SVectorBase<R>& rowVec, const R& rhsValue, bool scale = false)
2227  {
2228  int idx = nRows();
2229  int oldColNumber = nCols();
2230  int newRowScaleExp = 0;
2231 
2232  LPRowSetBase<R>::add(lhsValue, rowVec, rhsValue);
2233 
2235 
2236  // compute new row scaling factor and apply it to the sides
2237  if( scale )
2238  {
2239  newRowScaleExp = lp_scaler->computeScaleExp(rowVec, colscaleExp);
2240 
2241  if( rhs(idx) < infinity )
2242  rhs_w(idx) = spxLdexp(rhs_w(idx), newRowScaleExp);
2243  if( lhs(idx) > -infinity )
2244  lhs_w(idx) = spxLdexp(lhs_w(idx), newRowScaleExp);
2245 
2246  maxRowObj_w(idx) = spxLdexp(maxRowObj_w(idx), newRowScaleExp);
2247 
2248  LPRowSetBase<R>::scaleExp[idx] = newRowScaleExp;
2249  }
2250 
2251  SVectorBase<R>& vec = rowVector_w(idx);
2252 
2253  // now insert nonzeros to column file also
2254  for( int j = vec.size() - 1; j >= 0; --j )
2255  {
2256  int i = vec.index(j);
2257 
2258  // apply new row and existing column scaling factors to new values in RowSet
2259  if( scale )
2260  vec.value(j) = spxLdexp(vec.value(j), newRowScaleExp + colscaleExp[i]);
2261 
2262  R val = vec.value(j);
2263 
2264  // create new columns if required
2265  if( i >= nCols() )
2266  {
2267  LPColBase<R> empty;
2268  for( int k = nCols(); k <= i; ++k )
2269  LPColSetBase<R>::add(empty);
2270  }
2271 
2272  assert(i < nCols());
2273  LPColSetBase<R>::add2(i, 1, &idx, &val);
2274  }
2275 
2276  addedRows(1);
2277  addedCols(nCols() - oldColNumber);
2278  }
2279 
2280  ///
2281  void doAddRows(const LPRowSetBase<R>& set, bool scale = false)
2282  {
2283  int i, j, k, ii, idx;
2284  SVectorBase<R>* col;
2285  DataArray < int > newCols(nCols());
2286  int oldRowNumber = nRows();
2287  int oldColNumber = nCols();
2288 
2289  if( &set != this )
2290  LPRowSetBase<R>::add(set);
2291 
2294 
2295  // count additional nonzeros per column
2296  for( i = nCols() - 1; i >= 0; --i )
2297  newCols[i] = 0;
2298  for( i = set.num() - 1; i >= 0; --i )
2299  {
2300  const SVectorBase<R>& vec = set.rowVector(i);
2301 
2302  for( j = vec.size() - 1; j >= 0; --j )
2303  {
2304  // create new columns if required
2305  ii = vec.index(j);
2306  if( ii >= nCols() )
2307  {
2308  LPColBase<R> empty;
2309  newCols.reSize(ii + 1);
2310  for( k = nCols(); k <= ii; ++k )
2311  {
2312  newCols[k] = 0;
2313  LPColSetBase<R>::add(empty);
2314  }
2315  }
2316 
2317  assert(ii < nCols());
2318  newCols[ii]++;
2319  }
2320  }
2321 
2322  // extend columns as required (backward because of memory efficiency reasons)
2323  for( i = nCols() - 1; i >= 0; --i )
2324  {
2325  if( newCols[i] > 0 )
2326  {
2327  int len = newCols[i] + colVector(i).size();
2328  LPColSetBase<R>::xtend(i, len);
2329 
2330  /* preset the sizes: beware that this can irritate a consistency check call from xtend(). We need to set the
2331  * sizes here, because a possible garbage collection called from xtend might destroy the sizes again. */
2332  colVector_w(i).set_size( len );
2333  }
2334  }
2335 
2336  // compute new row scaling factor and insert new elements to column file
2337  for( i = nRows() - 1; i >= oldRowNumber; --i )
2338  {
2339  SVectorBase<R>& vec = rowVector_w(i);
2340  int newRowScaleExp = 0;
2341 
2343 
2344  // compute new row scaling factor and apply it to the sides
2345  if( scale )
2346  {
2347  newRowScaleExp = lp_scaler->computeScaleExp(vec, colscaleExp);
2348 
2349  if( rhs(i) < infinity )
2350  rhs_w(i) = spxLdexp(rhs_w(i), newRowScaleExp);
2351  if( lhs(i) > -infinity )
2352  lhs_w(i) = spxLdexp(lhs_w(i), newRowScaleExp);
2353 
2354  maxRowObj_w(i) = spxLdexp(maxRowObj_w(i), newRowScaleExp);
2355 
2356  LPRowSetBase<R>::scaleExp[i] = newRowScaleExp;
2357  }
2358 
2359  for( j = vec.size() - 1; j >= 0; --j )
2360  {
2361  k = vec.index(j);
2362  col = &colVector_w(k);
2363  idx = col->size() - newCols[k];
2364  assert(newCols[k] > 0);
2365  assert(idx >= 0);
2366  newCols[k]--;
2367  col->index(idx) = i;
2368  // apply new row and existing column scaling factors to both ColSet and RowSet
2369  if( scale )
2370  vec.value(j) = spxLdexp(vec.value(j), newRowScaleExp + colscaleExp[k]);
2371 
2372  col->value(idx) = vec.value(j);
2373  }
2374  }
2375 
2376 #ifndef NDEBUG
2377  for( i = 0; i < nCols(); ++i )
2378  assert( newCols[i] == 0 );
2379 #endif
2380 
2381  assert(SPxLPBase<R>::isConsistent());
2382 
2383  assert(set.num() == nRows() - oldRowNumber);
2384  addedRows(nRows() - oldRowNumber);
2385  addedCols(nCols() - oldColNumber);
2386  }
2387 
2388  ///
2389  void doAddCol (const LPColBase<R>& col, bool scale = false)
2390  {
2391  int idx = nCols();
2392  int oldRowNumber = nRows();
2393  int newColScaleExp = 0;
2394 
2395  LPColSetBase<R>::add(col);
2396  if( thesense != MAXIMIZE )
2397  LPColSetBase<R>::maxObj_w(idx) *= -1;
2398 
2399  SVectorBase<R>& vec = colVector_w(idx);
2400 
2402 
2403  // compute new column scaling factor and apply it to the bounds
2404  if( scale )
2405  {
2406  newColScaleExp = lp_scaler->computeScaleExp(vec, rowscaleExp);
2407 
2408  if( upper(idx) < infinity )
2409  upper_w(idx) = spxLdexp(upper_w(idx), - newColScaleExp);
2410  if( lower(idx) > -infinity )
2411  lower_w(idx) = spxLdexp(lower_w(idx), - newColScaleExp);
2412 
2413  maxObj_w(idx) = spxLdexp(maxObj_w(idx), newColScaleExp);
2414 
2415  LPColSetBase<R>::scaleExp[idx] = newColScaleExp;
2416  }
2417 
2418  // now insert nonzeros to row file also
2419  for( int j = vec.size() - 1; j >= 0; --j )
2420  {
2421  int i = vec.index(j);
2422 
2423  // apply new column and existing row scaling factors to new values in ColSet
2424  if( scale )
2425  vec.value(j) = spxLdexp(vec.value(j), newColScaleExp + rowscaleExp[i]);
2426 
2427  R val = vec.value(j);
2428 
2429  // create new rows if required
2430  if( i >= nRows() )
2431  {
2432  LPRowBase<R> empty;
2433  for( int k = nRows(); k <= i; ++k )
2434  LPRowSetBase<R>::add(empty);
2435  }
2436 
2437  assert(i < nRows());
2438  LPRowSetBase<R>::add2(i, 1, &idx, &val);
2439  }
2440 
2441  addedCols(1);
2442  addedRows(nRows() - oldRowNumber);
2443  }
2444 
2445  ///
2446  void doAddCol (const R& objValue, const R& lowerValue, const SVectorBase<R>& colVec, const R& upperValue, bool scale = false)
2447  {
2448  int idx = nCols();
2449  int oldRowNumber = nRows();
2450  int newColScaleExp = 0;
2451 
2452  LPColSetBase<R>::add(objValue, lowerValue, colVec, upperValue);
2453  if( thesense != MAXIMIZE )
2454  LPColSetBase<R>::maxObj_w(idx) *= -1;
2455 
2457 
2458  // compute new column scaling factor and apply it to the bounds
2459  if( scale )
2460  {
2461  newColScaleExp = lp_scaler->computeScaleExp(colVec, rowscaleExp);
2462 
2463  if( upper(idx) < infinity )
2464  upper_w(idx) = spxLdexp(upper_w(idx), - newColScaleExp);
2465  if( lower(idx) > -infinity )
2466  lower_w(idx) = spxLdexp(lower_w(idx), - newColScaleExp);
2467 
2468  maxObj_w(idx) = spxLdexp(maxObj_w(idx), newColScaleExp);
2469 
2470  LPColSetBase<R>::scaleExp[idx] = newColScaleExp;
2471  }
2472 
2473  SVectorBase<R>& vec = colVector_w(idx);
2474 
2475  // now insert nonzeros to row file also
2476  for( int j = vec.size() - 1; j >= 0; --j )
2477  {
2478  int i = vec.index(j);
2479 
2480  if( scale )
2481  vec.value(j) = spxLdexp(vec.value(j), newColScaleExp + rowscaleExp[i]);
2482 
2483  R val = vec.value(j);
2484 
2485  // create new rows if required
2486  if( i >= nRows() )
2487  {
2488  LPRowBase<R> empty;
2489  for( int k = nRows(); k <= i; ++k )
2490  LPRowSetBase<R>::add(empty);
2491  }
2492 
2493  assert(i < nRows());
2494  LPRowSetBase<R>::add2(i, 1, &idx, &val);
2495  }
2496 
2497  addedCols(1);
2498  addedRows(nRows() - oldRowNumber);
2499  }
2500 
2501  ///
2502  void doAddCols(const LPColSetBase<R>& set, bool scale = false)
2503  {
2504  int i, j;
2505  int oldColNumber = nCols();
2506  int oldRowNumber = nRows();
2507  DataArray < int > newRows(nRows());
2508 
2509  if( &set != this )
2510  LPColSetBase<R>::add(set);
2511 
2514 
2515  // count additional nonzeros per row
2516  for( i = nRows() - 1; i >= 0; --i )
2517  newRows[i] = 0;
2518 
2519  for( i = set.num() - 1; i >= 0; --i )
2520  {
2521  const SVectorBase<R>& vec = set.colVector(i);
2522 
2523  for( j = vec.size() - 1; j >= 0; --j )
2524  {
2525  // create new rows if required
2526  int l = vec.index(j);
2527  if( l >= nRows() )
2528  {
2529  LPRowBase<R> empty;
2530  newRows.reSize(l + 1);
2531  for( int k = nRows(); k <= l; ++k )
2532  {
2533  newRows[k] = 0;
2534  LPRowSetBase<R>::add(empty);
2535  }
2536 
2537  }
2538 
2539  assert(l < nRows());
2540  newRows[l]++;
2541  }
2542  }
2543 
2544  // extend rows as required
2545  for( i = 0; i < nRows(); ++i )
2546  {
2547  if( newRows[i] > 0 )
2548  {
2549  int len = newRows[i] + rowVector(i).size();
2550  LPRowSetBase<R>::xtend(i, len);
2551  rowVector_w(i).set_size( len );
2552  }
2553  }
2554 
2555  // insert new elements to row file
2556  for( i = oldColNumber; i < nCols(); ++i )
2557  {
2559  SVectorBase<R>& vec = colVector_w(i);
2560  int newColScaleExp = 0;
2561 
2563 
2564  // compute new column scaling factor and apply it to the bounds
2565  if( scale )
2566  {
2567  newColScaleExp = lp_scaler->computeScaleExp(vec, rowscaleExp);
2568 
2569  if( upper(i) < infinity )
2570  upper_w(i) = spxLdexp(upper_w(i), - newColScaleExp);
2571  if( lower(i) > -infinity )
2572  lower_w(i) = spxLdexp(lower_w(i), - newColScaleExp);
2573 
2574  maxObj_w(i) = spxLdexp(maxObj_w(i), newColScaleExp);
2575 
2576  LPColSetBase<R>::scaleExp[i] = newColScaleExp;
2577  }
2578 
2579  for( j = vec.size() - 1; j >= 0; --j )
2580  {
2581  int k = vec.index(j);
2582  SVectorBase<R>& row = rowVector_w(k);
2583  int idx = row.size() - newRows[k];
2584  assert(newRows[k] > 0);
2585  newRows[k]--;
2586  row.index(idx) = i;
2587  // apply new column and existing row scaling factors to both ColSet and RowSet
2588  if( scale )
2589  vec.value(j) = spxLdexp(vec.value(j), newColScaleExp + rowscaleExp[k]);
2590 
2591  row.value(idx) = vec.value(j);
2592  }
2593  }
2594 
2595 #ifndef NDEBUG
2596  for( i = 0; i < nRows(); ++i )
2597  assert( newRows[i] == 0 );
2598 #endif
2599 
2600  assert(SPxLPBase<R>::isConsistent());
2601 
2602  assert(set.num() == nCols() - oldColNumber);
2603  addedCols(nCols() - oldColNumber);
2604  addedRows(nRows() - oldRowNumber);
2605  }
2606 
2607  //@}
2608 
2609 public:
2610 
2611  // ------------------------------------------------------------------------------------------------------------------
2612  /**@name Constructors / Destructors */
2613  //@{
2614 
2615  /// Default constructor.
2617  {
2618  SPxLPBase<R>::clear(); // clear is virtual.
2619 
2620  assert(isConsistent());
2621  }
2622 
2623  /// Destructor.
2624  virtual ~SPxLPBase<R>()
2625  {}
2626 
2627  /// Copy constructor.
2629  : LPRowSetBase<R>(old)
2630  , LPColSetBase<R>(old)
2631  , thesense(old.thesense)
2632  , offset(old.offset)
2633  , _isScaled(old._isScaled)
2634  , lp_scaler(old.lp_scaler)
2635  , spxout(old.spxout)
2636  {
2637  assert(isConsistent());
2638  }
2639 
2640  /// Copy constructor.
2641  template < class S >
2643  : LPRowSetBase<R>(old)
2644  , LPColSetBase<R>(old)
2646  , offset(old.offset)
2647  , _isScaled(old._isScaled)
2648  , lp_scaler(old.lp_scaler)
2649  , spxout(old.spxout)
2650  {
2651  assert(isConsistent());
2652  }
2653 
2654  /// Assignment operator.
2656  {
2657  if( this != &old )
2658  {
2661  thesense = old.thesense;
2662  offset = old.offset;
2663  _isScaled = old._isScaled;
2664  lp_scaler = old.lp_scaler;
2665  spxout = old.spxout;
2666 
2667  assert(isConsistent());
2668  }
2669 
2670  return *this;
2671  }
2672 
2673  /// Assignment operator.
2674  template < class S >
2676  {
2677  if( this != (const SPxLPBase<R>*)(&old) )
2678  {
2682  offset = R(old.offset);
2683  _isScaled = old._isScaled;
2684  lp_scaler = old.lp_scaler;
2685  spxout = old.spxout;
2686 
2687  assert(isConsistent());
2688  }
2689 
2690  return *this;
2691  }
2692 
2693  //@}
2694 };
2695 
2696 
2697 // Declaration of Real specializations found in spxlpbase_real.cpp
2698 
2699 template <>
2701 
2702 template <>
2703 void SPxLPBase<Real>::computePrimalActivity(const VectorBase<Real>& primal, VectorBase<Real>& activity, const bool unscaled) const;
2704 
2705 template <>
2706 void SPxLPBase<Real>::computeDualActivity(const VectorBase<Real>& dual, VectorBase<Real>& activity, const bool unscaled) const;
2707 
2708 template <>
2709 Real SPxLPBase<Real>::maxAbsNzo(bool unscaled) const;
2710 
2711 template <>
2712 Real SPxLPBase<Real>::minAbsNzo(bool unscaled) const;
2713 
2714 template <>
2716 
2717 template <>
2719 
2720 template <>
2722 
2723 template <>
2724 Real SPxLPBase<Real>::rhsUnscaled(int i) const;
2725 
2726 template <>
2727 Real SPxLPBase<Real>::rhsUnscaled(const SPxRowId& id) const;
2728 
2729 template <>
2731 
2732 template <>
2733 Real SPxLPBase<Real>::lhsUnscaled(int i) const;
2734 
2735 template <>
2736 Real SPxLPBase<Real>::lhsUnscaled(const SPxRowId& id) const;
2737 
2738 template <>
2740 
2741 template <>
2743 
2744 template <>
2745 Real SPxLPBase<Real>::objUnscaled(int i) const;
2746 
2747 template <>
2748 Real SPxLPBase<Real>::objUnscaled(const SPxColId& id) const;
2749 
2750 template <>
2752 
2753 template <>
2755 
2756 template <>
2758 
2759 template <>
2761 
2762 template <>
2764 
2765 template <>
2767 
2768 template <>
2770 
2771 template <>
2773 
2774 template <>
2776 
2777 template <>
2778 void SPxLPBase<Real>::changeMaxObj(const VectorBase<Real>& newObj, bool scale);
2779 
2780 template <>
2781 void SPxLPBase<Real>::changeLower(const VectorBase<Real>& newLower, bool scale);
2782 
2783 template <>
2784 void SPxLPBase<Real>::changeUpper(const VectorBase<Real>& newUpper, bool scale);
2785 
2786 template <>
2787 void SPxLPBase<Real>::changeLhs(const VectorBase<Real>& newLhs, bool scale);
2788 
2789 template <>
2790 void SPxLPBase<Real>::changeRhs(const VectorBase<Real>& newRhs, bool scale);
2791 
2792 template <>
2793 bool SPxLPBase<Real>::readLPF(std::istream& p_input, NameSet* p_rnames, NameSet* p_cnames, DIdxSet* p_intvars);
2794 
2795 template <>
2796 bool SPxLPBase<Real>::readMPS(std::istream& p_input, NameSet* p_rnames, NameSet* p_cnames, DIdxSet* p_intvars);
2797 
2798 template <>
2799 void SPxLPBase<Real>::writeLPF(std::ostream& p_output, const NameSet* p_rnames, const NameSet* p_cnames, const DIdxSet* p_intvars) const;
2800 
2801 template <>
2802 void SPxLPBase<Real>::writeMPS(std::ostream& p_output, const NameSet* p_rnames, const NameSet* p_cnames, const DIdxSet* p_intvars) const;
2803 
2804 template <>
2805 void SPxLPBase<Real>::buildDualProblem(SPxLPBase<Real>& dualLP, SPxRowId primalRowIds[], SPxColId primalColIds[], SPxRowId dualRowIds[], SPxColId dualColIds[], int* nprimalrows, int* nprimalcols, int* ndualrows, int* ndualcols);
2806 
2807 } // namespace soplex
2808 
2809 /* reset the SOPLEX_DEBUG flag to its original value */
2810 #undef SOPLEX_DEBUG
2811 #ifdef SOPLEX_DEBUG_SPXLPBASE
2812 #define SOPLEX_DEBUG
2813 #undef SOPLEX_DEBUG_SPXLPBASE
2814 #endif
2815 
2816 #endif // _SPXLPBASE_H_
const VectorBase< R > & rhs() const
Returns right hand side vector.
Definition: spxlpbase.h:219
virtual void buildDualProblem(SPxLPBase< R > &dualLP, SPxRowId primalRowIds[]=0, SPxColId primalColIds[]=0, SPxRowId dualRowIds[]=0, SPxColId dualColIds[]=0, int *nprimalrows=0, int *nprimalcols=0, int *ndualrows=0, int *ndualcols=0)
Building the dual problem from a given LP.
VectorBase< R > & obj_w()
Returns the vector of objective coefficients (writeable).
Definition: lprowsetbase.h:173
bool has(const SPxId &id) const
Returns the row or column number for identifier id.
Definition: spxlpbase.h:554
LPRowBase< R >::Type rowType(const SPxRowId &id) const
Returns the inequality type of the row with identifier key.
Definition: spxlpbase.h:330
void getRhsUnscaled(VectorBase< Real > &vec) const
Gets unscaled right hand side vector.
Exception class for things that should NEVER happen.This class is derived from the SoPlex exception b...
Definition: exceptions.h:109
int number(const SPxId &id) const
Returns the row or column number for identifier id.
Definition: spxlpbase.h:534
virtual void removeRow(int i)
Removes i &#39;th row.
Definition: spxlpbase.h:904
void getRow(int i, LPRowBase< R > &row) const
Gets i &#39;th row.
Definition: spxlpbase.h:180
virtual void changeObj(SPxColId id, const R &newVal, bool scale=false)
Changes objective value of column with identifier id to newVal. scale determines whether the new data...
Definition: spxlpbase.h:1317
void memRemax(int newmax)
Resets length of nonzero memory.
Definition: lpcolsetbase.h:539
const SVectorBase< R > & colVector(const SPxColId &id) const
Returns column vector of column with identifier id.
Definition: spxlpbase.h:379
void addRows(const S *lhsValues, const S *rowValues, const int *rowIndices, const int *rowStarts, const int *rowLengths, const int numRows, const int numValues, const S *rhsValues)
Definition: spxlpbase.h:642
SPxRowId rId(int n) const
Returns the row identifier for row n.
Definition: spxlpbase.h:562
void doAddCol(const LPColBase< R > &col, bool scale=false)
Definition: spxlpbase.h:2389
const VectorBase< R > & lower() const
Definition: lpcolsetbase.h:130
const R & objOffset() const
Returns the objective function value offset.
Definition: spxlpbase.h:516
Set of LP columns.
LPRowBase< R >::Type type(int i) const
Returns the inequalitiy type of the i &#39;th LPRowBase.
Definition: lprowsetbase.h:227
const VectorBase< R > & upper() const
Returns upper bound vector.
Definition: spxlpbase.h:456
virtual R minAbsNzo(bool unscaled=true) const
Absolute smallest non-zero element in (possibly scaled) LP.
THREADLOCAL const Real infinity
Definition: spxdefines.cpp:26
void getRows(int start, int end, LPRowSetBase< R > &set) const
Gets rows start, ... end.
Definition: spxlpbase.h:195
Entry identifier class for items of a DataSet.
void setOutstream(SPxOut &newOutstream)
Definition: spxlpbase.h:125
const R & upper(int i) const
Returns upper bound of column i.
Definition: spxlpbase.h:462
bool _isScaled
true, if scaling has been performed
Definition: spxlpbase.h:113
Dense vector.Class VectorBase provides dense linear algebra vectors. It does not provide memory manag...
Definition: dsvectorbase.h:28
bool has(const SPxRowId &id) const
Returns the row number of the row with identifier id.
Definition: spxlpbase.h:542
Geometric mean row/column scaling.This SPxScaler implementation performs geometric mean scaling of th...
Definition: spxgeometsc.h:35
void changeObj(int i, const S *newVal)
changes i &#39;th objective vector element to newVal.
Definition: spxlpbase.h:1308
virtual void changeRange(SPxRowId id, const R &newLhs, const R &newRhs, bool scale=false)
Changes left and right hand side of row with identifier id. scale determines whether the new data sho...
Definition: spxlpbase.h:1556
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
const R & maxObj(int i) const
Returns objective value of column i for maximization problem.
Definition: spxlpbase.h:435
virtual void addRows(SPxRowId id[], const LPRowSetBase< R > &set, bool scale=false)
adds all LPRowBases of pset to LPRowSetBase.
Definition: spxlpbase.h:732
T * get_ptr()
get a C pointer to the data.
Definition: dataarray.h:110
R & maxObj_w(int i)
Returns objective value of column i for maximization problem.
Definition: spxlpbase.h:1938
const VectorBase< R > & lhs() const
Returns the vector of lhs values.
Definition: lprowsetbase.h:95
virtual void removeRowRange(int start, int end, int perm[]=0)
Removes rows from start to end (including both).
Definition: spxlpbase.h:974
int size() const
Number of used indices.
Definition: svectorbase.h:152
void doAddCols(const LPColSetBase< R > &set, bool scale=false)
Definition: spxlpbase.h:2502
void xtend(int n, int newmax)
Extends row n to fit newmax nonzeros.
Definition: lprowsetbase.h:436
virtual void changeLower(int i, const R &newLower, bool scale=false)
changes i &#39;th lower bound to newLower. scale determines whether the new data should be scaled ...
Definition: spxlpbase.h:1369
Dymnamic index set.
void changeRange(int i, const S *newLhs, const S *newRhs)
Changes left and right hand side of row i.
Definition: spxlpbase.h:1548
virtual bool readFile(const char *filename, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
Reads LP from a file.
Definition: spxlpbase.h:1154
virtual void changeMaxObj(int i, const R &newVal, bool scale=false)
changes i &#39;th objective vector element to newVal. scale determines whether the new data should be sca...
Definition: spxlpbase.h:1332
bool isScaled() const
Returns true if and only if the LP is scaled.
Definition: spxlpbase.h:139
R rhsUnscaled(int i) const
Returns unscaled right hand side of row number i.
void clear()
Removes all LPRowBases.
Definition: lprowsetbase.h:579
virtual void changeCol(int n, const LPColBase< R > &newCol, bool scale=false)
Replaces i &#39;th column of LP with newCol. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1638
virtual void changeRowObj(int i, const R &newRowObj, bool scale=false)
Changes i &#39;th row objective function value to newRowObj. scale determines whether the new data should...
Definition: spxlpbase.h:1572
virtual void removeCols(int perm[])
Removes multiple columns.
Definition: spxlpbase.h:1020
void getObj(VectorBase< R > &pobj) const
Gets objective vector.
Definition: spxlpbase.h:394
void doAddRow(const R &lhsValue, const SVectorBase< R > &rowVec, const R &rhsValue, bool scale=false)
Definition: spxlpbase.h:2226
const SVectorBase< R > & rowVector() const
Constraint row vector.
Definition: lprowbase.h:239
virtual void addedCols(int newcols)
Called after the last n columns have just been added.
Definition: spxlpbase.h:2095
R rhs() const
Right-hand side value.
Definition: lprowbase.h:215
Dynamic sparse vectors.Class DSVectorBase implements dynamic sparse vectors, i.e. SVectorBases with a...
Definition: dsvectorbase.h:42
void remove(int i)
Removes i &#39;th LPColBase.
Definition: lpcolsetbase.h:424
Least squares scaling.This SPxScaler implementation performs least squares scaling as suggested by Cu...
Definition: spxleastsqsc.h:36
virtual void changeElement(SPxRowId rid, SPxColId cid, const R &val, bool scale=false)
Changes LP element identified by (rid, cid) to val. scale determines whether the new data should be s...
Definition: spxlpbase.h:1757
virtual void changeBounds(int i, const R &newLower, const R &newUpper, bool scale=false)
Changes bounds of column i to newLower and newUpper. scale determines whether the new data should be ...
Definition: spxlpbase.h:1442
const R & lhs(int i) const
Returns left hand side of row number i.
Definition: spxlpbase.h:259
R obj(const SPxColId &id) const
Returns objective value of column with identifier id.
Definition: spxlpbase.h:413
void addRow(const S *lhsValue, const S *rowValues, const int *rowIndices, int rowSize, const S *rhsValue)
Definition: spxlpbase.h:593
virtual void removeRows(int nums[], int n, int perm[]=0)
Removes n LPRowBases.
Definition: spxlpbase.h:954
int number(const SPxRowId &id) const
Returns the row number of the row with identifier id.
Definition: spxlpbase.h:522
void setLower(const R &p_low)
Sets lower bound.
Definition: lpcolbase.h:142
const LPRowSetBase< R > * lprowset() const
Returns the LP as an LPRowSetBase.
Definition: spxlpbase.h:1962
void add(const LPColBase< R > &pcol)
Definition: lpcolsetbase.h:255
SPxLPBase< R > & operator=(const SPxLPBase< R > &old)
Assignment operator.
Definition: spxlpbase.h:2655
virtual Real scaleUpper(const SPxLPBase< Real > &lp, int col, Real upper) const
returns scaled upper bound of column col.
Definition: spxscaler.cpp:725
R obj() const
Gets objective value.
Definition: lpcolbase.h:113
virtual void changeRange(int i, const R &newLhs, const R &newRhs, bool scale=false)
Changes left and right hand side of row i. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1539
virtual bool read(std::istream &in, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
Reads LP in LP or MPS format from input stream in.
Definition: spxlpbase.h:1134
Set of strings.
virtual void removeCol(int i)
Removes i &#39;th column.
Definition: spxlpbase.h:1001
void getRowObj(VectorBase< R > &prowobj) const
Gets row objective function vector.
Definition: spxlpbase.h:271
R & value(int n)
Reference to value of n &#39;th nonzero.
Definition: svectorbase.h:252
virtual void changeRow(SPxRowId id, const LPRowBase< R > &newRow, bool scale=false)
Replaces row with identifier id with newRow. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1632
Ids for LP columns.Class SPxColId provides DataKeys for the column indices of an SPxLP.
Definition: spxid.h:36
VectorBase< R > & lhs_w()
Returns the vector of lhs values.
Definition: lprowsetbase.h:101
R & rhs_w(int i)
Returns right hand side of row i.
Definition: spxlpbase.h:1920
void setUpper(const R &p_up)
Sets upper bound.
Definition: lpcolbase.h:131
virtual bool readMPS(std::istream &in, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
Reads an LP in MPS format from input stream in.
VectorBase< R > & maxObj_w()
Returns vector of objective values w.r.t. maximization.
Definition: lpcolsetbase.h:100
void remove(int n, int m)
Remove nonzeros n thru m.
Definition: svectorbase.h:387
VectorBase< R > & lower_w()
Returns vector of lower bound values.
Definition: lpcolsetbase.h:136
const SVectorBase< R > & rowVector(const SPxRowId &id) const
Gets row vector of row with identifier id.
Definition: spxlpbase.h:210
virtual Real scaleLhs(const SPxLPBase< Real > &lp, int row, Real lhs) const
returns scaled left hand side of row row.
Definition: spxscaler.cpp:736
void add(const LPRowBase< R > &row)
Definition: lprowsetbase.h:321
const VectorBase< R > & maxObj() const
Definition: lpcolsetbase.h:94
VectorBase< R > & upper_w()
Returns vector of upper bound values.
Definition: lpcolsetbase.h:172
virtual void changeObjOffset(const R &o)
Definition: spxlpbase.h:1773
SPxColId cId(int n) const
Returns the column identifier for column n.
Definition: spxlpbase.h:568
SVectorBase< R > & rowVector_w(int i)
Definition: spxlpbase.h:2165
int number(const SPxColId &id) const
Returns the column number of the column with identifier id.
Definition: spxlpbase.h:528
virtual void removeRows(int perm[])
Removes multiple rows.
Definition: spxlpbase.h:923
void changeLower(int i, const S *newLower)
changes i &#39;th lower bound to newLower.
Definition: spxlpbase.h:1384
void getObjUnscaled(VectorBase< Real > &pobj) const
Gets unscaled objective vector.
void memRemax(int newmax)
Reallocates memory to be able to store newmax nonzeros.
Definition: lprowsetbase.h:621
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:151
bool isConsistent() const
Checks consistency.
Definition: lpcolsetbase.h:557
R lower() const
Gets lower bound.
Definition: lpcolbase.h:137
int number(const DataKey &k) const
Returns number of LPColBase with DataKey k in LPColSetBase.
Definition: lpcolsetbase.h:232
const SVectorBase< R > & colVector() const
Gets constraint column vector.
Definition: lpcolbase.h:148
Generic Ids for LP rows or columns.Both SPxColIds and SPxRowIds may be treated uniformly as SPxIds: ...
Definition: spxid.h:85
R objUnscaled(int i) const
Returns unscaled objective value of column i.
int nNzos() const
Returns number of nonzeros in LP.
Definition: spxlpbase.h:163
virtual void changeLhs(SPxRowId id, const R &newLhs, bool scale=false)
Changes left hand side value for row with identifier id. scale determines whether the new data should...
Definition: spxlpbase.h:1496
virtual void addCol(const R &objValue, const R &lowerValue, const SVectorBase< R > &colVec, const R &upperValue, bool scale=false)
Definition: spxlpbase.h:747
virtual void changeObj(int i, const R &newVal, bool scale=false)
changes i &#39;th objective vector element to newVal. scale determines whether the new data should be sca...
Definition: spxlpbase.h:1299
void getLowerUnscaled(DVector &vec) const
Gets unscaled lower bound vector.
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
SPxSense
Optimization sense.
Definition: spxlpbase.h:97
virtual void writeFile(const char *filename, const NameSet *rowNames=0, const NameSet *colNames=0, const DIdxSet *p_intvars=0) const
Write loaded LP to filename.
Definition: spxlpbase.h:1175
declaration of types for file output
void maxObjUnscaled(VectorBase< Real > &vec) const
Returns unscaled objective vector for maximization problem.
double Real
Definition: spxdefines.h:218
virtual void changeUpper(SPxColId id, const R &newUpper, bool scale=false)
Changes upper bound of column with identifier id to newLower. scale determines whether the new data s...
Definition: spxlpbase.h:1428
virtual void changeMaxObj(SPxColId id, const R &newVal, bool scale=false)
Changes objective value of column with identifier id to newVal. scale determines whether the new data...
Definition: spxlpbase.h:1354
virtual void computeDualActivity(const VectorBase< R > &dual, VectorBase< R > &activity, const bool unscaled=true) const
Computes "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need ...
virtual void doRemoveRows(int perm[])
Internal helper method.
Definition: spxlpbase.h:2009
void getColVectorUnscaled(int i, DSVectorBase< Real > &vec) const
Gets column vector of column i.
Row and columns Id&#39;s SPxLP.
static void setFixed(std::ostream &stream, int precision=8)
Sets the precision of the stream to 8 and the floatfield to fixed.
Definition: spxout.h:177
SPxSense spxSense() const
Returns the optimization sense.
Definition: spxlpbase.h:510
int & index(int n)
Reference to index of n &#39;th nonzero.
Definition: svectorbase.h:234
virtual void changeMaxObj(const VectorBase< R > &newObj, bool scale=false)
Changes objective vector to newObj. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1323
bool has(const DataKey &k) const
Does DataKey k belong to LPColSetBase ?
Definition: lpcolsetbase.h:238
SVectorBase< R > & colVector_w(int i)
Definition: lpcolsetbase.h:202
const VectorBase< R > & rhs() const
Returns the vector of rhs values.
Definition: lprowsetbase.h:131
R upperUnscaled(int i) const
Returns unscaled upper bound of column i.
R lhs() const
Left-hand side value.
Definition: lprowbase.h:203
virtual void addCol(SPxColId &id, const LPColBase< R > &col, bool scale=false)
Adds col to LPColSetVBase.
Definition: spxlpbase.h:786
LPRowSetBase< R > & operator=(const LPRowSetBase< R > &rs)
Assignment operator.
Definition: lprowsetbase.h:675
R rowObj(int i) const
Definition: spxlpbase.h:279
SVectorBase< R > & rowVector_w(int i)
Returns a writable rowVector of the i &#39;th LPRowBase.
Definition: lprowsetbase.h:203
Wrapper for several output streams. A verbosity level is used to decide which stream to use and wheth...
Definition: spxout.h:63
virtual void addRows(const LPRowSetBase< R > &pset, bool scale=false)
Definition: spxlpbase.h:635
virtual void changeBounds(SPxColId id, const R &newLower, const R &newUpper, bool scale=false)
Changes bounds of column with identifier id. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1459
virtual void changeRowObj(SPxRowId id, const R &newRowObj, bool scale=false)
Changes row objective function value for row with identifier id. scale determines whether the new dat...
Definition: spxlpbase.h:1581
void doAddRows(const LPRowSetBase< R > &set, bool scale=false)
Definition: spxlpbase.h:2281
void changeBounds(int i, const S *newLower, const S *newUpper)
Changes bounds of column i to newLower and newUpper.
Definition: spxlpbase.h:1451
virtual void changeLower(const VectorBase< R > &newLower, bool scale=false)
Changes vector of lower bounds to newLower. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1360
LPRowBase< R >::Type rowType(int i) const
Returns the inequality type of the i&#39;th LPRow.
Definition: spxlpbase.h:324
virtual bool readLPF(std::istream &in, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
Reads LP in LP format from input stream in.
virtual void removeRow(SPxRowId id)
Removes row with identifier id.
Definition: spxlpbase.h:913
virtual void changeRhs(const VectorBase< R > &newRhs, bool scale=false)
Changes right hand side vector for constraints to newRhs. scale determines whether the new data shoul...
Definition: spxlpbase.h:1502
R obj(int i) const
Returns objective value of column i.
Definition: spxlpbase.h:403
virtual void changeCol(SPxColId id, const LPColBase< R > &newCol, bool scale=false)
Replaces column with identifier id with newCol. scale determines whether the new data should be scale...
Definition: spxlpbase.h:1677
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 void changeRhs(SPxRowId id, const R &newRhs, bool scale=false)
Changes right hand side value for row with identifier id. scale determines whether the new data shoul...
Definition: spxlpbase.h:1525
virtual void removeCols(int nums[], int n, int perm[]=0)
Removes n LPCols.
Definition: spxlpbase.h:1051
void add2(const DataKey &k, int n, const int idx[], const R val[])
Adds n nonzero (idx, val)-pairs to rowVector with DataKey k.
Definition: lprowsetbase.h:448
virtual void addPrimalActivity(const SVectorBase< R > &primal, VectorBase< R > &activity) const
Updates activity of the rows for a given primal vector; activity does not need to be zero...
Definition: spxlpbase.h:1787
void addCols(const S *objValue, const S *lowerValues, const S *colValues, const int *colIndices, const int *colStarts, const int *colLengths, const int numCols, const int numValues, const S *upperValues)
Definition: spxlpbase.h:800
R rowObj(const SPxRowId &id) const
Returns row objective function value of row with identifier id.
Definition: spxlpbase.h:288
const R & lhs(const SPxRowId &id) const
Returns left hand side of row with identifier id.
Definition: spxlpbase.h:265
virtual void scaleObj(const SPxLPBase< Real > &lp, VectorReal &origObj) const
apply scaling to objective function vector origObj.
Definition: spxscaler.cpp:676
void getRhs(VectorBase< R > &vec) const
Gets (internal and possibly scaled) right hand side vector.
Definition: spxlpbase.h:238
Dynamic index set.Class DIdxSet provides dynamic IdxSet in the sense, that no restrictions are posed ...
Definition: didxset.h:42
virtual void changeBounds(const VectorBase< R > &newLower, const VectorBase< R > &newUpper, bool scale=false)
Changes variable bounds to newLower and newUpper. scale determines whether the new data should be sca...
Definition: spxlpbase.h:1434
void getCol(int i, LPColBase< R > &col) const
Gets i &#39;th column.
Definition: spxlpbase.h:336
LPColSetBase< R > & operator=(const LPColSetBase< R > &rs)
Assignment operator.
Definition: lpcolsetbase.h:592
virtual void addCols(SPxColId id[], const LPColSetBase< R > &set, bool scale=false)
Adds all LPColBases of set to LPColSetBase.
Definition: spxlpbase.h:888
column identifier.
Definition: spxid.h:99
void setObj(const R &p_obj)
Sets objective coefficient value.
Definition: lprowbase.h:233
const VectorBase< R > & maxRowObj() const
Definition: spxlpbase.h:297
R lhsUnscaled(int i) const
Returns unscaled left hand side of row number i.
(In)equality for LPs.Class LPRowBase provides constraints for linear programs in the form where a is...
Definition: lprowbase.h:45
void setScalingInfo(bool scaled)
set whether the LP is scaled or not
Definition: spxlpbase.h:145
virtual void changeRow(int n, const LPRowBase< R > &newRow, bool scale=false)
Replaces i &#39;th row of LP with newRow. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1593
void added2Set(SVSetBase< R > &set, const SVSetBase< R > &addset, int n)
Definition: spxlpbase.h:2099
virtual void changeUpper(const VectorBase< R > &newUpper, bool scale=false)
Changes vector of upper bounds to newUpper. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1397
R & maxRowObj_w(int i)
Returns objective function value of row i.
Definition: spxlpbase.h:1932
Debugging, floating point type and parameter definitions.
Simplex basis.Consider the linear program as provided from class SPxLP: where , and ...
Definition: spxbasis.h:82
virtual void removeRows(SPxRowId id[], int n, int perm[]=0)
Definition: spxlpbase.h:929
Set of strings.Class NameSet implements a symbol or name table. It allows to store or remove names (i...
Definition: nameset.h:61
virtual void addRow(const R &lhsValue, const SVectorBase< R > &rowVec, const R &rhsValue, bool scale=false)
Definition: spxlpbase.h:586
void setLhs(const R &p_left)
Sets left-hand side value.
Definition: lprowbase.h:209
bool EQ(Real a, Real b, Real eps=Param::epsilon())
returns true iff |a-b| <= eps
Definition: spxdefines.h:376
virtual void changeObj(const VectorBase< R > &newObj, bool scale=false)
Changes objective vector to newObj. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1291
virtual Real scaleLower(const SPxLPBase< Real > &lp, int col, Real lower) const
returns scaled lower bound of column col.
Definition: spxscaler.cpp:714
void getCol(const SPxColId &id, LPColBase< R > &col) const
Gets column with identifier id.
Definition: spxlpbase.h:345
R offset
offset computed, e.g., in simplification step
Definition: spxlpbase.h:112
virtual void addDualActivity(const SVectorBase< R > &dual, VectorBase< R > &activity) const
Updates "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need t...
Definition: spxlpbase.h:1810
void changeLhs(int i, const S *newLhs)
Changes i &#39;th left hand side value to newLhs.
Definition: spxlpbase.h:1489
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition: vectorbase.h:410
Collection of dense, sparse, and semi-sparse vectors.
virtual void addCol(const LPColBase< R > &col, bool scale=false)
Definition: spxlpbase.h:741
SPxLPBase< R > & operator=(const SPxLPBase< S > &old)
Assignment operator.
Definition: spxlpbase.h:2675
int dim() const
Dimension of vector.
Definition: vectorbase.h:215
virtual void doRemoveCols(int perm[])
Internal helper method.
Definition: spxlpbase.h:2069
bool has(const SPxColId &id) const
Returns the column number of the column with identifier id.
Definition: spxlpbase.h:548
Everything should be within this namespace.
const R & maxRowObj(int i) const
Definition: spxlpbase.h:303
void getCols(int start, int end, LPColSetBase< R > &set) const
Gets columns start, ..., end.
Definition: spxlpbase.h:351
virtual void changeLower(SPxColId id, const R &newLower, bool scale=false)
changes lower bound of column with identifier id to newLower. scale determines whether the new data s...
Definition: spxlpbase.h:1391
virtual void changeRange(const VectorBase< R > &newLhs, const VectorBase< R > &newRhs, bool scale=false)
Changes left and right hand side vectors. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1531
void changeElement(int i, int j, const S *val)
Changes LP element (i, j) to val.
Definition: spxlpbase.h:1726
void clear()
Remove all indices.
Definition: svectorbase.h:422
virtual void writeLPF(std::ostream &out, const NameSet *rowNames, const NameSet *colNames, const DIdxSet *p_intvars=0) const
R & upper_w(int i)
Returns upper bound of column i.
Definition: spxlpbase.h:1944
Saving LPs in a form suitable for SoPlex.Class SPxLPBase provides the data structures required for sa...
Definition: spxlpbase.h:80
Set of LP columns.Class LPColSetBase implements a set of LPColBase%s. Unless for memory limitations...
Definition: lpcolsetbase.h:43
const SVectorBase< R > & rowVector(int i) const
Returns the rowVector of the i &#39;th LPRowBase.
Definition: lprowsetbase.h:209
void setObj(const R &p_object)
Sets objective value.
Definition: lpcolbase.h:119
R lowerUnscaled(int i) const
Returns unscaled lower bound of column i.
virtual void clearRowObjs()
Clears row objective function values for all rows.
Definition: spxlpbase.h:1587
Type
(In)Equality type of an LP row.
Definition: lprowbase.h:72
const VectorBase< R > & maxObj() const
Returns objective vector for maximization problem.
Definition: spxlpbase.h:429
SPxScaler * lp_scaler
points to the scaler if the lp has been scaled, to 0 otherwise
Definition: spxlpbase.h:114
R upper() const
Gets upper bound.
Definition: lpcolbase.h:125
LP scaling base class.
R obj() const
Objective coefficient value.
Definition: lprowbase.h:227
const R & upper(const SPxColId &id) const
Returns upper bound of column with identifier id.
Definition: spxlpbase.h:468
void setRowVector(const DSVectorBase< R > &p_vec)
access constraint row vector.
Definition: lprowbase.h:245
(In)equality for LPs.
void doAddCol(const R &objValue, const R &lowerValue, const SVectorBase< R > &colVec, const R &upperValue, bool scale=false)
Definition: spxlpbase.h:2446
const LPColSetBase< R > * lpcolset() const
Returns the LP as an LPColSetBase.
Definition: spxlpbase.h:1968
bool has(const DataKey &k) const
does DataKey k belong to LPRowSetBase ?
Definition: lprowsetbase.h:304
int memMax() const
Returns length of nonzero memory.
Definition: lpcolsetbase.h:533
const SVectorBase< R > & rowVector(int i) const
Gets row vector of row i.
Definition: spxlpbase.h:204
virtual void writeMPS(std::ostream &out, const NameSet *rowNames, const NameSet *colNames, const DIdxSet *p_intvars=0) const
Writes a file in MPS format to out.
virtual void addRow(const LPRowBase< R > &row, bool scale=false)
Definition: spxlpbase.h:580
virtual void changeRowObj(const VectorBase< R > &newRowObj, bool scale=false)
Changes row objective function vector to newRowObj. scale determines whether the new data should be s...
Definition: spxlpbase.h:1562
LP scaler abstract base class.Instances of classes derived from SPxScaler may be loaded to SoPlex in ...
Definition: spxscaler.h:76
std::ifstream spxifstream
Definition: spxfileio.h:43
Set of LP rows.Class LPRowSetBase implements a set of LPRowBase%s. Unless for memory limitations...
Definition: lprowsetbase.h:44
virtual void changeSense(SPxSense sns)
Changes optimization sense to sns.
Definition: spxlpbase.h:1763
void getUpperUnscaled(DVector &vec) const
Gets unscaled upper bound vector.
void xtend(int n, int newmax)
Extends column n to fit newmax nonzeros.
Definition: lpcolsetbase.h:356
void unscaleLP()
unscales the lp and clears basis
bool isConsistent() const
Checks consistency.
Definition: lprowsetbase.h:638
const VectorBase< R > & upper() const
Definition: lpcolsetbase.h:166
void printProblemStatistics(std::ostream &os)
Definition: spxlpbase.h:1192
virtual void changeLhs(int i, const R &newLhs, bool scale=false)
Changes i &#39;th left hand side value to newLhs. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1474
int pos(int i) const
Position of index i.
Definition: svectorbase.h:185
SPxOut * spxout
Definition: spxlpbase.h:121
bool isConsistent() const
Consistency check.
Definition: spxlpbase.h:1867
LP column.
virtual void removeColRange(int start, int end, int perm[]=0)
Removes columns from start to end (including both).
Definition: spxlpbase.h:1071
const SVectorBase< R > & colVector(int i) const
Returns column vector of column i.
Definition: spxlpbase.h:373
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:157
virtual void removeCols(SPxColId id[], int n, int perm[]=0)
Definition: spxlpbase.h:1026
void changeUpper(int i, const S *newUpper)
Changes i &#39;th upper bound to newUpper.
Definition: spxlpbase.h:1421
virtual void changeElement(int i, int j, const R &val, bool scale=false)
Changes LP element (i, j) to val. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1683
virtual void removeCol(SPxColId id)
Removes column with identifier id.
Definition: spxlpbase.h:1010
virtual void changeLhs(const VectorBase< R > &newLhs, bool scale=false)
Changes left hand side vector for constraints to newLhs. scale determines whether the new data should...
Definition: spxlpbase.h:1465
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
Definition: dvectorbase.h:31
const R & rhs(int i) const
Returns right hand side of row number i.
Definition: spxlpbase.h:225
virtual void changeRhs(int i, const R &newRhs, bool scale=false)
Changes i &#39;th right hand side value to newRhs. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1511
virtual void doRemoveRow(int j)
Internal helper method.
Definition: spxlpbase.h:1974
SPxSense thesense
optimization sense.
Definition: spxlpbase.h:111
void add2(const DataKey &k, int n, const int idx[], const R val[])
Definition: lpcolsetbase.h:368
Ids for LP rows.Class SPxRowId provides DataKeys for the row indices of an SPxLP. ...
Definition: spxid.h:55
virtual void addedRows(int newrows)
Called after the last n rows have just been added.
Definition: spxlpbase.h:2091
const R & lower(int i) const
Returns (internal and possibly scaled) lower bound of column i.
Definition: spxlpbase.h:489
void addCol(const S *objValue, const S *lowerValue, const S *colValues, const int *colIndices, int colSize, const S *upperValue)
Definition: spxlpbase.h:754
#define MSGinconsistent(name)
Definition: spxdefines.h:126
int number(const DataKey &k) const
Returns the number of the LPRowBase with DataKey k in LPRowSetBase.
Definition: lprowsetbase.h:298
void setColVector(const SVectorBase< R > &p_vec)
Sets constraint column vector.
Definition: lpcolbase.h:154
void getLhsUnscaled(VectorBase< Real > &vec) const
Returns unscaled left hand side vector.
void doAddRow(const LPRowBase< R > &row, bool scale=false)
Definition: spxlpbase.h:2171
VectorBase< R > & rhs_w()
Returns the vector of rhs values (writeable).
Definition: lprowsetbase.h:137
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.
const R & maxObj(const SPxColId &id) const
Returns objective value of column with identifier id for maximization problem.
Definition: spxlpbase.h:441
SVectorBase< R > & colVector_w(int i)
Returns the LP as an LPRowSet.
Definition: spxlpbase.h:2159
const SVectorBase< R > & colVector(int i) const
Returns colVector of i &#39;th LPColBase in LPColSetBase.
Definition: lpcolsetbase.h:208
virtual void clear()
clears the LP.
Definition: spxlpbase.h:1098
virtual void doRemoveCol(int j)
Internal helper method.
Definition: spxlpbase.h:2030
const R & lower(const SPxColId &id) const
Returns (internal and possibly scaled) lower bound of column with identifier id.
Definition: spxlpbase.h:495
void clear()
Removes all LPColBases from the set.
Definition: lpcolsetbase.h:499
Equilibrium row/column scaling.This SPxScaler implementation performs equilibrium scaling of the LPs ...
Definition: spxequilisc.h:35
Set of LP columns.
const VectorBase< R > & obj() const
Returns the vector of objective coefficients.
Definition: lprowsetbase.h:167
void setRhs(const R &p_right)
Sets right-hand side value.
Definition: lprowbase.h:221
virtual void addRow(SPxRowId &id, const LPRowBase< R > &row, bool scale=false)
Adds row to LPRowSetBase.
Definition: spxlpbase.h:628
void reSize(int newsize)
reset size to newsize.
Definition: dataarray.h:223
void changeMaxObj(int i, const S *newVal)
changes i &#39;th objective vector element to newVal.
Definition: spxlpbase.h:1347
virtual void changeUpper(int i, const R &newUpper, bool scale=false)
Changes i &#39;th upper bound to newUpper. scale determines whether the new data should be scaled...
Definition: spxlpbase.h:1406
int num() const
Current number of SVectorBases.
Definition: svsetbase.h:746
const VectorBase< R > & lower() const
Returns (internal and possibly scaled) lower bound vector.
Definition: spxlpbase.h:483
virtual R maxAbsNzo(bool unscaled=true) const
Absolute biggest non-zero element in (in rational case possibly scaled) LP.
int num() const
Returns the number of LPColBases currently in LPColSetBase.
Definition: lpcolsetbase.h:82
virtual void computePrimalActivity(const VectorBase< R > &primal, VectorBase< R > &activity, const bool unscaled=true) const
Computes activity of the rows for a given primal vector; activity does not need to be zero...
void getRow(const SPxRowId &id, LPRowBase< R > &row) const
Gets row with identifier id.
Definition: spxlpbase.h:189
LP column.Class LPColBase provides a datatype for storing the column of an LP a the form similar to ...
Definition: lpcolbase.h:45
Sparse vector set.Class SVSetBase provides a set of sparse vectors SVectorBase. All SVectorBases in a...
Definition: ssvectorbase.h:33
void getRowVectorUnscaled(int i, DSVectorBase< Real > &vec) const
Gets unscaled row vector of row i.
VectorBase< R > & multSub(const S &x, const SVectorBase< T > &vec)
Subtraction of scaled vector.
Definition: basevectors.h:293
virtual void addCols(const LPColSetBase< R > &pset, bool scale=false)
Definition: spxlpbase.h:793
const R & maxRowObj(const SPxRowId &id) const
Returns row objective function value of row with identifier id.
Definition: spxlpbase.h:309
int num() const
Returns the number of LPRowBases in LPRowSetBase.
Definition: lprowsetbase.h:83
LP simplifier for removing uneccessary row/columns.This SPxSimplifier is mainly based on the paper "P...
Definition: spxmainsm.h:60
R & lhs_w(int i)
Returns left hand side of row i.
Definition: spxlpbase.h:1926
virtual void subDualActivity(const VectorBase< R > &dual, VectorBase< R > &activity) const
Updates "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need t...
Definition: spxlpbase.h:1828
void remove(int i)
Removes i &#39;th LPRowBase.
Definition: lprowsetbase.h:503
const R & rhs(const SPxRowId &id) const
Returns right hand side of row with identifier id.
Definition: spxlpbase.h:232