Skip to content
Advertisement

Gurobi – Is there a way to access the lazy constraints pool?

I have searched through all Gurobi’s PDF documentation and could not find what I am searching. I would like to know if there is a way to access the lazy constraints pool in Gurobi during the search?

In a MIP_NODE, during a callback at an integer node, GRB_CB_MIPSOL, I need to access all the previously generated lazy constraints and apply them to some values. I could not find a way to access the lazy constraints pool. My current workaround is to store all the lazy constraints I am generating in an array but that sounds a very poor way to me, especially in terms of RAM. And it is a pity to store them if we can directly access them as we know Gurobi stores them too.

            con = @build_constraint(λ ≥ sum([2(1-y[i])α[i] for i in V]) +
                sum([(x[mima(β[j][1],j)] + x[mima(β[j][2],j)] - 1)rp[mima(β[j][1],β[j][2])] for j in tildeV if length(β[j]) > 0]) - sum([y[j]γ[i,j] for i in V, j in V if i != j]))
                MOI.submit(m, MOI.LazyConstraint(cb_data), con)

                    function RHS_opt_cut(x,y)
                        sum_β = 0
                        for j in tildeV
                            if length(β[j]) > 0
                                sum_β += (x[mima(β[j][1],j)...] + x[mima(β[j][2],j)...] - 1)rp[mima(β[j][1],β[j][2])]
                            end
                        end
                        sum([2(1-y[i])α[i] for i in V]) + sum_β - sum([y[j]γ[i,j] for i in V, j in V if i != j])
                    end

                    push!(RHS_optimality_cuts, RHS_opt_cut)

Earlier in the code, testing all the previously stored RHS

            λ_two_opt = 0.
                for RHS in RHS_optimality_cuts
                    if RHS(x_two_opt, ŷ) > λ_two_opt
                        λ_two_opt = RHS(x_two_opt, ŷ)
                    end
                end

Advertisement

Answer

No, I don’t think there is a way to get the list of lazy constraints that have been added. Maintaining a list is the easiest solution.

But you should be very careful, just because you previously added a constraint, it doesn’t mean that the constraint is currently being used, or that the solution satisfies all previous lazy constraints. The only guarantee is that the final solution will respect all lazy constraints that were added.

p.s., If you’re using Julia, you can call anything in the C API: https://www.gurobi.com/documentation/9.5/refman/c_api_details.html

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement