Gurobi Python: how to write nested amount in constraint

I have an optimization problem and I am using Python and Gurobi to optimize it. In my problem statement, there is a limitation that has an invested amount.

limitation

I recently started learning python and searched in gurobi documentation and code examples and I could not find any example of nested sum.

I was wondering if anyone can help me solve this problem. Thank you in advance!

+5


source to share


1 answer


Use two for operators within a function quicksum()

and two for operators in a 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.

+5


source







All Articles