How do I enforce mutual exclusivity for an LP problem using PuLP?

Question:

I made the following LP problem formulation in PuLP. We have an objective function with 5 decision variables, each with bounds. We also have 5 binary variables for each decision variable, in order to enforce mutual exclusivity between the first 3, and between the last 2, decision variables. However when I run it, PuLP is giving me Status: Infeasible. What’s wrong with it?

Here is the code:

from pulp import *

# Define the problem as a maximization problem
prob = LpProblem("AVB-Problem", LpMaximize)

# Define the decision variables
P2 = LpVariable("P2", 10, 20)
P3 = LpVariable("P3", 20, 30)
P4 = LpVariable("P4", 30, None)
P6 = LpVariable("P6", 15, 30)
P7 = LpVariable("P7", 30, None)

y2 = LpVariable("y2", cat="Binary")
y3 = LpVariable("y3", cat="Binary")
y4 = LpVariable("y4", cat="Binary")
y6 = LpVariable("y6", cat="Binary")
y7 = LpVariable("y7", cat="Binary")

# Define the objective function
prob += 1*P2 + 1.5*P3 + 1.7*P4 + 2*P6 + 2.5*P7, "Z"

# Define the constraints
prob += P2 + P3 + P4 + P6 + P7 <= 500000, "Total-Constraint"
prob += P2 <= y2*10000000000, "P2-Binary-Constraint"
prob += P3 <= y3*10000000000, "P3-Binary-Constraint"
prob += P4 <= y4*10000000000, "P4-Binary-Constraint"
prob += P6 <= y6*10000000000, "P6-Binary-Constraint"
prob += P7 <= y7*10000000000, "P7-Binary-Constraint"
prob += y2 + y3 + y4 == 1, "Mutual Exclusivity 1"
prob += y6 + y7 == 1, "Mutual Exclusivity 2"

# Solve the problem
prob.solve(PULP_CBC_CMD(msg=1))

# Print the solution status
print(f"Status: {LpStatus[prob.status]}")

# Print the optimal solution and the optimal value of the objective function
for v in prob.variables():
    print(f"{v.name}: {v.varValue}")
print(f"Optimal Value of the Objective Function: {value(prob.objective)}")
Asked By: wizardjoe

||

Answers:

Here’s a hint: Think about the bounds you have for P2 and how that interacts with the constraint on P2:

P2 = LpVariable("P2", 10, 20)

prob += P2 <= y2*5000000, "P2-Binary-Constraint"

And do the same for P3.

And then throw in your mutual exclusivity (which is written correctly)

Answered By: AirSquid