deba@458
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@458
|
2 |
*
|
deba@458
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@458
|
4 |
*
|
deba@458
|
5 |
* Copyright (C) 2003-2008
|
deba@458
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@458
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@458
|
8 |
*
|
deba@458
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@458
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@458
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@458
|
12 |
*
|
deba@458
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@458
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@458
|
15 |
* purpose.
|
deba@458
|
16 |
*
|
deba@458
|
17 |
*/
|
deba@458
|
18 |
|
deba@458
|
19 |
#ifndef LEMON_LP_GLPK_H
|
deba@458
|
20 |
#define LEMON_LP_GLPK_H
|
deba@458
|
21 |
|
deba@458
|
22 |
///\file
|
deba@458
|
23 |
///\brief Header of the LEMON-GLPK lp solver interface.
|
deba@458
|
24 |
///\ingroup lp_group
|
deba@458
|
25 |
|
deba@458
|
26 |
#include <lemon/lp_base.h>
|
deba@458
|
27 |
|
deba@458
|
28 |
// forward declaration
|
deba@458
|
29 |
#ifndef _GLP_PROB
|
deba@458
|
30 |
#define _GLP_PROB
|
deba@458
|
31 |
typedef struct { double _prob; } glp_prob;
|
deba@458
|
32 |
/* LP/MIP problem object */
|
deba@458
|
33 |
#endif
|
deba@458
|
34 |
|
deba@458
|
35 |
namespace lemon {
|
deba@458
|
36 |
|
deba@458
|
37 |
|
deba@459
|
38 |
/// \brief Base interface for the GLPK LP and MIP solver
|
deba@458
|
39 |
///
|
deba@459
|
40 |
/// This class implements the common interface of the GLPK LP and MIP solver.
|
deba@459
|
41 |
/// \ingroup lp_group
|
deba@459
|
42 |
class GlpkBase : virtual public LpBase {
|
deba@458
|
43 |
protected:
|
deba@458
|
44 |
|
deba@458
|
45 |
typedef glp_prob LPX;
|
deba@458
|
46 |
glp_prob* lp;
|
deba@458
|
47 |
|
deba@459
|
48 |
GlpkBase();
|
deba@459
|
49 |
GlpkBase(const GlpkBase&);
|
deba@459
|
50 |
virtual ~GlpkBase();
|
deba@458
|
51 |
|
deba@458
|
52 |
protected:
|
deba@458
|
53 |
|
deba@458
|
54 |
virtual int _addCol();
|
deba@458
|
55 |
virtual int _addRow();
|
deba@459
|
56 |
|
deba@458
|
57 |
virtual void _eraseCol(int i);
|
deba@458
|
58 |
virtual void _eraseRow(int i);
|
deba@459
|
59 |
|
deba@459
|
60 |
virtual void _eraseColId(int i);
|
deba@459
|
61 |
virtual void _eraseRowId(int i);
|
deba@459
|
62 |
|
deba@459
|
63 |
virtual void _getColName(int col, std::string& name) const;
|
deba@459
|
64 |
virtual void _setColName(int col, const std::string& name);
|
deba@458
|
65 |
virtual int _colByName(const std::string& name) const;
|
deba@459
|
66 |
|
deba@459
|
67 |
virtual void _getRowName(int row, std::string& name) const;
|
deba@459
|
68 |
virtual void _setRowName(int row, const std::string& name);
|
deba@459
|
69 |
virtual int _rowByName(const std::string& name) const;
|
deba@459
|
70 |
|
deba@459
|
71 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
|
deba@459
|
72 |
virtual void _getRowCoeffs(int i, InsertIterator b) const;
|
deba@459
|
73 |
|
deba@459
|
74 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
|
deba@459
|
75 |
virtual void _getColCoeffs(int i, InsertIterator b) const;
|
deba@459
|
76 |
|
deba@458
|
77 |
virtual void _setCoeff(int row, int col, Value value);
|
deba@458
|
78 |
virtual Value _getCoeff(int row, int col) const;
|
deba@458
|
79 |
|
deba@458
|
80 |
virtual void _setColLowerBound(int i, Value value);
|
deba@458
|
81 |
virtual Value _getColLowerBound(int i) const;
|
deba@459
|
82 |
|
deba@458
|
83 |
virtual void _setColUpperBound(int i, Value value);
|
deba@458
|
84 |
virtual Value _getColUpperBound(int i) const;
|
deba@458
|
85 |
|
deba@459
|
86 |
virtual void _setRowLowerBound(int i, Value value);
|
deba@459
|
87 |
virtual Value _getRowLowerBound(int i) const;
|
deba@459
|
88 |
|
deba@459
|
89 |
virtual void _setRowUpperBound(int i, Value value);
|
deba@459
|
90 |
virtual Value _getRowUpperBound(int i) const;
|
deba@459
|
91 |
|
deba@459
|
92 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
|
deba@459
|
93 |
virtual void _getObjCoeffs(InsertIterator b) const;
|
deba@459
|
94 |
|
deba@458
|
95 |
virtual void _setObjCoeff(int i, Value obj_coef);
|
deba@458
|
96 |
virtual Value _getObjCoeff(int i) const;
|
deba@459
|
97 |
|
deba@459
|
98 |
virtual void _setSense(Sense);
|
deba@459
|
99 |
virtual Sense _getSense() const;
|
deba@459
|
100 |
|
deba@459
|
101 |
virtual void _clear();
|
deba@459
|
102 |
|
deba@459
|
103 |
public:
|
deba@459
|
104 |
|
deba@459
|
105 |
///Pointer to the underlying GLPK data structure.
|
deba@459
|
106 |
LPX *lpx() {return lp;}
|
deba@459
|
107 |
///Const pointer to the underlying GLPK data structure.
|
deba@459
|
108 |
const LPX *lpx() const {return lp;}
|
deba@459
|
109 |
|
deba@459
|
110 |
///Returns the constraint identifier understood by GLPK.
|
deba@459
|
111 |
int lpxRow(Row r) const { return rows(id(r)); }
|
deba@459
|
112 |
|
deba@459
|
113 |
///Returns the variable identifier understood by GLPK.
|
deba@459
|
114 |
int lpxCol(Col c) const { return cols(id(c)); }
|
deba@459
|
115 |
|
deba@459
|
116 |
};
|
deba@459
|
117 |
|
deba@459
|
118 |
/// \brief Interface for the GLPK LP solver
|
deba@459
|
119 |
///
|
deba@459
|
120 |
/// This class implements an interface for the GLPK LP solver.
|
deba@459
|
121 |
///\ingroup lp_group
|
deba@459
|
122 |
class LpGlpk : public GlpkBase, public LpSolver {
|
deba@459
|
123 |
public:
|
deba@458
|
124 |
|
deba@458
|
125 |
///\e
|
deba@459
|
126 |
LpGlpk();
|
deba@459
|
127 |
///\e
|
deba@459
|
128 |
LpGlpk(const LpGlpk&);
|
deba@459
|
129 |
|
deba@459
|
130 |
private:
|
deba@459
|
131 |
|
deba@459
|
132 |
mutable std::vector<double> _primal_ray;
|
deba@459
|
133 |
mutable std::vector<double> _dual_ray;
|
deba@459
|
134 |
|
deba@459
|
135 |
void _clear_temporals();
|
deba@459
|
136 |
|
deba@459
|
137 |
protected:
|
deba@459
|
138 |
|
deba@459
|
139 |
virtual LpGlpk* _cloneSolver() const;
|
deba@459
|
140 |
virtual LpGlpk* _newSolver() const;
|
deba@459
|
141 |
|
deba@459
|
142 |
virtual const char* _solverName() const;
|
deba@459
|
143 |
|
deba@459
|
144 |
virtual SolveExitStatus _solve();
|
deba@459
|
145 |
virtual Value _getPrimal(int i) const;
|
deba@459
|
146 |
virtual Value _getDual(int i) const;
|
deba@459
|
147 |
|
deba@459
|
148 |
virtual Value _getPrimalValue() const;
|
deba@459
|
149 |
|
deba@459
|
150 |
virtual VarStatus _getColStatus(int i) const;
|
deba@459
|
151 |
virtual VarStatus _getRowStatus(int i) const;
|
deba@459
|
152 |
|
deba@459
|
153 |
virtual Value _getPrimalRay(int i) const;
|
deba@459
|
154 |
virtual Value _getDualRay(int i) const;
|
deba@458
|
155 |
|
deba@458
|
156 |
///\todo It should be clarified
|
deba@458
|
157 |
///
|
deba@459
|
158 |
virtual ProblemType _getPrimalType() const;
|
deba@459
|
159 |
virtual ProblemType _getDualType() const;
|
deba@458
|
160 |
|
deba@458
|
161 |
public:
|
deba@458
|
162 |
|
deba@459
|
163 |
///Solve with primal simplex
|
deba@459
|
164 |
SolveExitStatus solvePrimal();
|
deba@459
|
165 |
|
deba@459
|
166 |
///Solve with dual simplex
|
deba@459
|
167 |
SolveExitStatus solveDual();
|
deba@459
|
168 |
|
deba@458
|
169 |
///Turns on or off the presolver
|
deba@458
|
170 |
|
deba@458
|
171 |
///Turns on (\c b is \c true) or off (\c b is \c false) the presolver
|
deba@458
|
172 |
///
|
deba@458
|
173 |
///The presolver is off by default.
|
deba@458
|
174 |
void presolver(bool b);
|
deba@458
|
175 |
|
deba@459
|
176 |
///Enum for \c messageLevel() parameter
|
deba@459
|
177 |
enum MessageLevel {
|
deba@459
|
178 |
/// no output (default value)
|
deba@459
|
179 |
MESSAGE_NO_OUTPUT = 0,
|
deba@459
|
180 |
/// error messages only
|
deba@459
|
181 |
MESSAGE_ERROR_MESSAGE = 1,
|
deba@459
|
182 |
/// normal output
|
deba@459
|
183 |
MESSAGE_NORMAL_OUTPUT = 2,
|
deba@459
|
184 |
/// full output (includes informational messages)
|
deba@459
|
185 |
MESSAGE_FULL_OUTPUT = 3
|
deba@459
|
186 |
};
|
deba@458
|
187 |
|
deba@459
|
188 |
private:
|
deba@458
|
189 |
|
deba@459
|
190 |
MessageLevel _message_level;
|
deba@459
|
191 |
|
deba@459
|
192 |
public:
|
deba@459
|
193 |
|
deba@459
|
194 |
///Set the verbosity of the messages
|
deba@459
|
195 |
|
deba@459
|
196 |
///Set the verbosity of the messages
|
deba@459
|
197 |
///
|
deba@459
|
198 |
///\param m is the level of the messages output by the solver routines.
|
deba@459
|
199 |
void messageLevel(MessageLevel m);
|
deba@458
|
200 |
};
|
deba@459
|
201 |
|
deba@459
|
202 |
/// \brief Interface for the GLPK MIP solver
|
deba@459
|
203 |
///
|
deba@459
|
204 |
/// This class implements an interface for the GLPK MIP solver.
|
deba@459
|
205 |
///\ingroup lp_group
|
deba@459
|
206 |
class MipGlpk : public GlpkBase, public MipSolver {
|
deba@459
|
207 |
public:
|
deba@459
|
208 |
|
deba@459
|
209 |
///\e
|
deba@459
|
210 |
MipGlpk();
|
deba@459
|
211 |
///\e
|
deba@459
|
212 |
MipGlpk(const MipGlpk&);
|
deba@459
|
213 |
|
deba@459
|
214 |
protected:
|
deba@459
|
215 |
|
deba@459
|
216 |
virtual MipGlpk* _cloneSolver() const;
|
deba@459
|
217 |
virtual MipGlpk* _newSolver() const;
|
deba@459
|
218 |
|
deba@459
|
219 |
virtual const char* _solverName() const;
|
deba@459
|
220 |
|
deba@459
|
221 |
virtual ColTypes _getColType(int col) const;
|
deba@459
|
222 |
virtual void _setColType(int col, ColTypes col_type);
|
deba@459
|
223 |
|
deba@459
|
224 |
virtual SolveExitStatus _solve();
|
deba@459
|
225 |
virtual ProblemType _getType() const;
|
deba@459
|
226 |
virtual Value _getSol(int i) const;
|
deba@459
|
227 |
virtual Value _getSolValue() const;
|
deba@459
|
228 |
|
deba@459
|
229 |
///Enum for \c messageLevel() parameter
|
deba@459
|
230 |
enum MessageLevel {
|
deba@459
|
231 |
/// no output (default value)
|
deba@459
|
232 |
MESSAGE_NO_OUTPUT = 0,
|
deba@459
|
233 |
/// error messages only
|
deba@459
|
234 |
MESSAGE_ERROR_MESSAGE = 1,
|
deba@459
|
235 |
/// normal output
|
deba@459
|
236 |
MESSAGE_NORMAL_OUTPUT = 2,
|
deba@459
|
237 |
/// full output (includes informational messages)
|
deba@459
|
238 |
MESSAGE_FULL_OUTPUT = 3
|
deba@459
|
239 |
};
|
deba@459
|
240 |
|
deba@459
|
241 |
private:
|
deba@459
|
242 |
|
deba@459
|
243 |
MessageLevel _message_level;
|
deba@459
|
244 |
|
deba@459
|
245 |
public:
|
deba@459
|
246 |
|
deba@459
|
247 |
///Set the verbosity of the messages
|
deba@459
|
248 |
|
deba@459
|
249 |
///Set the verbosity of the messages
|
deba@459
|
250 |
///
|
deba@459
|
251 |
///\param m is the level of the messages output by the solver routines.
|
deba@459
|
252 |
void messageLevel(MessageLevel m);
|
deba@459
|
253 |
};
|
deba@459
|
254 |
|
deba@459
|
255 |
|
deba@458
|
256 |
} //END OF NAMESPACE LEMON
|
deba@458
|
257 |
|
deba@458
|
258 |
#endif //LEMON_LP_GLPK_H
|
deba@458
|
259 |
|