# Gurobi - Branch Priority

**URL:** <https://discourse.julialang.org/t/gurobi-branch-priority/43826>\
**Category:** Optimization (Mathematical)\
**Created:** [July 28, 2020, 6:00pm UTC](https://discourse.julialang.org/t/gurobi-branch-priority/43826 "2020-07-28T18:00:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)\
**Post date:** [July 28, 2020, 6:00pm UTC](https://discourse.julialang.org/t/gurobi-branch-priority/43826/1 "2020-07-28T18:00:20Z")

</div>

I wish I could use the Gurobi attribute “Branch Priority”. So I tried to use it that way and it gave an error. Is there a smarter way to do this?

```julia
MOI.set(model,Gurobi.ModelAttribute("BranchPriority"), u)

```

u is the variable that I want to branch on

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [July 28, 2020, 6:29pm UTC](https://discourse.julialang.org/t/gurobi-branch-priority/43826/2 "2020-07-28T18:29:06Z")

</div>

You need to pass a value for this attribute, not just the variable `u`; see the [Gurobi documentation](https://www.gurobi.com/documentation/9.0/refman/branchpriority.html).

There is an example in the [Gurobi.jl tests](https://github.com/jump-dev/Gurobi.jl/blob/183a1c5916ff6253193e7242eba48a172ea7365f/test/MOI/MOI_wrapper.jl#L670) with the correct MOI syntax.  
Just don’t forget to pass an integer value for `BranchPriority`, e.g.:

```julia
MOI.set(model, Gurobi.VariableAttribute("BranchPriority"), u, 1)

```

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [July 28, 2020, 6:31pm UTC](https://discourse.julialang.org/t/gurobi-branch-priority/43826/3 "2020-07-28T18:31:57Z")

</div>

The function signature is also shown in the [MOI docs](https://jump.dev/MathOptInterface.jl/stable/apireference/#Attributes-1):

```julia
set(model::ModelLike, attr::AbstractVariableAttribute, v::VariableIndex, value)

```

---

<div class="post-metadata">

**Author:** ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)\
**Post date:** [July 28, 2020, 6:39pm UTC](https://discourse.julialang.org/t/gurobi-branch-priority/43826/4 "2020-07-28T18:39:55Z")

</div>

Thanks a lot!!!
