So, I'm trying to optimize MILP, which has PWL constraints. I use gurobi, and when I'm optimizing model without those constraints, gurobi finds solution in a matter of seconds. The problem is when I try to add PWL constraints, performance drops significantly. When I added only 419 out 4072 PWL constraints, gurobi took several minutes two solve the model, and when I added all of them, it couldn't find feasible solution (which must always exist) in several hours. PWL function I use has 11 breakpoints and has no jumps. I can't post all code (there's too much) so here super general outline:

s1 = m.addVars(indices, vtype=GRB.CONTINUOUS, name='s1')
s2 = m.addVars(indices, vtype=GRB.CONTINUOUS, name='s2')

# Some constraints with s1 and s2

c1 = m.addVars(indices, vtype=GRB.CONTINUOUS, name='c1')
c2 = m.addVars(indices, vtype=GRB.CONTINUOUS, name='c2')

for i in range(M):
    for j in range(N):
        m.addGenConstrPWL(s1[i, j], c1[i, j], X, Y)
        m.addGenConstrPWL(s1[i, j], c1[i, j], X, Y)

# also need to add constraints with c1 and c2 in the future

So my question is it expected that PWL constraints would cause such a drop in performance, and can I do something to improve it?

  • 2
    $\begingroup$ It is not shocking that PWL constraints would slow the solver significantly. Internally they may result in the addition of a bunch of binary variables and related constraints. As to how to improve performance, there is not enough information to say much. $\endgroup$
    – prubin
    Commented Jan 30, 2022 at 22:59
  • $\begingroup$ Is the feasible region convex? Convex models are much easier to solve than nonconvex models. $\endgroup$ Commented Mar 10, 2022 at 17:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.