# Retriving the Tableau from Gurobi

**URL:** https://discourse.julialang.org/t/retriving-the-tableau-from-gurobi/25468
**Category:** Optimization (Mathematical)
**Created:** [June 20, 2019, 4:21am UTC](https://discourse.julialang.org/t/retriving-the-tableau-from-gurobi/25468 "2019-06-20T04:21:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rcallen24](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rcallen24/32/8655_2.png) [@rcallen24](https://discourse.julialang.org/u/rcallen24)
#### Post date: [June 20, 2019, 4:21am UTC](https://discourse.julialang.org/t/retriving-the-tableau-from-gurobi/25468/1 "2019-06-20T04:21:18Z")

</div>

I am trying to get the tableau from Gurobi and running into some problems. I went through the gurobi github and reference manual and was able to put this together but it is erroring out.

```julia
# dummy model
m = direct_model(Gurobi.Optimizer(OutputFlag=0))
x = @variable(m, x[1:5] >= 0)
c1 = @constraint(m, c1, dot(x, [1,1,1,1,1]) == 5)
c2 = @constraint(m, c2, dot(x, [1,2,3,4,5]) == 7)
@objective(m, Min, dot(x, [1,2,3,4,5]))
optimize!(m)

# set up the output structure SVector as defined in the reference manual
# http://www.gurobi.com/documentation/8.1/refman/c_advanced_simplex_routine.html
mutable struct SVector
    len::Cint
    ind::Array{Cint,1}
    val::Array{Cdouble,1}
end

#call BinvRowi from Gurobi
function get_tableau_row(model::Gurobi.Model, row::Integer)
    num_vars = Gurobi.num_vars(model) # Model is of the form Ax=b 
    output = SVector(Cint(num_vars), convert(Vector{Cint}, zeros(num_vars)), convert(Vector{Cdouble}, zeros(num_vars)))
    ret = Gurobi.@grb_ccall(BinvRowi, Cint,
                            (Ptr{Cvoid}, Cint, SVector),
                            model, Cint(row-1), output)
    if ret != 0
        throw(Gurobi.GurobiError(model.env, ret))
    end
    return output
end

# call the tableau row generation function
get_tableau_row(backend(m).inner, 1)

```

I am able to get it from CPLEX (via a slight modification of the code [bbrunaud](https://discourse.julialang.org/u/bbrunaud) posted on the CPLEX github to make it compatible in Julia 1.1), but I would prefer to do everything in Gurobi.

Any help would be greatly appreciated. I am pretty sure my error is with respect to the Svector structure thats being passed to grb\_ccall.

---

<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: [June 20, 2019, 2:51pm UTC](https://discourse.julialang.org/t/retriving-the-tableau-from-gurobi/25468/2 "2019-06-20T14:51:13Z")

</div>

See [https://github.com/JuliaOpt/Gurobi.jl/pull/121](https://github.com/JuliaOpt/Gurobi.jl/pull/121)

I think you need something like this:

```nohighlight
mutable struct SVector
    len::Cint
    ind::Ptr{Cint}
    val::Ptr{Cdouble}
end

function get_tableau_row(model::Gurobi.Model, row::Cint)
    num_vars = Gurobi.num_vars(model)
    indices = Vector{Cint}(undef, num_vars)
    values = Vector{Cdouble}(undef, num_vars)
    svec = SVector(num_vars, pointer(indices), pointer(values))
    ret = Gurobi.@grb_ccall(
        BinvRowi, Cint, (Ptr{Cvoid}, Cint, Ptr{SVector}), model, row, Ref{SVector}(svec)
    )
    return ret, indices, values
end

```

---

<div class="post-metadata">

### Author: ![rcallen24](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rcallen24/32/8655_2.png) [@rcallen24](https://discourse.julialang.org/u/rcallen24)
#### Post date: [June 20, 2019, 3:11pm UTC](https://discourse.julialang.org/t/retriving-the-tableau-from-gurobi/25468/3 "2019-06-20T15:11:33Z")

</div>

[odow](https://discourse.julialang.org/u/odow), thanks you. I did a search on “BinvRowi” on the Gurobi github but searched the code and not the issues.
