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 agentPtr_->solver()->setIntParam(key,value);;
75 return agentPtr_->solver()->setDblParam(key,value);
83 return agentPtr_->solver()->setStrParam(key,value);
92 return agentPtr_->solver()->getIntParam(key,value);
100 return agentPtr_->solver()->getDblParam(key,value);
108 if ( key==OsiSolverName ) {
110 agentPtr_->solver()->getStrParam(key,value2);
111 value =
"cbc"+value2;
114 return agentPtr_->solver()->getStrParam(key,value);
124 return agentPtr_->solver()->isAbandoned();
129 return agentPtr_->solver()->isProvenOptimal();
134 return agentPtr_->solver()->isProvenPrimalInfeasible();
139 return agentPtr_->solver()->isProvenDualInfeasible();
143 return agentPtr_->solver()->isPrimalObjectiveLimitReached();
148 return agentPtr_->solver()->isDualObjectiveLimitReached();
153 return agentPtr_->solver()->isIterationLimitReached();
161 return agentPtr_->solver()->getEmptyWarmStart();
166 return agentPtr_->solver()->getWarmStart();
173 return agentPtr_->solver()->setWarmStart(warmstart);
187 agentPtr_->solver()->solveFromHotStart();
202 return agentPtr_->solver()->getRowSense();
207 return agentPtr_->solver()->getRightHandSide();
212 return agentPtr_->solver()->getRowRange();
219 return agentPtr_->solver()->isContinuous(colNumber);
228 return agentPtr_->solver()->getMatrixByRow();
233 return agentPtr_->solver()->getMatrixByCol();
239 return agentPtr_->solver()->getDualRays(maxNumRays);
244 return agentPtr_->solver()->getPrimalRays(maxNumRays);
250 agentPtr_->solver()->setContinuous(index);
262 agentPtr_->solver()->setContinuous(indices,len);
268 agentPtr_->solver()->setInteger(indices,len);
286 const double collb,
const double colub,
289 agentPtr_->solver()->addCol(vec,collb,colub,obj);
294 const double collb,
const double colub,
297 agentPtr_->solver()->addCol(numberElements, rows, elements,
303 const CoinPackedVectorBase *
const * cols,
304 const double* collb,
const double* colub,
307 agentPtr_->solver()->addCols(numcols,cols,collb,colub,obj);
313 agentPtr_->solver()->deleteCols(num,columnIndices);
318 const double rowlb,
const double rowub)
320 agentPtr_->solver()->addRow(vec,rowlb,rowub);
325 const char rowsen,
const double rowrhs,
328 agentPtr_->solver()->addRow(vec,rowsen,rowrhs,rowrng);
333 const CoinPackedVectorBase *
const * rows,
334 const double* rowlb,
const double* rowub)
336 agentPtr_->solver()->addRows(numrows,rows,rowlb,rowub);
341 const CoinPackedVectorBase *
const * rows,
342 const char* rowsen,
const double* rowrhs,
343 const double* rowrng)
345 agentPtr_->solver()->addRows(numrows,rows,rowsen,rowrhs,rowrng);
351 agentPtr_->solver()->deleteRows(num,rowIndices);
360 const double* collb,
const double* colub,
362 const double* rowlb,
const double* rowub)
364 agentPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowlb,rowub);
371 double*& collb,
double*& colub,
373 double*& rowlb,
double*& rowub)
375 agentPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowlb,rowub);
382 const double* collb,
const double* colub,
384 const char* rowsen,
const double* rowrhs,
385 const double* rowrng)
387 agentPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
394 double*& collb,
double*& colub,
396 char*& rowsen,
double*& rowrhs,
399 agentPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
406 const CoinBigIndex * start,
const int* index,
408 const double* collb,
const double* colub,
410 const double* rowlb,
const double* rowub)
412 agentPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
413 collb,colub,obj,rowlb,rowub);
419 const CoinBigIndex * start,
const int* index,
421 const double* collb,
const double* colub,
423 const char* rowsen,
const double* rowrhs,
424 const double* rowrng)
426 agentPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
427 collb,colub,obj,rowsen,rowrhs,rowrng);
435 const char * extension,
436 double objSense)
const 438 agentPtr_->solver()->writeMps(filename,extension,objSense);
443 const char ** rowNames,
const char ** columnNames,
444 int formatType,
int numberAcross,
double objSense)
const 446 return agentPtr_->solver()->writeMpsNative(filename, rowNames, columnNames,
447 formatType, numberAcross,objSense);
457 CbcStrategy * strategy)
470 CbcStrategyDefault defaultStrategy;
494 OsiSolverInterface(rhs)
516 OsiSolverInterface::operator=(rhs);
529 agentPtr_->solver()->applyRowCuts(1,&rowCut);
537 agentPtr_->solver()->applyRowCuts(numberCuts,cuts);
545 agentPtr_->solver()->applyRowCuts(numberCuts, cuts);
551 const double * lower =
agentPtr_->solver()->getColLower();
552 const double * upper =
agentPtr_->solver()->getColUpper();
553 const CoinPackedVector & lbs = cc.lbs();
554 const CoinPackedVector & ubs = cc.ubs();
557 for ( i=0; i<lbs.getNumElements(); i++ ) {
558 int iCol = lbs.getIndices()[i];
559 double value = lbs.getElements()[i];
560 if ( value > lower[iCol] )
561 agentPtr_->solver()->setColLower(iCol, value);
563 for ( i=0; i<ubs.getNumElements(); i++ ) {
564 int iCol = ubs.getIndices()[i];
565 double value = ubs.getElements()[i];
566 if ( value < upper[iCol] )
567 agentPtr_->solver()->setColUpper(iCol, value);
574 const char *extension )
576 return agentPtr_->solver()->readMps(filename,extension);
582 return agentPtr_->solver()->getColSolution();
589 return agentPtr_->solver()->getRowPrice();
596 return agentPtr_->solver()->getReducedCost();
604 return agentPtr_->solver()->getRowActivity();
609 return agentPtr_->solver()->getObjValue();
616 agentPtr_->solver()->setObjCoeff(elementIndex,elementValue);
624 agentPtr_->solver()->setColLower(elementIndex,elementValue);
632 agentPtr_->solver()->setColUpper(elementIndex,elementValue);
638 double lower,
double upper )
640 agentPtr_->solver()->setColBounds(elementIndex,lower,upper);
643 const int* indexLast,
644 const double* boundList)
646 agentPtr_->solver()->setColSetBounds(indexFirst,indexLast,boundList);
653 agentPtr_->solver()->setRowLower(elementIndex,elementValue);
660 agentPtr_->solver()->setRowUpper(elementIndex,elementValue);
666 double lower,
double upper ) {
667 agentPtr_->solver()->setRowBounds(elementIndex,lower,upper);
674 agentPtr_->solver()->setRowType(i,sense,rightHandSide,range);
678 const int* indexLast,
679 const double* boundList)
681 agentPtr_->solver()->setRowSetBounds(indexFirst,indexLast,boundList);
686 const int* indexLast,
687 const char* senseList,
688 const double* rhsList,
689 const double* rangeList)
691 agentPtr_->solver()->setRowSetTypes(indexFirst,indexLast,senseList,rhsList,rangeList);
696 OsiHintStrength strength,
697 void * otherInformation)
699 return agentPtr_->solver()->setHintParam(key,yesNo, strength, otherInformation);
705 OsiHintStrength & strength,
706 void *& otherInformation)
const 708 return agentPtr_->solver()->getHintParam(key,yesNo, strength, otherInformation);
714 OsiHintStrength & strength)
const 716 return agentPtr_->solver()->getHintParam(key,yesNo, strength);
723 return agentPtr_->solver()->getNumCols();
728 return agentPtr_->solver()->getNumRows();
733 return agentPtr_->solver()->getNumElements();
738 return agentPtr_->solver()->getColLower();
743 return agentPtr_->solver()->getColUpper();
748 return agentPtr_->solver()->getRowLower();
753 return agentPtr_->solver()->getRowUpper();
758 return agentPtr_->solver()->getObjCoefficients();
763 return agentPtr_->solver()->getObjSense();
768 return agentPtr_->solver()->getInfinity();
773 return agentPtr_->solver()->getIterationCount();
784 *messageHandler() <<
"Warning: Use of OsiCbc is deprecated." << CoinMessageEol;
785 *messageHandler() <<
"To enjoy the full performance of Cbc, use the CbcSolver interface." << CoinMessageEol;
800 return (
agentPtr_->solver()->dfltRowColName(rc,ndx,digits)) ;
805 return (
agentPtr_->solver()->getObjName(maxLen)) ;
810 return (
agentPtr_->solver()->getRowName(ndx,maxLen)) ;
815 return (
agentPtr_->solver()->getRowNames()) ;
820 return (
agentPtr_->solver()->getColName(ndx,maxLen)) ;
825 return (
agentPtr_->solver()->getColNames()) ;
829 int srcStart,
int len,
int tgtStart)
831 agentPtr_->solver()->setRowNames(srcNames,srcStart,len,tgtStart) ;
836 agentPtr_->solver()->deleteRowNames(tgtStart,len) ;
840 int srcStart,
int len,
int tgtStart)
842 agentPtr_->solver()->setColNames(srcNames,srcStart,len,tgtStart) ;
847 agentPtr_->solver()->deleteColNames(tgtStart,len) ;
868 agentPtr_->solver()->setRowName(ndx,name) ;
877 agentPtr_->solver()->setColName(ndx,name) ;
883 OsiSolverInterface::passInMessageHandler(handler);
885 agentPtr_->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.
CbcModel * agentPtr_
Cbc agent represented by this class instance.
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -DBL_MAX for -infinity.
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.
#define OSICBC_DFLT_SOLVER
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.