/home/coin/DyLP-1.1.2/Osi/src/OsiDylp/OsiDylpSolverInterface.hpp

Go to the documentation of this file.
00001 #ifndef OsiDylpSolverInterface_H
00002 #define OsiDylpSolverInterface_H
00003 
00017 /*
00018   sccs: @(#)OsiDylpSolverInterface.hpp  1.12    09/16/04
00019   cvs: $Id: OsiDylpSolverInterface.hpp 891 2007-02-02 02:42:21Z lou $
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 
00099 class OsiDylpSolverInterface: virtual public OsiSolverInterface
00100 
00101 { friend void OsiDylpSolverInterfaceUnitTest(const std::string &mpsDir,
00102                                              const std::string &netLibDir) ;
00103 
00104 /*
00105   Consult the COIN OSI documentation or relevant source code for details
00106   not covered here. Supported functions are listed first, followed by
00107   unsupported functions.
00108 */
00109 
00110 public:
00111 
00114 
00117   OsiDylpSolverInterface() ;
00118 
00121   OsiDylpSolverInterface(const OsiDylpSolverInterface &src) ;
00122 
00125   OsiSolverInterface* clone(bool copyData = true) const ;
00126 
00129   OsiDylpSolverInterface &operator=(const OsiDylpSolverInterface &rhs) ;
00130 
00133   ~OsiDylpSolverInterface() ;
00134 
00139   void reset() ;
00140 
00142 
00145 
00148   int readMps(const char *filename, const char *extension = "mps") ;
00149 
00154   int readMps(const char *filename, const char *extension,
00155               int &numberSets, CoinSet **&sets) ;
00156 
00164   void writeMps(const char *basename,
00165                 const char *extension = "mps",
00166                 double objsense = 0.0) const ;
00167 
00171   void loadProblem(const CoinPackedMatrix &matrix,
00172                    const double *collb, const double *colub, const double *obj,
00173                    const char *rowsen, const double *rowrhs,
00174                    const double *rowrng) ;
00175 
00179   void loadProblem(const CoinPackedMatrix &matrix,
00180                    const double *collb, const double *colub, const double *obj,
00181                    const double *rowlb, const double *rowub) ;
00182   
00186   void loadProblem(const int colcnt, const int rowcnt,
00187                const int *start, const int *index, const double *value,
00188                const double *collb, const double *colub, const double *obj,
00189                const char *sense, const double *rhsin, const double *range) ;
00190 
00194   void loadProblem(const int colcnt, const int rowcnt,
00195                    const int *start, const int *index, const double *value,
00196                    const double *collb, const double *colub, const double *obj,
00197                    const double *row_lower, const double *row_upper) ;
00198 
00202   void assignProblem(CoinPackedMatrix *&matrix,
00203                      double *&collb, double *&colub, double *&obj, 
00204                      char *&rowsen, double *&rowrhs, double *&rowrng) ;
00205 
00209   void assignProblem(CoinPackedMatrix *&matrix,
00210                      double *&collb, double *&colub, double *&obj,
00211                      double *&rowlb, double *&rowub) ;
00212 
00214 
00218 
00221   int getNumCols() const ;
00222 
00225   int getNumRows() const ;
00226 
00229   int getNumElements() const ;
00230 
00236   int getNumIntegers() const ;
00237 
00240   const double* getColLower() const ;
00241 
00244   const double* getColUpper() const ;
00245 
00248   bool isContinuous(int colIndex) const ;
00249 
00252   bool isBinary(int colIndex) const ;
00253 
00256   bool isIntegerNonBinary (int colIndex) const ;
00257 
00260   bool isInteger (int colIndex) const ;
00261 
00264   const char* getRowSense() const ;
00265 
00268   const double* getRightHandSide() const ;
00269 
00272   const double* getRowRange() const ;
00273 
00276   const double* getRowLower() const ;
00277 
00280   const double* getRowUpper() const ;
00281 
00284   const double* getObjCoefficients() const ;
00285 
00291   double getObjSense() const ;
00292 
00295   const CoinPackedMatrix *getMatrixByRow() const ;
00296 
00299   const CoinPackedMatrix *getMatrixByCol() const ;
00301 
00304 
00307   void setContinuous(int index) ;
00308 
00311   void setContinuous(const int *indices, int len) ;
00312 
00315   void setInteger(int index) ;
00316 
00319   void setInteger(const int *indices, int len) ;
00320 
00323   void setColLower(int index, double value) ;
00324   using OsiSolverInterface::setColLower ;
00325 
00328   void setColUpper(int index, double value) ;
00329   using OsiSolverInterface::setColUpper ;
00330 
00333   void setRowLower(int index, double value) ;
00334 
00337   void setRowUpper(int index, double value) ;
00338 
00341   void setRowType(int index, char rowsen, double rowrhs, double rowrng) ;
00342 
00345   void setObjCoeff (int index, double value) ;
00346 
00353   void setObjSense(double sense) ;
00354 
00357   void setColSolution(const double *colsol) ;
00358 
00361   void setRowPrice(const double*) ;
00362 
00363   /* For overload resolution with OSI::addCol functions. */
00364 
00365   using OsiSolverInterface::addCol ;
00366 
00369   void addCol(const CoinPackedVectorBase &vec,
00370               const double collb, const double colub, const double obj) ;
00371 
00374   void deleteCols(const int num, const int *colIndices) ;
00375 
00376   /* For overload resolution with OSI::addCol functions. */
00377 
00378   using OsiSolverInterface::addRow ;
00379 
00382   void addRow(const CoinPackedVectorBase &row,
00383               const double rowlb, const double rowub) ;
00384 
00387   void addRow(const CoinPackedVectorBase &row,
00388               const char rowsen, const double rowrhs, const double rowrng) ;
00389 
00392   void deleteRows(const int num, const int *rowIndices) ;
00393 
00396   void applyRowCut(const OsiRowCut &cut) ;
00397 
00400   void applyColCut(const OsiColCut &cut) ;
00402 
00405 
00408   void initialSolve() ;
00409 
00412   CoinWarmStart *getEmptyWarmStart () const ;
00413 
00416   CoinWarmStart *getWarmStart() const ;
00417 
00420   bool setWarmStart(const CoinWarmStart *warmStart) ;
00421 
00424   void resolve() ;
00425 
00428   void markHotStart() ;
00429 
00432   void solveFromHotStart() ;
00433 
00436   void unmarkHotStart() ;
00437 
00439 
00442 
00445   bool isAbandoned() const ;
00446 
00449   bool isProvenOptimal() const ;
00450 
00453   bool isProvenPrimalInfeasible() const ;
00454 
00458   bool isProvenDualInfeasible() const ;
00459 
00462   bool isIterationLimitReached() const ;
00463 
00466   int getIterationCount() const ;
00467 
00470   bool isPrimalObjectiveLimitReached() const ;
00471 
00474   bool isDualObjectiveLimitReached() const ;
00476 
00477 
00480 
00483   double getInfinity() const ;
00484 
00487   bool setIntParam(OsiIntParam key, int value) ;
00488 
00491   bool setDblParam(OsiDblParam key, double value) ;
00492 
00495   bool setStrParam(OsiStrParam key, const std::string& value) ;
00496 
00499   bool setHintParam(OsiHintParam key, bool sense = true,
00500                     OsiHintStrength strength = OsiHintTry, void *info = 0) ;
00501 
00504   bool getIntParam(OsiIntParam key, int &value) const ;
00505 
00508   bool getDblParam(OsiDblParam key, double &value) const ;
00509 
00512   bool getStrParam(OsiStrParam key, std::string &value) const ;
00513 
00514   /* For overload resolution with OSI::getHintParam functions. */
00515 
00516   using OsiSolverInterface::getHintParam ;
00517 
00520   bool getHintParam(OsiHintParam key, bool &sense,
00521                     OsiHintStrength &strength, void *&info) const ;
00522 
00525   inline void newLanguage(CoinMessages::Language language)
00526   { setOsiDylpMessages(language) ; } ;
00527 
00530   inline void setLanguage(CoinMessages::Language language)
00531   { setOsiDylpMessages(language) ; } ;
00532 
00534 
00537 
00540   const double* getColSolution() const ; 
00541 
00544   const double* getRowPrice() const ;
00545 
00548   const double* getReducedCost() const ;
00549 
00552   const double* getRowActivity() const ;
00553 
00556   double getObjValue() const ;
00557 
00559 
00562 
00569   void activateRowCutDebugger (const char * modelName) ;
00570 
00578   void activateRowCutDebugger (const double *solution) ;
00579 
00580 # if ODSI_PARANOIA >= 1
00581 
00590   void indexCheck (int k, bool isCol, std::string rtnnme) ;
00591 # endif
00592 
00594 
00597 
00600   void dylp_controlfile(const char* name, const bool silent,
00601                         const bool mustexist = true) ;
00602 
00605   void dylp_logfile(const char* name, bool echo = false) ;
00606 
00609   void dylp_outfile(const char* name) ;
00610 
00613   void dylp_printsoln(bool wantSoln, bool wantStats) ;
00614 
00617   void setOsiDylpMessages(CoinMessages::Language local_language) ;
00618 
00620 
00623 
00624 
00627   void branchAndBound() ;
00628 
00631   std::vector<double *> getDualRays(int) const ;
00632 
00635   std::vector<double *> getPrimalRays(int) const ;
00637 
00642 /*
00643   Leave them visible to the public for the nonce, until a better programmatic
00644   interface is available. Initialized by the constructor.
00645 */
00647 
00648   lpopts_struct *initialSolveOptions,*resolveOptions ;
00649   lptols_struct* tolerances ;
00650 
00652 
00653 private:
00654 
00655 /*
00656   Private implementation state and helper functions. If you're contemplating
00657   using any of these, you should have a look at the code.
00658   See OsiDylpSolverInterface.cpp for descriptions.
00659 */ 
00666 
00667   consys_struct* consys ;
00668   lpprob_struct* lpprob ;
00669   lpstats_struct* statistics ;
00670 
00672 
00675 
00676   static int reference_count ;
00677   static bool basis_ready ;
00678   static OsiDylpSolverInterface *dylp_owner ;
00679 
00681 
00682 
00688 
00695   ioid local_outchn ;
00696 
00702   ioid local_logchn ;
00703 
00708   bool initial_gtxecho ;
00709 
00714   bool resolve_gtxecho ;
00715 
00725   lpret_enum lp_retval ;
00726 
00732   double obj_sense ;
00733 
00736   double odsiInfinity ;
00737 
00740   const std::string solvername ;
00741 
00744   mutable void *info_[OsiLastHintParam] ;
00745 
00748   bool mps_debug ;
00749 
00752   CoinWarmStart *hotstart_fallback ;
00753 
00763   CoinWarmStart *activeBasis ;
00764 
00770   bool activeIsModified ;
00771 
00777   bool solnIsFresh ;
00778 
00788   int addedColCnt ;
00789 
00799   int addedRowCnt ;
00800 
00802 
00803 
00804 
00811 
00812   mutable double _objval ;
00813   mutable double* _col_obj ;
00814   mutable double* _col_x ;
00815   mutable double* _col_cbar ;
00816 
00817   mutable double* _row_rhs ;
00818   mutable double* _row_lower ;
00819   mutable double* _row_upper ;
00820   mutable char* _row_sense ;
00821   mutable double* _row_range ;
00822   mutable double* _row_lhs ;
00823   mutable double* _row_price ;
00824 
00825   mutable CoinPackedMatrix* _matrix_by_col ;
00826   mutable CoinPackedMatrix* _matrix_by_row ;
00827 
00829 
00836 
00842   CoinPresolveMatrix *preObj_ ;
00843 
00850   const CoinPresolveAction *postActions_ ;
00851 
00859   CoinPostsolveMatrix *postObj_ ;
00860 
00862   int passLimit_ ;
00863 
00865   bool keepIntegers_ ;
00866 
00868   consys_struct *savedConsys_ ;
00869 
00871   mutable double* saved_col_obj ;
00872   mutable double* saved_row_rhs ;
00873   mutable double* saved_row_lower ;
00874   mutable double* saved_row_upper ;
00875   mutable char* saved_row_sense ;
00876   mutable double* saved_row_range ;
00877   mutable CoinPackedMatrix* saved_matrix_by_col ;
00878   mutable CoinPackedMatrix* saved_matrix_by_row ;
00879 
00881 
00891 
00892   CoinPresolveMatrix *initialisePresolve(bool keepIntegers) ;
00893 
00895   void doPresolve() ;
00896 
00898   bool evalPresolve() ;
00899 
00901   void saveOriginalSys() ;
00902 
00904   void installPresolve() ;
00905 
00907   CoinPostsolveMatrix *initialisePostsolve(CoinPresolveMatrix *&preObj) ;
00908 
00910   void doPostsolve() ;
00911 
00913   void installPostsolve() ;
00914 
00916   void destruct_presolve() ;
00917 
00919 
00923   void construct_lpprob() ;
00924   void construct_options() ;
00925   void construct_consys(int cols, int rows) ;
00926   void dylp_ioinit() ;
00927   void gen_rowparms(int rowcnt,
00928                     double *rhs, double *rhslow, contyp_enum *ctyp,
00929                     const double *rowlb, const double *rowub) ;
00930   void gen_rowparms(int rowcnt,
00931                double *rhs, double *rhslow, contyp_enum *ctyp,
00932                const char *sense, const double *rhsin, const double *range) ;
00933   void load_problem(const CoinMpsIO &mps) ;
00934   void load_problem(const CoinPackedMatrix &matrix,
00935          const double* col_lower, const double* col_upper, const double* obj,
00936          const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00937   void load_problem (const int colcnt, const int rowcnt,
00938          const int *start, const int *lens,
00939          const int *index, const double *value,
00940          const double* col_lower, const double* col_upper, const double* obj,
00941          const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00943 
00947   lpret_enum do_lp (ODSI_start_enum start) ;
00949 
00952   void destruct_col_cache(bool structure) ;
00953   void destruct_row_cache(bool structure) ;
00954   void destruct_cache(bool rowStructure, bool colStructure) ;
00955   void destruct_problem(bool preserve_interface) ;
00956   void detach_dylp() ;
00958 
00959 
00961 /*
00962   There are separate groups for member and static methods so that doxygen
00963   won't promote the group to the top level.
00964 */
00966   
00967   void add_col(const CoinPackedVectorBase& coin_coli,
00968     vartyp_enum vtypi,double vlbi, double vubi, double obji) ;
00969   void add_row(const CoinPackedVectorBase& coin_rowi, 
00970     char clazzi, contyp_enum ctypi, double rhsi, double rhslowi) ;
00971   void calc_objval() ;
00972   contyp_enum bound_to_type(double lower, double upper) ;
00973   void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi, 
00974                             char sensei, double rhsini, double rangei) ;
00975   void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi, 
00976                             double rowlbi, double rowubi) ;
00977   void unimp_hint(bool dylpSense, bool hintSense,
00978                  OsiHintStrength hintStrength, const char *msgString) ;
00979   void pessimal_primal() ;
00980 
00982 
00985   static contyp_enum sense_to_type(char type) ;
00986   static char type_to_sense(contyp_enum type) ;
00988 
00995   template<class T> static void copy(const T* src, T* dst, int n) ;
00996   template<class T> static T* copy(const T* src, int n) ;
00997   template<class T> static T* copy(const T* src) ;
00998 /*
00999   Specializations for more complicated structures.
01000 */
01001   static basis_struct* copy_basis(const basis_struct* src, int dstsze) ;
01002   static void copy_basis(const basis_struct* src, basis_struct* dst) ;
01003   static lpprob_struct* copy_lpprob(const lpprob_struct* src) ;
01005 
01006 #ifndef _MSC_VER
01007 
01012   template<class T> static void assert_same(const T& t1, const T& t2,
01013                                             bool exact) ;
01014   template<class T> static void assert_same(const T* t1, const T* t2,
01015                                             int n, bool exact) ;
01016 
01017   static void assert_same(double d1, double d2, bool exact) ;
01018 
01019   static void assert_same(const basis_struct& b1, 
01020                           const basis_struct& b2, bool exact) ;
01021   static void assert_same(const consys_struct& c1, const 
01022                           consys_struct& c2, bool exact) ;
01023   static void assert_same(const conbnd_struct& c1, const 
01024                           conbnd_struct& c2, bool exact) ;
01025   static void assert_same(const lpprob_struct& l1, 
01026                           const lpprob_struct& l2, bool exact) ;
01027   static void assert_same(const OsiDylpSolverInterface& o1, 
01028                           const OsiDylpSolverInterface& o2, bool exact) ;
01030 #endif  /* ! _MSC_VER */
01031 
01034   template<class T> static T* idx_vec(T* data) ;
01035   static int idx(int i) ;
01036   template<class T> static T* inv_vec(T* data) ;
01037   static int inv(int i) ;
01038 
01039   static pkvec_struct* packed_vector(
01040     const CoinShallowPackedVector vector, int dimension) ;
01041   static void packed_vector(
01042     const CoinShallowPackedVector vector, int dimension, pkvec_struct *dst) ;
01044 
01047   static std::string make_filename(const char *filename, 
01048                                    const char *ext1, const char *ext2) ;
01050 
01051 } ;
01052 
01053 
01054 /*
01055   OsiDylpSolverInterfaceTest.cpp
01056 */
01057 
01065 void OsiDylpSolverInterfaceUnitTest(const std::string & mpsDir,
01066                                     const std::string &netLibDir) ;
01067 
01068 #endif // OsiDylpSolverInterface_H

Generated on Wed Aug 22 05:46:43 2007 by  doxygen 1.4.7