I want to model a binary variable $(b)$ from two continous variables $(x_{in},\:x_{out})$.
These variables are $ 0\leq x_{in} \leq x_{max},\: 0\leq x_{out} \leq x_{max})$. I want the following three conditions to apply on my binary variable
$$Condition\:1: b=1\:if\: x_{in}>0\:and\:x_{out}=0\\ Condition\:2: b=0\:if\: x_{in}=0\:and\:x_{out}>0\\ Condition\:3: b=0\:if\: x_{in}=0\:and\:x_{out}=0$$
I have tried two methods and neither of them worked.
First method
Method is explained here. $$x_{in}=b \times x_{max}$$ $$x_{out}=(1-b) \times x_{max}$$ The above solution works for the first two condition but it doesn't work for the 3rd condition.
Second method
Method is explained under this discussion. $$\epsilon\times b \leq x_{in} \leq \epsilon\times b \times x_{max}\\ \epsilon\times b \leq x_{out} \leq \epsilon\times b \times x_{max}$$ where $\epsilon>0$ and it is a very small number $(e.g. 10^{-9})$.
I am using most recent version of Gurobi.
Can you please help? I have tried everything (that I could understand from forums). My knowledge of optimisation algorithms is limited so I apologise in advance if this question is duplicate.
Based on your conditions, it is sufficient to introduce the following formulations
b <= M x X_in ; ( where M is a constant number greater than X_max )
b >= epsilon x ( X_in - X_out )
b in {0,1}
in this manner and due to the above formulations and
Condition 1: we have b<=M and b>=(epsilon). Hence, b=1.
Condition 2: we have b<=0 and b>=(-epsilon). Hence, b=0.
Condition 3: we have b<=0 and b>=0. Hence, b=0.
Good luck