Cplex interface has improved a lot.
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>
28 int LpGlpk::_addCol() {
29 int i=lpx_add_cols(lp, 1);
30 _setColLowerBound(i, -INF);
31 _setColUpperBound(i, INF);
36 int LpGlpk::_addRow() {
37 int i=lpx_add_rows(lp, 1);
42 void LpGlpk::_setRowCoeffs(int i,
45 const Value * values )
47 lpx_set_mat_row(lp, i, length,
48 const_cast<int * >(indices) ,
49 const_cast<Value * >(values));
52 void LpGlpk::_setColCoeffs(int i,
57 lpx_set_mat_col(lp, i, length,
58 const_cast<int * >(indices),
59 const_cast<Value * >(values));
62 void LpGlpk::_setColLowerBound(int i, Value lo)
67 int b=lpx_get_col_type(lp, i);
68 double up=lpx_get_col_ub(lp, i);
73 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
79 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
88 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
94 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
96 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
105 void LpGlpk::_setColUpperBound(int i, Value up)
110 int b=lpx_get_col_type(lp, i);
111 double lo=lpx_get_col_lb(lp, i);
118 lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
122 lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
130 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
133 lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
139 lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
141 lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
149 void LpGlpk::_setRowLowerBound(int i, Value lo)
154 int b=lpx_get_row_type(lp, i);
155 double up=lpx_get_row_ub(lp, i);
160 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
166 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
175 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
181 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
183 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
191 void LpGlpk::_setRowUpperBound(int i, Value up)
196 int b=lpx_get_row_type(lp, i);
197 double lo=lpx_get_row_lb(lp, i);
204 lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
208 lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
216 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
219 lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
225 lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
227 lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
235 void LpGlpk::_setObjCoeff(int i, Value obj_coef)
237 lpx_set_obj_coef(lp, i, obj_coef);
241 LpGlpk::SolveExitStatus LpGlpk::_solve()
243 int i= lpx_simplex(lp);
253 LpGlpk::Value LpGlpk::_getPrimal(int i)
255 return lpx_get_col_prim(lp,i);
258 LpGlpk::Value LpGlpk::_getPrimalValue()
260 return lpx_get_obj_val(lp);
264 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
266 int stat= lpx_get_status(lp);
268 case LPX_UNDEF://Undefined (no solve has been run yet)
271 case LPX_NOFEAS://There is no feasible solution (primal, I guess)
272 case LPX_INFEAS://Infeasible
275 case LPX_UNBND://Unbounded
278 case LPX_FEAS://Feasible
281 case LPX_OPT://Feasible
285 return UNDEFINED; //to avoid gcc warning
291 void LpGlpk::_setMax()
293 lpx_set_obj_dir(lp, LPX_MAX);
295 void LpGlpk::_setMin()
297 lpx_set_obj_dir(lp, LPX_MIN);
301 } //END OF NAMESPACE LEMON
303 #endif //LEMON_LP_GLPK_CC