Cannot Access variable values through Gurobi callback

Hello,

I’m trying to access my variable values through a callback on Gurobi (Gurobi Optimizer version 9.0.2; Pkg v0.8.1) (& JuMP v0.21.3). I’m able to run a few functions (eg. cbget_mipsol_obj), but ‘mipsol_sol’ is not working. Specifically, my code is:

cbget_mipsol_sol(m, cb_data, cb_where)

and I’m getting the error:

MethodError: no method matching cbget_mipsol_sol(::Model, ::CallbackData, ::Int32)
Closest candidates are:
  cbget_mipsol_sol(!Matched::Gurobi.Optimizer, ::Any, ::Any) ...

I checked out the Gurobi grb_callbacks.jl page and saw that ("mipsol_sol",4001) is commented out. Is there any other way to access the variable values through a callback? Any help would be appreciated. Thank you?

Looks like you probably want cbget_mipsol_sol(backend(m), cb_data, cb_where)
https://github.com/jump-dev/Gurobi.jl/blob/183a1c5916ff6253193e7242eba48a172ea7365f/src/MOI_callbacks.jl#L36-L40

This will only work in direct mode

model = direct_model(Gurobi.Optimizer())

Thank you for the reply @odow! I got it to work by removing the first input to the function since it’s already declared by default. I just used cbget_mipsol_sol(cb_data, cb_where)a long with Model(Gurobi.Optimizer).

While trying direct_model, I did come across an issue that I thought I’d bring up: It seems that direct_model() cannot handle RotatedSecondOrderCone() constraints; I kept getting the following error:

Constraints of type MathOptInterface.VectorAffineFunction{Float64}-in-MathOptInterface.RotatedSecondOrderCone are not supported by the solver.
error(::String) at error.jl:33
moi_add_constraint(::Gurobi.Optimizer, ::MathOptInterface.VectorAffineFunction{Float64}, ::MathOptInterface.RotatedSecondOrderCone) at constraints.jl:388
add_constraint(::Model, ::VectorConstraint{GenericAffExpr{Float64,VariableRef},MathOptInterface.RotatedSecondOrderCone,VectorShape}, ::String) at constraints.jl:402

Thought I’d bring it up. Thanks again!!