Gurobi Lazyconstraints with JuMP 0.21

Hi,
I am transferring some codes from old package versions (Julia 0.64, JuMP 0.18, Gurobi 8.5) to current environment. But I got some problems with one using lazyconstraints.

In the old environment, the problem was solved with 22 lazyconstraints added in about one and half hours. Currently, I am using Julia 1.2, JuMP 0.21, Gurboi 9.0. More than 15 thousand lazyconstraints were added in two hours and the problem was unsolved.

I didn’t find too much about callbacks in JuMP documents and examples. So I was wondering if there is anything changed in the newest version of JuMP, like when the callback functions are called, and if there is any parameters to control the callback functions. Below is a simple example showing how I use callback functions.

Thanks for your attention.

 using JuMP,Gurobi
 env = Gurobi.Env()
 
 model = Model(optimizer_with_attributes(() -> Gurobi.Optimizer(env), "OutputFlag" => 0, "LazyConstraints" => 1))
 @variable(model, x <= 10, Int)
 @objective(model, Max, x)
 function my_callback_function(cb_data)
     x_val = callback_value(cb_data, x)
     if x_val > 2 + 1e-6
         con = @build_constraint(x <= 2)
         MOI.submit(model, MOI.LazyConstraint(cb_data), con)
     end
 end
 MOI.set(model, MOI.LazyConstraintCallback(), my_callback_function)
 optimize!(model)

One reason is that we now call the lazy constraint at fractional nodes in the graph.

If you want more control, you could either check that x is integer, or use a solver-dependent callback. These aren’t well documented, but here is the Gurobi commands (Just replace things like MOI.get(model, MOI.CallbackVariablePrimal(), x) with callback_value(cb_data, x).

But it’s impossible to offer more advice without the actual code.

Some things you could check:

  • Are you adding 15,000 unique constraints? Or are you adding lots of identical constraints? If it’s the latter, you probably have the wrong tolerances.
  • What happens if you manually add the 22 constraints from JuMP 0.18?
1 Like

Thank you so much for your reply and explanation! I believe only calling the callback function at integer nodes should fix my problem. I will try to modify my codes with solver-dependent callback as you suggested. I really appreciate your help.