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-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file 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 "spxdefines.h"
34 #include "basevectors.h"
35 #include "dataarray.h"
36 #include "datakey.h"
37 #include "spxid.h"
38 #include "lprowbase.h"
39 #include "lpcolbase.h"
40 #include "lprowsetbase.h"
41 #include "lpcolsetbase.h"
42 #include "nameset.h"
43 #include "didxset.h"
44 #include "spxfileio.h"
45 #include "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 identifier for row \p n.
542  SPxRowId rId(int n) const
543  {
544  return SPxRowId(LPRowSetBase<R>::key(n));
545  }
546 
547  /// Returns the column identifier for column \p n.
548  SPxColId cId(int n) const
549  {
550  return SPxColId(LPColSetBase<R>::key(n));
551  }
552 
553  //@}
554 
555  // ------------------------------------------------------------------------------------------------------------------
556  /**@name Extension */
557  //@{
558 
559  ///
560  virtual void addRow(const LPRowBase<R>& row, bool scale = false)
561  {
562  doAddRow(row, scale);
563  }
564 
565  ///
566  virtual void addRow(const R& lhsValue, const SVectorBase<R>& rowVec, const R& rhsValue, bool scale = false)
567  {
568  doAddRow(lhsValue, rowVec, rhsValue, scale);
569  }
570 
571  ///
572  template < class S >
573  void addRow(const S* lhsValue, const S* rowValues, const int* rowIndices, int rowSize, const S* rhsValue)
574  {
575  assert(lhsValue != 0);
576  assert(rowSize <= 0 || rowValues != 0);
577  assert(rowSize <= 0 || rowIndices != 0);
578  assert(rhsValue != 0);
579 
580  int idx = nRows();
581  int oldColNumber = nCols();
582 
583  LPRowSetBase<R>::add(lhsValue, rowValues, rowIndices, rowSize, rhsValue);
584 
585  // now insert nonzeros to column file also
586  for( int j = rowSize - 1; j >= 0; --j )
587  {
588  const S& val = rowValues[j];
589  int i = rowIndices[j];
590 
591  // create new columns if required
592  if( i >= nCols() )
593  {
594  LPColBase<R> empty;
595  for( int k = nCols(); k <= i; ++k )
596  LPColSetBase<R>::add(empty);
597  }
598 
599  assert(i < nCols());
600  LPColSetBase<R>::add2(i, 1, &idx, &val);
601  }
602 
603  addedRows(1);
604  addedCols(nCols() - oldColNumber);
605  }
606 
607  /// Adds \p row to LPRowSetBase.
608  virtual void addRow(SPxRowId& id, const LPRowBase<R>& row, bool scale = false)
609  {
610  addRow(row, scale);
611  id = rId(nRows() - 1);
612  }
613 
614  ///
615  virtual void addRows(const LPRowSetBase<R>& pset, bool scale = false)
616  {
617  doAddRows(pset, scale);
618  }
619 
620  ///
621  template < class S >
622  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)
623  {
624  assert(lhsValues != 0);
625  assert(numValues <= 0 || rowValues != 0);
626  assert(numValues <= 0 || rowIndices != 0);
627  assert(numValues <= 0 || rowStarts != 0);
628  assert(numValues <= 0 || rowLengths != 0);
629  assert(rhsValues != 0);
630 
631  int i, j, k, idx;
632  SVectorBase<R>* col;
633  DataArray < int > newCols(nCols());
634  int oldRowNumber = nRows();
635  int oldColNumber = nCols();
636 
637  LPRowSetBase<R>::memRemax(oldRowNumber + numRows);
638  for( i = 0; i < numRows; i++ )
639  {
640  assert(numValues <= 0 || rowStarts[i] + rowLengths[i] <= numValues);
641  if( numValues <= 0 )
642  LPRowSetBase<R>::add(&(lhsValues[i]), (S*)0, (int*)0, 0, &(rhsValues[i]));
643  else
644  LPRowSetBase<R>::add(&(lhsValues[i]), &(rowValues[rowStarts[i]]), &(rowIndices[rowStarts[i]]), rowLengths[i], &(rhsValues[i]));
645  }
646 
649 
650  // count additional nonzeros per column
651  for( i = nCols() - 1; i >= 0; --i )
652  newCols[i] = 0;
653  if( numValues > 0 )
654  {
655  for( i = 0; i < numRows; i++ )
656  {
657  for( j = rowStarts[i]; j < rowStarts[i] + rowLengths[i]; j++ )
658  {
659  ///@todo implement the addition of new columns as in doAddRows()
660  assert(rowIndices[j] >= 0);
661  assert(rowIndices[j] < oldColNumber);
662  newCols[rowIndices[j]]++;
663  }
664  }
665  }
666 
667  // extend columns as required (backward because of memory efficiency reasons)
668  for( i = nCols() - 1; i >= 0; --i )
669  {
670  if( newCols[i] > 0 )
671  {
672  int len = newCols[i] + colVector(i).size();
673  LPColSetBase<R>::xtend(i, len);
674 
675  /* preset the sizes: beware that this can irritate a consistency check call from xtend(). We need to set the
676  * sizes here, because a possible garbage collection called from xtend might destroy the sizes again. */
677  colVector_w(i).set_size( len );
678  }
679  }
680 
681  // insert new elements to column file
682  for( i = nRows() - 1; i >= oldRowNumber; --i )
683  {
684  const SVectorBase<R>& vec = rowVector(i);
685 
686  for( j = vec.size() - 1; j >= 0; --j )
687  {
688  k = vec.index(j);
689  col = &colVector_w(k);
690  idx = col->size() - newCols[k];
691  assert(newCols[k] > 0);
692  assert(idx >= 0);
693  newCols[k]--;
694  col->index(idx) = i;
695  col->value(idx) = vec.value(j);
696  }
697  }
698 
699 #ifndef NDEBUG
700  for( i = 0; i < nCols(); ++i )
701  assert( newCols[i] == 0 );
702 #endif
703 
704  assert(SPxLPBase<R>::isConsistent());
705 
706  assert( numRows == nRows() - oldRowNumber );
707  addedRows( nRows() - oldRowNumber );
708  addedCols( nCols() - oldColNumber );
709  }
710 
711  /// adds all LPRowBase%s of \p pset to LPRowSetBase.
712  virtual void addRows(SPxRowId id[], const LPRowSetBase<R>& set, bool scale = false)
713  {
714  int i = nRows();
715  addRows(set, scale);
716  for( int j = 0; i < nRows(); ++i, ++j )
717  id[j] = rId(i);
718  }
719 
720  ///
721  virtual void addCol(const LPColBase<R>& col, bool scale = false)
722  {
723  doAddCol(col, scale);
724  }
725 
726  ///
727  virtual void addCol(const R& objValue, const R& lowerValue, const SVectorBase<R>& colVec, const R& upperValue, bool scale = false)
728  {
729  doAddCol(objValue, lowerValue, colVec, upperValue, scale);
730  }
731 
732  ///
733  template < class S >
734  void addCol(const S* objValue, const S* lowerValue, const S* colValues, const int* colIndices, int colSize, const S* upperValue)
735  {
736  int idx = nCols();
737  int oldRowNumber = nRows();
738 
739  LPColSetBase<R>::add(objValue, lowerValue, colValues, colIndices, colSize, upperValue);
740  if( thesense != MAXIMIZE )
741  LPColSetBase<R>::maxObj_w(idx) *= -1;
742 
743  // now insert nonzeros to column file also
744  for( int j = colSize - 1; j >= 0; --j )
745  {
746  const S& val = colValues[j];
747  int i = colIndices[j];
748 
749  // create new rows if required
750  if( i >= nRows() )
751  {
752  LPRowBase<R> empty;
753  for( int k = nRows(); k <= i; ++k )
754  LPRowSetBase<R>::add(empty);
755  }
756 
757  assert(i < nRows());
758  LPRowSetBase<R>::add2(i, 1, &idx, &val);
759  }
760 
761  addedCols(1);
762  addedRows(nRows() - oldRowNumber);
763  }
764 
765  /// Adds \p col to LPColSetVBase.
766  virtual void addCol(SPxColId& id, const LPColBase<R>& col, bool scale = false)
767  {
768  addCol(col, scale);
769  id = cId(nCols() - 1);
770  }
771 
772  ///
773  virtual void addCols(const LPColSetBase<R>& pset, bool scale = false)
774  {
775  doAddCols(pset, scale);
776  }
777 
778  ///
779  template < class S >
780  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)
781  {
782  assert(lowerValues != 0);
783  assert(numValues <= 0 || colValues != 0);
784  assert(numValues <= 0 || colIndices != 0);
785  assert(numValues <= 0 || colStarts != 0);
786  assert(numValues <= 0 || colLengths != 0);
787  assert(upperValues != 0);
788 
789  int i, j, k, idx;
790  SVectorBase<R>* row;
791  DataArray < int > newRows(nRows());
792  int oldColNumber = nCols();
793  int oldRowNumber = nRows();
794  idx = nCols();
795 
796  LPColSetBase<R>::memRemax(oldColNumber + numCols);
797  for( i = 0; i < numCols; i++ )
798  {
799  assert(numValues <= 0 || colStarts[i] + colLengths[i] <= numValues);
800  if( numValues <= 0 )
801  LPColSetBase<R>::add(&(objValue[i]), &(lowerValues[i]), (S*)0, (int*)0, 0, &(upperValues[i]));
802  else
803  LPColSetBase<R>::add(&(objValue[i]), &(lowerValues[i]), &(colValues[colStarts[i]]), &(colIndices[colStarts[i]]), colLengths[i], &(upperValues[i]));
804 
805  if( thesense != MAXIMIZE )
806  LPColSetBase<R>::maxObj_w(idx + i) *= -1;
807  }
808 
811 
812  // count additional nonzeros per rows
813  for( i = nRows() - 1; i >= 0; --i )
814  newRows[i] = 0;
815  for( i = numValues - 1; i >= 0; --i )
816  {
817  ///@todo implement the addition of new rows as in doAddCols()
818  assert(colIndices[i] >= 0);
819  assert(colIndices[i] < oldRowNumber);
820  newRows[colIndices[i]]++;
821  }
822 
823  // extend rows as required (backward because of memory efficiency reasons)
824  for( i = nRows() - 1; i >= 0; --i )
825  {
826  if( newRows[i] > 0 )
827  {
828  int len = newRows[i] + rowVector(i).size();
829  LPRowSetBase<R>::xtend(i, len);
830 
831  /* preset the sizes: beware that this can irritate a consistency check call from xtend(). We need to set the
832  * sizes here, because a possible garbage collection called from xtend might destroy the sizes again. */
833  rowVector_w(i).set_size( len );
834  }
835  }
836 
837  // insert new elements to row file
838  for( i = nCols() - 1; i >= oldColNumber; --i )
839  {
840  const SVectorBase<R>& vec = colVector(i);
841 
842  for( j = vec.size() - 1; j >= 0; --j )
843  {
844  k = vec.index(j);
845  row = &rowVector_w(k);
846  idx = row->size() - newRows[k];
847  assert(newRows[k] > 0);
848  assert(idx >= 0);
849  newRows[k]--;
850  row->index(idx) = i;
851  row->value(idx) = vec.value(j);
852  }
853  }
854 
855 #ifndef NDEBUG
856  for( i = 0; i < nRows(); ++i )
857  assert( newRows[i] == 0 );
858 #endif
859 
860  assert(SPxLPBase<R>::isConsistent());
861 
862  assert( numCols == nCols() - oldColNumber );
863  addedCols( nCols() - oldColNumber );
864  addedRows( nRows() - oldRowNumber );
865  }
866 
867  /// Adds all LPColBase%s of \p set to LPColSetBase.
868  virtual void addCols(SPxColId id[], const LPColSetBase<R>& set, bool scale = false)
869  {
870 
871  int i = nCols();
872  addCols(set, scale);
873  for( int j = 0; i < nCols(); ++i, ++j )
874  id[j] = cId(i);
875  }
876 
877  //@}
878 
879  // ------------------------------------------------------------------------------------------------------------------
880  /**@name Shrinking */
881  //@{
882 
883  /// Removes \p i 'th row.
884  virtual void removeRow(int i)
885  {
886  if( i < 0 )
887  return;
888 
889  doRemoveRow(i);
890  }
891 
892  /// Removes row with identifier \p id.
893  virtual void removeRow(SPxRowId id)
894  {
895  removeRow(number(id));
896  }
897 
898  /// Removes multiple rows.
899  /** This method removes all LPRowBase%s from the SPxLPBase with an index \p i such that \p perm[i] < 0. Upon
900  * completion, \p perm[i] >= 0 indicates the new index where the \p i'th LPRow has been moved to due to this
901  * removal. Note that \p perm must point to an array of at least #nRows() ints.
902  */
903  virtual void removeRows(int perm[])
904  {
905  doRemoveRows(perm);
906  }
907 
908  ///
909  virtual void removeRows(SPxRowId id[], int n, int perm[] = 0)
910  {
911 
912  if( perm == 0 )
913  {
915  removeRows(id, n, p.get_ptr());
916  return;
917  }
918 
919  for( int i = nRows() - 1; i >= 0; --i )
920  perm[i] = i;
921 
922  while( n-- )
923  perm[number(id[n])] = -1;
924 
925  removeRows(perm);
926  }
927 
928  /// Removes \p n LPRowBase%s.
929  /** Removing multiple rows with one method invocation is available in two flavours. An array \p perm can be passed as
930  * third argument or not. If given, \p perm must be an array at least of size #nRows(). It is used to return the
931  * permutations resulting from this removal: \p perm[i] < 0 indicates, that the element to index \p i has been
932  * removed. Otherwise, \p perm[i] is the new index of the element with index \p i before the removal.
933  */
934  virtual void removeRows(int nums[], int n, int perm[] = 0)
935  {
936 
937  if( perm == 0 )
938  {
940  removeRows(nums, n, p.get_ptr());
941  return;
942  }
943 
944  for( int i = nRows() - 1; i >= 0; --i )
945  perm[i] = i;
946 
947  while( n-- )
948  perm[nums[n]] = -1;
949 
950  removeRows(perm);
951  }
952 
953  /// Removes rows from \p start to \p end (including both).
954  virtual void removeRowRange(int start, int end, int perm[] = 0)
955  {
956 
957  if( perm == 0 )
958  {
959  int i = end - start + 1;
960  DataArray < int > p(i);
961 
962  while( --i >= 0 )
963  p[i] = start + i;
964 
965  removeRows(p.get_ptr(), end - start + 1);
966  return;
967  }
968 
969  int i;
970  for( i = 0; i < start; ++i )
971  perm[i] = i;
972  for( ; i <= end; ++i )
973  perm[i] = -1;
974  for( ; i < nRows(); ++i )
975  perm[i] = i;
976 
977  removeRows(perm);
978  }
979 
980  /// Removes \p i 'th column.
981  virtual void removeCol(int i)
982  {
983  if( i < 0 )
984  return;
985 
986  doRemoveCol(i);
987  }
988 
989  /// Removes column with identifier \p id.
990  virtual void removeCol(SPxColId id)
991  {
992  removeCol(number(id));
993  }
994 
995  /// Removes multiple columns.
996  /** This method removes all LPColBase%s from the SPxLPBase with an index \p i such that \p perm[i] < 0. Upon
997  * completion, \p perm[i] >= 0 indicates the new index where the \p i 'th LPColBase has been moved to due to this
998  * removal. Note, that \p perm must point to an array of at least #nCols() ints.
999  */
1000  virtual void removeCols(int perm[])
1001  {
1002  doRemoveCols(perm);
1003  }
1004 
1005  ///
1006  virtual void removeCols(SPxColId id[], int n, int perm[] = 0)
1007  {
1008 
1009  if( perm == 0 )
1010  {
1011  DataArray < int > p(nCols());
1012  removeCols(id, n, p.get_ptr());
1013  return;
1014  }
1015 
1016  for( int i = nCols() - 1; i >= 0; --i )
1017  perm[i] = i;
1018 
1019  while( n-- )
1020  perm[number(id[n])] = -1;
1021 
1022  removeCols(perm);
1023  }
1024 
1025  /// Removes \p n LPCols.
1026  /** Removing multiple columns with one method invocation is available in two flavours. An array \p perm can be passed
1027  * as third argument or not. If given, \p perm must be an array at least of size #nCols(). It is used to return the
1028  * permutations resulting from this removal: \p perm[i] < 0 indicates, that the element to index \p i has been
1029  * removed. Otherwise, \p perm[i] is the new index of the element with index \p i before the removal.
1030  */
1031  virtual void removeCols(int nums[], int n, int perm[] = 0)
1032  {
1033 
1034  if( perm == 0 )
1035  {
1036  DataArray < int > p(nCols());
1037  removeCols(nums, n, p.get_ptr());
1038  return;
1039  }
1040 
1041  for( int i = nCols() - 1; i >= 0; --i )
1042  perm[i] = i;
1043 
1044  while( n-- )
1045  perm[nums[n]] = -1;
1046 
1047  removeCols(perm);
1048  }
1049 
1050  /// Removes columns from \p start to \p end (including both).
1051  virtual void removeColRange(int start, int end, int perm[] = 0)
1052  {
1053 
1054  if( perm == 0 )
1055  {
1056  int i = end - start + 1;
1057  DataArray < int > p(i);
1058 
1059  while( --i >= 0 )
1060  p[i] = start + i;
1061 
1062  removeCols(p.get_ptr(), end - start + 1);
1063  return;
1064  }
1065 
1066  int i;
1067  for( i = 0; i < start; ++i )
1068  perm[i] = i;
1069  for( ; i <= end; ++i )
1070  perm[i] = -1;
1071  for( ; i < nCols(); ++i )
1072  perm[i] = i;
1073 
1074  removeCols(perm);
1075  }
1076 
1077  /// clears the LP.
1078  virtual void clear()
1079  {
1080 
1083  thesense = MAXIMIZE;
1084  offset = 0;
1085  _isScaled = false;
1086  lp_scaler = 0;
1089  }
1090 
1091  //@}
1092 
1093  // ------------------------------------------------------------------------------------------------------------------
1094  /**@name IO */
1095  //@{
1096 
1097  /// Reads LP in LP format from input stream \p in.
1098  virtual bool readLPF(std::istream& in, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0);
1099 
1100  /// Reads an LP in MPS format from input stream \p in.
1101  virtual bool readMPS(std::istream& in, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0);
1102 
1103  /// Reads LP in LP or MPS format from input stream \p in.
1104  /**@param in input stream.
1105  * @param rowNames contains after the call the names of the constraints (rows) in the same order as the rows in the
1106  * LP. Constraints without a name (only possible with LPF files) are automatically assigned a name.
1107  * Maybe 0 if the names are not needed.
1108  * @param colNames contains after the call the names of the variables (columns) in the same order as the columns in
1109  * the LP. Maybe 0 if the names are not needed.
1110  * @param intVars contains after the call the indices of those variables that where marked as beeing integer in the
1111  * file. Maybe 0 if the information is not needed.
1112  * @todo Make sure the Id's in the NameSet%s are the same as in the LP.
1113  */
1114  virtual bool read(std::istream& in, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0)
1115  {
1116  bool ok;
1117  char c;
1118 
1119  in.get(c);
1120  in.putback(c);
1121 
1122  /* MPS starts either with a comment mark '*' or with the keyword 'NAME' at the first column. LPF starts either
1123  * with blanks, a comment mark '\' or with the keyword "MAX" or "MIN" in upper or lower case. There is no
1124  * possible valid LPF file starting with a '*' or 'N'.
1125  */
1126  ok = ((c == '*') || (c == 'N'))
1127  ? readMPS(in, rowNames, colNames, intVars)
1128  : readLPF(in, rowNames, colNames, intVars);
1129 
1130  return ok;
1131  }
1132 
1133  /// Reads LP from a file.
1134  virtual bool readFile(const char* filename, NameSet* rowNames = 0, NameSet* colNames = 0, DIdxSet* intVars = 0)
1135  {
1136 
1137  spxifstream file(filename);
1138 
1139  if( !file )
1140  return false;
1141 
1142  return read(file, rowNames, colNames, intVars);
1143  }
1144 
1145  /** Writes a file in LP format to \p out. If \p rowNames and \p colNames are \c NULL, default names are used for the
1146  * constraints and variables. If \p intVars is not \c NULL, the variables contained in it are marked as integer in
1147  * the output.
1148  */
1149  virtual void writeLPF(std::ostream& out, const NameSet* rowNames, const NameSet* colNames, const DIdxSet* p_intvars = 0) const;
1150 
1151  /// Writes a file in MPS format to \p out.
1152  virtual void writeMPS(std::ostream& out, const NameSet* rowNames, const NameSet* colNames, const DIdxSet* p_intvars = 0) const;
1153 
1154  /// Write loaded LP to \p filename.
1155  virtual void writeFile(const char* filename, const NameSet* rowNames = 0, const NameSet* colNames = 0, const DIdxSet* p_intvars = 0) const
1156  {
1157 
1158  std::ofstream tmp(filename);
1159  size_t len_f = strlen(filename);
1160 
1161  if( len_f > 4 && filename[len_f-1] == 's' && filename[len_f-2] == 'p' && filename[len_f-3] == 'm' && filename[len_f-4] == '.' )
1162  {
1163  writeMPS(tmp, rowNames, colNames, p_intvars);
1164  }
1165  else
1166  {
1167  writeLPF(tmp, rowNames, colNames, p_intvars);
1168  }
1169  }
1170 
1171  /** prints problem statistics */
1172  void printProblemStatistics(std::ostream& os)
1173  {
1174  int countLower = 0;
1175  int countUpper = 0;
1176  int countBoxed = 0;
1177  int countFreeCol = 0;
1178 
1179  int countLhs = 0;
1180  int countRhs = 0;
1181  int countRanged = 0;
1182  int countFreeRow = 0;
1183 
1184  for( int i = 0; i < nCols(); i++ )
1185  {
1186  bool hasLower = false;
1187  bool hasUpper = false;
1188 
1189  if( lower(i) > -infinity )
1190  {
1191  countLower++;
1192  hasLower = true;
1193  }
1194 
1195  if( upper(i) < infinity )
1196  {
1197  countUpper++;
1198  hasUpper = true;
1199  }
1200 
1201  if( hasUpper && hasLower )
1202  countBoxed++;
1203 
1204  if( !hasUpper && !hasLower )
1205  countFreeCol++;
1206  }
1207 
1208  for( int i = 0; i < nRows(); i++)
1209  {
1210  bool hasRhs = false;
1211  bool hasLhs = false;
1212 
1213  if( lhs(i) > -infinity )
1214  {
1215  countLhs++;
1216  hasLhs = true;
1217  }
1218 
1219  if( rhs(i) < infinity )
1220  {
1221  countRhs++;
1222  hasRhs = true;
1223  }
1224 
1225  if( hasRhs && hasLhs )
1226  countRanged++;
1227 
1228  if( !hasRhs && !hasLhs )
1229  countFreeRow++;
1230  }
1231 
1232  os << " Columns : " << nCols() << "\n"
1233  << " boxed : " << countBoxed << "\n"
1234  << " lower bound : " << countLower << "\n"
1235  << " upper bound : " << countUpper << "\n"
1236  << " free : " << countFreeCol << "\n"
1237  << " Rows : " << nRows() << "\n"
1238  << " ranged : " << countRanged << "\n"
1239  << " lhs : " << countLhs << "\n"
1240  << " rhs : " << countRhs << "\n"
1241  << " free : " << countFreeRow << "\n"
1242  << " Nonzeros : " << nNzos() << "\n"
1243  << " per column : " << Real(nNzos()) / Real(nCols()) << "\n"
1244  << " per row : " << Real(nNzos()) / Real(nRows()) << "\n"
1245  << " sparsity : " << Real(nNzos()) / Real(nCols()) / Real(nRows()) << "\n"
1246  << " min. abs. value : " << Real(minAbsNzo()) << "\n"
1247  << " max. abs. value : " << Real(maxAbsNzo()) << "\n";
1248  }
1249 
1250  //@}
1251 
1252  // ------------------------------------------------------------------------------------------------------------------
1253  /**@name Manipulation */
1254  //@{
1255 
1256  /// Changes objective vector to \p newObj. \p scale determines whether the new data should be scaled
1257  virtual void changeObj(const VectorBase<R>& newObj, bool scale = false)
1258  {
1259  changeMaxObj(newObj, scale);
1260  if( spxSense() == MINIMIZE )
1261  LPColSetBase<R>::maxObj_w() *= -1;
1262  }
1263 
1264  /// changes \p i 'th objective vector element to \p newVal. \p scale determines whether the new data should be scaled
1265  virtual void changeObj(int i, const R& newVal, bool scale = false)
1266  {
1267  changeMaxObj(i, newVal, scale);
1268  if( spxSense() == MINIMIZE )
1269  LPColSetBase<R>::maxObj_w(i) *= -1;
1270  }
1271 
1272  /// changes \p i 'th objective vector element to \p newVal.
1273  template < class S >
1274  void changeObj(int i, const S* newVal)
1275  {
1276  LPColSetBase<R>::maxObj_w(i) = *newVal;
1277  if( spxSense() == MINIMIZE )
1278  LPColSetBase<R>::maxObj_w(i) *= -1;
1279  assert(isConsistent());
1280  }
1281 
1282  /// Changes objective value of column with identifier \p id to \p newVal. \p scale determines whether the new data should be scaled
1283  virtual void changeObj(SPxColId id, const R& newVal, bool scale = false)
1284  {
1285  changeObj(number(id), newVal, scale);
1286  }
1287 
1288  /// Changes objective vector to \p newObj. \p scale determines whether the new data should be scaled
1289  virtual void changeMaxObj(const VectorBase<R>& newObj, bool scale = false)
1290  {
1291  assert(maxObj().dim() == newObj.dim());
1292  LPColSetBase<R>::maxObj_w() = newObj;
1293  assert(isConsistent());
1294  }
1295 
1296  /// changes \p i 'th objective vector element to \p newVal. \p scale determines whether the new data should be scaled
1297  virtual void changeMaxObj(int i, const R& newVal, bool scale = false)
1298  {
1299  if( scale )
1300  {
1301  assert(_isScaled);
1302  assert(lp_scaler);
1303  LPColSetBase<R>::maxObj_w(i) = lp_scaler->scaleObj(*this, i, newVal);
1304  }
1305  else
1306  LPColSetBase<R>::maxObj_w(i) = newVal;
1307  assert(isConsistent());
1308  }
1309 
1310  /// changes \p i 'th objective vector element to \p newVal.
1311  template < class S >
1312  void changeMaxObj(int i, const S* newVal)
1313  {
1314  LPColSetBase<R>::maxObj_w(i) = *newVal;
1315  assert(isConsistent());
1316  }
1317 
1318  /// Changes objective value of column with identifier \p id to \p newVal. \p scale determines whether the new data should be scaled
1319  virtual void changeMaxObj(SPxColId id, const R& newVal, bool scale = false)
1320  {
1321  changeMaxObj(number(id), newVal, scale);
1322  }
1323 
1324  /// Changes vector of lower bounds to \p newLower. \p scale determines whether the new data should be scaled
1325  virtual void changeLower(const VectorBase<R>& newLower, bool scale = false)
1326  {
1327  assert(lower().dim() == newLower.dim());
1328  LPColSetBase<R>::lower_w() = newLower;
1329  assert(isConsistent());
1330  }
1331 
1332  /// changes \p i 'th lower bound to \p newLower. \p scale determines whether the new data should be scaled
1333  virtual void changeLower(int i, const R& newLower, bool scale = false)
1334  {
1335  if( scale && newLower > -infinity)
1336  {
1337  assert(_isScaled);
1338  assert(lp_scaler);
1339  LPColSetBase<R>::lower_w(i) = lp_scaler->scaleLower(*this, i, newLower);
1340  }
1341  else
1342  LPColSetBase<R>::lower_w(i) = newLower;
1343  assert(isConsistent());
1344  }
1345 
1346  /// changes \p i 'th lower bound to \p newLower.
1347  template < class S >
1348  void changeLower(int i, const S* newLower)
1349  {
1350  LPColSetBase<R>::lower_w(i) = *newLower;
1351  assert(isConsistent());
1352  }
1353 
1354  /// changes lower bound of column with identifier \p id to \p newLower. \p scale determines whether the new data should be scaled
1355  virtual void changeLower(SPxColId id, const R& newLower, bool scale = false)
1356  {
1357  changeLower(number(id), newLower, scale);
1358  }
1359 
1360  /// Changes vector of upper bounds to \p newUpper. \p scale determines whether the new data should be scaled
1361  virtual void changeUpper(const VectorBase<R>& newUpper, bool scale = false)
1362  {
1363  assert(upper().dim() == newUpper.dim());
1364  LPColSetBase<R>::upper_w() = newUpper;
1365  assert(isConsistent());
1366  }
1367 
1368  /// Changes \p i 'th upper bound to \p newUpper. \p scale determines whether the new data should be scaled
1369  virtual void changeUpper(int i, const R& newUpper, bool scale = false)
1370  {
1371  if( scale && newUpper < infinity )
1372  {
1373  assert(_isScaled);
1374  assert(lp_scaler);
1375  LPColSetBase<R>::upper_w(i) = lp_scaler->scaleUpper(*this, i, newUpper);
1376  }
1377  else
1378  LPColSetBase<R>::upper_w(i) = newUpper;
1379  assert(isConsistent());
1380  }
1381 
1382  /// Changes \p i 'th upper bound to \p newUpper.
1383  template < class S >
1384  void changeUpper(int i, const S* newUpper)
1385  {
1386  LPColSetBase<R>::upper_w(i) = *newUpper;
1387  assert(isConsistent());
1388  }
1389 
1390  /// Changes upper bound of column with identifier \p id to \p newLower. \p scale determines whether the new data should be scaled
1391  virtual void changeUpper(SPxColId id, const R& newUpper, bool scale = false)
1392  {
1393  changeUpper(number(id), newUpper, scale);
1394  }
1395 
1396  /// Changes variable bounds to \p newLower and \p newUpper. \p scale determines whether the new data should be scaled
1397  virtual void changeBounds(const VectorBase<R>& newLower, const VectorBase<R>& newUpper, bool scale = false)
1398  {
1399  changeLower(newLower, scale);
1400  changeUpper(newUpper, scale);
1401  assert(isConsistent());
1402  }
1403 
1404  /// Changes bounds of column \p i to \p newLower and \p newUpper. \p scale determines whether the new data should be scaled
1405  virtual void changeBounds(int i, const R& newLower, const R& newUpper, bool scale = false)
1406  {
1407  changeLower(i, newLower, scale);
1408  changeUpper(i, newUpper, scale);
1409  assert(isConsistent());
1410  }
1411 
1412  /// Changes bounds of column \p i to \p newLower and \p newUpper.
1413  template < class S >
1414  void changeBounds(int i, const S* newLower, const S* newUpper)
1415  {
1416  LPColSetBase<R>::lower_w(i) = *newLower;
1417  LPColSetBase<R>::upper_w(i) = *newUpper;
1418  assert(isConsistent());
1419  }
1420 
1421  /// Changes bounds of column with identifier \p id. \p scale determines whether the new data should be scaled
1422  virtual void changeBounds(SPxColId id, const R& newLower, const R& newUpper, bool scale = false)
1423  {
1424  changeBounds(number(id), newLower, newUpper, scale);
1425  }
1426 
1427  /// Changes left hand side vector for constraints to \p newLhs. \p scale determines whether the new data should be scaled
1428  virtual void changeLhs(const VectorBase<R>& newLhs, bool scale = false)
1429  {
1430  assert(lhs().dim() == newLhs.dim());
1431  LPRowSetBase<R>::lhs_w() = newLhs;
1432  assert(isConsistent());
1433  }
1434 
1435  /// Changes \p i 'th left hand side value to \p newLhs. \p scale determines whether the new data should be scaled
1436  virtual void changeLhs(int i, const R& newLhs, bool scale = false)
1437  {
1438  if( scale && newLhs > -infinity )
1439  LPRowSetBase<R>::lhs_w(i) = lp_scaler->scaleLhs(*this, i, newLhs);
1440  else
1441  LPRowSetBase<R>::lhs_w(i) = newLhs;
1442  assert(isConsistent());
1443  }
1444 
1445  /// Changes \p i 'th left hand side value to \p newLhs.
1446  template < class S >
1447  void changeLhs(int i, const S* newLhs)
1448  {
1449  LPRowSetBase<R>::lhs_w(i) = *newLhs;
1450  assert(isConsistent());
1451  }
1452 
1453  /// Changes left hand side value for row with identifier \p id. \p scale determines whether the new data should be scaled
1454  virtual void changeLhs(SPxRowId id, const R& newLhs, bool scale = false)
1455  {
1456  changeLhs(number(id), newLhs, scale);
1457  }
1458 
1459  /// Changes right hand side vector for constraints to \p newRhs. \p scale determines whether the new data should be scaled
1460  virtual void changeRhs(const VectorBase<R>& newRhs, bool scale = false)
1461  {
1462  assert(rhs().dim() == newRhs.dim());
1463  LPRowSetBase<R>::rhs_w() = newRhs;
1464  assert(isConsistent());
1465  }
1466 
1467  /// Changes \p i 'th right hand side value to \p newRhs. \p scale determines whether the new data should be scaled
1468  virtual void changeRhs(int i, const R& newRhs, bool scale = false)
1469  {
1470  if( scale && newRhs < infinity )
1471  LPRowSetBase<R>::rhs_w(i) = lp_scaler->scaleRhs(*this, i, newRhs);
1472  else
1473  LPRowSetBase<R>::rhs_w(i) = newRhs;
1474  assert(isConsistent());
1475  }
1476 
1477  /// Changes right hand side value for row with identifier \p id. \p scale determines whether the new data should be scaled
1478  virtual void changeRhs(SPxRowId id, const R& newRhs, bool scale = false)
1479  {
1480  changeRhs(number(id), newRhs, scale);
1481  }
1482 
1483  /// Changes left and right hand side vectors. \p scale determines whether the new data should be scaled
1484  virtual void changeRange(const VectorBase<R>& newLhs, const VectorBase<R>& newRhs, bool scale = false)
1485  {
1486  changeLhs(newLhs, scale);
1487  changeRhs(newRhs, scale);
1488  assert(isConsistent());
1489  }
1490 
1491  /// Changes left and right hand side of row \p i. \p scale determines whether the new data should be scaled
1492  virtual void changeRange(int i, const R& newLhs, const R& newRhs, bool scale = false)
1493  {
1494  changeLhs(i, newLhs, scale);
1495  changeRhs(i, newRhs, scale);
1496  assert(isConsistent());
1497  }
1498 
1499  /// Changes left and right hand side of row \p i.
1500  template < class S >
1501  void changeRange(int i, const S* newLhs, const S* newRhs)
1502  {
1503  LPRowSetBase<R>::lhs_w(i) = *newLhs;
1504  LPRowSetBase<R>::rhs_w(i) = *newRhs;
1505  assert(isConsistent());
1506  }
1507 
1508  /// Changes left and right hand side of row with identifier \p id. \p scale determines whether the new data should be scaled
1509  virtual void changeRange(SPxRowId id, const R& newLhs, const R& newRhs, bool scale = false)
1510  {
1511  changeRange(number(id), newLhs, newRhs, scale);
1512  }
1513 
1514  /// Changes row objective function vector to \p newRowObj. \p scale determines whether the new data should be scaled
1515  virtual void changeRowObj(const VectorBase<R>& newRowObj, bool scale = false)
1516  {
1517  assert(maxRowObj().dim() == newRowObj.dim());
1518  LPRowSetBase<R>::obj_w() = newRowObj;
1519  if( spxSense() == MINIMIZE )
1520  LPRowSetBase<R>::obj_w() *= -1;
1521  assert(isConsistent());
1522  }
1523 
1524  /// Changes \p i 'th row objective function value to \p newRowObj. \p scale determines whether the new data should be scaled
1525  virtual void changeRowObj(int i, const R& newRowObj, bool scale = false)
1526  {
1527  LPRowSetBase<R>::obj_w(i) = newRowObj;
1528  if( spxSense() == MINIMIZE )
1529  LPRowSetBase<R>::obj_w(i) *= -1;
1530  assert(isConsistent());
1531  }
1532 
1533  /// Changes row objective function value for row with identifier \p id. \p scale determines whether the new data should be scaled
1534  virtual void changeRowObj(SPxRowId id, const R& newRowObj, bool scale = false)
1535  {
1536  changeRowObj(number(id), newRowObj, scale);
1537  }
1538 
1539  /// Clears row objective function values for all rows
1540  virtual void clearRowObjs()
1541  {
1542  LPRowSetBase<R>::obj_w().clear();
1543  }
1544 
1545  /// Replaces \p i 'th row of LP with \p newRow. \p scale determines whether the new data should be scaled
1546  virtual void changeRow(int n, const LPRowBase<R>& newRow, bool scale = false)
1547  {
1548  if( n < 0 )
1549  return;
1550 
1551  int j;
1552  SVectorBase<R>& row = rowVector_w(n);
1553  for( j = row.size() - 1; j >= 0; --j )
1554  {
1555  SVectorBase<R>& col = colVector_w(row.index(j));
1556  col.remove(col.pos(n));
1557  }
1558 
1559  row.clear();
1560 
1561  changeLhs(n, newRow.lhs(), scale);
1562  changeRhs(n, newRow.rhs(), scale);
1563  changeRowObj(n, newRow.obj(), scale);
1564 
1565  const SVectorBase<R>& newrow = newRow.rowVector();
1566  for( j = newrow.size() - 1; j >= 0; --j )
1567  {
1568  int idx = newrow.index(j);
1569  R val = newrow.value(j);
1570  if( scale )
1572  LPRowSetBase<R>::add2(n, 1, &idx, &val);
1573  LPColSetBase<R>::add2(idx, 1, &n, &val);
1574  }
1575 
1576  assert(isConsistent());
1577  }
1578 
1579  /// Replaces row with identifier \p id with \p newRow. \p scale determines whether the new data should be scaled
1580  virtual void changeRow(SPxRowId id, const LPRowBase<R>& newRow, bool scale = false)
1581  {
1582  changeRow(number(id), newRow, scale);
1583  }
1584 
1585  /// Replaces \p i 'th column of LP with \p newCol. \p scale determines whether the new data should be scaled
1586  virtual void changeCol(int n, const LPColBase<R>& newCol, bool scale = false)
1587  {
1588  if( n < 0 )
1589  return;
1590 
1591  int j;
1592  SVectorBase<R>& col = colVector_w(n);
1593  for( j = col.size() - 1; j >= 0; --j )
1594  {
1595  SVectorBase<R>& row = rowVector_w(col.index(j));
1596  row.remove(row.pos(n));
1597  }
1598 
1599  col.clear();
1600 
1601  changeUpper(n, newCol.upper(), scale);
1602  changeLower(n, newCol.lower(), scale);
1603  changeObj(n, newCol.obj(), scale);
1604 
1605  const SVectorBase<R>& newcol = newCol.colVector();
1606  for( j = newcol.size() - 1; j >= 0; --j )
1607  {
1608  int idx = newcol.index(j);
1609  R val = newcol.value(j);
1610  if( scale )
1612  LPColSetBase<R>::add2(n, 1, &idx, &val);
1613  LPRowSetBase<R>::add2(idx, 1, &n, &val);
1614  }
1615 
1616  assert(isConsistent());
1617  }
1618 
1619  /// Replaces column with identifier \p id with \p newCol. \p scale determines whether the new data should be scaled
1620  virtual void changeCol(SPxColId id, const LPColBase<R>& newCol, bool scale = false)
1621  {
1622  changeCol(number(id), newCol, scale);
1623  }
1624 
1625  /// Changes LP element (\p i, \p j) to \p val. \p scale determines whether the new data should be scaled
1626  virtual void changeElement(int i, int j, const R& val, bool scale = false)
1627  {
1628  if( i < 0 || j < 0 )
1629  return;
1630 
1631  SVectorBase<R>& row = rowVector_w(i);
1632  SVectorBase<R>& col = colVector_w(j);
1633 
1634  if( val != R(0) )
1635  {
1636  Real newVal;
1637 
1638  if( scale )
1639  {
1640  assert(_isScaled);
1641  assert(lp_scaler);
1642  newVal = lp_scaler->scaleElement(*this, i, j, val);
1643  }
1644  else
1645  newVal = val;
1646 
1647  if( row.pos(j) >= 0 )
1648  {
1649  row.value(row.pos(j)) = newVal;
1650  col.value(col.pos(i)) = newVal;
1651  }
1652  else
1653  {
1654  LPRowSetBase<R>::add2(i, 1, &j, &newVal);
1655  LPColSetBase<R>::add2(j, 1, &i, &newVal);
1656  }
1657  }
1658  else if( row.pos(j) >= 0 )
1659  {
1660  row.remove(row.pos(j));
1661  col.remove(col.pos(i));
1662  }
1663 
1664  assert(isConsistent());
1665  }
1666 
1667  /// Changes LP element (\p i, \p j) to \p val.
1668  template < class S >
1669  void changeElement(int i, int j, const S* val)
1670  {
1671  if( i < 0 || j< 0 )
1672  return;
1673 
1674  SVectorBase<R>& row = rowVector_w(i);
1675  SVectorBase<R>& col = colVector_w(j);
1676 
1677  if( mpq_get_d(*val) != R(0) )
1678  {
1679  if( row.pos(j) >= 0 )
1680  {
1681  row.value(row.pos(j)) = *val;
1682  col.value(col.pos(i)) = *val;
1683  }
1684  else
1685  {
1686  LPRowSetBase<R>::add2(i, 1, &j, val);
1687  LPColSetBase<R>::add2(j, 1, &i, val);
1688  }
1689  }
1690  else if( row.pos(j) >= 0 )
1691  {
1692  row.remove(row.pos(j));
1693  col.remove(col.pos(i));
1694  }
1695 
1696  assert(isConsistent());
1697  }
1698 
1699  /// Changes LP element identified by (\p rid, \p cid) to \p val. \p scale determines whether the new data should be scaled
1700  virtual void changeElement(SPxRowId rid, SPxColId cid, const R& val, bool scale = false)
1701  {
1702  changeElement(number(rid), number(cid), val, scale);
1703  }
1704 
1705  /// Changes optimization sense to \p sns.
1706  virtual void changeSense(SPxSense sns)
1707  {
1708  if( sns != thesense )
1709  {
1710  LPColSetBase<R>::maxObj_w() *= -1;
1711  LPRowSetBase<R>::obj_w() *= -1;
1712  }
1713  thesense = sns;
1714  }
1715 
1716  virtual void changeObjOffset(const R& o)
1717  {
1718  offset = o;
1719  }
1720 
1721  /// Computes activity of the rows for a given primal vector; activity does not need to be zero
1722  /// @throw SPxInternalCodeException if the dimension of primal vector does not match number of columns or if the
1723  /// dimension of the activity vector does not match the number of rows
1724  /// \p unscaled determines whether the returned data should be unscaled (if scaling was applied prior)
1725  virtual void computePrimalActivity(const VectorBase<R>& primal, VectorBase<R>& activity, const bool unscaled = true) const;
1726 
1727  /// Updates activity of the rows for a given primal vector; activity does not need to be zero
1728  /// @throw SPxInternalCodeException if the dimension of primal vector does not match number of columns or if the
1729  /// dimension of the activity vector does not match the number of rows
1730  virtual void addPrimalActivity(const SVectorBase<R>& primal, VectorBase<R>& activity) const
1731  {
1732  if( activity.dim() != nRows() )
1733  {
1734  throw SPxInternalCodeException("XSPXLP03 Activity vector computing row activity has wrong dimension");
1735  }
1736 
1737  for( int i = primal.size() - 1; i >= 0; i-- )
1738  {
1739  assert(primal.index(i) >= 0);
1740  assert(primal.index(i) < nCols());
1741  activity.multAdd(primal.value(i), colVector(primal.index(i)));
1742  }
1743  }
1744 
1745  /// Computes "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need to be zero
1746  /// @throw SPxInternalCodeException if dimension of dual vector does not match number of rows or if the dimension of
1747  /// the activity vector does not match the number of columns
1748  virtual void computeDualActivity(const VectorBase<R>& dual, VectorBase<R>& activity, const bool unscaled = true) const;
1749 
1750  /// Updates "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need to be zero
1751  /// @throw SPxInternalCodeException if dimension of dual vector does not match number of rows or if the dimension of
1752  /// the activity vector does not match the number of columns
1753  virtual void addDualActivity(const SVectorBase<R>& dual, VectorBase<R>& activity) const
1754  {
1755  if( activity.dim() != nCols() )
1756  {
1757  throw SPxInternalCodeException("XSPXLP04 Activity vector computing dual activity has wrong dimension");
1758  }
1759 
1760  for( int i = dual.size() - 1; i >= 0; i-- )
1761  {
1762  assert(dual.index(i) >= 0);
1763  assert(dual.index(i) < nRows());
1764  activity.multAdd(dual.value(i), rowVector(dual.index(i)));
1765  }
1766  }
1767 
1768  /// Updates "dual" activity of the columns for a given dual vector, i.e., y^T A; activity does not need to be zero
1769  /// @throw SPxInternalCodeException if dimension of dual vector does not match number of rows or if the dimension of
1770  /// the activity vector does not match the number of columns
1771  virtual void subDualActivity(const VectorBase<R>& dual, VectorBase<R>& activity) const
1772  {
1773  if( dual.dim() != nRows() )
1774  {
1775  throw SPxInternalCodeException("XSPXLP02 Dual vector for computing dual activity has wrong dimension");
1776  }
1777 
1778  if( activity.dim() != nCols() )
1779  {
1780  throw SPxInternalCodeException("XSPXLP04 Activity vector computing dual activity has wrong dimension");
1781  }
1782 
1783  for( int r = 0; r < nRows(); r++ )
1784  {
1785  if( dual[r] != 0 )
1786  activity.multSub(dual[r], rowVector(r));
1787  }
1788  }
1789 
1790  //@}
1791 
1792  // ------------------------------------------------------------------------------------------------------------------
1793  /**@name Construction of dual problem */
1794  //@{
1795 
1796  /// Building the dual problem from a given LP
1797  /// @note primalRows must be as large as the number of unranged primal rows + 2 * the number of ranged primal rows.
1798  /// dualCols must have the identical size to the primal rows.
1799  virtual void buildDualProblem(SPxLPBase<R>& dualLP, SPxRowId primalRowIds[] = 0, SPxColId primalColIds[] = 0,
1800  SPxRowId dualRowIds[] = 0, SPxColId dualColIds[] = 0, int* nprimalrows = 0, int* nprimalcols = 0,
1801  int* ndualrows = 0, int* ndualcols = 0);
1802 
1803  //@}
1804 
1805  // ------------------------------------------------------------------------------------------------------------------
1806  /**@name Miscellaneous */
1807  //@{
1808 
1809  /// Consistency check.
1810  bool isConsistent() const
1811  {
1812 #ifdef ENABLE_CONSISTENCY_CHECKS
1813 
1814  for( int i = nCols() - 1; i >= 0; --i )
1815  {
1816  const SVectorBase<R>& v = colVector(i);
1817 
1818  for( int j = v.size() - 1; j >= 0; --j )
1819  {
1820  const SVectorBase<R>& w = rowVector(v.index(j));
1821  int n = w.pos(i);
1822 
1823  if( n < 0 )
1824  return MSGinconsistent("SPxLPBase");
1825 
1826  if( v.value(j) != w.value(n) )
1827  return MSGinconsistent("SPxLPBase");
1828  }
1829  }
1830 
1831  for( int i = nRows() - 1; i >= 0; --i )
1832  {
1833  const SVectorBase<R>& v = rowVector(i);
1834 
1835  for( int j = v.size() - 1; j >= 0; --j )
1836  {
1837  const SVectorBase<R>& w = colVector(v.index(j));
1838  int n = w.pos(i);
1839 
1840  if( n < 0 )
1841  return MSGinconsistent("SPxLPBase");
1842 
1843  if( v.value(j) != w.value(n) )
1844  return MSGinconsistent("SPxLPBase");
1845  }
1846  }
1847 
1849 #else
1850  return true;
1851 #endif
1852  }
1853 
1854  //@}
1855 
1856 protected:
1857 
1858  // ------------------------------------------------------------------------------------------------------------------
1859  /**@name Protected write access */
1860  //@{
1861 
1862  /// Returns right hand side of row \p i.
1863  R& rhs_w(int i)
1864  {
1865  return LPRowSetBase<R>::rhs_w(i);
1866  }
1867 
1868  /// Returns left hand side of row \p i.
1869  R& lhs_w(int i)
1870  {
1871  return LPRowSetBase<R>::lhs_w(i);
1872  }
1873 
1874  /// Returns objective function value of row \p i.
1875  R& maxRowObj_w(int i)
1876  {
1877  return LPRowSetBase<R>::obj_w(i);
1878  }
1879 
1880  /// Returns objective value of column \p i for maximization problem.
1881  R& maxObj_w(int i)
1882  {
1883  return LPColSetBase<R>::maxObj_w(i);
1884  }
1885 
1886  /// Returns upper bound of column \p i.
1887  R& upper_w(int i)
1888  {
1889  return LPColSetBase<R>::upper_w(i);
1890  }
1891 
1892  /// Returns lower bound of column \p i.
1893  R& lower_w(int i)
1894  {
1895  return LPColSetBase<R>::lower_w(i);
1896  }
1897 
1898  //@}
1899 
1900  // ------------------------------------------------------------------------------------------------------------------
1901  /**@name Protected helpers */
1902  //@{
1903 
1904  /// Returns the LP as an LPRowSetBase.
1905  const LPRowSetBase<R>* lprowset() const
1906  {
1907  return static_cast<const LPRowSetBase<R>*>(this);
1908  }
1909 
1910  /// Returns the LP as an LPColSetBase.
1911  const LPColSetBase<R>* lpcolset() const
1912  {
1913  return static_cast<const LPColSetBase<R>*>(this);
1914  }
1915 
1916  /// Internal helper method.
1917  virtual void doRemoveRow(int j)
1918  {
1919 
1920  const SVectorBase<R>& vec = rowVector(j);
1921 
1922  // remove row vector from column file
1923  for( int i = vec.size() - 1; i >= 0; --i )
1924  {
1925  SVectorBase<R>& remvec = colVector_w(vec.index(i));
1926  remvec.remove(remvec.pos(j));
1927  }
1928 
1929  // move last row to removed position
1930  int idx = nRows() - 1;
1931  if( j != idx )
1932  {
1933  const SVectorBase<R>& l_vec = rowVector(idx);
1934  for( int i = l_vec.size() - 1; i >= 0; --i )
1935  {
1936  SVectorBase<R>& movevec = colVector_w(l_vec.index(i));
1937  movevec.index(movevec.pos(idx)) = j;
1938  }
1939  }
1940 
1942  }
1943 
1944  /// Internal helper method.
1945  virtual void doRemoveRows(int perm[])
1946  {
1947  int j = nCols();
1948 
1950 
1951  for( int i = 0; i < j; ++i )
1952  {
1953  SVectorBase<R>& vec = colVector_w(i);
1954  for( int k = vec.size() - 1; k >= 0; --k )
1955  {
1956  int idx = vec.index(k);
1957  if( perm[idx] < 0 )
1958  vec.remove(k);
1959  else
1960  vec.index(k) = perm[idx];
1961  }
1962  }
1963  }
1964 
1965  /// Internal helper method.
1966  virtual void doRemoveCol(int j)
1967  {
1968 
1969  const SVectorBase<R>& vec = colVector(j);
1970  int i;
1971 
1972  // remove column vector from row file
1973  for( i = vec.size() - 1; i >= 0; --i )
1974  {
1975  SVectorBase<R>& remvec = rowVector_w(vec.index(i));
1976  remvec.remove(remvec.pos(j));
1977  }
1978 
1979  // move last column to removed position
1980  int idx = nCols() - 1;
1981  if( j != idx )
1982  {
1983  const SVectorBase<R>& l_vec = colVector(idx);
1984  for( i = l_vec.size() - 1; i >= 0; --i )
1985  {
1986  SVectorBase<R>& movevec = rowVector_w(l_vec.index(i));
1987  movevec.index(movevec.pos(idx)) = j;
1988  }
1989  }
1990 
1992  }
1993 
1994  /// Internal helper method.
1995  virtual void doRemoveCols(int perm[])
1996  {
1997  int nrows = nRows();
1998 
2000 
2001  for( int i = 0; i < nrows; ++i )
2002  {
2003  SVectorBase<R>& vec = rowVector_w(i);
2004 
2005  for( int k = vec.size() - 1; k >= 0; --k )
2006  {
2007  int idx = vec.index(k);
2008  if( perm[idx] < 0 )
2009  vec.remove(k);
2010  else
2011  vec.index(k) = perm[idx];
2012  }
2013  }
2014  }
2015 
2016  /// Called after the last \p n rows have just been added.
2017  virtual void addedRows(int newrows)
2018  {}
2019 
2020  /// Called after the last \p n columns have just been added.
2021  virtual void addedCols(int newcols)
2022  {}
2023 
2024  ///
2025  void added2Set(SVSetBase<R>& set, const SVSetBase<R>& addset, int n)
2026  {
2027 
2028  if( n == 0 )
2029  return;
2030 
2031  DataArray<int> moreArray(set.num());
2032  int* more = moreArray.get_ptr();
2033 
2034  for( int i = set.num() - 1; i >= 0; --i )
2035  more[i] = 0;
2036 
2037  int tot = 0;
2038  int end = addset.num();
2039 
2040  for( int i = addset.num() - n; i < end; ++i )
2041  {
2042  const SVectorBase<R>& vec = addset[i];
2043 
2044  tot += vec.size();
2045  for( int j = vec.size() - 1; j >= 0; --j )
2046  more[vec.index(j)]++;
2047  }
2048 
2049  if( set.memMax() < tot )
2050  set.memRemax(tot);
2051 
2052  for( int i = set.num() - 1; i >= 0; --i )
2053  {
2054  int j = set[i].size();
2055  set.xtend(set[i], j + more[i]);
2056  set[i].set_size( j + more[i] );
2057  more[i] = j;
2058  }
2059 
2060  for( int i = addset.num() - n; i < addset.num(); ++i)
2061  {
2062  const SVectorBase<R>& vec = addset[i];
2063 
2064  for( int j = vec.size() - 1; j >= 0; --j )
2065  {
2066  int k = vec.index(j);
2067  int m = more[k]++;
2068  SVectorBase<R>& l_xtend = set[k];
2069  l_xtend.index(m) = i;
2070  l_xtend.value(m) = vec.value(j);
2071  }
2072  }
2073  }
2074 
2075  //@}
2076 
2077 
2078 private:
2079 
2080  // ------------------------------------------------------------------------------------------------------------------
2081  /**@name Private helpers */
2082  //@{
2083 
2084  /// Returns the LP as an LPRowSet.
2086  {
2087  return LPColSetBase<R>::colVector_w(i);
2088  }
2089 
2090  ///
2092  {
2093  return LPRowSetBase<R>::rowVector_w(i);
2094  }
2095 
2096  ///
2097  void doAddRow (const LPRowBase<R>& row, bool scale = false)
2098  {
2099  int idx = nRows();
2100  int oldColNumber = nCols();
2101  int newRowScaleExp = 0;
2102 
2103  LPRowSetBase<R>::add(row);
2104 
2105  SVectorBase<R>& vec = rowVector_w(idx);
2106 
2108 
2109  // compute new row scaling factor and apply it to the sides
2110  if( scale )
2111  {
2112  newRowScaleExp = lp_scaler->computeScaleExp(vec, colscaleExp);
2113 
2114  if( rhs(idx) < infinity )
2115  rhs_w(idx) = spxLdexp(rhs_w(idx), newRowScaleExp);
2116  if( lhs(idx) > -infinity )
2117  lhs_w(idx) = spxLdexp(lhs_w(idx), newRowScaleExp);
2118 
2119  maxRowObj_w(idx) = spxLdexp(maxRowObj_w(idx), newRowScaleExp);
2120 
2121  LPRowSetBase<R>::scaleExp[idx] = newRowScaleExp;
2122  }
2123 
2124  // now insert nonzeros to column file also
2125  for( int j = vec.size() - 1; j >= 0; --j )
2126  {
2127  int i = vec.index(j);
2128 
2129  // apply new row and existing column scaling factors to new values in RowSet
2130  if( scale )
2131  vec.value(j) = spxLdexp(vec.value(j), newRowScaleExp + colscaleExp[i]);
2132 
2133  R val = vec.value(j);
2134 
2135  // create new columns if required
2136  if( i >= nCols() )
2137  {
2138  LPColBase<R> empty;
2139  for( int k = nCols(); k <= i; ++k )
2140  LPColSetBase<R>::add(empty);
2141  }
2142 
2143  assert(i < nCols());
2144  LPColSetBase<R>::add2(i, 1, &idx, &val);
2145  }
2146 
2147  addedRows(1);
2148  addedCols(nCols() - oldColNumber);
2149  }
2150 
2151  ///
2152  void doAddRow (const R& lhsValue, const SVectorBase<R>& rowVec, const R& rhsValue, bool scale = false)
2153  {
2154  int idx = nRows();
2155  int oldColNumber = nCols();
2156  int newRowScaleExp = 0;
2157 
2158  LPRowSetBase<R>::add(lhsValue, rowVec, rhsValue);
2159 
2161 
2162  // compute new row scaling factor and apply it to the sides
2163  if( scale )
2164  {
2165  newRowScaleExp = lp_scaler->computeScaleExp(rowVec, colscaleExp);
2166 
2167  if( rhs(idx) < infinity )
2168  rhs_w(idx) = spxLdexp(rhs_w(idx), newRowScaleExp);
2169  if( lhs(idx) > -infinity )
2170  lhs_w(idx) = spxLdexp(lhs_w(idx), newRowScaleExp);
2171 
2172  maxRowObj_w(idx) = spxLdexp(maxRowObj_w(idx), newRowScaleExp);
2173 
2174  LPRowSetBase<R>::scaleExp[idx] = newRowScaleExp;
2175  }
2176 
2177  SVectorBase<R>& vec = rowVector_w(idx);
2178 
2179  // now insert nonzeros to column file also
2180  for( int j = vec.size() - 1; j >= 0; --j )
2181  {
2182  int i = vec.index(j);
2183 
2184  // apply new row and existing column scaling factors to new values in RowSet
2185  if( scale )
2186  vec.value(j) = spxLdexp(vec.value(j), newRowScaleExp + colscaleExp[i]);
2187 
2188  R val = vec.value(j);
2189 
2190  // create new columns if required
2191  if( i >= nCols() )
2192  {
2193  LPColBase<R> empty;
2194  for( int k = nCols(); k <= i; ++k )
2195  LPColSetBase<R>::add(empty);
2196  }
2197 
2198  assert(i < nCols());
2199  LPColSetBase<R>::add2(i, 1, &idx, &val);
2200  }
2201 
2202  addedRows(1);
2203  addedCols(nCols() - oldColNumber);
2204  }
2205 
2206  ///
2207  void doAddRows(const LPRowSetBase<R>& set, bool scale = false)
2208  {
2209  int i, j, k, ii, idx;
2210  SVectorBase<R>* col;
2211  DataArray < int > newCols(nCols());
2212  int oldRowNumber = nRows();
2213  int oldColNumber = nCols();
2214 
2215  if( &set != this )
2216  LPRowSetBase<R>::add(set);
2217 
2220 
2221  // count additional nonzeros per column
2222  for( i = nCols() - 1; i >= 0; --i )
2223  newCols[i] = 0;
2224  for( i = set.num() - 1; i >= 0; --i )
2225  {
2226  const SVectorBase<R>& vec = set.rowVector(i);
2227 
2228  for( j = vec.size() - 1; j >= 0; --j )
2229  {
2230  // create new columns if required
2231  ii = vec.index(j);
2232  if( ii >= nCols() )
2233  {
2234  LPColBase<R> empty;
2235  newCols.reSize(ii + 1);
2236  for( k = nCols(); k <= ii; ++k )
2237  {
2238  newCols[k] = 0;
2239  LPColSetBase<R>::add(empty);
2240  }
2241  }
2242 
2243  assert(ii < nCols());
2244  newCols[ii]++;
2245  }
2246  }
2247 
2248  // extend columns as required (backward because of memory efficiency reasons)
2249  for( i = nCols() - 1; i >= 0; --i )
2250  {
2251  if( newCols[i] > 0 )
2252  {
2253  int len = newCols[i] + colVector(i).size();
2254  LPColSetBase<R>::xtend(i, len);
2255 
2256  /* preset the sizes: beware that this can irritate a consistency check call from xtend(). We need to set the
2257  * sizes here, because a possible garbage collection called from xtend might destroy the sizes again. */
2258  colVector_w(i).set_size( len );
2259  }
2260  }
2261 
2262  // compute new row scaling factor and insert new elements to column file
2263  for( i = nRows() - 1; i >= oldRowNumber; --i )
2264  {
2265  SVectorBase<R>& vec = rowVector_w(i);
2266  int newRowScaleExp = 0;
2267 
2269 
2270  // compute new row scaling factor and apply it to the sides
2271  if( scale )
2272  {
2273  newRowScaleExp = lp_scaler->computeScaleExp(vec, colscaleExp);
2274 
2275  if( rhs(i) < infinity )
2276  rhs_w(i) = spxLdexp(rhs_w(i), newRowScaleExp);
2277  if( lhs(i) > -infinity )
2278  lhs_w(i) = spxLdexp(lhs_w(i), newRowScaleExp);
2279 
2280  maxRowObj_w(i) = spxLdexp(maxRowObj_w(i), newRowScaleExp);
2281 
2282  LPRowSetBase<R>::scaleExp[i] = newRowScaleExp;
2283  }
2284 
2285  for( j = vec.size() - 1; j >= 0; --j )
2286  {
2287  k = vec.index(j);
2288  col = &colVector_w(k);
2289  idx = col->size() - newCols[k];
2290  assert(newCols[k] > 0);
2291  assert(idx >= 0);
2292  newCols[k]--;
2293  col->index(idx) = i;
2294  // apply new row and existing column scaling factors to both ColSet and RowSet
2295  if( scale )
2296  vec.value(j) = spxLdexp(vec.value(j), newRowScaleExp + colscaleExp[k]);
2297 
2298  col->value(idx) = vec.value(j);
2299  }
2300  }
2301 
2302 #ifndef NDEBUG
2303  for( i = 0; i < nCols(); ++i )
2304  assert( newCols[i] == 0 );
2305 #endif
2306 
2307  assert(SPxLPBase<R>::isConsistent());
2308 
2309  assert(set.num() == nRows() - oldRowNumber);
2310  addedRows(nRows() - oldRowNumber);
2311  addedCols(nCols() - oldColNumber);
2312  }
2313 
2314  ///
2315  void doAddCol (const LPColBase<R>& col, bool scale = false)
2316  {
2317  int idx = nCols();
2318  int oldRowNumber = nRows();
2319  int newColScaleExp = 0;
2320 
2321  LPColSetBase<R>::add(col);
2322  if( thesense != MAXIMIZE )
2323  LPColSetBase<R>::maxObj_w(idx) *= -1;
2324 
2325  SVectorBase<R>& vec = colVector_w(idx);
2326 
2328 
2329  // compute new column scaling factor and apply it to the bounds
2330  if( scale )
2331  {
2332  newColScaleExp = lp_scaler->computeScaleExp(vec, rowscaleExp);
2333 
2334  if( upper(idx) < infinity )
2335  upper_w(idx) = spxLdexp(upper_w(idx), - newColScaleExp);
2336  if( lower(idx) > -infinity )
2337  lower_w(idx) = spxLdexp(lower_w(idx), - newColScaleExp);
2338 
2339  maxObj_w(idx) = spxLdexp(maxObj_w(idx), newColScaleExp);
2340 
2341  LPColSetBase<R>::scaleExp[idx] = newColScaleExp;
2342  }
2343 
2344  // now insert nonzeros to row file also
2345  for( int j = vec.size() - 1; j >= 0; --j )
2346  {
2347  int i = vec.index(j);
2348 
2349  // apply new column and existing row scaling factors to new values in ColSet
2350  if( scale )
2351  vec.value(j) = spxLdexp(vec.value(j), newColScaleExp + rowscaleExp[i]);
2352 
2353  R val = vec.value(j);
2354 
2355  // create new rows if required
2356  if( i >= nRows() )
2357  {
2358  LPRowBase<R> empty;
2359  for( int k = nRows(); k <= i; ++k )
2360  LPRowSetBase<R>::add(empty);
2361  }
2362 
2363  assert(i < nRows());
2364  LPRowSetBase<R>::add2(i, 1, &idx, &val);
2365  }
2366 
2367  addedCols(1);
2368  addedRows(nRows() - oldRowNumber);
2369  }
2370 
2371  ///
2372  void doAddCol (const R& objValue, const R& lowerValue, const SVectorBase<R>& colVec, const R& upperValue, bool scale = false)
2373  {
2374  int idx = nCols();
2375  int oldRowNumber = nRows();
2376  int newColScaleExp = 0;
2377 
2378  LPColSetBase<R>::add(objValue, lowerValue, colVec, upperValue);
2379  if( thesense != MAXIMIZE )
2380  LPColSetBase<R>::maxObj_w(idx) *= -1;
2381 
2383 
2384  // compute new column scaling factor and apply it to the bounds
2385  if( scale )
2386  {
2387  newColScaleExp = lp_scaler->computeScaleExp(colVec, rowscaleExp);
2388 
2389  if( upper(idx) < infinity )
2390  upper_w(idx) = spxLdexp(upper_w(idx), - newColScaleExp);
2391  if( lower(idx) > -infinity )
2392  lower_w(idx) = spxLdexp(lower_w(idx), - newColScaleExp);
2393 
2394  maxObj_w(idx) = spxLdexp(maxObj_w(idx), newColScaleExp);
2395 
2396  LPColSetBase<R>::scaleExp[idx] = newColScaleExp;
2397  }
2398 
2399  SVectorBase<R>& vec = colVector_w(idx);
2400 
2401  // now insert nonzeros to row file also
2402  for( int j = vec.size() - 1; j >= 0; --j )
2403  {
2404  int i = vec.index(j);
2405 
2406  if( scale )
2407  vec.value(j) = spxLdexp(vec.value(j), newColScaleExp + rowscaleExp[i]);
2408 
2409  R val = vec.value(j);
2410 
2411  // create new rows if required
2412  if( i >= nRows() )
2413  {
2414  LPRowBase<R> empty;
2415  for( int k = nRows(); k <= i; ++k )
2416  LPRowSetBase<R>::add(empty);
2417  }
2418 
2419  assert(i < nRows());
2420  LPRowSetBase<R>::add2(i, 1, &idx, &val);
2421  }
2422 
2423  addedCols(1);
2424  addedRows(nRows() - oldRowNumber);
2425  }
2426 
2427  ///
2428  void doAddCols(const LPColSetBase<R>& set, bool scale = false)
2429  {
2430  int i, j;
2431  int oldColNumber = nCols();
2432  int oldRowNumber = nRows();
2433  DataArray < int > newRows(nRows());
2434 
2435  if( &set != this )
2436  LPColSetBase<R>::add(set);
2437 
2440 
2441  // count additional nonzeros per row
2442  for( i = nRows() - 1; i >= 0; --i )
2443  newRows[i] = 0;
2444 
2445  for( i = set.num() - 1; i >= 0; --i )
2446  {
2447  const SVectorBase<R>& vec = set.colVector(i);
2448 
2449  for( j = vec.size() - 1; j >= 0; --j )
2450  {
2451  // create new rows if required
2452  int l = vec.index(j);
2453  if( l >= nRows() )
2454  {
2455  LPRowBase<R> empty;
2456  newRows.reSize(l + 1);
2457  for( int k = nRows(); k <= l; ++k )
2458  {
2459  newRows[k] = 0;
2460  LPRowSetBase<R>::add(empty);
2461  }
2462 
2463  }
2464 
2465  assert(l < nRows());
2466  newRows[l]++;
2467  }
2468  }
2469 
2470  // extend rows as required
2471  for( i = 0; i < nRows(); ++i )
2472  {
2473  if( newRows[i] > 0 )
2474  {
2475  int len = newRows[i] + rowVector(i).size();
2476  LPRowSetBase<R>::xtend(i, len);
2477  rowVector_w(i).set_size( len );
2478  }
2479  }
2480 
2481  // insert new elements to row file
2482  for( i = oldColNumber; i < nCols(); ++i )
2483  {
2485  SVectorBase<R>& vec = colVector_w(i);
2486  int newColScaleExp = 0;
2487 
2489 
2490  // compute new column scaling factor and apply it to the bounds
2491  if( scale )
2492  {
2493  newColScaleExp = lp_scaler->computeScaleExp(vec, rowscaleExp);
2494 
2495  if( upper(i) < infinity )
2496  upper_w(i) = spxLdexp(upper_w(i), - newColScaleExp);
2497  if( lower(i) > -infinity )
2498  lower_w(i) = spxLdexp(lower_w(i), - newColScaleExp);
2499 
2500  maxObj_w(i) = spxLdexp(maxObj_w(i), newColScaleExp);
2501 
2502  LPColSetBase<R>::scaleExp[i] = newColScaleExp;
2503  }
2504 
2505  for( j = vec.size() - 1; j >= 0; --j )
2506  {
2507  int k = vec.index(j);
2508  SVectorBase<R>& row = rowVector_w(k);
2509  int idx = row.size() - newRows[k];
2510  assert(newRows[k] > 0);
2511  newRows[k]--;
2512  row.index(idx) = i;
2513  // apply new column and existing row scaling factors to both ColSet and RowSet
2514  if( scale )
2515  vec.value(j) = spxLdexp(vec.value(j), newColScaleExp + rowscaleExp[k]);
2516 
2517  row.value(idx) = vec.value(j);
2518  }
2519  }
2520 
2521 #ifndef NDEBUG
2522  for( i = 0; i < nRows(); ++i )
2523  assert( newRows[i] == 0 );
2524 #endif
2525 
2526  assert(SPxLPBase<R>::isConsistent());
2527 
2528  assert(set.num() == nCols() - oldColNumber);
2529  addedCols(nCols() - oldColNumber);
2530  addedRows(nRows() - oldRowNumber);
2531  }
2532 
2533  //@}
2534 
2535 public:
2536 
2537  // ------------------------------------------------------------------------------------------------------------------
2538  /**@name Constructors / Destructors */
2539  //@{
2540 
2541  /// Default constructor.
2543  {
2544  SPxLPBase<R>::clear(); // clear is virtual.
2545 
2546  assert(isConsistent());
2547  }
2548 
2549  /// Destructor.
2550  virtual ~SPxLPBase<R>()
2551  {}
2552 
2553  /// Copy constructor.
2555  : LPRowSetBase<R>(old)
2556  , LPColSetBase<R>(old)
2557  , thesense(old.thesense)
2558  , offset(old.offset)
2559  , _isScaled(old._isScaled)
2560  , lp_scaler(old.lp_scaler)
2561  , spxout(old.spxout)
2562  {
2563  assert(isConsistent());
2564  }
2565 
2566  /// Copy constructor.
2567  template < class S >
2569  : LPRowSetBase<R>(old)
2570  , LPColSetBase<R>(old)
2572  , offset(old.offset)
2573  , _isScaled(old._isScaled)
2574  , lp_scaler(old.lp_scaler)
2575  , spxout(old.spxout)
2576  {
2577  assert(isConsistent());
2578  }
2579 
2580  /// Assignment operator.
2582  {
2583  if( this != &old )
2584  {
2587  thesense = old.thesense;
2588  offset = old.offset;
2589  _isScaled = old._isScaled;
2590  lp_scaler = old.lp_scaler;
2591  spxout = old.spxout;
2592 
2593  assert(isConsistent());
2594  }
2595 
2596  return *this;
2597  }
2598 
2599  /// Assignment operator.
2600  template < class S >
2602  {
2603  if( this != (const SPxLPBase<R>*)(&old) )
2604  {
2608  offset = R(old.offset);
2609  _isScaled = old._isScaled;
2610  lp_scaler = old.lp_scaler;
2611  spxout = old.spxout;
2612 
2613  assert(isConsistent());
2614  }
2615 
2616  return *this;
2617  }
2618 
2619  //@}
2620 };
2621 
2622 } // namespace soplex
2623 
2624 /* reset the SOPLEX_DEBUG flag to its original value */
2625 #undef SOPLEX_DEBUG
2626 #ifdef SOPLEX_DEBUG_SPXLPBASE
2627 #define SOPLEX_DEBUG
2628 #undef SOPLEX_DEBUG_SPXLPBASE
2629 #endif
2630 
2631 #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
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:884
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:1283
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:622
SPxRowId rId(int n) const
Returns the row identifier for row n.
Definition: spxlpbase.h:542
void doAddCol(const LPColBase< R > &col, bool scale=false)
Definition: spxlpbase.h:2315
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
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:1274
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:1509
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:705
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:712
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:1881
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:954
int size() const
Number of used indices.
Definition: svectorbase.h:152
void doAddCols(const LPColSetBase< R > &set, bool scale=false)
Definition: spxlpbase.h:2428
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:1333
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:1501
virtual bool readFile(const char *filename, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
Reads LP from a file.
Definition: spxlpbase.h:1134
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:1297
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:1586
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:1525
virtual void removeCols(int perm[])
Removes multiple columns.
Definition: spxlpbase.h:1000
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:2152
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:2021
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:38
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:1700
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:1405
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:573
virtual void removeRows(int nums[], int n, int perm[]=0)
Removes n LPRowBases.
Definition: spxlpbase.h:934
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:1905
void add(const LPColBase< R > &pcol)
Definition: lpcolsetbase.h:255
SPxLPBase< R > & operator=(const SPxLPBase< R > &old)
Assignment operator.
Definition: spxlpbase.h:2581
virtual Real scaleUpper(const SPxLPBase< Real > &lp, int col, Real upper) const
returns scaled upper bound of column col.
Definition: spxscaler.cpp:730
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:1492
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:1114
Set of strings.
virtual void removeCol(int i)
Removes i &#39;th column.
Definition: spxlpbase.h:981
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:254
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:1580
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:1863
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:361
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:741
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:1716
SPxColId cId(int n) const
Returns the column identifier for column n.
Definition: spxlpbase.h:548
SVectorBase< R > & rowVector_w(int i)
Definition: spxlpbase.h:2091
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:903
void changeLower(int i, const S *newLower)
changes i &#39;th lower bound to newLower.
Definition: spxlpbase.h:1348
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:1454
virtual void addCol(const R &objValue, const R &lowerValue, const SVectorBase< R > &colVec, const R &upperValue, bool scale=false)
Definition: spxlpbase.h:727
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:1265
void getLowerUnscaled(DVector &vec) const
Gets unscaled lower bound vector.
Real spxLdexp(Real x, int exp)
returns x * 2^exp
Definition: spxdefines.h:347
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:1155
declaration of types for file output
void maxObjUnscaled(VectorBase< Real > &vec) const
Returns unscaled objective vector for maximization problem.
double Real
Definition: spxdefines.h:215
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:1391
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:1319
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:1945
void getColVectorUnscaled(int i, DSVectorBase< Real > &vec) const
Gets column vector of column i.
Row and columns Id&#39;s SPxLP.
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:236
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:1289
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:766
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:615
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:1422
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:1534
void doAddRows(const LPRowSetBase< R > &set, bool scale=false)
Definition: spxlpbase.h:2207
void changeBounds(int i, const S *newLower, const S *newUpper)
Changes bounds of column i to newLower and newUpper.
Definition: spxlpbase.h:1414
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:1325
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:893
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:1460
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:1620
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:1893
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:1478
virtual void removeCols(int nums[], int n, int perm[]=0)
Removes n LPCols.
Definition: spxlpbase.h:1031
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:1730
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:780
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:681
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:1397
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:868
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:1546
void added2Set(SVSetBase< R > &set, const SVSetBase< R > &addset, int n)
Definition: spxlpbase.h:2025
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:1361
R & maxRowObj_w(int i)
Returns objective function value of row i.
Definition: spxlpbase.h:1875
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:909
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:566
void setLhs(const R &p_left)
Sets left-hand side value.
Definition: lprowbase.h:209
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:1257
virtual Real scaleLower(const SPxLPBase< Real > &lp, int col, Real lower) const
returns scaled lower bound of column col.
Definition: spxscaler.cpp:719
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:1753
void changeLhs(int i, const S *newLhs)
Changes i &#39;th left hand side value to newLhs.
Definition: spxlpbase.h:1447
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:721
SPxLPBase< R > & operator=(const SPxLPBase< S > &old)
Assignment operator.
Definition: spxlpbase.h:2601
int dim() const
Dimension of vector.
Definition: vectorbase.h:215
virtual void doRemoveCols(int perm[])
Internal helper method.
Definition: spxlpbase.h:1995
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:1355
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:1484
void changeElement(int i, int j, const S *val)
Changes LP element (i, j) to val.
Definition: spxlpbase.h:1669
void clear()
Remove all indices.
Definition: svectorbase.h:396
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:1887
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:1540
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:2372
const LPColSetBase< R > * lpcolset() const
Returns the LP as an LPColSetBase.
Definition: spxlpbase.h:1911
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:560
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:1515
LP scaler abstract base class.Instances of classes derived from SPxScaler may be loaded to SoPlex in ...
Definition: spxscaler.h:75
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:1706
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:1172
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:1436
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:1810
LP column.
virtual void removeColRange(int start, int end, int perm[]=0)
Removes columns from start to end (including both).
Definition: spxlpbase.h:1051
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:1006
void changeUpper(int i, const S *newUpper)
Changes i &#39;th upper bound to newUpper.
Definition: spxlpbase.h:1384
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:1626
virtual void removeCol(SPxColId id)
Removes column with identifier id.
Definition: spxlpbase.h:990
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:1428
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:1468
virtual void doRemoveRow(int j)
Internal helper method.
Definition: spxlpbase.h:1917
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:2017
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:734
#define MSGinconsistent(name)
Definition: spxdefines.h:123
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:2097
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:752
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:2085
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:1078
virtual void doRemoveCol(int j)
Internal helper method.
Definition: spxlpbase.h:1966
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:608
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:1312
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:1369
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:773
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:1869
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:1771
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