I have a n
-dimensional vector m
, a set of JuMP
variables defined by
(where m_i means m[i]
), a set of n multidimensional array defined by \{A[i]\}_{i\in\{1,2,\ldots,n\}} with each A[i]\in[0,1]^{m_{1}\times m_{2}\times\ldots\times m_{n}}. I want to define the following n nonlinear expressions in JuMP
I am defining the set of variables in JuMP
as follows:
# Sample data
using JuMP
n = 3
m = [3, 1, 2]
function generate_A(n::Int, m::Vector{Int})
dims = Tuple(m)
# A[i] has dimensions m[1] x m[2] x ... x m[n].
A = Vector{Array{Float64}}(undef, n)
for i in 1:n
A[i] = rand(dims...)
end
return A
end
A = generate_A(n, m) # so A[i][k_1, k_2, ..., k_m] gives $\sum_{k_{1}\in[1:m_{1}]}\cdots\sum_{k_{n}\in[1:m_{n}]}A[i][k_{1},k_{2},\ldots,k_{n}]\left(x_{1,k_{1}}\times x_{2,k_{2}}\times\ldots\times x_{n,k_{n}}\right)$
# define JuMP model
myModel = Model(Gurobi.Optimizer)
# define {x_{i,k_i}}_{i ∈ 1:n, k_i ∈ 1:m[i]}
@variable(myModel, x[i=1:n, k_i=1:m[i]])
When n and entries of m are small, I can define the expressions (\text{EXPR})(i) for i \in \{1,\ldots,n\} in JuMP
manually without issue. However, it gets cumbersome for larger values of n or when m has large entries.
What is the best way to define the expressions (\text{EXPR})(i) for i\in \{1,\ldots,n\} in JuMP
programmatically, i.e., one inputs n
, m
, A
and the goal is to generate the nonlinear expressions (\text{EXPR})(i) for i\in \{1,\ldots,n\} in JuMP
? Any tips/suggestions will be much appreciated!