# Add local and purgeable cuts in CPLEX

**URL:** <https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378>\
**Category:** Optimization (Mathematical)\
**Tags:** cplex\
**Created:** [May 25, 2023, 12:34pm UTC](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378 "2023-05-25T12:34:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zacharie\_ALES](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zacharie_ales/32/11144_2.png) [@Zacharie\_ALES](https://discourse.julialang.org/u/Zacharie_ALES)\
**Post date:** [May 25, 2023, 12:34pm UTC](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378/1 "2023-05-25T12:34:33Z")

</div>

I am using CPLEX.jl and I add cuts in a callback with this syntax:

```
        con = @build_constraint(x <= 0)
        MOI.submit(myModel, MOI.UserCut(cb_data), con)

```

CPLEX library normally has several parameters when adding a cut that I would like to change (ex: the fact that the cut is purgeable or not, the fact that it is local to this branch or global to the whole tree).

To change these parameters, I would like to adapt the MOI.submit method. I tried to find its definition but the only one I found is the following one:

```
        function MOI.submit(
            model::Optimizer,
            cb::MOI.LazyConstraint{CallbackContext},
            f::MOI.ScalarAffineFunction{Float64},
            s::Union{
                MOI.LessThan{Float64},
                MOI.GreaterThan{Float64},
                MOI.EqualTo{Float64},
            },
        )

```

Unfortunately, this is not the method called when I use MOI.submit since the arguments types and number do not match. I tried to copy/paste it anyway just to be sure. I named the new method “mySubmit” but as expected, when I try to use it I get an error:

```
            ERROR: MethodError: no method matching mySubmit(::Model, ::MathOptInterface.LazyConstraint{CPLEX.CallbackContext}, ::ScalarConstraint{AffExpr, MathOptInterface.LessThan{Float64}})
            Closest candidates are:
              mySubmit(::CPLEX.Optimizer, ::MathOptInterface.LazyConstraint{CPLEX.CallbackContext}, ::MathOptInterface.ScalarAffineFunction{Float64}, ::Union{MathOptInterface.EqualTo{Float64}, MathOptInterface.GreaterThan{Float64}, MathOptInterface.LessThan{Float64}}) at /home/zach/Test/dummy_cb_ex.jl:79

```

Two of the arguments do not have the correct type:

- the first one is “Model” instead of “CPLEX.Optimizer”;
- the third one which defines the constraint.

Do you know where I can find the definition of the method called when I use MOI.submit? If it is the one I found, could you tell me why it does not work? I am a bit lost here…

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [May 25, 2023, 12:45pm UTC](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378/2 "2023-05-25T12:45:36Z")

</div>

> [@Zacharie\_ALES](#):
>
> Do you know where I can find the definition of the method called when I use MOI.submit?

Without answering your specific question, you can generally use the Julia macro `@which` before your function call to return this information:  
[https://docs.julialang.org/en/v1/stdlib/InteractiveUtils/#InteractiveUtils.@which](https://docs.julialang.org/en/v1/stdlib/InteractiveUtils/#InteractiveUtils.@which)

More specific to your question, each solver wrapper package (like `CPLEX.jl`) implements the MOI API. The `MOI.submit` for CPLEX [here](https://github.com/jump-dev/CPLEX.jl/blob/ccde44778f93d65af3c6492e44571af03bc015cc/src/MOI/MOI_callbacks.jl#L251) is the one you found?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [May 25, 2023, 1:08pm UTC](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378/3 "2023-05-25T13:08:00Z")

</div>

For the discrepancy in the first argument, notice that the example in the CPLEX.jl README uses `direct_model`:

```julia
model = direct_model(CPLEX.Optimizer())

```

For the second:

> [@Zacharie\_ALES](#):
>
> `::ScalarConstraint{AffExpr, MathOptInterface.LessThan{Float64}`

the error tells you your argument is of the type above, but it might need to be

> [@Zacharie\_ALES](#):
>
> ```julia
> s::Union{
> MOI.LessThan{Float64},
> MOI.GreaterThan{Float64},
> MOI.EqualTo{Float64},
> },
> 
> ```

---

<div class="post-metadata">

**Author:** ![Zacharie\_ALES](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zacharie_ales/32/11144_2.png) [@Zacharie\_ALES](https://discourse.julialang.org/u/Zacharie_ALES)\
**Post date:** [May 25, 2023, 1:15pm UTC](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378/4 "2023-05-25T13:15:42Z")

</div>

Thank you for your answers!  
With @which I was able to find exactly the function called. In the end I had to adapt 10 functions to make it work, but it works!

---

<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:** [May 25, 2023, 7:48pm UTC](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378/5 "2023-05-25T19:48:43Z")

</div>

Glad you got it working. You could also just use the solver-specific CPLEX callback and the C API directly. No need to modify a bunch of methods in MOI.
