jump-dev / CPLEX.jl

A Julia interface to the CPLEX solver
https://www.ibm.com/products/ilog-cplex-optimization-studio
MIT License
134 stars 63 forks source link

MOI.NUMERICAL_ERROR when solving quadratic problems #413

Closed ZacharieALES closed 1 year ago

ZacharieALES commented 1 year ago

I am solving the linear relaxation of mixed integer convex quadratic problems with CPLEX v12.10 and CPLEX.jl v0.9.3. Even if all the problems are feasibles I sometime get no solution and the termination status is "MOI.NUMERICAL_ERROR". 

To give you more details, I am implementing a cutting plane algorithm. Consequently, all these problems correspond to the linear relaxation of the same initial problem to which I stochastically add valid inequalities. Sometimes, everything works fine and sometime I get the numerical error.

To investigate further I wanted to print one of the models which lead to an error in an lp file but this is not possible since it has quadratic constraints.

Do you know if this problem could come from CPLEX or if it could be due to the CPLEX.jl package? Do you know if there are ways to avoid it?

odow commented 1 year ago

Do you know if this problem could come from CPLEX or if it could be due to the CPLEX.jl package?

It's from CPLEX.

CPLEX.jl just tells us whatever the upstream CPLEX says. In this case, MOI.NUMERICAL_ERROR corresponds to: https://github.com/jump-dev/CPLEX.jl/blob/ae25b29fbab0685d78fbbfb86d3bd2075f211471/src/MOI/MOI_wrapper.jl#L2752

https://www.ibm.com/docs/en/icos/12.9.0?topic=api-cpx-stat-num-best

The description of which is: Solution is available, but not proved optimal, due to numeric difficulties during optimization.

Do you know if there are ways to avoid it?

You could try setting the CPXPARAM_Emphasis_Numerical parameter: https://www.ibm.com/docs/en/icos/12.9.0?topic=parameters-numerical-precision-emphasis

using JuMP, CPLEX
model = Model(CPLEX.Optimizer)
set_optimizer_attribute(model, "CPXPARAM_Emphasis_Numerical", 1)

Otherwise, try a different solver (like Gurobi).

ZacharieALES commented 1 year ago

Thank you for the precisions. Setting the parameter to 1 does not seem to be enough to avoid the error.

You mention that when this error occurs, a solution is available but maybe not an optimal one. Do you know if it is possible to have access to it? It could be enough for me.

odow commented 1 year ago

Do you know if it is possible to have access to it?

Check primal_status(model) to see if it is FEASIBLE_POINT.

ZacharieALES commented 1 year ago

I get MOI.NO_SOLUTION so I guess not. I will try to change the tolerance. Thanks again for the help.

odow commented 1 year ago

I am solving the linear relaxation of mixed integer convex quadratic problems To give you more details, I am implementing a cutting plane algorithm.

Have you tried https://github.com/jump-dev/Pavito.jl?

odow commented 1 year ago

Closing because this is not a bug in CPLEX.jl.

If you have more questions, please post on the community forum, https://discourse.julialang.org/c/domain/opt/13, and we can keep discussing.

One thing I have found useful when I encounter errors like this is to reset the optimizer: https://github.com/odow/SDDP.jl/blob/c1e465960cf07a624a040d53c811154b165ade1d/src/algorithm.jl#L261-L270

optimize!(model)
if termination_status(model) != OPTIMAL
    MOI.Utilities.reset_optimizer(model)
    optimize!(model)
end
if termination_status(model) != OPTIMAL
    # Now I have no idea...
end

It clears any previously cached solutions and forces the optimizer to start again, which is often helpful.