# Generic Affine Expression in a constraint

**URL:** <https://discourse.julialang.org/t/generic-affine-expression-in-a-constraint/65275>\
**Category:** Optimization (Mathematical)\
**Created:** [July 25, 2021, 7:24pm UTC](https://discourse.julialang.org/t/generic-affine-expression-in-a-constraint/65275 "2021-07-25T19:24:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Villamar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daniel_villamar/32/27229_2.png) [@Daniel\_Villamar](https://discourse.julialang.org/u/Daniel_Villamar)\
**Post date:** [July 25, 2021, 7:24pm UTC](https://discourse.julialang.org/t/generic-affine-expression-in-a-constraint/65275/1 "2021-07-25T19:24:21Z")

</div>

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.

```nohighlight
#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.

---

<div class="post-metadata">

**Author:** ![Daniel\_Villamar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daniel_villamar/32/27229_2.png) [@Daniel\_Villamar](https://discourse.julialang.org/u/Daniel_Villamar)\
**Post date:** [July 26, 2021, 9:00am UTC](https://discourse.julialang.org/t/generic-affine-expression-in-a-constraint/65275/2 "2021-07-26T09:00:34Z")

</div>

> [@Daniel\_Villamar](#):
>
> @constraint(m, [i = 1:6], Cons1[i,1,1] - 1 \<= 0)

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.
