lemon/glpk.h
changeset 947 0dba9b96550a
parent 650 a8dfe89b7719
child 833 d2bc45e8f6f2
equal deleted inserted replaced
9:0689e102bead 11:49f5eecb5cad
    23 ///\brief Header of the LEMON-GLPK lp solver interface.
    23 ///\brief Header of the LEMON-GLPK lp solver interface.
    24 ///\ingroup lp_group
    24 ///\ingroup lp_group
    25 
    25 
    26 #include <lemon/lp_base.h>
    26 #include <lemon/lp_base.h>
    27 
    27 
    28 // forward declaration
       
    29 #if !defined _GLP_PROB && !defined GLP_PROB
       
    30 #define _GLP_PROB
       
    31 #define GLP_PROB
       
    32 typedef struct { double _opaque_prob; } glp_prob;
       
    33 /* LP/MIP problem object */
       
    34 #endif
       
    35 
       
    36 namespace lemon {
    28 namespace lemon {
    37 
    29 
       
    30   namespace _solver_bits {
       
    31     class VoidPtr {
       
    32     private:
       
    33       void *_ptr;      
       
    34     public:
       
    35       VoidPtr() : _ptr(0) {}
       
    36 
       
    37       template <typename T>
       
    38       VoidPtr(T* ptr) : _ptr(reinterpret_cast<void*>(ptr)) {}
       
    39 
       
    40       template <typename T>
       
    41       VoidPtr& operator=(T* ptr) { 
       
    42         _ptr = reinterpret_cast<void*>(ptr); 
       
    43         return *this;
       
    44       }
       
    45 
       
    46       template <typename T>
       
    47       operator T*() const { return reinterpret_cast<T*>(_ptr); }
       
    48     };
       
    49   }
    38 
    50 
    39   /// \brief Base interface for the GLPK LP and MIP solver
    51   /// \brief Base interface for the GLPK LP and MIP solver
    40   ///
    52   ///
    41   /// This class implements the common interface of the GLPK LP and MIP solver.
    53   /// This class implements the common interface of the GLPK LP and MIP solver.
    42   /// \ingroup lp_group
    54   /// \ingroup lp_group
    43   class GlpkBase : virtual public LpBase {
    55   class GlpkBase : virtual public LpBase {
    44   protected:
    56   protected:
    45 
    57 
    46     typedef glp_prob LPX;
    58     _solver_bits::VoidPtr lp;
    47     glp_prob* lp;
       
    48 
    59 
    49     GlpkBase();
    60     GlpkBase();
    50     GlpkBase(const GlpkBase&);
    61     GlpkBase(const GlpkBase&);
    51     virtual ~GlpkBase();
    62     virtual ~GlpkBase();
    52 
    63 
   120     int _message_level;
   131     int _message_level;
   121     
   132     
   122   public:
   133   public:
   123 
   134 
   124     ///Pointer to the underlying GLPK data structure.
   135     ///Pointer to the underlying GLPK data structure.
   125     LPX *lpx() {return lp;}
   136     _solver_bits::VoidPtr lpx() {return lp;}
   126     ///Const pointer to the underlying GLPK data structure.
   137     ///Const pointer to the underlying GLPK data structure.
   127     const LPX *lpx() const {return lp;}
   138     _solver_bits::VoidPtr lpx() const {return lp;}
   128 
   139 
   129     ///Returns the constraint identifier understood by GLPK.
   140     ///Returns the constraint identifier understood by GLPK.
   130     int lpxRow(Row r) const { return rows(id(r)); }
   141     int lpxRow(Row r) const { return rows(id(r)); }
   131 
   142 
   132     ///Returns the variable identifier understood by GLPK.
   143     ///Returns the variable identifier understood by GLPK.