# Callback information about parent in B&B tree

**URL:** <https://discourse.julialang.org/t/callback-information-about-parent-in-b-b-tree/12546>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [July 20, 2018, 9:35pm UTC](https://discourse.julialang.org/t/callback-information-about-parent-in-b-b-tree/12546 "2018-07-20T21:35:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![borelian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/borelian/32/4723_2.png) [@borelian](https://discourse.julialang.org/u/borelian)\
**Post date:** [July 20, 2018, 9:35pm UTC](https://discourse.julialang.org/t/callback-information-about-parent-in-b-b-tree/12546/1 "2018-07-20T21:35:42Z")

</div>

Hi everyone. in the B&B tree, I need to recover the father of the current node. A solution is to store the father id when the solver branchs, using a branch callback. I see that JuMP doesn’t have branch callbacks. How can I do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [July 21, 2018, 5:38am UTC](https://discourse.julialang.org/t/callback-information-about-parent-in-b-b-tree/12546/2 "2018-07-21T05:38:20Z")

</div>

I think you will need to give more context.

---

<div class="post-metadata">

**Author:** ![borelian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/borelian/32/4723_2.png) [@borelian](https://discourse.julialang.org/u/borelian)\
**Post date:** [July 21, 2018, 4:40pm UTC](https://discourse.julialang.org/t/callback-information-about-parent-in-b-b-tree/12546/3 "2018-07-21T16:40:11Z")

</div>

I’m implementing a Bender’s type of algorithm in Julia, adding Lazy cuts on the B&B tree using addlazycallback. But, to construct the cut, I need to know information about the “father” node in the B&B tree (the node that was branched, generating the current node). The ID of the father node is enough.

My expertise is in CPLEX. The way to do this in CPLEX, is during the “branching” process. You can add a branch callback, after CPLEX decide how to branch a node and create these new nodes, and use that information to store the father ID of each generated node.

I don’t see branch callbacks in Julia (am I correct?), and I don’t know if this can be done in a different way. I saw the documentation of what `addinfocallback` and what `MathProgBase` can return as info for a given node, but it is not enough.

Any idea?

---

<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:** [July 22, 2018, 10:14pm UTC](https://discourse.julialang.org/t/callback-information-about-parent-in-b-b-tree/12546/4 "2018-07-22T22:14:49Z")

</div>

You should be aware that the upcoming release of JuMP will not support solver independent callbacks. See

> [@Cutting plane algorithm performance varies with Gurobi and CPLEX](https://discourse.julialang.org/t/cutting-plane-algorithm-performance-varies-with-gurobi-and-cplex/8597/2):
>
> Callbacks are tied in very deeply to how a MIP solver works, and they’re just not the same across solvers. (This took some experience to discover.) In JuMP 0.19 we will no longer be providing solver-independent callbacks for this reason; they create a false expectation that you can abstract away the solver when you implement the callbacks. The replacement will be solver-specific callbacks that expose the same interface as the low-level API.

However, at present you can get the CPLEX model from a JuMP model as follows

```julia
m = Model(solver=CplexSolver())
# ... some stuff like @variable and @constraint...
JuMP.build(m)
cpx_mpb = JuMP.internalmodel(m)
# cpx_mpb is a CplexMathProgModel, see
# https://github.com/JuliaOpt/CPLEX.jl/blob/ad35be73747ba144fc67a685d4f0caee780a8c1d/src/CplexSolverInterface.jl#L3
cpx = cpx_mpb.inner 
# cpx is a CPLEX Model, see
# https://github.com/JuliaOpt/CPLEX.jl/blob/ad35be73747ba144fc67a685d4f0caee780a8c1d/src/cpx_model.jl#L1

```

You can then use the (wrapped) CPLEX C API to add branch callbacks etc.

---

<div class="post-metadata">

**Author:** ![borelian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/borelian/32/4723_2.png) [@borelian](https://discourse.julialang.org/u/borelian)\
**Post date:** [July 23, 2018, 12:48pm UTC](https://discourse.julialang.org/t/callback-information-about-parent-in-b-b-tree/12546/5 "2018-07-23T12:48:26Z")

</div>

Excellent! Thanks!
