# HG changeset patch # User athos # Date 1118310588 0 # Node ID 7a483c1d38b502e2d64210be1c27ad166685b4da # Parent be025fc1b13df64a92e55f2dc19f29e46205e613 Not ready, but I commit it for simplicity. diff -r be025fc1b13d -r 7a483c1d38b5 lemon/lp_base.h --- a/lemon/lp_base.h Thu Jun 09 09:47:51 2005 +0000 +++ b/lemon/lp_base.h Thu Jun 09 09:49:48 2005 +0000 @@ -108,11 +108,13 @@ public: - ///\e + ///Possible outcomes of an LP solving procedure enum SolveExitStatus { - ///\e + ///This means that the problem has been successfully solved: either + ///an optimal solution has been found or infeasibility/unboundedness + ///has been proved. SOLVED = 0, - ///\e + ///Any other case (including the case when some user specified limit has been exceeded) UNSOLVED = 1 }; @@ -915,7 +917,11 @@ ///@{ - ///\e + ///\e Solve the LP problem at hand + /// + ///\return The result of the optimization procedure. Possible values and their meanings can be found in the documentation of \ref SolveExitStatus. + /// + ///\todo Which method is used to solve the problem SolveExitStatus solve() { return _solve(); } ///@} @@ -924,7 +930,7 @@ ///@{ - ///\e + ///\e SolutionStatus primalStatus() { return _getPrimalStatus(); } diff -r be025fc1b13d -r 7a483c1d38b5 lemon/lp_cplex.cc --- a/lemon/lp_cplex.cc Thu Jun 09 09:47:51 2005 +0000 +++ b/lemon/lp_cplex.cc Thu Jun 09 09:49:48 2005 +0000 @@ -25,7 +25,6 @@ // env = CPXopenCPLEXdevelop(&status); env = CPXopenCPLEX(&status); lp = CPXcreateprob(env, &status, "LP problem"); - //CPXmsg (cpxresults, "Hello-bello\n"); } LpCplex::~LpCplex() { @@ -230,93 +229,123 @@ } } - + // The routine returns zero unless an error occurred during the + // optimization. Examples of errors include exhausting available + // memory (CPXERR_NO_MEMORY) or encountering invalid data in the + // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a + // user-specified CPLEX limit, or proving the model infeasible or + // unbounded, are not considered errors. Note that a zero return + // value does not necessarily mean that a solution exists. Use query + // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain + // further information about the status of the optimization. LpCplex::SolveExitStatus LpCplex::_solve() { - + //CPX_PARAM_LPMETHOD status = CPXlpopt (env, lp); if (status == 0){ - return SOLVED; + //We want to exclude some cases + switch (CPXgetstat (env, lp)){ + case CPX_OBJ_LIM: + case CPX_IT_LIM_FEAS: + case CPX_IT_LIM_INFEAS: + case CPX_TIME_LIM_FEAS: + case CPX_TIME_LIM_INFEAS: + return UNSOLVED; + default: + return SOLVED; + } } else{ return UNSOLVED; } -// int i= lpx_simplex(lp); -// switch (i) { -// case LPX_E_OK: -// return SOLVED; -// break; -// default: -// return UNSOLVED; -// } } - LpCplex::SolutionStatus LpCplex::_getPrimalStatus() - { -//7.5-os cplex statusai -// #define CPX_OPTIMAL 1 -// #define CPX_INFEASIBLE 2 -// #define CPX_UNBOUNDED 3 -// #define CPX_OBJ_LIM 4 -// #define CPX_IT_LIM_FEAS 5 -// #define CPX_IT_LIM_INFEAS 6 -// #define CPX_TIME_LIM_FEAS 7 -// #define CPX_TIME_LIM_INFEAS 8 -// #define CPX_NUM_BEST_FEAS 9 -// #define CPX_NUM_BEST_INFEAS 10 -// #define CPX_OPTIMAL_INFEAS 11 -// #define CPX_ABORT_FEAS 12 -// #define CPX_ABORT_INFEAS 13 -// #define CPX_ABORT_DUAL_INFEAS 14 -// #define CPX_ABORT_PRIM_INFEAS 15 -// #define CPX_ABORT_PRIM_DUAL_INFEAS 16 -// #define CPX_ABORT_PRIM_DUAL_FEAS 17 -// #define CPX_ABORT_CROSSOVER 18 -// #define CPX_INForUNBD 19 -// #define CPX_PIVOT 20 +//7.5-os cplex statusai (Vigyazat: a 9.0-asei masok!) +// This table lists the statuses, returned by the CPXgetstat() routine, for solutions to LP problems or mixed integer problems. If no solution exists, the return value is zero. + +// For Simplex, Barrier +// 1 CPX_OPTIMAL +// Optimal solution found +// 2 CPX_INFEASIBLE +// Problem infeasible +// 3 CPX_UNBOUNDED +// Problem unbounded +// 4 CPX_OBJ_LIM +// Objective limit exceeded in Phase II +// 5 CPX_IT_LIM_FEAS +// Iteration limit exceeded in Phase II +// 6 CPX_IT_LIM_INFEAS +// Iteration limit exceeded in Phase I +// 7 CPX_TIME_LIM_FEAS +// Time limit exceeded in Phase II +// 8 CPX_TIME_LIM_INFEAS +// Time limit exceeded in Phase I +// 9 CPX_NUM_BEST_FEAS +// Problem non-optimal, singularities in Phase II +// 10 CPX_NUM_BEST_INFEAS +// Problem non-optimal, singularities in Phase I +// 11 CPX_OPTIMAL_INFEAS +// Optimal solution found, unscaled infeasibilities +// 12 CPX_ABORT_FEAS +// Aborted in Phase II +// 13 CPX_ABORT_INFEAS +// Aborted in Phase I +// 14 CPX_ABORT_DUAL_INFEAS +// Aborted in barrier, dual infeasible +// 15 CPX_ABORT_PRIM_INFEAS +// Aborted in barrier, primal infeasible +// 16 CPX_ABORT_PRIM_DUAL_INFEAS +// Aborted in barrier, primal and dual infeasible +// 17 CPX_ABORT_PRIM_DUAL_FEAS +// Aborted in barrier, primal and dual feasible +// 18 CPX_ABORT_CROSSOVER +// Aborted in crossover +// 19 CPX_INForUNBD +// Infeasible or unbounded +// 20 CPX_PIVOT +// User pivot used +// // Ezeket hova tegyem: // ??case CPX_ABORT_DUAL_INFEAS // ??case CPX_ABORT_CROSSOVER // ??case CPX_INForUNBD // ??case CPX_PIVOT + LpCplex::SolutionStatus LpCplex::_getPrimalStatus() + { int stat = CPXgetstat (env, lp); switch (stat) { case 0: return UNDEFINED; //Undefined - break; case CPX_OPTIMAL://Optimal return OPTIMAL; - break; case CPX_UNBOUNDED://Unbounded return INFINITE; - break; case CPX_INFEASIBLE://Infeasible - case CPX_IT_LIM_INFEAS: - case CPX_TIME_LIM_INFEAS: - case CPX_NUM_BEST_INFEAS: - case CPX_OPTIMAL_INFEAS: - case CPX_ABORT_INFEAS: - case CPX_ABORT_PRIM_INFEAS: - case CPX_ABORT_PRIM_DUAL_INFEAS: + // case CPX_IT_LIM_INFEAS: +// case CPX_TIME_LIM_INFEAS: +// case CPX_NUM_BEST_INFEAS: +// case CPX_OPTIMAL_INFEAS: +// case CPX_ABORT_INFEAS: +// case CPX_ABORT_PRIM_INFEAS: +// case CPX_ABORT_PRIM_DUAL_INFEAS: return INFEASIBLE; - break; - case CPX_OBJ_LIM: - case CPX_IT_LIM_FEAS: - case CPX_TIME_LIM_FEAS: - case CPX_NUM_BEST_FEAS: - case CPX_ABORT_FEAS: - case CPX_ABORT_PRIM_DUAL_FEAS: - return FEASIBLE; - break; +// case CPX_OBJ_LIM: +// case CPX_IT_LIM_FEAS: +// case CPX_TIME_LIM_FEAS: +// case CPX_NUM_BEST_FEAS: +// case CPX_ABORT_FEAS: +// case CPX_ABORT_PRIM_DUAL_FEAS: +// return FEASIBLE; default: return UNDEFINED; //Everything else comes here //FIXME error } + } - //Nem tudom, hanyas cplex verzio statusai +//9.0-as cplex verzio statusai // CPX_STAT_ABORT_DUAL_OBJ_LIM // CPX_STAT_ABORT_IT_LIM // CPX_STAT_ABORT_OBJ_LIM @@ -333,26 +362,20 @@ // CPX_STAT_OPTIMAL_RELAXED // CPX_STAT_UNBOUNDED -// int stat = CPXgetstat (env, lp); -// switch (stat) { -// case CPX_STAT_OPTIMAL://Optimal -// return OPTIMAL; -// break; -// case CPX_STAT_INFEASIBLE://Infeasible -// return INFEASIBLE; -// break; -// case CPX_STAT_UNBOUNDED://Unbounded -// return INFINITE; -// break; -// case CPX_STAT_NUM_BEST://Feasible -// return FEASIBLE; -// break; -// default: -// return UNDEFINED; //Everything else comes here -// //FIXME error -// } - - } + LpCplex::SolutionStatus LpCplex::_getDualStatus() + { + int stat = CPXgetstat (env, lp); + switch (stat) { + case 0: + return UNDEFINED; //Undefined + case CPX_OPTIMAL://Optimal + return OPTIMAL; + case CPX_UNBOUNDED: + return INFEASIBLE; + default: + return UNDEFINED; //Everything else comes here + //FIXME error + } LpCplex::Value LpCplex::_getPrimal(int i) { diff -r be025fc1b13d -r 7a483c1d38b5 lemon/lp_glpk.cc --- a/lemon/lp_glpk.cc Thu Jun 09 09:47:51 2005 +0000 +++ b/lemon/lp_glpk.cc Thu Jun 09 09:49:48 2005 +0000 @@ -396,11 +396,10 @@ LpGlpk::SolveExitStatus LpGlpk::_solve() { - int i= lpx_simplex(lp); + int i = lpx_simplex(lp); switch (i) { case LPX_E_OK: return SOLVED; - break; default: return UNSOLVED; } @@ -423,6 +422,54 @@ switch (stat) { case LPX_UNDEF://Undefined (no solve has been run yet) return UNDEFINED; + case LPX_NOFEAS://There is no feasible solution (primal, I guess) + case LPX_INFEAS://Infeasible + return INFEASIBLE; + case LPX_UNBND://Unbounded + return INFINITE; + case LPX_FEAS://Feasible + return FEASIBLE; + case LPX_OPT://Feasible + return OPTIMAL; + default: + return UNDEFINED; //to avoid gcc warning + //FIXME error + } + } + + LpGlpk::SolutionStatus LpGlpk::_getDualStatus() + { + int stat= lpx_get_dual_stat(lp); + switch (stat) { + case LPX_D_UNDEF://Undefined (no solve has been run yet) + return UNDEFINED; + case LPX_D_NOFEAS://There is no feasible solution (primal, I guess) + case LPX_D_INFEAS://Infeasible + return INFEASIBLE; + case LPX_FEAS://Feasible + int stat2= lpx_get_prim_stat(lp); + switch (stat2){ + case LPX_P_NOFEAS: + return INFINITE; + case LPX_OPT: + return OPTIMAL; + default: + return FEASIBLE; + } + default: + return UNDEFINED; //to avoid gcc warning + //FIXME error + } + } + + LpGlpk::ProblemTypes LpGlpk::_problemType() + { + int stat= lpx_get_status(lp); + int statp= lpx_get_prim_stat(lp); + int statd= lpx_get_dual_stat(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 @@ -443,7 +490,6 @@ } } - void LpGlpk::_setMax() { lpx_set_obj_dir(lp, LPX_MAX);