Help with a conditional constraint!
回答済みHello,
I have the following code block:
for i in locations:
for o in facilityoptions:
m.addConstr(gp.quicksum(ProductionQty[p,i,o]/yieldpersqft[p,o] for p in setproduce) <= sqft[o]*LocationSelect[i,o], 'SqftConstraint')
My issue is that yieldpersqft[p,o] is 0 in some cases, and hence i get a divide by zero error. I need this constraint to hold only when yieldpersqft[p,o] > 0.
I saw some help topics on this, and i tried the following:
for i in locations:
for o in facilityoptions:
m.addConstr((yieldpersqft[p,o]>0.1) >> (gp.quicksum(ProductionQty[p,i,o]/yieldpersqft[p,o] for p in setproduce) <= sqft[o]*LocationSelect[i,o], 'SqftConstraint'))
But this does not work due to p not being initialized prior. Any tips on how to proceed?
Thanks in advance!
0
-
正式なコメント
This post is more than three 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. -
Is \( \texttt{yieldpersqft} \) fixed data that is known beforehand? If so, you can add a conditional statement to your \( \texttt{for} \) loop so you only sum terms for which \( \texttt{yieldpersqft[p, o]} \) is strictly positive:
for i in locations:
for o in facilityoptions:
m.addConstr(
gp.quicksum(
ProductionQty[p, i, o] / yieldpersqft[p, o]
for p in setproduce
if yieldpersqft[p, o] > 0
)
<= sqft[o] * LocationSelect[i, o],
"SqftConstraint",
)0 -
Thank you Eli Towle ! Yes, yieldpersqft is fixed data. I will try this and come back if there's any other issue.
0
投稿コメントは受け付けていません。
コメント
3件のコメント