11#include "CoinHelperFunctions.hpp"
12#include "CoinIndexedVector.hpp"
32#ifndef OSICBC_DFLT_SOLVER
33#define OSICBC_DFLT_SOLVER OsiClpSolverInterface
34#define OSICBC_CLP_DFLT_SOLVER
35#include "OsiClpSolverInterface.hpp"
37#include OSICBC_DFLT_SOLVER_HPP
42#include "OsiRowCut.hpp"
43#include "OsiColCut.hpp"
44#ifdef OSICBC_CLP_DFLT_SOLVER
45#include "ClpPresolve.hpp"
63 return modelPtr_->solver()->setIntParam(key, value);
70 return modelPtr_->solver()->setDblParam(key, value);
76 const std::string& value) {
77 return modelPtr_->solver()->setStrParam(key, value);
83 return modelPtr_->solver()->getIntParam(key, value);
89 return modelPtr_->solver()->getDblParam(key, value);
95 std::string& value)
const {
96 if (key == OsiSolverName) {
98 modelPtr_->solver()->getStrParam(key, value2);
99 value =
"cbc" + value2;
102 return modelPtr_->solver()->getStrParam(key, value);
113 return modelPtr_->solver()->isAbandoned();
120 return modelPtr_->solver()->isProvenOptimal();
127 return modelPtr_->solver()->isProvenPrimalInfeasible();
132 return modelPtr_->isProvenDualInfeasible();
134 return modelPtr_->solver()->isProvenDualInfeasible();
137 return modelPtr_->solver()->isPrimalObjectiveLimitReached();
141 return modelPtr_->solver()->isDualObjectiveLimitReached();
148 return modelPtr_->solver()->isIterationLimitReached();
155 return modelPtr_->solver()->getEmptyWarmStart();
159 return modelPtr_->solver()->getWarmStart();
165 return modelPtr_->solver()->setWarmStart(warmstart);
177 modelPtr_->solver()->solveFromHotStart();
190 return modelPtr_->solver()->getRowSense();
194 return modelPtr_->solver()->getRightHandSide();
198 return modelPtr_->solver()->getRowRange();
204 return modelPtr_->solver()->isContinuous(colNumber);
212 return modelPtr_->solver()->getMatrixByRow();
216 return modelPtr_->solver()->getMatrixByCol();
221 bool fullRay)
const {
222 return modelPtr_->solver()->getDualRays(maxNumRays, fullRay);
226 int maxNumRays)
const {
227 return modelPtr_->solver()->getPrimalRays(maxNumRays);
231 modelPtr_->solver()->setContinuous(index);
239 modelPtr_->solver()->setContinuous(indices, len);
243 modelPtr_->solver()->setInteger(indices, len);
258 const double collb,
const double colub,
260 modelPtr_->solver()->addCol(vec, collb, colub, obj);
264 const double* elements,
const double collb,
265 const double colub,
const double obj) {
266 modelPtr_->solver()->addCol(numberElements, rows, elements, collb, colub,
271 const CoinPackedVectorBase*
const* cols,
272 const double* collb,
const double* colub,
274 modelPtr_->solver()->addCols(numcols, cols, collb, colub, obj);
278 const int* columnIndices) {
279 modelPtr_->solver()->deleteCols(num, columnIndices);
283 const double rowlb,
const double rowub) {
284 modelPtr_->solver()->addRow(vec, rowlb, rowub);
288 const char rowsen,
const double rowrhs,
289 const double rowrng) {
290 modelPtr_->solver()->addRow(vec, rowsen, rowrhs, rowrng);
294 const CoinPackedVectorBase*
const* rows,
295 const double* rowlb,
const double* rowub) {
296 modelPtr_->solver()->addRows(numrows, rows, rowlb, rowub);
300 const CoinPackedVectorBase*
const* rows,
301 const char* rowsen,
const double* rowrhs,
302 const double* rowrng) {
303 modelPtr_->solver()->addRows(numrows, rows, rowsen, rowrhs, rowrng);
307 modelPtr_->solver()->deleteRows(num, rowIndices);
316 const double* colub,
const double* obj,
318 const double* rowub) {
319 modelPtr_->solver()->loadProblem(matrix, collb, colub, obj, rowlb, rowub);
325 double*& collb,
double*& colub,
326 double*& obj,
double*& rowlb,
328 modelPtr_->solver()->assignProblem(matrix, collb, colub, obj, rowlb, rowub);
335 const double* colub,
const double* obj,
337 const double* rowrhs,
338 const double* rowrng) {
339 modelPtr_->solver()->loadProblem(matrix, collb, colub, obj, rowsen, rowrhs,
346 double*& collb,
double*& colub,
347 double*& obj,
char*& rowsen,
348 double*& rowrhs,
double*& rowrng) {
349 modelPtr_->solver()->assignProblem(matrix, collb, colub, obj, rowsen, rowrhs,
356 const CoinBigIndex* start,
357 const int* index,
const double* value,
359 const double* colub,
const double* obj,
361 const double* rowub) {
362 modelPtr_->solver()->loadProblem(numcols, numrows, start, index, value, collb,
363 colub, obj, rowlb, rowub);
368 const int numcols,
const int numrows,
const CoinBigIndex* start,
369 const int* index,
const double* value,
const double* collb,
370 const double* colub,
const double* obj,
const char* rowsen,
371 const double* rowrhs,
const double* rowrng) {
372 modelPtr_->solver()->loadProblem(numcols, numrows, start, index, value, collb,
373 colub, obj, rowsen, rowrhs, rowrng);
381 const char* extension,
382 double objSense)
const {
383 modelPtr_->solver()->writeMps(filename, extension, objSense);
387 const char** rowNames,
388 const char** columnNames,
389 int formatType,
int numberAcross,
390 double objSense)
const {
391 return modelPtr_->solver()->writeMpsNative(
392 filename, rowNames, columnNames, formatType, numberAcross, objSense);
402 CbcStrategy* strategy)
403 : OsiSolverInterface() {
413 CbcStrategyDefault defaultStrategy;
433 : OsiSolverInterface(rhs) {
451 OsiSolverInterface::operator=(rhs);
463 modelPtr_->solver()->applyRowCuts(1, &rowCut);
469 const OsiRowCut* cuts) {
470 modelPtr_->solver()->applyRowCuts(numberCuts, cuts);
476 const OsiRowCut** cuts) {
477 modelPtr_->solver()->applyRowCuts(numberCuts, cuts);
482 const double* lower =
modelPtr_->solver()->getColLower();
483 const double* upper =
modelPtr_->solver()->getColUpper();
484 const CoinPackedVector& lbs = cc.lbs();
485 const CoinPackedVector& ubs = cc.ubs();
488 for (i = 0; i < lbs.getNumElements(); i++) {
489 int iCol = lbs.getIndices()[i];
490 double value = lbs.getElements()[i];
491 if (value > lower[iCol])
modelPtr_->solver()->setColLower(iCol, value);
493 for (i = 0; i < ubs.getNumElements(); i++) {
494 int iCol = ubs.getIndices()[i];
495 double value = ubs.getElements()[i];
496 if (value < upper[iCol])
modelPtr_->solver()->setColUpper(iCol, value);
502 const char* extension) {
503 return modelPtr_->solver()->readMps(filename, extension);
507 return modelPtr_->solver()->getColSolution();
512 return modelPtr_->solver()->getRowPrice();
517 return modelPtr_->solver()->getReducedCost();
523 return modelPtr_->solver()->getRowActivity();
526 return modelPtr_->solver()->getObjValue();
531 modelPtr_->solver()->setObjCoeff(elementIndex, elementValue);
537 modelPtr_->solver()->setColLower(elementIndex, elementValue);
543 modelPtr_->solver()->setColUpper(elementIndex, elementValue);
549 modelPtr_->solver()->setColBounds(elementIndex, lower, upper);
552 const int* indexLast,
553 const double* boundList) {
554 modelPtr_->solver()->setColSetBounds(indexFirst, indexLast, boundList);
560 modelPtr_->solver()->setRowLower(elementIndex, elementValue);
566 modelPtr_->solver()->setRowUpper(elementIndex, elementValue);
572 modelPtr_->solver()->setRowBounds(elementIndex, lower, upper);
577 modelPtr_->solver()->setRowType(i, sense, rightHandSide, range);
581 const int* indexLast,
582 const double* boundList) {
583 modelPtr_->solver()->setRowSetBounds(indexFirst, indexLast, boundList);
587 const int* indexLast,
588 const char* senseList,
589 const double* rhsList,
590 const double* rangeList) {
591 modelPtr_->solver()->setRowSetTypes(indexFirst, indexLast, senseList, rhsList,
596 OsiHintStrength strength,
597 void* otherInformation) {
598 return modelPtr_->solver()->setHintParam(key, yesNo, strength,
604 OsiHintStrength& strength,
605 void*& otherInformation)
const {
606 return modelPtr_->solver()->getHintParam(key, yesNo, strength,
612 OsiHintStrength& strength)
const {
613 return modelPtr_->solver()->getHintParam(key, yesNo, strength);
617 return modelPtr_->solver()->getNumCols();
620 return modelPtr_->solver()->getNumRows();
623 return modelPtr_->solver()->getNumElements();
626 return modelPtr_->solver()->getColLower();
629 return modelPtr_->solver()->getColUpper();
632 return modelPtr_->solver()->getRowLower();
635 return modelPtr_->solver()->getRowUpper();
638 return modelPtr_->solver()->getObjCoefficients();
641 return modelPtr_->solver()->getObjSense();
644 return modelPtr_->solver()->getInfinity();
647 return modelPtr_->solver()->getIterationCount();
654 *messageHandler() <<
"Warning: Use of OsiCbc is deprecated."
657 <<
"To enjoy the full performance of Cbc, use the CbcSolver interface."
671 unsigned digits)
const {
672 return (
modelPtr_->solver()->dfltRowColName(rc, ndx, digits));
676 return (
modelPtr_->solver()->getObjName(maxLen));
680 return (
modelPtr_->solver()->getRowName(ndx, maxLen));
684 return (
modelPtr_->solver()->getRowNames());
688 return (
modelPtr_->solver()->getColName(ndx, maxLen));
692 return (
modelPtr_->solver()->getColNames());
696 int len,
int tgtStart) {
697 modelPtr_->solver()->setRowNames(srcNames, srcStart, len, tgtStart);
701 modelPtr_->solver()->deleteRowNames(tgtStart, len);
705 int len,
int tgtStart) {
706 modelPtr_->solver()->setColNames(srcNames, srcStart, len, tgtStart);
710 modelPtr_->solver()->deleteColNames(tgtStart, len);
730 modelPtr_->solver()->setRowName(ndx, name);
739 modelPtr_->solver()->setColName(ndx, name);
743 OsiSolverInterface::passInMessageHandler(handler);
#define OSICBC_DFLT_SOLVER
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
virtual bool isIterationLimitReached() const
Iteration limit reached?
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
virtual double getObjValue() const
Get objective function value.
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
virtual int getNumElements() const
Get number of nonzero elements.
virtual std::string getObjName(unsigned maxLen=std::string::npos) const
Return the name of the objective function.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
virtual void initialSolve()
Solve initial LP relaxation.
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
virtual void deleteRows(const int num, const int *rowIndices)
virtual void deleteCols(const int num, const int *colIndices)
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual void setRowSetTypes(const int *indexFirst, const int *indexLast, const char *senseList, const double *rhsList, const double *rangeList)
Set the type of a number of rows simultaneously The default implementation just invokes setRowType()...
virtual void setObjName(std::string name)
Set the name of the objective function.
virtual void resolve()
Resolve an LP relaxation after problem modification.
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
virtual int writeMpsNative(const char *filename, const char **rowNames, const char **columnNames, int formatType=0, int numberAcross=2, double objSense=0.0) const
Write the problem into an mps file of the given filename, names may be null.
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
virtual bool setHintParam(OsiHintParam key, bool yesNo=true, OsiHintStrength strength=OsiHintTry, void *otherInformation=NULL)
virtual bool getHintParam(OsiHintParam key, bool &yesNo, OsiHintStrength &strength, void *&otherInformation) const
Get a hint parameter.
virtual void addCols(const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj)
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
virtual ~OsiCbcSolverInterface()
Destructor.
bool getIntParam(OsiIntParam key, int &value) const
virtual void branchAndBound()
Invoke solver's built-in enumeration algorithm.
virtual int getNumRows() const
Get number of rows.
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound Use -DBL_MAX for -infinity.
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual void setRowNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple row names.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
virtual void applyRowCuts(int numberCuts, const OsiRowCut *cuts)
Apply a collection of row cuts which are all effective.
bool getStrParam(OsiStrParam key, std::string &value) const
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut (append to constraint matrix).
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
virtual std::string getRowName(int rowIndex, unsigned maxLen=std::string::npos) const
Return the name of the row.
virtual void setColName(int ndx, std::string name)
Set a column name.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual void setColSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the bounds on a number of columns simultaneously The default implementation just invokes setColL...
bool setIntParam(OsiIntParam key, int value)
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
virtual bool isPrimalObjectiveLimitReached() const
Is the given primal objective limit reached?
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual int readMps(const char *filename, const char *extension="mps")
Read an mps file from the given filename (defaults to Osi reader) - returns number of errors (see Osi...
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound Use DBL_MAX for infinity.
virtual void setRowPrice(const double *rowprice)
Set dual solution vector.
OsiCbcSolverInterface(OsiSolverInterface *solver=NULL, CbcStrategy *strategy=NULL)
Default Constructor.
virtual void unmarkHotStart()
Delete the snapshot.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
virtual void deleteRowNames(int tgtStart, int len)
Delete len row names starting at index tgtStart.
bool setStrParam(OsiStrParam key, const std::string &value)
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (adjust one or more bounds).
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
virtual void passInMessageHandler(CoinMessageHandler *handler)
Pass in a message handler.
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
virtual void solveFromHotStart()
Optimize starting from the hotstart.
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound Use DBL_MAX for infinity.
virtual std::vector< double * > getDualRays(int maxNumRays, bool fullRay=false) const
Get as many dual rays as the solver can provide.
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
virtual void setColNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple column names.
virtual void writeMps(const char *filename, const char *extension="mps", double objSense=0.0) const
Write the problem into an mps file of the given filename.
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
virtual void setRowBounds(int elementIndex, double lower, double upper)
Set a single row lower and upper bound.
OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface &rhs)
Assignment operator.
virtual bool isAbandoned() const
Are there a numerical difficulties?
virtual void markHotStart()
Create a hotstart point of the optimization process.
virtual int getNumCols() const
Get number of columns.
virtual double getInfinity() const
Get solver's value for infinity.
bool setDblParam(OsiDblParam key, double value)
virtual void setRowName(int ndx, std::string name)
Set a row name.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -DBL_MAX for -infinity.
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
CbcModel * modelPtr_
Cbc model represented by this class instance.
virtual void addRows(const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub)
virtual std::string getColName(int colIndex, unsigned maxLen=std::string::npos) const
Return the name of the column.
virtual void assignProblem(CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, double *&rowlb, double *&rowub)
Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by l...
virtual const OsiNameVec & getColNames()
Return a pointer to a vector of column names.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row
virtual const OsiNameVec & getRowNames()
Return a pointer to a vector of row names.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual void setColSolution(const double *colsol)
Set the primal solution column values.
virtual std::string dfltRowColName(char rc, int ndx, unsigned digits=7) const
Generate a standard name of the form Rnnnnnnn or Cnnnnnnn.
bool getDblParam(OsiDblParam key, double &value) const
virtual void setRowSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the bounds on a number of rows simultaneously The default implementation just invokes setRowLowe...
virtual void setColBounds(int elementIndex, double lower, double upper)
Set a single column lower and upper bound.
virtual void deleteColNames(int tgtStart, int len)
Delete len column names starting at index tgtStart.