unsupported operand type(s) for +: 'Constr' and 'Var'
回答済みHi,
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
サインインしてコメントを残してください。
コメント
1件のコメント