# How to linearize a conditional constraint in JuMP?

Any proper way for linearizing this conditional constraint?
if x \leq 0 then y=0
if x > 0 then y=1

Use a big-M:

model = Model()
@variable(model, x)
@variable(model, y, Bin)
# x > 0 => y = 1
M = 10_000
@constraint(model, x <= M * y)
# x < 0 => y = 0
@constraint(model, -x <= M * (1 - y))
# The x = 0 case is ambiguous, could fix with something like x > eps => y = 1
@constraint(model, x - 1e-6 <= M * y)


Since you’ve asked a few of these MIP reformulation questions recently, you might want to do some wider reading:

I assume most textbooks should also cover various reformulation tricks, but I don’t have any to hand that I ca list.

You should also read: