Hi! I ran into a small issue when writing a MILP model, namely the fact that the splatting operator cannot be used in the definition of an index set. What I’m trying to achieve is to define JuMP variables with dimensions specified by a vector. I understand this is probably not something that is going to be changed in the future versions of JuMP for technical reasons (I’m one of those people who knows just enough about macros to stay away from them), but I wonder if people here have come up with creative workarounds. As an example of what doesn’t work:
using JuMP
# I would like a JuMP variable array with dimensions
# specified by the vector a, 2x3x4 in this case.
a=[1:2, 1:3, 1:4]
model = Model()
@variable(model, x[a...] >= 0) # Throws an error
And my workaround, sufficient for my use case where the indices are simply of the form 1:k, does not work if you want more general index sets like [1:2, ["red","blue"]]
:
using JuMP
a=[1:2, 1:3, 1:4]
model = Model()
x = Array{VariableRef}(undef, Tuple(length.(a)))
for index in CartesianIndices(x)
x[index] = @variable(model, base_name="x[$(join(Tuple(index),','))]", lower_bound=0)
end