Say I have a variable defined over two axes:
@variable(m, x[1:3,[:a, :b]])
2-dimensional DenseAxisArray{VariableRef,2,...} with index sets:
Dimension 1, Base.OneTo(3)
Dimension 2, [:a, :b]
And data, a 3×2 Matrix{VariableRef}:
x[1,a] x[1,b]
x[2,a] x[2,b]
x[3,a] x[3,b]
Is there a way to dynamically define a second variable using the keys of the first?
For example, one might expect @variable(m, y[axes(x)...])
to work, but this unfortunately results in an error: “cannot use splatting operator ...
in the definition of an index set.”
Using keys(x) as the index of y results in a variable that cannot be indexed in the same way as x. E.g. y[1,:a] will not work:
@variable(m, y[keys(x)])
1-dimensional DenseAxisArray{VariableRef,1,...} with index sets:
Dimension 1, JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}[JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((1, :a)), JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((2, :a)), JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((3, :a)), JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((1, :b)), JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((2, :b)), JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((3, :b))]
And data, a 6-element Vector{VariableRef}:
y[JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((1, :a))]
y[JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((2, :a))]
y[JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((3, :a))]
y[JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((1, :b))]
y[JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((2, :b))]
y[JuMP.Containers.DenseAxisArrayKey{Tuple{Int64, Symbol}}((3, :b))]