# How to get the current LP bound in an user callback (cplex)?

**URL:** <https://discourse.julialang.org/t/how-to-get-the-current-lp-bound-in-an-user-callback-cplex/27076>\
**Category:** Optimization (Mathematical)\
**Created:** [August 1, 2019, 12:10pm UTC](https://discourse.julialang.org/t/how-to-get-the-current-lp-bound-in-an-user-callback-cplex/27076 "2019-08-01T12:10:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [August 1, 2019, 12:10pm UTC](https://discourse.julialang.org/t/how-to-get-the-current-lp-bound-in-an-user-callback-cplex/27076/1 "2019-08-01T12:10:43Z")

</div>

Dear community,

I have a MIP in which I add cuts in a user callback (using JuMP 0.18.5, CPLEX 0.5, MathProgBase 0.7.7). I would like to retrieve the LP bound in the current node of the B&B tree, e.g., by doing something like `CPXgetcallbacknodeobjval()`.

In the documentation of MathProgBase I only found `cbgetlpsolution` which returns a vector of the current variable values, or `cbgetbestbound` which returns the objective value of the best remaining node by calling `CPX_CALLBACK_INFO_BEST_REMAINING`.

Did I miss something in the documentation? Do you have any other suggestions how to get the bound?

Thank you in advance, Michael

---

<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:** [August 1, 2019, 12:28pm UTC](https://discourse.julialang.org/t/how-to-get-the-current-lp-bound-in-an-user-callback-cplex/27076/2 "2019-08-01T12:28:08Z")

</div>

I’m not sure if there is a good solution. You could compute it from the LP solution.

We’ve had a lot of issues about missing specific functionality in the callbacks, which is one reason that they are missing from JuMP 0.19 until we can figure out a better solution.

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [August 1, 2019, 12:56pm UTC](https://discourse.julialang.org/t/how-to-get-the-current-lp-bound-in-an-user-callback-cplex/27076/3 "2019-08-01T12:56:41Z")

</div>

Thank you, I also thought about just computing it, which is hopefully not too costly.

I also thought about manually calling the function I need, but I do not really know how. Essentially CplexSolverInterface.jl does the same. So assuming that ` cb::CPLEX.CplexCutCallbackData` would not it be possible to call something like the following in the callback

```julia
val::Cdouble = 0.0
ret = @cpx_ccall(getcallbacknodeobjval, Cint, (Ptr{Cvoid},Ptr{Cvoid},Cint,Ptr{Cvoid}),
                              cb.cbdata.model.env.ptr, cb.cbdata.cbdata, cb.where, val)

```

?

---

<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:** [August 3, 2019, 8:38am UTC](https://discourse.julialang.org/t/how-to-get-the-current-lp-bound-in-an-user-callback-cplex/27076/4 "2019-08-03T08:38:01Z")

</div>

Sure. There might be some subtle details to work through, but in general the approach you outline should work.

You probably need to pass

```nohighlight
val = Ref{Cdouble}()

```

instead of `val::Cdouble`. There are other examples of this in the `callbacks.jl` file in `CPLEX.jl`.

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [August 20, 2019, 12:14pm UTC](https://discourse.julialang.org/t/how-to-get-the-current-lp-bound-in-an-user-callback-cplex/27076/5 "2019-08-20T12:14:07Z")

</div>

Finally, I had the time to test it. Thank you, it works with

```julia
val = Ref{Cdouble}() #pointer
ret = CPLEX.@cpx_ccall(getcallbacknodeobjval, Cint, (Ptr{Cvoid},Ptr{Cvoid},Cint,Ptr{Cvoid}),
                              cb.cbdata.model.env.ptr, cb.cbdata.cbdata, cb.where, val)

```

and then fetching the value from the pointer,

```julia
myval = val[]

```
