# Problem with JuMP + Gurobi.jl

**URL:** <https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, gurobi\
**Created:** [March 12, 2024, 8:08am UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505 "2024-03-12T08:08:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![njozefow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/njozefow/32/207654_2.png) [@njozefow](https://discourse.julialang.org/u/njozefow)\
**Post date:** [March 12, 2024, 8:08am UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/1 "2024-03-12T08:08:59Z")

</div>

Hello,

In continuation of the thread : [Poor time performance in modifying parameters of JuMP models when using Gurobi - #10 by odow](https://discourse.julialang.org/t/poor-time-performance-in-modifying-parameters-of-jump-models-when-using-gurobi/106982/10)

Here is a code that show the behavior (it emulates the behavior of a column generation algorithm).

```julia
module pbgrb

using JuMP
using Gurobi
using HiGHS

function sc_gurobi(nbconstraint::Int, nbcolums::Int, nbiter::Int)
    m = Model(Gurobi.Optimizer)
    set_silent(m)
    set_attribute(m, "Threads", 1)

    @objective(m, Min, 0)

    @constraint(m, constr[i=1:nbconstraint], 0 == 1)

    x = Vector{VariableRef}()

    for k in 1:nbiter
        optimize!(m)

        for i in 1:nbcolums
            push!(x, @variable(m, lower_bound=0, upper_bound=1))

            set_objective_coefficient(m, x[end], 1)

            for i in 1:nbconstraint
                set_normalized_coefficient(constr[i], x[end], 1)
            end
        end
    end
end

function sc_highs(nbconstraint::Int, nbcolums::Int, nbiter::Int)
    m = Model(HiGHS.Optimizer)
    set_silent(m)

    @objective(m, Min, 0)

    @constraint(m, constr[i=1:nbconstraint], 0 == 1)

    x = Vector{VariableRef}()

    for k in 1:nbiter
        optimize!(m)

        for i in 1:nbcolums
            push!(x, @variable(m, lower_bound = 0, upper_bound = 1))

            set_objective_coefficient(m, x[end], 1)

            for i in 1:nbconstraint
                set_normalized_coefficient(constr[i], x[end], 1)
            end
        end
    end
end

function main()
    start = time()
    sc_gurobi(100, 100, 20)
    println("Time Gurobi: ", time() - start)

    start = time()
    sc_highs(100, 100, 20)
    println("Time HiGHS: ", time() - start)
end

end # module pbgrb

```

On my computer, I obtain output such as

```console
Time Gurobi: 11.41237497329712
Time HiGHS: 0.17132186889648438

```

I am using a macbook with M1 pro processor under macos 14.3.1, julia 1.10.1, JuMP 1.20.0, Gurobi.jl 1.2.1, HiGHS 1.9.0, Gurobi 11.0.1.

I am under the impression that I do follow the rules regarding the lazy update.

Thank you in advance,

Best regards,

Nicolas.

---

<div class="post-metadata">

**Author:** ![torressa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torressa/32/202204_2.png) [@torressa](https://discourse.julialang.org/u/torressa)\
**Post date:** [March 12, 2024, 3:14pm UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/2 "2024-03-12T15:14:05Z")

</div>

Hi @njozefow! Thanks for the code.  
I can reproduce this. I will look into this as part of [Gurobi.jl#516](https://github.com/jump-dev/Gurobi.jl/issues/516)

---

<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:** [March 12, 2024, 9:28pm UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/3 "2024-03-12T21:28:45Z")

</div>

As a comment: is this a bottleneck in a real model? In what algorithm would you add many dense columns at each iteration?

---

<div class="post-metadata">

**Author:** ![njozefow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/njozefow/32/207654_2.png) [@njozefow](https://discourse.julialang.org/u/njozefow)\
**Post date:** [March 13, 2024, 9:08am UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/4 "2024-03-13T09:08:23Z")

</div>

Hello,

It happens to me in a column generation algorithm for a vehicle routing problem where the matrix is sparse. Still, there is an impact on the computational times. In my VRP application for medium size instances, using gurobi is 2-3 times slower than using HiGHS.

The example I provided is like that to increase the impact and because it was easier to implement.

Best regards,

---

<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:** [March 13, 2024, 8:03pm UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/5 "2024-03-13T20:03:13Z")

</div>

So @torressa, the problematic method is:

> <https://github.com/jump-dev/Gurobi.jl/blob/69d2d6e70ab517751275bea0d4ec0acdb263299f/src/MOI_wrapper/MOI_wrapper.jl#L3539-L3553>

It ends with `_require_update(model)` and calls `_update_if_necessary(model)` at the start, so we’re updating after every coefficient change.

---

<div class="post-metadata">

**Author:** ![torressa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torressa/32/202204_2.png) [@torressa](https://discourse.julialang.org/u/torressa)\
**Post date:** [March 14, 2024, 1:23pm UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/6 "2024-03-14T13:23:28Z")

</div>

Indeed! I think we can bundle it in with the refactor PR [Gurobi.jl#552](https://github.com/jump-dev/Gurobi.jl/pull/552) as there were other places were an update was not needed (this is probably the largest performance bottleneck though).

---

<div class="post-metadata">

**Author:** ![torressa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torressa/32/202204_2.png) [@torressa](https://discourse.julialang.org/u/torressa)\
**Post date:** [March 27, 2024, 1:57pm UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/7 "2024-03-27T13:57:38Z")

</div>

This should be fixed now with the new Gurobi.jl release: [v1.2.3](https://github.com/jump-dev/Gurobi.jl/releases/tag/v1.2.3).

I am getting:

```julia
Time Gurobi: 0.29712510108947754
Time HiGHS: 0.27363109588623047

```

---

<div class="post-metadata">

**Author:** ![njozefow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/njozefow/32/207654_2.png) [@njozefow](https://discourse.julialang.org/u/njozefow)\
**Post date:** [April 9, 2024, 1:36pm UTC](https://discourse.julialang.org/t/problem-with-jump-gurobi-jl/111505/8 "2024-04-09T13:36:03Z")

</div>

Hello

I also tested on my side and it works.

Thank you for the correction and all the work on the package.

Best regards,

N.
