# Establishment of 0-1 variable in JuMP

**URL:** https://discourse.julialang.org/t/establishment-of-0-1-variable-in-jump/44421
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [August 6, 2020, 2:18pm UTC](https://discourse.julialang.org/t/establishment-of-0-1-variable-in-jump/44421 "2020-08-06T14:18:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![abcde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abcde/32/16180_2.png) [@abcde](https://discourse.julialang.org/u/abcde)
#### Post date: [August 6, 2020, 2:18pm UTC](https://discourse.julialang.org/t/establishment-of-0-1-variable-in-jump/44421/1 "2020-08-06T14:18:10Z")

</div>

I wrote a very simple program

```julia
using JuMP
model=Model(Gurobi.Optimizer)

@variable(model,0<=w<=1,Int)
@variable(model,0<=x[1:2,1:2]<=10)

@constraint(model,w*x>=0)

@objective(model,Min,-x)
optimize!(model)

```

How to multiply a 0-1 variable with a matrix, you must also set the 0-1 variable into a matrix of the same dimension?

```julia
using JuMP
model=Model(Gurobi.Optimizer)

@variable(model,0<=w[1:2,1:2]<=1,Int)
@variable(model,0<=x[1:2,1:2]<=10)

@constraint(model,w.*x>=0)

@objective(model,Min,-x)
optimize!(model)

```

```julia
ERROR: LoadError: MethodError: promote_operation(::typeof(MutableArithmetics.sub_mul), ::Type{Array{GenericQuadExpr{Float64,VariableRef},2}}, ::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\27990\.juliapro\JuliaPro_v1.4.2-1\packages\MutableArithmetics\NuiNA\src\interface.jl:33
  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\27990\.juliapro\JuliaPro_v1.4.2-1\packages\MutableArithmetics\NuiNA\src\shortcuts.jl:59 
Possible fix, define
  promote_operation(::Union{typeof(MutableArithmetics.add_mul), typeof(MutableArithmetics.sub_mul)}, ::Type{#s13} where #s13<:Array, ::Type{#s12} where #s12<:Number)
Stacktrace:
 [1] mutability(::Type{T} where T, ::Function, ::Type{T} where T, ::Type{T} where T) at C:\Users\27990\.juliapro\JuliaPro_v1.4.2-1\packages\MutableArithmetics\NuiNA\src\interface.jl:132
 [2] mutability(::Array{GenericQuadExpr{Float64,VariableRef},2}, ::Function, ::Array{GenericQuadExpr{Float64,VariableRef},2}, ::Int64) at C:\Users\27990\.juliapro\JuliaPro_v1.4.2-1\packages\MutableArithmetics\NuiNA\src\interface.jl:138
 [3] operate!(::typeof(MutableArithmetics.sub_mul), ::Array{GenericQuadExpr{Float64,VariableRef},2}, ::Int64) at C:\Users\27990\.juliapro\JuliaPro_v1.4.2-1\packages\MutableArithmetics\NuiNA\src\rewrite.jl:70
 [4] top-level scope at C:\Users\27990\.juliapro\JuliaPro_v1.4.2-1\packages\MutableArithmetics\NuiNA\src\rewrite.jl:227
 [5] top-level scope at C:\Users\27990\.juliapro\JuliaPro_v1.4.2-1\packages\JuMP\YXK4e\src\macros.jl:416
in expression starting at untitled-3ec2ea91018ab30b053bc78b8257bb1c:8

```

The result is that they can’t. they report the same error

---

<div class="post-metadata">

### Author: ![abcde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abcde/32/16180_2.png) [@abcde](https://discourse.julialang.org/u/abcde)
#### Post date: [August 6, 2020, 2:20pm UTC](https://discourse.julialang.org/t/establishment-of-0-1-variable-in-jump/44421/2 "2020-08-06T14:20:27Z")

</div>

@miles.lubin@odow

---

<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: [August 6, 2020, 2:33pm UTC](https://discourse.julialang.org/t/establishment-of-0-1-variable-in-jump/44421/3 "2020-08-06T14:33:04Z")

</div>

You are adding a vector-valued constraint so you need to broadcast `.>=`:  
`@constraint(model, w * x .>= 0)`

The ambiguity error is a bug: [https://github.com/jump-dev/JuMP.jl/issues/2301](https://github.com/jump-dev/JuMP.jl/issues/2301)

p.s. there is no need to tag people in your question. You are better instead posting the issue under the `Optimization (Mathematical)` section (I moved this post there).
