Do JuMP Variable ensure contiguous memory to Gurobi?

WalterMadelim
Fri, 13 Mar 2026 07:58:21 +0000
Optimization (Mathematical)

The motivation is that I notices Gurobi exposes the 3 APIs.

GRBsetdblattrelement

GRBsetdblattrarray

GRBsetdblattrlist

Allegedly, using GRBsetdblattrarray should be the fastest (than using the list counterpart, than using the element entrywise in a (julia) loop).
But the array API only exposes a start and a len arg. So it’s probably only effective for variables with a contiguous index pattern.

So I wonder if JuMP.jl (based on Gurobi.jl) can ensure the contiguous pattern when creating JuMP variables? e.g.

JuMP.@variable(m, x[2:3, [4]])
# some other code
y = JuMP.@variable(m, [i = 1:5, j = i:5, u = (0, 1)])

can I expect that the x and y has a contiguous index pattern in the Gurobi solver? (The order in julia is x -> y, and intra-x it’s for i in x, intra-y it’s for i in y).

8 posts - 3 participants