conditional constraint between two binary decision variables
AnsweredHi, I have seen some posts regarding conditional constraints however none quite cleared my doubts. In order to make it easier to understand my problem, I will provide some context. My optimization concerns the production of an asset, which can be done at the production facilities, or the warehouses. If the asset is produced in the warehouse, it doesn't need to be transported there (obviously). In this case, I have three decision variables, all binary. X which denotes if the product is produced at factory f, W which denotes if the product is produced at warehouse w and T which denotes if there is transportation from factory f to warehouse w.
I want to add a constraint which will set that there is no transportation from production facility f to warehouse w if there is production at warehouse w.
I would appreciate any suggestions on how to code this.
-
Official comment
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. -
Hi José,
You can use Gurobi's indicator constraints to model what you need.
The indicator constraints would read
\[\begin{align*}
W_{wp} = 1 \rightarrow T_{fwp} = 0 \, \, \forall f \in \text{ factories}
\end{align*}\]The above means that if variable \(W_w\) equals \(1\), i.e., product \(p\) is produced at warehouse \(w\), then there is no transportation needed of product \(p\) to warehouse \(w\) from all factories \(f\).
In particular this means, that you will have to introduce one such indicator constraint for every factory \(f\).
Best regards,
Jaromił0 -
Dear Jaromił,
Thank you for your swift reply. In terms of coding it in python, what would that look like? By the way, I forgot to mention that there is only one product.
0 -
Dear José,
As shown in the documentation of indicator constraints, a pseudo code for your case might look something like
w = # some fitting warehouse index
model.addConstrs( (W_[w] == 1) >> (T_[w,f] == 0) for f in factories )Best regards,
Jaromił0 -
Dear Jaromił,
Thank you! Just realised what I was doing wrong, everything is working now.
0
Post is closed for comments.
Comments
5 comments