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