Gurobi Python: how to write nested sum in a constraint

前端 未结 1 2008
心在旅途
心在旅途 2021-01-06 01:52

I have an optimization problem and I\'m using Python and Gurobi to optimize it. In my problem formulation there is a constraint that has a nested sum.

constraint

1条回答
  •  無奈伤痛
    2021-01-06 02:31

    Use two for statements inside the quicksum() function and two for statements in the generator expression:

    mycts = m.addConstrs((quicksum(x[i,f,p]*y[i,f,p,t]
                                   for i in I for p in P[i,f]) <= z[f,t]
                                   for f in F for t in T), "myconstraint")
    

    where m is your Model object.

    0 讨论(0)
提交回复
热议问题