Linear Programming with Python and PuLP – Part 3
Real world examples – Resourcing Problem
We’ll now look at 2 more real world examples.
The first is a resourcing problem and the second is a blending problem.
Resourcing Problem
We’re consulting for a boutique car manufacturer, producing luxury cars.
They run on one month (30 days) cycles, we have one cycle to show we can provide value.
There is one robot, 2 engineers and one detailer in the factory. The detailer has some holiday off, so only has 21 days available.
The 2 cars need different time with each resource:
Robot time: Car A – 3 days; Car B – 4 days.
Engineer time: Car A – 5 days; Car B – 6 days.
Detailer time: Car A – 1.5 days; Car B – 3 days.
Car A provides €30,000 profit, whilst Car B offers €45,000 profit.
At the moment, they produce 4 of each cars per month, for €300,000 profit. Not bad at all, but we think we can do better for them.
This can be modelled as follows:
Maximise
$\text{Profit} = 30,000A + 45,000B$
Subject to:
$
A \geq 0 \\
B \geq 0 \\
3A + 4B \leq 30 \\
5A + 6B \leq 60 \\
1.5A + 3B \leq 21 \\
$
import pulp
# Instantiate our problem class
model = pulp.LpProblem("Profit maximising problem", pulp.LpMaximize)
Unlike our previous problem, the decision variables in this case won’t be continuous (We can’t sell half a car!), so the category is integer.
A = pulp.LpVariable('A', lowBound=0, cat='Integer')
B = pulp.LpVariable('B', lowBound=0, cat='Integer')
# Objective function
model += 30000 * A + 45000 * B, "Profit"
# Constraints
model += 3 * A + 4 * B <= 30
model += 5 * A + 6 * B <= 60
model += 1.5 * A + 3 * B <= 21
# Solve our problem
model.solve()
pulp.LpStatus[model.status]
# Print our decision variable values
print "Production of Car A = {}".format(A.varValue)
print "Production of Car B = {}".format(B.varValue)
# Print our objective function value
print pulp.value(model.objective)
So that’s €330,000 monthly profit, compared to their original monthly profit of €300,000
By producing 2 cars of Car A and 4 cars of Car B, we bolster the profits at the factory by €30,000 per month.
We take our consultancy fee and leave the company with €360,000 extra profit for the factory every year.
In the next part, we’ll be making some sausages!
Introduction
Part 1 – Introduction to Linear Programming
Part 2 – Introduction to PuLP
Part 3 – Real world examples – Resourcing Problem
Part 4 – Real world examples – Blending Problem
Part 5 – Using PuLP with pandas and binary constraints to solve a scheduling problem
Part 6 – Mocking conditional statements using binary constraints