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"
67 return modelPtr_->solver()->setIntParam(key,value);;
75 return modelPtr_->solver()->setDblParam(key,value);
83 return modelPtr_->solver()->setStrParam(key,value);
92 return modelPtr_->solver()->getIntParam(key,value);
100 return modelPtr_->solver()->getDblParam(key,value);
108 if ( key==OsiSolverName ) {
110 modelPtr_->solver()->getStrParam(key,value2);
111 value =
"cbc"+value2;
114 return modelPtr_->solver()->getStrParam(key,value);
127 return modelPtr_->solver()->isAbandoned();
135 return modelPtr_->solver()->isProvenOptimal();
143 return modelPtr_->solver()->isProvenPrimalInfeasible();
149 return modelPtr_->isProvenDualInfeasible();
151 return modelPtr_->solver()->isProvenDualInfeasible();
155 return modelPtr_->solver()->isPrimalObjectiveLimitReached();
160 return modelPtr_->solver()->isDualObjectiveLimitReached();
168 return modelPtr_->solver()->isIterationLimitReached();
176 return modelPtr_->solver()->getEmptyWarmStart();
181 return modelPtr_->solver()->getWarmStart();
188 return modelPtr_->solver()->setWarmStart(warmstart);
202 modelPtr_->solver()->solveFromHotStart();
217 return modelPtr_->solver()->getRowSense();
222 return modelPtr_->solver()->getRightHandSide();
227 return modelPtr_->solver()->getRowRange();
234 return modelPtr_->solver()->isContinuous(colNumber);
243 return modelPtr_->solver()->getMatrixByRow();
248 return modelPtr_->solver()->getMatrixByCol();
255 return modelPtr_->solver()->getDualRays(maxNumRays,fullRay);
260 return modelPtr_->solver()->getPrimalRays(maxNumRays);
266 modelPtr_->solver()->setContinuous(index);
278 modelPtr_->solver()->setContinuous(indices,len);
284 modelPtr_->solver()->setInteger(indices,len);
302 const double collb,
const double colub,
305 modelPtr_->solver()->addCol(vec,collb,colub,obj);
310 const double collb,
const double colub,
313 modelPtr_->solver()->addCol(numberElements, rows, elements,
319 const CoinPackedVectorBase *
const * cols,
320 const double* collb,
const double* colub,
323 modelPtr_->solver()->addCols(numcols,cols,collb,colub,obj);
329 modelPtr_->solver()->deleteCols(num,columnIndices);
334 const double rowlb,
const double rowub)
336 modelPtr_->solver()->addRow(vec,rowlb,rowub);
341 const char rowsen,
const double rowrhs,
344 modelPtr_->solver()->addRow(vec,rowsen,rowrhs,rowrng);
349 const CoinPackedVectorBase *
const * rows,
350 const double* rowlb,
const double* rowub)
352 modelPtr_->solver()->addRows(numrows,rows,rowlb,rowub);
357 const CoinPackedVectorBase *
const * rows,
358 const char* rowsen,
const double* rowrhs,
359 const double* rowrng)
361 modelPtr_->solver()->addRows(numrows,rows,rowsen,rowrhs,rowrng);
367 modelPtr_->solver()->deleteRows(num,rowIndices);
376 const double* collb,
const double* colub,
378 const double* rowlb,
const double* rowub)
380 modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowlb,rowub);
387 double*& collb,
double*& colub,
389 double*& rowlb,
double*& rowub)
391 modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowlb,rowub);
398 const double* collb,
const double* colub,
400 const char* rowsen,
const double* rowrhs,
401 const double* rowrng)
403 modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
410 double*& collb,
double*& colub,
412 char*& rowsen,
double*& rowrhs,
415 modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
422 const CoinBigIndex * start,
const int* index,
424 const double* collb,
const double* colub,
426 const double* rowlb,
const double* rowub)
428 modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
429 collb,colub,obj,rowlb,rowub);
435 const CoinBigIndex * start,
const int* index,
437 const double* collb,
const double* colub,
439 const char* rowsen,
const double* rowrhs,
440 const double* rowrng)
442 modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
443 collb,colub,obj,rowsen,rowrhs,rowrng);
451 const char * extension,
452 double objSense)
const
454 modelPtr_->solver()->writeMps(filename,extension,objSense);
459 const char ** rowNames,
const char ** columnNames,
460 int formatType,
int numberAcross,
double objSense)
const
462 return modelPtr_->solver()->writeMpsNative(filename, rowNames, columnNames,
463 formatType, numberAcross,objSense);
473 CbcStrategy * strategy)
486 CbcStrategyDefault defaultStrategy;
510OsiSolverInterface(rhs)
532 OsiSolverInterface::operator=(rhs);
545 modelPtr_->solver()->applyRowCuts(1,&rowCut);
553 modelPtr_->solver()->applyRowCuts(numberCuts,cuts);
561 modelPtr_->solver()->applyRowCuts(numberCuts, cuts);
567 const double * lower =
modelPtr_->solver()->getColLower();
568 const double * upper =
modelPtr_->solver()->getColUpper();
569 const CoinPackedVector & lbs = cc.lbs();
570 const CoinPackedVector & ubs = cc.ubs();
573 for ( i=0; i<lbs.getNumElements(); i++ ) {
574 int iCol = lbs.getIndices()[i];
575 double value = lbs.getElements()[i];
576 if ( value > lower[iCol] )
577 modelPtr_->solver()->setColLower(iCol, value);
579 for ( i=0; i<ubs.getNumElements(); i++ ) {
580 int iCol = ubs.getIndices()[i];
581 double value = ubs.getElements()[i];
582 if ( value < upper[iCol] )
583 modelPtr_->solver()->setColUpper(iCol, value);
590 const char *extension )
592 return modelPtr_->solver()->readMps(filename,extension);
598 return modelPtr_->solver()->getColSolution();
605 return modelPtr_->solver()->getRowPrice();
612 return modelPtr_->solver()->getReducedCost();
620 return modelPtr_->solver()->getRowActivity();
625 return modelPtr_->solver()->getObjValue();
632 modelPtr_->solver()->setObjCoeff(elementIndex,elementValue);
640 modelPtr_->solver()->setColLower(elementIndex,elementValue);
648 modelPtr_->solver()->setColUpper(elementIndex,elementValue);
654 double lower,
double upper )
656 modelPtr_->solver()->setColBounds(elementIndex,lower,upper);
659 const int* indexLast,
660 const double* boundList)
662 modelPtr_->solver()->setColSetBounds(indexFirst,indexLast,boundList);
669 modelPtr_->solver()->setRowLower(elementIndex,elementValue);
676 modelPtr_->solver()->setRowUpper(elementIndex,elementValue);
682 double lower,
double upper ) {
683 modelPtr_->solver()->setRowBounds(elementIndex,lower,upper);
690 modelPtr_->solver()->setRowType(i,sense,rightHandSide,range);
694 const int* indexLast,
695 const double* boundList)
697 modelPtr_->solver()->setRowSetBounds(indexFirst,indexLast,boundList);
702 const int* indexLast,
703 const char* senseList,
704 const double* rhsList,
705 const double* rangeList)
707 modelPtr_->solver()->setRowSetTypes(indexFirst,indexLast,senseList,rhsList,rangeList);
712 OsiHintStrength strength,
713 void * otherInformation)
715 return modelPtr_->solver()->setHintParam(key,yesNo, strength, otherInformation);
721 OsiHintStrength & strength,
722 void *& otherInformation)
const
724 return modelPtr_->solver()->getHintParam(key,yesNo, strength, otherInformation);
730 OsiHintStrength & strength)
const
732 return modelPtr_->solver()->getHintParam(key,yesNo, strength);
739 return modelPtr_->solver()->getNumCols();
744 return modelPtr_->solver()->getNumRows();
749 return modelPtr_->solver()->getNumElements();
754 return modelPtr_->solver()->getColLower();
759 return modelPtr_->solver()->getColUpper();
764 return modelPtr_->solver()->getRowLower();
769 return modelPtr_->solver()->getRowUpper();
774 return modelPtr_->solver()->getObjCoefficients();
779 return modelPtr_->solver()->getObjSense();
784 return modelPtr_->solver()->getInfinity();
789 return modelPtr_->solver()->getIterationCount();
800 *messageHandler() <<
"Warning: Use of OsiCbc is deprecated." << CoinMessageEol;
801 *messageHandler() <<
"To enjoy the full performance of Cbc, use the CbcSolver interface." << CoinMessageEol;
816 return (
modelPtr_->solver()->dfltRowColName(rc,ndx,digits)) ;
821 return (
modelPtr_->solver()->getObjName(maxLen)) ;
826 return (
modelPtr_->solver()->getRowName(ndx,maxLen)) ;
831 return (
modelPtr_->solver()->getRowNames()) ;
836 return (
modelPtr_->solver()->getColName(ndx,maxLen)) ;
841 return (
modelPtr_->solver()->getColNames()) ;
845 int srcStart,
int len,
int tgtStart)
847 modelPtr_->solver()->setRowNames(srcNames,srcStart,len,tgtStart) ;
852 modelPtr_->solver()->deleteRowNames(tgtStart,len) ;
856 int srcStart,
int len,
int tgtStart)
858 modelPtr_->solver()->setColNames(srcNames,srcStart,len,tgtStart) ;
863 modelPtr_->solver()->deleteColNames(tgtStart,len) ;
884 modelPtr_->solver()->setRowName(ndx,name) ;
893 modelPtr_->solver()->setColName(ndx,name) ;
899 OsiSolverInterface::passInMessageHandler(handler);
901 modelPtr_->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.