JuliaStochOpt / ParameterJuMP.jl

A JuMP extension to use parameter in constraints RHS
MIT License
41 stars 5 forks source link

Broken constraint creation in JuMP #55

Closed jd-lara closed 5 years ago

jd-lara commented 5 years ago

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 commented 5 years ago

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

jd-lara commented 5 years ago

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 commented 5 years ago

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