Skip to main content

Managing high number of constraints.



1 comment

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Gianluca,

    There is no good way to reformulate the constraint. The problem is that each variable holds a different index, i.e., even if the constraint would read \(x_{c,s} \geq x_{f,c}\cdot x_{f,s}\), you would still need the 18 million constraints, because you have to iterate over all \(c,f,s\) combinations. Adding a large number of constraints almost always results in long construction times. However, you could try some of the following:

    • Reduce the number of \(c\) indices
    • You could try to perform some presolving on your own, i.e., you could try to determine whether some of the variables are 0 or 1 if you have some additional knowledge
    • You could try using Gurobi's Python API instead of Pyomo to avoid additional overhead possible added by Pyomo
    • You could generate the model once and write it to an MPS or LP file, see Model.write(). Subsequently, you can compress the file with, e.g., \(\texttt{bz2}\), and read the model  instead of constructing the model every time

    Best regards,


Please sign in to leave a comment.