Suppose for a moment that I have 4 variables a,b,x,y and one constraint min(a,b) > min(x,y).
how can I represent this program in pulp python?
Ok. So, the first answer I posted (deleted) was a bit hasty and the logic was faulty for the relationship described. This is (hopefully) correct! ;)
max()
and min()
are nonlinear, so we need to linearize them somehow (with helper variable) and some logic to relate the 2 minima, which (below) can use a binary helper variable and a Big-M constraint.
in pseudocode:
a, b, x, y : real-valued variables
ab_min : real-valued variable
x_lt_y : binary variable, 1 implies x <= y, 0 else
M = some suitably large constant, depending on the max range of a, b, x, y
new constraints:
ab_min <= a
ab_min <= b
ab_min >= x - (1 - x_lt_y) * M
ab_min >= y - (x_lt_y) * M
Logic:
ab_min
.ab_min
must be greater than either x or y, or possibly both. For the "or"
constraint, we use the binary logic above and multiply it by the
"large constant" to make the other constraint trivial.