如何在线性规划中编写总内容的某些部分和单个最大项目内容之间的条件



Am正在尝试用Python纸浆解决优化问题。以下是我的基本LP模型。

prob = LpProblem("Minimizing cost", LpMinimize)
A = LpVariable("A", lowBound=0, cat='Integer')
B = LpVariable("B", lowBound=0, cat='Integer')
C = LpVariable("C", lowBound=0, cat='Integer')
prob += 1*A + 1.58*B + 2.98*C, "Objective function"
prob += 2*A + 4*B + 8*C >= content_requirement, "Content requirement"
prob += A+B+C <= 50

对于这个模型,我如何再添加一个约束来指定45%的总内容应该是解决方案中一个以上最大项目的内容。以下是几个例子。

case1: Solver gives the solution A=5, B=0, C=0. (Here, A is the item with largest content as B and C are zeros).
so the condition 45%(2*5 + 4*0 + 8*0) >= 2 should be true.
case2: Solver gives the solution A=3, B=2, C=0. (Here, B is the item with largest content as C is zero).
so the condition 45%(2*3 + 4*2 + 8*0) >= 4 should be true.
case3: Solver gives the solution A=1, B=1, C=2. (Here, C is the item with largest content).
so the condition 45%(2*1 + 4*1 + 8*2) >= 8 should be true.

如果总内容由2*A+4*B+8*C给出,项目A的内容由2*A给出,看起来您想说:

0.45 (coeff_A * A + coeff_B * B + coeff_C * C) >= max(coeff_A * A + coeff_B * B + coeff_C * C)

其中,A、B、C表示变量,coeff_A、coeff_B、coff_C系数表示它们在内容需求约束中的系数
在这种情况下,为每个变量添加一个约束就足够了:

0.45 (coeff_A * A + coeff_B * B + coeff_C * C) >= coeff_A * A
0.45 (coeff_A * A + coeff_B * B + coeff_C * C) >= coeff_B * B
0.45 (coeff_A * A + coeff_B * B + coeff_C * C) >= coeff_C * C

纸浆变成

prob += 0.45 * (2*A + 4*B + 8*C) >= 2*A
prob += 0.45 * (2*A + 4*B + 8*C) >= 4*B
prob += 0.45 * (2*A + 4*B + 8*C) >= 8*C

相关内容

最新更新