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: Lazy constraints at root node? · Issue #1226 · jump-dev/JuMP.jl · GitHub

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 Gurobi.jl/MOI_wrapper.jl at f7332cbd2881fa0f776776de2cceabfb7b97f750 · jump-dev/Gurobi.jl · GitHub for examples and https://github.com/JuliaOpt/Gurobi.jl/pull/194, DNMY: add solver-independent(-ish) callbacks by odow · Pull Request #670 · jump-dev/MathOptInterface.jl · GitHub 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: Compute IIS by dourouc05 · Pull Request #208 · jump-dev/Gurobi.jl · GitHub

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: [MOI] Set Gurobi-specific attributes · Issue #211 · jump-dev/Gurobi.jl · GitHub

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 Solver Callbacks — JuMP -- Julia for Mathematical Optimization 0.18 documentation?

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.