简体   繁体   English

如何指定至少一个决策变量应在python纸浆中取最小值?

[英]How to specify at least one decision variable should take minimum value in python pulp?

I solved the basic problem with the help of LP in python with PULP. 我借助LP中的LP和PULP解决了基本问题。 And now I want to add one more conditional constraint to specify at least one decision variable should take minimum value of 2. 现在,我想再添加一个条件约束,以指定至少一个决策变量应取最小值2。

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 += 44550*A +70570*B + 132835*C
prob += 1.014996087*A + 2.029992174*B + 4.060195806*C >= 5
prob += A+B+C <= 50
status = prob.solve()
print('Status:', LpStatus[status])
value(A), value(B), value(C), value(prob.objective)

Returns the following answer: 返回以下答案:

Status: Optimal
(1.0, 0.0, 1.0, 177385.0)

Here A=1 and C=1. 这里A = 1,C = 1。 How can I specify that one of A, B, C should take the minimum value of 2. 如何指定A,B,C之一应取最小值2。

With some extra binary variables α,β,γ we can formulate: 使用一些额外的二进制变量α,β,γ,我们可以得出:

A ≥ 2α 
B ≥ 2β
C ≥ 2γ
α+β+γ ≥ 1
α,β,γ ∈ {0,1} 

This models: "at least one of A,B,C should be ≥ 2". 此模型:“ A,B,C中的至少一个应≥2”。 These are simple linear inequalities and can be implemented directly in Pulp. 这些是简单的线性不等式,可以直接在Pulp中实现。

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

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