Greetings.
This thread is related to this one. I am trying to use user-cut with JuMP 0.21.4, Julia 1.6.2, and CPLEX 12.10. Below follows the code I am running.
using JuMP, CPLEX
model = direct_model(CPLEX.Optimizer())
MOI.set(model, MOI.NumberOfThreads(), 1)
@variable(model, 0 <= x <= 2.5)
@variable(model, 0 <= y <= 2.5, Int)
@objective(model, Max, x + y)
function my_callback_function(cb_data::CPLEX.CallbackContext, context_id::Clong)
# preliminary checkings
context_id != CPX_CALLBACKCONTEXT_CANDIDATE && return
ispoint_p = Ref{CPXINT}()
(CPXcallbackcandidateispoint(cb_data, ispoint_p) != 0 || ispoint_p[] == 0) && return
# get values
CPLEX.load_callback_variable_primal(cb_data, context_id)
x_val, y_val = callback_value(cb_data, x), callback_value(cb_data, y)
# check if the values are integers
(abs(x_val - floor(x_val + 0.5)) <= 1e-3 && abs(y_val - floor(y_val + 0.5)) <= 1e-3) && return
# add user cut
MOI.submit(model, MOI.UserCut(cb_data), @build_constraint(x + y <= 2))
end
MOI.set(model, CPLEX.CallbackFunction(), my_callback_function)
optimize!(model)
However, I am facing the following error:
CPLEX Error 1811: Attempt to invoke unsupported operation
Specifically, when x = 2.5
and y = 2
, i.e. when the command MOI.submit(model, MOI.UserCut(cb_data), @build_constraint(x + y <= 2))
is executed. I also tried commenting the command context_id != CPX_CALLBACKCONTEXT_CANDIDATE && return
, which led to the same result. I would like to know if anyone already used user-cuts with CPLEX.
Thank you for your time.