Skip to main content

Python quicksum() versus sum()

Answered

Comments

3 comments

  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    Hi Nan,

    Does this mean that building the model becomes faster if you use quicksum() or does also solving the model becomes faster when you use quicksum()?

    In principle, one can hope that building the model will become faster with quicksum(). But, as stated in the documentation, there are even quicker ways, such as addTerms or the LinExpr() constructors. You can use time or timeit to check the performance of Python's sum() method, the quicksum() method (as well as the others, if desired) and to assess it against the needs of your application.

    I do not believe that using quicksum() will speed up the solution process. This method is only used to construct the model and - to the best of my knowledge - has no impact on the solution process. Perhaps someone from Gurobi team can confirm this?

    Can we use quicksum() in the same way as we would use sum() (in terms of arguments and such)?

    Consult the documentation for instructions on how to use the method.

    Hope this helps.

    Best regards
    Jonasz

     

    1
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    I do not believe that using quicksum() will speed up the solution process. This method is only used to construct the model and - to the best of my knowledge - has no impact on the solution process. Perhaps someone from Gurobi team can confirm this?

    This is correct.

    1
  • Nan D
    Gurobi-versary
    Conversationalist
    Curious

    Thank you Jonasz Staszek and Jaromił Najman. It’s clear!

    0

Please sign in to leave a comment.