# Set parameters to Gurobi

**URL:** <https://discourse.julialang.org/t/set-parameters-to-gurobi/70794>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, gurobi\
**Created:** [November 2, 2021, 10:10am UTC](https://discourse.julialang.org/t/set-parameters-to-gurobi/70794 "2021-11-02T10:10:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wiz21b](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@wiz21b](https://discourse.julialang.org/u/wiz21b)\
**Post date:** [November 2, 2021, 10:10am UTC](https://discourse.julialang.org/t/set-parameters-to-gurobi/70794/1 "2021-11-02T10:10:18Z")

</div>

Hello,

I use Gurobi 9.1.2; Julia 1.6.2 and these packages:  
Gurobi v0.9.14  
JuMP v0.21.10

(I’ve seen that the C API has changed)

I try to tell Gurobi to use a specific optimizer (the PRIMAL (simplex) one):

```julia
LP_model = direct_model(Gurobi.Optimizer())

...

grb_model = backend(LP_model)
grb_env = GRBgetenv(grb_model)
@assert GRBsetintparam(grb_env, GRB_INT_PAR_METHOD, GRB_METHOD_PRIMAL) == 0 "Gurobi GRBsetintparam C call failed"
valueP = Ref{Cint}(1234)
@assert GRBgetintparam(grb_env, GRB_INT_PAR_METHOD, valueP) == 0 "Gurobi GRBgetintparam C call failed"
@assert valueP[] == GRB_METHOD_PRIMAL "Method was not set"

optimize!(LP_model)

```

This code doesn’t produce any error but when I do `println(solution_summary(LP_model, verbose=true))`, I get:

```julia
* Work counters
  Solve time (sec) : 0.00157
  Simplex iterations : 0
  Barrier iterations : 53
  Node count : 0

```

… from which I conclude Gurobi has used a Barrier method and not the Simplex one…

Am I using the JuMP C interface correctly ?

Note I’m a beginner here, so maybe I just don’t get how Gurobi works.

Thanks

---

<div class="post-metadata">

**Author:** ![wiz21b](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@wiz21b](https://discourse.julialang.org/u/wiz21b)\
**Post date:** [November 2, 2021, 10:49am UTC](https://discourse.julialang.org/t/set-parameters-to-gurobi/70794/2 "2021-11-02T10:49:02Z")

</div>

It’s strange, I do this:

```julia
println(solution_summary(LP_model, verbose=true))
println("Simplex iterations : $(simplex_iterations(LP_model))")
println("Barrier iterations : $(barrier_iterations(LP_model))")

```

and I get this:

```julia
* Work counters
  Solve time (sec) : 0.00164
  Simplex iterations : 0
  Barrier iterations : 37
  Node count : 0

Simplex iterations : 37.0
Barrier iterations : 0

```

So the reported numbers seems swapped… Any idea ?

---

<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:** [November 2, 2021, 8:56pm UTC](https://discourse.julialang.org/t/set-parameters-to-gurobi/70794/3 "2021-11-02T20:56:35Z")

</div>

Use `set_optimizer_attribute`

```nohighlight
using JuMP, Gurobi
model = Model(Gurobi.Optimizer)
set_optimizer_attribute(model, "Method", 0)

```

The Gurobi docs explain what the values are: [https://www.gurobi.com/documentation/9.1/refman/method.html](https://www.gurobi.com/documentation/9.1/refman/method.html)

The solution summary thing is fixed in the next release of JuMP. The numbers are just swapped in v0.21.

---

<div class="post-metadata">

**Author:** ![wiz21b](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@wiz21b](https://discourse.julialang.org/u/wiz21b)\
**Post date:** [November 5, 2021, 3:54pm UTC](https://discourse.julialang.org/t/set-parameters-to-gurobi/70794/4 "2021-11-05T15:54:09Z")

</div>

Thanks for answering. I didn’t see the `set_optimizer_attribute` method. I was driven to more complex stuff by Google 🙂 I understand there’s a Gurobi documentation for many languages binding, but not for Julia.

---

<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:** [November 5, 2021, 6:51pm UTC](https://discourse.julialang.org/t/set-parameters-to-gurobi/70794/5 "2021-11-05T18:51:10Z")

</div>

Yes, Gurobi.jl is maintained by the community and is not an official product. Please tell Gurobi you are interested in official support for Julia.
