# Cbc JuMP : get optimize() best possible, best solution, number of nodes

**URL:** <https://discourse.julialang.org/t/cbc-jump-get-optimize-best-possible-best-solution-number-of-nodes/54904>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [February 9, 2021, 8:49am UTC](https://discourse.julialang.org/t/cbc-jump-get-optimize-best-possible-best-solution-number-of-nodes/54904 "2021-02-09T08:49:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliamilp](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@juliamilp](https://discourse.julialang.org/u/juliamilp)\
**Post date:** [February 9, 2021, 8:49am UTC](https://discourse.julialang.org/t/cbc-jump-get-optimize-best-possible-best-solution-number-of-nodes/54904/1 "2021-02-09T08:49:06Z")

</div>

Hello,

I’m working on a Cbc optimizer using JuMP. When I use the optimize function, the best possible, best solution, total nodes and nodes on trees appears as : “Cbc0010I After 14000 nodes, 1054 on tree, 662 best solution, best possible 440.80398 (47.28 seconds)”. I would like to know if it is possible to get in parallel these values to fill in a csv file for exemple ?  
I succeeded in doing it by capturing the terminal but that takes time when there is a lot printed.

Thanks

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [February 9, 2021, 9:54am UTC](https://discourse.julialang.org/t/cbc-jump-get-optimize-best-possible-best-solution-number-of-nodes/54904/2 "2021-02-09T09:54:39Z")

</div>

For the node count, you can do `MOI.get(model, MOI.NodeCount())` where `model` is the JuMP model.  
However, it’s not possible yet for all of them but it is easy to add thanks to MathOptInterface attributes.  
This mechanism of attributes custom to a given solver already allows to access the `Cbc_status` and `Cbc_secondaryStatus`, see [here](https://github.com/jump-dev/Cbc.jl/blob/01ee423efa84f3cad38e4973b5f578915c69e181/src/MOI_wrapper/MOI_wrapper.jl#L795-L802) for how it’s implemented.  
You just need to find the corresponding `Cbc` call. For example to have access to the [Number of iterations](https://www.coin-or.org/Doxygen/CoinAll/_cbc ___c___ interface_8h.html#3fef49674073889478d64115eda2920b), do

```julia
using JuMP, Cbc
struct IterationCount <: MOI.AbstractModelAttribute end
MOI.is_set_by_optimize(::IterationCount) = true
MOI.get(model::Cbc.Optimizer, ::IterationCount) = Cbc.Cbc_getIterationCount(model.inner)

```

Then you’ll be able to get the iteration count with `MOI.get(model, IterationCount())` where `model` is the JuMP model.  
Pull requests to Cbc.jl welcome to add these attributes 🙂

---

<div class="post-metadata">

**Author:** ![juliamilp](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@juliamilp](https://discourse.julialang.org/u/juliamilp)\
**Post date:** [February 9, 2021, 10:21am UTC](https://discourse.julialang.org/t/cbc-jump-get-optimize-best-possible-best-solution-number-of-nodes/54904/3 "2021-02-09T10:21:00Z")

</div>

Thanks for your answer.

I can see that what you gave me outputs the number of Nodes that remains at the end of my Branch and Bound, but I wondered if it’s possible to have the number of nodes when the function optimize() runs, see the evolution of the number of number of nodes during the optimization.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [February 9, 2021, 8:28pm UTC](https://discourse.julialang.org/t/cbc-jump-get-optimize-best-possible-best-solution-number-of-nodes/54904/4 "2021-02-09T20:28:51Z")

</div>

It might be possible with callbacks but Cbc callbacks are not implemented by the MOI wrapper

---

<div class="post-metadata">

**Author:** ![juliamilp](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@juliamilp](https://discourse.julialang.org/u/juliamilp)\
**Post date:** [February 10, 2021, 8:23am UTC](https://discourse.julialang.org/t/cbc-jump-get-optimize-best-possible-best-solution-number-of-nodes/54904/5 "2021-02-10T08:23:56Z")

</div>

Ok thank you.
