0

我正在尝试用 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.
4

1 回答 1

0

如果总内容由 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、coeff_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
于 2018-08-01T11:24:58.583 回答