# JuMP variable bound by bin variable

**URL:** https://discourse.julialang.org/t/jump-variable-bound-by-bin-variable/42480
**Category:** Optimization (Mathematical)
**Tags:** question, jump
**Created:** [July 3, 2020, 3:26pm UTC](https://discourse.julialang.org/t/jump-variable-bound-by-bin-variable/42480 "2020-07-03T15:26:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RaulBritto](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raulbritto/32/15002_2.png) [@RaulBritto](https://discourse.julialang.org/u/RaulBritto)
#### Post date: [July 3, 2020, 3:26pm UTC](https://discourse.julialang.org/t/jump-variable-bound-by-bin-variable/42480/1 "2020-07-03T15:26:39Z")

</div>

Hello, I trying to optimize using JuMP with GLPK. The model has the vectors of variables:

- y is a binary vector. Each y[j] represents when thefeature is actived or deactived.

- x is float vector. Each variable x[j] is the weight thatwe associate to a feature y[j].

the variable are defined in Julia in this way:  
@variable(model, y[1:73], Bin)  
@variable(model, x[1:73])

and I have this constraint that I’m trying to implement as following:

![jump](https://global.discourse-cdn.com/julialang/original/3X/d/7/d758760d4755a22b64928dc0e5c1d990e854e062.png)

for i in 1:73  
@constraint(model, -y[i] \<= x[i] \<= y[i] )  
end

I’ve tried some approaches to implement this constraint but I did not get it yet.

Thanks

---

<div class="post-metadata">

### Author: ![RaulBritto](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raulbritto/32/15002_2.png) [@RaulBritto](https://discourse.julialang.org/u/RaulBritto)
#### Post date: [July 3, 2020, 3:27pm UTC](https://discourse.julialang.org/t/jump-variable-bound-by-bin-variable/42480/2 "2020-07-03T15:27:44Z")

</div>

I having the follow ERROR:

**ERROR: In `@constraint(model, -(y[i]) <= x[i] <= y[i])`: Expected -y[1] to be a number.**

---

<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 3, 2020, 5:31pm UTC](https://discourse.julialang.org/t/jump-variable-bound-by-bin-variable/42480/3 "2020-07-03T17:31:04Z")

</div>

Add them as two separate constraints:

```nohighlight
using JuMP
model = Model()
@variable(model, x[1:3])
@variable(model, y[1:3], Bin)
@constraint(model, [i = 1:3], x[i] >= -y[i])
@constraint(model, [i = 1:3], x[i] <= y[i])

```

JuMP tries to add an interval constraint, but it can’t because you have variables in every term. It will not split it into two constraints for you.
