# How to model a penalty for exceeding a threshold in a nonlinear optimization problem using IPOPT?

I'm working on a nonlinear optimization problem where I have a decision variable representing my product's price (P_m) and a constant representing my competitor's price (P_c). I want to introduce a penalty into my objective function when my price exceeds the competitor's price.

My goal is to penalize based on the percentage (I optimize a log(profit) function, hence removing a percentage is intuitive from a decision maker point of view) by which my price exceeds the competitor's, but have no penalty if my price is equal to or less than the competitor's. I don't want to solve it via a piecewise linear function as I want to use IPOPT solver. The idea is to similate this behavior if $$Penalty= \lambda* (P_m - P_c)/P_c \:if \: P_m > P_c \: else \: 0$$

Is there a way to model this penalty in a continuous and differentiable manner suitable for IPOPT?

What you want can be expressed mathematically as $$\text{Penalty} = \lambda * \text{max(}(P_m - P_c)/P_c,0)$$

In this problem, max is being used in a convex manner, so can be handled without introducing binary variables. That is fortunate, because IPOPT doesn't support them.

So use the epigraph form of max, which can be accomplished by introducing a new variable, $$P_{exceed}$$, and use $$\text{Penalty} = \lambda * P_{exceed}/P_c$$

and add the constraints $$0 \le P_{exceed}$$ $$P_m -P_c \le P_{exceed}$$

This problem will be as smooth (continuously differentiable) as if there were no Penalty term.

Some optimization modeling front ends which call IPOPT can do the epigraph formulation for you under the hood, and allow you to specify the model directly using max.