diff --git a/lemon/glpk.h b/lemon/glpk.h --- a/lemon/glpk.h +++ b/lemon/glpk.h @@ -26,9 +26,10 @@ #include // forward declaration -#ifndef _GLP_PROB +#if !defined _GLP_PROB && !defined GLP_PROB #define _GLP_PROB -typedef struct { double _prob; } glp_prob; +#define GLP_PROB +typedef struct { double _opaque_prob; } glp_prob; /* LP/MIP problem object */ #endif @@ -53,6 +54,7 @@ virtual int _addCol(); virtual int _addRow(); + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); virtual void _eraseCol(int i); virtual void _eraseRow(int i); @@ -100,6 +102,24 @@ virtual void _clear(); + virtual void _messageLevel(MessageLevel level); + + private: + + static void freeEnv(); + + struct FreeEnvHelper { + ~FreeEnvHelper() { + freeEnv(); + } + }; + + static FreeEnvHelper freeEnvHelper; + + protected: + + int _message_level; + public: ///Pointer to the underlying GLPK data structure. @@ -119,7 +139,7 @@ /// /// This class implements an interface for the GLPK LP solver. ///\ingroup lp_group - class GlpkLp : public GlpkBase, public LpSolver { + class GlpkLp : public LpSolver, public GlpkBase { public: ///\e @@ -127,6 +147,11 @@ ///\e GlpkLp(const GlpkLp&); + ///\e + virtual GlpkLp* cloneSolver() const; + ///\e + virtual GlpkLp* newSolver() const; + private: mutable std::vector _primal_ray; @@ -136,9 +161,6 @@ protected: - virtual GlpkLp* _cloneSolver() const; - virtual GlpkLp* _newSolver() const; - virtual const char* _solverName() const; virtual SolveExitStatus _solve(); @@ -153,8 +175,6 @@ virtual Value _getPrimalRay(int i) const; virtual Value _getDualRay(int i) const; - ///\todo It should be clarified - /// virtual ProblemType _getPrimalType() const; virtual ProblemType _getDualType() const; @@ -166,44 +186,26 @@ ///Solve with dual simplex SolveExitStatus solveDual(); + private: + + bool _presolve; + + public: + ///Turns on or off the presolver ///Turns on (\c b is \c true) or off (\c b is \c false) the presolver /// ///The presolver is off by default. - void presolver(bool b); + void presolver(bool presolve); - ///Enum for \c messageLevel() parameter - enum MessageLevel { - /// no output (default value) - MESSAGE_NO_OUTPUT = 0, - /// error messages only - MESSAGE_ERROR_MESSAGE = 1, - /// normal output - MESSAGE_NORMAL_OUTPUT = 2, - /// full output (includes informational messages) - MESSAGE_FULL_OUTPUT = 3 - }; - - private: - - MessageLevel _message_level; - - public: - - ///Set the verbosity of the messages - - ///Set the verbosity of the messages - /// - ///\param m is the level of the messages output by the solver routines. - void messageLevel(MessageLevel m); }; /// \brief Interface for the GLPK MIP solver /// /// This class implements an interface for the GLPK MIP solver. ///\ingroup lp_group - class GlpkMip : public GlpkBase, public MipSolver { + class GlpkMip : public MipSolver, public GlpkBase { public: ///\e @@ -211,11 +213,11 @@ ///\e GlpkMip(const GlpkMip&); + virtual GlpkMip* cloneSolver() const; + virtual GlpkMip* newSolver() const; + protected: - virtual GlpkMip* _cloneSolver() const; - virtual GlpkMip* _newSolver() const; - virtual const char* _solverName() const; virtual ColTypes _getColType(int col) const; @@ -226,30 +228,6 @@ virtual Value _getSol(int i) const; virtual Value _getSolValue() const; - ///Enum for \c messageLevel() parameter - enum MessageLevel { - /// no output (default value) - MESSAGE_NO_OUTPUT = 0, - /// error messages only - MESSAGE_ERROR_MESSAGE = 1, - /// normal output - MESSAGE_NORMAL_OUTPUT = 2, - /// full output (includes informational messages) - MESSAGE_FULL_OUTPUT = 3 - }; - - private: - - MessageLevel _message_level; - - public: - - ///Set the verbosity of the messages - - ///Set the verbosity of the messages - /// - ///\param m is the level of the messages output by the solver routines. - void messageLevel(MessageLevel m); };