# How to add names to a collection of constraints in JuMP using @constraints

**URL:** <https://discourse.julialang.org/t/how-to-add-names-to-a-collection-of-constraints-in-jump-using-constraints/100130>\
**Category:** Optimization (Mathematical)\
**Created:** [June 10, 2023, 5:49am UTC](https://discourse.julialang.org/t/how-to-add-names-to-a-collection-of-constraints-in-jump-using-constraints/100130 "2023-06-10T05:49:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackaChou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackachou/32/35269_2.png) [@JackaChou](https://discourse.julialang.org/u/JackaChou)\
**Post date:** [June 10, 2023, 5:49am UTC](https://discourse.julialang.org/t/how-to-add-names-to-a-collection-of-constraints-in-jump-using-constraints/100130/1 "2023-06-10T05:49:02Z")

</div>

I want to name different kinds of constraints for enhancing readability and debugging, what’s the right syntax to do it with @constraints, I know this is easy for @constraint(, base\_name = “Name”). Below is my code with errors.  
‘’’  
using JuMP, HiGHS  
M = Model(HiGHS.Optimizer)  
I = [1, 2, 3]  
J = [1, 2, 3]  
@variable(M, x[I, J] ≥ 0)  
@constraints(M, begin  
[i in I], sum(x[i, :]) \<= 5, base\_name = “name1”  
[j in J], sum(x[:, j]) \>= 6, base\_name = “name2”  
end)  
‘’’

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [June 10, 2023, 9:24am UTC](https://discourse.julialang.org/t/how-to-add-names-to-a-collection-of-constraints-in-jump-using-constraints/100130/2 "2023-06-10T09:24:39Z")

</div>

I use something like this:

```julia
@constraint( M, name1[i in I], sum(x[i, :]) <= 5)
@constraint( M, name2[j in J], sum(x[:, j]) >= 6)

```

(Note: I did not test it for your case)

---

<div class="post-metadata">

**Author:** ![JackaChou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackachou/32/35269_2.png) [@JackaChou](https://discourse.julialang.org/u/JackaChou)\
**Post date:** [June 10, 2023, 1:28pm UTC](https://discourse.julialang.org/t/how-to-add-names-to-a-collection-of-constraints-in-jump-using-constraints/100130/3 "2023-06-10T13:28:51Z")

</div>

it works with @constraints syntax, thx!

---

<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:** [June 11, 2023, 8:38pm UTC](https://discourse.julialang.org/t/how-to-add-names-to-a-collection-of-constraints-in-jump-using-constraints/100130/4 "2023-06-11T20:38:09Z")

</div>

Keyword arguments in the plural macros need additional `()` around them:

```julia
using JuMP, HiGHS
M = Model(HiGHS.Optimizer)
I = [1, 2, 3]
J = [1, 2, 3]
@variable(M, x[I, J] ≥ 0)
@constraints(M, begin
    [i in I], sum(x[i, :]) <= 5, (base_name = “name1”)
    [j in J], sum(x[:, j]) >= 6, (base_name = “name2”)
end)

```

I’ll update the documentation.

---

<div class="post-metadata">

**Author:** ![JackaChou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackachou/32/35269_2.png) [@JackaChou](https://discourse.julialang.org/u/JackaChou)\
**Post date:** [June 12, 2023, 6:37am UTC](https://discourse.julialang.org/t/how-to-add-names-to-a-collection-of-constraints-in-jump-using-constraints/100130/5 "2023-06-12T06:37:21Z")

</div>

Thx！
