Skip to main content

How to set constraints in gurobipy given numpy matrix

Answered

Comments

1 comment

  • 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

Please sign in to leave a comment.