Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly missing diagnostics for vector of vector of variables #3755

Closed
LebedevRI opened this issue May 25, 2024 · 3 comments · Fixed by #3756
Closed

Possibly missing diagnostics for vector of vector of variables #3755

LebedevRI opened this issue May 25, 2024 · 3 comments · Fixed by #3756
Labels
Category: Internals Related to JuMP internals

Comments

@LebedevRI
Copy link
Contributor

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 odow added the Category: Internals Related to JuMP internals label May 26, 2024
@odow
Copy link
Member

odow commented May 26, 2024

@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
Copy link
Member

odow commented May 26, 2024

Fix is #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
Copy link
Contributor Author

@odow thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Internals Related to JuMP internals
Development

Successfully merging a pull request may close this issue.

2 participants