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 -
Hi Jaromił Najman,
If quicksum does not speed up the calculation, what is the purpose of it, sum will do the job.
I got this answer from gpt.
I'm not really into the theory of Math, I'm into OR applied, but would like to know if you agree on that.
0 -
Hi Abderrahmen,
There are two timings we are interested in.
i) the time it takes to build the model
ii) the time it takes to solve the model
quicksum helps with the first (it is faster than sum), not the second.
The gpt description is somewhat correct. When you use sum it is creating intermediate LinExpr objects, and this is what is costly.
- Riley
0
Please sign in to leave a comment.
Comments
5 comments