Lazy Constraints on MIP problems

Hello all,
I am trying trying to solve the following MIP with the Xpress solver (and I’ve also tried it with the GLPK solver) with lazy constraint. Variables of interest are x and y (non-integer), integer variable z is only added in order to force the solver to solve a MIP, since, for what I understand, for LPs lazy constraints are ignored.

I have tried to solve it in a variety of different ways and formulations, but the solver seems to freeze (as it appears on its log file) when adding the lazy constraint. Does anyone know how this issue can be resolved?

Thank you in advance for the help,

using Pkg
Pkg.instantiate()
Pkg.activate(“.”)
Pkg.resolve()
using JuMP
using Xpress
using MathOptInterface
model = Model(()->Xpress.Optimizer(THREADS = 2))
variable(model, x >= 0)
variable(model, y >= 0)
variable(model, z >= 0, Int)
variable(model, FO >= 0)
constraint(model, FO == x + y )
constraint(model, x <= 1 )
constraint(model, y <= 1 )
objective(model, Max, FO)
function lazy_flow_constraints(cb_data)
x_val = callback_value(cb_data,x)
y_val = callback_value(cb_data,y)
if x_val + y_val > 1
con = build_constraint( (x + y)/sqrt(2) <= 1 )
MOI.submit(model, MOI.LazyConstraint(cb_data), con)
end
end

MOI.set(model, MOI.LazyConstraintCallback(), lazy_flow_constraints)
set_optimizer_attributes(model, “HEURSTRATEGY” => 0)
set_optimizer_attributes(model, “MIPDUALREDUCTIONS” => 0)
optimize!(model)
info(" Execution is " * string(termination_status(model)))
println(“x=”,JuMP.value(x))
println(“y=”,JuMP.value(y))

In the documentation, you’ll find a warning saying Only add a lazy constraint if your primal solution violates the constraint.

I am isolating the potential region from your code:

function lazy_flow_constraints(cb_data)
    ...
    if x_val + y_val > 1
        con = build_constraint( (x + y)/sqrt(2) <= 1 )
        MOI.submit(model, MOI.LazyConstraint(cb_data), con)
    end
end

I think x_val + y_val > 1 and (x + y)/sqrt(2) <= 1 are not respecting the stated rule.

1 Like

In other words, you should test for (x_val + y_val)/sqrt(2) > 1 instead of x_val + y_val > 1 in the if condition.

1 Like