# Empty constraint

**URL:** <https://discourse.julialang.org/t/empty-constraint/4111>\
**Category:** Optimization (Mathematical)\
**Created:** [June 6, 2017, 3:04pm UTC](https://discourse.julialang.org/t/empty-constraint/4111 "2017-06-06T15:04:53Z")\
**Posts on this page:** 9\
**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, 3:04pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/1 "2017-06-06T15:04:53Z")

</div>

Is it possible to create an empty constraint? I need that for coding a row-and-column generation algorithm where I need to generate constraints associated to new variables only. Hence, at some point I’ll need to create new empty constraints, which I’ll populate by creating my new variables column-wise. I guess I can do that using a dummy variable … Is there another way?

Answer found in the doc of JuMP

`@constraint(m, con, 0 <= 1)`

---

<div class="post-metadata">

**Author:** ![joehuchette](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joehuchette/32/32_2.png) [@joehuchette](https://discourse.julialang.org/u/joehuchette)\
**Post date:** [June 6, 2017, 4:58pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/2 "2017-06-06T16:58:03Z")

</div>

JuMP allows you to add constraints to models iteratively (i.e. after solving), so it will probably be more natural to add the constraints as-needed. Something like:

```julia
m = Model()
@variable(m, x)
solve(m)
@variable(m, y)
@constraint(m, y <= 1)
solve(m)

```

and so on.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 6, 2017, 5:04pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/3 "2017-06-06T17:04:55Z")

</div>

Does the solver then use the last solution obtained as an initial solution? Re-solving from scratch would be a waste.

---

<div class="post-metadata">

**Author:** ![joehuchette](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joehuchette/32/32_2.png) [@joehuchette](https://discourse.julialang.org/u/joehuchette)\
**Post date:** [June 6, 2017, 5:19pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/4 "2017-06-06T17:19:13Z")

</div>

Depends on the solver, but the variables and constraints will be added to the model already in memory if supported.

---

<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, 7:56pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/5 "2017-06-06T19:56:20Z")

</div>

That would not help me because I need to have references for my generated constraints and variables, and I can of course not use a new name at each iteration of my algorithm.

I think I can handle my specific algorithm by increasing the dimension of the “constraint array” on demand using the trick mentioned [here](https://discourse.julialang.org/t/dynamic-generation-of-constraints/4107/2). However, there does not seem to be a similar way to increase the size of the “variables array” dynamically. While I don’t need it for my current application, this seems to be a severe limitation of JuMP when compared to solvers classical APIs.

---

<div class="post-metadata">

**Author:** ![joehuchette](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joehuchette/32/32_2.png) [@joehuchette](https://discourse.julialang.org/u/joehuchette)\
**Post date:** [June 6, 2017, 8:21pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/6 "2017-06-06T20:21:36Z")

</div>

The way to dynamically update the “variables array” is to maintain the data structures yourself, using a julia array, dictionary, etc.

```nohighlight
m = Model()
x = Vector{Variable}(0)
push!(x, @variable(m))
push!(x, @variable(m))
@show x # ==> x = JuMP.Variable[__anon__ , __anon__]

```

---

<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, 8:34pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/7 "2017-06-06T20:34:02Z")

</div>

This seems to be a nice workaround. Yet, it is not as neat as the mentioned APIs since one is forced to use anonymous variables, which may harden debugging

---

<div class="post-metadata">

**Author:** ![joehuchette](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joehuchette/32/32_2.png) [@joehuchette](https://discourse.julialang.org/u/joehuchette)\
**Post date:** [June 6, 2017, 9:27pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/8 "2017-06-06T21:27:48Z")

</div>

```nohighlight
m = Model()
x = Vector{Variable}(0)
push!(x, @variable(m, basename="x"))
push!(x, @variable(m, basename="y"))
@show x # ==> x = JuMP.Variable[x,y]

```

---

<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 7, 2017, 8:37pm UTC](https://discourse.julialang.org/t/empty-constraint/4111/9 "2017-06-07T20:37:43Z")

</div>

Thanks, sounds enough for my needs.
