You have a few options:
julia> model = Model();
julia> @variable(model, x[2:9, 10:15])
2-dimensional DenseAxisArray{VariableRef,2,...} with index sets:
Dimension 1, 2:9
Dimension 2, 10:15
And data, a 8Ă—6 Matrix{VariableRef}:
x[2,10] x[2,11] x[2,12] x[2,13] x[2,14] x[2,15]
x[3,10] x[3,11] x[3,12] x[3,13] x[3,14] x[3,15]
x[4,10] x[4,11] x[4,12] x[4,13] x[4,14] x[4,15]
x[5,10] x[5,11] x[5,12] x[5,13] x[5,14] x[5,15]
x[6,10] x[6,11] x[6,12] x[6,13] x[6,14] x[6,15]
x[7,10] x[7,11] x[7,12] x[7,13] x[7,14] x[7,15]
x[8,10] x[8,11] x[8,12] x[8,13] x[8,14] x[8,15]
x[9,10] x[9,11] x[9,12] x[9,13] x[9,14] x[9,15]
julia> is_binary.(x)
2-dimensional DenseAxisArray{Bool,2,...} with index sets:
Dimension 1, 2:9
Dimension 2, 10:15
And data, a 8Ă—6 Matrix{Bool}:
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
julia> any(is_binary.(x))
false
julia> @variable(model, y[i=2:3, j=1:2*i])
JuMP.Containers.SparseAxisArray{VariableRef, 2, Tuple{Int64, Int64}} with 10 entries:
[2, 1] = y[2,1]
[2, 2] = y[2,2]
[2, 3] = y[2,3]
[2, 4] = y[2,4]
[3, 1] = y[3,1]
[3, 2] = y[3,2]
[3, 3] = y[3,3]
[3, 4] = y[3,4]
[3, 5] = y[3,5]
[3, 6] = y[3,6]
julia> is_binary.(y)
JuMP.Containers.SparseAxisArray{Bool, 2, Tuple{Int64, Int64}} with 10 entries:
[2, 1] = false
[2, 2] = false
[2, 3] = false
[2, 4] = false
[3, 1] = false
[3, 2] = false
[3, 3] = false
[3, 4] = false
[3, 5] = false
[3, 6] = false
julia> any(is_binary.(y))
false
julia> all(.!is_binary.(y))
true
julia> for i in eachindex(x)
@show i, x[i], is_binary(x[i])
end
(i, x[i], is_binary(x[i])) = (CartesianIndex(1, 1), x[2,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(2, 1), x[3,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(3, 1), x[4,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(4, 1), x[5,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(5, 1), x[6,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(6, 1), x[7,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(7, 1), x[8,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(8, 1), x[9,10], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(1, 2), x[2,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(2, 2), x[3,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(3, 2), x[4,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(4, 2), x[5,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(5, 2), x[6,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(6, 2), x[7,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(7, 2), x[8,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(8, 2), x[9,11], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(1, 3), x[2,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(2, 3), x[3,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(3, 3), x[4,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(4, 3), x[5,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(5, 3), x[6,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(6, 3), x[7,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(7, 3), x[8,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(8, 3), x[9,12], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(1, 4), x[2,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(2, 4), x[3,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(3, 4), x[4,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(4, 4), x[5,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(5, 4), x[6,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(6, 4), x[7,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(7, 4), x[8,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(8, 4), x[9,13], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(1, 5), x[2,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(2, 5), x[3,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(3, 5), x[4,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(4, 5), x[5,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(5, 5), x[6,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(6, 5), x[7,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(7, 5), x[8,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(8, 5), x[9,14], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(1, 6), x[2,15], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(2, 6), x[3,15], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(3, 6), x[4,15], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(4, 6), x[5,15], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(5, 6), x[6,15], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(6, 6), x[7,15], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(7, 6), x[8,15], false)
(i, x[i], is_binary(x[i])) = (CartesianIndex(8, 6), x[9,15], false)
julia> for i in eachindex(y)
@show i, y[i], is_binary(y[i])
end
(i, y[i], is_binary(y[i])) = ((2, 4), y[2,4], false)
(i, y[i], is_binary(y[i])) = ((3, 2), y[3,2], false)
(i, y[i], is_binary(y[i])) = ((3, 1), y[3,1], false)
(i, y[i], is_binary(y[i])) = ((3, 3), y[3,3], false)
(i, y[i], is_binary(y[i])) = ((3, 6), y[3,6], false)
(i, y[i], is_binary(y[i])) = ((2, 2), y[2,2], false)
(i, y[i], is_binary(y[i])) = ((2, 1), y[2,1], false)
(i, y[i], is_binary(y[i])) = ((3, 4), y[3,4], false)
(i, y[i], is_binary(y[i])) = ((2, 3), y[2,3], false)
(i, y[i], is_binary(y[i])) = ((3, 5), y[3,5], false)
The documentation describes different ways of working with containers: Containers · JuMP