Skip to main content

conditional constraint between two binary decision variables

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Jaromił Najman
    • Gurobi Staff

    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
  • José Rodrigues
    • Gurobi-versary
    • Curious
    • Conversationalist

    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
  • Jaromił Najman
    • Gurobi Staff

    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
  • José Rodrigues
    • Gurobi-versary
    • Curious
    • Conversationalist

    Dear Jaromił, 

    Thank you! Just realised what I was doing wrong, everything is working now.

    0

Post is closed for comments.