athos@1261: /* -*- C++ -*- athos@1261: * src/lemon/lp_glpk.cc - Part of LEMON, a generic C++ optimization library athos@1261: * athos@1261: * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport athos@1261: * (Egervary Combinatorial Optimization Research Group, 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: #ifndef LEMON_LP_GLPK_CC athos@1261: #define LEMON_LP_GLPK_CC athos@1261: athos@1261: ///\file athos@1261: ///\brief Implementation of the LEMON-GLPK lp solver interface. athos@1261: athos@1261: #include "lp_glpk.h" athos@1261: athos@1261: namespace lemon { athos@1261: athos@1261: /// \e athos@1261: int LpGlpk::_addCol() { athos@1261: int i=lpx_add_cols(lp, 1); athos@1261: _setColLowerBound(i, -INF); athos@1261: _setColUpperBound(i, INF); athos@1261: return i; athos@1261: } athos@1261: athos@1261: /// \e athos@1261: int LpGlpk::_addRow() { athos@1261: int i=lpx_add_rows(lp, 1); athos@1261: return i; athos@1261: } athos@1261: athos@1261: athos@1261: void LpGlpk::_setRowCoeffs(int i, athos@1261: int length, alpar@1263: const int * indices, alpar@1263: const Value * values ) athos@1261: { alpar@1263: lpx_set_mat_row(lp, i, length, alpar@1263: const_cast(indices) , alpar@1263: const_cast(values)); athos@1261: } athos@1261: athos@1261: void LpGlpk::_setColCoeffs(int i, athos@1261: int length, alpar@1263: const int * indices, alpar@1263: const Value * values) athos@1261: { alpar@1263: lpx_set_mat_col(lp, i, length, alpar@1263: const_cast(indices), alpar@1263: const_cast(values)); athos@1261: } athos@1261: athos@1261: void LpGlpk::_setColLowerBound(int i, Value lo) athos@1261: { athos@1261: if (lo==INF) { athos@1261: //FIXME error athos@1261: } athos@1261: int b=lpx_get_col_type(lp, i); athos@1261: double up=lpx_get_col_ub(lp, i); athos@1261: if (lo==-INF) { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: case LPX_LO: athos@1261: lpx_set_col_bnds(lp, i, LPX_FR, lo, up); athos@1261: break; athos@1261: case LPX_UP: athos@1261: break; athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: lpx_set_col_bnds(lp, i, LPX_UP, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } else { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: case LPX_LO: athos@1261: lpx_set_col_bnds(lp, i, LPX_LO, lo, up); athos@1261: break; athos@1261: case LPX_UP: athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: if (lo==up) athos@1261: lpx_set_col_bnds(lp, i, LPX_FX, lo, up); athos@1261: else athos@1261: lpx_set_col_bnds(lp, i, LPX_DB, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } athos@1261: athos@1261: } athos@1261: athos@1261: void LpGlpk::_setColUpperBound(int i, Value up) athos@1261: { athos@1261: if (up==-INF) { athos@1261: //FIXME error athos@1261: } athos@1261: int b=lpx_get_col_type(lp, i); athos@1261: double lo=lpx_get_col_lb(lp, i); athos@1261: if (up==INF) { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: case LPX_LO: athos@1261: break; athos@1261: case LPX_UP: athos@1261: lpx_set_col_bnds(lp, i, LPX_FR, lo, up); athos@1261: break; athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: lpx_set_col_bnds(lp, i, LPX_LO, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } else { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: lpx_set_col_bnds(lp, i, LPX_UP, lo, up); athos@1261: break; athos@1261: case LPX_UP: athos@1261: lpx_set_col_bnds(lp, i, LPX_UP, lo, up); athos@1261: break; athos@1261: case LPX_LO: athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: if (lo==up) athos@1261: lpx_set_col_bnds(lp, i, LPX_FX, lo, up); athos@1261: else athos@1261: lpx_set_col_bnds(lp, i, LPX_DB, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } athos@1261: } athos@1261: athos@1261: void LpGlpk::_setRowLowerBound(int i, Value lo) athos@1261: { athos@1261: if (lo==INF) { athos@1261: //FIXME error athos@1261: } athos@1261: int b=lpx_get_row_type(lp, i); athos@1261: double up=lpx_get_row_ub(lp, i); athos@1261: if (lo==-INF) { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: case LPX_LO: athos@1261: lpx_set_row_bnds(lp, i, LPX_FR, lo, up); athos@1261: break; athos@1261: case LPX_UP: athos@1261: break; athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: lpx_set_row_bnds(lp, i, LPX_UP, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } else { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: case LPX_LO: athos@1261: lpx_set_row_bnds(lp, i, LPX_LO, lo, up); athos@1261: break; athos@1261: case LPX_UP: athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: if (lo==up) athos@1261: lpx_set_row_bnds(lp, i, LPX_FX, lo, up); athos@1261: else athos@1261: lpx_set_row_bnds(lp, i, LPX_DB, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } athos@1261: } athos@1261: athos@1261: void LpGlpk::_setRowUpperBound(int i, Value up) athos@1261: { athos@1261: if (up==-INF) { athos@1261: //FIXME error athos@1261: } athos@1261: int b=lpx_get_row_type(lp, i); athos@1261: double lo=lpx_get_row_lb(lp, i); athos@1261: if (up==INF) { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: case LPX_LO: athos@1261: break; athos@1261: case LPX_UP: athos@1261: lpx_set_row_bnds(lp, i, LPX_FR, lo, up); athos@1261: break; athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: lpx_set_row_bnds(lp, i, LPX_LO, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } else { athos@1261: switch (b) { athos@1261: case LPX_FR: athos@1261: lpx_set_row_bnds(lp, i, LPX_UP, lo, up); athos@1261: break; athos@1261: case LPX_UP: athos@1261: lpx_set_row_bnds(lp, i, LPX_UP, lo, up); athos@1261: break; athos@1261: case LPX_LO: athos@1261: case LPX_DB: athos@1261: case LPX_FX: athos@1261: if (lo==up) athos@1261: lpx_set_row_bnds(lp, i, LPX_FX, lo, up); athos@1261: else athos@1261: lpx_set_row_bnds(lp, i, LPX_DB, lo, up); athos@1261: break; athos@1261: default: ; athos@1261: //FIXME error athos@1261: } athos@1261: } athos@1261: } athos@1261: athos@1261: void LpGlpk::_setObjCoeff(int i, Value obj_coef) athos@1261: { athos@1261: lpx_set_obj_coef(lp, i, obj_coef); athos@1261: } athos@1261: alpar@1263: alpar@1263: LpGlpk::SolutionType LpGlpk::_solve() alpar@1263: { alpar@1263: return OPTIMAL; alpar@1263: } alpar@1263: alpar@1263: LpGlpk::Value LpGlpk::_getSolution(int i) alpar@1263: { alpar@1263: return 0; alpar@1263: } alpar@1263: alpar@1263: alpar@1263: athos@1261: } //END OF NAMESPACE LEMON athos@1261: athos@1261: #endif //LEMON_LP_GLPK_CC