I have a nonlinear, nonconvex equality constraint, and I only care about its magnitude. I saw this thread but wasn’t sure how to best handle the constraint in the nonconvex case. For example, I want something like:
m = Model(solver=IpoptSolver()) @variable(m, -pi/2 <= x <= pi/2) @objective(m, Min, x) @NLconstraint(m, absval_constraint, abs(sin(x)) == 0.5)
I tried adding constraints like:
@NLconstraint(m, c1, sin(x) <= 0.5) @NLconstraint(m, c2, sin(x) >= -0.5) @NLconstraint(m, c3, sin(x) >= 0.5) @NLconstraint(m, c4, sin(x) <= -0.5)
but it makes sense that when solving, it’s infeasible unless I start from
x = -pi/6 or
x = pi/6.
I only have one constraint like this, so I could solve the problem twice separately with equality constraints (1)
sin(x) == 0.5 and (2)
sin(x) == -0.5, but is this what’s typically done? Is there a better way?