# MIP formulation for a lower semi-continuous function

How can I formulate in mixed linear programming (a set of constraints) the following issue. I have an objective function $$\underset{x}{\max} g(x)$$. I need to convert a continuous linear function $$f(x)$$ (with $$x$$ real) such that when $$f(x) < 0$$ it passes 0 to the objective function and when $$f(x) \ge 0$$ it passes $$f(x)$$.

I have the indicator constraints formulated as

$$$$y \ge \frac{1}{M}f(x) \tag{1}$$$$ $$$$y \le 1 + \frac{1}{M}f(x) \tag{2}$$$$

with $$M$$ sufficiently big, but I am missing the link from $$f(x$$) to $$g(x)$$ such that when

$$$$f(x) < 0 \quad \text{then} \quad g(x) = 0$$$$

and

$$$$f(x) \ge 0 \quad \text{then} \quad g(x) = f(x)$$$$ with $$g(x) \ge 0$$.

Any guidance on this?

You want to maximize $$\max(f(x),0)$$. Assume $$L \le f(x) \le U$$ for constants $$L$$ and $$U$$. Maximize $$g(x)$$ subject to $$0 \le g(x) \le U y \\ 0 \le g(x) - f(x) \le (0-L)(1-y) \\ y \in \{0,1\}$$

• what about if L=0 and U=+inf? Commented Nov 30, 2023 at 16:01
• $L=0$ is fine, but $U$ needs to be finite. Also, $L=0$ means that $f(x) \ge 0$, so $\max(f(x),0)=f(x)$. Commented Nov 30, 2023 at 16:05
• Not sure what you mean. Just think of $g$ as a variable. The formulation I proposed enforces $g=\max(f(x),0)$. Commented Nov 30, 2023 at 16:32
• many thanks. I think I got it. It's precisely what I need. making L safelly small and U safelly big generalizes the case. Commented Nov 30, 2023 at 17:09