Defining binary variable

71 Views Asked by At

I am currently working on my modeling skill and I wanted to try to find a linear constraint, that models a binary variable in a specific way. The new binary variable $\gamma_i$ should take the value $1$ if $\epsilon_i=5$ and the value $0$ if $0\le \epsilon_i<5$ holds.

This is my approach so far:

$$\gamma_{i}\ge \epsilon_{i}-4\ge 0~~~~\forall i\in I\\ \gamma_{i}\in \{0,1\} \\ \epsilon_i \in \{0,\ldots,5\} $$

Would such a formulation be correct?

3

There are 3 best solutions below

5
On

(1) Would such a formulation be correct ?
It is wrong.
When RHS is 1 , LHS $γ_i$ must be 1 , which is ok.
When RHS is 0 or lesser , LHS $γ_i$ could be 0 or 1 , which is not ok.
To make it 0 , we have to include additional calculations , Eg1 : We might say , take minimum value which satisfies the Criteria , thus 0 is minimum of 0 & 1 , Eg2 : We might say , always try to use 0 , when it is not satisfying the Criteria , then use 1.
These alternatives will make it Correct , though unnecessarily Complicated.

(2) Should we use such a formulation in general ?
There is not much Simplicity & it is non-intuitive.
(2A) Simplicity : We should use $Sign(\cdots)$ ( which will give -1 , 0 & +1 ) & make the Choice using that.
(2B) Intuitive : We should use Comparisons $<,=,>$ ( which will give true & false ) & make the Choice using that.

Eg3 : $γ_i = (1+Sign(ϵ_i-4.5))/2$
Eg4 : $γ_i = 1 \text{ if } (ϵ_i=5) \text{ else } 0$

These 2 formulations are Correct & Simple & have clarity.

ADDENDUM :
In response to OP query about using in linear Programming.

We can tweak the Criteria & Examples to avoid $Sign(\cdot)$ & use the Comparisons list in (2B) & make suitable linear Programming formulations.
We can shift $ϵ_i$ by $4.5$ & we can scale $γ_i$ by $4.5$ which will give unique Solutions to the Criteria.
Example 5 :

$γ_i-4.5 \le ϵ_i \tag{5X}$
$γ_i \ge 4.5ϵ_i \tag{5Y}$

We can see that when $γ_i=1,2,3,4$ :
$ϵ_i=0,1$ (not unique) by (5X)
$ϵ_i=0$ by (5Y)
Hence $ϵ_i=0$ (unique) , over-all.

We can then see that when $γ_i=5$ :
$ϵ_i=1$ by (5X)
$ϵ_i=0,1$ (not unique) by (5Y)
Hence $ϵ_i=1$ (unique) , over-all.

Exactly what we want !

1
On

No. Your first inequality has $\epsilon_i-4\ge0$, so $\epsilon_i \ge 4$ which is just false.

Simplest general approach is to just draw the points in x y coordinates, draw a bounding triangle and then compute the formulae for those lines.

1
On

Take the contrapositive, and impose a big-M constraint.

The first implication yields $$ \epsilon_i = 5 \implies \gamma_i = 1 \\ \gamma_i = 0 \implies \epsilon_i \le 4 \\ \epsilon_i - 4 \le (5-4) \gamma_i \\ \epsilon_i - 4 \le \gamma_i $$

The second implication yields $$ \epsilon_i \le 4 \implies \gamma_i = 0 \\ \gamma_i = 1 \implies \epsilon_i \ge 5 \\ 5 - \epsilon_i \le (5-0) (1-\gamma_i) \\ \epsilon_i \ge 5\gamma_i \\ $$

Combining these yields $$5\gamma_i \le \epsilon_i \le 4 + \gamma_i,$$ which you could also have derived via $$5\gamma_i + 0(1-\gamma_i) \le \epsilon_i \le 5\gamma_i + 4(1-\gamma_i).$$