# Cannot Access variable values through Gurobi callback

**URL:** <https://discourse.julialang.org/t/cannot-access-variable-values-through-gurobi-callback/46138>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [September 6, 2020, 12:04pm UTC](https://discourse.julialang.org/t/cannot-access-variable-values-through-gurobi-callback/46138 "2020-09-06T12:04:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hassanis](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@hassanis](https://discourse.julialang.org/u/hassanis)\
**Post date:** [September 6, 2020, 12:04pm UTC](https://discourse.julialang.org/t/cannot-access-variable-values-through-gurobi-callback/46138/1 "2020-09-06T12:04:10Z")

</div>

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:

```julia
cbget_mipsol_sol(m, cb_data, cb_where)

```

and I’m getting the error:

```julia
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?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 6, 2020, 9:59pm UTC](https://discourse.julialang.org/t/cannot-access-variable-values-through-gurobi-callback/46138/2 "2020-09-06T21:59:03Z")

</div>

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](https://github.com/jump-dev/Gurobi.jl/blob/183a1c5916ff6253193e7242eba48a172ea7365f/src/MOI_callbacks.jl#L36-L40)

This will only work in direct mode

```nohighlight
model = direct_model(Gurobi.Optimizer())

```

---

<div class="post-metadata">

**Author:** ![hassanis](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@hassanis](https://discourse.julialang.org/u/hassanis)\
**Post date:** [September 8, 2020, 12:38pm UTC](https://discourse.julialang.org/t/cannot-access-variable-values-through-gurobi-callback/46138/3 "2020-09-08T12:38:26Z")

</div>

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:

```julia
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!!
