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:
- Tips and tricks · JuMP
- 9 Mixed integer optimization — MOSEK Modeling Cookbook 3.3.0
- Introduction into Modeling and Optimization of Linear Systems - Advanced modelling techniques: big M constraints (at the bottom)
- https://web.mit.edu/15.053/www/AMP-Chapter-09.pdf
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: