Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

OsiSimplexInterface Class Reference

#include <OsiSimplexInterface.hpp>

Inheritance diagram for OsiSimplexInterface:

OsiClpSolverInterface List of all members.

Public Member Functions

OsiSimplexInterface methods
virtual void enableSimplexInterface (bool doingPrimal)
virtual void disableSimplexInterface ()
 Undo whatever setting changes the above method had to make.

virtual bool basisIsAvailable ()=0
 Returns true if a basis is available.

virtual void getBasisStatus (int *cstat, int *rstat)=0
virtual int setBasisStatus (const int *cstat, const int *rstat)=0
virtual int pivot (int colIn, int colOut, int outStatus)=0
virtual int primalPivotResult (int colIn, int sign, int &colOut, int &outStatus, double &t, CoinPackedVector *dx)=0
virtual int dualPivotResult (int &colIn, int &sign, int colOut, int outStatus, double &t, CoinPackedVector *dx)=0
virtual void getReducedGradient (double *columnReducedCosts, double *duals, const double *c)=0
 Get the reduced gradient for the cost vector c.

virtual void setObjectiveAndRefresh (double *c)=0
virtual void getBInvARow (int row, double *z)=0
 Get a row of the tableau.

virtual void getBInvRow (int row, double *z)=0
 Get a row of the basis inverse.

virtual void getBInvACol (int col, double *vec)=0
 Get a column of the tableau.

virtual void getBInvCol (int col, double *vec)=0
 Get a column of the basis inverse.

virtual void getBasics (int *index)=0
Constructors and destructors
 OsiSimplexInterface ()
 Default Constructor.

 OsiSimplexInterface (const OsiSimplexInterface &rhs)
 Copy constructor.

OsiSimplexInterfaceoperator= (const OsiSimplexInterface &rhs)
 Assignment operator.

virtual ~OsiSimplexInterface ()
 Destructor.


Friends

void OsiSimplexInterfaceCommonUnitTest (const OsiSolverInterface *emptySi, const std::string &mpsDir)

Detailed Description

Simplex Interface Abstract Base Class

Abstract Base Class for describing an advanced interface to a simplex solver. When switched on allows great control of simplex iterations. Also allows access to tableau.

Definition at line 26 of file OsiSimplexInterface.hpp.


Member Function Documentation

virtual int OsiSimplexInterface::dualPivotResult int &  colIn,
int &  sign,
int  colOut,
int  outStatus,
double &  t,
CoinPackedVector dx
[pure virtual]
 

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

Implemented in OsiClpSolverInterface.

virtual void OsiSimplexInterface::enableSimplexInterface bool  doingPrimal  )  [inline, virtual]
 

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. says whether will be doing primal or dual

Reimplemented in OsiClpSolverInterface.

Definition at line 40 of file OsiSimplexInterface.hpp.

00040 {};

virtual void OsiSimplexInterface::getBasics int *  index  )  [pure virtual]
 

Get basic indices (order of indices corresponds to the order of elements in a vector retured by getBInvACol() and getBInvCol()).

Implemented in OsiClpSolverInterface.

virtual void OsiSimplexInterface::getBasisStatus int *  cstat,
int *  rstat
[pure virtual]
 

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

Implemented in OsiClpSolverInterface.

virtual int OsiSimplexInterface::pivot int  colIn,
int  colOut,
int  outStatus
[pure virtual]
 

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

Implemented in OsiClpSolverInterface.

virtual int OsiSimplexInterface::primalPivotResult int  colIn,
int  sign,
int &  colOut,
int &  outStatus,
double &  t,
CoinPackedVector dx
[pure virtual]
 

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

Implemented in OsiClpSolverInterface.

virtual int OsiSimplexInterface::setBasisStatus const int *  cstat,
const int *  rstat
[pure virtual]
 

Set the status of structural/artificial variables and factorize, update solution etc

Implemented in OsiClpSolverInterface.

