Skip to main content

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

Answered

Comments

2 comments

  • Jonasz Staszek
    Community Moderator 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 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

Please sign in to leave a comment.