Skip to main content

Managing high number of constraints.

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • 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,
    Jaromił

    0

Post is closed for comments.