Reputation: 43
I'm trying to declare the constraints below in Python but it does not work.
This is my code:
m.addConstrs((tsk*Xkt[i]).sum(k, '*') + (tbk*Qkt[i]).sum(k, "*") <= bt[i]+Ot[i] for i in range(0, t))
Upvotes: 0
Views: 367
Reputation: 5653
The tupledict.sum()
method applies to a tupledict
object, not a LinExpr
such as tsk*Xkt[i]
. You have two alternatives:
Use the sum()
or quicksum()
function, creating an expression like:
m.addConstrs(quicksum(ts[k]*X[k,t] + tb[k]*Q[k,t] for k in Krange) <= b[t]+O[t] for t in Trange)
Use the tupledict.prod()
method:
m.addConstrs(X.prod(ts, '*', t) + Q.prod(tb, '*', t) <= b[t]+O[t] for t in Trange)
A few comments:
tupledict.prod()
; my code above reflects the correct use of this method.Upvotes: 2