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
-
正式なコメント
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
投稿コメントは受け付けていません。
コメント
2件のコメント