# Proper declaration of constraint

**URL:** https://discourse.julialang.org/t/proper-declaration-of-constraint/45424
**Category:** Optimization (Mathematical)
**Created:** [August 23, 2020, 5:01pm UTC](https://discourse.julialang.org/t/proper-declaration-of-constraint/45424 "2020-08-23T17:01:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamo/32/25591_2.png) [@mamo](https://discourse.julialang.org/u/mamo)
#### Post date: [August 23, 2020, 5:01pm UTC](https://discourse.julialang.org/t/proper-declaration-of-constraint/45424/1 "2020-08-23T17:01:52Z")

</div>

Constraint below says for each k, k=1, k=22, k=43 (since k is \< length(TIME)=63)  
PLEVEL[1]\<=…  
PLEVEL[22]\<=…  
PLEVEL[43]\<=…  
PLEVEL1 is binary.

```julia
s1[k in 1:interval:length(TIME) if k<length(TIME)],
PLEVEL[k]-limit<=M*PLEVEL1 #M - big number

```

I need your advice whether the the part within is properly defined.  
Thanks!

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [August 23, 2020, 9:57pm UTC](https://discourse.julialang.org/t/proper-declaration-of-constraint/45424/2 "2020-08-23T21:57:40Z")

</div>

Sorry definition of a constraint in what? `JuMP.jl`? If so, this is the wrong category, it should be in Mathematical Optimization, I can change the category (it is a “regular” user power), if this is the case.

---

<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 23, 2020, 10:26pm UTC](https://discourse.julialang.org/t/proper-declaration-of-constraint/45424/3 "2020-08-23T22:26:13Z")

</div>

Yes, this is for JuMP. I’ve changed the category. @mamo, please remember my suggestion to format your code correctly and provide a minimal working example.

---

<div class="post-metadata">

### Author: ![mamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamo/32/25591_2.png) [@mamo](https://discourse.julialang.org/u/mamo)
#### Post date: [August 24, 2020, 7:21am UTC](https://discourse.julialang.org/t/proper-declaration-of-constraint/45424/4 "2020-08-24T07:21:29Z")

</div>

Yes, thanks Henrique, my mistake.

---

<div class="post-metadata">

### Author: ![mamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamo/32/25591_2.png) [@mamo](https://discourse.julialang.org/u/mamo)
#### Post date: [August 24, 2020, 7:22am UTC](https://discourse.julialang.org/t/proper-declaration-of-constraint/45424/5 "2020-08-24T07:22:09Z")

</div>

Will do. Thanks odow.

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [August 24, 2020, 1:51pm UTC](https://discourse.julialang.org/t/proper-declaration-of-constraint/45424/6 "2020-08-24T13:51:39Z")

</div>

I think you want the functionality described at the [end of this section](https://jump.dev/JuMP.jl/stable/containers/).

Something like that (untested):

```julia
@constraint(model, [k=1:interval:(length(TIME)-1)], PLEVEL[k] - limit <= M * PLEVEL1)

```
