# Error: JuMP constraint vs Array constraint (same size) --\> ArgumentError: Broadcasting

**URL:** <https://discourse.julialang.org/t/error-jump-constraint-vs-array-constraint-same-size-argumenterror-broadcasting/42812>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, broadcast\
**Created:** [July 9, 2020, 11:10pm UTC](https://discourse.julialang.org/t/error-jump-constraint-vs-array-constraint-same-size-argumenterror-broadcasting/42812 "2020-07-09T23:10:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PabloGalaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablogalaz/32/16281_2.png) [@PabloGalaz](https://discourse.julialang.org/u/PabloGalaz)\
**Post date:** [July 9, 2020, 11:10pm UTC](https://discourse.julialang.org/t/error-jump-constraint-vs-array-constraint-same-size-argumenterror-broadcasting/42812/1 "2020-07-09T23:10:04Z")

</div>

Hello everyone,

I’m using Julia v1.4.2 and JuMP v0.21.2 to solve a optimization problem. I want to compare a decision variable with an array of zeros and a calculated array (with other array and another decision variable) with the same dimensions (I printed then and compare). The comparision and the constraint are showed in the next code:

```julia
M = 60
low_bound_early = M*(df[:,:min_delivery_time]-df[:, :actual_delivery])
println(typeof(y[:,"late"]))
println(size(y[:,"late"]))
        
println(typeof(low_bound_early))
println(size(low_bound_early))
       
@constraint(model, y[:,"early"] .>= 0) 
@constraint(model, y[:,"early"] .>= low_bound_early)

```

The output:

```julia
JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Int64,1}},Tuple{Dict{Int64,Int64}}}
(9,)
Array{Float64,1}
(9,)

```

and the next error:

```julia
ArgumentError: broadcasting requires an assigned BroadcastStyle

Stacktrace:
 [1] copy(::Base.Broadcast.Broadcasted{Base.Broadcast.Unknown,Tuple{UnitRange{Int64}},typeof(MutableArithmetics.sub_mul),Tuple{JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Int64,1}},Tuple{Dict{Int64,Int64}}},Array{GenericAffExpr{Float64,VariableRef},1}}}) at ./broadcast.jl:831
 [2] materialize at ./broadcast.jl:820 [inlined]
 [3] broadcast(::typeof(MutableArithmetics.sub_mul), ::JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Int64,1}},Tuple{Dict{Int64,Int64}}}, ::Array{GenericAffExpr{Float64,VariableRef},1}) at ./broadcast.jl:758
 [4] broadcast_fallback!(::MutableArithmetics.NotMutable, ::Function, ::JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Int64,1}},Tuple{Dict{Int64,Int64}}}, ::Array{GenericAffExpr{Float64,VariableRef},1}) at /Users/pablogalaz/.julia/packages/MutableArithmetics/ZGFsK/src/broadcast.jl:85
 [5] broadcast!(::Function, ::JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Int64,1}},Tuple{Dict{Int64,Int64}}}, ::Array{GenericAffExpr{Float64,VariableRef},1}) at /Users/pablogalaz/.julia/packages/MutableArithmetics/ZGFsK/src/broadcast.jl:77
 [6] macro expansion at /Users/pablogalaz/.julia/packages/MutableArithmetics/ZGFsK/src/rewrite.jl:227 [inlined]
 [7] macro expansion at /Users/pablogalaz/.julia/packages/JuMP/MnJQc/src/macros.jl:381 [inlined]
 [8] solve_buffers(::DataFrame, ::Int64) at ./In[103]:59
 [9] top-level scope at In[105]:4

```

How can I fix this error? ☹

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [July 10, 2020, 12:32am UTC](https://discourse.julialang.org/t/error-jump-constraint-vs-array-constraint-same-size-argumenterror-broadcasting/42812/2 "2020-07-10T00:32:35Z")

</div>

`y` Is a `DenseAxisArray` and `lower_bound_early` is a `Array{Float64, 1}`. They might have the same number of elements, but JuMP doesn’t know that you want a 1-to-1 mapping.

You want something like:

```nohighlight
for (lhs, rhs) in zip(y[:, "early"], lower_bound_early)
     @constraint(model, lhs >= rhs)
end

```

---

<div class="post-metadata">

**Author:** ![PabloGalaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablogalaz/32/16281_2.png) [@PabloGalaz](https://discourse.julialang.org/u/PabloGalaz)\
**Post date:** [July 18, 2020, 7:27pm UTC](https://discourse.julialang.org/t/error-jump-constraint-vs-array-constraint-same-size-argumenterror-broadcasting/42812/3 "2020-07-18T19:27:55Z")

</div>

Understood, it worked! Thank you
