CVXR icon indicating copy to clipboard operation
CVXR copied to clipboard

Fix GUROBI status map

Open klin333 opened this issue 2 years ago • 2 comments

Fixes issue #99

Looking at the Gurobi docs, there are status codes which indicate user limits reached. It appears to me suboptimal solution may and often exist in these cases. https://www.gurobi.com/documentation/6.5/refman/optimization_status_codes.html#sec:StatusCodes

I played around with these Gurobi user limits, and indeed when time, iteration and solution limits are hit (in my single test case of a mixed integer programming problem), suboptimal solutions are returned from Gurobi solver, and can be successfully unpacked by CVXR.

I suggest we relax what CVXR considers suboptimal solutions to include these user limit solutions. I made the change for GUROBI_CONIC as well, though I didn't bother testing that.

I did not use USER_LIMIT for these user limits status codes because USER_LIMIT is not included in SOLUTION_PRESENT, which would have caused no solution unpacking. I'm not sure if it's wise to add USER_LIMIT to SOLUTION_PRESENT, so I did not use USER_LIMIT.

klin333 avatar Nov 19 '21 00:11 klin333

@bnaras hi, any chance you can review this super simple PR. It's very important to me

klin333 avatar Jan 17 '22 22:01 klin333

@bnaras hi, any chance you can review this super simple PR. It's very important to me

Sorry this is a bit late, but please see the branch WIP_gurobi_solver_status. That implements a more general solution and provides descriptive messages; for example:

> result <- solve(problem, solver = "GUROBI")
> result$status
[1] "optimal"
attr(,"gurobi_status_code")
[1] "OPTIMAL"
attr(,"gurobi_status_desc")
[1] "Model was solved to optimality (subject to tolerances), and an optimal solution is available."

> result <- solve(problem, solver = "GUROBI", TimeLimit=1) ## optional valid parameter
> result$status
[1] "optimal"
attr(,"gurobi_status_code")
[1] "OPTIMAL"
attr(,"gurobi_status_desc")
[1] "Model was solved to optimality (subject to tolerances), and an optimal solution is available."

> result <- solve(problem, solver = "GUROBI", TimeLimit=0) ## optional valid parameter that should not proceed
> result$status
[1] "user_limit"
attr(,"gurobi_status_code")
[1] "TIME_LIMIT"
attr(,"gurobi_status_desc")
[1] "Optimization terminated because the time expended exceeded the value specified in the TimeLimit parameter."

> result <- solve(problem, solver = "GUROBI", TimeLimit1=1) ## optional INVALID parameter
Error in status_map(object, solution$status) : 
  GUROBI status unrecognized: SOLVER_ERROR

bnaras avatar Feb 15 '23 02:02 bnaras