How to build an IF A and B THEN C constraint？
AnsweredA：continuous
B：continuous
C：binary
D：constant
I want model IF（A>D and B<D) THEN C=1, ELSE C=0, How to build it in gurobi？
0

Hi Luo,
One idea is to use auxiliary binary variables \(b_1\) and \(b_2\) to model the following:
 \(b_1 = \begin{cases} 1, ~~ \mbox{if}~ A \geq D+\epsilon \\ 0, ~~ \mbox{if}~ A \leq D \end{cases}\)
 \(b_2 = \begin{cases} 1, ~~ \mbox{if}~ B \leq D\epsilon \\ 0, ~~ \mbox{if}~ B \geq D \end{cases}\)
 \(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
Please sign in to leave a comment.
Comments
1 comment