メインコンテンツへスキップ

How to set constraints in gurobipy given numpy matrix

回答済み

コメント

1件のコメント

  • 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

サインインしてコメントを残してください。