# Get basic variables of Gurobi solution

**URL:** <https://discourse.julialang.org/t/get-basic-variables-of-gurobi-solution/14605>\
**Category:** Optimization (Mathematical)\
**Created:** [September 6, 2018, 4:25am UTC](https://discourse.julialang.org/t/get-basic-variables-of-gurobi-solution/14605 "2018-09-06T04:25:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stelmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stelmo/32/6242_2.png) [@stelmo](https://discourse.julialang.org/u/stelmo)\
**Post date:** [September 6, 2018, 4:25am UTC](https://discourse.julialang.org/t/get-basic-variables-of-gurobi-solution/14605/1 "2018-09-06T04:25:01Z")

</div>

Hi,

Does anyone know how to get the basic variables after Gurobi solves an LP? It is not enough to just check for nonzero numbers in the solution since there could be degenerate basic variables. Gurobi exposes the function GRBgetBasisHead in its C API but I have no idea how to call this function with the Julia interface. Any help will be much appreciated!

---

<div class="post-metadata">

**Author:** ![bbrunaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bbrunaud/32/1737_2.png) [@bbrunaud](https://discourse.julialang.org/u/bbrunaud)\
**Post date:** [September 7, 2018, 5:30pm UTC](https://discourse.julialang.org/t/get-basic-variables-of-gurobi-solution/14605/2 "2018-09-07T17:30:20Z")

</div>

Hello,  
Any function in the API can be accessed. I tried a while ago to get the tableau from CPLEX. Check [cpx\_matrix](https://github.com/bbrunaud/CPLEX.jl/blob/indconstr/src/cpx_matrix.jl)

One way for you to achieve this would be to fork Gurobi.jl and add your function there. Look at the code and search for `@grb_ccall` . Those are the calls to the API. If that seems to overwhelming for you, let me know. There are other options.

---

<div class="post-metadata">

**Author:** ![stelmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stelmo/32/6242_2.png) [@stelmo](https://discourse.julialang.org/u/stelmo)\
**Post date:** [September 7, 2018, 6:39pm UTC](https://discourse.julialang.org/t/get-basic-variables-of-gurobi-solution/14605/3 "2018-09-07T18:39:13Z")

</div>

Actually, I dug a little deeper and my real application requires me to be able to swap the basic variables and non-basic variables out to find more vertices in the solution space (but not enumerate them all, i.e. I only want a certain number of them). It doesn’t look like Gurobi exposes this functionality. Do you know of any solver where this is possible?

---

<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 8, 2018, 3:15am UTC](https://discourse.julialang.org/t/get-basic-variables-of-gurobi-solution/14605/4 "2018-09-08T03:15:25Z")

</div>

If you need `getBasisHead`, please [open an issue](https://github.com/JuliaOpt/Gurobi.jl/issues/new) and we can walk you through how to wrap the function and make a PR 🙂
