icc like this a bit more (no warnings).
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()
39 ///\bug Unimplemented!
41 LpSolverBase &LpGlpk::_copyLp()
47 LpGlpk::LpGlpk() : Parent(),
48 lp(lpx_create_prob()) {
49 ///\todo constrol function for this:
50 lpx_set_int_parm(lp, LPX_K_DUAL, 1);
58 int LpGlpk::_addCol() {
59 int i=lpx_add_cols(lp, 1);
60 _setColLowerBound(i, -INF);
61 _setColUpperBound(i, INF);
65 int LpGlpk::_addRow() {
66 int i=lpx_add_rows(lp, 1);
71 void LpGlpk::_setRowCoeffs(int i,
74 const Value * values )
76 lpx_set_mat_row(lp, i, length,
77 const_cast<int * >(indices) ,
78 const_cast<Value * >(values));
81 void LpGlpk::_setColCoeffs(int i,
86 lpx_set_mat_col(lp, i, length,
87 const_cast<int * >(indices),
88 const_cast<Value * >(values));
91 void LpGlpk::_setColLowerBound(int i, Value lo)
96 int b=lpx_get_col_type(lp, i);
97 double up=lpx_get_col_ub(lp, i);
102 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
108 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
117 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
123 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
125 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
134 void LpGlpk::_setColUpperBound(int i, Value up)
139 int b=lpx_get_col_type(lp, i);
140 double lo=lpx_get_col_lb(lp, i);
147 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
151 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
159 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
162 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
168 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
170 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
178 void LpGlpk::_setRowLowerBound(int i, Value lo)
183 int b=lpx_get_row_type(lp, i);
184 double up=lpx_get_row_ub(lp, i);
189 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
195 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
204 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
210 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
212 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
220 void LpGlpk::_setRowUpperBound(int i, Value up)
225 int b=lpx_get_row_type(lp, i);
226 double lo=lpx_get_row_lb(lp, i);
233 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
237 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
245 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
248 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
254 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
256 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
264 void LpGlpk::_setObjCoeff(int i, Value obj_coef)
266 lpx_set_obj_coef(lp, i, obj_coef);
270 LpGlpk::SolveExitStatus LpGlpk::_solve()
272 int i= lpx_simplex(lp);
282 LpGlpk::Value LpGlpk::_getPrimal(int i)
284 return lpx_get_col_prim(lp,i);
287 LpGlpk::Value LpGlpk::_getPrimalValue()
289 return lpx_get_obj_val(lp);
293 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
295 int stat= lpx_get_status(lp);
297 case LPX_UNDEF://Undefined (no solve has been run yet)
300 case LPX_NOFEAS://There is no feasible solution (primal, I guess)
301 case LPX_INFEAS://Infeasible
304 case LPX_UNBND://Unbounded
307 case LPX_FEAS://Feasible
310 case LPX_OPT://Feasible
314 return UNDEFINED; //to avoid gcc warning
320 void LpGlpk::_setMax()
322 lpx_set_obj_dir(lp, LPX_MAX);
325 void LpGlpk::_setMin()
327 lpx_set_obj_dir(lp, LPX_MIN);
331 void LpGlpk::messageLevel(int m)
333 lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
336 void LpGlpk::presolver(bool b)
338 lpx_set_int_parm(lp, LPX_K_PRESOL, b);
342 } //END OF NAMESPACE LEMON
344 #endif //LEMON_LP_GLPK_CC