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@458
|
38 |
/// \brief Interface for the GLPK LP solver
|
deba@458
|
39 |
///
|
deba@458
|
40 |
/// This class implements an interface for the GLPK LP solver.
|
deba@458
|
41 |
///\ingroup lp_group
|
deba@458
|
42 |
class LpGlpk : virtual public LpSolverBase {
|
deba@458
|
43 |
protected:
|
deba@458
|
44 |
|
deba@458
|
45 |
typedef glp_prob LPX;
|
deba@458
|
46 |
glp_prob* lp;
|
deba@458
|
47 |
bool solved;
|
deba@458
|
48 |
|
deba@458
|
49 |
public:
|
deba@458
|
50 |
|
deba@458
|
51 |
typedef LpSolverBase Parent;
|
deba@458
|
52 |
|
deba@458
|
53 |
LpGlpk();
|
deba@458
|
54 |
LpGlpk(const LpGlpk &);
|
deba@458
|
55 |
~LpGlpk();
|
deba@458
|
56 |
|
deba@458
|
57 |
protected:
|
deba@458
|
58 |
virtual LpSolverBase* _newLp();
|
deba@458
|
59 |
virtual LpSolverBase* _copyLp();
|
deba@458
|
60 |
|
deba@458
|
61 |
virtual int _addCol();
|
deba@458
|
62 |
virtual int _addRow();
|
deba@458
|
63 |
virtual void _eraseCol(int i);
|
deba@458
|
64 |
virtual void _eraseRow(int i);
|
deba@458
|
65 |
virtual void _getColName(int col, std::string & name) const;
|
deba@458
|
66 |
virtual void _setColName(int col, const std::string & name);
|
deba@458
|
67 |
virtual int _colByName(const std::string& name) const;
|
deba@458
|
68 |
virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e);
|
deba@458
|
69 |
virtual void _getRowCoeffs(int i, RowIterator b) const;
|
deba@458
|
70 |
virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e);
|
deba@458
|
71 |
virtual void _getColCoeffs(int i, ColIterator b) const;
|
deba@458
|
72 |
virtual void _setCoeff(int row, int col, Value value);
|
deba@458
|
73 |
virtual Value _getCoeff(int row, int col) const;
|
deba@458
|
74 |
|
deba@458
|
75 |
virtual void _setColLowerBound(int i, Value value);
|
deba@458
|
76 |
virtual Value _getColLowerBound(int i) const;
|
deba@458
|
77 |
virtual void _setColUpperBound(int i, Value value);
|
deba@458
|
78 |
virtual Value _getColUpperBound(int i) const;
|
deba@458
|
79 |
|
deba@458
|
80 |
virtual void _setRowBounds(int i, Value lower, Value upper);
|
deba@458
|
81 |
virtual void _getRowBounds(int i, Value &lb, Value &ub) const;
|
deba@458
|
82 |
virtual void _setObjCoeff(int i, Value obj_coef);
|
deba@458
|
83 |
virtual Value _getObjCoeff(int i) const;
|
deba@458
|
84 |
virtual void _clearObj();
|
deba@458
|
85 |
|
deba@458
|
86 |
///\e
|
deba@458
|
87 |
|
deba@458
|
88 |
///\todo It should be clarified
|
deba@458
|
89 |
///
|
deba@458
|
90 |
virtual SolveExitStatus _solve();
|
deba@458
|
91 |
virtual Value _getPrimal(int i) const;
|
deba@458
|
92 |
virtual Value _getDual(int i) const;
|
deba@458
|
93 |
virtual Value _getPrimalValue() const;
|
deba@458
|
94 |
virtual bool _isBasicCol(int i) const;
|
deba@458
|
95 |
///\e
|
deba@458
|
96 |
|
deba@458
|
97 |
///\todo It should be clarified
|
deba@458
|
98 |
///
|
deba@458
|
99 |
virtual SolutionStatus _getPrimalStatus() const;
|
deba@458
|
100 |
virtual SolutionStatus _getDualStatus() const;
|
deba@458
|
101 |
virtual ProblemTypes _getProblemType() const;
|
deba@458
|
102 |
|
deba@458
|
103 |
virtual void _setMax();
|
deba@458
|
104 |
virtual void _setMin();
|
deba@458
|
105 |
|
deba@458
|
106 |
virtual bool _isMax() const;
|
deba@458
|
107 |
|
deba@458
|
108 |
public:
|
deba@458
|
109 |
///Set the verbosity of the messages
|
deba@458
|
110 |
|
deba@458
|
111 |
///Set the verbosity of the messages
|
deba@458
|
112 |
///
|
deba@458
|
113 |
///\param m is the level of the messages output by the solver routines.
|
deba@458
|
114 |
///The possible values are:
|
deba@458
|
115 |
///- 0 --- no output (default value)
|
deba@458
|
116 |
///- 1 --- error messages only
|
deba@458
|
117 |
///- 2 --- normal output
|
deba@458
|
118 |
///- 3 --- full output (includes informational messages)
|
deba@458
|
119 |
void messageLevel(int m);
|
deba@458
|
120 |
///Turns on or off the presolver
|
deba@458
|
121 |
|
deba@458
|
122 |
///Turns on (\c b is \c true) or off (\c b is \c false) the presolver
|
deba@458
|
123 |
///
|
deba@458
|
124 |
///The presolver is off by default.
|
deba@458
|
125 |
void presolver(bool b);
|
deba@458
|
126 |
|
deba@458
|
127 |
///Pointer to the underlying GLPK data structure.
|
deba@458
|
128 |
LPX *lpx() {return lp;}
|
deba@458
|
129 |
|
deba@458
|
130 |
///Returns the constraint identifier understood by GLPK.
|
deba@458
|
131 |
int lpxRow(Row r) { return _lpId(r); }
|
deba@458
|
132 |
|
deba@458
|
133 |
///Returns the variable identifier understood by GLPK.
|
deba@458
|
134 |
int lpxCol(Col c) { return _lpId(c); }
|
deba@458
|
135 |
};
|
deba@458
|
136 |
} //END OF NAMESPACE LEMON
|
deba@458
|
137 |
|
deba@458
|
138 |
#endif //LEMON_LP_GLPK_H
|
deba@458
|
139 |
|