简体   繁体   中英

Gurobi Python: how to write nested sum in a constraint

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

I've recently started learning python and I searched in gurobi documentation and example codes and I couldn't find any example of nested sum.

I was wondering if anyone could help me solve this problem. Thanks in advance!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM