I have an integer-valued bounded variable, call it X
. (Somewhere around 0<=X<=100
)
I want to have a binary variable, call it Y
, such that Y=1
if X >= A
and X <= B
, otherwise Y=0
.
The best I've come up with thus far is the following (where T<x>
are introduced binary variables, and M is a large number)
(minimize Y)
(X - A) <= M*Ta
(B - X) <= M*Tb
Y <= Ta
Y <= Tb
Y >= Ta + Tb - 1
(In other words, introducing two binary variables that are true if the variable satisfies the lower and upper bounds of the range, respectively, and setting the result to the binary multiplication of those variables)
This... Works, sort of, but has a couple major flaws. In particular, it's not rigorously defined - Y
can be 1
even if X
is outside the range.
So: is there a better way to do this? In particular: is there a way to rigorously define it, or if not, a way to at least prevent false positives?
Edit: to clarify: A
and B
are variables, not parameters.