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