# Integral of PWL-Constraint in Gurobi (Java)

In my optimization model, I use piecewise-linear constraints with the output of $$y[m]$$. The question or problem I have now is whether there is a way in Gurobi (Java) to form the integral for this PWL in my objective function, from $$-20$$ to my $$x[m]$$, where $$x[m]$$ is my optimization variable. I need the area between the $$x$$-axis and the PWL constraint, where $$y[m]$$ is always $$\ge0$$.

Integrating a piecewise linear function means you end up with a piecewise quadratic function.

Unless there is come convex structure in the resulting piecewise quadratic function (i.e. the PWL is non-decreasing) you will end up with a model involving nonconvexities.

It was an interesting question so I had to play around a bit with it, and wrote a small post here https://yalmip.github.io/example/integratedpwa/. It is not Java, but the basic idea in the 'hard way' should be easily transferable to any modelling language.

• Thank you for the detailed answer! But if I understand correctly, I now have to determine the function equation for all sections of my PWL and then integrate them and add them to my model with binary variables. If I have understood the idea correctly, I understand the approach, but would also mean at the same time that I no longer need my PWL constraint function from Gurobi, so to speak, or? May 5 at 14:27
• I don't see any approach where the basic piecewise affine functions would be explicitly used in the model. May 5 at 14:46
• The basic function itself is not, but since I don't have the basic function at all, so to speak, but only pass the points of the different sections to the PWL constraint, I have to set up the basic functions first in order to be able to integrate them, or not? May 5 at 14:56
• The points are only a proxy for the underlying function, so that just means those points have to be mapped into the associated integral instead. Having said that, if those points come from some function approximation, you can just as well continue with a piecewise affine approximation of the integral to reduce head-ache, i.e. do the last paragraph in the linked post, which corresponds to the PWL command I presume. May 5 at 15:10
• To be honest, I don't understand anything anymore. I have 5 x and 5 y values as input for my PWL constraint. Between these values is linearized in this constraint. As output parameter of the constraint I have y[m](x), which I can use directly in the objective function. So I do not have linearized straight line equations to integrate. But if I look at the example in the link, linear equations are put into integral form, added and then provided with a binary variable, or? May 5 at 15:58