1

I'm trying to use pyscipopt to solve a linear programming problem, but am unable to fit the piecewise linear function as a constraint.

The constraint is expressed as follows:

Constraint

I've tried to write it as the following:

cfm = quicksum( max(quicksum(cf[i][t] * q[i] - L[t] for i in range(I)), 0) for t in range(T) / quicksum(L[t] for t in range(T)) <= cfm_max

Where cfm_max = 0.15, in this case.

But it is probably very wrong since it returns a NotImplementedError. I've seen examples in piecewise.py found together with the package, but their usage seems different enough to not work in my case.

Would appreciate any help, thanks.

1 Answers1

1

I think this can be written as:

sum(t,y[t]) <= 0.15*sum(t,L[t])
y[t] >= sum(i,CF[i,t]*q[i])-L[t]

where y[t] are non-negative variables. This is now completely linear (no division, no max()).

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • Hi, thanks for the quick response. But `y[t]` has to be able to take on negative values (just due to the field of this problem). It is `sum(y[t]|y[t]>0)/L[t]` that has to be less than 0.15. The constraints proposed would be a feasible, but far from optimal solution. – Winsor-Mavis Apr 27 '22 at 11:04
  • No. `max(...,0)` can never assume negative values. By definition. Check your math. – Erwin Kalvelagen Apr 27 '22 at 11:06
  • I think I understand what you are doing now, and the optimization seems to be working. Many thanks. – Winsor-Mavis Apr 27 '22 at 15:25