Skip to main content

How to set constraints in gurobipy given numpy matrix

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • Jaromił Najman
    • Gurobi Staff

    Hi Fabiano,

    Ad described in the documentation of the tupledict.prod method, the coefficients have to be provided by a Python dictionary. Thus, you have to somehow convert the matrix slice into a fitting dictionary. A probably easier way is to just loop over the rows

    m.addConstrs((gb.quicksum(x[j] * B[i,j] for j in range(numxVar)) >= listOfDemand[i]) for i in range(len(listOfDemand)))

    Please also note that strict inequalities are not supported by Gurobi.

    Best regards, 
    Jaromił

    0

Post is closed for comments.