| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 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 | 28 |
// forward declaration |
| 29 |
# |
|
| 29 |
#if !defined _GLP_PROB && !defined GLP_PROB |
|
| 30 | 30 |
#define _GLP_PROB |
| 31 |
|
|
| 31 |
#define GLP_PROB |
|
| 32 |
typedef struct { double _opaque_prob; } glp_prob;
|
|
| 32 | 33 |
/* LP/MIP problem object */ |
| 33 | 34 |
#endif |
| 34 | 35 |
|
| 35 | 36 |
namespace lemon {
|
| 36 | 37 |
|
| 37 | 38 |
|
| 38 | 39 |
/// \brief Base interface for the GLPK LP and MIP solver |
| 39 | 40 |
/// |
| 40 | 41 |
/// This class implements the common interface of the GLPK LP and MIP solver. |
| 41 | 42 |
/// \ingroup lp_group |
| 42 | 43 |
class GlpkBase : virtual public LpBase {
|
| 43 | 44 |
protected: |
| 44 | 45 |
|
| 45 | 46 |
typedef glp_prob LPX; |
| 46 | 47 |
glp_prob* lp; |
| 47 | 48 |
|
| 48 | 49 |
GlpkBase(); |
| 49 | 50 |
GlpkBase(const GlpkBase&); |
| 50 | 51 |
virtual ~GlpkBase(); |
| 51 | 52 |
|
| 52 | 53 |
protected: |
| 53 | 54 |
|
| 54 | 55 |
virtual int _addCol(); |
| 55 | 56 |
virtual int _addRow(); |
| 56 | 57 |
|
| 57 | 58 |
virtual void _eraseCol(int i); |
| 58 | 59 |
virtual void _eraseRow(int i); |
| 59 | 60 |
|
| 60 | 61 |
virtual void _eraseColId(int i); |
| 61 | 62 |
virtual void _eraseRowId(int i); |
| 62 | 63 |
|
| 63 | 64 |
virtual void _getColName(int col, std::string& name) const; |
| 64 | 65 |
virtual void _setColName(int col, const std::string& name); |
| 65 | 66 |
virtual int _colByName(const std::string& name) const; |
| 66 | 67 |
|
| 67 | 68 |
virtual void _getRowName(int row, std::string& name) const; |
| 68 | 69 |
virtual void _setRowName(int row, const std::string& name); |
| 69 | 70 |
virtual int _rowByName(const std::string& name) const; |
| 70 | 71 |
|
| 71 | 72 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 72 | 73 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 73 | 74 |
|
| 74 | 75 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 75 | 76 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 76 | 77 |
|
| 77 | 78 |
virtual void _setCoeff(int row, int col, Value value); |
| 78 | 79 |
virtual Value _getCoeff(int row, int col) const; |
| 79 | 80 |
|
| 80 | 81 |
virtual void _setColLowerBound(int i, Value value); |
| 81 | 82 |
virtual Value _getColLowerBound(int i) const; |
| 82 | 83 |
|
| 83 | 84 |
virtual void _setColUpperBound(int i, Value value); |
| 84 | 85 |
virtual Value _getColUpperBound(int i) const; |
| 85 | 86 |
|
| 86 | 87 |
virtual void _setRowLowerBound(int i, Value value); |
| 87 | 88 |
virtual Value _getRowLowerBound(int i) const; |
| 88 | 89 |
|
| 89 | 90 |
virtual void _setRowUpperBound(int i, Value value); |
| 90 | 91 |
virtual Value _getRowUpperBound(int i) const; |
| 91 | 92 |
|
| 92 | 93 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 93 | 94 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 94 | 95 |
|
| 95 | 96 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 96 | 97 |
virtual Value _getObjCoeff(int i) const; |
| 97 | 98 |
|
| 98 | 99 |
virtual void _setSense(Sense); |
| 99 | 100 |
virtual Sense _getSense() const; |
| 100 | 101 |
|
| 101 | 102 |
virtual void _clear(); |
| 102 | 103 |
|
| 103 | 104 |
virtual void _messageLevel(MessageLevel level); |
| 104 | 105 |
|
| 105 | 106 |
private: |
| 106 | 107 |
|
| 107 | 108 |
static void freeEnv(); |
| 108 | 109 |
|
| 109 | 110 |
struct FreeEnvHelper {
|
| 110 | 111 |
~FreeEnvHelper() {
|
| 111 | 112 |
freeEnv(); |
| 112 | 113 |
} |
| 113 | 114 |
}; |
| 114 | 115 |
|
| 115 | 116 |
static FreeEnvHelper freeEnvHelper; |
| 116 | 117 |
|
| 117 | 118 |
protected: |
| 118 | 119 |
|
| 119 | 120 |
int _message_level; |
| 120 | 121 |
|
| 121 | 122 |
public: |
| 122 | 123 |
|
| 123 | 124 |
///Pointer to the underlying GLPK data structure. |
| 124 | 125 |
LPX *lpx() {return lp;}
|
| 125 | 126 |
///Const pointer to the underlying GLPK data structure. |
| 126 | 127 |
const LPX *lpx() const {return lp;}
|
| 127 | 128 |
|
0 comments (0 inline)