virtual void OsiSimplexInterface::setObjectiveAndRefresh double *  c  )  [pure virtual]
 

Set a new objective and apply the old basis so that the reduced costs are properly updated

Implemented in OsiClpSolverInterface.


Friends And Related Function Documentation

void OsiSimplexInterfaceCommonUnitTest const OsiSolverInterface emptySi,
const std::string &  mpsDir
[friend]
 

A function that tests the methods in the OsiSimplexInterface 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.

Definition at line 23 of file OsiSimplexInterfaceTest.cpp.

00025 {
00026   OsiSolverInterface * si = emptySi->clone();
00027   std::string solverName;
00028   si->getStrParam(OsiSolverName,solverName);
00029   OsiSimplexInterface * simplexSi = dynamic_cast<OsiSimplexInterface *> (si);
00030   
00031   if (simplexSi) {
00032     // solve an lp by hand
00033     
00034     std::string fn = mpsDir+"p0033";
00035     si->readMps(fn.c_str(),"mps");
00036     si->setObjSense(-1.0);
00037     si->initialSolve();
00038     si->setObjSense(1.0);
00039     // enable special mode
00040     simplexSi->enableSimplexInterface(true);
00041     // we happen to know that variables are 0-1 and rows are L
00042     int numberIterations=0;
00043     int numberColumns = si->getNumCols();
00044     int numberRows = si->getNumRows();
00045     double * fakeCost = new double[numberColumns];
00046     double * duals = new double [numberRows];
00047     double * djs = new double [numberColumns];
00048     const double * solution = si->getColSolution();
00049     memcpy(fakeCost,si->getObjCoefficients(),numberColumns*sizeof(double));
00050     while (1) {
00051       const double * dj;
00052       const double * dual;
00053       if ((numberIterations&1)==0) {
00054         // use given ones
00055         dj = si->getReducedCost();
00056         dual = si->getRowPrice();
00057       } else {
00058         // create
00059         dj = djs;
00060         dual = duals;
00061         simplexSi->getReducedGradient(djs,duals,fakeCost);
00062       }
00063       int i;
00064       int colIn=9999;
00065       int direction=1;
00066       double best=1.0e-6;
00067       // find most negative reduced cost
00068       // Should check basic - but should be okay on this problem
00069       for (i=0;i<numberRows;i++) {
00070         double value=dual[i];
00071         if (value>best) {
00072           direction=-1;
00073           best=value;
00074           colIn=-i-1;
00075         }
00076       }
00077       for (i=0;i<numberColumns;i++) {
00078         double value=dj[i];
00079         if (value<-best&&solution[i]<1.0e-6) {
00080           direction=1;
00081           best=-value;
00082           colIn=i;
00083         } else if (value>best&&solution[i]>1.0-1.0e-6) {
00084           direction=-1;
00085           best=value;
00086           colIn=i;
00087         }
00088       }
00089       if (colIn==9999)
00090         break; // should be optimal
00091       int colOut;
00092       int outStatus;
00093       double theta;
00094       assert(!simplexSi->primalPivotResult(colIn,direction,colOut,outStatus,theta,NULL));
00095       printf("out %d, direction %d theta %g\n",
00096              colOut,outStatus,theta);
00097       numberIterations++;
00098     }
00099     delete [] fakeCost;
00100     delete [] duals;
00101     delete [] djs;
00102     // exit special mode
00103     simplexSi->disableSimplexInterface();
00104     si->resolve();
00105     assert (!si->getIterationCount());
00106     si->setObjSense(-1.0);
00107     si->initialSolve();
00108     std::cout<<solverName<<" passed OsiSimplexInterface test"<<std::endl;
00109   } else {
00110     std::cout<<solverName<<" has no OsiSimplexInterface"<<std::endl;
00111   }
00112   delete si;
00113 }


The documentation for this class was generated from the following file:
Generated on Wed Dec 3 14:35:42 2003 for Osi by doxygen 1.3.5