Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
osiif.h
Go to the documentation of this file.
1
29#pragma once
30
31#include <ogdf/lib/abacus/lp.h>
37#include <coin/CoinPackedMatrix.hpp>
38#include <coin/CoinPackedVector.hpp>
39#include <coin/CoinWarmStartBasis.hpp>
40#include <coin/CoinBuild.hpp>
41
42namespace abacus {
43
44class LpMasterOsi;
45
46
47class OsiIF : public virtual LP {
48public:
49
51
57 OsiIF(Master *master);
58
60
72 OsiIF(Master *master,
74 int nRow,
75 int maxRow,
76 int nCol,
77 int maxCol,
82
84 virtual ~OsiIF();
85
88
90
92
93
94private:
95
97
102
103 /***************************************************
104 * Helper functions to free allocated memory
105 **************************************************/
106
107 void freeDouble(const double* &ptr) {
108 delete [] ptr;
109 ptr = nullptr;
110 }
111
112 void freeDouble(double* &ptr) {
113 delete [] ptr;
114 ptr = nullptr;
115 }
116
117 void freeInt(int* &ptr) {
118 delete [] ptr;
119 ptr = nullptr;
120 }
121
122 void freeChar(char* &ptr) {
123 delete [] ptr;
124 ptr = nullptr;
125 }
126
127 void freeChar(const char* &ptr) {
128 delete [] ptr;
129 ptr = nullptr;
130 }
131
132 void freeStatus(CoinWarmStartBasis::Status*&);
133
135
146 virtual void _initialize(
148 int nRow, int maxRow,
149 int nCol, int maxCol,
153 Array<Row*> &rows) override;
154
156
162
164
167 virtual OptSense _sense() const override;
168
170
173 virtual void _sense(const OptSense &newSense) override;
174
176
179 virtual int _nRow() const override { return numRows_; }
180
182
185 virtual int _maxRow() const override {
186 return numRows_; // Size management is completely done by Osi!
187 }
188
190
193 virtual int _nCol() const override { return numCols_; }
194
196
199 virtual int _maxCol() const override {
200 return numCols_; // Size management is completely done by Osi!
201 }
202
204
207 virtual double _obj(int i) const override { return objcoeff_[i]; }
208
210
213 virtual double _lBound(int i) const override { return collower_[i]; }
214
216
219 virtual double _uBound(int i) const override { return colupper_[i]; }
220
222
225 virtual double _rhs(int i) const override { return rhs_[i]; }
226
228
231 virtual void _row(int i, Row &r) const override;
232
234
237 virtual int _nnz() const override { return osiLP_->getNumElements(); }
238
240
243 virtual OPTSTAT _primalSimplex() override;
244
246
249 virtual OPTSTAT _dualSimplex() override;
250
252
255 virtual OPTSTAT _barrier(bool doCrossover) override;
256
258
261 virtual OPTSTAT _approx() override;
262
264
267 virtual double _value() const override { return value_; }
268
270
273 virtual double _xVal(int i) const override { return xVal_[i]; }
274
276
279 virtual double _barXVal(int i) const override;
280
282
285 virtual double _reco(int i) const override { return reco_[i]; }
286
288
291 virtual double _slack(int i) const override;
292
294
297 virtual double _yVal(int i) const override { return yVal_[i]; }
298
300
303 virtual LPVARSTAT::STATUS _lpVarStat(int i) const override;
304
306
309 virtual SlackStat::STATUS _slackStat(int i) const override;
310
312
326 virtual int _getInfeas(int &infeasRow, int &infeasCol, double *bInvRow) const override;
327
329
332 virtual void _remRows(ArrayBuffer<int> &ind) override;
333
335
338 virtual void _addRows(ArrayBuffer<Row*> &newRows) override ;
339
341
344 virtual void _remCols(ArrayBuffer<int> &vars) override;
345
347
350 virtual void _addCols(ArrayBuffer<Column*> &newVars) override;
351
353
357 virtual void _changeRhs(Array<double> &newRhs) override;
358
360
363 virtual void _changeLBound(int i, double newLb) override;
364
366
369 virtual void _changeUBound(int i, double newUb) override;
370
372
381
383
388 void getSol();
389
391 char csense2osi(CSense *sense) const;
392
395
397 CoinWarmStartBasis::Status lpVarStat2osi(LPVARSTAT::STATUS stat) const;
398
400 LPVARSTAT::STATUS osi2lpVarStat(CoinWarmStartBasis::Status stat) const;
401
403 CoinWarmStartBasis::Status slackStat2osi(SlackStat::STATUS stat) const;
404
406 SlackStat::STATUS osi2slackStat(CoinWarmStartBasis::Status stat) const;
407
410
413
415
418 void loadDummyRow(OsiSolverInterface* s2, const double* lbounds, const double* ubounds, const double* objectives);
419
421
432 void _rowRealloc(int newSize) override;
433
435
441 void _colRealloc(int newSize) override;
442
444
451 virtual int _setSimplexIterationLimit(int limit) override {
452 return(!osiLP_->setIntParam(OsiMaxNumIteration, limit));
453 }
454
456 /***
457 * \param limit Stores the iteration limit if the return value is 0.
458 *
459 * \return 0 If the iteration limit could be retrieved, \return 1 otherwise.
460 */
461 virtual int _getSimplexIterationLimit(int &limit) const override {
462 return(!osiLP_->getIntParam(OsiMaxNumIteration, limit));
463 }
464
466 double inf,
467 const char sense,
468 const double right,
469 const double range,
470 double& lower,
471 double& upper) const
472 {
473 switch (sense) {
474 case 'E':
475 lower = upper = right;
476 break;
477 case 'L':
478 lower = -inf;
479 upper = right;
480 break;
481 case 'G':
482 lower = right;
483 upper = inf;
484 break;
485 case 'R':
486 lower = right - range;
487 upper = right;
488 break;
489 case 'N':
490 lower = -inf;
491 upper = inf;
492 break;
493 }
494 }
495
497
499 double value_;
500
502 double *xVal_;
503
504 const double *barXVal_;
505
507 double *reco_;
508
510 double *yVal_;
511
513 char *cStat_;
514
517
520
522 char *rStat_;
523
525 const double *rhs_;
526
529
531 const char *rowsense_;
532
534 const double *colupper_;
535
537 const double *collower_;
538
540 const double *objcoeff_;
541
544
547
548 OsiIF(const OsiIF &rhs);
549 const OsiIF &operator=(const OsiIF &rhs);
550};
551
552}
Sense of constraints.
Definition csense.h:48
Linear programs.
Definition lp.h:70
double rhs(int i) const
Definition lp.h:257
virtual LPVARSTAT::STATUS lpVarStat(int i) const
Definition lp.h:350
int maxRow() const
Definition lp.h:221
OPTSTAT
The optimization status of the linear program.
Definition lp.h:74
int nCol() const
Definition lp.h:223
double lBound(int i) const
Definition lp.h:236
OptSense sense() const
Definition lp.h:215
virtual SlackStat::STATUS slackStat(int i) const
Definition lp.h:357
double uBound(int i) const
Definition lp.h:243
double obj(int i) const
Definition lp.h:229
int nRow() const
Definition lp.h:219
int maxCol() const
Definition lp.h:225
STATUS
The enumeration of the statuses a variable gets from the linear program solver.
Definition lpvarstat.h:54
The OSI LP master.
Definition lpmasterosi.h:43
The master of the optimization.
Definition master.h:69
Sense of optimization.
Definition optsense.h:44
virtual void _remCols(ArrayBuffer< int > &vars) override
Removes the columns listed in vars.
virtual void _changeRhs(Array< double > &newRhs) override
Sets the right hand side of the linear program to newRhs.
virtual LPVARSTAT::STATUS _lpVarStat(int i) const override
Returns the status of the column i.
void convertSenseToBound(double inf, const char sense, const double right, const double range, double &lower, double &upper) const
Definition osiif.h:465
LPVARSTAT::STATUS osi2lpVarStat(CoinWarmStartBasis::Status stat) const
Converts the OSI variable status to ABACUS format.
virtual void _initialize(OptSense sense, int nRow, int maxRow, int nCol, int maxCol, Array< double > &obj, Array< double > &lBound, Array< double > &uBound, Array< Row * > &rows) override
Loads the linear program defined by the following arguments to the solver.
virtual void _row(int i, Row &r) const override
Stores a copy of row i in r.
const OsiIF & operator=(const OsiIF &rhs)
virtual double _lBound(int i) const override
Returns the lower bound of column i.
Definition osiif.h:213
char * cStat_
An array storing the statuses of the variables after the linear program has been optimized.
Definition osiif.h:513
char csense2osi(CSense *sense) const
Converts the ABACUS representation of the row sense to the Osi representation.
virtual int _setSimplexIterationLimit(int limit) override
Changes the iteration limit of the Simplex algorithm.
Definition osiif.h:451
virtual int _nCol() const override
Returns the number of columns of the linear program.
Definition osiif.h:193
int numRows_
The number of rows currently used in the LP.
Definition osiif.h:519
virtual void _sense(const OptSense &newSense) override
Changes the sense of the optimization to newSense.
double value_
The value of the optimal solution.
Definition osiif.h:499
void loadDummyRow(OsiSolverInterface *s2, const double *lbounds, const double *ubounds, const double *objectives)
Initializes the problem with a dummy row.
virtual double _barXVal(int i) const override
Returns the value of the column i.
virtual ~OsiIF()
The destructor.
virtual void _changeLBound(int i, double newLb) override
Sets the lower bound of column i to newLb.
void _rowRealloc(int newSize) override
Reallocates the internal memory such that newSize rows can be stored.
void freeDouble(double *&ptr)
Definition osiif.h:112
CoinWarmStartBasis::Status lpVarStat2osi(LPVARSTAT::STATUS stat) const
Converts the ABACUS variable status to OSI format.
OsiSolverInterface * switchInterfaces(SOLVERTYPE newMethod)
Switches between exact and approximate solvers.
void freeChar(const char *&ptr)
Definition osiif.h:127
virtual int _getInfeas(int &infeasRow, int &infeasCol, double *bInvRow) const override
Can be called if the last linear program has been solved with the dual simplex method and is infeasib...
CoinWarmStartBasis::Status slackStat2osi(SlackStat::STATUS stat) const
Converts the ABACUS slack status to OSI format.
virtual int _getSimplexIterationLimit(int &limit) const override
Defines a pure virtual function of the base class LP.
Definition osiif.h:461
virtual SlackStat::STATUS _slackStat(int i) const override
Returns the status of the slack column i.
OsiSolverInterface * osiLP()
Definition osiif.h:91
SOLVERTYPE currentSolverType() const
Definition osiif.h:89
OsiIF(const OsiIF &rhs)
virtual double _rhs(int i) const override
Returns the right hand side of row i.
Definition osiif.h:225
virtual OPTSTAT _barrier(bool doCrossover) override
Calls the barrier method.
double * xVal_
An array storing the values of the variables after the linear program has been optimized.
Definition osiif.h:502
void freeChar(char *&ptr)
Definition osiif.h:122
virtual double _uBound(int i) const override
Returns the upper bound of column i.
Definition osiif.h:219
const char * rowsense_
An array storing the row senses of the linear program.
Definition osiif.h:531
void freeDouble(const double *&ptr)
Definition osiif.h:107
virtual int _maxCol() const override
Returns the maximal number of columns of the linear program.
Definition osiif.h:199
OsiIF(Master *master, OptSense sense, int nRow, int maxRow, int nCol, int maxCol, Array< double > &obj, Array< double > &lb, Array< double > &ub, Array< Row * > &rows)
A constructor with initialization.
virtual void _addCols(ArrayBuffer< Column * > &newVars) override
Adds the columns newCols to the linear program.
virtual double _obj(int i) const override
Returns the objective function coefficient of column i.
Definition osiif.h:207
SlackStat::STATUS osi2slackStat(CoinWarmStartBasis::Status stat) const
Converts the OSI slack status to ABACUS format.
LpMasterOsi * lpMasterOsi_
Definition osiif.h:496
const double * collower_
An array storing the column lower bounds of the linear program.
Definition osiif.h:537
double * reco_
An array storing the values of the reduced costs after the linear program has been optimized.
Definition osiif.h:507
OsiIF(Master *master)
Constructor without initialization.
const double * objcoeff_
An array storing the objective function coefficients of the linear program.
Definition osiif.h:540
virtual void _remRows(ArrayBuffer< int > &ind) override
Removes the rows listed in ind.
virtual void _loadBasis(Array< LPVARSTAT::STATUS > &lpVarStat, Array< SlackStat::STATUS > &slackStat) override
Loads a basis to the solver.
CSense::SENSE osi2csense(char sense) const
Converts the OSI representation of the row sense to the ABACUS representation.
SOLVERTYPE currentSolverType_
The type of the current solver interface.
Definition osiif.h:546
double * yVal_
An array storing the values of the dual variables after the linear program has been optimized.
Definition osiif.h:510
CoinWarmStartBasis * ws_
A warm start object storing information about a basis of the linear program.
Definition osiif.h:543
virtual void _addRows(ArrayBuffer< Row * > &newRows) override
Adds the rows to the linear program.
SOLVERTYPE
The enumeration of possible solver types.
Definition osiif.h:87
virtual OPTSTAT _dualSimplex() override
Calls the dual simplex method.
virtual OPTSTAT _primalSimplex() override
Calls the primal simplex method.
virtual void _changeUBound(int i, double newUb) override
Sets the upper bound of column i to newLb.
virtual double _reco(int i) const override
Returns the reduced cost of the column i.
Definition osiif.h:285
const double * rhs_
An array storing the right hand sides of the linear program.
Definition osiif.h:525
OsiSolverInterface * getDefaultInterface()
Allocates an Open Solver Interface of type defaultOsiSolver.
const double * barXVal_
Definition osiif.h:504
char * rStat_
An array storing the statuses of the slack variables after the linear program has been optimized.
Definition osiif.h:522
const double * colupper_
An array storing the column upper bounds of the linear program.
Definition osiif.h:534
virtual double _slack(int i) const override
Returns the value of the slack column of the row i.
virtual OPTSTAT _approx() override
Calls an approximate method.
void _colRealloc(int newSize) override
Reallocates the internal memory such that newSize columns can be stored.
OsiSolverInterface * osiLP_
Pointer to the Osi solver interface.
Definition osiif.h:101
virtual double _value() const override
Returns the optimum value of the linear program.
Definition osiif.h:267
virtual int _pivotSlackVariableIn(ArrayBuffer< int > &rows) override
Pivots the slack variables stored in the buffer rows into the basis.
void getSol()
Extracts the solution.
virtual int _nnz() const override
Returns the number of nonzero elements in the constraint matrix (not including the right hand side).
Definition osiif.h:237
virtual int _nRow() const override
Returns the number of rows of the linear program.
Definition osiif.h:179
virtual double _yVal(int i) const override
Returns the value of the dual column of the row i.
Definition osiif.h:297
double * rowactivity_
An array storing the row activity of the linear program.
Definition osiif.h:528
void freeStatus(CoinWarmStartBasis::Status *&)
virtual double _xVal(int i) const override
Returns the value of the column i.
Definition osiif.h:273
int numCols_
The number of columns currently used in the LP.
Definition osiif.h:516
virtual OptSense _sense() const override
Returns the sense of the optimization.
virtual int _maxRow() const override
Returns the maximal number of rows of the linear program.
Definition osiif.h:185
void freeInt(int *&ptr)
Definition osiif.h:117
Representation of constraints in the row format.
Definition row.h:51
STATUS
The different statuses of a slack variable.
Definition slackstat.h:51
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:56
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
csense.
int r[]
linear program.
status of variables.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
sense of optimization.
status of slack variables