Does Gurobi favors arrays over lists in python?
AnsweredHello,
Just a brief question, does gurobi get some beneficial computing time when the data is an array over a list?
let's say I am using python and my input data is a list from a csv file, of course gurobi accepts this when adding the variables and constraints, but before the data can be used it must go through some tunning like changing some values some values, of course the change can only be done in the list to keep the csv file unaltered,
If my data was a numpy array instead of a list would this changes be faster?
-
Official comment
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?. -
Hi Jose,
This is very hard to say without seeing your data structures and what kind of algorithms you apply to them. There are multiple modules to improve on the default data structures available in Python. Often, numpy is faster than simple lists, especially when applying some modifications/computations that can be parallelized. In the end, you need to pass the data to Gurobi and I don't think it makes much of a difference in what form you do this. There are more things that are happening in the background that are probably more expensive than reading the coefficients.
I can only recommend writing clean code and not over-optimizing it right from the start - you may need to go back and reformulate parts of the model and this is a lot easier if you didn't put in all kinds of tricks already.
Cheers,
Matthias0 -
Hello Matthias,
Thanks for answering my question, from the answer I am unsure what does over-optimizing mean, could you explain it?
0 -
Sure! The term over-optimizing refers to a common anti-pattern in writing code: It's about focusing on the performance of a certain part of the code before more important aspects are taken care of (here: correctness of the model, model reformulations to improve performance, etc.).
It doesn't sound like you have already arrived at a finished and nicely working formulation and are now looking for further improvements in your code. Parsing and cleaning the input data is usually not as performance-critical.
Please excuse me, if I am wrong and you really need to find a faster way of getting your model data set up. Then, I suggest you try numpy or pandas and watch out for slow pure Python loops. This is more of a Python question and not specific to Gurobi, though.
Cheers,
Matthias0
Post is closed for comments.
Comments
4 comments