'How to quickly generate a large number of constraints with pyomo
Actually I want to express a set of constraints like this: A + B + C + D + E <= F, A,B,C,D,E,F are all l*t matrices. Unfortunately, I only do constraint construction by using “for” loops,like this: '''
model.TN = pyo.Set(initialize = TN)
model.LN = pyo.Set(initialize = LN)
model.Pc = pyo.Var(model.GN, model.TN, domain = pyo.NonNegativeReals)
def branch_Cap1(t, l):
return sum(Tc[l, n] * model.Pc[n, t] for n in range(GenCount)) - sum(Tl[l, bus] * ldata[bus , t] for bus in range(loadCount)) <= Fmax[l]
def branch_Cap2(t, l):
return sum(Tc[l, n] * model.Pc[n, t] for n in range(GenCount)) - sum(Tl[l, bus] * ldata[bus , t] for bus in range(loadCount)) >= - Fmax[l]
model.branch_Cap1 = pyo.Constraint(model.TN, model.LN, rule = lambda model, t, l: branch_Cap1(t, l))
model.branch_Cap2 = pyo.Constraint(model.TN, model.LN, rule = lambda model, t, l: branch_Cap2(t, l))
''' Can somebody help me? thanks a lot.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
