# Dynamic generation of constraints

**URL:** <https://discourse.julialang.org/t/dynamic-generation-of-constraints/4107>\
**Category:** Optimization (Mathematical)\
**Created:** [June 6, 2017, 2:04pm UTC](https://discourse.julialang.org/t/dynamic-generation-of-constraints/4107 "2017-06-06T14:04:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mposs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mposs/32/21087_2.png) [@mposs](https://discourse.julialang.org/u/mposs)\
**Post date:** [June 6, 2017, 2:04pm UTC](https://discourse.julialang.org/t/dynamic-generation-of-constraints/4107/1 "2017-06-06T14:04:39Z")

</div>

Is there an easy way to expand the base set of a constraint?

For instance, suppose that I have created `@constraint(model, mycons[i in 1:2], x[i] >= 1)` and that I would like to extend it to `@constraint(model, mycons[i in 1:4], x[i] >= 1)` ?

The only why I found to do that is the following:

```julia
@constraintref mycons[1:2]
for i in 1:2 mycons[i] = @constraint(model, x[i] >= 1) end
...
mycons2 = mycons
@constraintref mycons[1:4]
for i in 1:2 mycons[i] = mycons2[i] end

```

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [June 6, 2017, 2:13pm UTC](https://discourse.julialang.org/t/dynamic-generation-of-constraints/4107/2 "2017-06-06T14:13:09Z")

</div>

Nope. JuMP doesn’t have a concept of base sets like in AMPL. The syntax `@constraint(model, mycons[i in 1:2], x[i] >= 1)` is just a convenient way of writing the `for` loop:

```julia
@constraintref mycons[1:2]
for i in 1:2 mycons[i] = @constraint(model, x[i] >= 1)

```

---

<div class="post-metadata">

**Author:** ![mposs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mposs/32/21087_2.png) [@mposs](https://discourse.julialang.org/u/mposs)\
**Post date:** [June 6, 2017, 2:21pm UTC](https://discourse.julialang.org/t/dynamic-generation-of-constraints/4107/3 "2017-06-06T14:21:45Z")

</div>

Thank’s.
