diff --git a/src/main/native/javacbc.cpp b/src/main/native/javacbc.cpp index 2aad218c406ff44636c38eb2b896e6d1ba6fe47d..e3fe37af684402f7504a80a4ea19897720914654 100644 --- a/src/main/native/javacbc.cpp +++ b/src/main/native/javacbc.cpp @@ -16,8 +16,6 @@ using namespace std; #include "CbcModel.hpp" #include "CbcStrategy.hpp" #include "OsiClpSolverInterface.hpp" -// Preprocessing -#include "CglPreProcess.hpp" #include "CoinTime.hpp" #include "javacbc.hpp" @@ -27,29 +25,7 @@ using namespace std; // Included for solver #include "CbcOrClpParam.hpp" -CoinPackedMatrix CPM(int numberRows, int numberColumns, int numberElements, int *startint, int nbelems, int *length, int *rows, double *elements){ - if(nbelems>0){ - CoinBigIndex *start; - start = new CoinBigIndex[nbelems]; - int i=0; - for(i=0;i0){ - CoinPackedMatrix matrix(true,rowIndices,colIndices,elements,nbelems); - return matrix; - } - CoinPackedMatrix matrix; - return matrix; -} // Solve initial LP relaxation. void initialSolve(OsiClpSolverInterface& solver){ @@ -58,49 +34,25 @@ void initialSolve(OsiClpSolverInterface& solver){ std::cout.flush(); } -// Solve initial LP relaxation. -void initialSolve(OsiSolverInterface& solver){ - solver.initialSolve(); - // Flush the stdout. - std::cout.flush(); -} - void setInt(OsiClpSolverInterface& solver, int i){ solver.setInteger(i); } -// Default Constructor. +// Default Constructor. OsiClpSolverInterface* newOsiClpSolverInterface(){ return new OsiClpSolverInterface(); } -// Copy constructor. -OsiClpSolverInterface* newOsiClpSolverInterface(OsiClpSolverInterface & s){ - return new OsiClpSolverInterface(s); -} - // Delete OsiClpSolverInterface void deleteOsiClpSolverInterface(OsiClpSolverInterface* solver) { delete solver; } -CoinBigIndex CBI(int start[]){ - int length = sizeof(start)/sizeof(int); - CoinBigIndex cbi[length]; - for(int i=0;i getDualRays(OsiClpSolverInterface& osi, int maxNumRays){ // Get as many dual rays as the solver can provide. - return osi.getDualRays(maxNumRays); -} -std::vector< double * > getPrimalRays(OsiClpSolverInterface& osi, int maxNumRays){ // Get as many primal rays as the solver can provide. - return osi.getPrimalRays(maxNumRays); -} - - //Changing bounds on variables and constraints void setObjCoeff(OsiClpSolverInterface& osi, int elementIndex, double elementValue){// Set an objective function setObjCoeff. @@ -383,36 +207,15 @@ void setColUpper(OsiClpSolverInterface& osi, int elementIndex, double elementVal void setColBounds(OsiClpSolverInterface& osi, int elementIndex, double lower, double upper){// Set a single column lower and upper bound. osi.setColBounds(elementIndex,lower,upper); } -void setColSetBounds(OsiClpSolverInterface& osi, const int *indexFirst, const int *indexLast, const double *boundList){// Set the bounds on a number of columns simultaneously, The default implementation just invokes setColLower() and setColUpper() over and over again. - osi.setColSetBounds(indexFirst,indexLast,boundList); -} void setRowLower(OsiClpSolverInterface& osi, int elementIndex, double elementValue){// Set a single row lower bound, Use -DBL_MAX for -infinity. osi.setRowLower(elementIndex,elementValue); } void setRowUpper(OsiClpSolverInterface& osi, int elementIndex, double elementValue){// Set a single row upper bound, Use DBL_MAX for infinity. osi.setRowUpper(elementIndex,elementValue); } -void setRowBounds(OsiClpSolverInterface& osi, int elementIndex, double lower, double upper){// Set a single row lower and upper bound. - osi.setRowBounds(elementIndex,lower,upper); -} -void setRowType(OsiClpSolverInterface& osi, int index, char sense, double rightHandSide, double range){// Set the type of a single row. - osi.setRowType(index,sense,rightHandSide,range); -} -void setRowSetBounds(OsiClpSolverInterface& osi, const int *indexFirst, const int *indexLast, const double *boundList){// Set the bounds on a number of rows simultaneously. The default implementation just invokes setRowLower() and setRowUpper() over and over again. - osi.setRowSetBounds(indexFirst,indexLast,boundList); -} -void setRowSetTypes(OsiClpSolverInterface& osi, 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() over and over again. - osi.setRowSetTypes(indexFirst,indexLast,senseList,rhsList,rangeList); -} void setObjective(OsiClpSolverInterface& osi, const double *array){// Set the objective coefficients for all columns array [getNumCols()] is an array of values for the objective. osi.setObjective(array); } -void setColLower(OsiClpSolverInterface& osi, const double *array){// Set the lower bounds for all columns array [getNumCols()] is an array of values for the objective. - osi.setColLower(array); -} -void setColUpper(OsiClpSolverInterface& osi, const double *array){// Set the upper bounds for all columns array [getNumCols()] is an array of values for the objective. - osi.setColUpper(array); -} void setRowName(OsiClpSolverInterface& osi, int rowIndex, std::string name){// Set name of row. osi.setRowName(rowIndex,name); } @@ -428,187 +231,51 @@ void setContinuous(OsiClpSolverInterface& osi, int index){// Set the index-th va void setInteger(OsiClpSolverInterface& osi, int index){// Set the index-th variable to be an integer variable. osi.setInteger(index); } -void setContinuous(OsiClpSolverInterface& osi, const int *indices, int len){// Set the variables listed in indices (which is of length len) to be continuous variables. - osi.setContinuous(indices,len); -} -void setInteger(OsiClpSolverInterface& osi, const int *indices, int len){// Set the variables listed in indices (which is of length len) to be integer variables. - osi.setInteger(indices,len); -} - - /*Methods to expand a problem. Note that if a column is added then by default it will correspond to a continuous variable. */ -void addCol(OsiClpSolverInterface& osi, const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj){// Add a column (primal variable) to the problem. - osi.addCol(vec,collb,colub,obj); -} void addCol(OsiClpSolverInterface& osi, int numberElements, const int *rows, const double *elements, const double collb, const double colub, const double obj){// Add a column (primal variable) to the problem. osi.addCol(numberElements,rows,elements,collb,colub,obj); } -void addCols(OsiClpSolverInterface& osi, const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj){// Add a set of columns (primal variables) to the problem. - osi.addCols (numcols,cols,collb,colub,obj); -} -void addCols(OsiClpSolverInterface& osi, const int numcols, const int *columnStarts, const int *rows, const double *elements, const double *collb, const double *colub, const double *obj){// Add a set of columns (primal variables) to the problem. - osi.addCols (numcols,columnStarts,rows,elements,collb,colub,obj); -} void deleteCols(OsiClpSolverInterface& osi, const int num, const int *colIndices){// Remove a set of columns (primal variables) from the problem. osi.deleteCols(num,colIndices); } -void addRow(OsiClpSolverInterface& osi, const CoinPackedVectorBase &vec, const double rowlb, const double rowub){// Add a row (constraint) to the problem. - osi.addRow(vec,rowlb,rowub); -} -void addRow(OsiClpSolverInterface& osi, const CoinPackedVectorBase &vec, const char rowsen, const double rowrhs, const double rowrng){// Add a row (constraint) to the problem. - osi.addRow(vec,rowsen,rowrhs,rowrng); -} void addRow(OsiClpSolverInterface& osi, int numberElements, const int *columns, const double *element, const double rowlb, const double rowub){// Add a row (constraint) to the problem. osi.addRow(numberElements,columns,element,rowlb,rowub); } -void addRows(OsiClpSolverInterface& osi, const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub){ - osi.addRows(numrows,rows,rowlb,rowub); -} -void addRows(OsiClpSolverInterface& osi, const int numrows, const CoinPackedVectorBase *const *rows, const char *rowsen, const double *rowrhs, const double *rowrng){// Add a set of rows (constraints) to the problem. - osi.addRows(numrows,rows,rowsen,rowrhs,rowrng); -} -void addRows(OsiClpSolverInterface& osi, const int numrows, const int *rowStarts, const int *columns, const double *element, const double *rowlb, const double *rowub){// Add a set of rows (constraints) to the problem. - osi.addRows(numrows,rowStarts,columns,element,rowlb,rowub); -} void modifyCoefficient(OsiClpSolverInterface& osi, int row, int column, double newElement, bool keepZero){ osi.modifyCoefficient(row,column,newElement,keepZero); } void deleteRows(OsiClpSolverInterface& osi, const int num, const int *rowIndices){// Delete a set of rows (constraints) from the problem. osi.deleteRows(num,rowIndices); } -void saveBaseModel(OsiClpSolverInterface& osi){// If solver wants it can save a copy of "base" (continuous) model here. - osi.saveBaseModel(); -} -void restoreBaseModel(OsiClpSolverInterface& osi, int numberRows){// Strip off rows to get to this number of rows. - osi.restoreBaseModel(numberRows); -} -void applyRowCuts(OsiClpSolverInterface& osi, int numberCuts, const OsiRowCut *cuts){// Apply a collection of row cuts which are all effective. - osi.applyRowCuts(numberCuts,cuts); -} -void applyRowCuts(OsiClpSolverInterface& osi, int numberCuts, const OsiRowCut **cuts){// Apply a collection of row cuts which are all effective. - osi.applyRowCuts(numberCuts,cuts); -} - - //Methods to input a problem -void loadProblem(OsiClpSolverInterface& osi, 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 bounds). - osi.loadProblem(matrix,collb,colub,obj,rowlb,rowub); -} -void assignProblem(OsiClpSolverInterface& osi, 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 lower and upper bounds). - osi.assignProblem(matrix,collb,colub,obj,rowlb,rowub); -} -void loadProblem(OsiClpSolverInterface& osi, const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng){// Load in an problem by copying the arguments (the constraints on the rows are given by sense/rhs/range triplets). - osi.loadProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng); -} -void assignProblem(OsiClpSolverInterface& osi, CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, char *&rowsen, double *&rowrhs, double *&rowrng){// Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by sense/rhs/range triplets). - osi.assignProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng); -} -void loadProblem(OsiClpSolverInterface& osi, const int numcols, const int numrows, const CoinBigIndex *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub){// Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). - osi.loadProblem(numcols,numrows,start,index,value,collb,colub,obj,rowlb,rowub); -} -void loadProblem(OsiClpSolverInterface& osi, const int numcols, const int numrows, const CoinBigIndex *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng){// Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). - osi.loadProblem(numcols,numrows,start,index,value,collb,colub,obj,rowsen,rowrhs,rowrng); -} -int loadFromCoinModel(OsiClpSolverInterface& osi, CoinModel &modelObject, bool keepSolution){// This loads a model from a coinModel object - returns number of errors. - osi.loadFromCoinModel(modelObject,keepSolution); -} -int readMps(OsiClpSolverInterface& osi, const char *filename, const char *extension){// Read an mps file from the given filename (defaults to Osi reader) - returns number of errors (see OsiMpsReader class). - osi.readMps(filename,extension); -} -int readMps(OsiClpSolverInterface& osi, const char *filename, bool keepNames, bool allowErrors){// Read an mps file from the given filename returns number of errors (see OsiMpsReader class). - osi.readMps(filename,keepNames,allowErrors); -} -void writeMps(OsiClpSolverInterface& osi, const char *filename, const char *extension, double objSense){// Write the problem into an mps file of the given filename. - osi.writeMps(filename,extension,objSense); -} -int writeMpsNative(OsiClpSolverInterface& osi, const char *filename, const char **rowNames, const char **columnNames, int formatType, int numberAcross, double objSense){// Write the problem into an mps file of the given filename, names may be null. - osi.writeMpsNative(filename,rowNames,columnNames,formatType,numberAcross,objSense); -} int readLp(OsiClpSolverInterface& osi, const char *filename, const double epsilon){// Read file in LP format (with names). osi.readLp(filename,epsilon); } void writeLp(OsiClpSolverInterface& osi, const char *filename, const char *extension, double epsilon, int numberAcross, int decimals, double objSense, bool useRowNames){// Write the problem into an Lp file of the given filename. osi.writeLp(filename,extension,epsilon,numberAcross,decimals,objSense,useRowNames); } -void writeLp(OsiClpSolverInterface& osi, FILE *fp, double epsilon, int numberAcross, int decimals, double objSense, bool useRowNames){// Write the problem into the file pointed to by the parameter fp. - osi.writeLp(fp,epsilon,numberAcross,decimals,objSense,useRowNames); -} - -// Create a new pre-processor -CglPreProcess* newCglPreProcess() { - return new CglPreProcess(); -} - -// Delete the pre-processor -void deleteCglPreProcess(CglPreProcess* p) { - delete p; -} - -// Run the preprocessor -OsiSolverInterface* preProcess(CglPreProcess& p, OsiClpSolverInterface& osi, bool makeEquality, int numberPasses) { - OsiSolverInterface* o = p.preProcess(osi,makeEquality, numberPasses); - // Flush the stdout. - std::cout.flush(); - return o; -} - -// Create solution in original model -void postProcess(CglPreProcess& p, OsiSolverInterface& osi) { - p.postProcess(osi); - // Flush the stdout. - std::cout.flush(); -} // Resolve an LP relaxation after problem modification. void resolve(OsiSolverInterface& osi) { osi.resolve(); } -// Returns solver - has current state. +// Returns solver - has current state. OsiClpSolverInterface* solver(CbcModel& m) { OsiSolverInterface *solver = m.solver(); return dynamic_cast(solver); } - -// Create a new CbcHeuristicFPump -CbcHeuristicFPump* newCbcHeuristicFPump() { - return new CbcHeuristicFPump(); -} -// Create a new CbcHeuristicFPump -CbcHeuristicFPump* newCbcHeuristicFPump(CbcModel& m, double downValue, bool roundExpensive) { - return new CbcHeuristicFPump(m, downValue, roundExpensive); -} -// Delete CbcHeuristicFPump -void deleteCbcHeuristicFPump(CbcHeuristicFPump * h) { - delete h; -} -// Add one heuristic - up to user to delete. -void addHeuristic(CbcModel& m, CbcHeuristicFPump* h) { - m.addHeuristic(h); -} -// Delete OsiSolverInterface -void deleteOsiSolverInterface(OsiSolverInterface* s) { - delete s; -} -// Set current log (detail) level. -void setLogLevel(CglPreProcess& p, int n) { - p.messageHandler()->setLogLevel(n); -} -// Set current log (detail) level. -void setLogLevel(OsiSolverInterface& s, int n) { - s.messageHandler()->setLogLevel(n); -} // Set current log (detail) level. void setLogLevel(OsiClpSolverInterface& s, int n) { s.messageHandler()->setLogLevel(n); } -// Get pointer to array[getNumCols()] of objective function coefficients. +// Get pointer to array[getNumCols()] of objective function coefficients. const double* getObjCoefficients(OsiClpSolverInterface& osi) { return osi.getObjCoefficients(); } @@ -659,43 +326,36 @@ double getObjValue(OsiSolverInterface& c) { } // Get pointer to array[getNumCols()] of primal solution vector. -double getColSolution(OsiSolverInterface& osi, int colIndex){ +double getColSolution(OsiSolverInterface& osi, int colIndex){ return osi.getColSolution()[colIndex]; } +double bestSolution(CbcModel& c, int colIndex){ +return c.bestSolution()[colIndex]; +} + // Simple method to solve the model with default settings. void solve(CbcModel &model) { int logLevel = 0; - bool preProcess = true; // Reduce printout model.setLogLevel(logLevel); model.messageHandler()->setLogLevel(logLevel); model.solver()->messageHandler()->setLogLevel(logLevel); - if (logLevel <= 1) { model.solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry); - } else { - model.solver()->setHintParam(OsiDoReducePrint, false, OsiHintTry); - } - + // TODO initialSolve on Clp - + model.initialSolve(); - + // Could tune more double objValue = model.solver()->getObjSense() * model.solver()->getObjValue(); double minimumDropA=CoinMin(1.0,fabs(objValue)*1.0e-3+1.0e-4); double minimumDrop= fabs(objValue)*1.0e-4+1.0e-4; model.setMinimumDrop(minimumDrop); - if (model.getNumCols()<500) - model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible - else if (model.getNumCols()<5000) - model.setMaximumCutPassesAtRoot(100); // use minimum drop - else - model.setMaximumCutPassesAtRoot(20); - model.setMaximumCutPasses(10); + // Switch off strong branching if wanted // model.setNumberStrong(0); @@ -708,20 +368,15 @@ void solve(CbcModel &model) { model.setNumberBeforeTrust(5); model.solver()->setIntParam(OsiMaxNumIterationHotStart,100); - + // Default strategy will leave cut generators as they exist already // so cutsOnlyAtRoot (1) ignored // numberStrong (2) is 5 (default) // numberBeforeTrust (3) is 5 (default is 0) // printLevel (4) defaults (0) - CbcStrategyDefault strategy(true,5,5); - // Set up pre-processing to find sos if wanted - if (preProcess) { - strategy.setupPreProcessing(2); - model.setStrategy(strategy); - } - + CbcStrategyDefault strategy(true,0,0); + // Do complete search model.branchAndBound(); - + } diff --git a/src/main/native/javacbc.hpp b/src/main/native/javacbc.hpp index fcaff8d9bbccda52d4dbf73abf0a4e2b1d04052f..bc63b35d0768fa3a4d7574e9d8712381dc640423 100644 --- a/src/main/native/javacbc.hpp +++ b/src/main/native/javacbc.hpp @@ -9,58 +9,34 @@ using namespace std; #include "CbcModel.hpp" #include "CbcStrategy.hpp" #include "OsiClpSolverInterface.hpp" -// Preprocessing -#include "CglPreProcess.hpp" + #include "CoinTime.hpp" #include "CbcHeuristicFPump.hpp" // Solve initial LP relaxation. void initialSolve(OsiClpSolverInterface& solver); -// Solve initial LP relaxation. -void initialSolve(OsiSolverInterface& solver); - void setInt(OsiClpSolverInterface& solver, int i); -// Default Constructor. +// Default Constructor. OsiClpSolverInterface* newOsiClpSolverInterface(); -// Copy constructor. -OsiClpSolverInterface* newOsiClpSolverInterface(OsiClpSolverInterface & s); - // Delete OsiClpSolverInterface void deleteOsiClpSolverInterface(OsiClpSolverInterface* solver); -CoinBigIndex CBI(int start[]); - -CoinPackedMatrix CPM(int numberRows, int numberColumns, int numberElements, int *startint, int nbelems, int *length, int *rows, double *elements); -CoinPackedMatrix CPM(int *rowIndices, int *colIndices, double *elements, int nbelems); - // Create a new instance of CbcModel CbcModel* newCbcModel(OsiClpSolverInterface& s); -// Create a new instance of CbcModel -CbcModel* newCbcModel(OsiSolverInterface& s); void deleteCbcModel(CbcModel* c); void initialSolve(CbcModel& c); void branchAndBound(CbcModel& c, int doStatistics = 0); int status(CbcModel& c); -int secondaryStatus(CbcModel& c); bool isProvenOptimal(CbcModel& c); bool isProvenInfeasible(CbcModel& c); -bool isContinuousUnbounded(CbcModel& c); -bool isNodeLimitReached(CbcModel& c); -bool isSecondsLimitReached(CbcModel& c); int getNumCols(CbcModel& c); int getNumRows(CbcModel& c) ; -CoinBigIndex getNumElements (CbcModel& c); -int numberIntegers(CbcModel& c) ; -char integerType(CbcModel& c, int i); double getColLower(CbcModel& c, int colIndex); double getColUpper(CbcModel& c, int colIndex); -const char* getRowSense(CbcModel& c); -double getRightHandSide(CbcModel& c, int rowIndex); -double getRowRange(CbcModel& c, int rowIndex); double getRowLower(CbcModel& c, int rowIndex); double getRowUpper(CbcModel& c, int rowIndex); double getObjCoefficients(CbcModel& c, int colIndex); @@ -69,46 +45,26 @@ void setObjSense(CbcModel& c, double s); bool isContinuous(CbcModel& c, int colIndex); bool isBinary(CbcModel& c, int colIndex); bool isInteger(CbcModel& c, int colIndex); -bool isIntegerNonBinary(CbcModel& c, int colIndex); -bool isFreeBinary(CbcModel& c, int colIndex); -const CoinPackedMatrix* getMatrixByRow(CbcModel& c); const CoinPackedMatrix* getMatrixByCol(CbcModel& c); double getInfinity(CbcModel& c); -double getCbcColLower(CbcModel& c, int colIndex); -double getCbcColUpper(CbcModel& c, int colIndex); double getCbcRowLower(CbcModel& c, int rowIndex); double getCbcRowUpper(CbcModel& c, int rowIndex); double getCbcColSolution(CbcModel& c, int colIndex); -double getCbcRowPrice(CbcModel& c, int colIndex); double getObjValue(CbcModel& c); -double bestSolution(CbcModel& c, int colIndex); -int getNumberThreads(CbcModel& c); -void setNumberThreads(CbcModel& c, int value); void setLogLevel(CbcModel& c, int n); -double getCurrentObjValue(CbcModel& c); //OsiClpInterface proxy methods //Methods returning info on how the solution process terminated -bool isAbandoned(OsiClpSolverInterface& osi); //Are there a numerical difficulties? bool isProvenOptimal(OsiClpSolverInterface& osi); //Is optimality proven? -bool isProvenPrimalInfeasible(OsiClpSolverInterface& osi);// Is primal infeasiblity proven? -bool isProvenDualInfeasible(OsiClpSolverInterface& osi);// Is dual infeasiblity proven? -bool isPrimalObjectiveLimitReached(OsiClpSolverInterface& osi);// Is the given primal objective limit reached? -bool isDualObjectiveLimitReached(OsiClpSolverInterface& osi);// Is the given dual objective limit reached? -bool isIterationLimitReached(OsiClpSolverInterface& osi);// Iteration limit reached? //Methods related to querying the input data int getNumCols(OsiClpSolverInterface& osi);// Get number of columns. int getNumRows(OsiClpSolverInterface& osi);// Get number of rows. -int getNumElements(OsiClpSolverInterface& osi);// Get number of nonzero elements. std::string getRowName(OsiClpSolverInterface& osi, int rowIndex, unsigned maxLen=std::string::npos);// Return name of row if one exists or Rnnnnnnn maxLen is currently ignored and only there to match the signature from the base class! std::string getColName(OsiClpSolverInterface& osi, int colIndex, unsigned maxLen=std::string::npos);// Return name of column if one exists or Cnnnnnnn maxLen is currently ignored and only there to match the signature from the base class! double getColLower(OsiClpSolverInterface& osi, int elementIndex);// Get pointer to array[getNumCols(OsiClpSolverInterface osi)] of column lower bounds. double getColUpper(OsiClpSolverInterface& osi, int elementIndex);// Get pointer to array[getNumCols(OsiClpSolverInterface osi)] of column upper bounds. double getObjCoefficients(OsiClpSolverInterface& osi, int elementIndex);// Get pointer to array[getNumCols(OsiClpSolverInterface osi)] of objective function coefficients. -const char * getRowSense(OsiClpSolverInterface& osi);// Get pointer to array[getNumRows(OsiClpSolverInterface osi)] of row constraint senses. -double getRightHandSide(OsiClpSolverInterface& osi, int rowIndex);// Get pointer to array[getNumRows(OsiClpSolverInterface osi)] of rows right-hand sides. -double getRowRange(OsiClpSolverInterface& osi, int rowIndex);// Get pointer to array[getNumRows(OsiClpSolverInterface osi)] of row ranges. double getRowLower(OsiClpSolverInterface& osi, int rowIndex);// Get pointer to array[getNumRows(OsiClpSolverInterface osi)] of row lower bounds. double getRowUpper(OsiClpSolverInterface& osi, int rowIndex);// Get pointer to array[getNumRows(OsiClpSolverInterface osi)] of row upper bounds. double getObjSense(OsiClpSolverInterface& osi);// Get objective function sense (1 for min (default), -1 for max). @@ -116,39 +72,21 @@ void setObjSense(OsiClpSolverInterface& osi, double s); // Sets objective functi bool isContinuous(OsiClpSolverInterface& osi, int colNumber);// Return true if column is continuous. bool isBinary(OsiClpSolverInterface& osi, int colIndex);// Return true if variable is binary. bool isInteger(OsiClpSolverInterface& osi, int colIndex);// Return true if column is integer. -bool isIntegerNonBinary(OsiClpSolverInterface& osi, int colIndex);// Return true if variable is general integer. -bool isFreeBinary(OsiClpSolverInterface& osi, int colIndex);// Return true if variable is binary and not fixed at either bound. -const char * getColType(OsiClpSolverInterface& osi, bool refresh=false);// Return array of column length 0 - continuous 1 - binary (may get fixed later) 2 - general integer (may get fixed later). -const CoinPackedMatrix * getMatrixByRow(OsiClpSolverInterface& osi);// Get pointer to row-wise copy of matrix. const CoinPackedMatrix * getMatrixByCol(OsiClpSolverInterface& osi);// Get pointer to column-wise copy of matrix. -CoinPackedMatrix *getMutableMatrixByCol(OsiClpSolverInterface& osi);// Get pointer to mutable column-wise copy of matrix. double getInfinity(OsiClpSolverInterface& osi);// Get solver's value for infinity. //Methods related to querying the solution double getColSolution(OsiClpSolverInterface& osi, int colIndex);// Get pointer to array[getNumCols()] of primal solution vector. -double getRowPrice(OsiClpSolverInterface& osi, int rowIndex);// Get pointer to array[getNumRows()] of dual prices. -double getReducedCost(OsiClpSolverInterface& osi, int colIndex);// Get a pointer to array[getNumCols()] of reduced costs. -double getRowActivity(OsiClpSolverInterface& osi, int rowIndex);// Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vector. double getObjValue(OsiClpSolverInterface& osi);// Get objective function value. -int getIterationCount(OsiClpSolverInterface& osi);// Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver. -std::vector< double * > getDualRays(OsiClpSolverInterface& osi, int maxNumRays);// Get as many dual rays as the solver can provide. -std::vector< double * > getPrimalRays(OsiClpSolverInterface& osi, int maxNumRays);// Get as many primal rays as the solver can provide. //Changing bounds on variables and constraints void setObjCoeff(OsiClpSolverInterface& osi, int elementIndex, double elementValue);// Set an objective function coefficient. void setColLower(OsiClpSolverInterface& osi, int elementIndex, double elementValue);// Set a single column lower bound, Use -DBL_MAX for -infinity. void setColUpper(OsiClpSolverInterface& osi, int elementIndex, double elementValue);// Set a single column upper bound, Use DBL_MAX for infinity. void setColBounds(OsiClpSolverInterface& osi, int elementIndex, double lower, double upper);// Set a single column lower and upper bound. -void setColSetBounds(OsiClpSolverInterface& osi, const int *indexFirst, const int *indexLast, const double *boundList);// Set the bounds on a number of columns simultaneously, The default implementation just invokes setColLower() and setColUpper() over and over again. void setRowLower(OsiClpSolverInterface& osi, int elementIndex, double elementValue);// Set a single row lower bound, Use -DBL_MAX for -infinity. void setRowUpper(OsiClpSolverInterface& osi, int elementIndex, double elementValue);// Set a single row upper bound, Use DBL_MAX for infinity. -void setRowBounds(OsiClpSolverInterface& osi, int elementIndex, double lower, double upper);// Set a single row lower and upper bound. -void setRowType(OsiClpSolverInterface& osi, int index, char sense, double rightHandSide, double range);// Set the type of a single row. -void setRowSetBounds(OsiClpSolverInterface& osi, const int *indexFirst, const int *indexLast, const double *boundList);// Set the bounds on a number of rows simultaneously. The default implementation just invokes setRowLower() and setRowUpper() over and over again. -void setRowSetTypes(OsiClpSolverInterface& osi, 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() over and over again. void setObjective(OsiClpSolverInterface& osi, const double *array);// Set the objective coefficients for all columns array [getNumCols()] is an array of values for the objective. -void setColLower(OsiClpSolverInterface& osi, const double *array);// Set the lower bounds for all columns array [getNumCols()] is an array of values for the objective. -void setColUpper(OsiClpSolverInterface& osi, const double *array);// Set the upper bounds for all columns array [getNumCols()] is an array of values for the objective. void setRowName(OsiClpSolverInterface& osi, int rowIndex, std::string name);// Set name of row. void setColName(OsiClpSolverInterface& osi, int colIndex, std::string name);// Set name of column. @@ -156,83 +94,29 @@ void setColName(OsiClpSolverInterface& osi, int colIndex, std::string name);// S //Integrality related changing methods void setContinuous(OsiClpSolverInterface& osi, int index);// Set the index-th variable to be a continuous variable. void setInteger(OsiClpSolverInterface& osi, int index);// Set the index-th variable to be an integer variable. -void setContinuous(OsiClpSolverInterface& osi, const int *indices, int len);// Set the variables listed in indices (which is of length len) to be continuous variables. -void setInteger(OsiClpSolverInterface& osi, const int *indices, int len);// Set the variables listed in indices (which is of length len) to be integer variables. - /*Methods to expand a problem. Note that if a column is added then by default it will correspond to a continuous variable. */ -void addCol(OsiClpSolverInterface& osi, const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj);// Add a column (primal variable) to the problem. void addCol(OsiClpSolverInterface& osi, int numberElements, const int *rows, const double *elements, const double collb, const double colub, const double obj);// Add a column (primal variable) to the problem. -void addCols(OsiClpSolverInterface& osi, const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj);// Add a set of columns (primal variables) to the problem. -void addCols(OsiClpSolverInterface& osi, const int numcols, const int *columnStarts, const int *rows, const double *elements, const double *collb, const double *colub, const double *obj);// Add a set of columns (primal variables) to the problem. void deleteCols(OsiClpSolverInterface& osi, const int num, const int *colIndices);// Remove a set of columns (primal variables) from the problem. -void addRow(OsiClpSolverInterface& osi, const CoinPackedVectorBase &vec, const double rowlb, const double rowub);// Add a row (constraint) to the problem. -void addRow(OsiClpSolverInterface& osi, const CoinPackedVectorBase &vec, const char rowsen, const double rowrhs, const double rowrng);// Add a row (constraint) to the problem. void addRow(OsiClpSolverInterface& osi, int numberElements, const int *columns, const double *element, const double rowlb, const double rowub);// Add a row (constraint) to the problem. -void addRows(OsiClpSolverInterface& osi, const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub); -void addRows(OsiClpSolverInterface& osi, const int numrows, const CoinPackedVectorBase *const *rows, const char *rowsen, const double *rowrhs, const double *rowrng);// Add a set of rows (constraints) to the problem. -void addRows(OsiClpSolverInterface& osi, const int numrows, const int *rowStarts, const int *columns, const double *element, const double *rowlb, const double *rowub);// Add a set of rows (constraints) to the problem. void modifyCoefficient(OsiClpSolverInterface& osi, int row, int column, double newElement, bool keepZero=false); void deleteRows(OsiClpSolverInterface& osi, const int num, const int *rowIndices);// Delete a set of rows (constraints) from the problem. -void saveBaseModel(OsiClpSolverInterface& osi);// If solver wants it can save a copy of "base" (continuous) model here. -void restoreBaseModel(OsiClpSolverInterface& osi, int numberRows);// Strip off rows to get to this number of rows. -void applyRowCuts(OsiClpSolverInterface& osi, int numberCuts, const OsiRowCut *cuts);// Apply a collection of row cuts which are all effective. -void applyRowCuts(OsiClpSolverInterface& osi, int numberCuts, const OsiRowCut **cuts);// Apply a collection of row cuts which are all effective. - //Methods to input a problem -void loadProblem(OsiClpSolverInterface& osi, 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 bounds). -void assignProblem(OsiClpSolverInterface& osi, 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 lower and upper bounds). -void loadProblem(OsiClpSolverInterface& osi, const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng);// Load in an problem by copying the arguments (the constraints on the rows are given by sense/rhs/range triplets). -void assignProblem(OsiClpSolverInterface& osi, CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, char *&rowsen, double *&rowrhs, double *&rowrng);// Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by sense/rhs/range triplets). -void loadProblem(OsiClpSolverInterface& osi, const int numcols, const int numrows, const CoinBigIndex *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub);// Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). -void loadProblem(OsiClpSolverInterface& osi, const int numcols, const int numrows, const CoinBigIndex *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng);// Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). -int loadFromCoinModel(OsiClpSolverInterface& osi, CoinModel &modelObject, bool keepSolution=false);// This loads a model from a coinModel object - returns number of errors. -int readMps(OsiClpSolverInterface& osi, const char *filename, const char *extension="mps");// Read an mps file from the given filename (defaults to Osi reader) - returns number of errors (see OsiMpsReader class). -int readMps(OsiClpSolverInterface& osi, const char *filename, bool keepNames, bool allowErrors);// Read an mps file from the given filename returns number of errors (see OsiMpsReader class). -void writeMps(OsiClpSolverInterface& osi, const char *filename, const char *extension="mps", double objSense=0.0);// Write the problem into an mps file of the given filename. -int writeMpsNative(OsiClpSolverInterface& osi, const char *filename, const char **rowNames, const char **columnNames, int formatType=0, int numberAcross=2, double objSense=0.0);// Write the problem into an mps file of the given filename, names may be null. int readLp(OsiClpSolverInterface& osi, const char *filename, const double epsilon=1e-5);// Read file in LP format (with names). void writeLp(OsiClpSolverInterface& osi, const char *filename, const char *extension="lp", double epsilon=1e-5, int numberAcross=10, int decimals=5, double objSense=0.0, bool useRowNames=true);// Write the problem into an Lp file of the given filename. -void writeLp(OsiClpSolverInterface& osi, FILE *fp, double epsilon=1e-5, int numberAcross=10, int decimals=5, double objSense=0.0, bool useRowNames=true);// Write the problem into the file pointed to by the parameter fp. - -// Create a new pre-processor -CglPreProcess* newCglPreProcess(); - -// Delete the pre-processor -void deleteCglPreProcess(CglPreProcess* p); - -// Run the preprocessor -OsiSolverInterface* preProcess(CglPreProcess& p, OsiClpSolverInterface& osi, bool makeEquality, int numberPasses); - -// Create solution in original model -void postProcess(CglPreProcess& p, OsiSolverInterface& osi); // Resolve an LP relaxation after problem modification. void resolve(OsiSolverInterface& osi); -// Returns solver - has current state. +// Returns solver - has current state. OsiClpSolverInterface* solver(CbcModel& m); -// Create a new CbcHeuristicFPump -CbcHeuristicFPump* newCbcHeuristicFPump(); -// Create a new CbcHeuristicFPump -CbcHeuristicFPump* newCbcHeuristicFPump(CbcModel& m, double downValue, bool roundExpensive ); -// Delete CbcHeuristicFPump -void deleteCbcHeuristicFPump(CbcHeuristicFPump * h); -// Add one heuristic - up to user to delete. -void addHeuristic(CbcModel& m, CbcHeuristicFPump* h); -// Delete OsiSolverInterface -void deleteOsiSolverInterface(OsiSolverInterface* s); -// Set current log (detail) level. -void setLogLevel(CglPreProcess& p, int n); -// Set current log (detail) level. -void setLogLevel(OsiSolverInterface& s, int n); // Set current log (detail) level. void setLogLevel(OsiClpSolverInterface& s, int n); -// Get pointer to array[getNumCols()] of objective function coefficients. +// Get pointer to array[getNumCols()] of objective function coefficients. const double* getObjCoefficients(OsiClpSolverInterface& osi); // Sets the objective coefficient void setObjCoefficients(OsiClpSolverInterface& osi, int numberElements, const int *rows, const double *coefs); @@ -247,4 +131,6 @@ int callCbc1 (int argc, const char *argv[], CbcModel & babSolver); double getObjValue(OsiSolverInterface& c); // Get pointer to array[getNumCols()] of primal solution vector. double getColSolution(OsiSolverInterface& osi, int colIndex); + +double bestSolution(CbcModel& c, int colIndex); #endif diff --git a/src/main/native/javacbc.i b/src/main/native/javacbc.i index c302935f6121ff3a63a97ed2c7ac0d0e8e3b0eba..a61277147b4590ae228f3ba1eba28697db9df050 100644 --- a/src/main/native/javacbc.i +++ b/src/main/native/javacbc.i @@ -17,92 +17,52 @@ typedef std::string String; // Solve initial LP relaxation. extern void initialSolve(OsiClpSolverInterface &solver); -// Solve initial LP relaxation. -extern void initialSolve(OsiSolverInterface& solver); - extern void setInt(OsiClpSolverInterface &solver, int i); // Default Constructor. extern OsiClpSolverInterface* newOsiClpSolverInterface(); -// Copy constructor. -extern OsiClpSolverInterface* newOsiClpSolverInterface(OsiClpSolverInterface & s); - // Delete OsiClpSolverInterface extern void deleteOsiClpSolverInterface(OsiClpSolverInterface* solver); -extern CoinBigIndex CBI(int start[]); -extern CoinPackedMatrix CPM(int numberRows, int numberColumns, int numberElements, int *startint, int nbelems, int *length, int *rows, double *elements); -extern CoinPackedMatrix CPM(int *rowIndices, int *colIndices, double *elements, int nbelems); - // Create a new instance of CbcModel extern CbcModel* newCbcModel(OsiClpSolverInterface &s); -// Create a new instance of CbcModel -extern CbcModel* newCbcModel(OsiSolverInterface& s); extern void deleteCbcModel(CbcModel* c); extern void initialSolve(CbcModel &c); extern void branchAndBound(CbcModel &c, int doStatistics = 0); extern int status(CbcModel &c); -extern int secondaryStatus(CbcModel &c); extern bool isProvenOptimal(CbcModel &c); extern bool isProvenInfeasible(CbcModel &c); -extern bool isContinuousUnbounded(CbcModel &c); -extern bool isNodeLimitReached(CbcModel &c); -extern bool isSecondsLimitReached(CbcModel &c); extern int getNumCols(CbcModel &c); extern int getNumRows(CbcModel &c) ; -extern CoinBigIndex getNumElements(CbcModel &c); -extern int numberIntegers(CbcModel &c) ; -extern char integerType(CbcModel &c,int i); extern double getColLower(CbcModel &c, int colIndex); extern double getColUpper(CbcModel &c, int colIndex); extern double getObjCoefficients(CbcModel &c, int colIndex); -extern double getCbcColLower(CbcModel &c, int colIndex); -extern double getCbcColUpper(CbcModel &c, int colIndex); extern double getCbcColSolution(CbcModel &c, int colIndex); -extern double getRightHandSide(CbcModel &c, int rowIndex); -extern double getRowRange(CbcModel &c, int rowIndex); extern double getRowLower(CbcModel &c, int rowIndex); extern double getRowUpper(CbcModel &c, int rowIndex); extern double getCbcRowLower(CbcModel &c, int rowIndex); extern double getCbcRowUpper(CbcModel &c, int rowIndex); -extern double getCbcRowPrice(CbcModel &c, int rowIndex); -extern double bestSolution(CbcModel &c, int colIndex); -double getCurrentObjValue(CbcModel &c); - -extern const char* getRowSense(CbcModel &c); extern double getObjSense(CbcModel &c); extern void setObjSense(CbcModel &c, double s); extern bool isContinuous(CbcModel &c, int colIndex); extern bool isBinary(CbcModel &c, int colIndex); extern bool isInteger(CbcModel &c, int colIndex); -extern bool isIntegerNonBinary(CbcModel &c, int colIndex); -extern bool isFreeBinary(CbcModel &c, int colIndex); -extern const CoinPackedMatrix* getMatrixByRow(CbcModel &c); extern const CoinPackedMatrix* getMatrixByCol(CbcModel &c); extern double getInfinity(CbcModel &c); extern double getObjValue(CbcModel &c); -extern int getNumberThreads(CbcModel &c); -extern void setNumberThreads(CbcModel &c, int value); extern void setLogLevel(CbcModel &c, int n); //OsiClpSolverInterface proxy functions and constructor //Methods returning info on how the solution process terminated -extern bool isAbandoned(OsiClpSolverInterface &osi); //Are there a numerical difficulties? extern bool isProvenOptimal(OsiClpSolverInterface &osi); //Is optimality proven? -extern bool isProvenPrimalInfeasible(OsiClpSolverInterface &osi);// Is primal infeasiblity proven? -extern bool isProvenDualInfeasible(OsiClpSolverInterface &osi);// Is dual infeasiblity proven? -extern bool isPrimalObjectiveLimitReached(OsiClpSolverInterface &osi);// Is the given primal objective limit reached? -extern bool isDualObjectiveLimitReached(OsiClpSolverInterface &osi);// Is the given dual objective limit reached? -extern bool isIterationLimitReached(OsiClpSolverInterface &osi);// Iteration limit reached? //Methods related to querying the input data extern int getNumCols(OsiClpSolverInterface &osi);// Get number of columns. extern int getNumRows(OsiClpSolverInterface &osi);// Get number of rows. -extern int getNumElements(OsiClpSolverInterface &osi);// Get number of nonzero elements. extern std::string getRowName(OsiClpSolverInterface &osi, int rowIndex, unsigned maxLen=std::string::npos);// Return name of row if one exists or Rnnnnnnn maxLen is currently ignored and only there to match the signature from the base class! extern std::string getColName(OsiClpSolverInterface &osi, int colIndex, unsigned maxLen=std::string::npos);// Return name of column if one exists or Cnnnnnnn maxLen is currently ignored and only there to match the signature from the base class! @@ -110,54 +70,29 @@ extern double getColLower(OsiClpSolverInterface &osi, int elementIndex); // Get extern double getColUpper(OsiClpSolverInterface &osi, int elementIndex); // Get pointer to array[getNumCols()] of column upper bounds. extern double getObjCoefficients(OsiClpSolverInterface &osi, int elementIndex); // Get pointer to array[getNumCols()] of objective function coefficients. -extern double getRightHandSide(OsiClpSolverInterface &osi, int rowIndex);// Get pointer to array[getNumRows()] of rows right-hand sides. -extern double getRowRange(OsiClpSolverInterface &osi, int rowIndex);// Get pointer to array[getNumRows()] of row ranges. extern double getRowLower(OsiClpSolverInterface &osi, int rowIndex);// Get pointer to array[getNumRows()] of row lower bounds. extern double getRowUpper(OsiClpSolverInterface &osi, int rowIndex);// Get pointer to array[getNumRows()] of row upper bounds. -extern const char * getRowSense(OsiClpSolverInterface &osi);// Get pointer to array[getNumRows()] of row constraint senses. - extern double getObjSense(OsiClpSolverInterface &osi);// Get objective function sense (1 for min (default), -1 for max). extern void setObjSense(OsiClpSolverInterface &osi, double s);// Sets objective function sense (1 for min (default), -1 for max). extern bool isContinuous(OsiClpSolverInterface &osi, int colNumber);// Return true if column is continuous. extern bool isBinary(OsiClpSolverInterface &osi, int colIndex);// Return true if variable is binary. extern bool isInteger(OsiClpSolverInterface &osi, int colIndex);// Return true if column is integer. -extern bool isIntegerNonBinary(OsiClpSolverInterface &osi, int colIndex);// Return true if variable is general integer. -extern bool isFreeBinary(OsiClpSolverInterface &osi, int colIndex);// Return true if variable is binary and not fixed at either bound. -extern const char * getColType(OsiClpSolverInterface &osi, bool refresh=false);// Return array of column length 0 - continuous 1 - binary (may get fixed later) 2 - general integer (may get fixed later). -extern const CoinPackedMatrix * getMatrixByRow(OsiClpSolverInterface &osi);// Get pointer to row-wise copy of matrix. extern const CoinPackedMatrix * getMatrixByCol(OsiClpSolverInterface &osi);// Get pointer to column-wise copy of matrix. -extern CoinPackedMatrix *getMutableMatrixByCol(OsiClpSolverInterface &osi);// Get pointer to mutable column-wise copy of matrix. extern double getInfinity(OsiClpSolverInterface &osi);// Get solver's value for infinity. //Methods related to querying the solution extern double getColSolution(OsiClpSolverInterface &osi, int colIndex);// Get pointer to array[getNumCols()] of primal solution vector. -extern double getReducedCost(OsiClpSolverInterface &osi, int colIndex);// Get a pointer to array[getNumCols()] of reduced costs. - -extern double getRowPrice(OsiClpSolverInterface &osi, int rowIndex);// Get pointer to array[getNumRows()] of dual prices. -extern double getRowActivity(OsiClpSolverInterface &osi, int rowIndex);// Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vector. - extern double getObjValue(OsiClpSolverInterface &osi);// Get objective function value. -extern int getIterationCount(OsiClpSolverInterface &osi);// Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver. -extern std::vector< double * > getDualRays(OsiClpSolverInterface &osi, int maxNumRays);// Get as many dual rays as the solver can provide. -extern std::vector< double * > getPrimalRays(OsiClpSolverInterface &osi, int maxNumRays);// Get as many primal rays as the solver can provide. - //Changing bounds on variables and constraints void setObjCoeff(OsiClpSolverInterface &osi, int elementIndex, double elementValue);// Set an objective function coefficient. void setColLower(OsiClpSolverInterface &osi, int elementIndex, double elementValue);// Set a single column lower bound, Use -DBL_MAX for -infinity. void setColUpper(OsiClpSolverInterface &osi, int elementIndex, double elementValue);// Set a single column upper bound, Use DBL_MAX for infinity. void setColBounds(OsiClpSolverInterface &osi, int elementIndex, double lower, double upper);// Set a single column lower and upper bound. -void setColSetBounds(OsiClpSolverInterface &osi, const int *indexFirst, const int *indexLast, const double *boundList);// Set the bounds on a number of columns simultaneously, The default implementation just invokes setColLower() and setColUpper() over and over again. void setRowLower(OsiClpSolverInterface &osi, int elementIndex, double elementValue);// Set a single row lower bound, Use -DBL_MAX for -infinity. void setRowUpper(OsiClpSolverInterface &osi, int elementIndex, double elementValue);// Set a single row upper bound, Use DBL_MAX for infinity. -void setRowBounds(OsiClpSolverInterface &osi, int elementIndex, double lower, double upper);// Set a single row lower and upper bound. -void setRowType(OsiClpSolverInterface &osi, int index, char sense, double rightHandSide, double range);// Set the type of a single row. -void setRowSetBounds(OsiClpSolverInterface &osi, const int *indexFirst, const int *indexLast, const double *boundList);// Set the bounds on a number of rows simultaneously. The default implementation just invokes setRowLower() and setRowUpper() over and over again. -void setRowSetTypes(OsiClpSolverInterface &osi, 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() over and over again. void setObjective(OsiClpSolverInterface &osi, const double *array);// Set the objective coefficients for all columns array [getNumCols()] is an array of values for the objective. -void setColLower(OsiClpSolverInterface &osi, const double *array);// Set the lower bounds for all columns array [getNumCols()] is an array of values for the objective. -void setColUpper(OsiClpSolverInterface &osi, const double *array);// Set the upper bounds for all columns array [getNumCols()] is an array of values for the objective. void setRowName(OsiClpSolverInterface &osi, int rowIndex, std::string name);// Set name of row. void setColName(OsiClpSolverInterface &osi, int colIndex, std::string name);// Set name of column. @@ -165,80 +100,26 @@ void setColName(OsiClpSolverInterface &osi, int colIndex, std::string name);// S //Integrality related changing methods void setContinuous(OsiClpSolverInterface &osi, int index);// Set the index-th variable to be a continuous variable. void setInteger(OsiClpSolverInterface &osi, int index);// Set the index-th variable to be an integer variable. -void setContinuous(OsiClpSolverInterface &osi, const int *indices, int len);// Set the variables listed in indices (which is of length len) to be continuous variables. -void setInteger(OsiClpSolverInterface &osi, const int *indices, int len);// Set the variables listed in indices (which is of length len) to be integer variables. - - //Methods to expand a problem. //Note that if a column is added then by default //it will correspond to a continuous variable. -extern void addCol(OsiClpSolverInterface &osi, const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj);// Add a column (primal variable) to the problem. extern void addCol(OsiClpSolverInterface &osi, int numberElements, const int *rows, const double *elements, const double collb, const double colub, const double obj);// Add a column (primal variable) to the problem. -extern void addCols(OsiClpSolverInterface &osi, const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj);// Add a set of columns (primal variables) to the problem. -extern void addCols(OsiClpSolverInterface &osi, const int numcols, const int *columnStarts, const int *rows, const double *elements, const double *collb, const double *colub, const double *obj);// Add a set of columns (primal variables) to the problem. extern void deleteCols(OsiClpSolverInterface &osi, const int num, const int *colIndices);// Remove a set of columns (primal variables) from the problem. -extern void addRow(OsiClpSolverInterface &osi, const CoinPackedVectorBase &vec, const double rowlb, const double rowub);// Add a row (constraint) to the problem. -extern void addRow(OsiClpSolverInterface &osi, const CoinPackedVectorBase &vec, const char rowsen, const double rowrhs, const double rowrng);// Add a row (constraint) to the problem. extern void addRow(OsiClpSolverInterface &osi, int numberElements, const int *columns, const double *element, const double rowlb, const double rowub);// Add a row (constraint) to the problem. -extern void addRows(OsiClpSolverInterface &osi, const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub); -extern void addRows(OsiClpSolverInterface &osi, const int numrows, const CoinPackedVectorBase *const *rows, const char *rowsen, const double *rowrhs, const double *rowrng);// Add a set of rows (constraints) to the problem. -extern void addRows(OsiClpSolverInterface &osi, const int numrows, const int *rowStarts, const int *columns, const double *element, const double *rowlb, const double *rowub);// Add a set of rows (constraints) to the problem. extern void modifyCoefficient(OsiClpSolverInterface &osi, int row, int column, double newElement, bool keepZero=false); extern void deleteRows(OsiClpSolverInterface &osi, const int num, const int *rowIndices);// Delete a set of rows (constraints) from the problem. -extern void saveBaseModel(OsiClpSolverInterface &osi);// If solver wants it can save a copy of "base" (continuous) model here. -extern void restoreBaseModel(OsiClpSolverInterface &osi, int numberRows);// Strip off rows to get to this number of rows. -extern void applyRowCuts(OsiClpSolverInterface &osi, int numberCuts, const OsiRowCut *cuts);// Apply a collection of row cuts which are all effective. -extern void applyRowCuts(OsiClpSolverInterface &osi, int numberCuts, const OsiRowCut **cuts);// Apply a collection of row cuts which are all effective. //Methods to input a problem -extern void loadProblem(OsiClpSolverInterface &osi, 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 bounds). -extern void assignProblem(OsiClpSolverInterface &osi, 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 lower and upper bounds). -extern void loadProblem(OsiClpSolverInterface &osi, const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng);// Load in an problem by copying the arguments (the constraints on the rows are given by sense/rhs/range triplets). -extern void assignProblem(OsiClpSolverInterface &osi, CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, char *&rowsen, double *&rowrhs, double *&rowrng);// Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by sense/rhs/range triplets). -extern void loadProblem(OsiClpSolverInterface &osi, const int numcols, const int numrows, const CoinBigIndex *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub);// Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). -extern void loadProblem(OsiClpSolverInterface &osi, const int numcols, const int numrows, const CoinBigIndex *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng);// Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). -extern int loadFromCoinModel(OsiClpSolverInterface &osi, CoinModel &modelObject, bool keepSolution=false);// This loads a model from a coinModel object - returns number of errors. -extern int readMps(OsiClpSolverInterface &osi, const char *filename, const char *extension="mps");// Read an mps file from the given filename (defaults to Osi reader) - returns number of errors (see OsiMpsReader class). -extern int readMps(OsiClpSolverInterface &osi, const char *filename, bool keepNames, bool allowErrors);// Read an mps file from the given filename returns number of errors (see OsiMpsReader class). -extern void writeMps(OsiClpSolverInterface &osi, const char *filename, const char *extension="mps", double objSense=0.0);// Write the problem into an mps file of the given filename. -extern int writeMpsNative(OsiClpSolverInterface &osi, const char *filename, const char **rowNames, const char **columnNames, int formatType=0, int numberAcross=2, double objSense=0.0);// Write the problem into an mps file of the given filename, names may be null. extern int readLp(OsiClpSolverInterface &osi, const char *filename, const double epsilon=1e-5);// Read file in LP format (with names). extern void writeLp(OsiClpSolverInterface &osi, const char *filename, const char *extension="lp", double epsilon=1e-5, int numberAcross=10, int decimals=5, double objSense=0.0, bool useRowNames=true);// Write the problem into an Lp file of the given filename. -extern void writeLp(OsiClpSolverInterface &osi, FILE *fp, double epsilon=1e-5, int numberAcross=10, int decimals=5, double objSense=0.0, bool useRowNames=true);// Write the problem into the file pointed to by the parameter fp. - -// Create a new pre-processor -extern CglPreProcess* newCglPreProcess(); - -// Delete the pre-processor -extern void deleteCglPreProcess(CglPreProcess* p); - -// Run the preprocessor -extern OsiSolverInterface* preProcess(CglPreProcess& p, OsiClpSolverInterface &osi, bool makeEquality, int numberPasses); - -// Create solution in original model -extern void postProcess(CglPreProcess& p, OsiSolverInterface& osi); // Resolve an LP relaxation after problem modification. extern void resolve(OsiSolverInterface& osi); // Returns solver - has current state. extern OsiClpSolverInterface* solver(CbcModel &m); -// Create a new CbcHeuristicFPump -extern CbcHeuristicFPump* newCbcHeuristicFPump(); -// Create a new CbcHeuristicFPump -extern CbcHeuristicFPump* newCbcHeuristicFPump(CbcModel &m, double downValue, bool roundExpensive ); -// Delete CbcHeuristicFPump -extern void deleteCbcHeuristicFPump(CbcHeuristicFPump * h); -// Add one heuristic - up to user to delete. -extern void addHeuristic(CbcModel &m, CbcHeuristicFPump* h); -// Delete OsiSolverInterface -extern void deleteOsiSolverInterface(OsiSolverInterface* s); -// Set current log (detail) level. -extern void setLogLevel(CglPreProcess& p, int n); -// Set current log (detail) level. -extern void setLogLevel(OsiSolverInterface& s, int n); // Set current log (detail) level. extern void setLogLevel(OsiClpSolverInterface &s, int n); // Get pointer to array[getNumCols()] of objective function coefficients. @@ -260,3 +141,5 @@ extern int callCbc1 (int argc, const char *argv[], CbcModel &babSolver); extern double getObjValue(OsiSolverInterface& c); // Get pointer to array[getNumCols()] of primal solution vector. extern double getColSolution(OsiSolverInterface& osi, int colIndex); + +extern double bestSolution(CbcModel& c, int colIndex);