unsupported operand type(s) for +: 'Constr' and 'Var'
AnsweredHi,
I have an error for this code, can you please tell me what part should I need to rewrite?
Both equation sides should occur for each month, I simply expected to obtain 2 variable summation to be tr variable, however it gives an error.
T= m4.addConstrs( tr[month] == gp.quicksum( Ci[month] + Cr[month]) for month in months)
TypeError: unsupported operand type(s) for +: 'Constr' and 'Var'
Thank you,
Best regards
-1
-
The quicksum() function takes a list of terms as arguments. The correct usage in your case would be
T = m4.addConstrs( tr[month] == gp.quicksum( [Ci[month], Cr[month]]) for month in months)
Alternatively, you can useT = m4.addConstrs( tr[month] == Ci[month] + Cr[month] for month in months)
This will create a constraint for each month, ensuring thattr[month]
equals the sum ofCi[month]
andCr[month]
.0
Please sign in to leave a comment.
Comments
1 comment