Retriving the Tableau from Gurobi

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.

# 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 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.

See https://github.com/JuliaOpt/Gurobi.jl/pull/121

I think you need something like this:

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
1 Like

odow, thanks you. I did a search on “BinvRowi” on the Gurobi github but searched the code and not the issues.