JuMP : Adding variables/constraints to a model dynamically


Is it possible to add dynamically constraints and/or variables to a model?

I know there is a syntax to add variable (for column generation) but in the documentation I found that “Some solvers do not expose the ability to modify a model after creation - the model must be constructed from scratch each time”

How do we know which solvers are able to modify and which ones are not?


It’s useful to look at the source code to see what’s actually going on. You’ll see that if the solver does not support adding variables, JuMP will print the following warning,

Solver does not appear to support adding variables to an existing model. JuMP's internal model will be discarded.


Ok thank you I will check.



I would like to know if it will be possible to handle range constraints
using JuMP and Mosek solver.

Best regards,



If Mosek supports range constraints it is possible. Otherwise, JuMP can simply convert the range constraint into two regular constraints.


Hello there,

I see you said, JuMP can simply convert the range constraint into two regular constraint. Did you simply meant something like :

@constraint(m, 0 <= dummy <= 1) <=>
@constraint(m, dummy <= 1)
@constraint(m, dummy >=0)

Or is there another way of doing it, because i’m having an issue solving an MIP with range constraints. It gives two different results for the left and right side of the equivalence i wrote. Do you have any idea why?

Thank you for your help,



Can you post a reproducible example? Ideally something minimal?


To clarify, JuMP does not convert range constraints into two one-sided constraints. These are passed directly to the solver. Not all solvers handle range constraints correctly, unfortunately. It’s usually safer just to replace them with an equality constraint involving a slack variable that has lower and upper bounds.


I replaced the constraint with equality one and slack variables. It gives the same results now.

To be honest, I think my problem came from solving the same problem with two different solvers : GLPKSolverMIP and CPLEX, Cplex being faster but providing a less accurate solution. The second one not handling ranged constraint, I though the difference came from a mistake translating into equality constraint.