Creating an array of symmetric matrix variables in `JuMP`

Is there any command

Not directly. See Broadcasting variables constrained on creation · Issue #2148 · jump-dev/JuMP.jl · GitHub

A good thing to remember is that you aren’t limited by the available JuMP syntax. You can create new data structures using Julia:

julia> using JuMP

julia> n, N = 2, 3
(2, 3)

julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> X = model[:X] = reshape(
           hcat([
               @variable(model, [1:n, 1:n], Symmetric, base_name = "X$(i)")
               for i in 1:N
           ]...),
           n, n, N,
       )
2×2×3 Array{VariableRef, 3}:
[:, :, 1] =
 X1[1,1]  X1[1,2]
 X1[1,2]  X1[2,2]

[:, :, 2] =
 X2[1,1]  X2[1,2]
 X2[1,2]  X2[2,2]

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

julia> model
A JuMP Model
Feasibility problem with:
Variables: 9
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: X

julia> model[:X]
2×2×3 Array{VariableRef, 3}:
[:, :, 1] =
 X1[1,1]  X1[1,2]
 X1[1,2]  X1[2,2]

[:, :, 2] =
 X2[1,1]  X2[1,2]
 X2[1,2]  X2[2,2]

[:, :, 3] =
 X3[1,1]  X3[1,2]
 X3[1,2]  X3[2,2]
1 Like