# Callback jump MOI interface lazy constraints are not cutting the solution properly

**URL:** <https://discourse.julialang.org/t/callback-jump-moi-interface-lazy-constraints-are-not-cutting-the-solution-properly/79227>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization, lazy-constraint\
**Created:** [April 8, 2022, 2:20pm UTC](https://discourse.julialang.org/t/callback-jump-moi-interface-lazy-constraints-are-not-cutting-the-solution-properly/79227 "2022-04-08T14:20:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)\
**Post date:** [April 8, 2022, 2:20pm UTC](https://discourse.julialang.org/t/callback-jump-moi-interface-lazy-constraints-are-not-cutting-the-solution-properly/79227/1 "2022-04-08T14:20:19Z")

</div>

Hey there, can anyone please help me?

I am trying to solve a combinatorial optimization problem through lazy constraints using Gurobi as Solver. Bellow a code of my presets and variables:

```julia
model = Model(Gurobi.Optimizer)
set_optimizer_attribute(model, "LazyConstraints", 1) 
@variables(model, begin
    x[i=1:(n-1), j=(i+1):n], Bin 
    y[i=1:(n-1), j=(i+1):n], Bin 
end)
.
.
.
MOI.set(model, MOI.LazyConstraintCallback(), my_callback_function_lazy)
optimize!(model)

```

My callback function identifies violated cliques and we cut off some of these solutions. After identifying them, I set the lazy constraints through MOI build constraint, as follows:

```julia
con = @build_constraint(sum(x[k[1],k[2]] for k in expr) <= (r*(r-1))/2-1)
println(con)
MOI.submit(model, MOI.LazyConstraint(cb_data), con)

```

As we can see, I tried to print out the constraints added in the model to control which one is entering as lazy constraint. An example printed:

```julia
ScalarConstraint{AffExpr, MathOptInterface.LessThan{Float64}}(x[3,4] + x[1,4] + x[1,3], MathOptInterface.LessThan{Float64}(2.0))

```

I.e., x[3,4] + x[1,4] + x[1,3] \<= 2. As metioned before, x is a binary variable, so in that case, I force the three of them to not be at the same time in the solution. However, in the final solution, we have

x[3,4] = 1  
x[1,4] = 1  
x[1,3] = 1

I don’t know what else to think to fix this. Can you help me?

Ps.: In the Gurobi log they are supposedly being added

```julia
Cutting planes:
  Lazy constraints: 91

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 8, 2022, 10:50pm UTC](https://discourse.julialang.org/t/callback-jump-moi-interface-lazy-constraints-are-not-cutting-the-solution-properly/79227/2 "2022-04-08T22:50:50Z")

</div>

Can you provide a reproducible example?
