# HG changeset patch # User alpar # Date 1112941991 0 # Node ID bc3a4c498eb25147d0f5ef53947a2a3a1b57acc4 # Parent 9863b5d51beb0cadd820eff23928309ab5ebc8aa No output messages by default diff -r 9863b5d51beb -r bc3a4c498eb2 src/lemon/lp_glpk.cc --- a/src/lemon/lp_glpk.cc Fri Apr 08 05:36:16 2005 +0000 +++ b/src/lemon/lp_glpk.cc Fri Apr 08 06:33:11 2005 +0000 @@ -24,169 +24,178 @@ namespace lemon { - /// \e - int LpGlpk::_addCol() { - int i=lpx_add_cols(lp, 1); - _setColLowerBound(i, -INF); - _setColUpperBound(i, INF); - return i; + LpGlpk::LpGlpk() : Parent(), + lp(lpx_create_prob()) { + ///\todo constrol function for this: + lpx_set_int_parm(lp, LPX_K_DUAL, 1); + messageLevel(0); + } + + LpGlpk::~LpGlpk() { + lpx_delete_prob(lp); + } + + int LpGlpk::_addCol() { + int i=lpx_add_cols(lp, 1); + _setColLowerBound(i, -INF); + _setColUpperBound(i, INF); + return i; + } + + int LpGlpk::_addRow() { + int i=lpx_add_rows(lp, 1); + return i; + } + + + void LpGlpk::_setRowCoeffs(int i, + int length, + const int * indices, + const Value * values ) + { + lpx_set_mat_row(lp, i, length, + const_cast(indices) , + const_cast(values)); + } + + void LpGlpk::_setColCoeffs(int i, + int length, + const int * indices, + const Value * values) + { + lpx_set_mat_col(lp, i, length, + const_cast(indices), + const_cast(values)); + } + + void LpGlpk::_setColLowerBound(int i, Value lo) + { + if (lo==INF) { + //FIXME error + } + int b=lpx_get_col_type(lp, i); + double up=lpx_get_col_ub(lp, i); + if (lo==-INF) { + switch (b) { + case LPX_FR: + case LPX_LO: + lpx_set_col_bnds(lp, i, LPX_FR, lo, up); + break; + case LPX_UP: + break; + case LPX_DB: + case LPX_FX: + lpx_set_col_bnds(lp, i, LPX_UP, lo, up); + break; + default: ; + //FIXME error + } + } else { + switch (b) { + case LPX_FR: + case LPX_LO: + lpx_set_col_bnds(lp, i, LPX_LO, lo, up); + break; + case LPX_UP: + case LPX_DB: + case LPX_FX: + if (lo==up) + lpx_set_col_bnds(lp, i, LPX_FX, lo, up); + else + lpx_set_col_bnds(lp, i, LPX_DB, lo, up); + break; + default: ; + //FIXME error + } } - /// \e - int LpGlpk::_addRow() { - int i=lpx_add_rows(lp, 1); - return i; + } + + void LpGlpk::_setColUpperBound(int i, Value up) + { + if (up==-INF) { + //FIXME error } - - - void LpGlpk::_setRowCoeffs(int i, - int length, - const int * indices, - const Value * values ) - { - lpx_set_mat_row(lp, i, length, - const_cast(indices) , - const_cast(values)); - } - - void LpGlpk::_setColCoeffs(int i, - int length, - const int * indices, - const Value * values) - { - lpx_set_mat_col(lp, i, length, - const_cast(indices), - const_cast(values)); - } - - void LpGlpk::_setColLowerBound(int i, Value lo) - { - if (lo==INF) { + int b=lpx_get_col_type(lp, i); + double lo=lpx_get_col_lb(lp, i); + if (up==INF) { + switch (b) { + case LPX_FR: + case LPX_LO: + break; + case LPX_UP: + lpx_set_col_bnds(lp, i, LPX_FR, lo, up); + break; + case LPX_DB: + case LPX_FX: + lpx_set_col_bnds(lp, i, LPX_LO, lo, up); + break; + default: ; //FIXME error } - int b=lpx_get_col_type(lp, i); - double up=lpx_get_col_ub(lp, i); - if (lo==-INF) { - switch (b) { - case LPX_FR: - case LPX_LO: - lpx_set_col_bnds(lp, i, LPX_FR, lo, up); - break; - case LPX_UP: - break; - case LPX_DB: - case LPX_FX: - lpx_set_col_bnds(lp, i, LPX_UP, lo, up); - break; - default: ; - //FIXME error - } - } else { - switch (b) { - case LPX_FR: - case LPX_LO: - lpx_set_col_bnds(lp, i, LPX_LO, lo, up); - break; - case LPX_UP: - case LPX_DB: - case LPX_FX: - if (lo==up) - lpx_set_col_bnds(lp, i, LPX_FX, lo, up); - else - lpx_set_col_bnds(lp, i, LPX_DB, lo, up); - break; - default: ; - //FIXME error - } - } - - } - - void LpGlpk::_setColUpperBound(int i, Value up) - { - if (up==-INF) { + } else { + switch (b) { + case LPX_FR: + lpx_set_col_bnds(lp, i, LPX_UP, lo, up); + break; + case LPX_UP: + lpx_set_col_bnds(lp, i, LPX_UP, lo, up); + break; + case LPX_LO: + case LPX_DB: + case LPX_FX: + if (lo==up) + lpx_set_col_bnds(lp, i, LPX_FX, lo, up); + else + lpx_set_col_bnds(lp, i, LPX_DB, lo, up); + break; + default: ; //FIXME error } - int b=lpx_get_col_type(lp, i); - double lo=lpx_get_col_lb(lp, i); - if (up==INF) { - switch (b) { - case LPX_FR: - case LPX_LO: - break; - case LPX_UP: - lpx_set_col_bnds(lp, i, LPX_FR, lo, up); - break; - case LPX_DB: - case LPX_FX: - lpx_set_col_bnds(lp, i, LPX_LO, lo, up); - break; - default: ; - //FIXME error - } - } else { - switch (b) { - case LPX_FR: - lpx_set_col_bnds(lp, i, LPX_UP, lo, up); - break; - case LPX_UP: - lpx_set_col_bnds(lp, i, LPX_UP, lo, up); - break; - case LPX_LO: - case LPX_DB: - case LPX_FX: - if (lo==up) - lpx_set_col_bnds(lp, i, LPX_FX, lo, up); - else - lpx_set_col_bnds(lp, i, LPX_DB, lo, up); - break; - default: ; - //FIXME error - } + } + } + + void LpGlpk::_setRowLowerBound(int i, Value lo) + { + if (lo==INF) { + //FIXME error + } + int b=lpx_get_row_type(lp, i); + double up=lpx_get_row_ub(lp, i); + if (lo==-INF) { + switch (b) { + case LPX_FR: + case LPX_LO: + lpx_set_row_bnds(lp, i, LPX_FR, lo, up); + break; + case LPX_UP: + break; + case LPX_DB: + case LPX_FX: + lpx_set_row_bnds(lp, i, LPX_UP, lo, up); + break; + default: ; + //FIXME error + } + } else { + switch (b) { + case LPX_FR: + case LPX_LO: + lpx_set_row_bnds(lp, i, LPX_LO, lo, up); + break; + case LPX_UP: + 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::_setRowLowerBound(int i, Value lo) - { - if (lo==INF) { - //FIXME error - } - int b=lpx_get_row_type(lp, i); - double up=lpx_get_row_ub(lp, i); - if (lo==-INF) { - switch (b) { - case LPX_FR: - case LPX_LO: - lpx_set_row_bnds(lp, i, LPX_FR, lo, up); - break; - case LPX_UP: - break; - case LPX_DB: - case LPX_FX: - lpx_set_row_bnds(lp, i, LPX_UP, lo, up); - break; - default: ; - //FIXME error - } - } else { - switch (b) { - case LPX_FR: - case LPX_LO: - lpx_set_row_bnds(lp, i, LPX_LO, lo, up); - break; - case LPX_UP: - 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::_setRowUpperBound(int i, Value up) { @@ -290,12 +299,19 @@ void LpGlpk::_setMax() { - lpx_set_obj_dir(lp, LPX_MAX); - } + lpx_set_obj_dir(lp, LPX_MAX); + } + void LpGlpk::_setMin() { - lpx_set_obj_dir(lp, LPX_MIN); - } + lpx_set_obj_dir(lp, LPX_MIN); + } + + + void LpGlpk::messageLevel(int m) + { + lpx_set_int_parm(lp, LPX_K_MSGLEV, m); + } } //END OF NAMESPACE LEMON diff -r 9863b5d51beb -r bc3a4c498eb2 src/lemon/lp_glpk.h --- a/src/lemon/lp_glpk.h Fri Apr 08 05:36:16 2005 +0000 +++ b/src/lemon/lp_glpk.h Fri Apr 08 06:33:11 2005 +0000 @@ -32,24 +32,16 @@ /// /// This class implements a lemon wrapper for GLPK. class LpGlpk : public LpSolverBase { - + protected: + LPX* lp; + public: - + typedef LpSolverBase Parent; - /// \e - LPX* lp; - - /// \e - LpGlpk() : Parent(), - lp(lpx_create_prob()) { - lpx_set_int_parm(lp, LPX_K_DUAL, 1); - } - /// \e - ~LpGlpk() { - lpx_delete_prob(lp); - } - + LpGlpk(); + ~LpGlpk(); + protected: virtual int _addCol(); virtual int _addRow(); @@ -68,36 +60,30 @@ virtual void _setObjCoeff(int i, Value obj_coef); ///\e - ///\bug Unimplemented + ///\todo It should be clarified /// virtual SolveExitStatus _solve(); - ///\e - - ///\bug Unimplemented - /// virtual Value _getPrimal(int i); - ///\e - - ///\bug Unimplemented - /// virtual Value _getPrimalValue(); ///\e - ///\bug Unimplemented + ///\todo It should be clarified /// virtual SolutionStatus _getPrimalStatus(); + virtual void _setMax(); + virtual void _setMin(); - ///\e + public: + ///Set the verbosity of the messages + + ///\param m is the level of the messages output by the solver routines. + ///The possible values are: + ///- 0 --- no output (default value) + ///- 1 --- error messages only + ///- 2 --- normal output + ///- 3 --- full output (includes informational messages) + void messageLevel(int m); - ///\bug Unimplemented - /// - virtual void _setMax(); - ///\e - - ///\bug Unimplemented - /// - virtual void _setMin(); - }; } //END OF NAMESPACE LEMON