Skip to main content

Unsupported type (<class 'gurobipy.MLinExpr'>) for LinExpr addition argument

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    Hi Jonas,

    after a brief look into the documentation, I believe that instead of adding variables per model.addMVar, you should add them per model.addVar or model.addVars and store them in a tupledict.

    According to the documentation, model.addMVar works best if you are able to supply a complete matrix of coefficients. You seem to be building the constraints one by one - I believe you would be better off when dealing with variables "one by one" as well.

    Perhaps someone from the Gurobi's support team can confirm this?

    Best regards
    Jonasz

    0
  • Jaromił Najman
    • Gurobi Staff

    Jonasz is correct.

    Currently, the Python Matrix API works best with a complete matrix of coefficients. It is possible to make it work with vectors, cf. Python Matrix API in our Knowledge Base. However, it is currently requires some extra work and might not seem intuitive.

    In your particular case, using Vars over MVars should not result in any significant performance loss/gain.

    We are trying to improve the Python Matrix API with each release. Thus, this particular behavior may improve significantly in an upcoming release.

    Best regards, 
    Jaromił

    0

Post is closed for comments.