3

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?

ido kahana
  • 165
  • 2
  • 8

2 Answers2

3

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:

  • We find the minimum of a, b with ab_min.
  • We need "upward pressure" from the min(x, y)... So we know that 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.
AirSquid
  • 10,214
  • 2
  • 7
  • 31
1

I would reformulate this as:

z <= x
z <= y
z >= x - Mδ
z >= y - M(1-δ)
a >= z + 0.00001
b >= z + 0.00001
δ ∈ {0,1}

One extra binary variable δ is needed, and one continuous variable z. M is a large enough constant to be chosen with care.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39