Osi trunk
OsiXprSolverInterface.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 // This code is licensed under the terms of the Eclipse Public License (EPL).
00004 
00005 #ifndef OsiXprSolverInterface_H
00006 #define OsiXprSolverInterface_H
00007 
00008 #include <string>
00009 #include <cstdio>
00010 
00011 #include "OsiSolverInterface.hpp"
00012 
00013 typedef struct xo_prob_struct* XPRSprob;
00014 
00015 //#############################################################################
00016 
00021 class OsiXprSolverInterface : virtual public OsiSolverInterface {
00022    friend void OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00023 public:
00026 
00027     virtual void initialSolve();
00028 
00030     virtual void resolve();
00031 
00033     virtual void branchAndBound();
00035   
00051     // Set an integer parameter
00052     bool setIntParam(OsiIntParam key, int value);
00053     // Set an double parameter
00054     bool setDblParam(OsiDblParam key, double value);
00055     // Set a string parameter
00056     bool setStrParam(OsiStrParam key, const std::string & value);
00057     // Get an integer parameter
00058     bool getIntParam(OsiIntParam key, int& value) const;
00059     // Get an double parameter
00060     bool getDblParam(OsiDblParam key, double& value) const;
00061     // Get a string parameter
00062     bool getStrParam(OsiStrParam key, std::string& value) const;
00064 
00065   //---------------------------------------------------------------------------
00067 
00068 
00069     virtual bool isAbandoned() const;
00071     virtual bool isProvenOptimal() const;
00073     virtual bool isProvenPrimalInfeasible() const;
00075     virtual bool isProvenDualInfeasible() const;
00077     virtual bool isPrimalObjectiveLimitReached() const;
00079     virtual bool isDualObjectiveLimitReached() const;
00081     virtual bool isIterationLimitReached() const;
00083 
00084   //---------------------------------------------------------------------------
00087 
00088     CoinWarmStart *getEmptyWarmStart () const;
00090     virtual CoinWarmStart* getWarmStart() const;
00093     virtual bool setWarmStart(const CoinWarmStart* warmstart);
00095 
00096   //---------------------------------------------------------------------------
00103 
00104     virtual void markHotStart();
00106     virtual void solveFromHotStart();
00108     virtual void unmarkHotStart();
00110 
00111   //---------------------------------------------------------------------------
00126 
00127       virtual int getNumCols() const;
00128   
00130       virtual int getNumRows() const;
00131   
00133       virtual int getNumElements() const;
00134   
00136       virtual const double * getColLower() const;
00137   
00139       virtual const double * getColUpper() const;
00140   
00150       virtual const char * getRowSense() const;
00151   
00160       virtual const double * getRightHandSide() const;
00161   
00170       virtual const double * getRowRange() const;
00171   
00173       virtual const double * getRowLower() const;
00174   
00176       virtual const double * getRowUpper() const;
00177   
00179       virtual const double * getObjCoefficients() const;
00180   
00182       virtual double getObjSense() const;
00183   
00185       virtual bool isContinuous(int colIndex) const;
00186   
00187 #if 0
00188 
00189       virtual bool isBinary(int colIndex) const;
00190   
00195       virtual bool isInteger(int colIndex) const;
00196   
00198       virtual bool isIntegerNonBinary(int colIndex) const;
00199   
00201       virtual bool isFreeBinary(int colIndex) const; 
00202 #endif
00203 
00204       virtual const CoinPackedMatrix * getMatrixByRow() const;
00205   
00207       virtual const CoinPackedMatrix * getMatrixByCol() const;
00208   
00210       virtual double getInfinity() const;
00212     
00215 
00216       virtual const double * getColSolution() const;
00217   
00219       virtual const double * getRowPrice() const;
00220   
00222       virtual const double * getReducedCost() const;
00223   
00226       virtual const double * getRowActivity() const;
00227   
00229       virtual double getObjValue() const;
00230   
00233       virtual int getIterationCount() const;
00234   
00252       virtual std::vector<double*> getDualRays(int maxNumRays,
00253                                                bool fullRay=false) const;
00265       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00266   
00267 #if 0
00268 
00270       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00271         const;
00272 #endif
00273 
00274 
00275 
00276   //---------------------------------------------------------------------------
00277 
00280     //-------------------------------------------------------------------------
00284       virtual void setObjCoeff( int elementIndex, double elementValue );
00285 
00288       virtual void setColLower( int elementIndex, double elementValue );
00289       
00292       virtual void setColUpper( int elementIndex, double elementValue );
00293       
00297       virtual void setColBounds( int elementIndex,
00298                                  double lower, double upper );
00299     
00308       virtual void setColSetBounds(const int* indexFirst,
00309                                    const int* indexLast,
00310                                    const double* boundList);
00311       
00314       virtual void setRowLower( int elementIndex, double elementValue );
00315       
00318       virtual void setRowUpper( int elementIndex, double elementValue );
00319     
00323       virtual void setRowBounds( int elementIndex,
00324                                  double lower, double upper );
00325     
00327       virtual void setRowType(int index, char sense, double rightHandSide,
00328                               double range);
00329     
00338       virtual void setRowSetBounds(const int* indexFirst,
00339                                    const int* indexLast,
00340                                    const double* boundList);
00341     
00352       virtual void setRowSetTypes(const int* indexFirst,
00353                                   const int* indexLast,
00354                                   const char* senseList,
00355                                   const double* rhsList,
00356                                   const double* rangeList);
00358     
00359     //-------------------------------------------------------------------------
00363       virtual void setContinuous(int index);
00365       virtual void setInteger(int index);
00368       virtual void setContinuous(const int* indices, int len);
00371       virtual void setInteger(const int* indices, int len);
00373     
00374     //-------------------------------------------------------------------------
00376     virtual void setObjSense(double s);
00377     
00388     virtual void setColSolution(const double * colsol);
00389     
00400     virtual void setRowPrice(const double * rowprice);
00401     
00402     //-------------------------------------------------------------------------
00408       virtual void addCol(const CoinPackedVectorBase& vec,
00409                           const double collb, const double colub,   
00410                           const double obj);
00412       virtual void addCols(const int numcols,
00413                            const CoinPackedVectorBase * const * cols,
00414                            const double* collb, const double* colub,   
00415                            const double* obj);
00417       virtual void deleteCols(const int num, const int * colIndices);
00418     
00420       virtual void addRow(const CoinPackedVectorBase& vec,
00421                           const double rowlb, const double rowub);
00423       virtual void addRow(const CoinPackedVectorBase& vec,
00424                           const char rowsen, const double rowrhs,   
00425                           const double rowrng);
00427       virtual void addRows(const int numrows,
00428                            const CoinPackedVectorBase * const * rows,
00429                            const double* rowlb, const double* rowub);
00431       virtual void addRows(const int numrows,
00432                            const CoinPackedVectorBase * const * rows,
00433                            const char* rowsen, const double* rowrhs,   
00434                            const double* rowrng);
00436       virtual void deleteRows(const int num, const int * rowIndices);
00437 #if 0
00438       //-----------------------------------------------------------------------
00460       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00461                                             double effectivenessLb = 0.0);
00463 
00464 #endif
00465   //---------------------------------------------------------------------------
00466 
00480     virtual void loadProblem(const CoinPackedMatrix& matrix,
00481                              const double* collb, const double* colub,   
00482                              const double* obj,
00483                              const double* rowlb, const double* rowub);
00484                             
00492     virtual void assignProblem(CoinPackedMatrix*& matrix,
00493                                double*& collb, double*& colub, double*& obj,
00494                                double*& rowlb, double*& rowub);
00495 
00508     virtual void loadProblem(const CoinPackedMatrix& matrix,
00509                              const double* collb, const double* colub,
00510                              const double* obj,
00511                              const char* rowsen, const double* rowrhs,   
00512                              const double* rowrng);
00513 
00521     virtual void assignProblem(CoinPackedMatrix*& matrix,
00522                                double*& collb, double*& colub, double*& obj,
00523                                char*& rowsen, double*& rowrhs,
00524                                double*& rowrng);
00525 
00528     virtual void loadProblem(const int numcols, const int numrows,
00529                              const int* start, const int* index,
00530                              const double* value,
00531                              const double* collb, const double* colub,   
00532                              const double* obj,
00533                              const double* rowlb, const double* rowub);
00534 
00537     virtual void loadProblem(const int numcols, const int numrows,
00538                              const int* start, const int* index,
00539                              const double* value,
00540                              const double* collb, const double* colub,   
00541                              const double* obj,
00542                              const char* rowsen, const double* rowrhs,   
00543                              const double* rowrng);
00544 
00545 
00547     virtual int readMps(const char *filename,
00548                          const char *extension = "mps");
00549 
00550 
00555     virtual void writeMps(const char *filename,
00556                           const char *extension = "mps",
00557                           double objSense=0.0) const;
00559 
00567     void passInMessageHandler(CoinMessageHandler * handler);
00569 
00570   //---------------------------------------------------------------------------
00571 
00585       static  void incrementInstanceCounter();
00586 
00595       static  void decrementInstanceCounter();
00596 
00599       static  unsigned int getNumInstances();
00600       
00602       XPRSprob getLpPtr() { return prob_; }
00604 
00606     static int version();
00607 
00610     static int iXprCallCount_;
00611 
00612 
00614       static FILE * getLogFilePtr();
00617       static void setLogFileName( const char * filename );
00619 
00620 
00623 
00624     OsiXprSolverInterface (int newrows = 50, int newnz = 100);
00625 
00627     virtual OsiSolverInterface * clone(bool copyData = true) const;
00628 
00630     OsiXprSolverInterface (const OsiXprSolverInterface &);
00631 
00633     OsiXprSolverInterface & operator=(const OsiXprSolverInterface& rhs);
00634 
00636     virtual ~OsiXprSolverInterface ();
00638 
00639 protected:
00640 
00643 
00644     virtual void applyRowCut( const OsiRowCut & rc );
00645 
00649     virtual void applyColCut( const OsiColCut & cc );
00651 
00652 private:  
00653   
00656 
00657     static const char * logFileName_;
00658 
00660     static FILE * logFilePtr_;
00661 
00663     static  unsigned int numInstances_;
00664 
00666     static  unsigned int osiSerial_;
00667 
00669 
00672 
00673     void gutsOfCopy( const OsiXprSolverInterface & source );
00674 
00676     void gutsOfConstructor(); 
00677 
00679     void gutsOfDestructor(); 
00680 
00682     void freeSolution();
00683 
00686     void freeCachedResults();
00687 
00689     int getNumIntVars() const;
00690 
00693 
00694       void getVarTypes() const;
00695 
00699       void    activateMe() const;
00700 
00705       bool    isDataLoaded() const;
00707 
00708 
00711 
00714     
00715     mutable XPRSprob prob_;
00716     
00718       mutable std::string  xprProbname_;
00720 
00728       mutable CoinPackedMatrix *matrixByRow_;
00729       mutable CoinPackedMatrix *matrixByCol_;
00730 
00732       mutable double  *colupper_;
00733 
00735       mutable double  *collower_;
00736 
00738       mutable double  *rowupper_;
00739 
00741       mutable double  *rowlower_;
00742 
00744       mutable char    *rowsense_;
00745 
00747       mutable double  *rhs_;
00748 
00752       mutable double  *rowrange_;
00753 
00755       mutable double  *objcoeffs_;
00756 
00758       mutable double  objsense_;
00759 
00761       mutable double  *colsol_;
00762 
00764       mutable double  *rowsol_;
00765 
00767       mutable double  *rowact_;
00768 
00770       mutable double  *rowprice_;
00771 
00773       mutable double  *colprice_;
00774 
00776       mutable int     *ivarind_;
00777 
00786       mutable char    *ivartype_;
00787 
00791       mutable char    *vartype_;
00792 
00794       mutable bool lastsolvewasmip;
00796 
00797 };
00798 
00799 //#############################################################################
00805 void
00806 OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00807 
00808 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines