I would like to add a constraint that is the sum of absolute values, something like
using JuMP
model = Model(Ipopt.Optimizer)
@variable(model, w[1:n] >=0)
...
@constraint(model, sum(abs.(w - p)) <= alpha) # not possible
I understand that the absolute function is not available (ERROR: LoadError: MethodError: no method matching abs(::JuMP.AffExpr). Also tried
@NLconstraint(model, sum(abs(w[i] - p[i]) for i in 1:n) <= alpha)
but got, as I was expecting, the same error. It is not clear to me how to proceed, for instance, using slack variables if that makes sense. How may I do it? Thanks in advance!
model = Model()
@variable(model, w >= 0)
p = rand()
@variable(model, t)
@constraint(model, t >= w - p)
@constraint(model, t >= p - w)
@constraint(model, t <= alpha)