00001 #ifdef COIN_USE_DYLP
00002 #ifndef OsiDylpSolverInterface_H
00003 #define OsiDylpSolverInterface_H
00004
00019
00020
00021
00022
00023
00024 #include <CoinPackedMatrix.hpp>
00025 #include <OsiSolverInterface.hpp>
00026 #include <CoinWarmStart.hpp>
00027 #include <CoinMessageHandler.hpp>
00028 #include <CoinMpsIO.hpp>
00029
00030 #define DYLP_INTERNAL
00031 extern "C" {
00032 #include "dylp.h"
00033 }
00034
00071 class OsiDylpSolverInterface: public OsiSolverInterface
00072
00073 { friend void OsiDylpSolverInterfaceUnitTest(const std::string &mpsDir,
00074 const std::string &netLibDir) ;
00075
00076
00077
00078
00079
00080
00081
00082 public:
00083
00086
00089 OsiDylpSolverInterface() ;
00090
00093 OsiDylpSolverInterface(const OsiDylpSolverInterface &src) ;
00094
00097 OsiSolverInterface* clone(bool copyData = true) const ;
00098
00101 OsiDylpSolverInterface &operator=(const OsiDylpSolverInterface &rhs) ;
00102
00105 ~OsiDylpSolverInterface() ;
00106
00111 void reset() ;
00112
00114
00117
00120 int readMps(const char *filename, const char *extension = "mps") ;
00121
00124 void writeMps(const char *basename,
00125 const char *extension = "mps",
00126 double objsense = 0.0) const ;
00127
00131 void loadProblem(const CoinPackedMatrix &matrix,
00132 const double *collb, const double *colub, const double *obj,
00133 const char *rowsen, const double *rowrhs,
00134 const double *rowrng) ;
00135
00139 void loadProblem(const CoinPackedMatrix &matrix,
00140 const double *collb, const double *colub, const double *obj,
00141 const double *rowlb, const double *rowub) ;
00142
00146 void loadProblem(const int colcnt, const int rowcnt,
00147 const int *start, const int *index, const double *value,
00148 const double *collb, const double *colub, const double *obj,
00149 const char *sense, const double *rhsin, const double *range) ;
00150
00154 void loadProblem(const int colcnt, const int rowcnt,
00155 const int *start, const int *index, const double *value,
00156 const double *collb, const double *colub, const double *obj,
00157 const double *row_lower, const double *row_upper) ;
00158
00162 void assignProblem(CoinPackedMatrix *&matrix,
00163 double *&collb, double *&colub, double *&obj,
00164 char *&rowsen, double *&rowrhs, double *&rowrng) ;
00165
00169 void assignProblem(CoinPackedMatrix *&matrix,
00170 double *&collb, double *&colub, double *&obj,
00171 double *&rowlb, double *&rowub) ;
00172
00174
00178
00181 int getNumCols() const ;
00182
00185 int getNumRows() const ;
00186
00189 int getNumElements() const ;
00190
00193 const double* getColLower() const ;
00194
00197 const double* getColUpper() const ;
00198
00201 bool isContinuous(int colIndex) const ;
00202
00205 bool isBinary(int colIndex) const ;
00206
00209 bool isIntegerNonBinary (int colIndex) const ;
00210
00213 bool isInteger (int colIndex) const ;
00214
00217 const char* getRowSense() const ;
00218
00221 const double* getRightHandSide() const ;
00222
00225 const double* getRowRange() const ;
00226
00229 const double* getRowLower() const ;
00230
00233 const double* getRowUpper() const ;
00234
00237 const double* getObjCoefficients() const ;
00238
00241 double getObjSense() const ;
00242
00245 const CoinPackedMatrix *getMatrixByRow() const ;
00246
00249 const CoinPackedMatrix *getMatrixByCol() const ;
00251
00254
00257 void setContinuous(int index) ;
00258
00261 void setContinuous(const int *indices, int len) ;
00262
00265 void setInteger(int index) ;
00266
00269 void setInteger(const int *indices, int len) ;
00270
00273 void setColLower(int index, double value) ;
00274
00277 void setColUpper(int index, double value) ;
00278
00281 void setRowLower(int index, double value) ;
00282
00285 void setRowUpper(int index, double value) ;
00286
00289 void setRowType(int index, char rowsen, double rowrhs, double rowrng) ;
00290
00293 void setObjCoeff (int index, double value) ;
00294
00297 void setObjSense(double sense) ;
00298
00301 void setColSolution(const double *colsol) ;
00302
00305 void setRowPrice(const double*) ;
00306
00309 void addCol(const CoinPackedVectorBase &vec,
00310 const double collb, const double colub, const double obj) ;
00311
00314 void deleteCols(const int num, const int *colIndices) ;
00315
00318 void addRow(const CoinPackedVectorBase &row,
00319 const double rowlb, const double rowub) ;
00320
00323 void addRow(const CoinPackedVectorBase &row,
00324 const char rowsen, const double rowrhs, const double rowrng) ;
00325
00328 void deleteRows(const int num, const int *rowIndices) ;
00329
00332 void applyRowCut(const OsiRowCut &cut) ;
00333
00336 void applyColCut(const OsiColCut &cut) ;
00338
00341
00344 void initialSolve() ;
00345
00348 CoinWarmStart *getEmptyWarmStart () const ;
00349
00352 CoinWarmStart *getWarmStart() const ;
00353
00356 bool setWarmStart(const CoinWarmStart *warmStart) ;
00357
00360 void resolve() ;
00361
00364 void markHotStart() ;
00365
00368 void solveFromHotStart() ;
00369
00372 void unmarkHotStart() ;
00373
00375
00378
00381 bool isAbandoned() const ;
00382
00385 bool isProvenOptimal() const ;
00386
00389 bool isProvenPrimalInfeasible() const ;
00390
00394 bool isProvenDualInfeasible() const ;
00395
00398 bool isIterationLimitReached() const ;
00399
00402 int getIterationCount() const ;
00403
00406 bool isPrimalObjectiveLimitReached() const ;
00407
00410 bool isDualObjectiveLimitReached() const ;
00412
00413
00416
00419 double getInfinity() const ;
00420
00423 bool setIntParam(OsiIntParam key, int value) ;
00424
00427 bool setDblParam(OsiDblParam key, double value) ;
00428
00431 bool setStrParam(OsiStrParam key, const std::string& value) ;
00432
00435 bool setHintParam(OsiHintParam key, bool sense = true,
00436 OsiHintStrength strength = OsiHintTry, void *info = 0) ;
00437
00440 bool getIntParam(OsiIntParam key, int &value) const ;
00441
00444 bool getDblParam(OsiDblParam key, double &value) const ;
00445
00448 bool getStrParam(OsiStrParam key, std::string &value) const ;
00449
00450
00451
00452 using OsiSolverInterface::getHintParam ;
00453
00456 bool getHintParam(OsiHintParam key, bool &sense,
00457 OsiHintStrength &strength, void *&info) const ;
00458
00461 inline void newLanguage(CoinMessages::Language language)
00462 { setOsiDylpMessages(language) ; } ;
00463
00466 inline void setLanguage(CoinMessages::Language language)
00467 { setOsiDylpMessages(language) ; } ;
00468
00470
00473
00476 const double* getColSolution() const ;
00477
00480 const double* getRowPrice() const ;
00481
00484 const double* getReducedCost() const ;
00485
00488 const double* getRowActivity() const ;
00489
00492 double getObjValue() const ;
00493
00495
00498
00501 void activateRowCutDebugger (const char * modelName) ;
00502
00504
00507
00510 void dylp_controlfile(const char* name, const bool silent,
00511 const bool mustexist = true) ;
00512
00515 void dylp_logfile(const char* name, bool echo = false) ;
00516
00519 void setOsiDylpMessages(CoinMessages::Language local_language) ;
00520
00522
00525
00526
00529 void branchAndBound() ;
00530
00533 std::vector<double *> getDualRays(int) const ;
00534
00537 std::vector<double *> getPrimalRays(int) const ;
00539
00544
00545
00546
00547
00549
00550 lpopts_struct *initialSolveOptions,*resolveOptions ;
00551 lptols_struct* tolerances ;
00552
00554
00555 private:
00556
00557
00558
00559
00560
00561
00568
00569 consys_struct* consys ;
00570 lpprob_struct* lpprob ;
00571 lpstats_struct* statistics ;
00572
00574
00577
00578 static int reference_count ;
00579 static bool basis_ready ;
00580 static OsiDylpSolverInterface *dylp_owner ;
00581
00583
00584
00590
00593 ioid local_logchn ;
00594
00597 bool initial_gtxecho ;
00598 bool resolve_gtxecho ;
00599
00602 lpret_enum lp_retval ;
00603
00609 double obj_sense ;
00610
00613 const std::string solvername ;
00614
00617 void *info_[OsiLastHintParam] ;
00618
00621 bool mps_debug ;
00622
00625 CoinWarmStart *hotstart_fallback ;
00626
00629 CoinWarmStart *activeBasis ;
00630
00635 bool activeIsModified ;
00636
00638
00639
00640
00647
00648 mutable double _objval ;
00649 mutable double* _col_x ;
00650 mutable double* _col_obj ;
00651 mutable double* _col_cbar ;
00652 mutable double* _row_lhs ;
00653 mutable double* _row_lower ;
00654 mutable double* _row_price ;
00655 mutable double* _row_range ;
00656 mutable double* _row_rhs ;
00657 mutable char* _row_sense ;
00658 mutable double* _row_upper ;
00659 mutable CoinPackedMatrix* _matrix_by_row ;
00660 mutable CoinPackedMatrix* _matrix_by_col ;
00661
00663
00667 void construct_lpprob() ;
00668 void construct_options() ;
00669 void construct_consys(int cols, int rows) ;
00670 void dylp_ioinit() ;
00671 void gen_rowparms(int rowcnt,
00672 double *rhs, double *rhslow, contyp_enum *ctyp,
00673 const double *rowlb, const double *rowub) ;
00674 void gen_rowparms(int rowcnt,
00675 double *rhs, double *rhslow, contyp_enum *ctyp,
00676 const char *sense, const double *rhsin, const double *range) ;
00677 void load_problem(const CoinMpsIO &mps) ;
00678 void load_problem(const CoinPackedMatrix &matrix,
00679 const double* col_lower, const double* col_upper, const double* obj,
00680 const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00681 void load_problem (const int colcnt, const int rowcnt,
00682 const int *start, const int *index, const double *value,
00683 const double* col_lower, const double* col_upper, const double* obj,
00684 const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00686
00689 void destruct_col_cache() ;
00690 void destruct_row_cache() ;
00691 void destruct_cache() ;
00692 void destruct_problem(bool preserve_interface) ;
00693 void detach_dylp() ;
00695
00696
00698
00699
00700
00701
00703
00704 void add_col(const CoinPackedVectorBase& coin_coli,
00705 vartyp_enum vtypi,double vlbi, double vubi, double obji) ;
00706 void add_row(const CoinPackedVectorBase& coin_rowi,
00707 char clazzi, contyp_enum ctypi, double rhsi, double rhslowi) ;
00708 void worst_case_primal() ;
00709 void calc_objval() ;
00710 void unimp_hint(bool dylpSense, bool hintSense,
00711 OsiHintStrength hintStrength, const char *msgString) ;
00712
00714
00717 static contyp_enum bound_to_type(double lower, double upper) ;
00718 static contyp_enum sense_to_type(char type) ;
00719 static char type_to_sense(contyp_enum type) ;
00720 static void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi,
00721 char sensei, double rhsini, double rangei) ;
00722 static void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi,
00723 double rowlbi, double rowubi) ;
00725
00732 template<class T> static void copy(const T* src, T* dst, int n) ;
00733 template<class T> static T* copy(const T* src, int n) ;
00734 template<class T> static T* copy(const T* src) ;
00735
00736
00737
00738 static basis_struct* copy_basis(const basis_struct* src, int dstsze) ;
00739 static void copy_basis(const basis_struct* src, basis_struct* dst) ;
00740 static lpprob_struct* copy_lpprob(const lpprob_struct* src) ;
00742
00743 #ifndef _MSC_VER
00744
00749 template<class T> static void assert_same(const T& t1, const T& t2,
00750 bool exact) ;
00751 template<class T> static void assert_same(const T* t1, const T* t2,
00752 int n, bool exact) ;
00753
00754 static void assert_same(double d1, double d2, bool exact) ;
00755
00756 static void assert_same(const basis_struct& b1,
00757 const basis_struct& b2, bool exact) ;
00758 static void assert_same(const consys_struct& c1, const
00759 consys_struct& c2, bool exact) ;
00760 static void assert_same(const conbnd_struct& c1, const
00761 conbnd_struct& c2, bool exact) ;
00762 static void assert_same(const lpprob_struct& l1,
00763 const lpprob_struct& l2, bool exact) ;
00764 static void assert_same(const OsiDylpSolverInterface& o1,
00765 const OsiDylpSolverInterface& o2, bool exact) ;
00767 #endif
00768
00771 template<class T> static T* idx_vec(T* data) ;
00772 static int idx(int i) ;
00773 template<class T> static T* inv_vec(T* data) ;
00774 static int inv(int i) ;
00775
00776 static pkvec_struct* packed_vector(
00777 const CoinShallowPackedVector vector, int dimension) ;
00778 static void packed_vector(
00779 const CoinShallowPackedVector vector, int dimension, pkvec_struct *dst) ;
00781
00784 static std::string make_filename(const char *filename,
00785 const char *ext1, const char *ext2) ;
00787
00788 } ;
00789
00790
00791
00792
00793
00794
00799 void OsiDylpSolverInterfaceUnitTest(const std::string & mpsDir) ;
00800
00801 #endif // OsiDylpSolverInterface_H
00802 #endif // COIN_USE_DYLP