Hello to everyone!
I have a question concernig a possible way to provide the problem variables in JuMP.
I would like to assign the variables in a 3-dimensional matrix, but one of the three dimensions is not constant. To clarify the concept, I add a simplified code that shows my case study.
using JuMP
using CPLEX
mod = Model(CPLEX.Optimizer)
@variable(mod, x[1:4, i=1:6, 1:i])
Now, JuMP accepts the variables written with the form above, but the resulting type of x is: JuMP.Containers.SparseAxisArray{VariableRef,3,Tuple{Int64,Int64,Int64}}. However, being a container, it is not possible to call x with a range in the index (x[1, :, 1] or x[1, 1:6, 1] return both errors). The easiest way that I know to call the variables in this context is exploiting the for:
[x[1, i, 1] for i=1:6]
but, clearly, this form is less compact with respect to the one used for the arrays (x[1, 1:6, 1]) and, in my opinion, makes the script more confusing when it is necessary to write several operations between arrays.
Now, I would ask if it is possible to assign the variables not as a container, but as an array of matrices. In this way, it would be possible to exploit the range in the index to call the variables:
x[1][ :, 1]
I hope that I have been sufficiently clear, thank you in advance for your support.
Bye!