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
42#pragma GCC visibility push(default)
43namespace abacus {
44
45class LpMasterOsi;
46
47
48class OsiIF : public virtual LP {
49public:
50
52
58 OsiIF(Master *master);
59
61
73 OsiIF(Master *master,
75 int nRow,
76 int maxRow,
77 int nCol,
78 int maxCol,
80 Array<double> &lb,
81 Array<double> &ub,
82 Array<Row*> &rows);
83
85 virtual ~OsiIF();
86
89
91
92 OsiSolverInterface* osiLP() { return osiLP_; }
93
94
95private:
96
98
102 OsiSolverInterface *osiLP_;
103
104 /***************************************************
105 * Helper functions to free allocated memory
106 **************************************************/
107
108 void freeDouble(const double* &ptr) {
109 delete [] ptr;
110 ptr = nullptr;
111 }
112
113 void freeDouble(double* &ptr) {
114 delete [] ptr;
115 ptr = nullptr;
116 }
117
118 void freeInt(int* &ptr) {
119 delete [] ptr;
120 ptr = nullptr;
121 }
122
123 void freeChar(char* &ptr) {
124 delete [] ptr;
125 ptr = nullptr;
126 }
127
128 void freeChar(const char* &ptr) {
129 delete [] ptr;
130 ptr = nullptr;
131 }
132
133 void freeStatus(CoinWarmStartBasis::Status*&);
134
136
147 virtual void _initialize(
149 int nRow, int maxRow,
150 int nCol, int maxCol,
154 Array<Row*> &rows) override;
155
157
163
165
168 virtual OptSense _sense() const override;
169
171
174 virtual void _sense(const OptSense &newSense) override;
175
177
180 virtual int _nRow() const override { return numRows_; }
181
183
186 virtual int _maxRow() const override {
187 return numRows_; // Size management is completely done by Osi!
188 }
189
191
194 virtual int _nCol() const override { return numCols_; }
195
197
200 virtual int _maxCol() const override {
201 return numCols_; // Size management is completely done by Osi!
202 }
203
205
208 virtual double _obj(int i) const override { return objcoeff_[i]; }
209
211
214 virtual double _lBound(int i) const override { return collower_[i]; }
215
217
220 virtual double _uBound(int i) const override { return colupper_[i]; }
221
223
226 virtual double _rhs(int i) const override { return rhs_[i]; }
227
229
232 virtual void _row(int i, Row &r) const override;
233
235
238 virtual int _nnz() const override { return osiLP_->getNumElements(); }
239
241
244 virtual OPTSTAT _primalSimplex() override;
245
247
250 virtual OPTSTAT _dualSimplex() override;
251
253
256 virtual OPTSTAT _barrier(bool doCrossover) override;
257
259
262 virtual OPTSTAT _approx() override;
263
265
268 virtual double _value() const override { return value_; }
269
271
274 virtual double _xVal(int i) const override { return xVal_[i]; }
275
277
280 virtual double _barXVal(int i) const override;
281
283
286 virtual double _reco(int i) const override { return reco_[i]; }
287
289
292 virtual double _slack(int i) const override;
293
295
298 virtual double _yVal(int i) const override { return yVal_[i]; }
299
301
304 virtual LPVARSTAT::STATUS _lpVarStat(int i) const override;
305
307
310 virtual SlackStat::STATUS _slackStat(int i) const override;
311
313
327 virtual int _getInfeas(int &infeasRow, int &infeasCol, double *bInvRow) const override;
328
330
333 virtual void _remRows(ArrayBuffer<int> &ind) override;
334
336
339 virtual void _addRows(ArrayBuffer<Row*> &newRows) override ;
340
342
345 virtual void _remCols(ArrayBuffer<int> &vars) override;
346
348
351 virtual void _addCols(ArrayBuffer<Column*> &newVars) override;
352
354
358 virtual void _changeRhs(Array<double> &newRhs) override;
359
361
364 virtual void _changeLBound(int i, double newLb) override;
365
367
370 virtual void _changeUBound(int i, double newUb) override;
371
373
381 virtual int _pivotSlackVariableIn(ArrayBuffer<int> &rows) override;
382
384
389 void getSol();
390
392 char csense2osi(CSense *sense) const;
393
396
398 CoinWarmStartBasis::Status lpVarStat2osi(LPVARSTAT::STATUS stat) const;
399
401 LPVARSTAT::STATUS osi2lpVarStat(CoinWarmStartBasis::Status stat) const;
402
404 CoinWarmStartBasis::Status slackStat2osi(SlackStat::STATUS stat) const;
405
407 SlackStat::STATUS osi2slackStat(CoinWarmStartBasis::Status stat) const;
408
410 OsiSolverInterface* getDefaultInterface();
411
413 OsiSolverInterface* switchInterfaces(SOLVERTYPE newMethod);
414
416
419 void loadDummyRow(OsiSolverInterface* s2, const double* lbounds, const double* ubounds, const double* objectives);
420
422
433 void _rowRealloc(int newSize) override;
434
436
442 void _colRealloc(int newSize) override;
443
445
452 virtual int _setSimplexIterationLimit(int limit) override {
453 return(!osiLP_->setIntParam(OsiMaxNumIteration, limit));
454 }
455
457 /***
458 * \param limit Stores the iteration limit if the return value is 0.
459 *
460 * \return 0 If the iteration limit could be retrieved, \return 1 otherwise.
461 */
462 virtual int _getSimplexIterationLimit(int &limit) const override {
463 return(!osiLP_->getIntParam(OsiMaxNumIteration, limit));
464 }
465
467 double inf,
468 const char sense,
469 const double right,
470 const double range,
471 double& lower,
472 double& upper) const
473 {
474 switch (sense) {
475 case 'E':
476 lower = upper = right;
477 break;
478 case 'L':
479 lower = -inf;
480 upper = right;
481 break;
482 case 'G':
483 lower = right;
484 upper = inf;
485 break;
486 case 'R':
487 lower = right - range;
488 upper = right;
489 break;
490 case 'N':
491 lower = -inf;
492 upper = inf;
493 break;
494 }
495 }
496
498
500 double value_;
501
503 double *xVal_;
504
505 const double *barXVal_;
506
508 double *reco_;
509
511 double *yVal_;
512
514 char *cStat_;
515
518
521
523 char *rStat_;
524
526 const double *rhs_;
527
530
532 const char *rowsense_;
533
535 const double *colupper_;
536
538 const double *collower_;
539
541 const double *objcoeff_;
542
544 CoinWarmStartBasis *ws_;
545
548
549 OsiIF(const OsiIF &rhs);
550 const OsiIF &operator=(const OsiIF &rhs);
551};
552
553}
554#pragma GCC visibility pop
Sense of constraints.
Definition csense.h:49
Linear programs.
Definition lp.h:71
double rhs(int i) const
Definition lp.h:258
virtual LPVARSTAT::STATUS lpVarStat(int i) const
Definition lp.h:351
int maxRow() const
Definition lp.h:222
OPTSTAT
The optimization status of the linear program.
Definition lp.h:75
int nCol() const
Definition lp.h:224
double lBound(int i) const
Definition lp.h:237
OptSense sense() const
Definition lp.h:216
virtual SlackStat::STATUS slackStat(int i) const
Definition lp.h:358
double uBound(int i) const
Definition lp.h:244
double obj(int i) const
Definition lp.h:230
int nRow() const
Definition lp.h:220
int maxCol() const
Definition lp.h:226
STATUS
The enumeration of the statuses a variable gets from the linear program solver.
Definition lpvarstat.h:55
The OSI LP master.
Definition lpmasterosi.h:44
The master of the optimization.
Definition master.h:70
Sense of optimization.
Definition optsense.h:45
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:466
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:214
char * cStat_
An array storing the statuses of the variables after the linear program has been optimized.
Definition osiif.h:514
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:452
virtual int _nCol() const override
Returns the number of columns of the linear program.
Definition osiif.h:194
int numRows_
The number of rows currently used in the LP.
Definition osiif.h:520
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:500
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:113
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:128
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:462
virtual SlackStat::STATUS _slackStat(int i) const override
Returns the status of the slack column i.
OsiSolverInterface * osiLP()
Definition osiif.h:92
SOLVERTYPE currentSolverType() const
Definition osiif.h:90
OsiIF(const OsiIF &rhs)
virtual double _rhs(int i) const override
Returns the right hand side of row i.
Definition osiif.h:226
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:503
void freeChar(char *&ptr)
Definition osiif.h:123
virtual double _uBound(int i) const override
Returns the upper bound of column i.
Definition osiif.h:220
const char * rowsense_
An array storing the row senses of the linear program.
Definition osiif.h:532
void freeDouble(const double *&ptr)
Definition osiif.h:108
virtual int _maxCol() const override
Returns the maximal number of columns of the linear program.
Definition osiif.h:200
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:208
SlackStat::STATUS osi2slackStat(CoinWarmStartBasis::Status stat) const
Converts the OSI slack status to ABACUS format.
LpMasterOsi * lpMasterOsi_
Definition osiif.h:497
const double * collower_
An array storing the column lower bounds of the linear program.
Definition osiif.h:538
double * reco_
An array storing the values of the reduced costs after the linear program has been optimized.
Definition osiif.h:508
OsiIF(Master *master)
Constructor without initialization.
const double * objcoeff_
An array storing the objective function coefficients of the linear program.
Definition osiif.h:541
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:547
double * yVal_
An array storing the values of the dual variables after the linear program has been optimized.
Definition osiif.h:511
CoinWarmStartBasis * ws_
A warm start object storing information about a basis of the linear program.
Definition osiif.h:544
virtual void _addRows(ArrayBuffer< Row * > &newRows) override
Adds the rows to the linear program.
SOLVERTYPE
The enumeration of possible solver types.
Definition osiif.h:88
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:286
const double * rhs_
An array storing the right hand sides of the linear program.
Definition osiif.h:526
OsiSolverInterface * getDefaultInterface()
Allocates an Open Solver Interface of type defaultOsiSolver.
const double * barXVal_
Definition osiif.h:505
char * rStat_
An array storing the statuses of the slack variables after the linear program has been optimized.
Definition osiif.h:523
const double * colupper_
An array storing the column upper bounds of the linear program.
Definition osiif.h:535
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:102
virtual double _value() const override
Returns the optimum value of the linear program.
Definition osiif.h:268
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:238
virtual int _nRow() const override
Returns the number of rows of the linear program.
Definition osiif.h:180
virtual double _yVal(int i) const override
Returns the value of the dual column of the row i.
Definition osiif.h:298
double * rowactivity_
An array storing the row activity of the linear program.
Definition osiif.h:529
void freeStatus(CoinWarmStartBasis::Status *&)
virtual double _xVal(int i) const override
Returns the value of the column i.
Definition osiif.h:274
int numCols_
The number of columns currently used in the LP.
Definition osiif.h:517
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:186
void freeInt(int *&ptr)
Definition osiif.h:118
Representation of constraints in the row format.
Definition row.h:52
STATUS
The different statuses of a slack variable.
Definition slackstat.h:52
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
csense.
linear program.
status of variables.
sense of optimization.
status of slack variables