Python quicksum() versus sum()
AnsweredHi!
I have a question about the Gurobi documentation of Pythons quicksum(). It says: “a version of the Python sum function that is much more efficient for building large Gurobi expressions”.
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()?
Can we use quicksum() in the same way as we would use sum() (in terms of arguments and such)?
Thank you!
-
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
Jonasz1 -
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 -
Thank you Jonasz Staszek and Jaromił Najman. It’s clear!
0
Please sign in to leave a comment.
Comments
3 comments