You can't model z = sign(x-c)
exactly with a linear program (because the constraints in an LP are restricted to linear combinations of variables).
However, you can model sign
if you are willing to convert your linear program into a mixed integer program, you can model this with the following two constraints:
L*b <= x - c <= U*(1-b)
z = 1 - 2*b
Where b
is a binary variable, and L
and U
are lower and upper bounds on the quantity x-c
. If b = 0
, we have 0 <= x - c <= U
and z = 1
. If b = 1
, we have L <= x - c <= 0
and z = 1 - 2*1 = -1
.
You can use a solver like Gurobi to solve mixed integer programs.