Use Sign Function in JuMP NLconstraint

I’m currently trying to solve a problem in JuMP that has a nonlinear constraint that has the form
y= (other expressions) + constant * sign(x). This throws an error saying sign is not a recognized function. How do I fix this? (x can take the value of 0 as well, both x and y are continuous)

Thank you!

Dear @cupcc,
the function sign is currently not implemented in current JuMP’s AD.
I recommend reformulating your problem by using:
sign(x) = abs(x) / x
as the function abs is supported by JuMP. Your constraint would rewrite:

y * x = (other expressions) * x + constant * abs(x) 

(better to avoid divisions in constraints when using a NLP solver)

3 Likes

Thank you so much for the help!