Creating Matrix Parameters in JuMP

Hello,

Sorry if this is a dumb question, but I can’t figure out how to declare a matrix (or higher dimensional array) variable that is constrained to a parameter set in JuMP, as shown for the vector case here: Variables · JuMP

I tried different things like

@variable(model, p[1:2,1:2] in Parameter(zeros(2,2)))

but none of them worked. Does anybody know how I should go about defining this?

Thank you.

Hmm. It should be this, but it looks like there is a bug. Let me take a look.

julia> model = Model();

julia> @variable(model, p[1:2, 1:2] in Parameter(0.0))
ERROR: MethodError: no method matching build_variable(::JuMP.var"#_error#111"{LineNumberNode}, ::Matrix{ScalarVariable{Float64, Float64, Float64, Float64}}, ::Parameter{Float64})

Closest candidates are:
  build_variable(::Function, ::AbstractVariable, ::AbstractScalarSet)
   @ JuMP ~/.julia/dev/JuMP/src/sets.jl:260
  build_variable(::Function, ::AbstractArray{<:ScalarVariable}, ::MathOptInterface.AbstractScalarSet)
   @ JuMP ~/.julia/dev/JuMP/src/macros.jl:2188
  build_variable(::Function, ::AbstractArray{<:ScalarVariable}, ::AbstractArray{<:MathOptInterface.AbstractScalarSet})
   @ JuMP ~/.julia/dev/JuMP/src/macros.jl:2173
  ...

Stacktrace:
 [1] macro expansion
   @ ~/.julia/dev/JuMP/src/macros.jl:1218 [inlined]
 [2] top-level scope
   @ REPL[19]:1

Edit: More Parameter woes · Issue #3523 · jump-dev/JuMP.jl · GitHub

1 Like

I have a PR to fix this: Fix constructing an array of Parameter variables by odow · Pull Request #3524 · jump-dev/JuMP.jl · GitHub

Parameters were added fairly recently, so a few cases slipped past me. Sorry for the confusion!

5 Likes

Thank you!

1 Like