athos@1261: /* -*- C++ -*- athos@1261: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library alpar@1956: * alpar@2553: * Copyright (C) 2003-2008 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1359: * (Egervary Research Group on Combinatorial Optimization, EGRES). athos@1261: * athos@1261: * Permission to use, modify and distribute this software is granted athos@1261: * provided that this copyright notice appears in all copies. For athos@1261: * precise terms see the accompanying LICENSE file. athos@1261: * athos@1261: * This software is provided "AS IS" with no warranty of any kind, athos@1261: * express or implied, and with no claim as to its suitability for any athos@1261: * purpose. athos@1261: * athos@1261: */ athos@1261: athos@1261: ///\file athos@1261: ///\brief Implementation of the LEMON-GLPK lp solver interface. athos@1261: ladanyi@1305: #include athos@1473: //#include deba@2441: deba@2441: #if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15) deba@2441: #define LEMON_glp(func) (glp_##func) deba@2441: #define LEMON_lpx(func) (lpx_##func) deba@2441: deba@2441: #define LEMON_GLP(def) (GLP_##def) deba@2441: #define LEMON_LPX(def) (LPX_##def) deba@2441: deba@2441: #else deba@2441: deba@2441: #define LEMON_glp(func) (lpx_##func) deba@2441: #define LEMON_lpx(func) (lpx_##func) deba@2441: deba@2441: #define LEMON_GLP(def) (LPX_##def) deba@2441: #define LEMON_LPX(def) (LPX_##def) deba@2441: deba@2441: #endif deba@2441: athos@1261: namespace lemon { athos@1261: deba@2363: LpGlpk::LpGlpk() : Parent() { deba@2441: solved = false; deba@2363: rows = _lp_bits::LpId(1); deba@2363: cols = _lp_bits::LpId(1); deba@2441: lp = LEMON_glp(create_prob)(); deba@2441: LEMON_glp(create_index)(lp); deba@2441: LEMON_lpx(set_int_parm)(lp, LEMON_LPX(K_DUAL), 1); alpar@1321: messageLevel(0); alpar@1321: } alpar@1321: deba@2363: LpGlpk::LpGlpk(const LpGlpk &glp) : Parent() { deba@2441: solved = false; deba@2363: rows = _lp_bits::LpId(1); deba@2363: cols = _lp_bits::LpId(1); deba@2441: lp = LEMON_glp(create_prob)(); deba@2441: LEMON_glp(create_index)(lp); deba@2363: ///\todo control function for this: deba@2441: LEMON_lpx(set_int_parm)(lp, LEMON_LPX(K_DUAL), 1); alpar@2321: messageLevel(0); alpar@2321: //Coefficient matrix, row bounds deba@2441: LEMON_glp(add_rows)(lp, LEMON_glp(get_num_rows)(glp.lp)); deba@2441: LEMON_glp(add_cols)(lp, LEMON_glp(get_num_cols)(glp.lp)); alpar@2321: int len; ladanyi@2591: std::vector ind(1+LEMON_glp(get_num_cols)(glp.lp)); ladanyi@2591: std::vector val(1+LEMON_glp(get_num_cols)(glp.lp)); deba@2441: for (int i=1;i<=LEMON_glp(get_num_rows)(glp.lp);++i) alpar@2321: { ladanyi@2591: len=LEMON_glp(get_mat_row)(glp.lp,i,&*ind.begin(),&*val.begin()); ladanyi@2591: LEMON_glp(set_mat_row)(lp, i,len,&*ind.begin(),&*val.begin()); deba@2441: LEMON_glp(set_row_bnds)(lp,i, deba@2441: LEMON_glp(get_row_type)(glp.lp,i), deba@2441: LEMON_glp(get_row_lb)(glp.lp,i), deba@2441: LEMON_glp(get_row_ub)(glp.lp,i)); alpar@2321: } alpar@2321: alpar@2321: //Objective function, coloumn bounds deba@2441: LEMON_glp(set_obj_dir)(lp, LEMON_glp(get_obj_dir)(glp.lp)); alpar@2321: //Objectif function's constant term treated separately deba@2441: LEMON_glp(set_obj_coef)(lp,0,LEMON_glp(get_obj_coef)(glp.lp,0)); deba@2441: for (int i=1;i<=LEMON_glp(get_num_cols)(glp.lp);++i) alpar@2321: { deba@2441: LEMON_glp(set_obj_coef)(lp,i, deba@2441: LEMON_glp(get_obj_coef)(glp.lp,i)); deba@2441: LEMON_glp(set_col_bnds)(lp,i, deba@2441: LEMON_glp(get_col_type)(glp.lp,i), deba@2441: LEMON_glp(get_col_lb)(glp.lp,i), deba@2441: LEMON_glp(get_col_ub)(glp.lp,i)); alpar@2321: } alpar@2321: } alpar@2321: alpar@1321: LpGlpk::~LpGlpk() { deba@2441: LEMON_glp(delete_prob)(lp); alpar@1321: } alpar@1321: alpar@1321: int LpGlpk::_addCol() { deba@2441: int i=LEMON_glp(add_cols)(lp, 1); deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FR), 0.0, 0.0); deba@2441: solved = false; alpar@1321: return i; alpar@1321: } alpar@1321: athos@1436: ///\e athos@1436: athos@1436: athos@1436: LpSolverBase &LpGlpk::_newLp() athos@1436: { alpar@2321: LpGlpk* newlp=new LpGlpk; athos@1436: return *newlp; athos@1436: } athos@1436: athos@1436: ///\e athos@1436: athos@1436: LpSolverBase &LpGlpk::_copyLp() athos@1436: { alpar@2321: LpGlpk* newlp=new LpGlpk(*this); athos@1436: return *newlp; athos@1436: } athos@1436: alpar@1321: int LpGlpk::_addRow() { deba@2441: int i=LEMON_glp(add_rows)(lp, 1); deba@2441: solved = false; alpar@1321: return i; alpar@1321: } alpar@1321: alpar@1321: athos@1432: void LpGlpk::_eraseCol(int i) { deba@2386: int ca[2]; deba@2386: ca[1]=i; deba@2441: LEMON_glp(del_cols)(lp, 1, ca); deba@2441: solved = false; athos@1432: } athos@1432: athos@1432: void LpGlpk::_eraseRow(int i) { deba@2386: int ra[2]; deba@2386: ra[1]=i; deba@2441: LEMON_glp(del_rows)(lp, 1, ra); deba@2441: solved = false; athos@1432: } athos@1432: deba@2386: void LpGlpk::_getColName(int c, std::string & name) const alpar@1895: { alpar@1895: deba@2441: const char *n = LEMON_glp(get_col_name)(lp,c); alpar@1895: name = n?n:""; alpar@1895: } alpar@1895: alpar@1895: deba@2386: void LpGlpk::_setColName(int c, const std::string & name) alpar@1895: { deba@2441: LEMON_glp(set_col_name)(lp,c,const_cast(name.c_str())); athos@2349: alpar@1895: } deba@2366: deba@2366: int LpGlpk::_colByName(const std::string& name) const deba@2366: { deba@2441: int k = LEMON_glp(find_col)(lp, const_cast(name.c_str())); deba@2366: return k > 0 ? k : -1; deba@2366: } deba@2366: alpar@1895: deba@2364: void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) alpar@1321: { deba@2312: std::vector indices; deba@2312: std::vector values; deba@2312: deba@2312: indices.push_back(0); deba@2312: values.push_back(0); deba@2312: deba@2364: for(ConstRowIterator it=b; it!=e; ++it) { deba@2312: indices.push_back(it->first); deba@2312: values.push_back(it->second); deba@2312: } deba@2312: deba@2441: LEMON_glp(set_mat_row)(lp, i, values.size() - 1, deba@2441: &indices[0], &values[0]); deba@2441: deba@2441: solved = false; alpar@1321: } deba@2364: deba@2386: void LpGlpk::_getRowCoeffs(int ix, RowIterator b) const deba@2364: { deba@2441: int length = LEMON_glp(get_mat_row)(lp, ix, 0, 0); deba@2364: deba@2364: std::vector indices(length + 1); deba@2364: std::vector values(length + 1); deba@2364: deba@2441: LEMON_glp(get_mat_row)(lp, ix, &indices[0], &values[0]); deba@2364: deba@2364: for (int i = 1; i <= length; ++i) { deba@2364: *b = std::make_pair(indices[i], values[i]); deba@2364: ++b; deba@2364: } deba@2364: } alpar@1321: deba@2386: void LpGlpk::_setColCoeffs(int ix, ConstColIterator b, ConstColIterator e) { deba@2312: deba@2312: std::vector indices; deba@2312: std::vector values; deba@2312: deba@2312: indices.push_back(0); deba@2312: values.push_back(0); deba@2312: deba@2364: for(ConstColIterator it=b; it!=e; ++it) { deba@2312: indices.push_back(it->first); deba@2312: values.push_back(it->second); deba@2312: } deba@2312: deba@2441: LEMON_glp(set_mat_col)(lp, ix, values.size() - 1, deba@2441: &indices[0], &values[0]); deba@2441: deba@2441: solved = false; alpar@1321: } athos@1431: deba@2386: void LpGlpk::_getColCoeffs(int ix, ColIterator b) const deba@2364: { deba@2441: int length = LEMON_glp(get_mat_col)(lp, ix, 0, 0); deba@2364: deba@2364: std::vector indices(length + 1); deba@2364: std::vector values(length + 1); deba@2364: deba@2441: LEMON_glp(get_mat_col)(lp, ix, &indices[0], &values[0]); deba@2364: deba@2364: for (int i = 1; i <= length; ++i) { deba@2364: *b = std::make_pair(indices[i], values[i]); deba@2364: ++b; deba@2364: } deba@2364: } athos@1431: deba@2386: void LpGlpk::_setCoeff(int ix, int jx, Value value) athos@1431: { deba@2312: deba@2441: if (LEMON_glp(get_num_cols)(lp) < LEMON_glp(get_num_rows)(lp)) { deba@2312: deba@2441: int length=LEMON_glp(get_mat_row)(lp, ix, 0, 0); deba@2312: deba@2312: std::vector indices(length + 2); deba@2312: std::vector values(length + 2); deba@2312: deba@2441: LEMON_glp(get_mat_row)(lp, ix, &indices[0], &values[0]); deba@2312: deba@2312: //The following code does not suppose that the elements of the deba@2312: //array indices are sorted deba@2312: bool found=false; deba@2312: for (int i = 1; i <= length; ++i) { deba@2386: if (indices[i]==jx){ deba@2312: found=true; deba@2312: values[i]=value; deba@2312: break; deba@2312: } deba@2312: } deba@2312: if (!found){ deba@2312: ++length; deba@2386: indices[length]=jx; deba@2312: values[length]=value; deba@2312: } athos@1431: deba@2441: LEMON_glp(set_mat_row)(lp, ix, length, &indices[0], &values[0]); deba@2312: deba@2312: } else { deba@2312: deba@2441: int length=LEMON_glp(get_mat_col)(lp, jx, 0, 0); deba@2312: deba@2312: std::vector indices(length + 2); deba@2312: std::vector values(length + 2); deba@2312: deba@2441: LEMON_glp(get_mat_col)(lp, jx, &indices[0], &values[0]); deba@2312: deba@2312: //The following code does not suppose that the elements of the deba@2312: //array indices are sorted deba@2312: bool found=false; deba@2312: for (int i = 1; i <= length; ++i) { deba@2386: if (indices[i]==jx){ deba@2312: found=true; deba@2312: values[i]=value; deba@2312: break; deba@2312: } deba@2312: } deba@2312: if (!found){ deba@2312: ++length; deba@2386: indices[length]=ix; deba@2312: values[length]=value; deba@2312: } athos@1431: deba@2441: LEMON_glp(set_mat_col)(lp, jx, length, &indices[0], &values[0]); athos@1431: } deba@2441: deba@2441: solved = false; athos@1431: } athos@1431: deba@2386: LpGlpk::Value LpGlpk::_getCoeff(int ix, int jx) const athos@2324: { athos@2328: deba@2441: int length=LEMON_glp(get_mat_row)(lp, ix, 0, 0); athos@2328: deba@2364: std::vector indices(length + 1); deba@2364: std::vector values(length + 1); athos@2328: deba@2441: LEMON_glp(get_mat_row)(lp, ix, &indices[0], &values[0]); athos@2328: athos@2328: //The following code does not suppose that the elements of the athos@2328: //array indices are sorted athos@2328: for (int i = 1; i <= length; ++i) { deba@2386: if (indices[i]==jx){ athos@2328: return values[i]; athos@2328: } athos@2328: } athos@2324: return 0; athos@2328: athos@2324: } athos@2324: athos@2324: alpar@1321: void LpGlpk::_setColLowerBound(int i, Value lo) alpar@1321: { alpar@1321: if (lo==INF) { alpar@1321: //FIXME error alpar@1321: } deba@2441: int b=LEMON_glp(get_col_type)(lp, i); deba@2441: double up=LEMON_glp(get_col_ub)(lp, i); alpar@1321: if (lo==-INF) { alpar@1321: switch (b) { deba@2441: case LEMON_GLP(FR): deba@2441: case LEMON_GLP(LO): deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FR), lo, up); alpar@1321: break; deba@2441: case LEMON_GLP(UP): alpar@1321: break; deba@2441: case LEMON_GLP(DB): deba@2441: case LEMON_GLP(FX): deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(UP), lo, up); alpar@1321: break; alpar@1321: default: ; alpar@1321: //FIXME error alpar@1321: } alpar@1321: } else { alpar@1321: switch (b) { deba@2441: case LEMON_GLP(FR): deba@2441: case LEMON_GLP(LO): deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(LO), lo, up); alpar@1321: break; deba@2441: case LEMON_GLP(UP): deba@2441: case LEMON_GLP(DB): deba@2441: case LEMON_GLP(FX): alpar@1321: if (lo==up) deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FX), lo, up); alpar@1321: else deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(DB), lo, up); alpar@1321: break; alpar@1321: default: ; alpar@1321: //FIXME error alpar@1321: } athos@1261: } athos@1261: deba@2441: solved = false; alpar@1321: } athos@2328: deba@2366: LpGlpk::Value LpGlpk::_getColLowerBound(int i) const athos@2328: { deba@2441: int b=LEMON_glp(get_col_type)(lp, i); athos@2328: switch (b) { deba@2441: case LEMON_GLP(LO): deba@2441: case LEMON_GLP(DB): deba@2441: case LEMON_GLP(FX): deba@2441: return LEMON_glp(get_col_lb)(lp, i); athos@2328: default: ; athos@2328: return -INF; athos@2328: } athos@2328: } alpar@1321: alpar@1321: void LpGlpk::_setColUpperBound(int i, Value up) alpar@1321: { alpar@1321: if (up==-INF) { alpar@1321: //FIXME error athos@1261: } deba@2441: int b=LEMON_glp(get_col_type)(lp, i); deba@2441: double lo=LEMON_glp(get_col_lb)(lp, i); alpar@1321: if (up==INF) { alpar@1321: switch (b) { deba@2441: case LEMON_GLP(FR): deba@2441: case LEMON_GLP(LO): alpar@1321: break; deba@2441: case LEMON_GLP(UP): deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FR), lo, up); alpar@1321: break; deba@2441: case LEMON_GLP(DB): deba@2441: case LEMON_GLP(FX): deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(LO), lo, up); alpar@1321: break; alpar@1321: default: ; athos@1261: //FIXME error athos@1261: } alpar@1321: } else { alpar@1321: switch (b) { deba@2441: case LEMON_GLP(FR): deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(UP), lo, up); alpar@1321: break; deba@2441: case LEMON_GLP(UP): deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(UP), lo, up); alpar@1321: break; deba@2441: case LEMON_GLP(LO): deba@2441: case LEMON_GLP(DB): deba@2441: case LEMON_GLP(FX): alpar@1321: if (lo==up) deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FX), lo, up); alpar@1321: else deba@2441: LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(DB), lo, up); alpar@1321: break; alpar@1321: default: ; athos@1261: //FIXME error athos@1261: } alpar@1321: } deba@2441: deba@2441: solved = false; alpar@1321: } athos@2328: deba@2366: LpGlpk::Value LpGlpk::_getColUpperBound(int i) const athos@2328: { deba@2441: int b=LEMON_glp(get_col_type)(lp, i); athos@2328: switch (b) { deba@2441: case LEMON_GLP(UP): deba@2441: case LEMON_GLP(DB): deba@2441: case LEMON_GLP(FX): deba@2441: return LEMON_glp(get_col_ub)(lp, i); athos@2328: default: ; athos@2328: return INF; athos@2328: } athos@2328: } alpar@1321: athos@1379: void LpGlpk::_setRowBounds(int i, Value lb, Value ub) athos@1379: { athos@1379: //Bad parameter athos@1379: if (lb==INF || ub==-INF) { athos@1379: //FIXME error athos@1379: } athos@1379: athos@1379: if (lb == -INF){ athos@1379: if (ub == INF){ deba@2441: LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(FR), lb, ub); athos@1379: } athos@1379: else{ deba@2441: LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(UP), lb, ub); athos@1379: } athos@1379: } athos@1379: else{ athos@1379: if (ub==INF){ deba@2441: LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(LO), lb, ub); athos@1379: athos@1379: } athos@1379: else{ athos@1379: if (lb == ub){ deba@2441: LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(FX), lb, ub); athos@1379: } athos@1379: else{ deba@2441: LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(DB), lb, ub); athos@1379: } athos@1379: } athos@1379: } athos@1379: deba@2441: solved = false; athos@1379: } athos@2328: deba@2366: void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) const athos@2328: { athos@2328: deba@2441: int b=LEMON_glp(get_row_type)(lp, i); athos@2328: switch (b) { deba@2441: case LEMON_GLP(FR): deba@2441: case LEMON_GLP(UP): athos@2328: lb = -INF; athos@2328: break; athos@2328: default: deba@2441: lb=LEMON_glp(get_row_lb)(lp, i); athos@2328: } athos@2328: athos@2328: switch (b) { deba@2441: case LEMON_GLP(FR): deba@2441: case LEMON_GLP(LO): athos@2328: ub = INF; athos@2328: break; athos@2328: default: deba@2441: ub=LEMON_glp(get_row_ub)(lp, i); athos@2328: } athos@2328: athos@2328: } athos@1261: athos@1298: void LpGlpk::_setObjCoeff(int i, Value obj_coef) athos@1298: { athos@1376: //i=0 means the constant term (shift) deba@2441: LEMON_glp(set_obj_coef)(lp, i, obj_coef); deba@2441: deba@2441: solved = false; athos@1298: } athos@1261: deba@2366: LpGlpk::Value LpGlpk::_getObjCoeff(int i) const { athos@2324: //i=0 means the constant term (shift) deba@2441: return LEMON_glp(get_obj_coef)(lp, i); athos@2324: } athos@2324: athos@1377: void LpGlpk::_clearObj() athos@1376: { deba@2441: for (int i=0;i<=LEMON_glp(get_num_cols)(lp);++i){ deba@2441: LEMON_glp(set_obj_coef)(lp, i, 0); athos@1376: } deba@2441: deba@2441: solved = false; athos@1376: } alpar@1263: alpar@1303: LpGlpk::SolveExitStatus LpGlpk::_solve() alpar@1263: { athos@2345: // A way to check the problem to be solved deba@2441: //LEMON_glp(write_cpxlp(lp,"naittvan.cpx"); athos@2345: deba@2441: LEMON_lpx(std_basis)(lp); deba@2441: int i = LEMON_lpx(simplex)(lp); deba@2363: athos@1298: switch (i) { deba@2441: case LEMON_LPX(E_OK): deba@2441: solved = true; athos@1298: return SOLVED; athos@1298: default: athos@1298: return UNSOLVED; athos@1298: } alpar@1263: } alpar@1263: deba@2366: LpGlpk::Value LpGlpk::_getPrimal(int i) const alpar@1263: { deba@2441: return LEMON_glp(get_col_prim)(lp,i); alpar@1263: } marci@1787: deba@2366: LpGlpk::Value LpGlpk::_getDual(int i) const marci@1787: { deba@2441: return LEMON_glp(get_row_dual)(lp,i); marci@1787: } alpar@1263: deba@2366: LpGlpk::Value LpGlpk::_getPrimalValue() const alpar@1312: { deba@2441: return LEMON_glp(get_obj_val)(lp); alpar@1312: } deba@2366: bool LpGlpk::_isBasicCol(int i) const deba@2366: { deba@2441: return (LEMON_glp(get_col_stat)(lp, i)==LEMON_GLP(BS)); marci@1840: } alpar@1312: athos@1298: deba@2366: LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() const alpar@1294: { deba@2441: if (!solved) return UNDEFINED; deba@2441: int stat= LEMON_lpx(get_status)(lp); athos@1298: switch (stat) { deba@2441: case LEMON_LPX(UNDEF)://Undefined (no solve has been run yet) athos@1298: return UNDEFINED; deba@2441: case LEMON_LPX(NOFEAS)://There is no feasible solution (primal, I guess) deba@2441: case LEMON_LPX(INFEAS)://Infeasible athos@1458: return INFEASIBLE; deba@2441: case LEMON_LPX(UNBND)://Unbounded athos@1458: return INFINITE; deba@2441: case LEMON_LPX(FEAS)://Feasible athos@1458: return FEASIBLE; deba@2441: case LEMON_LPX(OPT)://Feasible athos@1458: return OPTIMAL; athos@1458: default: athos@1458: return UNDEFINED; //to avoid gcc warning athos@1458: //FIXME error athos@1458: } athos@1458: } athos@1458: deba@2366: LpGlpk::SolutionStatus LpGlpk::_getDualStatus() const athos@1458: { deba@2441: if (!solved) return UNDEFINED; deba@2441: switch (LEMON_lpx(get_dual_stat)(lp)) { deba@2441: case LEMON_LPX(D_UNDEF)://Undefined (no solve has been run yet) athos@1458: return UNDEFINED; deba@2441: case LEMON_LPX(D_NOFEAS)://There is no dual feasible solution deba@2441: // case LEMON_LPX(D_INFEAS://Infeasible athos@1458: return INFEASIBLE; deba@2441: case LEMON_LPX(D_FEAS)://Feasible deba@2441: switch (LEMON_lpx(get_status)(lp)) { deba@2441: case LEMON_LPX(NOFEAS): athos@1458: return INFINITE; deba@2441: case LEMON_LPX(OPT): athos@1458: return OPTIMAL; athos@1458: default: athos@1458: return FEASIBLE; athos@1458: } athos@1458: default: athos@1458: return UNDEFINED; //to avoid gcc warning athos@1458: //FIXME error athos@1458: } athos@1458: } athos@1458: deba@2366: LpGlpk::ProblemTypes LpGlpk::_getProblemType() const athos@1458: { deba@2441: if (!solved) return UNKNOWN; deba@2441: //int stat= LEMON_glp(get_status(lp); deba@2441: int statp= LEMON_lpx(get_prim_stat)(lp); deba@2441: int statd= LEMON_lpx(get_dual_stat)(lp); deba@2441: if (statp==LEMON_LPX(P_FEAS) && statd==LEMON_LPX(D_FEAS)) athos@1460: return PRIMAL_DUAL_FEASIBLE; deba@2441: if (statp==LEMON_LPX(P_FEAS) && statd==LEMON_LPX(D_NOFEAS)) athos@1460: return PRIMAL_FEASIBLE_DUAL_INFEASIBLE; deba@2441: if (statp==LEMON_LPX(P_NOFEAS) && statd==LEMON_LPX(D_FEAS)) athos@1460: return PRIMAL_INFEASIBLE_DUAL_FEASIBLE; deba@2441: if (statp==LEMON_LPX(P_NOFEAS) && statd==LEMON_LPX(D_NOFEAS)) athos@1460: return PRIMAL_DUAL_INFEASIBLE; athos@1460: //In all other cases athos@1460: return UNKNOWN; alpar@1294: } alpar@1263: alpar@1312: void LpGlpk::_setMax() alpar@1312: { deba@2441: solved = false; deba@2441: LEMON_glp(set_obj_dir)(lp, LEMON_GLP(MAX)); alpar@1321: } alpar@1321: alpar@1312: void LpGlpk::_setMin() alpar@1312: { deba@2441: solved = false; deba@2441: LEMON_glp(set_obj_dir)(lp, LEMON_GLP(MIN)); alpar@1321: } alpar@1321: deba@2366: bool LpGlpk::_isMax() const athos@2324: { deba@2441: return (LEMON_glp(get_obj_dir)(lp)==LEMON_GLP(MAX)); athos@2324: } athos@2324: alpar@1321: athos@2324: alpar@1321: void LpGlpk::messageLevel(int m) alpar@1321: { deba@2441: LEMON_lpx(set_int_parm)(lp, LEMON_LPX(K_MSGLEV), m); alpar@1321: } alpar@1312: alpar@1326: void LpGlpk::presolver(bool b) alpar@1326: { deba@2441: LEMON_lpx(set_int_parm)(lp, LEMON_LPX(K_PRESOL), b); alpar@1326: } alpar@1326: alpar@1312: athos@1261: } //END OF NAMESPACE LEMON