Obsolte test removed.
2 * src/lemon/lp_glpk.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef LEMON_LP_GLPK_CC
18 #define LEMON_LP_GLPK_CC
21 ///\brief Implementation of the LEMON-GLPK lp solver interface.
23 #include <lemon/lp_glpk.h>
27 LpGlpk::LpGlpk() : Parent(),
28 lp(lpx_create_prob()) {
29 ///\todo constrol function for this:
30 lpx_set_int_parm(lp, LPX_K_DUAL, 1);
38 int LpGlpk::_addCol() {
39 int i=lpx_add_cols(lp, 1);
40 _setColLowerBound(i, -INF);
41 _setColUpperBound(i, INF);
45 int LpGlpk::_addRow() {
46 int i=lpx_add_rows(lp, 1);
51 void LpGlpk::_setRowCoeffs(int i,
54 const Value * values )
56 lpx_set_mat_row(lp, i, length,
57 const_cast<int * >(indices) ,
58 const_cast<Value * >(values));
61 void LpGlpk::_setColCoeffs(int i,
66 lpx_set_mat_col(lp, i, length,
67 const_cast<int * >(indices),
68 const_cast<Value * >(values));
71 void LpGlpk::_setColLowerBound(int i, Value lo)
76 int b=lpx_get_col_type(lp, i);
77 double up=lpx_get_col_ub(lp, i);
82 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
88 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
97 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
103 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
105 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
114 void LpGlpk::_setColUpperBound(int i, Value up)
119 int b=lpx_get_col_type(lp, i);
120 double lo=lpx_get_col_lb(lp, i);
127 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
131 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
139 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
142 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
148 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
150 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
158 void LpGlpk::_setRowLowerBound(int i, Value lo)
163 int b=lpx_get_row_type(lp, i);
164 double up=lpx_get_row_ub(lp, i);
169 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
175 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
184 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
190 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
192 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
200 void LpGlpk::_setRowUpperBound(int i, Value up)
205 int b=lpx_get_row_type(lp, i);
206 double lo=lpx_get_row_lb(lp, i);
213 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
217 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
225 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
228 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
234 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
236 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
244 void LpGlpk::_setObjCoeff(int i, Value obj_coef)
246 lpx_set_obj_coef(lp, i, obj_coef);
250 LpGlpk::SolveExitStatus LpGlpk::_solve()
252 int i= lpx_simplex(lp);
262 LpGlpk::Value LpGlpk::_getPrimal(int i)
264 return lpx_get_col_prim(lp,i);
267 LpGlpk::Value LpGlpk::_getPrimalValue()
269 return lpx_get_obj_val(lp);
273 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
275 int stat= lpx_get_status(lp);
277 case LPX_UNDEF://Undefined (no solve has been run yet)
280 case LPX_NOFEAS://There is no feasible solution (primal, I guess)
281 case LPX_INFEAS://Infeasible
284 case LPX_UNBND://Unbounded
287 case LPX_FEAS://Feasible
290 case LPX_OPT://Feasible
294 return UNDEFINED; //to avoid gcc warning
300 void LpGlpk::_setMax()
302 lpx_set_obj_dir(lp, LPX_MAX);
305 void LpGlpk::_setMin()
307 lpx_set_obj_dir(lp, LPX_MIN);
311 void LpGlpk::messageLevel(int m)
313 lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
316 void LpGlpk::presolver(bool b)
318 lpx_set_int_parm(lp, LPX_K_PRESOL, b);
322 } //END OF NAMESPACE LEMON
324 #endif //LEMON_LP_GLPK_CC