# MILP Penalty Function Only for Negative Values

This is (hopefully) an easy answer but I haven't dealt with this before.

I have a MILP which includes an unbounded, continuous decision variable. However, I generally don't want this decision variable to take negative values, so I want to include a penalty in the objective function where there is zero penalty incurred for a positive value, but for negative values, the penalty is proportional to the absolute value. Basically, I want a value of -100 to be penalized twice as much as -50, and 10x as much as -10.

Right now I have formulated an indicator variable that is 1 if the decision variable is negative, which incurs a penalty; but this penalty is the same for any negative value.

Any suggestions on how to implement this?

If $$x$$ denotes your free variable, you can penalize the term $$f(x)=\max\{-x,0\}$$ in your objective function, which you can linearize by replacing it with a variable $$y$$, and constraints $$y\ge -x, y\ge 0$$.
You do not need to introduce an indicator variable. Suppose $$x$$ is your free variable. Introduce nonnegative variables $$x^+$$ and $$x^-$$, replace $$x$$ with $$x^+-x^-$$ throughout, and penalize $$x^-$$ linearly in the objective.