Get branch and bound node count in JuMP/Gurobi

Viewed 346

I am trying to get the branch and bound node count using the JuMP interface and the Gurobi solver in Julia.

I tried getnodecount(m) as suggested on the JuMP website, but this came back as undefined. After doing more research, I read to try: MathProgBase.getnodecount(m)

A simple example:

using Gurobi
using JuMP
using MathProgBase

m = Model(with_optimizer(Gurobi.Optimizer))
@variable(m, x, Bin)
@variable(m, y >=0)
@objective(m, Min, x*y)

optimize!(m)
println(value(x))

# getnodecount(m)
MathProgBase.getnodecount(m)

I expected to get a node count of 0, but got this error:

LoadError: MethodError: no method matching getnodecount(::Model)

Closest candidates are: getnodecount(!Matched::Gurobi.GurobiMathProgModel) at /uliapro/JuliaPro_v1.1.1.1/packages/Gurobi/dlJep/src/MPB_wrapper.jl:759

1 Answers

You seem to be using the new MathOptInterface rather than MathProgBase. That is why you do not get a GurobiMathProgModel and hence the error. In MathOptInterface, you can do the following to get the node count.

MOI.get(model, MOI.NodeCount())

which will call the Gurobi.get_node_count(model::Model) method implemented here. For other attributes, please refer to the MOI API Reference.

Related