/home/coin/DyLP-1.1.0/Osi/src/OsiSym/OsiSymSolverInterface.hpp

Go to the documentation of this file.
00001 /*===========================================================================*/
00002 /*                                                                           */
00003 /* This file is part of the SYMPHONY Branch, Cut, and Price Callable         */
00004 /* Library.                                                                  */
00005 /*                                                                           */
00006 /* SYMPHONY was jointly developed by Ted Ralphs (tkralphs@lehigh.edu) and    */
00007 /* Laci Ladanyi (ladanyi@us.ibm.com).                                        */
00008 /*                                                                           */
00009 /* (c) Copyright 2004-2006 Ted Ralphs and Lehigh University.                 */
00010 /* All Rights Reserved.                                                      */
00011 /*                                                                           */
00012 /* The authors of this file are Menal Guzelsoy and Ted Ralphs                */
00013 /*                                                                           */
00014 /* This software is licensed under the Common Public License. Please see     */
00015 /* accompanying file for terms.                                              */
00016 /*                                                                           */
00017 /*===========================================================================*/
00018 
00019 #ifndef OsiSymSolverInterface_hpp
00020 #define OsiSymSolverInterface_hpp
00021 
00022 #include "OsiSolverInterface.hpp"
00023 #include "OsiSymSolverParameters.hpp"
00024 /* Switch off part of PROTO as seems to cause problems on some architectures.
00025    and not needed in interface ? */
00026 #define HAS_SRANDOM
00027 #define HAS_RANDOM
00028 #include "SymWarmStart.hpp"
00029 #include "symphony_api.h"
00030 
00031 #include "CoinPackedVector.hpp"
00032 #include "CoinPackedMatrix.hpp"
00033 
00034 #include <iostream>
00035 #include <string>
00036 #include <cassert>
00037 
00038 using namespace std;
00039 
00040 //#############################################################################
00041 
00063 class OsiSymSolverInterface : virtual public OsiSolverInterface {
00064    friend void OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00065    
00066 public:
00068 
00069 
00070    virtual void initialSolve();
00071 
00073    virtual void resolve();
00074 
00076    virtual void branchAndBound();
00077    
00079    virtual void multiCriteriaBranchAndBound();
00080 
00082    virtual double getLbForNewRhs(int cnt, int *index, 
00083                                  double * value);
00085    virtual double getUbForNewRhs(int cnt, int *index, 
00086                                  double * value);
00087 #if 0
00089    virtual double getLbForNewObj(int cnt, int *index, 
00090                                  double * value);
00092 #endif
00093    virtual double getUbForNewObj(int cnt, int *index, 
00094                                  double * value);
00095 
00097 
00098   //---------------------------------------------------------------------------
00115     // Set an integer parameter
00116     virtual bool setIntParam(OsiIntParam key, int value);
00117 
00118     // Set SYMPHONY int parameter
00119     virtual bool setSymParam(OsiSymIntParam key, int value);
00120 
00121     // Set SYMPHONY int parameter directly by the C interface parameter name
00122     virtual bool setSymParam(const std::string key, int value);
00123 
00124 
00125     // Set an double parameter
00126     virtual bool setDblParam(OsiDblParam key, double value);
00127 
00128     // Set SYMPHONY double parameter
00129     virtual bool setSymParam(OsiSymDblParam key, double value);
00130 
00131     // Set SYMPHONY double parameter directly by the C interface parameter name
00132     virtual bool setSymParam(const std::string key, double value);
00133 
00134 
00135 
00136     // Set a string parameter
00137     virtual bool setStrParam(OsiStrParam key, const std::string & value);
00138 
00139     // Set SYMPHONY string parameter
00140     virtual bool setSymParam(OsiSymStrParam key, const std::string & value);
00141 
00142     // Set SYMPHONY string parameter directly by the C interface parameter name
00143     virtual bool setSymParam(const std::string key, const std::string value);
00144 
00145 
00146 
00147     // Get an integer parameter
00148     virtual bool getIntParam(OsiIntParam key, int& value) const;
00149 
00150     // Get SYMPHONY int parameter
00151     virtual bool getSymParam(OsiSymIntParam key, int& value) const;
00152 
00153     // Get SYMPHONY int parameter directly by the C interface parameter name
00154     virtual bool getSymParam(const std::string key, int& value) const;
00155 
00156 
00157     // Get an double parameter
00158     virtual bool getDblParam(OsiDblParam key, double& value) const;
00159 
00160     // Get SYMPHONY double parameter
00161     virtual bool getSymParam(OsiSymDblParam key, double& value) const;
00162 
00163     // Get SYMPHONY double parameter directly by the C interface parameter name
00164     virtual bool getSymParam(const std::string key, double& value) const;
00165 
00166 
00167 
00168     // Get a string parameter
00169     virtual bool getStrParam(OsiStrParam key, std::string& value) const;
00170 
00171     // Get SYMPHONY string parameter
00172     virtual bool getSymParam(OsiSymStrParam key, std::string& value) const;
00173 
00174     // Get SYMPHONY string parameter directly by the C interface parameter name
00175     virtual bool getSymParam(const std::string key, std::string& value) const;
00176 
00178 
00179   //---------------------------------------------------------------------------
00181 
00182 
00183    virtual bool isAbandoned() const;
00184 
00186    virtual bool isProvenOptimal() const;
00187 
00189    virtual bool isProvenPrimalInfeasible() const;
00190 
00192    virtual bool isProvenDualInfeasible() const {
00193       throw CoinError("Error: Function not implemented",
00194                       "isProvenDualInfeasible", "OsiSymSolverInterface");
00195    };
00197    virtual bool isPrimalObjectiveLimitReached() const;
00198 
00200     virtual bool isDualObjectiveLimitReached() const{
00201        throw CoinError("Error: Function not implemented",
00202                        "isDualObjectiveLimitReached", "OsiSymSolverInterface");
00203     };
00205    virtual bool isIterationLimitReached() const;
00206 
00208    virtual bool isTimeLimitReached() const;
00209 
00211    virtual bool isTargetGapReached() const;
00212 
00214 
00215   //---------------------------------------------------------------------------
00225     virtual CoinWarmStart *getEmptyWarmStart () const{
00226        throw CoinError("Error: Function not implemented",
00227                        "getEmptyWarmStart", "OsiSymSolverInterface");
00228     };
00229 
00236    /* 
00237       virtual CoinWarmStart* getWarmStart(bool keepTreeInSymEnv = false) const;
00238    */
00239 
00240     virtual CoinWarmStart* getWarmStart() const;
00241 
00246    virtual bool setWarmStart(const CoinWarmStart* warmstart);
00248    
00249   //---------------------------------------------------------------------------
00260 
00261    sym_environment *getSymphonyEnvironment() const {return env_;}
00262    
00264    virtual int getNumCols() const;
00265    
00267    virtual int getNumRows() const;
00268   
00270    virtual int getNumElements() const;
00271   
00273    virtual const double * getColLower() const;
00274   
00276    virtual const double * getColUpper() const;
00277   
00287    virtual const char * getRowSense() const;
00288   
00301    virtual const double * getRightHandSide() const;
00302   
00311    virtual const double * getRowRange() const;
00312   
00314    virtual const double * getRowLower() const;
00315   
00317    virtual const double * getRowUpper() const;
00318   
00320    virtual const double * getObjCoefficients() const;
00321   
00325    virtual const double * getObj2Coefficients() const;
00326 
00328    virtual double getObjSense() const; 
00329  
00331    virtual bool isContinuous(int colIndex) const;
00332   
00334    virtual bool isBinary(int colIndex) const;  
00335 
00340    virtual bool isInteger(int colIndex) const;
00341   
00343    virtual bool isIntegerNonBinary(int colIndex) const;
00344   
00346    virtual bool isFreeBinary(int colIndex) const; 
00347    
00349    virtual const CoinPackedMatrix * getMatrixByRow() const;
00350   
00352    virtual const CoinPackedMatrix * getMatrixByCol() const;  
00353 
00355       virtual double getInfinity() const;
00356 
00358     
00361 
00362    virtual const double * getColSolution() const;
00363   
00365       virtual const double * getRowPrice() const{
00366          //       throw CoinError("Error: Function not implemented",
00367          //       "getRowPrice", "OsiSymSolverInterface");
00368          return (0);
00369     };
00370   
00372       virtual const double * getReducedCost() const{
00373          //       throw CoinError("Error: Function not implemented",
00374          //       "getReducedCost", "OsiSymSolverInterface");
00375          return (0);
00376     };
00377   
00380    virtual const double * getRowActivity() const;
00381   
00383    virtual double getObjValue() const;
00384 
00386    virtual double getPrimalBound() const;
00387 
00390    virtual int getIterationCount() const;
00391   
00405       virtual std::vector<double*> getDualRays(int maxNumRays) const{
00406        throw CoinError("Error: Function not implemented",
00407                        "getDualRays", "OsiSymSolverInterface");
00408     };
00420       virtual std::vector<double*> getPrimalRays(int maxNumRays) const{
00421        throw CoinError("Error: Function not implemented",
00422                        "getPrimalRays", "OsiSymSolverInterface");
00423     };
00424   
00426 
00427     //-------------------------------------------------------------------------
00440    virtual void setObjCoeff( int elementIndex, double elementValue );
00441 
00443    virtual void setObj2Coeff( int elementIndex, double elementValue );
00444 
00447    virtual void setColLower( int elementIndex, double elementValue );
00448       
00451    virtual void setColUpper( int elementIndex, double elementValue );      
00452 
00455    virtual void setRowLower( int elementIndex, double elementValue );
00456       
00459    virtual void setRowUpper( int elementIndex, double elementValue );
00460     
00462       virtual void setRowType(int index, char sense, double rightHandSide,
00463                               double range);
00464     
00467    virtual void setObjSense(double s);
00468     
00478    virtual void setColSolution(const double *colsol);
00479    
00482    virtual void setPrimalBound(const double bound);
00483 
00494    virtual void setRowPrice(const double * rowprice){
00495        throw CoinError("Error: Function not implemented",
00496                        "setRowPrice", "OsiSymSolverInterface");
00497     };
00498 
00500 
00501     //-------------------------------------------------------------------------
00505    virtual void setContinuous(int index);
00506 
00508    virtual void setInteger(int index);
00509 
00510 
00511    virtual void setColName(char **colname);
00512 
00514     //-------------------------------------------------------------------------
00515     
00516     //-------------------------------------------------------------------------
00524       virtual void addCol(const CoinPackedVectorBase& vec,
00525                           const double collb, const double colub,   
00526                           const double obj);
00527 
00529    virtual void deleteCols(const int num, const int * colIndices);
00530     
00532    virtual void addRow(const CoinPackedVectorBase& vec,
00533                        const double rowlb, const double rowub);
00535    virtual void addRow(const CoinPackedVectorBase& vec,
00536                        const char rowsen, const double rowrhs,   
00537                        const double rowrng);
00538    
00540    virtual void deleteRows(const int num, const int * rowIndices);
00541     
00543 
00544   //---------------------------------------------------------------------------
00545 
00548 
00549     virtual void loadProblem();
00550    
00562     virtual void loadProblem(const CoinPackedMatrix& matrix,
00563                              const double* collb, const double* colub,   
00564                              const double* obj,
00565                              const double* rowlb, const double* rowub);
00566                             
00576     virtual void assignProblem(CoinPackedMatrix*& matrix,
00577                                double*& collb, double*& colub, double*& obj,
00578                                double*& rowlb, double*& rowub);
00579 
00592     virtual void loadProblem(const CoinPackedMatrix& matrix,
00593                              const double* collb, const double* colub,
00594                              const double* obj,
00595                              const char* rowsen, const double* rowrhs,   
00596                              const double* rowrng);
00597 
00607     virtual void assignProblem(CoinPackedMatrix*& matrix,
00608                                double*& collb, double*& colub, double*& obj,
00609                                char*& rowsen, double*& rowrhs,
00610                                double*& rowrng);
00611 
00614     virtual void loadProblem(const int numcols, const int numrows,
00615                              const CoinBigIndex * start, const int* index,
00616                              const double* value,
00617                              const double* collb, const double* colub,   
00618                              const double* obj,
00619                              const double* rowlb, const double* rowub);
00620 
00623     virtual void loadProblem(const int numcols, const int numrows,
00624                              const CoinBigIndex * start, const int* index,
00625                              const double* value,
00626                              const double* collb, const double* colub,   
00627                              const double* obj,
00628                              const char* rowsen, const double* rowrhs,   
00629                              const double* rowrng);
00630 
00637     virtual void writeMps(const char *filename,
00638                           const char *extension = "mps",
00639                           double objSense=0.0) const;
00640 
00641    void parseCommandLine(int argc, char **argv);
00642 
00643    virtual int readMps(const char * infile, const char *extension = "mps");
00644 
00645    virtual int readGMPL(const char * modelFile, const char * dataFile=NULL);
00646 
00647    void findInitialBounds();
00648 
00649    int createPermanentCutPools();
00650 
00652 
00653   //---------------------------------------------------------------------------
00654 
00655    enum keepCachedFlag {
00657       KEEPCACHED_NONE    = 0,
00659       KEEPCACHED_COLUMN  = 1,
00661       KEEPCACHED_ROW     = 2,
00663       KEEPCACHED_MATRIX  = 4,
00665       KEEPCACHED_RESULTS = 8,
00667       KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00669       KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00671       FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
00673       FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
00675       FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
00677       FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
00678    };
00679    
00681 
00682 
00683     OsiSymSolverInterface(); 
00684     
00690    virtual OsiSolverInterface * clone(bool copyData = true) const;
00691   
00693     OsiSymSolverInterface(const OsiSymSolverInterface &);
00694   
00696     OsiSymSolverInterface & operator=(const OsiSymSolverInterface& rhs);
00697   
00699     virtual ~OsiSymSolverInterface ();
00700 
00707     virtual void reset();
00709 
00710   //---------------------------------------------------------------------------
00711 
00712 protected:
00714 
00715 
00716    virtual void applyRowCut( const OsiRowCut & rc );
00717 
00719    virtual void applyColCut( const OsiColCut & cc );
00720 
00728     void setInitialData();
00730 
00731 private:
00732 
00734   void gutsOfConstructor();
00735   
00737   void gutsOfDestructor();
00738 
00740   void freeCachedColRim();
00741 
00743   void freeCachedRowRim();
00744 
00746   void freeCachedResults();
00747   
00749   void freeCachedMatrix();
00750 
00752   void freeCachedData( int keepCached = KEEPCACHED_NONE );
00753 
00755   void freeAllMemory();
00756 
00758   void printBounds(); 
00759 
00762 
00763    sym_environment *env_;
00765    
00767    mutable double  *obj_;
00768 
00770    mutable double  *obj2_;
00771    
00773    mutable double  *collower_;
00774    
00776    mutable double  *colupper_;
00777    
00779    mutable char    *rowsense_;
00780   
00782    mutable double  *rhs_;
00783   
00787    mutable double  *rowrange_;
00788    
00790    mutable double  *rowlower_;
00791    
00793    mutable double  *rowupper_;
00794    
00796    mutable double  *colsol_;
00797    
00799    mutable double  *rowact_;
00800    
00802    mutable CoinPackedMatrix *matrixByRow_;  
00803    
00805    mutable CoinPackedMatrix *matrixByCol_;  
00806 
00807 };
00808 
00809 //#############################################################################
00815 void OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00816 
00817 #endif

Generated on Wed Aug 22 05:43:41 2007 by  doxygen 1.4.7