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)) <= 0.015
There are two non-linearities: a division and a function. Note that I am not sure which symbols are variables or parameters. I'll try to explain some possible cases below.
Division
Exogenous divisions of the form where is a constant, are not an issue. This is just really a linear coefficient . If you have in the constraints, I would advice to calculate in advance, so we can simplify things to It is a good habit to keep constraints as simple as possible, as they are more difficult to debug than parameter assignments.
If we have something like (endogenous division) we need to be careful and worry about division by zero (or, more generally, that the expression can assume very large values if ). If is a positive variable, we can protect things a bit by using a lower bound, say . This is difficult to do if is a free variable (we want a hole in the middle). If we have it may be better to write this as: at the expense of an extra variable and constraint. It has the additional advantage of making the model less non-linear (fewer non-linear variables, smaller non-linear part of the Jacobian). Note that we assumed here that . If this expression can assume both negative and positive values, this will not not work.
If the division is not embedded in other non-linear expressions, we often can multiply things out. E.g. if we have the constraint: then we can write: This is now linear. This is what can apply to our original constraint:
Max function
We can feed to a general-purpose NLP solver. However, this is dangerous. Although this function is continuous, it is non-differentiable at .
In the special case we can write: If represents an expression, you may want to use an extra variable to prevent duplication.
If we have we can do: Note that the variables are a bit difficult to interpret. They can be larger than if the inequality is not tight. The reason I use is that it is sufficient for our purpose and that is just way more difficult to represent.
This is the reformulation we can apply to our original problem: This is now completely linear: we have removed the division and the function.
References
- Piecewise Linear Function as Constraint, https://stackoverflow.com/questions/72026948/piecewise-linear-function-as-constraint
No comments:
Post a Comment