00001 #ifdef COIN_HAS_DYLP
00002 #ifndef OsiDylpSolverInterface_H
00003 #define OsiDylpSolverInterface_H
00004
00018
00019
00020
00021
00022
00023 #include <CoinPackedMatrix.hpp>
00024 #include <OsiSolverInterface.hpp>
00025 #include <CoinWarmStart.hpp>
00026 #include <CoinMessageHandler.hpp>
00027 #include <CoinMpsIO.hpp>
00028 #include <CoinPresolveMatrix.hpp>
00029
00030 #define DYLP_INTERNAL
00031 extern "C" {
00032 #include "dylp.h"
00033 }
00034
00037 typedef enum { startInvalid = 0,
00038 startCold = 1, startWarm, startHot } ODSI_start_enum ;
00039
00040
00100 class OsiDylpSolverInterface: virtual public OsiSolverInterface
00101
00102 { friend void OsiDylpSolverInterfaceUnitTest(const std::string &mpsDir,
00103 const std::string &netLibDir) ;
00104
00105
00106
00107
00108
00109
00110
00111 public:
00112
00115
00118 OsiDylpSolverInterface() ;
00119
00122 OsiDylpSolverInterface(const OsiDylpSolverInterface &src) ;
00123
00126 OsiSolverInterface* clone(bool copyData = true) const ;
00127
00130 OsiDylpSolverInterface &operator=(const OsiDylpSolverInterface &rhs) ;
00131
00134 ~OsiDylpSolverInterface() ;
00135
00140 void reset() ;
00141
00143
00146
00149 int readMps(const char *filename, const char *extension = "mps") ;
00150
00155 int readMps(const char *filename, const char *extension,
00156 int &numberSets, CoinSet **&sets) ;
00157
00160 void writeMps(const char *basename,
00161 const char *extension = "mps",
00162 double objsense = 0.0) const ;
00163
00167 void loadProblem(const CoinPackedMatrix &matrix,
00168 const double *collb, const double *colub, const double *obj,
00169 const char *rowsen, const double *rowrhs,
00170 const double *rowrng) ;
00171
00175 void loadProblem(const CoinPackedMatrix &matrix,
00176 const double *collb, const double *colub, const double *obj,
00177 const double *rowlb, const double *rowub) ;
00178
00182 void loadProblem(const int colcnt, const int rowcnt,
00183 const int *start, const int *index, const double *value,
00184 const double *collb, const double *colub, const double *obj,
00185 const char *sense, const double *rhsin, const double *range) ;
00186
00190 void loadProblem(const int colcnt, const int rowcnt,
00191 const int *start, const int *index, const double *value,
00192 const double *collb, const double *colub, const double *obj,
00193 const double *row_lower, const double *row_upper) ;
00194
00198 void assignProblem(CoinPackedMatrix *&matrix,
00199 double *&collb, double *&colub, double *&obj,
00200 char *&rowsen, double *&rowrhs, double *&rowrng) ;
00201
00205 void assignProblem(CoinPackedMatrix *&matrix,
00206 double *&collb, double *&colub, double *&obj,
00207 double *&rowlb, double *&rowub) ;
00208
00210
00214
00217 int getNumCols() const ;
00218
00221 int getNumRows() const ;
00222
00225 int getNumElements() const ;
00226
00229 const double* getColLower() const ;
00230
00233 const double* getColUpper() const ;
00234
00237 bool isContinuous(int colIndex) const ;
00238
00241 bool isBinary(int colIndex) const ;
00242
00245 bool isIntegerNonBinary (int colIndex) const ;
00246
00249 bool isInteger (int colIndex) const ;
00250
00253 const char* getRowSense() const ;
00254
00257 const double* getRightHandSide() const ;
00258
00261 const double* getRowRange() const ;
00262
00265 const double* getRowLower() const ;
00266
00269 const double* getRowUpper() const ;
00270
00273 const double* getObjCoefficients() const ;
00274
00277 double getObjSense() const ;
00278
00281 const CoinPackedMatrix *getMatrixByRow() const ;
00282
00285 const CoinPackedMatrix *getMatrixByCol() const ;
00287
00290
00293 void setContinuous(int index) ;
00294
00297 void setContinuous(const int *indices, int len) ;
00298
00301 void setInteger(int index) ;
00302
00305 void setInteger(const int *indices, int len) ;
00306
00309 void setColLower(int index, double value) ;
00310 using OsiSolverInterface::setColLower ;
00311
00314 void setColUpper(int index, double value) ;
00315 using OsiSolverInterface::setColUpper ;
00316
00319 void setRowLower(int index, double value) ;
00320
00323 void setRowUpper(int index, double value) ;
00324
00327 void setRowType(int index, char rowsen, double rowrhs, double rowrng) ;
00328
00331 void setObjCoeff (int index, double value) ;
00332
00335 void setObjSense(double sense) ;
00336
00339 void setColSolution(const double *colsol) ;
00340
00343 void setRowPrice(const double*) ;
00344
00345
00346
00347 using OsiSolverInterface::addCol ;
00348
00351 void addCol(const CoinPackedVectorBase &vec,
00352 const double collb, const double colub, const double obj) ;
00353
00356 void deleteCols(const int num, const int *colIndices) ;
00357
00358
00359
00360 using OsiSolverInterface::addRow ;
00361
00364 void addRow(const CoinPackedVectorBase &row,
00365 const double rowlb, const double rowub) ;
00366
00369 void addRow(const CoinPackedVectorBase &row,
00370 const char rowsen, const double rowrhs, const double rowrng) ;
00371
00374 void deleteRows(const int num, const int *rowIndices) ;
00375
00378 void applyRowCut(const OsiRowCut &cut) ;
00379
00382 void applyColCut(const OsiColCut &cut) ;
00384
00387
00390 void initialSolve() ;
00391
00394 CoinWarmStart *getEmptyWarmStart () const ;
00395
00398 CoinWarmStart *getWarmStart() const ;
00399
00402 bool setWarmStart(const CoinWarmStart *warmStart) ;
00403
00406 void resolve() ;
00407
00410 void markHotStart() ;
00411
00414 void solveFromHotStart() ;
00415
00418 void unmarkHotStart() ;
00419
00421
00424
00427 bool isAbandoned() const ;
00428
00431 bool isProvenOptimal() const ;
00432
00435 bool isProvenPrimalInfeasible() const ;
00436
00440 bool isProvenDualInfeasible() const ;
00441
00444 bool isIterationLimitReached() const ;
00445
00448 int getIterationCount() const ;
00449
00452 bool isPrimalObjectiveLimitReached() const ;
00453
00456 bool isDualObjectiveLimitReached() const ;
00458
00459
00462
00465 double getInfinity() const ;
00466
00469 bool setIntParam(OsiIntParam key, int value) ;
00470
00473 bool setDblParam(OsiDblParam key, double value) ;
00474
00477 bool setStrParam(OsiStrParam key, const std::string& value) ;
00478
00481 bool setHintParam(OsiHintParam key, bool sense = true,
00482 OsiHintStrength strength = OsiHintTry, void *info = 0) ;
00483
00486 bool getIntParam(OsiIntParam key, int &value) const ;
00487
00490 bool getDblParam(OsiDblParam key, double &value) const ;
00491
00494 bool getStrParam(OsiStrParam key, std::string &value) const ;
00495
00496
00497
00498 using OsiSolverInterface::getHintParam ;
00499
00502 bool getHintParam(OsiHintParam key, bool &sense,
00503 OsiHintStrength &strength, void *&info) const ;
00504
00507 inline void newLanguage(CoinMessages::Language language)
00508 { setOsiDylpMessages(language) ; } ;
00509
00512 inline void setLanguage(CoinMessages::Language language)
00513 { setOsiDylpMessages(language) ; } ;
00514
00516
00519
00522 const double* getColSolution() const ;
00523
00526 const double* getRowPrice() const ;
00527
00530 const double* getReducedCost() const ;
00531
00534 const double* getRowActivity() const ;
00535
00538 double getObjValue() const ;
00539
00541
00544
00551 void activateRowCutDebugger (const char * modelName) ;
00552
00560 void activateRowCutDebugger (const double *solution) ;
00561
00562 # ifdef ODSI_PARANOIA
00563
00572 void indexCheck (int k, bool isCol, std::string rtnnme) ;
00573 # endif
00574
00576
00579
00582 void dylp_controlfile(const char* name, const bool silent,
00583 const bool mustexist = true) ;
00584
00587 void dylp_logfile(const char* name, bool echo = false) ;
00588
00591 void dylp_outfile(const char* name) ;
00592
00595 void dylp_printsoln(bool wantSoln, bool wantStats) ;
00596
00599 void setOsiDylpMessages(CoinMessages::Language local_language) ;
00600
00602
00605
00606
00609 void branchAndBound() ;
00610
00613 std::vector<double *> getDualRays(int) const ;
00614
00617 std::vector<double *> getPrimalRays(int) const ;
00619
00624
00625
00626
00627
00629
00630 lpopts_struct *initialSolveOptions,*resolveOptions ;
00631 lptols_struct* tolerances ;
00632
00634
00635 private:
00636
00637
00638
00639
00640
00641
00648
00649 consys_struct* consys ;
00650 lpprob_struct* lpprob ;
00651 lpstats_struct* statistics ;
00652
00654
00657
00658 static int reference_count ;
00659 static bool basis_ready ;
00660 static OsiDylpSolverInterface *dylp_owner ;
00661
00663
00664
00670
00677 ioid local_outchn ;
00678
00684 ioid local_logchn ;
00685
00690 bool initial_gtxecho ;
00691
00696 bool resolve_gtxecho ;
00697
00707 lpret_enum lp_retval ;
00708
00714 double obj_sense ;
00715
00718 double odsiInfinity ;
00719
00722 const std::string solvername ;
00723
00726 mutable void *info_[OsiLastHintParam] ;
00727
00730 bool mps_debug ;
00731
00734 CoinWarmStart *hotstart_fallback ;
00735
00745 CoinWarmStart *activeBasis ;
00746
00752 bool activeIsModified ;
00753
00759 bool solnIsFresh ;
00760
00770 int addedColCnt ;
00771
00781 int addedRowCnt ;
00782
00784
00785
00786
00793
00794 mutable double _objval ;
00795 mutable double* _col_obj ;
00796 mutable double* _col_x ;
00797 mutable double* _col_cbar ;
00798
00799 mutable double* _row_rhs ;
00800 mutable double* _row_lower ;
00801 mutable double* _row_upper ;
00802 mutable char* _row_sense ;
00803 mutable double* _row_range ;
00804 mutable double* _row_lhs ;
00805 mutable double* _row_price ;
00806
00807 mutable CoinPackedMatrix* _matrix_by_col ;
00808 mutable CoinPackedMatrix* _matrix_by_row ;
00809
00811
00818
00824 CoinPresolveMatrix *preObj_ ;
00825
00832 const CoinPresolveAction *postActions_ ;
00833
00841 CoinPostsolveMatrix *postObj_ ;
00842
00844 int passLimit_ ;
00845
00847 bool keepIntegers_ ;
00848
00850 consys_struct *savedConsys_ ;
00851
00853 mutable double* saved_col_obj ;
00854 mutable double* saved_row_rhs ;
00855 mutable double* saved_row_lower ;
00856 mutable double* saved_row_upper ;
00857 mutable char* saved_row_sense ;
00858 mutable double* saved_row_range ;
00859 mutable CoinPackedMatrix* saved_matrix_by_col ;
00860 mutable CoinPackedMatrix* saved_matrix_by_row ;
00861
00863
00873
00874 CoinPresolveMatrix *initialisePresolve(bool keepIntegers) ;
00875
00877 void doPresolve() ;
00878
00880 bool evalPresolve() ;
00881
00883 void saveOriginalSys() ;
00884
00886 void installPresolve() ;
00887
00889 CoinPostsolveMatrix *initialisePostsolve(CoinPresolveMatrix *&preObj) ;
00890
00892 void doPostsolve() ;
00893
00895 void installPostsolve() ;
00896
00898 void destruct_presolve() ;
00899
00901
00905 void construct_lpprob() ;
00906 void construct_options() ;
00907 void construct_consys(int cols, int rows) ;
00908 void dylp_ioinit() ;
00909 void gen_rowparms(int rowcnt,
00910 double *rhs, double *rhslow, contyp_enum *ctyp,
00911 const double *rowlb, const double *rowub) ;
00912 void gen_rowparms(int rowcnt,
00913 double *rhs, double *rhslow, contyp_enum *ctyp,
00914 const char *sense, const double *rhsin, const double *range) ;
00915 void load_problem(const CoinMpsIO &mps) ;
00916 void load_problem(const CoinPackedMatrix &matrix,
00917 const double* col_lower, const double* col_upper, const double* obj,
00918 const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00919 void load_problem (const int colcnt, const int rowcnt,
00920 const int *start, const int *lens,
00921 const int *index, const double *value,
00922 const double* col_lower, const double* col_upper, const double* obj,
00923 const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00925
00929 lpret_enum do_lp (ODSI_start_enum start) ;
00931
00934 void destruct_col_cache(bool structure) ;
00935 void destruct_row_cache(bool structure) ;
00936 void destruct_cache(bool rowStructure, bool colStructure) ;
00937 void destruct_problem(bool preserve_interface) ;
00938 void detach_dylp() ;
00940
00941
00943
00944
00945
00946
00948
00949 void add_col(const CoinPackedVectorBase& coin_coli,
00950 vartyp_enum vtypi,double vlbi, double vubi, double obji) ;
00951 void add_row(const CoinPackedVectorBase& coin_rowi,
00952 char clazzi, contyp_enum ctypi, double rhsi, double rhslowi) ;
00953 void calc_objval() ;
00954 contyp_enum bound_to_type(double lower, double upper) ;
00955 void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi,
00956 char sensei, double rhsini, double rangei) ;
00957 void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi,
00958 double rowlbi, double rowubi) ;
00959 void unimp_hint(bool dylpSense, bool hintSense,
00960 OsiHintStrength hintStrength, const char *msgString) ;
00961 void pessimal_primal() ;
00962
00964
00967 static contyp_enum sense_to_type(char type) ;
00968 static char type_to_sense(contyp_enum type) ;
00970
00977 template<class T> static void copy(const T* src, T* dst, int n) ;
00978 template<class T> static T* copy(const T* src, int n) ;
00979 template<class T> static T* copy(const T* src) ;
00980
00981
00982
00983 static basis_struct* copy_basis(const basis_struct* src, int dstsze) ;
00984 static void copy_basis(const basis_struct* src, basis_struct* dst) ;
00985 static lpprob_struct* copy_lpprob(const lpprob_struct* src) ;
00987
00988 #ifndef _MSC_VER
00989
00994 template<class T> static void assert_same(const T& t1, const T& t2,
00995 bool exact) ;
00996 template<class T> static void assert_same(const T* t1, const T* t2,
00997 int n, bool exact) ;
00998
00999 static void assert_same(double d1, double d2, bool exact) ;
01000
01001 static void assert_same(const basis_struct& b1,
01002 const basis_struct& b2, bool exact) ;
01003 static void assert_same(const consys_struct& c1, const
01004 consys_struct& c2, bool exact) ;
01005 static void assert_same(const conbnd_struct& c1, const
01006 conbnd_struct& c2, bool exact) ;
01007 static void assert_same(const lpprob_struct& l1,
01008 const lpprob_struct& l2, bool exact) ;
01009 static void assert_same(const OsiDylpSolverInterface& o1,
01010 const OsiDylpSolverInterface& o2, bool exact) ;
01012 #endif
01013
01016 template<class T> static T* idx_vec(T* data) ;
01017 static int idx(int i) ;
01018 template<class T> static T* inv_vec(T* data) ;
01019 static int inv(int i) ;
01020
01021 static pkvec_struct* packed_vector(
01022 const CoinShallowPackedVector vector, int dimension) ;
01023 static void packed_vector(
01024 const CoinShallowPackedVector vector, int dimension, pkvec_struct *dst) ;
01026
01029 static std::string make_filename(const char *filename,
01030 const char *ext1, const char *ext2) ;
01032
01033 } ;
01034
01035
01036
01037
01038
01039
01047 void OsiDylpSolverInterfaceUnitTest(const std::string & mpsDir) ;
01048
01049 #endif // OsiDylpSolverInterface_H
01050 #endif // COIN_HAS_DYLP