00001
00002
00003
00004 #ifndef OsiVolSolverInterface_H
00005 #define OsiVolSolverInterface_H
00006
00007 #include <string>
00008
00009 #include "VolVolume.hpp"
00010
00011 #include "CoinPackedMatrix.hpp"
00012
00013 #include "OsiSolverInterface.hpp"
00014
00015 static const double OsiVolInfinity = 1.0e31;
00016
00017
00018
00024 class OsiVolSolverInterface :
00025 virtual public OsiSolverInterface, public VOL_user_hooks {
00026 friend int OsiVolSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00027
00028 private:
00029 class OsiVolMatrixOneMinusOne_ {
00030 int majorDim_;
00031 int minorDim_;
00032
00033 int plusSize_;
00034 int * plusInd_;
00035 int * plusStart_;
00036 int * plusLength_;
00037
00038 int minusSize_;
00039 int * minusInd_;
00040 int * minusStart_;
00041 int * minusLength_;
00042
00043 public:
00044 OsiVolMatrixOneMinusOne_(const CoinPackedMatrix& m);
00045 ~OsiVolMatrixOneMinusOne_();
00046 void timesMajor(const double* x, double* y) const;
00047 };
00048
00049 public:
00050
00053
00054 virtual void initialSolve();
00055
00057 virtual void resolve();
00058
00060 virtual void branchAndBound() {
00061 throw CoinError("Sorry, the Volume Algorithm doesn't implement B&B",
00062 "branchAndBound", "OsiVolSolverInterface");
00063 }
00065
00066
00082
00083 bool setIntParam(OsiIntParam key, int value);
00084
00085 bool setDblParam(OsiDblParam key, double value);
00086
00087 bool setStrParam(OsiStrParam key, const std::string & value);
00088
00089 bool getIntParam(OsiIntParam key, int& value) const;
00090
00091 bool getDblParam(OsiDblParam key, double& value) const;
00092
00093 bool getStrParam(OsiStrParam key, std::string& value) const;
00095
00096
00098
00099
00100 virtual bool isAbandoned() const;
00102 virtual bool isProvenOptimal() const;
00104 virtual bool isProvenPrimalInfeasible() const;
00106 virtual bool isProvenDualInfeasible() const;
00108 virtual bool isPrimalObjectiveLimitReached() const;
00110 virtual bool isDualObjectiveLimitReached() const;
00112 virtual bool isIterationLimitReached() const;
00114
00115
00124 virtual CoinWarmStart *getEmptyWarmStart () const ;
00125
00127 virtual CoinWarmStart* getWarmStart() const;
00130 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00132
00133
00140
00141 virtual void markHotStart();
00143 virtual void solveFromHotStart();
00145 virtual void unmarkHotStart();
00147
00148
00163
00164 virtual int getNumCols() const {
00165 return rowMatrixCurrent_?
00166 rowMatrix_.getNumCols() : colMatrix_.getNumCols(); }
00167
00169 virtual int getNumRows() const {
00170 return rowMatrixCurrent_?
00171 rowMatrix_.getNumRows() : colMatrix_.getNumRows(); }
00172
00174 virtual int getNumElements() const {
00175 return rowMatrixCurrent_?
00176 rowMatrix_.getNumElements() : colMatrix_.getNumElements(); }
00177
00179 virtual const double * getColLower() const { return collower_; }
00180
00182 virtual const double * getColUpper() const { return colupper_; }
00183
00193 virtual const char * getRowSense() const { return rowsense_; }
00194
00203 virtual const double * getRightHandSide() const { return rhs_; }
00204
00213 virtual const double * getRowRange() const { return rowrange_; }
00214
00216 virtual const double * getRowLower() const { return rowlower_; }
00217
00219 virtual const double * getRowUpper() const { return rowupper_; }
00220
00222 virtual const double * getObjCoefficients() const { return objcoeffs_; }
00223
00225 virtual double getObjSense() const { return objsense_; }
00226
00228 virtual bool isContinuous(int colNumber) const;
00229
00230 #if 0
00232 virtual bool isBinary(int colNumber) const;
00233
00238 virtual bool isInteger(int colNumber) const;
00239
00241 virtual bool isIntegerNonBinary(int colNumber) const;
00242
00244 virtual bool isFreeBinary(int colNumber) const;
00245 #endif
00246
00248 virtual const CoinPackedMatrix * getMatrixByRow() const;
00249
00251 virtual const CoinPackedMatrix * getMatrixByCol() const;
00252
00254 virtual double getInfinity() const { return OsiVolInfinity; }
00256
00259
00260 virtual const double * getColSolution() const { return colsol_; }
00261
00263 virtual const double * getRowPrice() const { return rowprice_; }
00264
00266 virtual const double * getReducedCost() const { return rc_; }
00267
00270 virtual const double * getRowActivity() const { return lhs_; }
00271
00273 virtual double getObjValue() const {
00274 #if 1
00275
00276 return lagrangeanCost_;
00277 #else
00278 return OsiSolverInterface::getObjValue();
00279 #endif
00280 }
00281
00284 virtual int getIterationCount() const { return volprob_.iter(); }
00285
00303 virtual std::vector<double*> getDualRays(int maxNumRays,
00304 bool fullRay = false) const;
00316 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00317
00318 #if 0
00319
00321 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00322 const;
00323 #endif
00324
00325
00326
00327
00328
00331
00335 virtual void setObjCoeff( int elementIndex, double elementValue ) {
00336 objcoeffs_[elementIndex] = elementValue;
00337 }
00338
00339 using OsiSolverInterface::setColLower ;
00342 virtual void setColLower( int elementIndex, double elementValue ) {
00343 collower_[elementIndex] = elementValue;
00344 }
00345
00346 using OsiSolverInterface::setColUpper ;
00349 virtual void setColUpper( int elementIndex, double elementValue ) {
00350 colupper_[elementIndex] = elementValue;
00351 }
00352
00354 virtual void setColBounds( int elementIndex,
00355 double lower, double upper ) {
00356 collower_[elementIndex] = lower;
00357 colupper_[elementIndex] = upper;
00358 }
00359
00368 virtual void setColSetBounds(const int* indexFirst,
00369 const int* indexLast,
00370 const double* boundList);
00371
00374 virtual void setRowLower( int elementIndex, double elementValue ) {
00375 rowlower_[elementIndex] = elementValue;
00376 convertBoundToSense(elementValue, rowupper_[elementIndex],
00377 rowsense_[elementIndex], rhs_[elementIndex],
00378 rowrange_[elementIndex]);
00379 }
00380
00383 virtual void setRowUpper( int elementIndex, double elementValue ) {
00384 rowupper_[elementIndex] = elementValue;
00385 convertBoundToSense(rowlower_[elementIndex], elementValue,
00386 rowsense_[elementIndex], rhs_[elementIndex],
00387 rowrange_[elementIndex]);
00388 }
00389
00391 virtual void setRowBounds( int elementIndex,
00392 double lower, double upper ) {
00393 rowlower_[elementIndex] = lower;
00394 rowupper_[elementIndex] = upper;
00395 convertBoundToSense(lower, upper,
00396 rowsense_[elementIndex], rhs_[elementIndex],
00397 rowrange_[elementIndex]);
00398 }
00399
00401 virtual void setRowType(int index, char sense, double rightHandSide,
00402 double range) {
00403 rowsense_[index] = sense;
00404 rhs_[index] = rightHandSide;
00405 rowrange_[index] = range;
00406 convertSenseToBound(sense, rightHandSide, range,
00407 rowlower_[index], rowupper_[index]);
00408 }
00409
00418 virtual void setRowSetBounds(const int* indexFirst,
00419 const int* indexLast,
00420 const double* boundList);
00421
00432 virtual void setRowSetTypes(const int* indexFirst,
00433 const int* indexLast,
00434 const char* senseList,
00435 const double* rhsList,
00436 const double* rangeList);
00438
00439
00443 virtual void setContinuous(int index);
00445 virtual void setInteger(int index);
00448 virtual void setContinuous(const int* indices, int len);
00451 virtual void setInteger(const int* indices, int len);
00453
00454
00456 virtual void setObjSense(double s ) { objsense_ = s < 0 ? -1.0 : 1.0; }
00457
00468 virtual void setColSolution(const double * colsol);
00469
00480 virtual void setRowPrice(const double * rowprice);
00481
00482
00487
00488 using OsiSolverInterface::addCol ;
00490 virtual void addCol(const CoinPackedVectorBase& vec,
00491 const double collb, const double colub,
00492 const double obj);
00493
00494 using OsiSolverInterface::addCols ;
00496 virtual void addCols(const int numcols,
00497 const CoinPackedVectorBase * const * cols,
00498 const double* collb, const double* colub,
00499 const double* obj);
00500 #if 0
00501
00502 virtual void addCols(const CoinPackedMatrix& matrix,
00503 const double* collb, const double* colub,
00504 const double* obj);
00505 #endif
00506
00507 virtual void deleteCols(const int num, const int * colIndices);
00508
00509 using OsiSolverInterface::addRow ;
00511 virtual void addRow(const CoinPackedVectorBase& vec,
00512 const double rowlb, const double rowub);
00514 virtual void addRow(const CoinPackedVectorBase& vec,
00515 const char rowsen, const double rowrhs,
00516 const double rowrng);
00517
00518 using OsiSolverInterface::addRows ;
00520 virtual void addRows(const int numrows,
00521 const CoinPackedVectorBase * const * rows,
00522 const double* rowlb, const double* rowub);
00524 virtual void addRows(const int numrows,
00525 const CoinPackedVectorBase * const * rows,
00526 const char* rowsen, const double* rowrhs,
00527 const double* rowrng);
00528 #if 0
00529
00530 virtual void addRows(const CoinPackedMatrix& matrix,
00531 const double* rowlb, const double* rowub);
00533 virtual void addRows(const CoinPackedMatrix& matrix,
00534 const char* rowsen, const double* rowrhs,
00535 const double* rowrng);
00536 #endif
00537
00538 virtual void deleteRows(const int num, const int * rowIndices);
00539
00540
00541 #if 0
00542
00563 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00564 double effectivenessLb = 0.0);
00565 #endif
00566
00567
00568
00569
00570
00571 protected:
00573 void initFromRlbRub(const int rownum,
00574 const double* rowlb, const double* rowub);
00575 void initFromRhsSenseRange(const int rownum, const char* rowsen,
00576 const double* rowrhs, const double* rowrng);
00577 void initFromClbCubObj(const int colnum, const double* collb,
00578 const double* colub, const double* obj);
00579 public:
00580
00594 virtual void loadProblem(const CoinPackedMatrix& matrix,
00595 const double* collb, const double* colub,
00596 const double* obj,
00597 const double* rowlb, const double* rowub);
00598
00606 virtual void assignProblem(CoinPackedMatrix*& matrix,
00607 double*& collb, double*& colub, double*& obj,
00608 double*& rowlb, double*& rowub);
00609
00622 virtual void loadProblem(const CoinPackedMatrix& matrix,
00623 const double* collb, const double* colub,
00624 const double* obj,
00625 const char* rowsen, const double* rowrhs,
00626 const double* rowrng);
00627
00635 virtual void assignProblem(CoinPackedMatrix*& matrix,
00636 double*& collb, double*& colub, double*& obj,
00637 char*& rowsen, double*& rowrhs,
00638 double*& rowrng);
00639
00642 virtual void loadProblem(const int numcols, const int numrows,
00643 const int* start, const int* index,
00644 const double* value,
00645 const double* collb, const double* colub,
00646 const double* obj,
00647 const double* rowlb, const double* rowub);
00648
00651 virtual void loadProblem(const int numcols, const int numrows,
00652 const int* start, const int* index,
00653 const double* value,
00654 const double* collb, const double* colub,
00655 const double* obj,
00656 const char* rowsen, const double* rowrhs,
00657 const double* rowrng);
00658
00659 using OsiSolverInterface::readMps ;
00661 virtual int readMps(const char *filename,
00662 const char *extension = "mps");
00663
00668 virtual void writeMps(const char *filename,
00669 const char *extension = "mps",
00670 double objSense=0.0) const;
00672
00673
00674
00677
00678 VOL_problem* volprob() { return &volprob_; }
00680
00681
00682
00685
00686 OsiVolSolverInterface ();
00687
00689 virtual OsiSolverInterface * clone(bool copyData = true) const;
00690
00692 OsiVolSolverInterface (const OsiVolSolverInterface &);
00693
00695 OsiVolSolverInterface & operator=(const OsiVolSolverInterface& rhs);
00696
00698 virtual ~OsiVolSolverInterface ();
00700
00701
00702
00703 protected:
00705
00706
00707 virtual void applyRowCut(const OsiRowCut& rc);
00708
00710 virtual void applyColCut(const OsiColCut& cc);
00712
00713
00714
00715 private:
00718
00719 virtual int compute_rc(const VOL_dvector& u, VOL_dvector& rc);
00721 virtual int solve_subproblem(const VOL_dvector& dual,
00722 const VOL_dvector& rc,
00723 double& lcost, VOL_dvector& x, VOL_dvector& v,
00724 double& pcost);
00727 virtual int heuristics(const VOL_problem& ,
00728 const VOL_dvector& , double& heur_val) {
00729 heur_val = DBL_MAX;
00730 return 0;
00731 }
00733
00734
00735
00736 private:
00740 void updateRowMatrix_() const;
00742 void updateColMatrix_() const;
00743
00746 void checkData_() const;
00749 void compute_rc_(const double* u, double* rc) const;
00751 void gutsOfDestructor_();
00752
00755 void rowRimAllocator_();
00758 void colRimAllocator_();
00759
00761 void rowRimResize_(const int newSize);
00763 void colRimResize_(const int newSize);
00764
00766 void convertBoundsToSenses_();
00768 void convertSensesToBounds_();
00769
00771 bool test_zero_one_minusone_(const CoinPackedMatrix& m) const;
00773
00774
00775
00776 private:
00777
00778
00782
00783 mutable bool rowMatrixCurrent_;
00785 mutable CoinPackedMatrix rowMatrix_;
00787 mutable bool colMatrixCurrent_;
00789 mutable CoinPackedMatrix colMatrix_;
00791
00792
00795
00796 bool isZeroOneMinusOne_;
00798 OsiVolMatrixOneMinusOne_* rowMatrixOneMinusOne_;
00800 OsiVolMatrixOneMinusOne_* colMatrixOneMinusOne_;
00802
00803
00806
00807 double *colupper_;
00809 double *collower_;
00811 bool *continuous_;
00813 double *rowupper_;
00815 double *rowlower_;
00817 char *rowsense_;
00819 double *rhs_;
00822 double *rowrange_;
00824 double *objcoeffs_;
00826
00827
00829 double objsense_;
00830
00831
00834
00835 double *colsol_;
00837 double *rowprice_;
00839 double *rc_;
00841 double *lhs_;
00843 double lagrangeanCost_;
00845
00846
00849 double *rowpriceHotStart_;
00850
00852 int maxNumrows_;
00854 int maxNumcols_;
00855
00857 VOL_problem volprob_;
00858 };
00859
00860
00868 int
00869 OsiVolSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00870
00871 #endif