9 #include "CoinTime.hpp" 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 41 #include "OsiCuts.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);
124 return modelPtr_->solver()->isAbandoned();
129 return modelPtr_->solver()->isProvenOptimal();
134 return modelPtr_->solver()->isProvenPrimalInfeasible();
139 return modelPtr_->solver()->isProvenDualInfeasible();
143 return modelPtr_->solver()->isPrimalObjectiveLimitReached();
148 return modelPtr_->solver()->isDualObjectiveLimitReached();
153 return modelPtr_->solver()->isIterationLimitReached();
161 return modelPtr_->solver()->getEmptyWarmStart();
166 return modelPtr_->solver()->getWarmStart();
173 return modelPtr_->solver()->setWarmStart(warmstart);
187 modelPtr_->solver()->solveFromHotStart();
202 return modelPtr_->solver()->getRowSense();
207 return modelPtr_->solver()->getRightHandSide();
212 return modelPtr_->solver()->getRowRange();
219 return modelPtr_->solver()->isContinuous(colNumber);
228 return modelPtr_->solver()->getMatrixByRow();
233 return modelPtr_->solver()->getMatrixByCol();
240 return modelPtr_->solver()->getDualRays(maxNumRays,fullRay);
245 return modelPtr_->solver()->getPrimalRays(maxNumRays);
251 modelPtr_->solver()->setContinuous(index);
263 modelPtr_->solver()->setContinuous(indices,len);
269 modelPtr_->solver()->setInteger(indices,len);
287 const double collb,
const double colub,
290 modelPtr_->solver()->addCol(vec,collb,colub,obj);
295 const double collb,
const double colub,
298 modelPtr_->solver()->addCol(numberElements, rows, elements,
304 const CoinPackedVectorBase *
const * cols,
305 const double* collb,
const double* colub,
308 modelPtr_->solver()->addCols(numcols,cols,collb,colub,obj);
314 modelPtr_->solver()->deleteCols(num,columnIndices);
319 const double rowlb,
const double rowub)
321 modelPtr_->solver()->addRow(vec,rowlb,rowub);
326 const char rowsen,
const double rowrhs,
329 modelPtr_->solver()->addRow(vec,rowsen,rowrhs,rowrng);
334 const CoinPackedVectorBase *
const * rows,
335 const double* rowlb,
const double* rowub)
337 modelPtr_->solver()->addRows(numrows,rows,rowlb,rowub);
342 const CoinPackedVectorBase *
const * rows,
343 const char* rowsen,
const double* rowrhs,
344 const double* rowrng)
346 modelPtr_->solver()->addRows(numrows,rows,rowsen,rowrhs,rowrng);
352 modelPtr_->solver()->deleteRows(num,rowIndices);
361 const double* collb,
const double* colub,
363 const double* rowlb,
const double* rowub)
365 modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowlb,rowub);
372 double*& collb,
double*& colub,
374 double*& rowlb,
double*& rowub)
376 modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowlb,rowub);
383 const double* collb,
const double* colub,
385 const char* rowsen,
const double* rowrhs,
386 const double* rowrng)
388 modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
395 double*& collb,
double*& colub,
397 char*& rowsen,
double*& rowrhs,
400 modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
407 const CoinBigIndex * start,
const int* index,
409 const double* collb,
const double* colub,
411 const double* rowlb,
const double* rowub)
413 modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
414 collb,colub,obj,rowlb,rowub);
420 const CoinBigIndex * start,
const int* index,
422 const double* collb,
const double* colub,
424 const char* rowsen,
const double* rowrhs,
425 const double* rowrng)
427 modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
428 collb,colub,obj,rowsen,rowrhs,rowrng);
436 const char * extension,
437 double objSense)
const 439 modelPtr_->solver()->writeMps(filename,extension,objSense);
444 const char ** rowNames,
const char ** columnNames,
445 int formatType,
int numberAcross,
double objSense)
const 447 return modelPtr_->solver()->writeMpsNative(filename, rowNames, columnNames,
448 formatType, numberAcross,objSense);
458 CbcStrategy * strategy)
471 CbcStrategyDefault defaultStrategy;
495 OsiSolverInterface(rhs)
517 OsiSolverInterface::operator=(rhs);
530 modelPtr_->solver()->applyRowCuts(1,&rowCut);
538 modelPtr_->solver()->applyRowCuts(numberCuts,cuts);
546 modelPtr_->solver()->applyRowCuts(numberCuts, cuts);
552 const double * lower =
modelPtr_->solver()->getColLower();
553 const double * upper =
modelPtr_->solver()->getColUpper();
554 const CoinPackedVector & lbs = cc.lbs();
555 const CoinPackedVector & ubs = cc.ubs();
558 for ( i=0; i<lbs.getNumElements(); i++ ) {
559 int iCol = lbs.getIndices()[i];
560 double value = lbs.getElements()[i];
561 if ( value > lower[iCol] )
562 modelPtr_->solver()->setColLower(iCol, value);
564 for ( i=0; i<ubs.getNumElements(); i++ ) {
565 int iCol = ubs.getIndices()[i];
566 double value = ubs.getElements()[i];
567 if ( value < upper[iCol] )
568 modelPtr_->solver()->setColUpper(iCol, value);
575 const char *extension )
577 return modelPtr_->solver()->readMps(filename,extension);
583 return modelPtr_->solver()->getColSolution();
590 return modelPtr_->solver()->getRowPrice();
597 return modelPtr_->solver()->getReducedCost();
605 return modelPtr_->solver()->getRowActivity();
610 return modelPtr_->solver()->getObjValue();
617 modelPtr_->solver()->setObjCoeff(elementIndex,elementValue);
625 modelPtr_->solver()->setColLower(elementIndex,elementValue);
633 modelPtr_->solver()->setColUpper(elementIndex,elementValue);
639 double lower,
double upper )
641 modelPtr_->solver()->setColBounds(elementIndex,lower,upper);
644 const int* indexLast,
645 const double* boundList)
647 modelPtr_->solver()->setColSetBounds(indexFirst,indexLast,boundList);
654 modelPtr_->solver()->setRowLower(elementIndex,elementValue);
661 modelPtr_->solver()->setRowUpper(elementIndex,elementValue);
667 double lower,
double upper ) {
668 modelPtr_->solver()->setRowBounds(elementIndex,lower,upper);
675 modelPtr_->solver()->setRowType(i,sense,rightHandSide,range);
679 const int* indexLast,
680 const double* boundList)
682 modelPtr_->solver()->setRowSetBounds(indexFirst,indexLast,boundList);
687 const int* indexLast,
688 const char* senseList,
689 const double* rhsList,
690 const double* rangeList)
692 modelPtr_->solver()->setRowSetTypes(indexFirst,indexLast,senseList,rhsList,rangeList);
697 OsiHintStrength strength,
698 void * otherInformation)
700 return modelPtr_->solver()->setHintParam(key,yesNo, strength, otherInformation);
706 OsiHintStrength & strength,
707 void *& otherInformation)
const 709 return modelPtr_->solver()->getHintParam(key,yesNo, strength, otherInformation);
715 OsiHintStrength & strength)
const 717 return modelPtr_->solver()->getHintParam(key,yesNo, strength);
724 return modelPtr_->solver()->getNumCols();
729 return modelPtr_->solver()->getNumRows();
734 return modelPtr_->solver()->getNumElements();
739 return modelPtr_->solver()->getColLower();
744 return modelPtr_->solver()->getColUpper();
749 return modelPtr_->solver()->getRowLower();
754 return modelPtr_->solver()->getRowUpper();
759 return modelPtr_->solver()->getObjCoefficients();
764 return modelPtr_->solver()->getObjSense();
769 return modelPtr_->solver()->getInfinity();
774 return modelPtr_->solver()->getIterationCount();
785 *messageHandler() <<
"Warning: Use of OsiCbc is deprecated." << CoinMessageEol;
786 *messageHandler() <<
"To enjoy the full performance of Cbc, use the CbcSolver interface." << CoinMessageEol;
801 return (
modelPtr_->solver()->dfltRowColName(rc,ndx,digits)) ;
806 return (
modelPtr_->solver()->getObjName(maxLen)) ;
811 return (
modelPtr_->solver()->getRowName(ndx,maxLen)) ;
816 return (
modelPtr_->solver()->getRowNames()) ;
821 return (
modelPtr_->solver()->getColName(ndx,maxLen)) ;
826 return (
modelPtr_->solver()->getColNames()) ;
830 int srcStart,
int len,
int tgtStart)
832 modelPtr_->solver()->setRowNames(srcNames,srcStart,len,tgtStart) ;
837 modelPtr_->solver()->deleteRowNames(tgtStart,len) ;
841 int srcStart,
int len,
int tgtStart)
843 modelPtr_->solver()->setColNames(srcNames,srcStart,len,tgtStart) ;
848 modelPtr_->solver()->deleteColNames(tgtStart,len) ;
869 modelPtr_->solver()->setRowName(ndx,name) ;
878 modelPtr_->solver()->setColName(ndx,name) ;
884 OsiSolverInterface::passInMessageHandler(handler);
886 modelPtr_->passInMessageHandler(handler);
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
virtual void setObjName(std::string name)
Set the name of the objective function.
virtual void applyRowCuts(int numberCuts, const OsiRowCut *cuts)
Apply a collection of row cuts which are all effective.
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound Use DBL_MAX for infinity.
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver...
virtual void resolve()
Resolve an LP relaxation after problem modification.
#define OSICBC_DFLT_SOLVER
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -DBL_MAX for -infinity.
CbcModel * modelPtr_
Cbc model represented by this class instance.
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 addRows(const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub)
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual void deleteCols(const int num, const int *colIndices)
virtual void markHotStart()
Create a hotstart point of the optimization process.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
virtual bool setHintParam(OsiHintParam key, bool yesNo=true, OsiHintStrength strength=OsiHintTry, void *otherInformation=NULL)
bool getIntParam(OsiIntParam key, int &value) const
virtual void initialSolve()
Solve initial LP relaxation.
virtual void setColBounds(int elementIndex, double lower, double upper)
Set a single column lower and upper bound.
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
virtual void passInMessageHandler(CoinMessageHandler *handler)
Pass in a message handler.
virtual void setRowPrice(const double *rowprice)
Set dual solution vector.
virtual std::string getRowName(int rowIndex, unsigned maxLen=std::string::npos) const
Return the name of the row.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row
virtual std::vector< double * > getDualRays(int maxNumRays) const
Get as many dual rays as the solver can provide.
std::string name(int nuc)
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual bool isPrimalObjectiveLimitReached() const
Is the given primal objective limit reached?
virtual bool getHintParam(OsiHintParam key, bool &yesNo, OsiHintStrength &strength, void *&otherInformation) const
Get a hint parameter.
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
virtual double getInfinity() const
Get solver's value for infinity.
virtual std::string getObjName(unsigned maxLen=std::string::npos) const
Return the name of the objective function.
virtual const OsiNameVec & getRowNames()
Return a pointer to a vector of row names.
virtual void deleteRowNames(int tgtStart, int len)
Delete len row names starting at index tgtStart.
bool getDblParam(OsiDblParam key, double &value) const
bool getStrParam(OsiStrParam key, std::string &value) const
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...
virtual int getNumElements() const
Get number of nonzero elements.
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut (append to constraint matrix).
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 setColNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple column names.
virtual int getNumRows() const
Get number of rows.
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (adjust one or more bounds).
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
virtual ~OsiCbcSolverInterface()
Destructor.
bool setStrParam(OsiStrParam key, const std::string &value)
virtual void solveFromHotStart()
Optimize starting from the hotstart.
virtual bool isAbandoned() const
Are there a numerical difficulties?
virtual void deleteColNames(int tgtStart, int len)
Delete len column names starting at index tgtStart.
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...
OsiCbcSolverInterface(OsiSolverInterface *solver=NULL, CbcStrategy *strategy=NULL)
Default Constructor.
virtual double getObjValue() const
Get objective function value.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
virtual void branchAndBound()
Invoke solver's built-in enumeration algorithm.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
virtual void setColSolution(const double *colsol)
Set the primal solution column values.
static std::string digits
string of digit characters
virtual const OsiNameVec & getColNames()
Return a pointer to a vector of column names.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound Use -DBL_MAX for -infinity.
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 setRowBounds(int elementIndex, double lower, double upper)
Set a single row lower and upper bound.
virtual void deleteRows(const int num, const int *rowIndices)
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual void addCols(const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj)
virtual std::string dfltRowColName(char rc, int ndx, unsigned digits=7) const
Generate a standard name of the form Rnnnnnnn or Cnnnnnnn.
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 void setRowNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple row names.
virtual void setRowName(int ndx, std::string name)
Set a row name.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound Use DBL_MAX for infinity.
virtual int getNumCols() const
Get number of columns.
bool setIntParam(OsiIntParam key, int value)
virtual void unmarkHotStart()
Delete the snapshot.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
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 void setColName(int ndx, std::string name)
Set a column name.
virtual bool isIterationLimitReached() const
Iteration limit reached?
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
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 char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface &rhs)
Assignment operator.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
bool setDblParam(OsiDblParam key, double value)
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.