- Main Page
- Namespaces
- Classes
- Files
- Directories

- Search for |

- File List
- File Members

# OsiTestSolverInterface.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2000, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 // This file is licensed under the terms of Eclipse Public License (EPL).
    00004
    00005 // this is a copy of OsiVolSolverInterface (trunk rev. 1466) renamed to OsiTestSolverInterface
    00006
    00007 #ifndef OsiTestSolverInterface_H
    00008 #define OsiTestSolverInterface_H
    00009
    00010 #include <string>
    00011
    00012 #include "OsiTestSolver.hpp"
    00013
    00014 #include "CoinPackedMatrix.hpp"
    00015
    00016 #include "OsiSolverInterface.hpp"
    00017
    00018 static const double OsiTestInfinity = 1.0e31;
    00019
    00020 //#############################################################################
    00021
    00027 class OsiTestSolverInterface :
    00028    virtual public OsiSolverInterface, public VOL_user_hooks {
    00029    friend void OsiTestSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00030
    00031 private:
    00032   class OsiVolMatrixOneMinusOne_ {
    00033     int majorDim_;
    00034     int minorDim_;
    00035
    00036     int plusSize_;
    00037     int * plusInd_;
    00038     int * plusStart_;
    00039     int * plusLength_;
    00040
    00041     int minusSize_;
    00042     int * minusInd_;
    00043     int * minusStart_;
    00044     int * minusLength_;
    00045
    00046   public:
    00047     OsiVolMatrixOneMinusOne_(const CoinPackedMatrix& m);
    00048     ~OsiVolMatrixOneMinusOne_();
    00049     void timesMajor(const double* x, double* y) const;
    00050   };
    00051
    00052 public:
    00053   //---------------------------------------------------------------------------
    00056
    00057     virtual void initialSolve();
    00058
    00060     virtual void resolve();
    00061
    00063     virtual void branchAndBound() {
    00064       throw CoinError("Sorry, the Volume Algorithm doesn't implement B&B",
    00065                      "branchAndBound", "OsiTestSolverInterface");
    00066     }
    00068
    00069   //---------------------------------------------------------------------------
    00085     // Set an integer parameter
    00086     bool setIntParam(OsiIntParam key, int value);
    00087     // Set an double parameter
    00088     bool setDblParam(OsiDblParam key, double value);
    00089     // Set a string parameter
    00090     bool setStrParam(OsiStrParam key, const std::string & value);
    00091     // Get an integer parameter
    00092     bool getIntParam(OsiIntParam key, int& value) const;
    00093     // Get an double parameter
    00094     bool getDblParam(OsiDblParam key, double& value) const;
    00095     // Get a string parameter
    00096     bool getStrParam(OsiStrParam key, std::string& value) const;
    00098
    00099   //---------------------------------------------------------------------------
    00101
    00102
    00103     virtual bool isAbandoned() const;
    00105     virtual bool isProvenOptimal() const;
    00107     virtual bool isProvenPrimalInfeasible() const;
    00109     virtual bool isProvenDualInfeasible() const;
    00111     virtual bool isPrimalObjectiveLimitReached() const;
    00113     virtual bool isDualObjectiveLimitReached() const;
    00115     virtual bool isIterationLimitReached() const;
    00117
    00118   //---------------------------------------------------------------------------
    00127     virtual CoinWarmStart *getEmptyWarmStart () const ;
    00128
    00130     virtual CoinWarmStart* getWarmStart() const;
    00133     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00135
    00136   //---------------------------------------------------------------------------
    00143
    00144     virtual void markHotStart();
    00146     virtual void solveFromHotStart();
    00148     virtual void unmarkHotStart();
    00150
    00151   //---------------------------------------------------------------------------
    00166
    00167       virtual int getNumCols() const {
    00168         return rowMatrixCurrent_?
    00169         rowMatrix_.getNumCols() : colMatrix_.getNumCols(); }
    00170
    00172       virtual int getNumRows() const {
    00173         return rowMatrixCurrent_?
    00174         rowMatrix_.getNumRows() : colMatrix_.getNumRows(); }
    00175
    00177       virtual int getNumElements() const {
    00178         return rowMatrixCurrent_?
    00179         rowMatrix_.getNumElements() : colMatrix_.getNumElements(); }
    00180
    00182       virtual const double * getColLower() const { return collower_; }
    00183
    00185       virtual const double * getColUpper() const { return colupper_; }
    00186
    00196       virtual const char * getRowSense() const { return rowsense_; }
    00197
    00206       virtual const double * getRightHandSide() const { return rhs_; }
    00207
    00216       virtual const double * getRowRange() const { return rowrange_; }
    00217
    00219       virtual const double * getRowLower() const { return rowlower_; }
    00220
    00222       virtual const double * getRowUpper() const { return rowupper_; }
    00223
    00225       virtual const double * getObjCoefficients() const { return objcoeffs_; }
    00226
    00228       virtual double getObjSense() const { return objsense_; }
    00229
    00231       virtual bool isContinuous(int colNumber) const;
    00232
    00233 #if 0
    00235       virtual bool isBinary(int colNumber) const;
    00236
    00241       virtual bool isInteger(int colNumber) const;
    00242
    00244       virtual bool isIntegerNonBinary(int colNumber) const;
    00245
    00247       virtual bool isFreeBinary(int colNumber) const;
    00248 #endif
    00249
    00251       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00252
    00254       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00255
    00257       virtual double getInfinity() const { return OsiTestInfinity; }
    00259
    00262
    00263       virtual const double * getColSolution() const { return colsol_; }
    00264
    00266       virtual const double * getRowPrice() const { return rowprice_; }
    00267
    00269       virtual const double * getReducedCost() const { return rc_; }
    00270
    00273       virtual const double * getRowActivity() const { return lhs_; }
    00274
    00276       virtual double getObjValue() const {
    00277 #if 1
    00278         // This does not pass unitTest if getObjValue is called before solve
    00279         return lagrangeanCost_;
    00280 #else
    00281         return OsiSolverInterface::getObjValue();
    00282 #endif
    00283       }
    00284
    00287       virtual int getIterationCount() const { return volprob_.iter(); }
    00288
    00306       virtual std::vector<double*> getDualRays(int maxNumRays,
    00307                                                bool fullRay = false) const;
    00319       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00320
    00321 #if 0
    00322
    00324       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00325         const;
    00326 #endif
    00327
    00328
    00329
    00330   //---------------------------------------------------------------------------
    00331
    00334     //-------------------------------------------------------------------------
    00338       virtual void setObjCoeff( int elementIndex, double elementValue ) {
    00339         objcoeffs_[elementIndex] = elementValue;
    00340       }
    00341
    00342       using OsiSolverInterface::setColLower ;
    00345       virtual void setColLower( int elementIndex, double elementValue ) {
    00346         collower_[elementIndex] = elementValue;
    00347       }
    00348
    00349       using OsiSolverInterface::setColUpper ;
    00352       virtual void setColUpper( int elementIndex, double elementValue ) {
    00353         colupper_[elementIndex] = elementValue;
    00354       }
    00355
    00357       virtual void setColBounds( int elementIndex,
    00358                                  double lower, double upper ) {
    00359         collower_[elementIndex] = lower;
    00360         colupper_[elementIndex] = upper;
    00361       }
    00362
    00371       virtual void setColSetBounds(const int* indexFirst,
    00372                                    const int* indexLast,
    00373                                    const double* boundList);
    00374
    00377       virtual void setRowLower( int elementIndex, double elementValue ) {
    00378         rowlower_[elementIndex] = elementValue;
    00379         convertBoundToSense(elementValue, rowupper_[elementIndex],
    00380                             rowsense_[elementIndex], rhs_[elementIndex],
    00381                             rowrange_[elementIndex]);
    00382       }
    00383
    00386       virtual void setRowUpper( int elementIndex, double elementValue ) {
    00387         rowupper_[elementIndex] = elementValue;
    00388         convertBoundToSense(rowlower_[elementIndex], elementValue,
    00389                             rowsense_[elementIndex], rhs_[elementIndex],
    00390                             rowrange_[elementIndex]);
    00391       }
    00392
    00394       virtual void setRowBounds( int elementIndex,
    00395                                  double lower, double upper ) {
    00396         rowlower_[elementIndex] = lower;
    00397         rowupper_[elementIndex] = upper;
    00398         convertBoundToSense(lower, upper,
    00399                             rowsense_[elementIndex], rhs_[elementIndex],
    00400                             rowrange_[elementIndex]);
    00401       }
    00402
    00404       virtual void setRowType(int index, char sense, double rightHandSide,
    00405                               double range) {
    00406         rowsense_[index] = sense;
    00407         rhs_[index] = rightHandSide;
    00408         rowrange_[index] = range;
    00409         convertSenseToBound(sense, rightHandSide, range,
    00410                             rowlower_[index], rowupper_[index]);
    00411       }
    00412
    00421       virtual void setRowSetBounds(const int* indexFirst,
    00422                                    const int* indexLast,
    00423                                    const double* boundList);
    00424
    00435       virtual void setRowSetTypes(const int* indexFirst,
    00436                                   const int* indexLast,
    00437                                   const char* senseList,
    00438                                   const double* rhsList,
    00439                                   const double* rangeList);
    00441
    00442     //-------------------------------------------------------------------------
    00446       virtual void setContinuous(int index);
    00448       virtual void setInteger(int index);
    00451       virtual void setContinuous(const int* indices, int len);
    00454       virtual void setInteger(const int* indices, int len);
    00456
    00457     //-------------------------------------------------------------------------
    00459     virtual void setObjSense(double s ) { objsense_ = s < 0 ? -1.0 : 1.0; }
    00460
    00471     virtual void setColSolution(const double * colsol);
    00472
    00483     virtual void setRowPrice(const double * rowprice);
    00484
    00485     //-------------------------------------------------------------------------
    00490
    00491       using OsiSolverInterface::addCol ;
    00493       virtual void addCol(const CoinPackedVectorBase& vec,
    00494                              const double collb, const double colub,
    00495                              const double obj);
    00496
    00497       using OsiSolverInterface::addCols ;
    00499       virtual void addCols(const int numcols,
    00500                            const CoinPackedVectorBase * const * cols,
    00501                            const double* collb, const double* colub,
    00502                            const double* obj);
    00503 #if 0
    00504
    00505       virtual void addCols(const CoinPackedMatrix& matrix,
    00506                            const double* collb, const double* colub,
    00507                            const double* obj);
    00508 #endif
    00509
    00510       virtual void deleteCols(const int num, const int * colIndices);
    00511
    00512       using OsiSolverInterface::addRow ;
    00514       virtual void addRow(const CoinPackedVectorBase& vec,
    00515                           const double rowlb, const double rowub);
    00517       virtual void addRow(const CoinPackedVectorBase& vec,
    00518                           const char rowsen, const double rowrhs,
    00519                           const double rowrng);
    00520
    00521       using OsiSolverInterface::addRows ;
    00523       virtual void addRows(const int numrows,
    00524                            const CoinPackedVectorBase * const * rows,
    00525                            const double* rowlb, const double* rowub);
    00527       virtual void addRows(const int numrows,
    00528                            const CoinPackedVectorBase * const * rows,
    00529                            const char* rowsen, const double* rowrhs,
    00530                            const double* rowrng);
    00531 #if 0
    00532
    00533       virtual void addRows(const CoinPackedMatrix& matrix,
    00534                            const double* rowlb, const double* rowub);
    00536       virtual void addRows(const CoinPackedMatrix& matrix,
    00537                            const char* rowsen, const double* rowrhs,
    00538                            const double* rowrng);
    00539 #endif
    00540
    00541       virtual void deleteRows(const int num, const int * rowIndices);
    00542
    00543       //-----------------------------------------------------------------------
    00544 #if 0
    00545
    00566       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00567                                             double effectivenessLb = 0.0);
    00568 #endif
    00569
    00570
    00571
    00572   //---------------------------------------------------------------------------
    00573
    00574 protected:
    00576   void initFromRlbRub(const int rownum,
    00577                       const double* rowlb, const double* rowub);
    00578   void initFromRhsSenseRange(const int rownum, const char* rowsen,
    00579                              const double* rowrhs, const double* rowrng);
    00580   void initFromClbCubObj(const int colnum, const double* collb,
    00581                          const double* colub, const double* obj);
    00582 public:
    00583
    00597     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00598                              const double* collb, const double* colub,
    00599                              const double* obj,
    00600                              const double* rowlb, const double* rowub);
    00601
    00609     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00610                              double*& collb, double*& colub, double*& obj,
    00611                              double*& rowlb, double*& rowub);
    00612
    00625     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00626                            const double* collb, const double* colub,
    00627                            const double* obj,
    00628                            const char* rowsen, const double* rowrhs,
    00629                            const double* rowrng);
    00630
    00638     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00639                              double*& collb, double*& colub, double*& obj,
    00640                              char*& rowsen, double*& rowrhs,
    00641                              double*& rowrng);
    00642
    00645     virtual void loadProblem(const int numcols, const int numrows,
    00646                              const int* start, const int* index,
    00647                              const double* value,
    00648                              const double* collb, const double* colub,
    00649                              const double* obj,
    00650                              const double* rowlb, const double* rowub);
    00651
    00654     virtual void loadProblem(const int numcols, const int numrows,
    00655                              const int* start, const int* index,
    00656                              const double* value,
    00657                              const double* collb, const double* colub,
    00658                              const double* obj,
    00659                              const char* rowsen, const double* rowrhs,
    00660                              const double* rowrng);
    00661
    00662     using OsiSolverInterface::readMps ;
    00664     virtual int readMps(const char *filename,
    00665                          const char *extension = "mps");
    00666
    00671     virtual void writeMps(const char *filename,
    00672                           const char *extension = "mps",
    00673                           double objSense=0.0) const;
    00675
    00676   //---------------------------------------------------------------------------
    00677
    00680
    00681     VOL_problem* volprob() { return &volprob_; }
    00683
    00684   //---------------------------------------------------------------------------
    00685
    00688
    00689     OsiTestSolverInterface ();
    00690
    00692     virtual OsiSolverInterface * clone(bool copyData = true) const;
    00693
    00695     OsiTestSolverInterface (const OsiTestSolverInterface &);
    00696
    00698     OsiTestSolverInterface & operator=(const OsiTestSolverInterface& rhs);
    00699
    00701     virtual ~OsiTestSolverInterface ();
    00703
    00704   //---------------------------------------------------------------------------
    00705
    00706 protected:
    00708
    00709
    00710     virtual void applyRowCut(const OsiRowCut& rc);
    00711
    00713     virtual void applyColCut(const OsiColCut& cc);
    00715
    00716   //---------------------------------------------------------------------------
    00717
    00718 private:
    00721
    00722     virtual int compute_rc(const VOL_dvector& u, VOL_dvector& rc);
    00724     virtual int solve_subproblem(const VOL_dvector& dual,
    00725                                  const VOL_dvector& rc,
    00726                                  double& lcost, VOL_dvector& x, VOL_dvector& v,
    00727                                  double& pcost);
    00730   virtual int heuristics(const VOL_problem& /*p*/,
    00731                          const VOL_dvector& /*x*/, double& heur_val) {
    00732       heur_val = COIN_DBL_MAX;
    00733       return 0;
    00734     }
    00736
    00737   //---------------------------------------------------------------------------
    00738
    00739 private:
    00743     void updateRowMatrix_() const;
    00745     void updateColMatrix_() const;
    00746
    00749     void checkData_() const;
    00752     void compute_rc_(const double* u, double* rc) const;
    00754     void gutsOfDestructor_();
    00755
    00758     void rowRimAllocator_();
    00761     void colRimAllocator_();
    00762
    00764     void rowRimResize_(const int newSize);
    00766     void colRimResize_(const int newSize);
    00767
    00769     void convertBoundsToSenses_();
    00771     void convertSensesToBounds_();
    00772
    00774     bool test_zero_one_minusone_(const CoinPackedMatrix& m) const;
    00776
    00777   //---------------------------------------------------------------------------
    00778
    00779 private:
    00780
    00781   //---------------------------------------------------------------------------
    00785
    00786     mutable bool rowMatrixCurrent_;
    00788     mutable CoinPackedMatrix rowMatrix_;
    00790     mutable bool colMatrixCurrent_;
    00792     mutable CoinPackedMatrix colMatrix_;
    00794
    00795   //---------------------------------------------------------------------------
    00798
    00799     bool isZeroOneMinusOne_;
    00801     OsiVolMatrixOneMinusOne_* rowMatrixOneMinusOne_;
    00803     OsiVolMatrixOneMinusOne_* colMatrixOneMinusOne_;
    00805
    00806   //---------------------------------------------------------------------------
    00809
    00810     double  *colupper_;
    00812     double  *collower_;
    00814     bool    *continuous_;
    00816     double  *rowupper_;
    00818     double  *rowlower_;
    00820     char    *rowsense_;
    00822     double  *rhs_;
    00825     double  *rowrange_;
    00827     double  *objcoeffs_;
    00829
    00830   //---------------------------------------------------------------------------
    00832   double  objsense_;
    00833
    00834   //---------------------------------------------------------------------------
    00837
    00838     double  *colsol_;
    00840     double  *rowprice_;
    00842     double  *rc_;
    00844     double  *lhs_;
    00846     double   lagrangeanCost_;
    00848
    00849   //---------------------------------------------------------------------------
    00852   double  *rowpriceHotStart_;
    00853
    00855   int maxNumrows_;
    00857   int maxNumcols_;
    00858
    00860   VOL_problem volprob_;
    00861 };
    00862
    00864 void
    00865 OsiTestSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00866
    00867 #endif