Gurobi Error 10005 is seen on submitting lazy constraint also when cb_where == GRB_CB_MIPNODE

WalterMadelim
Sat, 17 May 2025 13:04:26 +0000
Optimization (Mathematical)

My code (full and runnable) is

import LinearAlgebra.dot as dot
import LinearAlgebra.norm as norm
import JuMP, Gurobi, Random
function my_callback_function(cb_data, cb_where::Cint)
    if cb_where == Gurobi.GRB_CB_MIPSOL # || cb_where == Gurobi.GRB_CB_MIPNODE
        Gurobi.load_callback_variable_primal(cb_data, cb_where)
        for i in Random.shuffle(1:N), j in Random.shuffle(1:N)
            vx = JuMP.callback_value(cb_data, x[i])
            vy = JuMP.callback_value(cb_data, y[j])
            vz = JuMP.callback_value(cb_data, z[i, j])
            if vz > vx + COT
                JuMP.MOI.submit(m, JuMP.MOI.LazyConstraint(cb_data),
                    JuMP.@build_constraint(z[i, j] <= x[i])
                );  return
            elseif vz > vy + COT
                JuMP.MOI.submit(m, JuMP.MOI.LazyConstraint(cb_data),
                    JuMP.@build_constraint(z[i, j] <= y[j])
                );  return
            elseif vz < vx + vy - 1 - COT
                JuMP.MOI.submit(m, JuMP.MOI.LazyConstraint(cb_data),
                    JuMP.@build_constraint(z[i, j] >= x[i] + y[j] - 1)
                );  return
            end
        end
    end
end
const COT = 1e-6;
N = 10;
Random.seed!(1)
Q = rand(-1:.0017:1, N, N);
m = JuMP.Model(Gurobi.Optimizer);
JuMP.@variable(m, 0 <= x[1:N] <= 1, Bin);
JuMP.@variable(m, 0 <= y[1:N] <= 1, Bin);
JuMP.@variable(m, 0 <= z[1:N, 1:N] <= 1);
JuMP.@objective(m, Min, dot(Q, z));
JuMP.set_attribute(m, "LazyConstraints", 1);
JuMP.MOI.set(m, Gurobi.CallbackFunction(), my_callback_function);
JuMP.optimize!(m)
JuMP.assert_is_solved_and_feasible(m; allow_local = false)
norm(JuMP.value.(x) * JuMP.value.(y)' - JuMP.value.(z)) == 0 && @info "test success!"

The situation is:
if you run this code, you will see “test success!”.
However, if you remove that # on line 5, you will see ERROR: Gurobi Error 10005: after calling JuMP.optimize!(m).

FYI Here is the Gurobi’s doc ErrorCode And GRBcblazy.

I can’t fathom what is happening.
Further Reading: Background of this case (click for more details)
3 posts - 2 participants