メインコンテンツへスキップ

How to build an IF A and B THEN C constraint?

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Maliheh Aramon
    • Gurobi Staff

    Hi Luo, 

    One idea is to use auxiliary binary variables \(b_1\) and \(b_2\) to model the following:

    1. \(b_1 = \begin{cases} 1, ~~ \mbox{if}~ A \geq D+\epsilon \\ 0, ~~ \mbox{if}~ A \leq D \end{cases}\)
    2. \(b_2 = \begin{cases} 1, ~~ \mbox{if}~ B \leq D-\epsilon \\ 0, ~~ \mbox{if}~ B \geq D \end{cases}\)
    3. \(C = \begin{cases} 1, ~~ \mbox{if}~ b_1=1 ~ \mbox{and} ~ b_2=1 \\ 0, \mbox{otherwise} \end{cases}\)

    Since Gurobi does not support strict inequality constraints, the value \(\epsilon > 0\) represents a small positive tolerance value to model inequality constraints. 

    Expression 1 is logically equivalent to:

    • \(\mbox{if}~ b_1 = 0 \rightarrow A \leq D\)
    • \(\mbox{if}~ b_1 = 1 \rightarrow A \geq D + \epsilon\)

    Expression 2 is logically equivalent to:

    • \(\mbox{if}~ b_2 = 0 \rightarrow B \geq D\)
    • \(\mbox{if}~ b_2 = 1 \rightarrow B \leq D - \epsilon\)

    Each of the four items above can be implemented using the Model.addGenConstrIndicator() API. Expression 3 can be implemented using the Model.addGenConstrAnd() API.

    Best regards,

    Maliheh

    0

投稿コメントは受け付けていません。