简体   繁体   中英

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. And now I want to add one more conditional constraint to specify at least one decision variable should take minimum value of 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. How can I specify that one of A, B, C should take the minimum value of 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". These are simple linear inequalities and can be implemented directly in Pulp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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