简体   繁体   English

满足以下约束的纸浆程序 min(a,b) > min(x,y)

[英]pulp program for the the following constraint min(a,b) > min(x,y)

Suppose for a moment that I have 4 variables a,b,x,y and one constraint min(a,b) > min(x,y).假设我有 4 个变量 a,b,x,y 和一个约束 min(a,b) > min(x,y)。

how can I represent this program in pulp python?我如何在纸浆 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. max()min()是非线性的,因此我们需要以某种方式对它们进行线性化(使用辅助变量)和一些逻辑来关联 2 个最小值,这(下)可以使用二进制辅助变量和 Big-M 约束。

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 .我们用ab_min找到 a, b 的最小值。
  • 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.我们需要来自 min(x, y) 的“向上压力”......所以我们知道ab_min必须大于 xy,或者可能两者都大于。 For the "or" constraint, we use the binary logic above and multiply it by the "large constant" to make the other constraint trivial.对于“或”约束,我们使用上面的二进制逻辑并将其乘以“大常数”以使其他约束变得微不足道。

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.需要一个额外的二元变量 δ 和一个连续变量 z。 M is a large enough constant to be chosen with care. M 是一个足够大的常数,需要谨慎选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM