# Equivalent of old syntax @constraintref

**URL:** <https://discourse.julialang.org/t/equivalent-of-old-syntax-constraintref/78315>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [March 23, 2022, 12:33am UTC](https://discourse.julialang.org/t/equivalent-of-old-syntax-constraintref/78315 "2022-03-23T00:33:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Popeye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/popeye/32/25244_2.png) [@Popeye](https://discourse.julialang.org/u/Popeye)\
**Post date:** [March 23, 2022, 12:33am UTC](https://discourse.julialang.org/t/equivalent-of-old-syntax-constraintref/78315/1 "2022-03-23T00:33:30Z")

</div>

I came across `@constraintref` macro which was available in older versions of JuMP to generate constraints in a loop. This was removed in latest releases. How could I perform the same functionality in the latest version of JuMP as in the MWE below?

```julia
using JuMP
model = Model()
data = [10,11,10,19,15]
@variable(model,x[i=1:5]>=0)
@variable(model,10<=y[i=1:5]<=20)
@constraintref rconstraints[1:10]
for j = 1:5
    rconstraints[j] = @constraint(m, y[j]<=data[j])
    rconstraints[j+5] = @constraint(m, y[j]<=sum(x[i] for i in j:5))
end

```

One way could be to define `rconstraints` as a vector of type Any, but I am not sure what is the correct type to use here.

---

<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:** [March 23, 2022, 1:52am UTC](https://discourse.julialang.org/t/equivalent-of-old-syntax-constraintref/78315/2 "2022-03-23T01:52:29Z")

</div>

We removed it. You can create your own data structures, you don’t have to rely on the ones JuMP provides.

```julia
using JuMP
model = Model()
data = [10,11,10,19,15]
@variable(model,x[i=1:5]>=0)
@variable(model,10<=y[i=1:5]<=20)

# Option 1 (easiest, probably preferred option)
r_1 = @constraint(model, [j=1:5], y[j] <= data[j])
r_2 = @constraint(model, [j=1:5], y[j] <= sum(x[i] for i in j:5))
rconstraints = vcat(r_1, r_2)

# Option 2 (still an abstract type. Can have issues if one constraint is <= and another >=)
rconstraints = Vector{ConstraintRef}(undef, 10)
for j = 1:5
    rconstraints[j] = @constraint(model, y[j] <= data[j])
    rconstraints[j+5] = @constraint(model, y[j] <= sum(x[i] for i in j:5))
end

```

---

<div class="post-metadata">

**Author:** ![Popeye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/popeye/32/25244_2.png) [@Popeye](https://discourse.julialang.org/u/Popeye)\
**Post date:** [March 24, 2022, 5:39pm UTC](https://discourse.julialang.org/t/equivalent-of-old-syntax-constraintref/78315/3 "2022-03-24T17:39:43Z")

</div>

Thank you
