JuMP with absolute value constraint on variables

I’m trying to optimize a function with absolute constraints on its variable (a<=|x|<=b), but I don’t know how to replace function “abs” in JuMP constraint or variable.
At first I wrote this one, where x_min and x_max are two known 1*2 array:

myModel = Model(GLPK.Optimizer)
@variable(myModel, x_min[i] <= abs(x[i = 1:2]) <= x_max[i])

But it turns out that abs cannot be used in variable. I also tried to add constraint with abs, but that also failed.
I know that I can write -b<=x<=b to replace |x|<=b, but how should I deal with a<=|x|?

That’s a non-convex constraint if a is positive and x can be negative or positive which I assume must be the case. You can use a mixed integer formulation to encode this.

2 Likes

For more information on such a formulation, you can look here:
https://docs.mosek.com/modeling-cookbook/mio.html#exact-absolute-value
Once you’ve reformulated |x| = t, just add the constraint x_{min} \leq t \leq x_{max}

See also this recent question: Absolute value, abs(), on Gurobi solver - #3 by jd-foster

2 Likes