jump-dev / JuMP.jl

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)
http://jump.dev/JuMP.jl/
Other
2.17k stars 390 forks source link

Possibly missing diagnostics for vector of vector of variables #3755

Closed LebedevRI closed 1 month ago

LebedevRI commented 1 month ago
using JuMP
model = Model()
@variable(model, x[1:10][1:5])

results in

5-element Vector{VariableRef}:
 x[1]
 x[2]
 x[3]
 x[4]
 x[5]

... so the outer dimension is "lost". Should this be diagnosed?

Perhaps the intended behavior is

using JuMP
model = Model()
x = [@variable(model, [1:5], base_name="x[$i]") for i in 1:10]

I encountered this when creating a 3-dimensional variable, which is a vector of symmetrical 2D matrixes:

x = [@variable(model, [1:5,1:5], base_name="x[$f]", Symmetric, Bin) for f in 1:10]
odow commented 1 month ago

@variable(model, x[1:10][1:5])

This is not valid JuMP syntax.

We should throw an error instead of silently dropping the [1:10]

odow commented 1 month ago

Fix is https://github.com/jump-dev/JuMP.jl/pull/3756

This is the recommended syntax:

using JuMP
model = Model()
x = [@variable(model, [1:5], base_name="x[$i]") for i in 1:10]
LebedevRI commented 1 month ago

@odow thank you!