00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 using namespace std;
00035
00036
00037
00059 class OsiSymSolverInterface : virtual public OsiSolverInterface {
00060 friend void OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00061
00062 public:
00064
00065
00066 virtual void initialSolve();
00067
00069 virtual void resolve();
00070
00072 virtual void branchAndBound();
00073
00075 virtual void multiCriteriaBranchAndBound();
00076
00078 virtual double getLbForNewRhs(int cnt, int *index,
00079 double * value);
00081 virtual double getUbForNewRhs(int cnt, int *index,
00082 double * value);
00083 #if 0
00085 virtual double getLbForNewObj(int cnt, int *index,
00086 double * value);
00088 #endif
00089 virtual double getUbForNewObj(int cnt, int *index,
00090 double * value);
00091
00093
00094
00111
00112 virtual bool setIntParam(OsiIntParam key, int value);
00113
00114
00115 virtual bool setSymParam(OsiSymIntParam key, int value);
00116
00117
00118 virtual bool setSymParam(const std::string key, int value);
00119
00120
00121
00122 virtual bool setDblParam(OsiDblParam key, double value);
00123
00124
00125 virtual bool setSymParam(OsiSymDblParam key, double value);
00126
00127
00128 virtual bool setSymParam(const std::string key, double value);
00129
00130
00131
00132
00133 virtual bool setStrParam(OsiStrParam key, const std::string & value);
00134
00135
00136 virtual bool setSymParam(OsiSymStrParam key, const std::string & value);
00137
00138
00139 virtual bool setSymParam(const std::string key, const std::string value);
00140
00141
00142
00143
00144 virtual bool getIntParam(OsiIntParam key, int& value) const;
00145
00146
00147 virtual bool getSymParam(OsiSymIntParam key, int& value) const;
00148
00149
00150 virtual bool getSymParam(const std::string key, int& value) const;
00151
00152
00153
00154 virtual bool getDblParam(OsiDblParam key, double& value) const;
00155
00156
00157 virtual bool getSymParam(OsiSymDblParam key, double& value) const;
00158
00159
00160 virtual bool getSymParam(const std::string key, double& value) const;
00161
00162
00163
00164
00165 virtual bool getStrParam(OsiStrParam key, std::string& value) const;
00166
00167
00168 virtual bool getSymParam(OsiSymStrParam key, std::string& value) const;
00169
00170
00171 virtual bool getSymParam(const std::string key, std::string& value) const;
00172
00174
00175
00177
00178
00179 virtual bool isAbandoned() const;
00180
00182 virtual bool isProvenOptimal() const;
00183
00185 virtual bool isProvenPrimalInfeasible() const;
00186
00188 virtual bool isProvenDualInfeasible() const {
00189 throw CoinError("Error: Function not implemented",
00190 "isProvenDualInfeasible", "OsiSymSolverInterface");
00191 };
00193 virtual bool isPrimalObjectiveLimitReached() const;
00194
00196 virtual bool isDualObjectiveLimitReached() const{
00197 throw CoinError("Error: Function not implemented",
00198 "isDualObjectiveLimitReached", "OsiSymSolverInterface");
00199 };
00201 virtual bool isIterationLimitReached() const;
00202
00204 virtual bool isTimeLimitReached() const;
00205
00207 virtual bool isTargetGapReached() const;
00208
00210
00211
00221 virtual CoinWarmStart *getEmptyWarmStart () const{
00222 throw CoinError("Error: Function not implemented",
00223 "getEmptyWarmStart", "OsiSymSolverInterface");
00224 };
00225
00232
00233
00234
00235
00236 virtual CoinWarmStart* getWarmStart() const;
00237
00242 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00244
00245
00256
00257 sym_environment *getSymphonyEnvironment() const {return env_;}
00258
00260 virtual int getNumCols() const;
00261
00263 virtual int getNumRows() const;
00264
00266 virtual int getNumElements() const;
00267
00269 virtual const double * getColLower() const;
00270
00272 virtual const double * getColUpper() const;
00273
00283 virtual const char * getRowSense() const;
00284
00297 virtual const double * getRightHandSide() const;
00298
00307 virtual const double * getRowRange() const;
00308
00310 virtual const double * getRowLower() const;
00311
00313 virtual const double * getRowUpper() const;
00314
00316 virtual const double * getObjCoefficients() const;
00317
00321 virtual const double * getObj2Coefficients() const;
00322
00324 virtual double getObjSense() const;
00325
00327 virtual bool isContinuous(int colIndex) const;
00328
00330 virtual bool isBinary(int colIndex) const;
00331
00336 virtual bool isInteger(int colIndex) const;
00337
00339 virtual bool isIntegerNonBinary(int colIndex) const;
00340
00342 virtual bool isFreeBinary(int colIndex) const;
00343
00345 virtual const CoinPackedMatrix * getMatrixByRow() const;
00346
00348 virtual const CoinPackedMatrix * getMatrixByCol() const;
00349
00351 virtual double getInfinity() const;
00352
00354
00357
00358 virtual const double * getColSolution() const;
00359
00361 virtual const double * getRowPrice() const{
00362
00363
00364 return (0);
00365 };
00366
00368 virtual const double * getReducedCost() const{
00369
00370
00371 return (0);
00372 };
00373
00376 virtual const double * getRowActivity() const;
00377
00379 virtual double getObjValue() const;
00380
00382 virtual double getPrimalBound() const;
00383
00386 virtual int getIterationCount() const;
00387
00401 virtual std::vector<double*> getDualRays(int maxNumRays) const{
00402 throw CoinError("Error: Function not implemented",
00403 "getDualRays", "OsiSymSolverInterface");
00404 };
00416 virtual std::vector<double*> getPrimalRays(int maxNumRays) const{
00417 throw CoinError("Error: Function not implemented",
00418 "getPrimalRays", "OsiSymSolverInterface");
00419 };
00420
00422
00423
00436 virtual void setObjCoeff( int elementIndex, double elementValue );
00437
00439 virtual void setObj2Coeff( int elementIndex, double elementValue );
00440
00443 virtual void setColLower( int elementIndex, double elementValue );
00444
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
00501 virtual void setContinuous(int index);
00502
00504 virtual void setInteger(int index);
00505
00506
00507 virtual void setColName(char **colname);
00508
00510
00511
00512
00520 virtual void addCol(const CoinPackedVectorBase& vec,
00521 const double collb, const double colub,
00522 const double obj);
00523
00525 virtual void deleteCols(const int num, const int * colIndices);
00526
00528 virtual void addRow(const CoinPackedVectorBase& vec,
00529 const double rowlb, const double rowub);
00531 virtual void addRow(const CoinPackedVectorBase& vec,
00532 const char rowsen, const double rowrhs,
00533 const double rowrng);
00534
00536 virtual void deleteRows(const int num, const int * rowIndices);
00537
00539
00540
00541
00544
00545 virtual void loadProblem();
00546
00558 virtual void loadProblem(const CoinPackedMatrix& matrix,
00559 const double* collb, const double* colub,
00560 const double* obj,
00561 const double* rowlb, const double* rowub);
00562
00572 virtual void assignProblem(CoinPackedMatrix*& matrix,
00573 double*& collb, double*& colub, double*& obj,
00574 double*& rowlb, double*& rowub);
00575
00588 virtual void loadProblem(const CoinPackedMatrix& matrix,
00589 const double* collb, const double* colub,
00590 const double* obj,
00591 const char* rowsen, const double* rowrhs,
00592 const double* rowrng);
00593
00603 virtual void assignProblem(CoinPackedMatrix*& matrix,
00604 double*& collb, double*& colub, double*& obj,
00605 char*& rowsen, double*& rowrhs,
00606 double*& rowrng);
00607
00610 virtual void loadProblem(const int numcols, const int numrows,
00611 const CoinBigIndex * start, const int* index,
00612 const double* value,
00613 const double* collb, const double* colub,
00614 const double* obj,
00615 const double* rowlb, const double* rowub);
00616
00619 virtual void loadProblem(const int numcols, const int numrows,
00620 const CoinBigIndex * start, const int* index,
00621 const double* value,
00622 const double* collb, const double* colub,
00623 const double* obj,
00624 const char* rowsen, const double* rowrhs,
00625 const double* rowrng);
00626
00633 virtual void writeMps(const char *filename,
00634 const char *extension = "mps",
00635 double objSense=0.0) const;
00636
00637 void parseCommandLine(int argc, char **argv);
00638
00639 virtual int readMps(const char * infile, const char *extension = "mps");
00640
00641 virtual int readGMPL(const char * modelFile, const char * dataFile=NULL);
00642
00643 void findInitialBounds();
00644
00645 int createPermanentCutPools();
00646
00648
00649
00650
00651 enum keepCachedFlag {
00653 KEEPCACHED_NONE = 0,
00655 KEEPCACHED_COLUMN = 1,
00657 KEEPCACHED_ROW = 2,
00659 KEEPCACHED_MATRIX = 4,
00661 KEEPCACHED_RESULTS = 8,
00663 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00665 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00667 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
00669 FREECACHED_ROW = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
00671 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
00673 FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
00674 };
00675
00677
00678
00679 OsiSymSolverInterface();
00680
00686 virtual OsiSolverInterface * clone(bool copyData = true) const;
00687
00689 OsiSymSolverInterface(const OsiSymSolverInterface &);
00690
00692 OsiSymSolverInterface & operator=(const OsiSymSolverInterface& rhs);
00693
00695 virtual ~OsiSymSolverInterface ();
00696
00703 virtual void reset();
00705
00706
00707
00708 protected:
00710
00711
00712 virtual void applyRowCut( const OsiRowCut & rc );
00713
00715 virtual void applyColCut( const OsiColCut & cc );
00716
00724 void setInitialData();
00726
00727 private:
00728
00730 void gutsOfConstructor();
00731
00733 void gutsOfDestructor();
00734
00736 void freeCachedColRim();
00737
00739 void freeCachedRowRim();
00740
00742 void freeCachedResults();
00743
00745 void freeCachedMatrix();
00746
00748 void freeCachedData( int keepCached = KEEPCACHED_NONE );
00749
00751 void freeAllMemory();
00752
00754 void printBounds();
00755
00758
00759 sym_environment *env_;
00761
00763 mutable double *obj_;
00764
00766 mutable double *obj2_;
00767
00769 mutable double *collower_;
00770
00772 mutable double *colupper_;
00773
00775 mutable char *rowsense_;
00776
00778 mutable double *rhs_;
00779
00783 mutable double *rowrange_;
00784
00786 mutable double *rowlower_;
00787
00789 mutable double *rowupper_;
00790
00792 mutable double *colsol_;
00793
00795 mutable double *rowact_;
00796
00798 mutable CoinPackedMatrix *matrixByRow_;
00799
00801 mutable CoinPackedMatrix *matrixByCol_;
00802
00803 };
00804
00805
00811 void OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00812
00813 #endif