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 Research Group on Combinatorial Optimization, 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>
29 ///\bug Unimplemented!
31 LpSolverBase &LpGlpk::_newLp()
33 return *((LpSolverBase *)0);
38 ///\bug Unimplemented!
40 LpSolverBase &LpGlpk::_copyLp()
42 return *((LpSolverBase *)0);
45 LpGlpk::LpGlpk() : Parent(),
46 lp(lpx_create_prob()) {
47 ///\todo constrol function for this:
48 lpx_set_int_parm(lp, LPX_K_DUAL, 1);
56 int LpGlpk::_addCol() {
57 int i=lpx_add_cols(lp, 1);
58 _setColLowerBound(i, -INF);
59 _setColUpperBound(i, INF);
63 int LpGlpk::_addRow() {
64 int i=lpx_add_rows(lp, 1);
69 void LpGlpk::_setRowCoeffs(int i,
72 const Value * values )
74 lpx_set_mat_row(lp, i, length,
75 const_cast<int * >(indices) ,
76 const_cast<Value * >(values));
79 void LpGlpk::_setColCoeffs(int i,
84 lpx_set_mat_col(lp, i, length,
85 const_cast<int * >(indices),
86 const_cast<Value * >(values));
89 void LpGlpk::_setColLowerBound(int i, Value lo)
94 int b=lpx_get_col_type(lp, i);
95 double up=lpx_get_col_ub(lp, i);
100 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
106 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
115 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
121 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
123 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
132 void LpGlpk::_setColUpperBound(int i, Value up)
137 int b=lpx_get_col_type(lp, i);
138 double lo=lpx_get_col_lb(lp, i);
145 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
149 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
157 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
160 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
166 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
168 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
176 void LpGlpk::_setRowLowerBound(int i, Value lo)
181 int b=lpx_get_row_type(lp, i);
182 double up=lpx_get_row_ub(lp, i);
187 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
193 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
202 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
208 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
210 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
218 void LpGlpk::_setRowUpperBound(int i, Value up)
223 int b=lpx_get_row_type(lp, i);
224 double lo=lpx_get_row_lb(lp, i);
231 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
235 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
243 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
246 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
252 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
254 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
262 void LpGlpk::_setObjCoeff(int i, Value obj_coef)
264 lpx_set_obj_coef(lp, i, obj_coef);
268 LpGlpk::SolveExitStatus LpGlpk::_solve()
270 int i= lpx_simplex(lp);
280 LpGlpk::Value LpGlpk::_getPrimal(int i)
282 return lpx_get_col_prim(lp,i);
285 LpGlpk::Value LpGlpk::_getPrimalValue()
287 return lpx_get_obj_val(lp);
291 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
293 int stat= lpx_get_status(lp);
295 case LPX_UNDEF://Undefined (no solve has been run yet)
298 case LPX_NOFEAS://There is no feasible solution (primal, I guess)
299 case LPX_INFEAS://Infeasible
302 case LPX_UNBND://Unbounded
305 case LPX_FEAS://Feasible
308 case LPX_OPT://Feasible
312 return UNDEFINED; //to avoid gcc warning
318 void LpGlpk::_setMax()
320 lpx_set_obj_dir(lp, LPX_MAX);
323 void LpGlpk::_setMin()
325 lpx_set_obj_dir(lp, LPX_MIN);
329 void LpGlpk::messageLevel(int m)
331 lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
334 void LpGlpk::presolver(bool b)
336 lpx_set_int_parm(lp, LPX_K_PRESOL, b);
340 } //END OF NAMESPACE LEMON
342 #endif //LEMON_LP_GLPK_CC