Generic Affine Expression in a constraint

I am having a hard time with a NL model that I am creating. My model uses matrices and therefore my variable and constraints are arrays.
I want to create an array of constraints that includes some calculations with my variable S but I get an error message that doesn’t help me much.
I provide a MWE with some comments that I hope may be useful. I use JuMP v0.21.4 and Julia v1.4.2.

#model size
(K,T,E)=(6,2,2)
m = Model(Ipopt.Optimizer)
#Defining variables 
@variable(m, S[1:K*T,1,1:E]>=0)
#Step required to perform calcualtions with the array S
TempS=convert(Array{Any},zeros(K*T,1,E))
for e in 1:E
    for j in 1:K*T
        TempS[j,1,e]=S[j,1,e]
    end
end
Cons1=convert(Array{Any},zeros(K,1,E))
for e in 1:E
    for k in 1:K
        Cons1[k,1,e]=sum(TempS[(k-1)*T+1:(1+(k-1))*T],dims=1)
    end
end
Cons1

The array Cons1 is a bunch of expresions like this one:
GenericAffExpr{Float64,VariableRef}[S[1,1,1] + S[2,1,1]]

I am traying to use Cons1 in a constraint:
@constraint(m, [i = 1:6], Cons1[i,1,1] - 1 <= 0)
Obtaining the following error:
MethodError: promote_operation(::typeof(MutableArithmetics.sub_mul), ::Type{Array{GenericAffExpr{Float64,VariableRef},1}}, ::Type{Int64}) is ambiguous. Candidates:
promote_operation(op::Union{typeof(+), typeof(-), typeof(MutableArithmetics.add_mul), typeof(MutableArithmetics.sub_mul)}, A::Type{#s13} where #s13<:Array, α::Type{#s12} where #s12<:Number) in MutableArithmetics at C:\Users\danuk.julia\packages\MutableArithmetics\bPWR4\src\interface.jl:46
promote_operation(op::Union{typeof(MutableArithmetics.add_mul), typeof(MutableArithmetics.sub_mul)}, T::Type, args::Vararg{Type,N}) where N in MutableArithmetics at C:\Users\danuk.julia\packages\MutableArithmetics\bPWR4\src\shortcuts.jl:63
Possible fix, define
promote_operation(::Union{typeof(MutableArithmetics.add_mul), typeof(MutableArithmetics.sub_mul)}, ::Type{#s13} where #s13<:Array, ::Type{#s12} where #s12<:Number)

Thank you in advance for any help you can give me.

Sorry, I found the problem, as always is the dot in the constrait that is missing
@constraint(m, [i = 1:6], Cons1[i,1,1] .- 1 .<= 0)
With this it works just fine.

1 Like