#include <OsiClpSolverInterface.hpp>
Inheritance diagram for OsiClpSolverInterface:
Public Member Functions | |
virtual void | setObjSense (double s) |
Set objective function sense (1 for min (default), -1 for max,). | |
virtual void | setColSolution (const double *colsol) |
virtual void | setRowPrice (const double *rowprice) |
Solve methods | |
virtual void | initialSolve () |
Solve initial LP relaxation. | |
virtual void | resolve () |
Resolve an LP relaxation after problem modification. | |
virtual void | branchAndBound () |
Invoke solver's built-in enumeration algorithm. | |
OsiSimplexInterface methods | |
virtual void | enableSimplexInterface (bool doingPrimal) |
virtual void | disableSimplexInterface () |
Undo whatever setting changes the above method had to make. | |
virtual bool | basisIsAvailable () |
Returns true if a basis is available. | |
virtual void | getBasisStatus (int *cstat, int *rstat) |
virtual int | setBasisStatus (const int *cstat, const int *rstat) |
virtual int | pivot (int colIn, int colOut, int outStatus) |
virtual int | primalPivotResult (int colIn, int sign, int &colOut, int &outStatus, double &t, CoinPackedVector *dx) |
virtual int | dualPivotResult (int &colIn, int &sign, int colOut, int outStatus, double &t, CoinPackedVector *dx) |
virtual void | getReducedGradient (double *columnReducedCosts, double *duals, const double *c) |
Get the reduced gradient for the cost vector c. | |
virtual void | setObjectiveAndRefresh (double *c) |
virtual void | getBInvARow (int row, double *z) |
Get a row of the tableau. | |
virtual void | getBInvRow (int row, double *z) |
Get a row of the basis inverse. | |
virtual void | getBInvACol (int col, double *vec) |
Get a column of the tableau. | |
virtual void | getBInvCol (int col, double *vec) |
Get a column of the basis inverse. | |
virtual void | getBasics (int *index) |
Parameter set/get methods | |
The set methods return true if the parameter was set to the given value, false otherwise. There can be various reasons for failure: the given parameter is not applicable for the solver (e.g., refactorization frequency for the clp algorithm), the parameter is not yet implemented for the solver or simply the value of the parameter is out of the range the solver accepts. If a parameter setting call returns false check the details of your solver.
The get methods return true if the given parameter is applicable for the solver and is implemented. In this case the value of the parameter is returned in the second argument. Otherwise they return false. | |
bool | setIntParam (OsiIntParam key, int value) |
bool | setDblParam (OsiDblParam key, double value) |
bool | setStrParam (OsiStrParam key, const std::string &value) |
bool | getIntParam (OsiIntParam key, int &value) const |
bool | getDblParam (OsiDblParam key, double &value) const |
bool | getStrParam (OsiStrParam key, std::string &value) const |
Methods returning info on how the solution process terminated | |
virtual bool | isAbandoned () const |
Are there a numerical difficulties? | |
virtual bool | isProvenOptimal () const |
Is optimality proven? | |
virtual bool | isProvenPrimalInfeasible () const |
Is primal infeasiblity proven? | |
virtual bool | isProvenDualInfeasible () const |
Is dual infeasiblity proven? | |
virtual bool | isPrimalObjectiveLimitReached () const |
Is the given primal objective limit reached? | |
virtual bool | isDualObjectiveLimitReached () const |
Is the given dual objective limit reached? | |
virtual bool | isIterationLimitReached () const |
Iteration limit reached? | |
WarmStart related methods | |
virtual CoinWarmStart * | getEmptyWarmStart () const |
Get an empty warm start object. | |
virtual CoinWarmStart * | getWarmStart () const |
Get warmstarting information. | |
virtual bool | setWarmStart (const CoinWarmStart *warmstart) |
Hotstart related methods (primarily used in strong branching). <br> | |
The user can create a hotstart (a snapshot) of the optimization process then reoptimize over and over again always starting from there. NOTE: between hotstarted optimizations only bound changes are allowed. | |
virtual void | markHotStart () |
Create a hotstart point of the optimization process. | |
virtual void | solveFromHotStart () |
Optimize starting from the hotstart. | |
virtual void | unmarkHotStart () |
Delete the snapshot. | |
Methods related to querying the input data | |
virtual int | getNumCols () const |
Get number of columns. | |
virtual int | getNumRows () const |
Get number of rows. | |
virtual int | getNumElements () const |
Get number of nonzero elements. | |
virtual const double * | getColLower () const |
Get pointer to array[getNumCols()] of column lower bounds. | |
virtual const double * | getColUpper () const |
Get pointer to array[getNumCols()] of column upper bounds. | |
virtual const char * | getRowSense () const |
virtual const double * | getRightHandSide () const |
virtual const double * | getRowRange () const |
virtual const double * | getRowLower () const |
Get pointer to array[getNumRows()] of row lower bounds. | |
virtual const double * | getRowUpper () const |
Get pointer to array[getNumRows()] of row upper bounds. | |
virtual const double * | getObjCoefficients () const |
Get pointer to array[getNumCols()] of objective function coefficients. | |
virtual double | getObjSense () const |
Get objective function sense (1 for min (default), -1 for max). | |
virtual bool | isContinuous (int colNumber) const |
Return true if column is continuous. | |
virtual const CoinPackedMatrix * | getMatrixByRow () const |
Get pointer to row-wise copy of matrix. | |
virtual const CoinPackedMatrix * | getMatrixByCol () const |
Get pointer to column-wise copy of matrix. | |
virtual double | getInfinity () const |
Get solver's value for infinity. | |
Methods related to querying the solution | |
virtual const double * | getColSolution () const |
Get pointer to array[getNumCols()] of primal solution vector. | |
virtual const double * | getRowPrice () const |
Get pointer to array[getNumRows()] of dual prices. | |
virtual const double * | getReducedCost () const |
Get a pointer to array[getNumCols()] of reduced costs. | |
virtual const double * | getRowActivity () const |
virtual double | getObjValue () const |
Get objective function value. | |
virtual int | getIterationCount () const |
virtual std::vector< double * > | getDualRays (int maxNumRays) const |
virtual std::vector< double * > | getPrimalRays (int maxNumRays) const |
Changing bounds on variables and constraints | |
virtual void | setObjCoeff (int elementIndex, double elementValue) |
virtual void | setColLower (int elementIndex, double elementValue) |
virtual void | setColUpper (int elementIndex, double elementValue) |
virtual void | setColBounds (int elementIndex, double lower, double upper) |
virtual void | setColSetBounds (const int *indexFirst, const int *indexLast, const double *boundList) |
virtual void | setRowLower (int elementIndex, double elementValue) |
virtual void | setRowUpper (int elementIndex, double elementValue) |
virtual void | setRowBounds (int elementIndex, double lower, double upper) |
virtual void | setRowType (int index, char sense, double rightHandSide, double range) |
virtual void | setRowSetBounds (const int *indexFirst, const int *indexLast, const double *boundList) |
virtual void | setRowSetTypes (const int *indexFirst, const int *indexLast, const char *senseList, const double *rhsList, const double *rangeList) |
Integrality related changing methods | |
virtual void | setContinuous (int index) |
virtual void | setInteger (int index) |
virtual void | setContinuous (const int *indices, int len) |
virtual void | setInteger (const int *indices, int len) |
Methods to expand a problem.<br> | |
Note that if a column is added then by default it will correspond to a continuous variable. | |
virtual void | addCol (const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj) |
virtual void | addCols (const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj) |
virtual void | deleteCols (const int num, const int *colIndices) |
virtual void | addRow (const CoinPackedVectorBase &vec, const double rowlb, const double rowub) |
virtual void | addRow (const CoinPackedVectorBase &vec, const char rowsen, const double rowrhs, const double rowrng) |
virtual void | addRows (const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub) |
virtual void | addRows (const int numrows, const CoinPackedVectorBase *const *rows, const char *rowsen, const double *rowrhs, const double *rowrng) |
virtual void | deleteRows (const int num, const int *rowIndices) |
virtual void | applyRowCuts (int numberCuts, const OsiRowCut *cuts) |
Methods to input a problem | |
virtual void | loadProblem (const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub) |
virtual void | assignProblem (CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, double *&rowlb, double *&rowub) |
virtual void | loadProblem (const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng) |
virtual void | assignProblem (CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, char *&rowsen, double *&rowrhs, double *&rowrng) |
virtual void | loadProblem (const int numcols, const int numrows, const int *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub) |
virtual void | loadProblem (const int numcols, const int numrows, const int *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) |
virtual int | readMps (const char *filename, const char *extension="mps") |
virtual void | writeMps (const char *filename, const char *extension="mps", double objSense=0.0) const |
virtual int | writeMpsNative (const char *filename, const char **rowNames, const char **columnNames, int formatType=0, int numberAcross=2, double objSense=0.0) const |
Message handling (extra for Clp messages). | |
Normally I presume you would want the same language. If not then you could use underlying model pointer | |
void | newLanguage (CoinMessages::Language language) |
Set language. | |
void | setLanguage (CoinMessages::Language language) |
Clp specific public interfaces | |
ClpSimplex * | getModelPtr () const |
Get pointer to Clp model. | |
Constructors and destructors | |
OsiClpSolverInterface () | |
Default Constructor. | |
virtual OsiSolverInterface * | clone (bool copyData=true) const |
Clone. | |
OsiClpSolverInterface (const OsiClpSolverInterface &) | |
Copy constructor. | |
OsiClpSolverInterface (ClpSimplex *) | |
Borrow constructor - only delete one copy. | |
void | releaseClp () |
Releases so won't error. | |
OsiClpSolverInterface & | operator= (const OsiClpSolverInterface &rhs) |
Assignment operator. | |
virtual | ~OsiClpSolverInterface () |
Destructor. | |
virtual void | reset () |
Resets as if default constructor. | |
Protected Member Functions | |
Protected methods | |
virtual void | applyRowCut (const OsiRowCut &rc) |
virtual void | applyColCut (const OsiColCut &cc) |
Private Member Functions | |
Private methods | |
void | gutsOfDestructor () |
The real work of a copy constructor (used by copy and assignment). | |
void | freeCachedResults () const |
Deletes all mutable stuff. | |
void | extractSenseRhsRange () const |
A method that fills up the rowsense_, rhs_ and rowrange_ arrays. | |
void | fillParamMaps () |
CoinWarmStartBasis | getBasis (ClpSimplex *model) const |
Warm start. | |
void | setBasis (const CoinWarmStartBasis &basis, ClpSimplex *model) |
Sets up working basis as a copy of input. | |
Private Attributes | |
Private member data | |
ClpSimplex * | modelPtr_ |
Clp model represented by this class instance. | |
double * | linearObjective_ |
Linear objective - just points to ClpModel. | |
Cached information derived from the OSL model | |
char * | rowsense_ |
Pointer to dense vector of row sense indicators. | |
double * | rhs_ |
Pointer to dense vector of row right-hand side values. | |
double * | rowrange_ |
CoinWarmStartBasis * | ws_ |
double * | rowActivity_ |
double * | columnActivity_ |
CoinWarmStartBasis | basis_ |
int | itlimOrig_ |
int | lastAlgorithm_ |
Last algorithm used. | |
bool | notOwned_ |
To say if destructor should delete underlying model. | |
CoinPackedMatrix * | matrixByRow_ |
Pointer to row-wise copy of problem matrix coefficients. | |
char * | integerInformation_ |
Pointer to integer information. | |
std::map< OsiIntParam, ClpIntParam > | intParamMap_ |
std::map< OsiDblParam, ClpDblParam > | dblParamMap_ |
std::map< OsiStrParam, ClpStrParam > | strParamMap_ |
ClpDataSave | saveData_ |
To save data in OsiSimplex stuff. | |
Friends | |
void | OsiClpSolverInterfaceUnitTest (const std::string &mpsDir, const std::string &netlibDir) |
Instantiation of OsiClpSolverInterface for the Model Algorithm.
It has a trivial branch and bound code for completeness. It would be an interesting project to expand it and move it to base class.
Definition at line 35 of file OsiClpSolverInterface.hpp.
|
Add a column (primal variable) to the problem. Implements OsiSolverInterface. Definition at line 844 of file OsiClpSolverInterface.cpp. References basis_, freeCachedResults(), integerInformation_, linearObjective_, modelPtr_, CoinWarmStartBasis::resize(), setColBounds(), and setObjCoeff().
00847 { 00848 int numberColumns = modelPtr_->numberColumns(); 00849 modelPtr_->resize(modelPtr_->numberRows(),numberColumns+1); 00850 linearObjective_ = modelPtr_->objective(); 00851 basis_.resize(modelPtr_->numberRows(),numberColumns+1); 00852 setColBounds(numberColumns,collb,colub); 00853 setObjCoeff(numberColumns,obj); 00854 if (!modelPtr_->clpMatrix()) 00855 modelPtr_->createEmptyMatrix(); 00856 modelPtr_->matrix()->appendCol(vec); 00857 if (integerInformation_) { 00858 char * temp = new char[numberColumns+1]; 00859 memcpy(temp,integerInformation_,numberColumns*sizeof(char)); 00860 delete [] integerInformation_; 00861 integerInformation_ = temp; 00862 integerInformation_[numberColumns]=0; 00863 } 00864 freeCachedResults(); 00865 } |
|
Add a set of columns (primal variables) to the problem. The default implementation simply makes repeated calls to addCol(). Reimplemented from OsiSolverInterface. Definition at line 868 of file OsiClpSolverInterface.cpp. References basis_, OsiSolverInterface::forceIntoRange(), freeCachedResults(), integerInformation_, linearObjective_, modelPtr_, and CoinWarmStartBasis::resize().
00872 { 00873 int numberColumns = modelPtr_->numberColumns(); 00874 modelPtr_->resize(modelPtr_->numberRows(),numberColumns+numcols); 00875 linearObjective_ = modelPtr_->objective(); 00876 basis_.resize(modelPtr_->numberRows(),numberColumns+numcols); 00877 double * lower = modelPtr_->columnLower()+numberColumns; 00878 double * upper = modelPtr_->columnUpper()+numberColumns; 00879 double * objective = modelPtr_->objective()+numberColumns; 00880 int iCol; 00881 for (iCol = 0; iCol < numcols; iCol++) { 00882 lower[iCol]= forceIntoRange(collb[iCol], -OsiClpInfinity, OsiClpInfinity); 00883 upper[iCol]= forceIntoRange(colub[iCol], -OsiClpInfinity, OsiClpInfinity); 00884 objective[iCol] = obj[iCol]; 00885 } 00886 if (!modelPtr_->clpMatrix()) 00887 modelPtr_->createEmptyMatrix(); 00888 modelPtr_->matrix()->appendCols(numcols,cols); 00889 if (integerInformation_) { 00890 char * temp = new char[numberColumns+numcols]; 00891 memcpy(temp,integerInformation_,numberColumns*sizeof(char)); 00892 delete [] integerInformation_; 00893 integerInformation_ = temp; 00894 for (iCol = 0; iCol < numcols; iCol++) 00895 integerInformation_[numberColumns+iCol]=0; 00896 } 00897 freeCachedResults(); 00898 } |
|
Add a row (constraint) to the problem. Implements OsiSolverInterface. Definition at line 910 of file OsiClpSolverInterface.cpp. References basis_, freeCachedResults(), modelPtr_, CoinWarmStartBasis::resize(), and setRowBounds(). Referenced by applyRowCut().
00912 { 00913 int numberRows = modelPtr_->numberRows(); 00914 modelPtr_->resize(numberRows+1,modelPtr_->numberColumns()); 00915 basis_.resize(numberRows+1,modelPtr_->numberColumns()); 00916 setRowBounds(numberRows,rowlb,rowub); 00917 if (!modelPtr_->clpMatrix()) 00918 modelPtr_->createEmptyMatrix(); 00919 modelPtr_->matrix()->appendRow(vec); 00920 freeCachedResults(); 00921 } |
|
Add a set of rows (constraints) to the problem. The default implementation simply makes repeated calls to addRow(). Reimplemented from OsiSolverInterface. Definition at line 962 of file OsiClpSolverInterface.cpp. References basis_, OsiSolverInterface::convertSenseToBound(), OsiSolverInterface::forceIntoRange(), freeCachedResults(), modelPtr_, and CoinWarmStartBasis::resize().
00966 { 00967 int numberRows = modelPtr_->numberRows(); 00968 modelPtr_->resize(numberRows+numrows,modelPtr_->numberColumns()); 00969 basis_.resize(numberRows+numrows,modelPtr_->numberColumns()); 00970 double * lower = modelPtr_->rowLower()+numberRows; 00971 double * upper = modelPtr_->rowUpper()+numberRows; 00972 int iRow; 00973 for (iRow = 0; iRow < numrows; iRow++) { 00974 double rowlb, rowub; 00975 convertSenseToBound(rowsen[iRow], rowrhs[iRow], rowrng[iRow], 00976 rowlb, rowub); 00977 lower[iRow]= forceIntoRange(rowlb, -OsiClpInfinity, OsiClpInfinity); 00978 upper[iRow]= forceIntoRange(rowub, -OsiClpInfinity, OsiClpInfinity); 00979 } 00980 if (!modelPtr_->clpMatrix()) 00981 modelPtr_->createEmptyMatrix(); 00982 modelPtr_->matrix()->appendRows(numrows,rows); 00983 freeCachedResults(); 00984 } |
|
Add a set of rows (constraints) to the problem. The default implementation simply makes repeated calls to addRow(). Reimplemented from OsiSolverInterface. Definition at line 941 of file OsiClpSolverInterface.cpp. References basis_, OsiSolverInterface::forceIntoRange(), freeCachedResults(), modelPtr_, and CoinWarmStartBasis::resize(). Referenced by applyRowCuts().
00944 { 00945 int numberRows = modelPtr_->numberRows(); 00946 modelPtr_->resize(numberRows+numrows,modelPtr_->numberColumns()); 00947 basis_.resize(numberRows+numrows,modelPtr_->numberColumns()); 00948 double * lower = modelPtr_->rowLower()+numberRows; 00949 double * upper = modelPtr_->rowUpper()+numberRows; 00950 int iRow; 00951 for (iRow = 0; iRow < numrows; iRow++) { 00952 lower[iRow]= forceIntoRange(rowlb[iRow], -OsiClpInfinity, OsiClpInfinity); 00953 upper[iRow]= forceIntoRange(rowub[iRow], -OsiClpInfinity, OsiClpInfinity); 00954 } 00955 if (!modelPtr_->clpMatrix()) 00956 modelPtr_->createEmptyMatrix(); 00957 modelPtr_->matrix()->appendRows(numrows,rows); 00958 freeCachedResults(); 00959 } |
|
Apply a column cut (adjust one or more bounds). Implements OsiSolverInterface. Definition at line 1365 of file OsiClpSolverInterface.cpp. References CoinPackedVector::getElements(), CoinPackedVector::getIndices(), CoinPackedVector::getNumElements(), OsiColCut::lbs(), modelPtr_, and OsiColCut::ubs().
01366 { 01367 double * lower = modelPtr_->columnLower(); 01368 double * upper = modelPtr_->columnUpper(); 01369 const CoinPackedVector & lbs = cc.lbs(); 01370 const CoinPackedVector & ubs = cc.ubs(); 01371 int i; 01372 01373 for ( i=0; i<lbs.getNumElements(); i++ ) { 01374 int iCol = lbs.getIndices()[i]; 01375 double value = lbs.getElements()[i]; 01376 if ( value > lower[iCol] ) 01377 lower[iCol]= value; 01378 } 01379 for ( i=0; i<ubs.getNumElements(); i++ ) { 01380 int iCol = ubs.getIndices()[i]; 01381 double value = ubs.getElements()[i]; 01382 if ( value < upper[iCol] ) 01383 upper[iCol]= value; 01384 } 01385 } |
|
Apply a row cut (append to constraint matrix). Implements OsiSolverInterface. Definition at line 1328 of file OsiClpSolverInterface.cpp. References addRow(), OsiRowCut::lb(), OsiRowCut::row(), and OsiRowCut::ub().
01329 { 01330 const CoinPackedVector & row=rowCut.row(); 01331 addRow(row , rowCut.lb(),rowCut.ub()); 01332 } |
|
Apply a collection of row cuts which are all effective. applyCuts seems to do one at a time which seems inefficient. Reimplemented from OsiSolverInterface. Definition at line 1337 of file OsiClpSolverInterface.cpp. References addRows(), getNumElements(), CoinPackedVectorBase::getNumElements(), getNumRows(), and OsiRowCut::lb().
01338 { 01339 int i; 01340 if (!numberCuts) 01341 return; 01342 01343 const CoinPackedVectorBase * * rows 01344 = new const CoinPackedVectorBase * [numberCuts]; 01345 double * rowlb = new double [numberCuts]; 01346 double * rowub = new double [numberCuts]; 01347 for (i=0;i<numberCuts;i++) { 01348 rowlb[i] = cuts[i].lb(); 01349 rowub[i] = cuts[i].ub(); 01350 rows[i] = &cuts[i].row(); 01351 #ifdef TAKEOUT 01352 if (rows[i]->getNumElements()==10||rows[i]->getNumElements()==15) 01353 printf("ApplyCuts %d size %d\n",getNumRows()+i,rows[i]->getNumElements()); 01354 #endif 01355 } 01356 addRows(numberCuts,rows,rowlb,rowub); 01357 delete [] rows; 01358 delete [] rowlb; 01359 delete [] rowub; 01360 01361 } |
|
Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by sense/rhs/range triplets). For default values see the previous method. Implements OsiSolverInterface. Definition at line 1057 of file OsiClpSolverInterface.cpp. References linearObjective_, loadProblem(), and modelPtr_.
01062 { 01063 loadProblem(*matrix, collb, colub, obj, rowsen, rowrhs, rowrng); 01064 linearObjective_ = modelPtr_->objective(); 01065 delete matrix; matrix = NULL; 01066 delete[] collb; collb = NULL; 01067 delete[] colub; colub = NULL; 01068 delete[] obj; obj = NULL; 01069 delete[] rowsen; rowsen = NULL; 01070 delete[] rowrhs; rowrhs = NULL; 01071 delete[] rowrng; rowrng = NULL; 01072 } |
|
Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by lower and upper bounds). For default values see the previous method. Implements OsiSolverInterface. Definition at line 1013 of file OsiClpSolverInterface.cpp. References freeCachedResults(), linearObjective_, and modelPtr_.
01017 { 01018 modelPtr_->loadProblem(*matrix, collb, colub, obj, rowlb, rowub); 01019 linearObjective_ = modelPtr_->objective(); 01020 01021 freeCachedResults(); 01022 delete matrix; matrix = NULL; 01023 delete[] collb; collb = NULL; 01024 delete[] colub; colub = NULL; 01025 delete[] obj; obj = NULL; 01026 delete[] rowlb; rowlb = NULL; 01027 delete[] rowub; rowub = NULL; 01028 } |
|
Remove a set of columns (primal variables) from the problem. Implements OsiSolverInterface. Definition at line 901 of file OsiClpSolverInterface.cpp. References basis_, CoinWarmStartBasis::deleteColumns(), freeCachedResults(), linearObjective_, and modelPtr_.
00902 { 00903 modelPtr_->deleteColumns(num,columnIndices); 00904 basis_.deleteColumns(num,columnIndices); 00905 linearObjective_ = modelPtr_->objective(); 00906 freeCachedResults(); 00907 } |
|
Delete a set of rows (constraints) from the problem. Implements OsiSolverInterface. Definition at line 987 of file OsiClpSolverInterface.cpp. References basis_, CoinWarmStartBasis::deleteRows(), freeCachedResults(), and modelPtr_.
00988 { 00989 modelPtr_->deleteRows(num,rowIndices); 00990 basis_.deleteRows(num,rowIndices); 00991 freeCachedResults(); 00992 } |
|
Obtain a result of the dual pivot (similar to the previous method) Differences: entering variable and a sign of its change are now the outputs, the leaving variable and its statuts -- the inputs If dx!=NULL, then *dx contains dual ray Return code: same Implements OsiSimplexInterface. Definition at line 1883 of file OsiClpSolverInterface.cpp. References modelPtr_.
01886 { 01887 assert (modelPtr_->solveType()==2); 01888 abort(); 01889 return 0; 01890 } |
|
Enables normal operation of subsequent functions. This method is supposed to ensure that all typical things (like reduced costs, etc.) are updated when individual pivots are executed and can be queried by other methods Reimplemented from OsiSimplexInterface. Definition at line 1646 of file OsiClpSolverInterface.cpp. References modelPtr_, and saveData_.
01647 { 01648 assert (modelPtr_->solveType()==1); 01649 modelPtr_->setSolveType(2); 01650 if (doingPrimal) 01651 modelPtr_->setAlgorithm(1); 01652 else 01653 modelPtr_->setAlgorithm(-1); 01654 modelPtr_->scaling(0); 01655 // Do initialization 01656 saveData_ = modelPtr_->saveData(); 01657 // set infeasibility cost up 01658 modelPtr_->setInfeasibilityCost(1.0e12); 01659 // probably should save and restore? 01660 ClpDualRowDantzig dantzig; 01661 modelPtr_->setDualRowPivotAlgorithm(dantzig); 01662 ClpPrimalColumnDantzig dantzigP; 01663 modelPtr_->setPrimalColumnPivotAlgorithm(dantzigP); 01664 assert (!modelPtr_->startup(0)); 01665 } |
|
Get basic indices (order of indices corresponds to the order of elements in a vector retured by getBInvACol() and getBInvCol()). Implements OsiSimplexInterface. Definition at line 2013 of file OsiClpSolverInterface.cpp. References modelPtr_.
|
|
The following two methods may be replaced by the methods of OsiSolverInterface using OsiWarmStartBasis if: 1. OsiWarmStartBasis resize operation is implemented more efficiently and 2. It is ensured that effects on the solver are the same Returns a basis status of the structural/artificial variables At present as warm start i.e 0 free, 1 basic, 2 upper, 3 lower Implements OsiSimplexInterface. Definition at line 1688 of file OsiClpSolverInterface.cpp. References modelPtr_.
01689 { 01690 assert (modelPtr_->solveType()==2); 01691 int i, n; 01692 n=modelPtr_->numberRows(); 01693 int lookup[]={0,1,2,3,0,3}; 01694 for (i=0;i<n;i++) 01695 rstat[i] = lookup[modelPtr_->getRowStatus(i)]; 01696 n=modelPtr_->numberColumns(); 01697 for (i=0;i<n;i++) 01698 cstat[i] = lookup[modelPtr_->getColumnStatus(i)]; 01699 } |
|
Get as many dual rays as the solver can provide. (In case of proven primal infeasibility there should be at least one.)
NOTE for implementers of solver interfaces:
NOTE for users of solver interfaces: Implements OsiSolverInterface. Definition at line 669 of file OsiClpSolverInterface.cpp. References modelPtr_.
00670 { 00671 return std::vector<double*>(1, modelPtr_->infeasibilityRay()); 00672 } |
|
Get an empty warm start object. This routine returns an empty CoinWarmStartBasis object. Its purpose is to provide a way to give a client a warm start basis object of the appropriate type, which can resized and modified as desired. Implements OsiSolverInterface. Definition at line 528 of file OsiClpSolverInterface.cpp.
00529 { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; } |
|
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver. Implements OsiSolverInterface. Definition at line 351 of file OsiClpSolverInterface.hpp. References modelPtr_.
00352 { return modelPtr_->numberIterations(); } |
|
Get as many primal rays as the solver can provide. (In case of proven dual infeasibility there should be at least one.)
NOTE for implementers of solver interfaces:
NOTE for users of solver interfaces: Implements OsiSolverInterface. Definition at line 674 of file OsiClpSolverInterface.cpp. References modelPtr_.
00675 { 00676 return std::vector<double*>(1, modelPtr_->unboundedRay()); 00677 } |
|
Get pointer to array[getNumRows()] of rows right-hand sides
Implements OsiSolverInterface. Definition at line 621 of file OsiClpSolverInterface.cpp. References extractSenseRhsRange(), and rhs_.
00622 { 00623 extractSenseRhsRange(); 00624 return rhs_; 00625 } |
|
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vector Implements OsiSolverInterface. Definition at line 1583 of file OsiClpSolverInterface.cpp. References modelPtr_.
|
|
Get pointer to array[getNumRows()] of row ranges.
Implements OsiSolverInterface. Definition at line 627 of file OsiClpSolverInterface.cpp. References extractSenseRhsRange(), and rowrange_.
00628 { 00629 extractSenseRhsRange(); 00630 return rowrange_; 00631 } |
|
Get pointer to array[getNumRows()] of row constraint senses.
Implements OsiSolverInterface. Definition at line 615 of file OsiClpSolverInterface.cpp. References extractSenseRhsRange(), and rowsense_.
00616 { 00617 extractSenseRhsRange(); 00618 return rowsense_; 00619 } |
|
Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). Implements OsiSolverInterface. Definition at line 1093 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::convertSenseToBound(), freeCachedResults(), linearObjective_, and modelPtr_.
01100 { 01101 assert( rowsen != NULL ); 01102 assert( rowrhs != NULL ); 01103 double * rowlb = new double[numrows]; 01104 double * rowub = new double[numrows]; 01105 for (int i = numrows-1; i >= 0; --i) { 01106 convertSenseToBound(rowsen[i],rowrhs[i],rowrng[i],rowlb[i],rowub[i]); 01107 } 01108 modelPtr_->loadProblem(numcols, numrows, start, index, 01109 value, collb, colub, obj, 01110 rowlb, rowub); 01111 linearObjective_ = modelPtr_->objective(); 01112 freeCachedResults(); 01113 delete[] rowlb; 01114 delete[] rowub; 01115 } |
|
Just like the other loadProblem() methods except that the matrix is given in a standard column major ordered format (without gaps). Implements OsiSolverInterface. Definition at line 1077 of file OsiClpSolverInterface.cpp. References freeCachedResults(), linearObjective_, and modelPtr_.
01083 { 01084 modelPtr_->loadProblem(numcols, numrows, start, index, 01085 value, collb, colub, obj, 01086 rowlb, rowub); 01087 linearObjective_ = modelPtr_->objective(); 01088 freeCachedResults(); 01089 } |
|
Load in an problem by copying the arguments (the constraints on the rows are given by sense/rhs/range triplets). If a pointer is 0 then the following values are the default:
Implements OsiSolverInterface. Definition at line 1033 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::convertSenseToBound(), freeCachedResults(), linearObjective_, and modelPtr_.
01038 { 01039 assert( rowsen != NULL ); 01040 assert( rowrhs != NULL ); 01041 int numrows = matrix.getNumRows(); 01042 double * rowlb = new double[numrows]; 01043 double * rowub = new double[numrows]; 01044 for (int i = numrows-1; i >= 0; --i) { 01045 convertSenseToBound(rowsen[i],rowrhs[i],rowrng[i],rowlb[i],rowub[i]); 01046 } 01047 modelPtr_->loadProblem(matrix, collb, colub, obj, rowlb, rowub); 01048 linearObjective_ = modelPtr_->objective(); 01049 freeCachedResults(); 01050 delete [] rowlb; 01051 delete [] rowub; 01052 } |
|
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper bounds). If a pointer is 0 then the following values are the default:
Implements OsiSolverInterface. Definition at line 999 of file OsiClpSolverInterface.cpp. References freeCachedResults(), linearObjective_, and modelPtr_. Referenced by assignProblem().
01003 { 01004 modelPtr_->loadProblem(matrix, collb, colub, obj, rowlb, rowub); 01005 linearObjective_ = modelPtr_->objective(); 01006 freeCachedResults(); 01007 01008 } |
|
Perform a pivot by substituting a colIn for colOut in the basis. The status of the leaving variable is given in statOut. Where 1 is to upper bound, -1 to lower bound Implements OsiSimplexInterface. Definition at line 1816 of file OsiClpSolverInterface.cpp. References modelPtr_.
01817 { 01818 assert (modelPtr_->solveType()==2); 01819 // convert to Clp style (what about flips?) 01820 if (colIn<0) 01821 colIn = modelPtr_->numberColumns()+(-1-colIn); 01822 if (colOut<0) 01823 colOut = modelPtr_->numberColumns()+(-1-colOut); 01824 // in clp direction of out is reversed 01825 outStatus = - outStatus; 01826 // set in clp 01827 modelPtr_->setDirectionOut(outStatus); 01828 modelPtr_->setSequenceIn(colIn); 01829 modelPtr_->setSequenceOut(colOut); 01830 // do pivot 01831 modelPtr_->pivot(); 01832 return 0; 01833 } |
|
Obtain a result of the primal pivot Outputs: colOut -- leaving column, outStatus -- its status, t -- step size, and, if dx!=NULL, *dx -- primal ray direction. Inputs: colIn -- entering column, sign -- direction of its change (+/-1). Both for colIn and colOut, artificial variables are index by the negative of the row index minus 1. Return code (for now): 0 -- leaving variable found, -1 -- everything else? Clearly, more informative set of return values is required Implements OsiSimplexInterface. Definition at line 1846 of file OsiClpSolverInterface.cpp. References modelPtr_, and CoinPackedVector::setFullNonZero().
01849 { 01850 assert (modelPtr_->solveType()==2); 01851 // convert to Clp style 01852 if (colIn<0) 01853 colIn = modelPtr_->numberColumns()+(-1-colIn); 01854 // set in clp 01855 modelPtr_->setDirectionIn(sign); 01856 modelPtr_->setSequenceIn(colIn); 01857 modelPtr_->setSequenceOut(-1); 01858 int returnCode = modelPtr_->primalPivotResult(); 01859 t = modelPtr_->theta(); 01860 int numberColumns = modelPtr_->numberColumns(); 01861 if (dx) { 01862 double * ray = modelPtr_->unboundedRay(); 01863 if (ray) 01864 dx->setFullNonZero(numberColumns,ray); 01865 else 01866 printf("No ray?\n"); 01867 delete [] ray; 01868 } 01869 outStatus = - modelPtr_->directionOut(); 01870 colOut = modelPtr_->sequenceOut(); 01871 if (colOut>= numberColumns) 01872 colOut = -1-(colOut - numberColumns); 01873 return returnCode; 01874 } |
|
Read an mps file from the given filename (defaults to Osi reader) - returns number of errors (see OsiMpsReader class) Reimplemented from OsiSolverInterface. Definition at line 1517 of file OsiClpSolverInterface.cpp. References integerInformation_, OsiSolverInterface::isInteger(), modelPtr_, and OsiSolverInterface::readMps().
01519 { 01520 // Get rid of integer stuff 01521 delete [] integerInformation_; 01522 integerInformation_=NULL; 01523 01524 int numberErrors = OsiSolverInterface::readMps(filename,extension); 01525 // move across integer information 01526 int numberColumns = modelPtr_->numberColumns(); 01527 int i; 01528 char * info = new char [numberColumns]; 01529 int numberIntegers=0; 01530 for (i=0;i<numberColumns;i++) { 01531 if (isInteger(i)) { 01532 info[i]=1; 01533 numberIntegers++; 01534 } else { 01535 info[i]=0; 01536 } 01537 } 01538 if (numberIntegers) 01539 modelPtr_->copyInIntegerInformation(info); 01540 delete [] info; 01541 return numberErrors; 01542 } |
|
Set the status of structural/artificial variables and factorize, update solution etc Implements OsiSimplexInterface. Definition at line 1703 of file OsiClpSolverInterface.cpp. References modelPtr_.
01704 { 01705 assert (modelPtr_->solveType()==2); 01706 modelPtr_->createStatus(); 01707 int i, n; 01708 double * lower, * upper, * solution; 01709 n=modelPtr_->numberRows(); 01710 lower = modelPtr_->rowLower(); 01711 upper = modelPtr_->rowUpper(); 01712 solution = modelPtr_->primalRowSolution(); 01713 for (i=0;i<n;i++) { 01714 int status = rstat[i]; 01715 if (status<0||status>3) 01716 status = 3; 01717 if (lower[i]<-1.0e50&&upper[i]>1.0e50&&status!=1) 01718 status = 0; // set free if should be 01719 else if (lower[i]<-1.0e50&&status==3) 01720 status = 2; // can't be at lower bound 01721 else if (upper[i]>1.0e50&&status==2) 01722 status = 3; // can't be at upper bound 01723 switch (status) { 01724 // free or superbasic 01725 case 0: 01726 if (lower[i]<-1.0e50&&upper[i]>1.0e50) { 01727 modelPtr_->setRowStatus(i,ClpSimplex::isFree); 01728 if (fabs(solution[i])>1.0e20) 01729 solution[i]=0.0; 01730 } else { 01731 modelPtr_->setRowStatus(i,ClpSimplex::superBasic); 01732 if (fabs(solution[i])>1.0e20) 01733 solution[i]=0.0; 01734 } 01735 break; 01736 case 1: 01737 // basic 01738 modelPtr_->setRowStatus(i,ClpSimplex::basic); 01739 break; 01740 case 2: 01741 // at upper bound 01742 solution[i]=upper[i]; 01743 if (upper[i]>lower[i]) 01744 modelPtr_->setRowStatus(i,ClpSimplex::atUpperBound); 01745 else 01746 modelPtr_->setRowStatus(i,ClpSimplex::isFixed); 01747 break; 01748 case 3: 01749 // at lower bound 01750 solution[i]=lower[i]; 01751 if (upper[i]>lower[i]) 01752 modelPtr_->setRowStatus(i,ClpSimplex::atLowerBound); 01753 else 01754 modelPtr_->setRowStatus(i,ClpSimplex::isFixed); 01755 break; 01756 } 01757 } 01758 n=modelPtr_->numberColumns(); 01759 lower = modelPtr_->columnLower(); 01760 upper = modelPtr_->columnUpper(); 01761 solution = modelPtr_->primalColumnSolution(); 01762 for (i=0;i<n;i++) { 01763 int status = cstat[i]; 01764 if (status<0||status>3) 01765 status = 3; 01766 if (lower[i]<-1.0e50&&upper[i]>1.0e50&&status!=1) 01767 status = 0; // set free if should be 01768 else if (lower[i]<-1.0e50&&status==3) 01769 status = 2; // can't be at lower bound 01770 else if (upper[i]>1.0e50&&status==2) 01771 status = 3; // can't be at upper bound 01772 switch (status) { 01773 // free or superbasic 01774 case 0: 01775 if (lower[i]<-1.0e50&&upper[i]>1.0e50) { 01776 modelPtr_->setColumnStatus(i,ClpSimplex::isFree); 01777 if (fabs(solution[i])>1.0e20) 01778 solution[i]=0.0; 01779 } else { 01780 modelPtr_->setColumnStatus(i,ClpSimplex::superBasic); 01781 if (fabs(solution[i])>1.0e20) 01782 solution[i]=0.0; 01783 } 01784 break; 01785 case 1: 01786 // basic 01787 modelPtr_->setColumnStatus(i,ClpSimplex::basic); 01788 break; 01789 case 2: 01790 // at upper bound 01791 solution[i]=upper[i]; 01792 if (upper[i]>lower[i]) 01793 modelPtr_->setColumnStatus(i,ClpSimplex::atUpperBound); 01794 else 01795 modelPtr_->setColumnStatus(i,ClpSimplex::isFixed); 01796 break; 01797 case 3: 01798 // at lower bound 01799 solution[i]=lower[i]; 01800 if (upper[i]>lower[i]) 01801 modelPtr_->setColumnStatus(i,ClpSimplex::atLowerBound); 01802 else 01803 modelPtr_->setColumnStatus(i,ClpSimplex::isFixed); 01804 break; 01805 } 01806 } 01807 modelPtr_->statusOfProblem(); 01808 return 0; 01809 } |
|
Set a single column lower and upper bound Reimplemented from OsiSolverInterface. Definition at line 1629 of file OsiClpSolverInterface.cpp. References modelPtr_. Referenced by addCol().
01631 { 01632 modelPtr_->columnLower()[elementIndex] = lower; 01633 modelPtr_->columnUpper()[elementIndex] = upper; 01634 if (modelPtr_->solveType()==2) { 01635 // simplex interface 01636 modelPtr_->lowerRegion(1)[elementIndex] = lower; 01637 modelPtr_->upperRegion(1)[elementIndex] = upper; 01638 } 01639 } |
|
Set a single column lower bound Implements OsiSolverInterface. Definition at line 1606 of file OsiClpSolverInterface.cpp. References modelPtr_.
|
|
Set the bounds on a number of columns simultaneously
Reimplemented from OsiSolverInterface. Definition at line 681 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::forceIntoRange(), and modelPtr_.
00684 { 00685 double * lower = modelPtr_->columnLower(); 00686 double * upper = modelPtr_->columnUpper(); 00687 while (indexFirst != indexLast) { 00688 const int iCol=*indexFirst++; 00689 lower[iCol]= forceIntoRange(*boundList++, -OsiClpInfinity, OsiClpInfinity); 00690 upper[iCol]= forceIntoRange(*boundList++, -OsiClpInfinity, OsiClpInfinity); 00691 } 00692 if (modelPtr_->solveType()==2) { 00693 // directly into code as well 00694 double * lower = modelPtr_->lowerRegion(1); 00695 double * upper = modelPtr_->upperRegion(1); 00696 while (indexFirst != indexLast) { 00697 const int iCol=*indexFirst++; 00698 lower[iCol]= forceIntoRange(*boundList++, -OsiClpInfinity, OsiClpInfinity); 00699 upper[iCol]= forceIntoRange(*boundList++, -OsiClpInfinity, OsiClpInfinity); 00700 } 00701 00702 } 00703 } |
|
Set the primal solution column values colsol[numcols()] is an array of values of the problem column variables. These values are copied to memory owned by the solver object or the solver. They will be returned as the result of colsol() until changed by another call to setColsol() or by a call to any solver routine. Whether the solver makes use of the solution in any way is solver-dependent. Implements OsiSolverInterface. Definition at line 818 of file OsiClpSolverInterface.cpp. References modelPtr_.
|
|
Set a single column upper bound Implements OsiSolverInterface. Definition at line 1618 of file OsiClpSolverInterface.cpp. References modelPtr_.
|
|
Set the variables listed in indices (which is of length len) to be continuous variables Reimplemented from OsiSolverInterface. Definition at line 795 of file OsiClpSolverInterface.cpp. References integerInformation_.
00796 { 00797 if (integerInformation_) { 00798 int i; 00799 for (i=0; i<len;i++) { 00800 integerInformation_[i]=0; 00801 } 00802 } 00803 } |
|
Set the index-th variable to be a continuous variable Implements OsiSolverInterface. Definition at line 776 of file OsiClpSolverInterface.cpp. References integerInformation_.
00777 { 00778 00779 if (integerInformation_) { 00780 integerInformation_[index]=0; 00781 } 00782 } |
|
Set the variables listed in indices (which is of length len) to be integer variables Reimplemented from OsiSolverInterface. Definition at line 806 of file OsiClpSolverInterface.cpp. References integerInformation_, and modelPtr_.
00807 { 00808 if (!integerInformation_) { 00809 integerInformation_ = new char[modelPtr_->numberColumns()]; 00810 CoinFillN ( integerInformation_, modelPtr_->numberColumns(),(char) 0); 00811 } 00812 int i; 00813 for (i=0; i<len;i++) { 00814 integerInformation_[indices[i]]=1; 00815 } 00816 } |
|
Set the index-th variable to be an integer variable Implements OsiSolverInterface. Definition at line 785 of file OsiClpSolverInterface.cpp. References integerInformation_, and modelPtr_.
00786 { 00787 if (!integerInformation_) { 00788 integerInformation_ = new char[modelPtr_->numberColumns()]; 00789 CoinFillN ( integerInformation_, modelPtr_->numberColumns(),(char) 0); 00790 } 00791 integerInformation_[index]=1; 00792 } |
|
Set an objective function coefficient Implements OsiSolverInterface. Definition at line 1594 of file OsiClpSolverInterface.cpp. References linearObjective_, and modelPtr_. Referenced by addCol().
01595 { 01596 linearObjective_[elementIndex] = elementValue; 01597 if (modelPtr_->solveType()==2) { 01598 // simplex interface 01599 modelPtr_->costRegion(1)[elementIndex] = elementValue; 01600 } 01601 } |
|
Set a new objective and apply the old basis so that the reduced costs are properly updated Implements OsiSimplexInterface. Definition at line 1917 of file OsiClpSolverInterface.cpp. References modelPtr_.
|
|
Set a single row lower and upper bound Reimplemented from OsiSolverInterface. Definition at line 429 of file OsiClpSolverInterface.hpp. References modelPtr_. Referenced by addRow(), and setRowType().
|
|
Set a single row lower bound Implements OsiSolverInterface. Definition at line 418 of file OsiClpSolverInterface.hpp. References modelPtr_.
00418 { 00419 modelPtr_->rowLower()[elementIndex] = elementValue; 00420 } |
|
Set dual solution vector rowprice[numrows()] is an array of values of the problem row dual variables. These values are copied to memory owned by the solver object or the solver. They will be returned as the result of rowprice() until changed by another call to setRowprice() or by a call to any solver routine. Whether the solver makes use of the solution in any way is solver-dependent. Implements OsiSolverInterface. Definition at line 829 of file OsiClpSolverInterface.cpp. References modelPtr_.
|
|
Set the bounds on a number of rows simultaneously
Reimplemented from OsiSolverInterface. Definition at line 715 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::convertBoundToSense(), OsiSolverInterface::forceIntoRange(), modelPtr_, rhs_, rowrange_, and rowsense_.
00718 { 00719 double * lower = modelPtr_->rowLower(); 00720 double * upper = modelPtr_->rowUpper(); 00721 const int len = indexLast - indexFirst; 00722 while (indexFirst != indexLast) { 00723 const int iRow=*indexFirst++; 00724 lower[iRow]= forceIntoRange(*boundList++, -OsiClpInfinity, OsiClpInfinity); 00725 upper[iRow]= forceIntoRange(*boundList++, -OsiClpInfinity, OsiClpInfinity); 00726 } 00727 if (rowsense_ != NULL) { 00728 assert ((rhs_ != NULL) && (rowrange_ != NULL)); 00729 indexFirst -= len; 00730 while (indexFirst != indexLast) { 00731 const int iRow=*indexFirst++; 00732 convertBoundToSense(lower[iRow], upper[iRow], 00733 rowsense_[iRow], rhs_[iRow], rowrange_[iRow]); 00734 } 00735 } 00736 } |
|
Set the type of a number of rows simultaneously
Reimplemented from OsiSolverInterface. Definition at line 739 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::convertSenseToBound(), modelPtr_, rhs_, rowrange_, and rowsense_.
00744 { 00745 double * lower = modelPtr_->rowLower(); 00746 double * upper = modelPtr_->rowUpper(); 00747 const int len = indexLast - indexFirst; 00748 while (indexFirst != indexLast) { 00749 const int iRow= *indexFirst++; 00750 if (rangeList){ 00751 convertSenseToBound(*senseList++, *rhsList++, *rangeList++, 00752 lower[iRow], upper[iRow]); 00753 } else { 00754 convertSenseToBound(*senseList++, *rhsList++, 0, 00755 lower[iRow], upper[iRow]); 00756 } 00757 } 00758 if (rowsense_ != NULL) { 00759 assert ((rhs_ != NULL) && (rowrange_ != NULL)); 00760 indexFirst -= len; 00761 senseList -= len; 00762 rhsList -= len; 00763 if (rangeList) 00764 rangeList -= len; 00765 while (indexFirst != indexLast) { 00766 const int iRow=*indexFirst++; 00767 rowsense_[iRow] = *senseList++; 00768 rhs_[iRow] = *rhsList++; 00769 if (rangeList) 00770 rowrange_[iRow] = *rangeList++; 00771 } 00772 } 00773 } |
|
Set the type of a single row Implements OsiSolverInterface. Definition at line 706 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::convertSenseToBound(), and setRowBounds().
00708 { 00709 // *TEST* 00710 double lower, upper; 00711 convertSenseToBound(sense, rightHandSide, range, lower, upper); 00712 setRowBounds(i, lower, upper); 00713 } |
|
Set a single row upper bound Implements OsiSolverInterface. Definition at line 424 of file OsiClpSolverInterface.hpp. References modelPtr_.
00424 { 00425 modelPtr_->rowUpper()[elementIndex] = elementValue; 00426 } |
|
Set warmstarting information. Return true/false depending on whether the warmstart information was accepted or not. Implements OsiSolverInterface. Definition at line 539 of file OsiClpSolverInterface.cpp. References basis_. Referenced by solveFromHotStart().
00540 { 00541 00542 const CoinWarmStartBasis* ws = 00543 dynamic_cast<const CoinWarmStartBasis*>(warmstart); 00544 00545 if (! ws) 00546 return false; 00547 basis_ = CoinWarmStartBasis(*ws); 00548 return true; 00549 00550 } |
|
Write the problem into an mps file of the given filename. If objSense is non zero then -1.0 forces the code to write a maximization objective and +1.0 to write a minimization one. If 0.0 then solver can do what it wants Implements OsiSolverInterface. Definition at line 1121 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::writeMpsNative().
01124 { 01125 std::string f(filename); 01126 std::string e(extension); 01127 std::string fullname; 01128 if (e!="") { 01129 fullname = f + "." + e; 01130 } else { 01131 // no extension so no trailing period 01132 fullname = f; 01133 } 01134 // Fall back on Osi version - without names 01135 OsiSolverInterface::writeMpsNative(fullname.c_str(), 01136 NULL, NULL,0,2,objSense); 01137 } |
|
Write the problem into an mps file of the given filename, names may be null. formatType is 0 - normal 1 - extra accuracy 2 - IEEE hex (later) Returns non-zero on I/O error Reimplemented from OsiSolverInterface. Definition at line 1140 of file OsiClpSolverInterface.cpp. References OsiSolverInterface::writeMpsNative().
01143 { 01144 return OsiSolverInterface::writeMpsNative(filename, rowNames, columnNames, 01145 formatType, numberAcross,objSense); 01146 } |
|
A function that tests the methods in the OsiClpSolverInterface class. The only reason for it not to be a member method is that this way it doesn't have to be compiled into the library. And that's a gain, because the library should be compiled with optimization on, but this method should be compiled with debugging. Also, if this method is compiled with optimization, the compilation takes 10-15 minutes and the machine pages (has 256M core memory!)... Definition at line 51 of file OsiClpSolverInterfaceTest.cpp.
00052 { 00053 00054 // Test default constructor 00055 { 00056 OsiClpSolverInterface m; 00057 assert( m.rowsense_==NULL ); 00058 assert( m.rhs_==NULL ); 00059 assert( m.rowrange_==NULL ); 00060 assert( m.matrixByRow_==NULL ); 00061 assert( m.ws_==NULL); 00062 assert( m.itlimOrig_==9999999); 00063 assert( m.lastAlgorithm_==0); 00064 assert( m.integerInformation_==NULL); 00065 } 00066 00067 00068 { 00069 CoinRelFltEq eq; 00070 OsiClpSolverInterface m; 00071 std::string fn = mpsDir+"exmip1"; 00072 m.readMps(fn.c_str(),"mps"); 00073 00074 { 00075 OsiClpSolverInterface im; 00076 00077 assert( im.getNumCols() == 0 ); 00078 00079 assert( im.getModelPtr()!=NULL ); 00080 // Test reset 00081 im.reset(); 00082 assert( im.rowsense_==NULL ); 00083 assert( im.rhs_==NULL ); 00084 assert( im.rowrange_==NULL ); 00085 assert( im.matrixByRow_==NULL ); 00086 assert( im.ws_==NULL); 00087 assert( im.itlimOrig_==9999999); 00088 assert( im.lastAlgorithm_==0); 00089 assert( im.integerInformation_==NULL); 00090 } 00091 00092 // Test copy constructor and assignment operator 00093 { 00094 OsiClpSolverInterface lhs; 00095 { 00096 OsiClpSolverInterface im(m); 00097 00098 OsiClpSolverInterface imC1(im); 00099 assert( imC1.getModelPtr()!=im.getModelPtr() ); 00100 assert( imC1.getNumCols() == im.getNumCols() ); 00101 assert( imC1.getNumRows() == im.getNumRows() ); 00102 00103 OsiClpSolverInterface imC2(im); 00104 assert( imC2.getModelPtr()!=im.getModelPtr() ); 00105 assert( imC2.getNumCols() == im.getNumCols() ); 00106 assert( imC2.getNumRows() == im.getNumRows() ); 00107 00108 assert( imC2.getModelPtr()!=imC1.getModelPtr() ); 00109 00110 lhs=imC2; 00111 } 00112 // Test that lhs has correct values even though rhs has gone out of scope 00113 00114 assert( lhs.getModelPtr() != m.getModelPtr() ); 00115 assert( lhs.getNumCols() == m.getNumCols() ); 00116 assert( lhs.getNumRows() == m.getNumRows() ); 00117 } 00118 // Test clone 00119 { 00120 OsiClpSolverInterface oslSi(m); 00121 OsiSolverInterface * siPtr = &oslSi; 00122 OsiSolverInterface * siClone = siPtr->clone(); 00123 OsiClpSolverInterface * oslClone = dynamic_cast<OsiClpSolverInterface*>(siClone); 00124 assert( oslClone != NULL ); 00125 assert( oslClone->getModelPtr() != oslSi.getModelPtr() ); 00126 assert( oslClone->getNumRows() == oslSi.getNumRows() ); 00127 assert( oslClone->getNumCols() == m.getNumCols() ); 00128 00129 delete siClone; 00130 } 00131 00132 // test infinity 00133 { 00134 OsiClpSolverInterface si; 00135 assert( eq(si.getInfinity(),OsiClpInfinity)); 00136 } 00137 00138 // Test setting solution 00139 { 00140 OsiClpSolverInterface m1(m); 00141 int i; 00142 00143 double * cs = new double[m1.getNumCols()]; 00144 for ( i = 0; i < m1.getNumCols(); i++ ) 00145 cs[i] = i + .5; 00146 m1.setColSolution(cs); 00147 for ( i = 0; i < m1.getNumCols(); i++ ) 00148 assert(m1.getColSolution()[i] == i + .5); 00149 00150 double * rs = new double[m1.getNumRows()]; 00151 for ( i = 0; i < m1.getNumRows(); i++ ) 00152 rs[i] = i - .5; 00153 m1.setRowPrice(rs); 00154 for ( i = 0; i < m1.getNumRows(); i++ ) 00155 assert(m1.getRowPrice()[i] == i - .5); 00156 00157 delete [] cs; 00158 delete [] rs; 00159 } 00160 00161 00162 // Test fraction Indices 00163 { 00164 OsiClpSolverInterface fim; 00165 std::string fn = mpsDir+"exmip1"; 00166 fim.readMps(fn.c_str(),"mps"); 00167 // exmip1.mps has 2 integer variables with index 2 & 3 00168 assert( fim.isContinuous(0) ); 00169 assert( fim.isContinuous(1) ); 00170 assert( !fim.isContinuous(2) ); 00171 assert( !fim.isContinuous(3) ); 00172 assert( fim.isContinuous(4) ); 00173 00174 assert( !fim.isInteger(0) ); 00175 assert( !fim.isInteger(1) ); 00176 assert( fim.isInteger(2) ); 00177 assert( fim.isInteger(3) ); 00178 assert( !fim.isInteger(4) ); 00179 00180 assert( !fim.isBinary(0) ); 00181 assert( !fim.isBinary(1) ); 00182 assert( fim.isBinary(2) ); 00183 assert( fim.isBinary(3) ); 00184 assert( !fim.isBinary(4) ); 00185 00186 assert( !fim.isIntegerNonBinary(0) ); 00187 assert( !fim.isIntegerNonBinary(1) ); 00188 assert( !fim.isIntegerNonBinary(2) ); 00189 assert( !fim.isIntegerNonBinary(3) ); 00190 assert( !fim.isIntegerNonBinary(4) ); 00191 00192 // Test fractionalIndices 00193 { 00194 double sol[]={2.9,3.0}; 00195 memcpy(fim.modelPtr_->primalColumnSolution()+2,sol,2*sizeof(double)); 00196 OsiVectorInt fi = fim.getFractionalIndices(1e-5); 00197 assert( fi.size() == 1 ); 00198 assert( fi[0]==2 ); 00199 00200 // Set integer variables very close to integer values 00201 sol[0]=5 + .00001/2.; 00202 sol[1]=8 - .00001/2.; 00203 memcpy(fim.modelPtr_->primalColumnSolution()+2,sol,2*sizeof(double)); 00204 fi = fim.getFractionalIndices(1e-5); 00205 assert( fi.size() == 0 ); 00206 00207 // Set integer variables close, but beyond tolerances 00208 sol[0]=5 + .00001*2.; 00209 sol[1]=8 - .00001*2.; 00210 memcpy(fim.modelPtr_->primalColumnSolution()+2,sol,2*sizeof(double)); 00211 fi = fim.getFractionalIndices(1e-5); 00212 assert( fi.size() == 2 ); 00213 assert( fi[0]==2 ); 00214 assert( fi[1]==3 ); 00215 } 00216 00217 00218 00219 // Change date so column 2 & 3 are integerNonBinary 00220 double ub[]={5.0,6.0}; 00221 memcpy(fim.modelPtr_->columnUpper()+2,ub,2*sizeof(double)); 00222 assert( !fim.isBinary(0) ); 00223 assert( !fim.isBinary(1) ); 00224 assert( !fim.isBinary(2) ); 00225 assert( !fim.isBinary(3) ); 00226 assert( !fim.isBinary(4) ); 00227 00228 assert( !fim.isIntegerNonBinary(0) ); 00229 assert( !fim.isIntegerNonBinary(1) ); 00230 assert( fim.isIntegerNonBinary(2) ); 00231 assert( fim.isIntegerNonBinary(3) ); 00232 assert( !fim.isIntegerNonBinary(4) ); 00233 } 00234 00235 // Test apply cuts method 00236 { 00237 OsiClpSolverInterface im(m); 00238 OsiCuts cuts; 00239 00240 // Generate some cuts 00241 { 00242 // Get number of rows and columns in model 00243 int nr=im.getNumRows(); 00244 int nc=im.getNumCols(); 00245 assert( nr == 5 ); 00246 assert( nc == 8 ); 00247 00248 // Generate a valid row cut from thin air 00249 int c; 00250 { 00251 int *inx = new int[nc]; 00252 for (c=0;c<nc;c++) inx[c]=c; 00253 double *el = new double[nc]; 00254 for (c=0;c<nc;c++) el[c]=((double)c)*((double)c); 00255 00256 OsiRowCut rc; 00257 rc.setRow(nc,inx,el); 00258 rc.setLb(-100.); 00259 rc.setUb(100.); 00260 rc.setEffectiveness(22); 00261 00262 cuts.insert(rc); 00263 delete[]el; 00264 delete[]inx; 00265 } 00266 00267 // Generate valid col cut from thin air 00268 { 00269 const double * oslColLB = im.getColLower(); 00270 const double * oslColUB = im.getColUpper(); 00271 int *inx = new int[nc]; 00272 for (c=0;c<nc;c++) inx[c]=c; 00273 double *lb = new double[nc]; 00274 double *ub = new double[nc]; 00275 for (c=0;c<nc;c++) lb[c]=oslColLB[c]+0.001; 00276 for (c=0;c<nc;c++) ub[c]=oslColUB[c]-0.001; 00277 00278 OsiColCut cc; 00279 cc.setLbs(nc,inx,lb); 00280 cc.setUbs(nc,inx,ub); 00281 00282 cuts.insert(cc); 00283 delete [] ub; 00284 delete [] lb; 00285 delete [] inx; 00286 } 00287 00288 { 00289 // Generate a row and column cut which are ineffective 00290 OsiRowCut * rcP= new OsiRowCut; 00291 rcP->setEffectiveness(-1.); 00292 cuts.insert(rcP); 00293 assert(rcP==NULL); 00294 00295 OsiColCut * ccP= new OsiColCut; 00296 ccP->setEffectiveness(-12.); 00297 cuts.insert(ccP); 00298 assert(ccP==NULL); 00299 } 00300 { 00301 //Generate inconsistent Row cut 00302 OsiRowCut rc; 00303 const int ne=1; 00304 int inx[ne]={-10}; 00305 double el[ne]={2.5}; 00306 rc.setRow(ne,inx,el); 00307 rc.setLb(3.); 00308 rc.setUb(4.); 00309 assert(!rc.consistent()); 00310 cuts.insert(rc); 00311 } 00312 { 00313 //Generate inconsistent col cut 00314 OsiColCut cc; 00315 const int ne=1; 00316 int inx[ne]={-10}; 00317 double el[ne]={2.5}; 00318 cc.setUbs(ne,inx,el); 00319 assert(!cc.consistent()); 00320 cuts.insert(cc); 00321 } 00322 { 00323 // Generate row cut which is inconsistent for model m 00324 OsiRowCut rc; 00325 const int ne=1; 00326 int inx[ne]={10}; 00327 double el[ne]={2.5}; 00328 rc.setRow(ne,inx,el); 00329 assert(rc.consistent()); 00330 assert(!rc.consistent(im)); 00331 cuts.insert(rc); 00332 } 00333 { 00334 // Generate col cut which is inconsistent for model m 00335 OsiColCut cc; 00336 const int ne=1; 00337 int inx[ne]={30}; 00338 double el[ne]={2.0}; 00339 cc.setLbs(ne,inx,el); 00340 assert(cc.consistent()); 00341 assert(!cc.consistent(im)); 00342 cuts.insert(cc); 00343 } 00344 { 00345 // Generate col cut which is infeasible 00346 OsiColCut cc; 00347 const int ne=1; 00348 int inx[ne]={0}; 00349 double el[ne]={2.0}; 00350 cc.setUbs(ne,inx,el); 00351 cc.setEffectiveness(1000.); 00352 assert(cc.consistent()); 00353 assert(cc.consistent(im)); 00354 assert(cc.infeasible(im)); 00355 cuts.insert(cc); 00356 } 00357 } 00358 assert(cuts.sizeRowCuts()==4); 00359 assert(cuts.sizeColCuts()==5); 00360 00361 OsiSolverInterface::ApplyCutsReturnCode rc = im.applyCuts(cuts); 00362 assert( rc.getNumIneffective() == 2 ); 00363 assert( rc.getNumApplied() == 2 ); 00364 assert( rc.getNumInfeasible() == 1 ); 00365 assert( rc.getNumInconsistentWrtIntegerModel() == 2 ); 00366 assert( rc.getNumInconsistent() == 2 ); 00367 assert( cuts.sizeCuts() == rc.getNumIneffective() + 00368 rc.getNumApplied() + 00369 rc.getNumInfeasible() + 00370 rc.getNumInconsistentWrtIntegerModel() + 00371 rc.getNumInconsistent() ); 00372 } 00373 00374 { 00375 OsiClpSolverInterface oslSi(m); 00376 int nc = oslSi.getNumCols(); 00377 int nr = oslSi.getNumRows(); 00378 const double * cl = oslSi.getColLower(); 00379 const double * cu = oslSi.getColUpper(); 00380 const double * rl = oslSi.getRowLower(); 00381 const double * ru = oslSi.getRowUpper(); 00382 assert( nc == 8 ); 00383 assert( nr == 5 ); 00384 assert( eq(cl[0],2.5) ); 00385 assert( eq(cl[1],0.0) ); 00386 assert( eq(cu[1],4.1) ); 00387 assert( eq(cu[2],1.0) ); 00388 assert( eq(rl[0],2.5) ); 00389 assert( eq(rl[4],3.0) ); 00390 assert( eq(ru[1],2.1) ); 00391 assert( eq(ru[4],15.0) ); 00392 00393 const double * cs = oslSi.getColSolution(); 00394 assert( eq(cs[0],2.5) ); 00395 assert( eq(cs[7],0.0) ); 00396 00397 assert( !eq(cl[3],1.2345) ); 00398 oslSi.setColLower( 3, 1.2345 ); 00399 assert( eq(oslSi.getColLower()[3],1.2345) ); 00400 00401 assert( !eq(cu[4],10.2345) ); 00402 oslSi.setColUpper( 4, 10.2345 ); 00403 assert( eq(oslSi.getColUpper()[4],10.2345) ); 00404 00405 double objValue = oslSi.getObjValue(); 00406 assert( eq(objValue,3.5) ); 00407 00408 assert( eq( oslSi.getObjCoefficients()[0], 1.0) ); 00409 assert( eq( oslSi.getObjCoefficients()[1], 0.0) ); 00410 assert( eq( oslSi.getObjCoefficients()[2], 0.0) ); 00411 assert( eq( oslSi.getObjCoefficients()[3], 0.0) ); 00412 assert( eq( oslSi.getObjCoefficients()[4], 2.0) ); 00413 assert( eq( oslSi.getObjCoefficients()[5], 0.0) ); 00414 assert( eq( oslSi.getObjCoefficients()[6], 0.0) ); 00415 assert( eq( oslSi.getObjCoefficients()[7], -1.0) ); 00416 } 00417 00418 // Test matrixByRow method 00419 { 00420 const OsiClpSolverInterface si(m); 00421 const CoinPackedMatrix * smP = si.getMatrixByRow(); 00422 // LL: const OsiClpPackedMatrix * osmP = dynamic_cast<const OsiClpPackedMatrix*>(smP); 00423 // LL: assert( osmP!=NULL ); 00424 00425 CoinRelFltEq eq; 00426 const double * ev = smP->getElements(); 00427 assert( eq(ev[0], 3.0) ); 00428 assert( eq(ev[1], 1.0) ); 00429 assert( eq(ev[2], -2.0) ); 00430 assert( eq(ev[3], -1.0) ); 00431 assert( eq(ev[4], -1.0) ); 00432 assert( eq(ev[5], 2.0) ); 00433 assert( eq(ev[6], 1.1) ); 00434 assert( eq(ev[7], 1.0) ); 00435 assert( eq(ev[8], 1.0) ); 00436 assert( eq(ev[9], 2.8) ); 00437 assert( eq(ev[10], -1.2) ); 00438 assert( eq(ev[11], 5.6) ); 00439 assert( eq(ev[12], 1.0) ); 00440 assert( eq(ev[13], 1.9) ); 00441 00442 const int * mi = smP->getVectorStarts(); 00443 assert( mi[0]==0 ); 00444 assert( mi[1]==5 ); 00445 assert( mi[2]==7 ); 00446 assert( mi[3]==9 ); 00447 assert( mi[4]==11 ); 00448 assert( mi[5]==14 ); 00449 00450 const int * ei = smP->getIndices(); 00451 assert( ei[0] == 0 ); 00452 assert( ei[1] == 1 ); 00453 assert( ei[2] == 3 ); 00454 assert( ei[3] == 4 ); 00455 assert( ei[4] == 7 ); 00456 assert( ei[5] == 1 ); 00457 assert( ei[6] == 2 ); 00458 assert( ei[7] == 2 ); 00459 assert( ei[8] == 5 ); 00460 assert( ei[9] == 3 ); 00461 assert( ei[10] == 6 ); 00462 assert( ei[11] == 0 ); 00463 assert( ei[12] == 4 ); 00464 assert( ei[13] == 7 ); 00465 00466 assert( smP->getMajorDim() == 5 ); 00467 assert( smP->getNumElements() == 14 ); 00468 00469 } 00470 // Test adding several cuts 00471 { 00472 OsiClpSolverInterface fim; 00473 std::string fn = mpsDir+"exmip1"; 00474 fim.readMps(fn.c_str(),"mps"); 00475 // exmip1.mps has 2 integer variables with index 2 & 3 00476 fim.initialSolve(); 00477 OsiRowCut cuts[3]; 00478 00479 00480 // Generate one ineffective cut plus two trivial cuts 00481 int c; 00482 int nc = fim.getNumCols(); 00483 int *inx = new int[nc]; 00484 for (c=0;c<nc;c++) inx[c]=c; 00485 double *el = new double[nc]; 00486 for (c=0;c<nc;c++) el[c]=1.0e-50+((double)c)*((double)c); 00487 00488 cuts[0].setRow(nc,inx,el); 00489 cuts[0].setLb(-100.); 00490 cuts[0].setUb(500.); 00491 cuts[0].setEffectiveness(22); 00492 el[4]=0.0; // to get inf later 00493 00494 for (c=2;c<4;c++) { 00495 el[0]=1.0; 00496 inx[0]=c; 00497 cuts[c-1].setRow(1,inx,el); 00498 cuts[c-1].setLb(1.); 00499 cuts[c-1].setUb(100.); 00500 cuts[c-1].setEffectiveness(c); 00501 } 00502 fim.writeMps("x1.mps"); 00503 fim.applyRowCuts(3,cuts); 00504 fim.writeMps("x2.mps"); 00505 // resolve - should get message about zero elements 00506 fim.resolve(); 00507 fim.writeMps("x3.mps"); 00508 // check integer solution 00509 const double * cs = fim.getColSolution(); 00510 CoinRelFltEq eq; 00511 assert( eq(cs[2], 1.0) ); 00512 assert( eq(cs[3], 1.0) ); 00513 // check will find invalid matrix 00514 el[0]=1.0/el[4]; 00515 inx[0]=0; 00516 cuts[0].setRow(nc,inx,el); 00517 cuts[0].setLb(-100.); 00518 cuts[0].setUb(500.); 00519 cuts[0].setEffectiveness(22); 00520 fim.applyRowCut(cuts[0]); 00521 // resolve - should get message about zero elements 00522 fim.resolve(); 00523 assert (fim.isAbandoned()); 00524 delete[]el; 00525 delete[]inx; 00526 } 00527 // Test matrixByCol method 00528 { 00529 00530 const OsiClpSolverInterface si(m); 00531 const CoinPackedMatrix * smP = si.getMatrixByCol(); 00532 // LL: const OsiClpPackedMatrix * osmP = dynamic_cast<const OsiClpPackedMatrix*>(smP); 00533 // LL: assert( osmP!=NULL ); 00534 00535 CoinRelFltEq eq; 00536 const double * ev = smP->getElements(); 00537 assert( eq(ev[0], 3.0) ); 00538 assert( eq(ev[1], 5.6) ); 00539 assert( eq(ev[2], 1.0) ); 00540 assert( eq(ev[3], 2.0) ); 00541 assert( eq(ev[4], 1.1) ); 00542 assert( eq(ev[5], 1.0) ); 00543 assert( eq(ev[6], -2.0) ); 00544 assert( eq(ev[7], 2.8) ); 00545 assert( eq(ev[8], -1.0) ); 00546 assert( eq(ev[9], 1.0) ); 00547 assert( eq(ev[10], 1.0) ); 00548 assert( eq(ev[11], -1.2) ); 00549 assert( eq(ev[12], -1.0) ); 00550 assert( eq(ev[13], 1.9) ); 00551 00552 const int * mi = smP->getVectorStarts(); 00553 assert( mi[0]==0 ); 00554 assert( mi[1]==2 ); 00555 assert( mi[2]==4 ); 00556 assert( mi[3]==6 ); 00557 assert( mi[4]==8 ); 00558 assert( mi[5]==10 ); 00559 assert( mi[6]==11 ); 00560 assert( mi[7]==12 ); 00561 assert( mi[8]==14 ); 00562 00563 const int * ei = smP->getIndices(); 00564 assert( ei[0] == 0 ); 00565 assert( ei[1] == 4 ); 00566 assert( ei[2] == 0 ); 00567 assert( ei[3] == 1 ); 00568 assert( ei[4] == 1 ); 00569 assert( ei[5] == 2 ); 00570 assert( ei[6] == 0 ); 00571 assert( ei[7] == 3 ); 00572 assert( ei[8] == 0 ); 00573 assert( ei[9] == 4 ); 00574 assert( ei[10] == 2 ); 00575 assert( ei[11] == 3 ); 00576 assert( ei[12] == 0 ); 00577 assert( ei[13] == 4 ); 00578 00579 assert( smP->getMajorDim() == 8 ); 00580 assert( smP->getNumElements() == 14 ); 00581 00582 assert( smP->getSizeVectorStarts()==9 ); 00583 assert( smP->getMinorDim() == 5 ); 00584 00585 } 00586 //-------------- 00587 // Test rowsense, rhs, rowrange, matrixByRow 00588 { 00589 OsiClpSolverInterface lhs; 00590 { 00591 assert( m.rowrange_==NULL ); 00592 assert( m.rowsense_==NULL ); 00593 assert( m.rhs_==NULL ); 00594 assert( m.matrixByRow_==NULL ); 00595 00596 OsiClpSolverInterface siC1(m); 00597 assert( siC1.rowrange_==NULL ); 00598 assert( siC1.rowsense_==NULL ); 00599 assert( siC1.rhs_==NULL ); 00600 assert( siC1.matrixByRow_==NULL ); 00601 00602 const char * siC1rs = siC1.getRowSense(); 00603 assert( siC1rs[0]=='G' ); 00604 assert( siC1rs[1]=='L' ); 00605 assert( siC1rs[2]=='E' ); 00606 assert( siC1rs[3]=='R' ); 00607 assert( siC1rs[4]=='R' ); 00608 00609 const double * siC1rhs = siC1.getRightHandSide(); 00610 assert( eq(siC1rhs[0],2.5) ); 00611 assert( eq(siC1rhs[1],2.1) ); 00612 assert( eq(siC1rhs[2],4.0) ); 00613 assert( eq(siC1rhs[3],5.0) ); 00614 assert( eq(siC1rhs[4],15.) ); 00615 00616 const double * siC1rr = siC1.getRowRange(); 00617 assert( eq(siC1rr[0],0.0) ); 00618 assert( eq(siC1rr[1],0.0) ); 00619 assert( eq(siC1rr[2],0.0) ); 00620 assert( eq(siC1rr[3],5.0-1.8) ); 00621 assert( eq(siC1rr[4],15.0-3.0) ); 00622 00623 const CoinPackedMatrix * siC1mbr = siC1.getMatrixByRow(); 00624 assert( siC1mbr != NULL ); 00625 00626 const double * ev = siC1mbr->getElements(); 00627 assert( eq(ev[0], 3.0) ); 00628 assert( eq(ev[1], 1.0) ); 00629 assert( eq(ev[2], -2.0) ); 00630 assert( eq(ev[3], -1.0) ); 00631 assert( eq(ev[4], -1.0) ); 00632 assert( eq(ev[5], 2.0) ); 00633 assert( eq(ev[6], 1.1) ); 00634 assert( eq(ev[7], 1.0) ); 00635 assert( eq(ev[8], 1.0) ); 00636 assert( eq(ev[9], 2.8) ); 00637 assert( eq(ev[10], -1.2) ); 00638 assert( eq(ev[11], 5.6) ); 00639 assert( eq(ev[12], 1.0) ); 00640 assert( eq(ev[13], 1.9) ); 00641 00642 const int * mi = siC1mbr->getVectorStarts(); 00643 assert( mi[0]==0 ); 00644 assert( mi[1]==5 ); 00645 assert( mi[2]==7 ); 00646 assert( mi[3]==9 ); 00647 assert( mi[4]==11 ); 00648 assert( mi[5]==14 ); 00649 00650 const int * ei = siC1mbr->getIndices(); 00651 assert( ei[0] == 0 ); 00652 assert( ei[1] == 1 ); 00653 assert( ei[2] == 3 ); 00654 assert( ei[3] == 4 ); 00655 assert( ei[4] == 7 ); 00656 assert( ei[5] == 1 ); 00657 assert( ei[6] == 2 ); 00658 assert( ei[7] == 2 ); 00659 assert( ei[8] == 5 ); 00660 assert( ei[9] == 3 ); 00661 assert( ei[10] == 6 ); 00662 assert( ei[11] == 0 ); 00663 assert( ei[12] == 4 ); 00664 assert( ei[13] == 7 ); 00665 00666 assert( siC1mbr->getMajorDim() == 5 ); 00667 assert( siC1mbr->getNumElements() == 14 ); 00668 00669 00670 assert( siC1rs == siC1.getRowSense() ); 00671 assert( siC1rhs == siC1.getRightHandSide() ); 00672 assert( siC1rr == siC1.getRowRange() ); 00673 00674 // Change OSL Model by adding free row 00675 OsiRowCut rc; 00676 rc.setLb(-DBL_MAX); 00677 rc.setUb( DBL_MAX); 00678 OsiCuts cuts; 00679 cuts.insert(rc); 00680 siC1.applyCuts(cuts); 00681 00682 // Since model was changed, test that cached 00683 // data is now freed. 00684 assert( siC1.rowrange_==NULL ); 00685 assert( siC1.rowsense_==NULL ); 00686 assert( siC1.rhs_==NULL ); 00687 assert( siC1.matrixByRow_==NULL ); 00688 00689 siC1rs = siC1.getRowSense(); 00690 assert( siC1rs[0]=='G' ); 00691 assert( siC1rs[1]=='L' ); 00692 assert( siC1rs[2]=='E' ); 00693 assert( siC1rs[3]=='R' ); 00694 assert( siC1rs[4]=='R' ); 00695 assert( siC1rs[5]=='N' ); 00696 00697 siC1rhs = siC1.getRightHandSide(); 00698 assert( eq(siC1rhs[0],2.5) ); 00699 assert( eq(siC1rhs[1],2.1) ); 00700 assert( eq(siC1rhs[2],4.0) ); 00701 assert( eq(siC1rhs[3],5.0) ); 00702 assert( eq(siC1rhs[4],15.) ); 00703 assert( eq(siC1rhs[5],0.0 ) ); 00704 00705 siC1rr = siC1.getRowRange(); 00706 assert( eq(siC1rr[0],0.0) ); 00707 assert( eq(siC1rr[1],0.0) ); 00708 assert( eq(siC1rr[2],0.0) ); 00709 assert( eq(siC1rr[3],5.0-1.8) ); 00710 assert( eq(siC1rr[4],15.0-3.0) ); 00711 assert( eq(siC1rr[5],0.0) ); 00712 00713 lhs=siC1; 00714 } 00715 // Test that lhs has correct values even though siC1 has gone out of scope 00716 assert( lhs.rowrange_==NULL ); 00717 assert( lhs.rowsense_==NULL ); 00718 assert( lhs.rhs_==NULL ); 00719 assert( lhs.matrixByRow_==NULL ); 00720 00721 const char * lhsrs = lhs.getRowSense(); 00722 assert( lhsrs[0]=='G' ); 00723 assert( lhsrs[1]=='L' ); 00724 assert( lhsrs[2]=='E' ); 00725 assert( lhsrs[3]=='R' ); 00726 assert( lhsrs[4]=='R' ); 00727 assert( lhsrs[5]=='N' ); 00728 00729 const double * lhsrhs = lhs.getRightHandSide(); 00730 assert( eq(lhsrhs[0],2.5) ); 00731 assert( eq(lhsrhs[1],2.1) ); 00732 assert( eq(lhsrhs[2],4.0) ); 00733 assert( eq(lhsrhs[3],5.0) ); 00734 assert( eq(lhsrhs[4],15.) ); 00735 assert( eq(lhsrhs[5],0.0) ); 00736 00737 const double *lhsrr = lhs.getRowRange(); 00738 assert( eq(lhsrr[0],0.0) ); 00739 assert( eq(lhsrr[1],0.0) ); 00740 assert( eq(lhsrr[2],0.0) ); 00741 assert( eq(lhsrr[3],5.0-1.8) ); 00742 assert( eq(lhsrr[4],15.0-3.0) ); 00743 assert( eq(lhsrr[5],0.0) ); 00744 00745 const CoinPackedMatrix * lhsmbr = lhs.getMatrixByRow(); 00746 assert( lhsmbr != NULL ); 00747 const double * ev = lhsmbr->getElements(); 00748 assert( eq(ev[0], 3.0) ); 00749 assert( eq(ev[1], 1.0) ); 00750 assert( eq(ev[2], -2.0) ); 00751 assert( eq(ev[3], -1.0) ); 00752 assert( eq(ev[4], -1.0) ); 00753 assert( eq(ev[5], 2.0) ); 00754 assert( eq(ev[6], 1.1) ); 00755 assert( eq(ev[7], 1.0) ); 00756 assert( eq(ev[8], 1.0) ); 00757 assert( eq(ev[9], 2.8) ); 00758 assert( eq(ev[10], -1.2) ); 00759 assert( eq(ev[11], 5.6) ); 00760 assert( eq(ev[12], 1.0) ); 00761 assert( eq(ev[13], 1.9) ); 00762 00763 const int * mi = lhsmbr->getVectorStarts(); 00764 assert( mi[0]==0 ); 00765 assert( mi[1]==5 ); 00766 assert( mi[2]==7 ); 00767 assert( mi[3]==9 ); 00768 assert( mi[4]==11 ); 00769 assert( mi[5]==14 ); 00770 00771 const int * ei = lhsmbr->getIndices(); 00772 assert( ei[0] == 0 ); 00773 assert( ei[1] == 1 ); 00774 assert( ei[2] == 3 ); 00775 assert( ei[3] == 4 ); 00776 assert( ei[4] == 7 ); 00777 assert( ei[5] == 1 ); 00778 assert( ei[6] == 2 ); 00779 assert( ei[7] == 2 ); 00780 assert( ei[8] == 5 ); 00781 assert( ei[9] == 3 ); 00782 assert( ei[10] == 6 ); 00783 assert( ei[11] == 0 ); 00784 assert( ei[12] == 4 ); 00785 assert( ei[13] == 7 ); 00786 00787 int md = lhsmbr->getMajorDim(); 00788 assert( md == 6 ); 00789 assert( lhsmbr->getNumElements() == 14 ); 00790 } 00791 00792 } 00793 00794 // Test add/delete columns 00795 { 00796 OsiClpSolverInterface m; 00797 std::string fn = mpsDir+"p0033"; 00798 m.readMps(fn.c_str(),"mps"); 00799 double inf = m.getInfinity(); 00800 00801 CoinPackedVector c0; 00802 c0.insert(0, 4); 00803 c0.insert(1, 1); 00804 m.addCol(c0, 0, inf, 3); 00805 m.initialSolve(); 00806 double objValue = m.getObjValue(); 00807 CoinRelFltEq eq(1.0e-2); 00808 assert( eq(objValue,2520.57) ); 00809 // Try deleting first column 00810 int * d = new int[1]; 00811 d[0]=0; 00812 m.deleteCols(1,d); 00813 delete [] d; 00814 d=NULL; 00815 m.resolve(); 00816 objValue = m.getObjValue(); 00817 assert( eq(objValue,2520.57) ); 00818 // Try deleting column we added 00819 int iCol = m.getNumCols()-1; 00820 m.deleteCols(1,&iCol); 00821 m.resolve(); 00822 objValue = m.getObjValue(); 00823 assert( eq(objValue,2520.57) ); 00824 00825 } 00826 // Test matt 00827 if (fopen("../Clp/matt.mps","r")) { 00828 OsiClpSolverInterface m; 00829 m.readMps("../Clp/matt","mps"); 00830 m.setHintParam(OsiDoPresolveInResolve, true, OsiHintDo); 00831 m.resolve(); 00832 00833 std::vector<double *> rays = m.getDualRays(1); 00834 std::cout << "Dual Ray: " << std::endl; 00835 for(int i = 0; i < m.getNumRows(); i++){ 00836 if(fabs(rays[0][i]) > 0.00001) 00837 std::cout << i << " : " << rays[0][i] << std::endl; 00838 } 00839 00840 std::cout << "isProvenOptimal = " << m.isProvenOptimal() << std::endl; 00841 std::cout << "isProvenPrimalInfeasible = " << m.isProvenPrimalInfeasible() 00842 << std::endl; 00843 00844 delete [] rays[0]; 00845 00846 } 00847 00848 // Solve an lp by hand 00849 { 00850 OsiClpSolverInterface m; 00851 std::string fn = mpsDir+"p0033"; 00852 m.readMps(fn.c_str(),"mps"); 00853 m.setObjSense(-1.0); 00854 m.getModelPtr()->messageHandler()->setLogLevel(4); 00855 m.initialSolve(); 00856 m.getModelPtr()->factorization()->maximumPivots(5); 00857 m.setObjSense(1.0); 00858 // enable special mode 00859 m.enableSimplexInterface(true); 00860 // we happen to know that variables are 0-1 and rows are L 00861 int numberIterations=0; 00862 int numberColumns = m.getNumCols(); 00863 int numberRows = m.getNumRows(); 00864 double * fakeCost = new double[numberColumns]; 00865 double * duals = new double [numberRows]; 00866 double * djs = new double [numberColumns]; 00867 const double * solution = m.getColSolution(); 00868 memcpy(fakeCost,m.getObjCoefficients(),numberColumns*sizeof(double)); 00869 while (1) { 00870 const double * dj; 00871 const double * dual; 00872 if ((numberIterations&1)==0) { 00873 // use given ones 00874 dj = m.getReducedCost(); 00875 dual = m.getRowPrice(); 00876 } else { 00877 // create 00878 dj = djs; 00879 dual = duals; 00880 m.getReducedGradient(djs,duals,fakeCost); 00881 } 00882 int i; 00883 int colIn=9999; 00884 int direction=1; 00885 double best=1.0e-6; 00886 // find most negative reduced cost 00887 // Should check basic - but should be okay on this problem 00888 for (i=0;i<numberRows;i++) { 00889 double value=dual[i]; 00890 if (value>best) { 00891 direction=-1; 00892 best=value; 00893 colIn=-i-1; 00894 } 00895 } 00896 for (i=0;i<numberColumns;i++) { 00897 double value=dj[i]; 00898 if (value<-best&&solution[i]<1.0e-6) { 00899 direction=1; 00900 best=-value; 00901 colIn=i; 00902 } else if (value>best&&solution[i]>1.0-1.0e-6) { 00903 direction=-1; 00904 best=value; 00905 colIn=i; 00906 } 00907 } 00908 if (colIn==9999) 00909 break; // should be optimal 00910 int colOut; 00911 int outStatus; 00912 double theta; 00913 assert(!m.primalPivotResult(colIn,direction,colOut,outStatus,theta,NULL)); 00914 printf("out %d, direction %d theta %g\n", 00915 colOut,outStatus,theta); 00916 numberIterations++; 00917 } 00918 delete [] fakeCost; 00919 delete [] duals; 00920 delete [] djs; 00921 // exit special mode 00922 m.disableSimplexInterface(); 00923 m.getModelPtr()->messageHandler()->setLogLevel(4); 00924 m.resolve(); 00925 assert (!m.getIterationCount()); 00926 m.setObjSense(-1.0); 00927 m.initialSolve(); 00928 } 00929 // Do common solverInterface testing 00930 { 00931 OsiClpSolverInterface m; 00932 OsiSolverInterfaceCommonUnitTest(&m, mpsDir,netlibDir); 00933 } 00934 } |
|
Warmstart information to be used in resolves. Definition at line 770 of file OsiClpSolverInterface.hpp. Referenced by addCol(), addCols(), addRow(), addRows(), deleteCols(), deleteRows(), disableSimplexInterface(), getWarmStart(), initialSolve(), operator=(), OsiClpSolverInterface(), reset(), resolve(), and setWarmStart(). |
|
The original iteration limit before hotstarts started. Definition at line 772 of file OsiClpSolverInterface.hpp. Referenced by reset(), and solveFromHotStart(). |
|
also save row and column information for hot starts only used in hotstarts so can be casual Definition at line 767 of file OsiClpSolverInterface.hpp. Referenced by markHotStart(), operator=(), reset(), solveFromHotStart(), unmarkHotStart(), and ~OsiClpSolverInterface(). |
|
Pointer to dense vector of slack upper bounds for range constraints (undefined for non-range rows) Definition at line 760 of file OsiClpSolverInterface.hpp. Referenced by extractSenseRhsRange(), freeCachedResults(), getRowRange(), setRowSetBounds(), and setRowSetTypes(). |
|
A pointer to the warmstart information to be used in the hotstarts. This is NOT efficient and more thought should be given to it... Reimplemented from OsiSolverInterface. Definition at line 764 of file OsiClpSolverInterface.hpp. Referenced by freeCachedResults(), markHotStart(), operator=(), OsiClpSolverInterface(), reset(), solveFromHotStart(), unmarkHotStart(), and ~OsiClpSolverInterface(). |