How to add Integer contraint to variables using the @variables macro?

To bound a variable to be integer I can use integer=true, e.g. @variable(m, 0 <= p, integer=true, start=1), but how to do that when I use the @variables macro?

I did try as such, but it is not recognised (also base_name it doesn’t work):

@variables trmodel begin
    x[p in plants, m in markets] >= 0
    base_name="shipment quantities in cases" # doesn't work
    integer=true                             # doesn't work
end

You can do

@variables trmodel begin
    x[p in plants, m in markets] >= 0, (base_name="shipment quantities in cases", integer=true)
end

or

@variables trmodel begin
    x[p in plants, m in markets] >= 0, (integer=true,)
end

if there is only one keyword argument.
See https://github.com/JuliaOpt/JuMP.jl/blob/79a4fe4d4fc11bc96b62a88b085734429a833dd2/src/macros.jl#L847-L848

1 Like