Modeling conditional constraints with products of variables inside
回答済みHi, I am trying to model a conditional constraint in Python Gurobi. Here x_e is a binary variable, z and b are continuous variables and r is a parameter.
if b[e,i] >=0.8 then
z[e,j] >= x_e[e,(i,j)]*(z[e,i]+r[i]*2.25*(0.8-b[e,i])*100)
z[e,j] >= x_e[e,(i,j)]*(z[e,i]+r[i]*6*(b[e,i])*100)
ind = mdl.addVars(((item, element) for item in E for element in V), vtype = GRB.BINARY, name = "ind")
mdl.addConstrs((b[e,i] >= 0.8-M*(1-ind[e,i])) for i in V for e in E )
mdl.addConstrs((b[e,i] <= 0.8+M*ind[e,i]) for i in V for e in E )
mdl.addConstrs((ind[e,i] == 1) >> (z[e,j] >= x_e[e,(i,j)]*(z[e,i]+r[i]*2.25*(0.8-b[e,i])*100)) for i in V for j in N for e in E if i!=j)
mdl.addConstrs((ind[e,i] == 0) >> (z[e,j] >= x_e[e,(i,j)]*(z[e,i]+r[i]*6*(b[e,i])*100)) for i in V for j in N for e in E if i!=j)
-
正式なコメント
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. -
Indicator constraints, Model.addGenConstrIndicator(), require LinExpr object. You may find this post helpful. It discusses how to use the Big-M method instead of indicator constraints for conditional relations involving quadratic constraints.
0 -
We can also work around the LinExpr requirement for Model.addGenConstrIndicator() by introducing auxiliary variables in the model that hold the value of the quadratic expressions and use them in the indicator constraints instead.
mdl.addConstrs( w[e,i,j] = x_e[e,(i,j)]*(z[e,i]+r[i]*2.25*(0.8-b[e,i])*100) for i in V for j in N for e in E if i!=j )
mdl.addConstrs( y[e,i,j] = x_e[e,(i,j)]*(z[e,i]+r[i]*6*(b[e,i])*100) for i in V for j in N for e in E if i!=j )
mdl.addConstrs((ind[e,i] == 1) >> (z[e,j] >= w[e,i,j]) for i in V for j in N for e in E if i!=j)
mdl.addConstrs((ind[e,i] == 0) >> (z[e,j] >= y[e,i,j]) for i in V for j in N for e in E if i!=j)Please note the default lower bound for variables in Gurobi is zero. Please update the lower bounds of the auxiliary variables if they can take negative values.
0 -
Thank you!
0
投稿コメントは受け付けていません。
コメント
4件のコメント