Problem Detail: I want to express the following constraint, in an integer linear program: $$y = begin{cases} 0 &text{if } x=0 1 &text{if } xne 0. end{cases}$$ I already have the integer variables $x,y$ and I’m promised that $-100 le x le 100$. How can I express the above constraint, in a form suitable for use with an integer linear programming solver? This will presumably require introducing some additional variables. What new variables and constraints do I need to add? Can it be done cleanly with one new variable? Two? Equivalently, this is asking how to enforce the constraint $$y ne 0 text{ if and only if } x ne 0.$$ in the context where I already have constraints that imply $|x| le 100$ and $0 le y le 1$. (My goal is to fix an error in http://cs.stackexchange.com/a/12118/755.)
Asked By : D.W.
Answered By : Erwin Kalvelagen
I think I can do it with one extra binary variable $delta in {0,1}$: $$ -100y le x le 100 y $$ $$ 0.001y-100.001delta le x le -0.001y+100.001 (1-delta) $$
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/51025