# 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;
    00063     // Set mipstart option (pass column solution to XPRESS before MIP start)
    00064     void setMipStart(bool value) { domipstart = value; }
    00065     // Get mipstart option value
    00066     bool getMipStart() const { return domipstart; }
    00068
    00069   //---------------------------------------------------------------------------
    00071
    00072
    00073     virtual bool isAbandoned() const;
    00075     virtual bool isProvenOptimal() const;
    00077     virtual bool isProvenPrimalInfeasible() const;
    00079     virtual bool isProvenDualInfeasible() const;
    00081     virtual bool isPrimalObjectiveLimitReached() const;
    00083     virtual bool isDualObjectiveLimitReached() const;
    00085     virtual bool isIterationLimitReached() const;
    00087
    00088   //---------------------------------------------------------------------------
    00091
    00092     CoinWarmStart *getEmptyWarmStart () const;
    00094     virtual CoinWarmStart* getWarmStart() const;
    00097     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00099
    00100   //---------------------------------------------------------------------------
    00107
    00108     virtual void markHotStart();
    00110     virtual void solveFromHotStart();
    00112     virtual void unmarkHotStart();
    00114
    00115   //---------------------------------------------------------------------------
    00130
    00131       virtual int getNumCols() const;
    00132
    00134       virtual int getNumRows() const;
    00135
    00137       virtual int getNumElements() const;
    00138
    00140       virtual const double * getColLower() const;
    00141
    00143       virtual const double * getColUpper() const;
    00144
    00154       virtual const char * getRowSense() const;
    00155
    00164       virtual const double * getRightHandSide() const;
    00165
    00174       virtual const double * getRowRange() const;
    00175
    00177       virtual const double * getRowLower() const;
    00178
    00180       virtual const double * getRowUpper() const;
    00181
    00183       virtual const double * getObjCoefficients() const;
    00184
    00186       virtual double getObjSense() const;
    00187
    00189       virtual bool isContinuous(int colIndex) const;
    00190
    00191 #if 0
    00193       virtual bool isBinary(int colIndex) const;
    00194
    00199       virtual bool isInteger(int colIndex) const;
    00200
    00202       virtual bool isIntegerNonBinary(int colIndex) const;
    00203
    00205       virtual bool isFreeBinary(int colIndex) const;
    00206 #endif
    00208       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00209
    00211       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00212
    00214       virtual double getInfinity() const;
    00216
    00219
    00220       virtual const double * getColSolution() const;
    00221
    00223       virtual const double * getRowPrice() const;
    00224
    00226       virtual const double * getReducedCost() const;
    00227
    00230       virtual const double * getRowActivity() const;
    00231
    00233       virtual double getObjValue() const;
    00234
    00237       virtual int getIterationCount() const;
    00238
    00256       virtual std::vector<double*> getDualRays(int maxNumRays,
    00257                                                bool fullRay=false) const;
    00269       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00270
    00271 #if 0
    00272
    00274       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00275         const;
    00276 #endif
    00277
    00278
    00279
    00280   //---------------------------------------------------------------------------
    00281
    00284     //-------------------------------------------------------------------------
    00288       virtual void setObjCoeff( int elementIndex, double elementValue );
    00289
    00292       virtual void setColLower( int elementIndex, double elementValue );
    00293
    00296       virtual void setColUpper( int elementIndex, double elementValue );
    00297
    00301       virtual void setColBounds( int elementIndex,
    00302                                  double lower, double upper );
    00303
    00312       virtual void setColSetBounds(const int* indexFirst,
    00313                                    const int* indexLast,
    00314                                    const double* boundList);
    00315
    00318       virtual void setRowLower( int elementIndex, double elementValue );
    00319
    00322       virtual void setRowUpper( int elementIndex, double elementValue );
    00323
    00327       virtual void setRowBounds( int elementIndex,
    00328                                  double lower, double upper );
    00329
    00331       virtual void setRowType(int index, char sense, double rightHandSide,
    00332                               double range);
    00333
    00342       virtual void setRowSetBounds(const int* indexFirst,
    00343                                    const int* indexLast,
    00344                                    const double* boundList);
    00345
    00356       virtual void setRowSetTypes(const int* indexFirst,
    00357                                   const int* indexLast,
    00358                                   const char* senseList,
    00359                                   const double* rhsList,
    00360                                   const double* rangeList);
    00362
    00363     //-------------------------------------------------------------------------
    00367       virtual void setContinuous(int index);
    00369       virtual void setInteger(int index);
    00372       virtual void setContinuous(const int* indices, int len);
    00375       virtual void setInteger(const int* indices, int len);
    00377
    00378     //-------------------------------------------------------------------------
    00380     virtual void setObjSense(double s);
    00381
    00392     virtual void setColSolution(const double * colsol);
    00393
    00404     virtual void setRowPrice(const double * rowprice);
    00405
    00406     //-------------------------------------------------------------------------
    00412       virtual void addCol(const CoinPackedVectorBase& vec,
    00413                           const double collb, const double colub,
    00414                           const double obj);
    00416       virtual void addCols(const int numcols,
    00417                            const CoinPackedVectorBase * const * cols,
    00418                            const double* collb, const double* colub,
    00419                            const double* obj);
    00421       virtual void deleteCols(const int num, const int * colIndices);
    00422
    00424       virtual void addRow(const CoinPackedVectorBase& vec,
    00425                           const double rowlb, const double rowub);
    00427       virtual void addRow(const CoinPackedVectorBase& vec,
    00428                           const char rowsen, const double rowrhs,
    00429                           const double rowrng);
    00431       virtual void addRows(const int numrows,
    00432                            const CoinPackedVectorBase * const * rows,
    00433                            const double* rowlb, const double* rowub);
    00435       virtual void addRows(const int numrows,
    00436                            const CoinPackedVectorBase * const * rows,
    00437                            const char* rowsen, const double* rowrhs,
    00438                            const double* rowrng);
    00440       virtual void deleteRows(const int num, const int * rowIndices);
    00441 #if 0
    00442       //-----------------------------------------------------------------------
    00464       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00465                                             double effectivenessLb = 0.0);
    00467
    00468 #endif
    00469   //---------------------------------------------------------------------------
    00470
    00484     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00485                              const double* collb, const double* colub,
    00486                              const double* obj,
    00487                              const double* rowlb, const double* rowub);
    00488
    00496     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00497                                double*& collb, double*& colub, double*& obj,
    00498                                double*& rowlb, double*& rowub);
    00499
    00512     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00513                              const double* collb, const double* colub,
    00514                              const double* obj,
    00515                              const char* rowsen, const double* rowrhs,
    00516                              const double* rowrng);
    00517
    00525     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00526                                double*& collb, double*& colub, double*& obj,
    00527                                char*& rowsen, double*& rowrhs,
    00528                                double*& rowrng);
    00529
    00532     virtual void loadProblem(const int numcols, const int numrows,
    00533                              const int* start, const int* index,
    00534                              const double* value,
    00535                              const double* collb, const double* colub,
    00536                              const double* obj,
    00537                              const double* rowlb, const double* rowub);
    00538
    00541     virtual void loadProblem(const int numcols, const int numrows,
    00542                              const int* start, const int* index,
    00543                              const double* value,
    00544                              const double* collb, const double* colub,
    00545                              const double* obj,
    00546                              const char* rowsen, const double* rowrhs,
    00547                              const double* rowrng);
    00548
    00549
    00551     virtual int readMps(const char *filename,
    00552                          const char *extension = "mps");
    00553
    00554
    00559     virtual void writeMps(const char *filename,
    00560                           const char *extension = "mps",
    00561                           double objSense=0.0) const;
    00563
    00571     void passInMessageHandler(CoinMessageHandler * handler);
    00573
    00574   //---------------------------------------------------------------------------
    00575
    00589       static  void incrementInstanceCounter();
    00590
    00599       static  void decrementInstanceCounter();
    00600
    00603       static  unsigned int getNumInstances();
    00604
    00606       XPRSprob getLpPtr() { return prob_; }
    00608
    00610     static int version();
    00611
    00614     static int iXprCallCount_;
    00615
    00616
    00618       static FILE * getLogFilePtr();
    00621       static void setLogFileName( const char * filename );
    00623
    00624
    00627
    00628     OsiXprSolverInterface (int newrows = 50, int newnz = 100);
    00629
    00631     virtual OsiSolverInterface * clone(bool copyData = true) const;
    00632
    00634     OsiXprSolverInterface (const OsiXprSolverInterface &);
    00635
    00637     OsiXprSolverInterface & operator=(const OsiXprSolverInterface& rhs);
    00638
    00640     virtual ~OsiXprSolverInterface ();
    00642
    00643 protected:
    00644
    00647
    00648     virtual void applyRowCut( const OsiRowCut & rc );
    00649
    00653     virtual void applyColCut( const OsiColCut & cc );
    00655
    00656 private:
    00657
    00660
    00661     static const char * logFileName_;
    00662
    00664     static FILE * logFilePtr_;
    00665
    00667     static  unsigned int numInstances_;
    00668
    00670     static  unsigned int osiSerial_;
    00671
    00673
    00676
    00677     void gutsOfCopy( const OsiXprSolverInterface & source );
    00678
    00680     void gutsOfConstructor();
    00681
    00683     void gutsOfDestructor();
    00684
    00686     void freeSolution();
    00687
    00690     void freeCachedResults();
    00691
    00693     int getNumIntVars() const;
    00694
    00697
    00698       void getVarTypes() const;
    00699
    00703       void    activateMe() const;
    00704
    00709       bool    isDataLoaded() const;
    00711
    00712
    00715
    00718
    00719     mutable XPRSprob prob_;
    00720
    00722       mutable std::string  xprProbname_;
    00724
    00732       mutable CoinPackedMatrix *matrixByRow_;
    00733       mutable CoinPackedMatrix *matrixByCol_;
    00734
    00736       mutable double  *colupper_;
    00737
    00739       mutable double  *collower_;
    00740
    00742       mutable double  *rowupper_;
    00743
    00745       mutable double  *rowlower_;
    00746
    00748       mutable char    *rowsense_;
    00749
    00751       mutable double  *rhs_;
    00752
    00756       mutable double  *rowrange_;
    00757
    00759       mutable double  *objcoeffs_;
    00760
    00762       mutable double  objsense_;
    00763
    00765       mutable double  *colsol_;
    00766
    00768       mutable double  *rowsol_;
    00769
    00771       mutable double  *rowact_;
    00772
    00774       mutable double  *rowprice_;
    00775
    00777       mutable double  *colprice_;
    00778
    00780       mutable int     *ivarind_;
    00781
    00790       mutable char    *ivartype_;
    00791
    00795       mutable char    *vartype_;
    00796
    00798       mutable bool lastsolvewasmip;
    00800
    00801
    00803       bool            domipstart;
    00804 };
    00805
    00806 //#############################################################################
    00808 void OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00809
    00810 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines