gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Merge bugfix #337
0 1 0
merge default
1 file changed with 23 insertions and 12 deletions:
↑ Collapse diff ↑
Ignore white space 24 line context
... ...
@@ -16,44 +16,55 @@
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_GLPK_H
20 20
#define LEMON_GLPK_H
21 21

	
22 22
///\file
23 23
///\brief Header of the LEMON-GLPK lp solver interface.
24 24
///\ingroup lp_group
25 25

	
26 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 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 51
  /// \brief Base interface for the GLPK LP and MIP solver
40 52
  ///
41 53
  /// This class implements the common interface of the GLPK LP and MIP solver.
42 54
  /// \ingroup lp_group
43 55
  class GlpkBase : virtual public LpBase {
44 56
  protected:
45 57

	
46
    typedef glp_prob LPX;
47
    glp_prob* lp;
58
    _solver_bits::VoidPtr lp;
48 59

	
49 60
    GlpkBase();
50 61
    GlpkBase(const GlpkBase&);
51 62
    virtual ~GlpkBase();
52 63

	
53 64
  protected:
54 65

	
55 66
    virtual int _addCol();
56 67
    virtual int _addRow();
57 68
    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
58 69

	
59 70
    virtual void _eraseCol(int i);
... ...
@@ -114,27 +125,27 @@
114 125
      }
115 126
    };
116 127
    
117 128
    static FreeEnvHelper freeEnvHelper;
118 129

	
119 130
  protected:
120 131
    
121 132
    int _message_level;
122 133
    
123 134
  public:
124 135

	
125 136
    ///Pointer to the underlying GLPK data structure.
126
    LPX *lpx() {return lp;}
137
    _solver_bits::VoidPtr lpx() {return lp;}
127 138
    ///Const pointer to the underlying GLPK data structure.
128
    const LPX *lpx() const {return lp;}
139
    _solver_bits::VoidPtr lpx() const {return lp;}
129 140

	
130 141
    ///Returns the constraint identifier understood by GLPK.
131 142
    int lpxRow(Row r) const { return rows(id(r)); }
132 143

	
133 144
    ///Returns the variable identifier understood by GLPK.
134 145
    int lpxCol(Col c) const { return cols(id(c)); }
135 146

	
136 147
  };
137 148

	
138 149
  /// \brief Interface for the GLPK LP solver
139 150
  ///
140 151
  /// This class implements an interface for the GLPK LP solver.
0 comments (0 inline)