00001 #ifndef OsiDylpSolverInterface_H
00002 #define OsiDylpSolverInterface_H
00003
00017
00018
00019
00020
00021
00022 #include "OsiConfig.h"
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
00232 int getNumIntegers() const ;
00233
00236 const double* getColLower() const ;
00237
00240 const double* getColUpper() const ;
00241
00244 bool isContinuous(int colIndex) const ;
00245
00248 bool isBinary(int colIndex) const ;
00249
00252 bool isIntegerNonBinary (int colIndex) const ;
00253
00256 bool isInteger (int colIndex) const ;
00257
00260 const char* getRowSense() const ;
00261
00264 const double* getRightHandSide() const ;
00265
00268 const double* getRowRange() const ;
00269
00272 const double* getRowLower() const ;
00273
00276 const double* getRowUpper() const ;
00277
00280 const double* getObjCoefficients() const ;
00281
00284 double getObjSense() const ;
00285
00288 const CoinPackedMatrix *getMatrixByRow() const ;
00289
00292 const CoinPackedMatrix *getMatrixByCol() const ;
00294
00297
00300 void setContinuous(int index) ;
00301
00304 void setContinuous(const int *indices, int len) ;
00305
00308 void setInteger(int index) ;
00309
00312 void setInteger(const int *indices, int len) ;
00313
00316 void setColLower(int index, double value) ;
00317 using OsiSolverInterface::setColLower ;
00318
00321 void setColUpper(int index, double value) ;
00322 using OsiSolverInterface::setColUpper ;
00323
00326 void setRowLower(int index, double value) ;
00327
00330 void setRowUpper(int index, double value) ;
00331
00334 void setRowType(int index, char rowsen, double rowrhs, double rowrng) ;
00335
00338 void setObjCoeff (int index, double value) ;
00339
00342 void setObjSense(double sense) ;
00343
00346 void setColSolution(const double *colsol) ;
00347
00350 void setRowPrice(const double*) ;
00351
00352
00353
00354 using OsiSolverInterface::addCol ;
00355
00358 void addCol(const CoinPackedVectorBase &vec,
00359 const double collb, const double colub, const double obj) ;
00360
00363 void deleteCols(const int num, const int *colIndices) ;
00364
00365
00366
00367 using OsiSolverInterface::addRow ;
00368
00371 void addRow(const CoinPackedVectorBase &row,
00372 const double rowlb, const double rowub) ;
00373
00376 void addRow(const CoinPackedVectorBase &row,
00377 const char rowsen, const double rowrhs, const double rowrng) ;
00378
00381 void deleteRows(const int num, const int *rowIndices) ;
00382
00385 void applyRowCut(const OsiRowCut &cut) ;
00386
00389 void applyColCut(const OsiColCut &cut) ;
00391
00394
00397 void initialSolve() ;
00398
00401 CoinWarmStart *getEmptyWarmStart () const ;
00402
00405 CoinWarmStart *getWarmStart() const ;
00406
00409 bool setWarmStart(const CoinWarmStart *warmStart) ;
00410
00413 void resolve() ;
00414
00417 void markHotStart() ;
00418
00421 void solveFromHotStart() ;
00422
00425 void unmarkHotStart() ;
00426
00428
00431
00434 bool isAbandoned() const ;
00435
00438 bool isProvenOptimal() const ;
00439
00442 bool isProvenPrimalInfeasible() const ;
00443
00447 bool isProvenDualInfeasible() const ;
00448
00451 bool isIterationLimitReached() const ;
00452
00455 int getIterationCount() const ;
00456
00459 bool isPrimalObjectiveLimitReached() const ;
00460
00463 bool isDualObjectiveLimitReached() const ;
00465
00466
00469
00472 double getInfinity() const ;
00473
00476 bool setIntParam(OsiIntParam key, int value) ;
00477
00480 bool setDblParam(OsiDblParam key, double value) ;
00481
00484 bool setStrParam(OsiStrParam key, const std::string& value) ;
00485
00488 bool setHintParam(OsiHintParam key, bool sense = true,
00489 OsiHintStrength strength = OsiHintTry, void *info = 0) ;
00490
00493 bool getIntParam(OsiIntParam key, int &value) const ;
00494
00497 bool getDblParam(OsiDblParam key, double &value) const ;
00498
00501 bool getStrParam(OsiStrParam key, std::string &value) const ;
00502
00503
00504
00505 using OsiSolverInterface::getHintParam ;
00506
00509 bool getHintParam(OsiHintParam key, bool &sense,
00510 OsiHintStrength &strength, void *&info) const ;
00511
00514 inline void newLanguage(CoinMessages::Language language)
00515 { setOsiDylpMessages(language) ; } ;
00516
00519 inline void setLanguage(CoinMessages::Language language)
00520 { setOsiDylpMessages(language) ; } ;
00521
00523
00526
00529 const double* getColSolution() const ;
00530
00533 const double* getRowPrice() const ;
00534
00537 const double* getReducedCost() const ;
00538
00541 const double* getRowActivity() const ;
00542
00545 double getObjValue() const ;
00546
00548
00551
00558 void activateRowCutDebugger (const char * modelName) ;
00559
00567 void activateRowCutDebugger (const double *solution) ;
00568
00569 # if ODSI_PARANOIA >= 1
00570
00579 void indexCheck (int k, bool isCol, std::string rtnnme) ;
00580 # endif
00581
00583
00586
00589 void dylp_controlfile(const char* name, const bool silent,
00590 const bool mustexist = true) ;
00591
00594 void dylp_logfile(const char* name, bool echo = false) ;
00595
00598 void dylp_outfile(const char* name) ;
00599
00602 void dylp_printsoln(bool wantSoln, bool wantStats) ;
00603
00606 void setOsiDylpMessages(CoinMessages::Language local_language) ;
00607
00609
00612
00613
00616 void branchAndBound() ;
00617
00620 std::vector<double *> getDualRays(int) const ;
00621
00624 std::vector<double *> getPrimalRays(int) const ;
00626
00631
00632
00633
00634
00636
00637 lpopts_struct *initialSolveOptions,*resolveOptions ;
00638 lptols_struct* tolerances ;
00639
00641
00642 private:
00643
00644
00645
00646
00647
00648
00655
00656 consys_struct* consys ;
00657 lpprob_struct* lpprob ;
00658 lpstats_struct* statistics ;
00659
00661
00664
00665 static int reference_count ;
00666 static bool basis_ready ;
00667 static OsiDylpSolverInterface *dylp_owner ;
00668
00670
00671
00677
00684 ioid local_outchn ;
00685
00691 ioid local_logchn ;
00692
00697 bool initial_gtxecho ;
00698
00703 bool resolve_gtxecho ;
00704
00714 lpret_enum lp_retval ;
00715
00721 double obj_sense ;
00722
00725 double odsiInfinity ;
00726
00729 const std::string solvername ;
00730
00733 mutable void *info_[OsiLastHintParam] ;
00734
00737 bool mps_debug ;
00738
00741 CoinWarmStart *hotstart_fallback ;
00742
00752 CoinWarmStart *activeBasis ;
00753
00759 bool activeIsModified ;
00760
00766 bool solnIsFresh ;
00767
00777 int addedColCnt ;
00778
00788 int addedRowCnt ;
00789
00791
00792
00793
00800
00801 mutable double _objval ;
00802 mutable double* _col_obj ;
00803 mutable double* _col_x ;
00804 mutable double* _col_cbar ;
00805
00806 mutable double* _row_rhs ;
00807 mutable double* _row_lower ;
00808 mutable double* _row_upper ;
00809 mutable char* _row_sense ;
00810 mutable double* _row_range ;
00811 mutable double* _row_lhs ;
00812 mutable double* _row_price ;
00813
00814 mutable CoinPackedMatrix* _matrix_by_col ;
00815 mutable CoinPackedMatrix* _matrix_by_row ;
00816
00818
00825
00831 CoinPresolveMatrix *preObj_ ;
00832
00839 const CoinPresolveAction *postActions_ ;
00840
00848 CoinPostsolveMatrix *postObj_ ;
00849
00851 int passLimit_ ;
00852
00854 bool keepIntegers_ ;
00855
00857 consys_struct *savedConsys_ ;
00858
00860 mutable double* saved_col_obj ;
00861 mutable double* saved_row_rhs ;
00862 mutable double* saved_row_lower ;
00863 mutable double* saved_row_upper ;
00864 mutable char* saved_row_sense ;
00865 mutable double* saved_row_range ;
00866 mutable CoinPackedMatrix* saved_matrix_by_col ;
00867 mutable CoinPackedMatrix* saved_matrix_by_row ;
00868
00870
00880
00881 CoinPresolveMatrix *initialisePresolve(bool keepIntegers) ;
00882
00884 void doPresolve() ;
00885
00887 bool evalPresolve() ;
00888
00890 void saveOriginalSys() ;
00891
00893 void installPresolve() ;
00894
00896 CoinPostsolveMatrix *initialisePostsolve(CoinPresolveMatrix *&preObj) ;
00897
00899 void doPostsolve() ;
00900
00902 void installPostsolve() ;
00903
00905 void destruct_presolve() ;
00906
00908
00912 void construct_lpprob() ;
00913 void construct_options() ;
00914 void construct_consys(int cols, int rows) ;
00915 void dylp_ioinit() ;
00916 void gen_rowparms(int rowcnt,
00917 double *rhs, double *rhslow, contyp_enum *ctyp,
00918 const double *rowlb, const double *rowub) ;
00919 void gen_rowparms(int rowcnt,
00920 double *rhs, double *rhslow, contyp_enum *ctyp,
00921 const char *sense, const double *rhsin, const double *range) ;
00922 void load_problem(const CoinMpsIO &mps) ;
00923 void load_problem(const CoinPackedMatrix &matrix,
00924 const double* col_lower, const double* col_upper, const double* obj,
00925 const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00926 void load_problem (const int colcnt, const int rowcnt,
00927 const int *start, const int *lens,
00928 const int *index, const double *value,
00929 const double* col_lower, const double* col_upper, const double* obj,
00930 const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00932
00936 lpret_enum do_lp (ODSI_start_enum start) ;
00938
00941 void destruct_col_cache(bool structure) ;
00942 void destruct_row_cache(bool structure) ;
00943 void destruct_cache(bool rowStructure, bool colStructure) ;
00944 void destruct_problem(bool preserve_interface) ;
00945 void detach_dylp() ;
00947
00948
00950
00951
00952
00953
00955
00956 void add_col(const CoinPackedVectorBase& coin_coli,
00957 vartyp_enum vtypi,double vlbi, double vubi, double obji) ;
00958 void add_row(const CoinPackedVectorBase& coin_rowi,
00959 char clazzi, contyp_enum ctypi, double rhsi, double rhslowi) ;
00960 void calc_objval() ;
00961 contyp_enum bound_to_type(double lower, double upper) ;
00962 void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi,
00963 char sensei, double rhsini, double rangei) ;
00964 void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi,
00965 double rowlbi, double rowubi) ;
00966 void unimp_hint(bool dylpSense, bool hintSense,
00967 OsiHintStrength hintStrength, const char *msgString) ;
00968 void pessimal_primal() ;
00969
00971
00974 static contyp_enum sense_to_type(char type) ;
00975 static char type_to_sense(contyp_enum type) ;
00977
00984 template<class T> static void copy(const T* src, T* dst, int n) ;
00985 template<class T> static T* copy(const T* src, int n) ;
00986 template<class T> static T* copy(const T* src) ;
00987
00988
00989
00990 static basis_struct* copy_basis(const basis_struct* src, int dstsze) ;
00991 static void copy_basis(const basis_struct* src, basis_struct* dst) ;
00992 static lpprob_struct* copy_lpprob(const lpprob_struct* src) ;
00994
00995 #ifndef _MSC_VER
00996
01001 template<class T> static void assert_same(const T& t1, const T& t2,
01002 bool exact) ;
01003 template<class T> static void assert_same(const T* t1, const T* t2,
01004 int n, bool exact) ;
01005
01006 static void assert_same(double d1, double d2, bool exact) ;
01007
01008 static void assert_same(const basis_struct& b1,
01009 const basis_struct& b2, bool exact) ;
01010 static void assert_same(const consys_struct& c1, const
01011 consys_struct& c2, bool exact) ;
01012 static void assert_same(const conbnd_struct& c1, const
01013 conbnd_struct& c2, bool exact) ;
01014 static void assert_same(const lpprob_struct& l1,
01015 const lpprob_struct& l2, bool exact) ;
01016 static void assert_same(const OsiDylpSolverInterface& o1,
01017 const OsiDylpSolverInterface& o2, bool exact) ;
01019 #endif
01020
01023 template<class T> static T* idx_vec(T* data) ;
01024 static int idx(int i) ;
01025 template<class T> static T* inv_vec(T* data) ;
01026 static int inv(int i) ;
01027
01028 static pkvec_struct* packed_vector(
01029 const CoinShallowPackedVector vector, int dimension) ;
01030 static void packed_vector(
01031 const CoinShallowPackedVector vector, int dimension, pkvec_struct *dst) ;
01033
01036 static std::string make_filename(const char *filename,
01037 const char *ext1, const char *ext2) ;
01039
01040 } ;
01041
01042
01043
01044
01045
01046
01054 void OsiDylpSolverInterfaceUnitTest(const std::string & mpsDir,
01055 const std::string &netLibDir) ;
01056
01057 #endif // OsiDylpSolverInterface_H