/home/coin/SVN-release/Osi-0.97.1/Osi/src/OsiDylp/OsiDylpSolverInterface.hpp

Go to the documentation of this file.
00001 #ifndef OsiDylpSolverInterface_H
00002 #define OsiDylpSolverInterface_H
00003 
00018 /*
00019   sccs: @(#)OsiDylpSolverInterface.hpp  1.12    09/16/04
00020   cvs: $Id: OsiDylpSolverInterface.hpp 1071 2007-08-20 04:04:33Z andreasw $
00021 */
00022 
00023 #include "OsiConfig.h"
00024 #include <CoinPackedMatrix.hpp>
00025 #include <OsiSolverInterface.hpp>
00026 #include <CoinWarmStart.hpp>
00027 #include <CoinMessageHandler.hpp>
00028 #include <CoinMpsIO.hpp>
00029 #include <CoinPresolveMatrix.hpp>
00030 
00031 #define DYLP_INTERNAL
00032 extern "C" {
00033 #include "dylp.h"
00034 }
00035 
00038 typedef enum { startInvalid = 0,
00039                startCold = 1, startWarm, startHot } ODSI_start_enum ;
00040 
00041 
00100 class OsiDylpSolverInterface: virtual public OsiSolverInterface
00101 
00102 { friend void OsiDylpSolverInterfaceUnitTest(const std::string &mpsDir,
00103                                              const std::string &netLibDir) ;
00104 
00105 /*
00106   Consult the COIN OSI documentation or relevant source code for details
00107   not covered here. Supported functions are listed first, followed by
00108   unsupported functions.
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 
00165   void writeMps(const char *basename,
00166                 const char *extension = "mps",
00167                 double objsense = 0.0) const ;
00168 
00172   void loadProblem(const CoinPackedMatrix &matrix,
00173                    const double *collb, const double *colub, const double *obj,
00174                    const char *rowsen, const double *rowrhs,
00175                    const double *rowrng) ;
00176 
00180   void loadProblem(const CoinPackedMatrix &matrix,
00181                    const double *collb, const double *colub, const double *obj,
00182                    const double *rowlb, const double *rowub) ;
00183   
00187   void loadProblem(const int colcnt, const int rowcnt,
00188                const int *start, const int *index, const double *value,
00189                const double *collb, const double *colub, const double *obj,
00190                const char *sense, const double *rhsin, const double *range) ;
00191 
00195   void loadProblem(const int colcnt, const int rowcnt,
00196                    const int *start, const int *index, const double *value,
00197                    const double *collb, const double *colub, const double *obj,
00198                    const double *row_lower, const double *row_upper) ;
00199 
00203   void assignProblem(CoinPackedMatrix *&matrix,
00204                      double *&collb, double *&colub, double *&obj, 
00205                      char *&rowsen, double *&rowrhs, double *&rowrng) ;
00206 
00210   void assignProblem(CoinPackedMatrix *&matrix,
00211                      double *&collb, double *&colub, double *&obj,
00212                      double *&rowlb, double *&rowub) ;
00213 
00215 
00219 
00222   int getNumCols() const ;
00223 
00226   int getNumRows() const ;
00227 
00230   int getNumElements() const ;
00231 
00237   int getNumIntegers() const ;
00238 
00241   const double* getColLower() const ;
00242 
00245   const double* getColUpper() const ;
00246 
00249   bool isContinuous(int colIndex) const ;
00250 
00253   bool isBinary(int colIndex) const ;
00254 
00257   bool isIntegerNonBinary (int colIndex) const ;
00258 
00261   bool isInteger (int colIndex) const ;
00262 
00265   const char* getRowSense() const ;
00266 
00269   const double* getRightHandSide() const ;
00270 
00273   const double* getRowRange() const ;
00274 
00277   const double* getRowLower() const ;
00278 
00281   const double* getRowUpper() const ;
00282 
00285   const double* getObjCoefficients() const ;
00286 
00292   double getObjSense() const ;
00293 
00296   const CoinPackedMatrix *getMatrixByRow() const ;
00297 
00300   const CoinPackedMatrix *getMatrixByCol() const ;
00302 
00305 
00308   void setContinuous(int index) ;
00309 
00312   void setContinuous(const int *indices, int len) ;
00313 
00316   void setInteger(int index) ;
00317 
00320   void setInteger(const int *indices, int len) ;
00321 
00324   void setColLower(int index, double value) ;
00325   using OsiSolverInterface::setColLower ;
00326 
00329   void setColUpper(int index, double value) ;
00330   using OsiSolverInterface::setColUpper ;
00331 
00334   void setRowLower(int index, double value) ;
00335 
00338   void setRowUpper(int index, double value) ;
00339 
00342   void setRowType(int index, char rowsen, double rowrhs, double rowrng) ;
00343 
00346   void setObjCoeff (int index, double value) ;
00347 
00354   void setObjSense(double sense) ;
00355 
00358   void setColSolution(const double *colsol) ;
00359 
00362   void setRowPrice(const double*) ;
00363 
00364   /* For overload resolution with OSI::addCol functions. */
00365 
00366   using OsiSolverInterface::addCol ;
00367 
00370   void addCol(const CoinPackedVectorBase &vec,
00371               const double collb, const double colub, const double obj) ;
00372 
00375   void deleteCols(const int num, const int *colIndices) ;
00376 
00377   /* For overload resolution with OSI::addRow functions. */
00378 
00379   using OsiSolverInterface::addRow ;
00380 
00383   void addRow(const CoinPackedVectorBase &row,
00384               const double rowlb, const double rowub) ;
00385 
00388   void addRow(const CoinPackedVectorBase &row,
00389               const char rowsen, const double rowrhs, const double rowrng) ;
00390 
00393   void deleteRows(const int num, const int *rowIndices) ;
00394 
00397   void applyRowCut(const OsiRowCut &cut) ;
00398 
00401   void applyColCut(const OsiColCut &cut) ;
00403 
00406 
00409   void initialSolve() ;
00410 
00413   CoinWarmStart *getEmptyWarmStart () const ;
00414 
00417   CoinWarmStart *getWarmStart() const ;
00418 
00421   bool setWarmStart(const CoinWarmStart *warmStart) ;
00422 
00425   void resolve() ;
00426 
00429   void markHotStart() ;
00430 
00433   void solveFromHotStart() ;
00434 
00437   void unmarkHotStart() ;
00438 
00440 
00443 
00446   bool isAbandoned() const ;
00447 
00450   bool isProvenOptimal() const ;
00451 
00454   bool isProvenPrimalInfeasible() const ;
00455 
00459   bool isProvenDualInfeasible() const ;
00460 
00463   bool isIterationLimitReached() const ;
00464 
00467   int getIterationCount() const ;
00468 
00474   bool isPrimalObjectiveLimitReached() const ;
00475 
00481   bool isDualObjectiveLimitReached() const ;
00483 
00484 
00487 
00490   double getInfinity() const ;
00491 
00494   bool setIntParam(OsiIntParam key, int value) ;
00495 
00498   bool setDblParam(OsiDblParam key, double value) ;
00499 
00502   bool setStrParam(OsiStrParam key, const std::string& value) ;
00503 
00506   bool setHintParam(OsiHintParam key, bool sense = true,
00507                     OsiHintStrength strength = OsiHintTry, void *info = 0) ;
00508 
00511   bool getIntParam(OsiIntParam key, int &value) const ;
00512 
00515   bool getDblParam(OsiDblParam key, double &value) const ;
00516 
00519   bool getStrParam(OsiStrParam key, std::string &value) const ;
00520 
00521   /* For overload resolution with OSI::getHintParam functions. */
00522 
00523   using OsiSolverInterface::getHintParam ;
00524 
00527   bool getHintParam(OsiHintParam key, bool &sense,
00528                     OsiHintStrength &strength, void *&info) const ;
00529 
00532   inline void newLanguage(CoinMessages::Language language)
00533   { setOsiDylpMessages(language) ; }
00534 
00537   inline void setLanguage(CoinMessages::Language language)
00538   { setOsiDylpMessages(language) ; }
00539 
00541 
00544 
00547   const double* getColSolution() const ; 
00548 
00551   const double* getRowPrice() const ;
00552 
00555   const double* getReducedCost() const ;
00556 
00559   const double* getRowActivity() const ;
00560 
00563   double getObjValue() const ;
00564 
00566 
00573 
00576   void setObjName (std::string name) ;
00577 
00583   void setRowName(int ndx, std::string name) ;
00584 
00590   void setColName(int ndx, std::string name) ;
00591 
00593 
00596 
00603   void activateRowCutDebugger (const char * modelName) ;
00604 
00612   void activateRowCutDebugger (const double *solution) ;
00613 
00614 # if ODSI_PARANOIA >= 1
00615 
00624   void indexCheck (int k, bool isCol, std::string rtnnme) ;
00625 # endif
00626 
00628 
00631 
00634   void dylp_controlfile(const char* name, const bool silent,
00635                         const bool mustexist = true) ;
00636 
00639   void dylp_logfile(const char* name, bool echo = false) ;
00640 
00643   void dylp_outfile(const char* name) ;
00644 
00647   void dylp_printsoln(bool wantSoln, bool wantStats) ;
00648 
00651   void setOsiDylpMessages(CoinMessages::Language local_language) ;
00652 
00654 
00657 
00658 
00661   void branchAndBound() ;
00662 
00665   std::vector<double *> getDualRays(int) const ;
00666 
00669   std::vector<double *> getPrimalRays(int) const ;
00671 
00676 /*
00677   Leave them visible to the public for the nonce, until a better programmatic
00678   interface is available. Initialized by the constructor.
00679 */
00681 
00682   lpopts_struct *initialSolveOptions,*resolveOptions ;
00683   lptols_struct* tolerances ;
00684 
00686 
00687 private:
00688 
00689 /*
00690   Private implementation state and helper functions. If you're contemplating
00691   using any of these, you should have a look at the code.
00692   See OsiDylpSolverInterface.cpp for descriptions.
00693 */ 
00700 
00701   consys_struct* consys ;
00702   lpprob_struct* lpprob ;
00703   lpstats_struct* statistics ;
00704 
00706 
00709 
00710   static int reference_count ;
00711   static bool basis_ready ;
00712   static OsiDylpSolverInterface *dylp_owner ;
00713 
00715 
00716 
00722 
00729   ioid local_outchn ;
00730 
00736   ioid local_logchn ;
00737 
00742   bool initial_gtxecho ;
00743 
00748   bool resolve_gtxecho ;
00749 
00759   lpret_enum lp_retval ;
00760 
00766   double obj_sense ;
00767 
00770   double odsiInfinity ;
00771 
00774   const std::string solvername ;
00775 
00778   mutable void *info_[OsiLastHintParam] ;
00779 
00782   bool mps_debug ;
00783 
00786   CoinWarmStart *hotstart_fallback ;
00787 
00797   CoinWarmStart *activeBasis ;
00798 
00804   bool activeIsModified ;
00805 
00811   bool solnIsFresh ;
00812 
00822   int addedColCnt ;
00823 
00833   int addedRowCnt ;
00834 
00836 
00837 
00838 
00845 
00846   mutable double _objval ;
00847   mutable double* _col_obj ;
00848   mutable double* _col_x ;
00849   mutable double* _col_cbar ;
00850 
00851   mutable double* _row_rhs ;
00852   mutable double* _row_lower ;
00853   mutable double* _row_upper ;
00854   mutable char* _row_sense ;
00855   mutable double* _row_range ;
00856   mutable double* _row_lhs ;
00857   mutable double* _row_price ;
00858 
00859   mutable CoinPackedMatrix* _matrix_by_col ;
00860   mutable CoinPackedMatrix* _matrix_by_row ;
00861 
00863 
00870 
00876   CoinPresolveMatrix *preObj_ ;
00877 
00884   const CoinPresolveAction *postActions_ ;
00885 
00893   CoinPostsolveMatrix *postObj_ ;
00894 
00896   int passLimit_ ;
00897 
00899   bool keepIntegers_ ;
00900 
00902   consys_struct *savedConsys_ ;
00903 
00905   mutable double* saved_col_obj ;
00906   mutable double* saved_row_rhs ;
00907   mutable double* saved_row_lower ;
00908   mutable double* saved_row_upper ;
00909   mutable char* saved_row_sense ;
00910   mutable double* saved_row_range ;
00911   mutable CoinPackedMatrix* saved_matrix_by_col ;
00912   mutable CoinPackedMatrix* saved_matrix_by_row ;
00913 
00915 
00925 
00926   CoinPresolveMatrix *initialisePresolve(bool keepIntegers) ;
00927 
00929   void doPresolve() ;
00930 
00932   bool evalPresolve() ;
00933 
00935   void saveOriginalSys() ;
00936 
00938   void installPresolve() ;
00939 
00941   CoinPostsolveMatrix *initialisePostsolve(CoinPresolveMatrix *&preObj) ;
00942 
00944   void doPostsolve() ;
00945 
00947   void installPostsolve() ;
00948 
00950   void destruct_presolve() ;
00951 
00953 
00957   void construct_lpprob() ;
00958   void construct_options() ;
00959   void construct_consys(int cols, int rows) ;
00960   void dylp_ioinit() ;
00961   void gen_rowparms(int rowcnt,
00962                     double *rhs, double *rhslow, contyp_enum *ctyp,
00963                     const double *rowlb, const double *rowub) ;
00964   void gen_rowparms(int rowcnt,
00965                double *rhs, double *rhslow, contyp_enum *ctyp,
00966                const char *sense, const double *rhsin, const double *range) ;
00967   void load_problem(const CoinMpsIO &mps) ;
00968   void load_problem(const CoinPackedMatrix &matrix,
00969          const double* col_lower, const double* col_upper, const double* obj,
00970          const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00971   void load_problem (const int colcnt, const int rowcnt,
00972          const int *start, const int *lens,
00973          const int *index, const double *value,
00974          const double* col_lower, const double* col_upper, const double* obj,
00975          const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00977 
00981   lpret_enum do_lp (ODSI_start_enum start) ;
00983 
00986   void destruct_col_cache(bool structure) ;
00987   void destruct_row_cache(bool structure) ;
00988   void destruct_cache(bool rowStructure, bool colStructure) ;
00989   void destruct_problem(bool preserve_interface) ;
00990   void detach_dylp() ;
00992 
00993 
00995 /*
00996   There are separate groups for member and static methods so that doxygen
00997   won't promote the group to the top level.
00998 */
01000   
01001   void add_col(const CoinPackedVectorBase& coin_coli,
01002                vartyp_enum vtypi, double vlbi,
01003                double vubi, double obji, const std::string *nme) ;
01004   void add_row(const CoinPackedVectorBase& coin_rowi, 
01005                char clazzi, contyp_enum ctypi,
01006                double rhsi, double rhslowi, const std::string *nme) ;
01007   void calc_objval() ;
01008   contyp_enum bound_to_type(double lower, double upper) ;
01009   void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi, 
01010                             char sensei, double rhsini, double rangei) ;
01011   void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi, 
01012                             double rowlbi, double rowubi) ;
01013   void unimp_hint(bool dylpSense, bool hintSense,
01014                  OsiHintStrength hintStrength, const char *msgString) ;
01015   void pessimal_primal() ;
01016 
01018 
01021   static contyp_enum sense_to_type(char type) ;
01022   static char type_to_sense(contyp_enum type) ;
01024 
01031   template<class T> static void copy(const T* src, T* dst, int n) ;
01032   template<class T> static T* copy(const T* src, int n) ;
01033   template<class T> static T* copy(const T* src) ;
01034 /*
01035   Specializations for more complicated structures.
01036 */
01037   static basis_struct* copy_basis(const basis_struct* src, int dstsze) ;
01038   static void copy_basis(const basis_struct* src, basis_struct* dst) ;
01039   static lpprob_struct* copy_lpprob(const lpprob_struct* src) ;
01041 
01042 #ifndef _MSC_VER
01043 
01048   template<class T> static void assert_same(const T& t1, const T& t2,
01049                                             bool exact) ;
01050   template<class T> static void assert_same(const T* t1, const T* t2,
01051                                             int n, bool exact) ;
01052 
01053   static void assert_same(double d1, double d2, bool exact) ;
01054 
01055   static void assert_same(const basis_struct& b1, 
01056                           const basis_struct& b2, bool exact) ;
01057   static void assert_same(const consys_struct& c1, const 
01058                           consys_struct& c2, bool exact) ;
01059   static void assert_same(const conbnd_struct& c1, const 
01060                           conbnd_struct& c2, bool exact) ;
01061   static void assert_same(const lpprob_struct& l1, 
01062                           const lpprob_struct& l2, bool exact) ;
01063   static void assert_same(const OsiDylpSolverInterface& o1, 
01064                           const OsiDylpSolverInterface& o2, bool exact) ;
01066 #endif  /* ! _MSC_VER */
01067 
01070   template<class T> static T* idx_vec(T* data) ;
01071   static int idx(int i) ;
01072   template<class T> static T* inv_vec(T* data) ;
01073   static int inv(int i) ;
01074 
01075   static pkvec_struct* packed_vector(
01076     const CoinShallowPackedVector vector, int dimension) ;
01077   static void packed_vector(
01078     const CoinShallowPackedVector vector, int dimension, pkvec_struct *dst) ;
01080 
01083   static std::string make_filename(const char *filename, 
01084                                    const char *ext1, const char *ext2) ;
01086 
01087 } ;
01088 
01089 
01090 /*
01091   OsiDylpSolverInterfaceTest.cpp
01092 */
01093 
01101 void OsiDylpSolverInterfaceUnitTest(const std::string & mpsDir,
01102                                     const std::string &netLibDir) ;
01103 
01104 #endif // OsiDylpSolverInterface_H

Generated on Fri May 16 00:16:56 2008 by  doxygen 1.4.7