Setting constraints as lazy with JuMP 0.19 and Gurobi

I build a mixed-integer model with JuMP and Gurobi. I want to set certain constraints as lazy. With JuMP 0.18 I was using the solution described here: https://github.com/JuliaOpt/JuMP.jl/issues/1226

Now I am using JuMP 0.19 and I cannot find information on how to achieve the same thing. Is it currently possible? If not, what would it take?

1 Like

See https://github.com/JuliaOpt/Gurobi.jl/blob/f7332cbd2881fa0f776776de2cceabfb7b97f750/test/MOI_wrapper.jl#L106-L198 for examples and https://github.com/JuliaOpt/Gurobi.jl/pull/194, https://github.com/JuliaOpt/MathOptInterface.jl/pull/670 for future directions

1 Like

Thank you. This seems to be about adding lazy cuts from a callback. I was referring to adding lazy constraints when creating a model, which is a different (although similar) concept, and which does not rely on the concept of callback.

Edit for clarity: by that I mean that lazy constraints do not require to write an additional callback, Gurobi handles them. Ideally, adding Lazy=true when creating a constraint could tell Gurobi that this constraint is lazy.

Since you know that you’re using Gurobi, you should use JuMP in direct-mode. The new syntax would be:

model = JuMP.direct_model(Gurobi.Optimizer())
@variable(model, x >= 0)
@constraint(model, c, 2x >= 1)
grb = JuMP.backend(model)
row = grb[JuMP.index(c)]
Gurobi.set_intattrelement!(grb.inner, "Lazy", row, 3)

If you use this a lot, it’d be a nice contribution to add this as a MOI attribute, similar to the in-progress IIS: https://github.com/JuliaOpt/Gurobi.jl/pull/208

Then the syntax would be

model = Modle(with_optimizer(Gurobi.Optimizer))
@variable(model, x >= 0)
@constraint(model, c, 2x >= 1)
MOI.set(model, Gurobi.Lazy(), c, 3)

or even

model = Modle(with_optimizer(Gurobi.Optimizer))
@variable(model, x >= 0)
@constraint(model, c, 2x >= 1)
MOI.set(model, Gurobi.ConstraintAttribute("lazy"), c, 3)

Let me know, and we can point you in the right direction.

2 Likes

Thank you, this works!

I would like to add this as a MOI attribute, where do I start?

1 Like

I’ve opened an issue with some pointers: https://github.com/JuliaOpt/Gurobi.jl/issues/211

Let’s continue the discussion there.

What are the equivalent steps for the Lazy constraints generation that is described in the “Lazy Constraints” section of http://www.juliaopt.org/JuMP.jl/0.18/callbacks.html#lazy-constraints?

We’re still in the process of re-introducing callbacks into JuMP 0.19. For now, if you need callbacks, stick with JuMP 0.18.