我正在尝试使用JuMP接口和Julia中的Gurobi求解器来获取分支和绑定节点数。
我尝试按照JuMP网站上的建议尝试getnodecount(m),但是返回时未定义。做更多研究后,我阅读尝试:
MathProgBase.getnodecount(m)
一个简单的例子:
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)
我希望得到的节点数为0,但出现此错误:
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
答案 0 :(得分:0)
您似乎正在使用新的MathOptInterface
而不是MathProgBase
。这就是为什么您没有得到GurobiMathProgModel
并因此得到错误的原因。在MathOptInterface
中,您可以执行以下操作以获取节点数。
MOI.get(model, MOI.NodeCount())
将调用here实现的Gurobi.get_node_count(model::Model)
方法。有关其他属性,请参阅the MOI API Reference.