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

Broken constraint creation in JuMP #55

Closed
jd-lara opened this issue May 3, 2019 · 3 comments
Closed

Broken constraint creation in JuMP #55

jd-lara opened this issue May 3, 2019 · 3 comments

Comments

@jd-lara
Copy link
Contributor

jd-lara commented May 3, 2019

Something broke after v0.1.0 that broke this case for creating constraints with Parameters

m = ModelWithParams()
k = add_parameter(m, 10)
x = @variable(m, x[1:2])
@constraint(m, k + sum(x[i] for i in 1:2) <= 0)

And throws a method error

MethodError: no method matching length(::ParameterRef)
Closest candidates are:
  length(!Matched::Core.SimpleVector) at essentials.jl:561
  length(!Matched::Base.MethodList) at reflection.jl:801
  length(!Matched::Core.MethodTable) at reflection.jl:875
@joaquimg
Copy link
Collaborator

joaquimg commented May 4, 2019

Shouldn’t it be x[i] inside the sum?

@jd-lara
Copy link
Contributor Author

jd-lara commented May 4, 2019

I added it and get inconsistent behavior, I resorted to putting the parameters in the RHS of the constraint. It seems to be that sometimes the @constraint macro will try to fold the parameter with the rest of the terms in the sum.

Sometimes this type of construction will fail

m = ModelWithParams()
k = add_parameter(m, 10)
x = @variable(m, x[1:2])
@constraint(m, k + sum(x[i] for i in 1:2) <= 0)

But this one will work

m = ModelWithParams()
k = add_parameter(m, 10)
x = @variable(m, x[1:2])
@constraint(m, sum(x[i] for i in 1:2) + k <= 0)

Also, I can't reproduce it all the time with smaller examples.

@joaquimg
Copy link
Collaborator

joaquimg commented May 5, 2019

That is very weird.
I will look into it, the debugger is good for tracking this kind of error.

@jd-lara jd-lara closed this as completed Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants