- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Cgl-0.53.1/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 #include "SymWarmStart.hpp"
    00025 #include "symphony.h"
    00026
    00027 #include "CoinPackedVector.hpp"
    00028 #include "CoinPackedMatrix.hpp"
    00029
    00030 #include <iostream>
    00031 #include <string>
    00032 #include <cassert>
    00033
    00034 //#############################################################################
    00035
    00057 class OsiSymSolverInterface : virtual public OsiSolverInterface {
    00058    friend int OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00059
    00060 public:
    00062
    00063
    00064    virtual void initialSolve();
    00065
    00067    virtual void resolve();
    00068
    00070    virtual void branchAndBound();
    00071
    00073    virtual void multiCriteriaBranchAndBound();
    00074
    00076    virtual double getLbForNewRhs(int cnt, int *index,
    00077                                  double * value);
    00079    virtual double getUbForNewRhs(int cnt, int *index,
    00080                                  double * value);
    00081 #if 0
    00083    virtual double getLbForNewObj(int cnt, int *index,
    00084                                  double * value);
    00086 #endif
    00087    virtual double getUbForNewObj(int cnt, int *index,
    00088                                  double * value);
    00089
    00091
    00092   //---------------------------------------------------------------------------
    00109     // Set an integer parameter
    00110     virtual bool setIntParam(OsiIntParam key, int value);
    00111
    00112     // Set SYMPHONY int parameter
    00113     virtual bool setSymParam(OsiSymIntParam key, int value);
    00114
    00115     // Set SYMPHONY int parameter directly by the C interface parameter name
    00116     virtual bool setSymParam(const std::string key, int value);
    00117
    00118
    00119     // Set an double parameter
    00120     virtual bool setDblParam(OsiDblParam key, double value);
    00121
    00122     // Set SYMPHONY double parameter
    00123     virtual bool setSymParam(OsiSymDblParam key, double value);
    00124
    00125     // Set SYMPHONY double parameter directly by the C interface parameter name
    00126     virtual bool setSymParam(const std::string key, double value);
    00127
    00128
    00129
    00130     // Set a string parameter
    00131     virtual bool setStrParam(OsiStrParam key, const std::string & value);
    00132
    00133     // Set SYMPHONY string parameter
    00134     virtual bool setSymParam(OsiSymStrParam key, const std::string & value);
    00135
    00136     // Set SYMPHONY string parameter directly by the C interface parameter name
    00137     virtual bool setSymParam(const std::string key, const std::string value);
    00138
    00139
    00140
    00141     // Get an integer parameter
    00142     virtual bool getIntParam(OsiIntParam key, int& value) const;
    00143
    00144     // Get SYMPHONY int parameter
    00145     virtual bool getSymParam(OsiSymIntParam key, int& value) const;
    00146
    00147     // Get SYMPHONY int parameter directly by the C interface parameter name
    00148     virtual bool getSymParam(const std::string key, int& value) const;
    00149
    00150
    00151     // Get an double parameter
    00152     virtual bool getDblParam(OsiDblParam key, double& value) const;
    00153
    00154     // Get SYMPHONY double parameter
    00155     virtual bool getSymParam(OsiSymDblParam key, double& value) const;
    00156
    00157     // Get SYMPHONY double parameter directly by the C interface parameter name
    00158     virtual bool getSymParam(const std::string key, double& value) const;
    00159
    00160
    00161
    00162     // Get a string parameter
    00163     virtual bool getStrParam(OsiStrParam key, std::string& value) const;
    00164
    00165     // Get SYMPHONY string parameter
    00166     virtual bool getSymParam(OsiSymStrParam key, std::string& value) const;
    00167
    00168     // Get SYMPHONY string parameter directly by the C interface parameter name
    00169     virtual bool getSymParam(const std::string key, std::string& value) const;
    00170
    00172
    00173   //---------------------------------------------------------------------------
    00175
    00176
    00177    virtual bool isAbandoned() const;
    00178
    00180    virtual bool isProvenOptimal() const;
    00181
    00183    virtual bool isProvenPrimalInfeasible() const;
    00184
    00186    virtual bool isProvenDualInfeasible() const {
    00187       throw CoinError("Error: Function not implemented",
    00188                       "isProvenDualInfeasible", "OsiSymSolverInterface");
    00189    }
    00191    virtual bool isPrimalObjectiveLimitReached() const;
    00192
    00194     virtual bool isDualObjectiveLimitReached() const{
    00195        throw CoinError("Error: Function not implemented",
    00196                        "isDualObjectiveLimitReached", "OsiSymSolverInterface");
    00197     }
    00199    virtual bool isIterationLimitReached() const;
    00200
    00202    virtual bool isTimeLimitReached() const;
    00203
    00205    virtual bool isTargetGapReached() const;
    00206
    00208
    00209   //---------------------------------------------------------------------------
    00219     virtual CoinWarmStart *getEmptyWarmStart () const{
    00220        throw CoinError("Error: Function not implemented",
    00221                        "getEmptyWarmStart", "OsiSymSolverInterface");
    00222     }
    00223
    00230    /*
    00231       virtual CoinWarmStart* getWarmStart(bool keepTreeInSymEnv = false) const;
    00232    */
    00233
    00234     virtual CoinWarmStart* getWarmStart() const;
    00235
    00240    virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00242
    00243   //---------------------------------------------------------------------------
    00254
    00255    sym_environment *getSymphonyEnvironment() const {return env_;}
    00256
    00258    virtual int getNumCols() const;
    00259
    00261    virtual int getNumRows() const;
    00262
    00264    virtual int getNumElements() const;
    00265
    00267    virtual const double * getColLower() const;
    00268
    00270    virtual const double * getColUpper() const;
    00271
    00281    virtual const char * getRowSense() const;
    00282
    00295    virtual const double * getRightHandSide() const;
    00296
    00305    virtual const double * getRowRange() const;
    00306
    00308    virtual const double * getRowLower() const;
    00309
    00311    virtual const double * getRowUpper() const;
    00312
    00314    virtual const double * getObjCoefficients() const;
    00315
    00319    virtual const double * getObj2Coefficients() const;
    00320
    00322    virtual double getObjSense() const;
    00323
    00325    virtual bool isContinuous(int colIndex) const;
    00326
    00328    virtual bool isBinary(int colIndex) const;
    00329
    00334    virtual bool isInteger(int colIndex) const;
    00335
    00337    virtual bool isIntegerNonBinary(int colIndex) const;
    00338
    00340    virtual bool isFreeBinary(int colIndex) const;
    00341
    00343    virtual const CoinPackedMatrix * getMatrixByRow() const;
    00344
    00346    virtual const CoinPackedMatrix * getMatrixByCol() const;
    00347
    00349       virtual double getInfinity() const;
    00350
    00352
    00355
    00356    virtual const double * getColSolution() const;
    00357
    00359       virtual const double * getRowPrice() const{
    00360          //       throw CoinError("Error: Function not implemented",
    00361          //       "getRowPrice", "OsiSymSolverInterface");
    00362          return (0);
    00363     }
    00364
    00366       virtual const double * getReducedCost() const{
    00367          //       throw CoinError("Error: Function not implemented",
    00368          //       "getReducedCost", "OsiSymSolverInterface");
    00369          return (0);
    00370     }
    00371
    00374    virtual const double * getRowActivity() const;
    00375
    00377    virtual double getObjValue() const;
    00378
    00380    virtual double getPrimalBound() const;
    00381
    00384    virtual int getIterationCount() const;
    00385
    00399       virtual std::vector<double*> getDualRays(int maxNumRays) const{
    00400        throw CoinError("Error: Function not implemented",
    00401                        "getDualRays", "OsiSymSolverInterface");
    00402     }
    00414       virtual std::vector<double*> getPrimalRays(int maxNumRays) const{
    00415        throw CoinError("Error: Function not implemented",
    00416                        "getPrimalRays", "OsiSymSolverInterface");
    00417     }
    00418
    00420
    00421     //-------------------------------------------------------------------------
    00434    virtual void setObjCoeff( int elementIndex, double elementValue );
    00435
    00437    virtual void setObj2Coeff( int elementIndex, double elementValue );
    00438
    00439    using OsiSolverInterface::setColLower ;
    00442    virtual void setColLower( int elementIndex, double elementValue );
    00443
    00444    using OsiSolverInterface::setColUpper ;
    00447    virtual void setColUpper( int elementIndex, double elementValue );
    00448
    00451    virtual void setRowLower( int elementIndex, double elementValue );
    00452
    00455    virtual void setRowUpper( int elementIndex, double elementValue );
    00456
    00458       virtual void setRowType(int index, char sense, double rightHandSide,
    00459                               double range);
    00460
    00463    virtual void setObjSense(double s);
    00464
    00474    virtual void setColSolution(const double *colsol);
    00475
    00478    virtual void setPrimalBound(const double bound);
    00479
    00490    virtual void setRowPrice(const double * rowprice){
    00491        throw CoinError("Error: Function not implemented",
    00492                        "setRowPrice", "OsiSymSolverInterface");
    00493     }
    00494
    00496
    00497     //-------------------------------------------------------------------------
    00500
    00501       using OsiSolverInterface::setContinuous ;
    00503    virtual void setContinuous(int index);
    00504
    00505       using OsiSolverInterface::setInteger ;
    00507    virtual void setInteger(int index);
    00508
    00509
    00510       using OsiSolverInterface::setColName ;
    00511    virtual void setColName(char **colname);
    00512
    00514     //-------------------------------------------------------------------------
    00515
    00516     //-------------------------------------------------------------------------
    00523
    00524       using OsiSolverInterface::addCol ;
    00526       virtual void addCol(const CoinPackedVectorBase& vec,
    00527                           const double collb, const double colub,
    00528                           const double obj);
    00529
    00531    virtual void deleteCols(const int num, const int * colIndices);
    00532
    00533       using OsiSolverInterface::addRow ;
    00535    virtual void addRow(const CoinPackedVectorBase& vec,
    00536                        const double rowlb, const double rowub);
    00538    virtual void addRow(const CoinPackedVectorBase& vec,
    00539                        const char rowsen, const double rowrhs,
    00540                        const double rowrng);
    00541
    00543    virtual void deleteRows(const int num, const int * rowIndices);
    00544
    00546
    00547   //---------------------------------------------------------------------------
    00548
    00551
    00552     virtual void loadProblem();
    00553
    00565     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00566                              const double* collb, const double* colub,
    00567                              const double* obj,
    00568                              const double* rowlb, const double* rowub);
    00569
    00579     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00580                                double*& collb, double*& colub, double*& obj,
    00581                                double*& rowlb, double*& rowub);
    00582
    00595     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00596                              const double* collb, const double* colub,
    00597                              const double* obj,
    00598                              const char* rowsen, const double* rowrhs,
    00599                              const double* rowrng);
    00600
    00610     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00611                                double*& collb, double*& colub, double*& obj,
    00612                                char*& rowsen, double*& rowrhs,
    00613                                double*& rowrng);
    00614
    00617     virtual void loadProblem(const int numcols, const int numrows,
    00618                              const CoinBigIndex * start, const int* index,
    00619                              const double* value,
    00620                              const double* collb, const double* colub,
    00621                              const double* obj,
    00622                              const double* rowlb, const double* rowub);
    00623
    00626     virtual void loadProblem(const int numcols, const int numrows,
    00627                              const CoinBigIndex * start, const int* index,
    00628                              const double* value,
    00629                              const double* collb, const double* colub,
    00630                              const double* obj,
    00631                              const char* rowsen, const double* rowrhs,
    00632                              const double* rowrng);
    00633
    00640     virtual void writeMps(const char *filename,
    00641                           const char *extension = "mps",
    00642                           double objSense=0.0) const;
    00643
    00644    void parseCommandLine(int argc, char **argv);
    00645
    00646    using OsiSolverInterface::readMps ;
    00647    virtual int readMps(const char * infile, const char *extension = "mps");
    00648
    00649    virtual int readGMPL(const char * modelFile, const char * dataFile=NULL);
    00650
    00651    void findInitialBounds();
    00652
    00653    int createPermanentCutPools();
    00654
    00656
    00657   //---------------------------------------------------------------------------
    00658
    00659    enum keepCachedFlag {
    00661       KEEPCACHED_NONE    = 0,
    00663       KEEPCACHED_COLUMN  = 1,
    00665       KEEPCACHED_ROW     = 2,
    00667       KEEPCACHED_MATRIX  = 4,
    00669       KEEPCACHED_RESULTS = 8,
    00671       KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00673       KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00675       FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
    00677       FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
    00679       FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
    00681       FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
    00682    };
    00683
    00685
    00686
    00687     OsiSymSolverInterface();
    00688
    00694    virtual OsiSolverInterface * clone(bool copyData = true) const;
    00695
    00697     OsiSymSolverInterface(const OsiSymSolverInterface &);
    00698
    00700     OsiSymSolverInterface & operator=(const OsiSymSolverInterface& rhs);
    00701
    00703     virtual ~OsiSymSolverInterface ();
    00704
    00711     virtual void reset();
    00713
    00714   //---------------------------------------------------------------------------
    00715
    00716 protected:
    00718
    00719
    00720    virtual void applyRowCut( const OsiRowCut & rc );
    00721
    00723    virtual void applyColCut( const OsiColCut & cc );
    00724
    00732     void setInitialData();
    00734
    00735 private:
    00736
    00738   void gutsOfConstructor();
    00739
    00741   void gutsOfDestructor();
    00742
    00744   void freeCachedColRim();
    00745
    00747   void freeCachedRowRim();
    00748
    00750   void freeCachedResults();
    00751
    00753   void freeCachedMatrix();
    00754
    00756   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00757
    00759   void freeAllMemory();
    00760
    00762   void printBounds();
    00763
    00766
    00767    sym_environment *env_;
    00769
    00771    mutable double  *obj_;
    00772
    00774    mutable double  *obj2_;
    00775
    00777    mutable double  *collower_;
    00778
    00780    mutable double  *colupper_;
    00781
    00783    mutable char    *rowsense_;
    00784
    00786    mutable double  *rhs_;
    00787
    00791    mutable double  *rowrange_;
    00792
    00794    mutable double  *rowlower_;
    00795
    00797    mutable double  *rowupper_;
    00798
    00800    mutable double  *colsol_;
    00801
    00803    mutable double  *rowact_;
    00804
    00806    mutable CoinPackedMatrix *matrixByRow_;
    00807
    00809    mutable CoinPackedMatrix *matrixByCol_;
    00810
    00811 };
    00812
    00813 //#############################################################################
    00819 int OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00820
    00821 #endif