Empty constraint


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)


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:

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

and so on.


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


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


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. 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.


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

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


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

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]


Thanks, sounds enough for my needs.