/home/coin/SVN-release/CoinAll-1.1.0/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 1204 2008-03-28 17:31:52Z lou $
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 int 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 
00426   bool setWarmStart(const CoinWarmStart *warmStart) ;
00427 
00430   void resolve() ;
00431 
00434   void markHotStart() ;
00435 
00438   void solveFromHotStart() ;
00439 
00442   void unmarkHotStart() ;
00443 
00445 
00448 
00451   bool isAbandoned() const ;
00452 
00455   bool isProvenOptimal() const ;
00456 
00459   bool isProvenPrimalInfeasible() const ;
00460 
00464   bool isProvenDualInfeasible() const ;
00465 
00468   bool isIterationLimitReached() const ;
00469 
00472   int getIterationCount() const ;
00473 
00479   bool isPrimalObjectiveLimitReached() const ;
00480 
00486   bool isDualObjectiveLimitReached() const ;
00488 
00489 
00492 
00495   double getInfinity() const ;
00496 
00499   bool setIntParam(OsiIntParam key, int value) ;
00500 
00503   bool setDblParam(OsiDblParam key, double value) ;
00504 
00507   bool setStrParam(OsiStrParam key, const std::string& value) ;
00508 
00511   bool setHintParam(OsiHintParam key, bool sense = true,
00512                     OsiHintStrength strength = OsiHintTry, void *info = 0) ;
00513 
00516   bool getIntParam(OsiIntParam key, int &value) const ;
00517 
00520   bool getDblParam(OsiDblParam key, double &value) const ;
00521 
00524   bool getStrParam(OsiStrParam key, std::string &value) const ;
00525 
00526   /* For overload resolution with OSI::getHintParam functions. */
00527 
00528   using OsiSolverInterface::getHintParam ;
00529 
00532   bool getHintParam(OsiHintParam key, bool &sense,
00533                     OsiHintStrength &strength, void *&info) const ;
00534 
00537   inline void newLanguage(CoinMessages::Language language)
00538   { setOsiDylpMessages(language) ; }
00539 
00542   inline void setLanguage(CoinMessages::Language language)
00543   { setOsiDylpMessages(language) ; }
00544 
00546 
00549 
00552   const double* getColSolution() const ; 
00553 
00556   const double* getRowPrice() const ;
00557 
00560   const double* getReducedCost() const ;
00561 
00564   const double* getRowActivity() const ;
00565 
00568   double getObjValue() const ;
00569 
00571 
00578 
00581   void setObjName (std::string name) ;
00582 
00588   void setRowName(int ndx, std::string name) ;
00589 
00595   void setColName(int ndx, std::string name) ;
00596 
00598 
00601 
00608   void activateRowCutDebugger (const char * modelName) ;
00609 
00617   void activateRowCutDebugger (const double *solution) ;
00618 
00619 # if ODSI_PARANOIA >= 1
00620 
00629   void indexCheck (int k, bool isCol, std::string rtnnme) ;
00630 # endif
00631 
00633 
00636 
00639   void dylp_controlfile(const char* name, const bool silent,
00640                         const bool mustexist = true) ;
00641 
00644   void dylp_logfile(const char* name, bool echo = false) ;
00645 
00648   void dylp_outfile(const char* name) ;
00649 
00652   void dylp_printsoln(bool wantSoln, bool wantStats) ;
00653 
00656   void setOsiDylpMessages(CoinMessages::Language local_language) ;
00657 
00659 
00662 
00663 
00666   void branchAndBound() ;
00667 
00670   std::vector<double *> getDualRays(int) const ;
00671 
00674   std::vector<double *> getPrimalRays(int) const ;
00676 
00681 /*
00682   Leave them visible to the public for the nonce, until a better programmatic
00683   interface is available. Initialized by the constructor.
00684 */
00686 
00687   lpopts_struct *initialSolveOptions,*resolveOptions ;
00688   lptols_struct* tolerances ;
00689 
00691 
00692 private:
00693 
00694 /*
00695   Private implementation state and helper functions. If you're contemplating
00696   using any of these, you should have a look at the code.
00697   See OsiDylpSolverInterface.cpp for descriptions.
00698 */ 
00705 
00706   consys_struct* consys ;
00707   lpprob_struct* lpprob ;
00708   lpstats_struct* statistics ;
00709 
00711 
00714 
00715   static int reference_count ;
00716   static bool basis_ready ;
00717   static OsiDylpSolverInterface *dylp_owner ;
00718 
00720 
00721 
00727 
00734   ioid local_outchn ;
00735 
00741   ioid local_logchn ;
00742 
00747   bool initial_gtxecho ;
00748 
00753   bool resolve_gtxecho ;
00754 
00764   lpret_enum lp_retval ;
00765 
00771   double obj_sense ;
00772 
00775   double odsiInfinity ;
00776 
00779   const std::string solvername ;
00780 
00783   mutable void *info_[OsiLastHintParam] ;
00784 
00787   bool mps_debug ;
00788 
00796   CoinWarmStart *hotstart_fallback ;
00797 
00818   enum basisCondition
00819   { basisNone = 0, basisFresh, basisModified, basisDamaged } ;
00820 
00838   struct
00839   { CoinWarmStart *basis ;
00840     basisCondition condition ;
00841     int balance ; } activeBasis ;
00842 
00848   bool solnIsFresh ;
00849 
00851 
00852 
00853 
00860 
00861   mutable double _objval ;
00862   mutable double* _col_obj ;
00863   mutable double* _col_x ;
00864   mutable double* _col_cbar ;
00865 
00866   mutable double* _row_rhs ;
00867   mutable double* _row_lower ;
00868   mutable double* _row_upper ;
00869   mutable char* _row_sense ;
00870   mutable double* _row_range ;
00871   mutable double* _row_lhs ;
00872   mutable double* _row_price ;
00873 
00874   mutable CoinPackedMatrix* _matrix_by_col ;
00875   mutable CoinPackedMatrix* _matrix_by_row ;
00876 
00878 
00885 
00891   CoinPresolveMatrix *preObj_ ;
00892 
00899   const CoinPresolveAction *postActions_ ;
00900 
00908   CoinPostsolveMatrix *postObj_ ;
00909 
00911   int passLimit_ ;
00912 
00914   bool keepIntegers_ ;
00915 
00917   consys_struct *savedConsys_ ;
00918 
00920   mutable double* saved_col_obj ;
00921   mutable double* saved_row_rhs ;
00922   mutable double* saved_row_lower ;
00923   mutable double* saved_row_upper ;
00924   mutable char* saved_row_sense ;
00925   mutable double* saved_row_range ;
00926   mutable CoinPackedMatrix* saved_matrix_by_col ;
00927   mutable CoinPackedMatrix* saved_matrix_by_row ;
00928 
00930 
00940 
00941   CoinPresolveMatrix *initialisePresolve(bool keepIntegers) ;
00942 
00944   void doPresolve() ;
00945 
00947   bool evalPresolve() ;
00948 
00950   void saveOriginalSys() ;
00951 
00953   void installPresolve() ;
00954 
00956   CoinPostsolveMatrix *initialisePostsolve(CoinPresolveMatrix *&preObj) ;
00957 
00959   void doPostsolve() ;
00960 
00962   void installPostsolve() ;
00963 
00965   void destruct_presolve() ;
00966 
00968 
00972   void construct_lpprob() ;
00973   void construct_options() ;
00974   void construct_consys(int cols, int rows) ;
00975   void dylp_ioinit() ;
00976   void gen_rowparms(int rowcnt,
00977                     double *rhs, double *rhslow, contyp_enum *ctyp,
00978                     const double *rowlb, const double *rowub) ;
00979   void gen_rowparms(int rowcnt,
00980                double *rhs, double *rhslow, contyp_enum *ctyp,
00981                const char *sense, const double *rhsin, const double *range) ;
00982   void load_problem(const CoinMpsIO &mps) ;
00983   void load_problem(const CoinPackedMatrix &matrix,
00984          const double* col_lower, const double* col_upper, const double* obj,
00985          const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00986   void load_problem (const int colcnt, const int rowcnt,
00987          const int *start, const int *lens,
00988          const int *index, const double *value,
00989          const double* col_lower, const double* col_upper, const double* obj,
00990          const contyp_enum *ctyp, const double* rhs, const double* rhslow) ;
00992 
00996   lpret_enum do_lp (ODSI_start_enum start) ;
00998 
01001   void destruct_col_cache(bool structure) ;
01002   void destruct_row_cache(bool structure) ;
01003   void destruct_cache(bool rowStructure, bool colStructure) ;
01004   void destruct_problem(bool preserve_interface) ;
01005   void detach_dylp() ;
01007 
01008 
01010 /*
01011   There are separate groups for member and static methods so that doxygen
01012   won't promote the group to the top level.
01013 */
01015   
01016   void add_col(const CoinPackedVectorBase& coin_coli,
01017                vartyp_enum vtypi, double vlbi,
01018                double vubi, double obji, const std::string *nme) ;
01019   void add_row(const CoinPackedVectorBase& coin_rowi, 
01020                char clazzi, contyp_enum ctypi,
01021                double rhsi, double rhslowi, const std::string *nme) ;
01022   void calc_objval() ;
01023   contyp_enum bound_to_type(double lower, double upper) ;
01024   void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi, 
01025                             char sensei, double rhsini, double rangei) ;
01026   void gen_rowiparms(contyp_enum* ctypi, double* rhsi, double* rhslowi, 
01027                             double rowlbi, double rowubi) ;
01028   void unimp_hint(bool dylpSense, bool hintSense,
01029                  OsiHintStrength hintStrength, const char *msgString) ;
01030   void pessimal_primal() ;
01031   void reduceActiveBasis() ;
01032 
01034 
01037   static contyp_enum sense_to_type(char type) ;
01038   static char type_to_sense(contyp_enum type) ;
01040 
01047   template<class T> static void copy(const T* src, T* dst, int n) ;
01048   template<class T> static T* copy(const T* src, int n) ;
01049   template<class T> static T* copy(const T* src) ;
01050 /*
01051   Specializations for more complicated structures.
01052 */
01053   static basis_struct* copy_basis(const basis_struct* src, int dstsze) ;
01054   static void copy_basis(const basis_struct* src, basis_struct* dst) ;
01055   static lpprob_struct* copy_lpprob(const lpprob_struct* src) ;
01057 
01058 #ifndef _MSC_VER
01059 
01064   template<class T> static void assert_same(const T& t1, const T& t2,
01065                                             bool exact) ;
01066   template<class T> static void assert_same(const T* t1, const T* t2,
01067                                             int n, bool exact) ;
01068 
01069   static void assert_same(double d1, double d2, bool exact) ;
01070 
01071   static void assert_same(const basis_struct& b1, 
01072                           const basis_struct& b2, bool exact) ;
01073   static void assert_same(const consys_struct& c1, const 
01074                           consys_struct& c2, bool exact) ;
01075   static void assert_same(const conbnd_struct& c1, const 
01076                           conbnd_struct& c2, bool exact) ;
01077   static void assert_same(const lpprob_struct& l1, 
01078                           const lpprob_struct& l2, bool exact) ;
01079   static void assert_same(const OsiDylpSolverInterface& o1, 
01080                           const OsiDylpSolverInterface& o2, bool exact) ;
01082 #endif  /* ! _MSC_VER */
01083 
01086   template<class T> static T* idx_vec(T* data) ;
01087   static int idx(int i) ;
01088   template<class T> static T* inv_vec(T* data) ;
01089   static int inv(int i) ;
01090 
01091   static pkvec_struct* packed_vector(
01092     const CoinShallowPackedVector vector, int dimension) ;
01093   static void packed_vector(
01094     const CoinShallowPackedVector vector, int dimension, pkvec_struct *dst) ;
01096 
01099   static std::string make_filename(const char *filename, 
01100                                    const char *ext1, const char *ext2) ;
01102 
01103 } ;
01104 
01105 
01106 /*
01107   OsiDylpSolverInterfaceTest.cpp
01108 */
01109 
01117 int OsiDylpSolverInterfaceUnitTest(const std::string & mpsDir,
01118                                     const std::string &netLibDir) ;
01119 
01120 #endif // OsiDylpSolverInterface_H

Generated on Sun Nov 14 14:06:40 2010 for Coin-All by  doxygen 1.4.7