JuliaStochOpt / ParameterJuMP.jl

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

Cannot create constraint from PAE #43

Closed jd-lara closed 5 years ago

jd-lara commented 5 years ago

Another missing method.

model = ModelWithParams()
x = @variable(model)
y = @variable(model)
a = Parameter(model, 10)
b = Parameter(model, 11)

exp = x + a 
@constraint(model, exp == 0)
ERROR: MethodError: no method matching copy(::ParameterJuMP.ParametrizedAffExpr{Float64})
Closest candidates are:
  copy(::Expr) at expr.jl:36
  copy(::Core.CodeInfo) at expr.jl:64
  copy(::BitSet) at bitset.jl:46
  ...
Stacktrace:
 [1] _destructive_add_with_reorder!(::Val{false}, ::ParameterJuMP.ParametrizedAffExpr{Float64}) at /Users/jdlara/.julia/packages/JuMP/jnmGG/src/parse_expr.jl:291
 [2] top-level scope at /Users/jdlara/.julia/packages/JuMP/jnmGG/src/macros.jl:410
joaquimg commented 5 years ago

I will have to re-implement these JuMP methods:

Base.iszero(a::GenericAffExpr) = isempty(a.terms) && iszero(a.constant)
Base.zero(::Type{GenericAffExpr{C,V}}) where {C,V} = GenericAffExpr{C,V}(zero(C), OrderedDict{V,C}())
Base.one(::Type{GenericAffExpr{C,V}}) where {C,V}  = GenericAffExpr{C,V}(one(C), OrderedDict{V,C}())
Base.zero(a::GenericAffExpr) = zero(typeof(a))
Base.one( a::GenericAffExpr) =  one(typeof(a))
Base.copy(a::GenericAffExpr) = GenericAffExpr(copy(a.constant), copy(a.terms))
jd-lara commented 5 years ago

I can add those to the PR I have open. Already implemented zero and one.

joaquimg commented 5 years ago

solved by #45