# HG changeset patch # User athos # Date 1112625923 0 # Node ID d1ca90316b59a7a5fd63589e05565b1c2993ff76 # Parent fde0d12545c1f11f666a769730f0df83db7007b7 Now one can solve an lp problem. diff -r fde0d12545c1 -r d1ca90316b59 src/work/athos/lp/lp_glpk.cc --- a/src/work/athos/lp/lp_glpk.cc Mon Apr 04 10:13:33 2005 +0000 +++ b/src/work/athos/lp/lp_glpk.cc Mon Apr 04 14:45:23 2005 +0000 @@ -188,71 +188,98 @@ } } - void LpGlpk::_setRowUpperBound(int i, Value up) - { - if (up==-INF) { + void LpGlpk::_setRowUpperBound(int i, Value up) + { + if (up==-INF) { + //FIXME error + } + int b=lpx_get_row_type(lp, i); + double lo=lpx_get_row_lb(lp, i); + if (up==INF) { + switch (b) { + case LPX_FR: + case LPX_LO: + break; + case LPX_UP: + lpx_set_row_bnds(lp, i, LPX_FR, lo, up); + break; + case LPX_DB: + case LPX_FX: + lpx_set_row_bnds(lp, i, LPX_LO, lo, up); + break; + default: ; //FIXME error } - int b=lpx_get_row_type(lp, i); - double lo=lpx_get_row_lb(lp, i); - if (up==INF) { - switch (b) { - case LPX_FR: - case LPX_LO: - break; - case LPX_UP: - lpx_set_row_bnds(lp, i, LPX_FR, lo, up); - break; - case LPX_DB: - case LPX_FX: - lpx_set_row_bnds(lp, i, LPX_LO, lo, up); - break; - default: ; - //FIXME error - } - } else { - switch (b) { - case LPX_FR: - lpx_set_row_bnds(lp, i, LPX_UP, lo, up); - break; - case LPX_UP: - lpx_set_row_bnds(lp, i, LPX_UP, lo, up); - break; - case LPX_LO: - case LPX_DB: - case LPX_FX: - if (lo==up) - lpx_set_row_bnds(lp, i, LPX_FX, lo, up); - else - lpx_set_row_bnds(lp, i, LPX_DB, lo, up); - break; - default: ; - //FIXME error - } + } else { + switch (b) { + case LPX_FR: + lpx_set_row_bnds(lp, i, LPX_UP, lo, up); + break; + case LPX_UP: + lpx_set_row_bnds(lp, i, LPX_UP, lo, up); + break; + case LPX_LO: + case LPX_DB: + case LPX_FX: + if (lo==up) + lpx_set_row_bnds(lp, i, LPX_FX, lo, up); + else + lpx_set_row_bnds(lp, i, LPX_DB, lo, up); + break; + default: ; + //FIXME error } } + } - void LpGlpk::_setObjCoeff(int i, Value obj_coef) - { - lpx_set_obj_coef(lp, i, obj_coef); - } + void LpGlpk::_setObjCoeff(int i, Value obj_coef) + { + lpx_set_obj_coef(lp, i, obj_coef); + } LpGlpk::SolutionStatus LpGlpk::_solve() { - return SOLVED; + int i= lpx_simplex(lp); + switch (i) { + case LPX_E_OK: + return SOLVED; + break; + default: + return UNSOLVED; + } } LpGlpk::Value LpGlpk::_getPrimal(int i) { - return 0; + return lpx_get_col_prim(lp,i); } + LpGlpk::SolutionType LpGlpk::_getPrimalType() { - return OPTIMAL; + int stat= lpx_get_status(lp); + switch (stat) { + case LPX_UNDEF://Undefined (no solve has been run yet) + return UNDEFINED; + break; + case LPX_NOFEAS://There is no feasible solution (primal, I guess) + case LPX_INFEAS://Infeasible + return INFEASIBLE; + break; + case LPX_UNBND://Unbounded + return INFINITE; + break; + case LPX_FEAS://Feasible +2 return FEASIBLE; + break; + case LPX_OPT://Feasible + return OPTIMAL; + break; + default: ; + //FIXME error + } } - } //END OF NAMESPACE LEMON