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