I am surprised I couldn't find an already written answer for my question in the internet.
I want to linearize $x$ different of $y$ for two nonegative integer decision variables. I am not considering using Constraint Programming which I know that it is better for such constraints, only ILP.
My idea was that I use two sets of constraints:
$x \ge y + 0.5 \text{ OR } x \le y - 0.5$
Then, with binary variable $z$ and $M$ rightly chosen constant depending on the domains of $x$ and $y$:
$x \ge (y + 0.5)z$
$x \le (y - 0.5) + Mz$
Then linearize the first constraint.
However, one of my friend suggested me: "compute $x-y$ and $y-x$, take maximum value of these two variables, for instance using this next picture:
And then you have the distance between $x$ and $y$ which you impose to be positive.
What is the best way?