メインコンテンツへスキップ

Efficiency in building large number of constraints

回答済み

コメント

6件のコメント

  • 正式なコメント
    Simranjit Kaur
    • 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • David Torres Sanchez
    • Gurobi Staff

    That seems like the best way to do it using the Python API. Have you already tried this?
    Alternatively, you can maybe also try using the Python Matrix API (see an example and some relevant articles).

    Depending on the formulation, with several million constraints, it may be the case the model building is actually the bottleneck.
    You may also find some useful tips in the article: How do I improve the time to build my model? 

    Cheers,
    David

    0
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Álvaro,

    Responsible for the slow model building is most likely not Gurobi itself but the inner Python for-loop. The embedded if-clause is probably pretty expensive and to speed up the whole process, you should try simplifying or preparing your data structures to avoid this if-clause.

    Cheers,
    Matthias

    0
  • Alvaro Garcia Sanchez
    • Gurobi-versary
    • First Comment
    • First Question

    Many thanks, David and Matthias.

    I will take a look at what David mentions.

    I will try first to avoid the loop within the addconstraint preparing the data to confirm that.

    I assume that serveral million constraints should not be an issue. Am I right?

    Regards, 

    Álvaro.

    0
  • Matthias Miltenberger
    • Gurobi Staff

    Well, model instances with a few million constraints are pretty large but constructing such models should not be an issue. To benchmark your model construction, you could also write out the model file as MPS and compare how much time is needed to read that file in.

    Cheers,
    Matthias

    0
  • Alvaro Garcia Sanchez
    • Gurobi-versary
    • First Comment
    • First Question

    Hi,

    I removed the if from the quicksum as Matthias suggested and the building time has improved.

    Now the problem is preprocessing data, but that is nothing related with Gurobi. When I get that data efficiently processed, I will see how fast I can build the model.

    Many thanks,

    Álvaro.

    0

投稿コメントは受け付けていません。