Skip to main content

Does Gurobi favors arrays over lists in python?

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff 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 why not try our AI Gurobot?.
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    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,
    Matthias

    0
  • Jose Vindel
    Gurobi-versary
    Thought Leader
    Investigator

    Hello Matthias,

    Thanks for answering my question, from the answer I am unsure what does over-optimizing mean, could you explain it?

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    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,
    Matthias

    0

Post is closed for comments.