Abs in JuMP

Hi!

I haven’t asked many programming questions before so please forgive the formatting if it’s not appropriate.

It’s a good question. You can make it a little better by providing the S and x matrices. Currently, I can’t run your example.

To model abs, you can use:

# To model: sum(abs.(y .- x))
@variable(model, t[1:length(x)] >= 0)
@constraint(model, t .>= y .- x)
@constraint(model, t .>= x .- y)
@objective(model, Min, sum(t))

But JuMP actually has special support for this with the NormOneCone:

# To model: sum(abs.(y .- x))
@variable(model, t)
@constraint(model, [t; y .- x] in MOI.NormOneCone(1 + length(x)))
@objective(model, Min, t)
1 Like