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

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

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 for how it’s implemented.
You just need to find the corresponding Cbc call. For example to have access to the Number of iterations, do

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 :slight_smile:

2 Likes

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 :slight_smile:

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

1 Like

Ok thank you.