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