# How to define an array of variables in JuMP that has different lengths in different dimensions

I have a parameter called z_{t, w} with the size of 2 \times 2 which is a vector of vectors.
For example, z_{1,1} and z_{2,1} are

z[1,1] = [10 10 30 40 50]
z[2,1] = [20 30 40]


I want to define a variable y based on z. The first two indices of y and z are the same. However, y has one extra index which is defined based on the length corresponding z element.
since the length(z[1,1]) = 5 and length(z[2,1]) = 3,
Therefore, we should have

y[1,1,:] =
y[1,1,1]
y[1,1,2]
y[1,1,3]
y[1,1,4]
y[1,1,5]


and

y[2,1,:] =
y[2,1,1]
y[2,1,2]
y[2,1,3]


Is it possible to define such a variable in Julia using the JuMP package?

@variable(model, y[i=1:2, j=1:2, k=1:length(z[i, j])])


Documentation: Variables · JuMP

1 Like