• Gurobi Staff

Hi Bahareh,

To better answer your question, let us make things a bit simpler. The gist of the question is how to model terms such as $$yx$$ in the objective function where both $$y$$ and $$x$$ are decision variables. Furthermore $$y$$ is a piecewise-linear function of another decision variable $$u$$. An example of this in your specific case is: $$x = x_{jl}^{FM}$$, $$y = C_l^{FM}(u_{jl}^{FM})$$, and $$u = u_{jl}^{FM}$$.

The objective function can be set to a quadratic expression using the Model.setObjective() method. We should model $$y=f(u)$$ as a constraint using the Model.addGenConstrPWL() method. In your specific use-case, we have:

$y = \begin{cases} 89 + 8.9 u - 5.95(u-15) & u \geq 15, \\ 89 + 8.9 u & u < 15. \end{cases}$

Looking at the signature of the Model.addGenConstrPWL() method, we should provide the breakpoints (vertices) of $$f$$ as arguments. The vertices of $$f$$ occur at $$[(13, 204.7), (15,222.5), (17, 228.4)]$$. So, we define the constraint as below:

model.addGenConstrPWL(u, y, [13, 15, 17], [204.7, 222.5, 228.4])

Note that the above constraint needs to be added for each $$C_l^{FM}(u_{jl}^{FM})$$ term in the objective function. Furthermore, we could have used any number less than 15 instead of 13 and any number greater than 15 instead of 17. The same logic applies to your $$C_l^{FC}$$ function as well.

Be aware that adding piecewise-linear constraints will transform your model into a MIP if it is not already a MIP.  To learn more about how piecewise-linear functions are defined, I highly recommend checking piecewise-linear objectives

Best regards,

Maliheh

Thank you so much for your guidance.

Regards,

Bahar

• Gurobi Staff

Hi Bahareh,

Do you have the following case where $$u \in [13, 17] \cup \{0\}$$?

$y = \begin{cases} 89 + 8.9 u - 5.95(u-15) & 15 \leq u \leq 17, \\ 89 + 8.9 u & 13 \leq u < 15, \\ 0 & u = 0. \end{cases}$

You can define $$u$$ as a semi continuous variable and modify the constraint by adding the new point.

u = gurobipy.addVar(lb=13, ub=17, vtype=GRB.SEMICONT)model.addGenConstrPWL(u, y, [0, 13, 15, 17], [0, 204.7, 222.5, 228.4])

The PWL constraint adds $$y = \frac{204.7-0}{13-0} u, u \leq 13$$ and $$y = 228.4 + \frac{228.4 - 222.5}{17-15} (u - 17), u \geq 17$$ to the model. However, these pieces will be ignored for the values which are not in the domain of $$u$$.

Best regards,

Maliheh

Thank you Maliheh for your help.

Regards,

Bahar