1 | /* -*- C++ -*- |
---|
2 | * |
---|
3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
4 | * |
---|
5 | * Copyright (C) 2003-2008 |
---|
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
8 | * |
---|
9 | * Permission to use, modify and distribute this software is granted |
---|
10 | * provided that this copyright notice appears in all copies. For |
---|
11 | * precise terms see the accompanying LICENSE file. |
---|
12 | * |
---|
13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
14 | * express or implied, and with no claim as to its suitability for any |
---|
15 | * purpose. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef LEMON_LP_GLPK_H |
---|
20 | #define LEMON_LP_GLPK_H |
---|
21 | |
---|
22 | ///\file |
---|
23 | ///\brief Header of the LEMON-GLPK lp solver interface. |
---|
24 | ///\ingroup lp_group |
---|
25 | |
---|
26 | #include <lemon/lp_base.h> |
---|
27 | extern "C" { |
---|
28 | #include <glpk.h> |
---|
29 | } |
---|
30 | |
---|
31 | namespace lemon { |
---|
32 | |
---|
33 | |
---|
34 | /// \brief Interface for the GLPK LP solver |
---|
35 | /// |
---|
36 | /// This class implements an interface for the GLPK LP solver. |
---|
37 | ///\ingroup lp_group |
---|
38 | class LpGlpk : virtual public LpSolverBase { |
---|
39 | protected: |
---|
40 | LPX* lp; |
---|
41 | bool solved; |
---|
42 | |
---|
43 | public: |
---|
44 | |
---|
45 | typedef LpSolverBase Parent; |
---|
46 | |
---|
47 | LpGlpk(); |
---|
48 | LpGlpk(const LpGlpk &); |
---|
49 | ~LpGlpk(); |
---|
50 | |
---|
51 | protected: |
---|
52 | virtual LpSolverBase &_newLp(); |
---|
53 | virtual LpSolverBase &_copyLp(); |
---|
54 | |
---|
55 | virtual int _addCol(); |
---|
56 | virtual int _addRow(); |
---|
57 | virtual void _eraseCol(int i); |
---|
58 | virtual void _eraseRow(int i); |
---|
59 | virtual void _getColName(int col, std::string & name) const; |
---|
60 | virtual void _setColName(int col, const std::string & name); |
---|
61 | virtual int _colByName(const std::string& name) const; |
---|
62 | virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e); |
---|
63 | virtual void _getRowCoeffs(int i, RowIterator b) const; |
---|
64 | virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e); |
---|
65 | virtual void _getColCoeffs(int i, ColIterator b) const; |
---|
66 | virtual void _setCoeff(int row, int col, Value value); |
---|
67 | virtual Value _getCoeff(int row, int col) const; |
---|
68 | |
---|
69 | virtual void _setColLowerBound(int i, Value value); |
---|
70 | virtual Value _getColLowerBound(int i) const; |
---|
71 | virtual void _setColUpperBound(int i, Value value); |
---|
72 | virtual Value _getColUpperBound(int i) const; |
---|
73 | |
---|
74 | virtual void _setRowBounds(int i, Value lower, Value upper); |
---|
75 | virtual void _getRowBounds(int i, Value &lb, Value &ub) const; |
---|
76 | virtual void _setObjCoeff(int i, Value obj_coef); |
---|
77 | virtual Value _getObjCoeff(int i) const; |
---|
78 | virtual void _clearObj(); |
---|
79 | |
---|
80 | ///\e |
---|
81 | |
---|
82 | ///\todo It should be clarified |
---|
83 | /// |
---|
84 | virtual SolveExitStatus _solve(); |
---|
85 | virtual Value _getPrimal(int i) const; |
---|
86 | virtual Value _getDual(int i) const; |
---|
87 | virtual Value _getPrimalValue() const; |
---|
88 | virtual bool _isBasicCol(int i) const; |
---|
89 | ///\e |
---|
90 | |
---|
91 | ///\todo It should be clarified |
---|
92 | /// |
---|
93 | virtual SolutionStatus _getPrimalStatus() const; |
---|
94 | virtual SolutionStatus _getDualStatus() const; |
---|
95 | virtual ProblemTypes _getProblemType() const; |
---|
96 | |
---|
97 | virtual void _setMax(); |
---|
98 | virtual void _setMin(); |
---|
99 | |
---|
100 | virtual bool _isMax() const; |
---|
101 | |
---|
102 | public: |
---|
103 | ///Set the verbosity of the messages |
---|
104 | |
---|
105 | ///Set the verbosity of the messages |
---|
106 | /// |
---|
107 | ///\param m is the level of the messages output by the solver routines. |
---|
108 | ///The possible values are: |
---|
109 | ///- 0 --- no output (default value) |
---|
110 | ///- 1 --- error messages only |
---|
111 | ///- 2 --- normal output |
---|
112 | ///- 3 --- full output (includes informational messages) |
---|
113 | void messageLevel(int m); |
---|
114 | ///Turns on or off the presolver |
---|
115 | |
---|
116 | ///Turns on (\c b is \c true) or off (\c b is \c false) the presolver |
---|
117 | /// |
---|
118 | ///The presolver is off by default. |
---|
119 | void presolver(bool b); |
---|
120 | |
---|
121 | LPX *lpx() {return lp;} |
---|
122 | }; |
---|
123 | } //END OF NAMESPACE LEMON |
---|
124 | |
---|
125 | #endif //LEMON_LP_GLPK_H |
---|
126 | |
---|