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