3/9/2021 Linear Programming with Python and PuLP – Part 3 – Ben Alex Keen
Ben Alex Keen
LINEAR PROGRAMMING WITH PYTHON AND PULP - PART
1ST APRIL 2016 | IN PYTHON | BY BEN KEEN
Linear Programming with Python and PuLP
Part 3
Real world examples – Resourcing Problem
We’ll now look at 2 more real world examples.
The rst 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 o , so only h
days available.
benalexkeen.com/linear-programming-with-python-and-pulp-part-3/ 1/4
3/9/2021 Linear Programming with Python and PuLP – Part 3 – Ben Alex Keen
The 2 cars need di erent 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 pro t, whilst Car B o ers €45,000 pro t.
At the moment, they produce 4 of each cars per month, for €300,000 pro t. Not bad at all, but we think w
do better for them.
This can be modelled as follows:
Maximise
Profit = 30, 000A + 45, 000B
Subject to:
A ≥ 0
B ≥ 0
3A + 4B ≤ 30
5A + 6B ≤ 60
1.5A + 3B ≤ 21
In [1]:
import pulp
In [2]:
# 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 c
the category is integer.
In [3]:
benalexkeen.com/linear-programming-with-python-and-pulp-part-3/ 2/4
3/9/2021 Linear Programming with Python and PuLP – Part 3 – Ben Alex Keen
A = pulp.LpVariable('A', lowBound=0, cat='Integer')
B = pulp.LpVariable('B', lowBound=0, cat='Integer')
In [4]:
# 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
In [5]:
# Solve our problem
model.solve()
pulp.LpStatus[model.status]
Out[5]:
'Optimal'
In [6]:
# Print our decision variable values
print "Production of Car A = {}".format(A.varValue)
print "Production of Car B = {}".format(B.varValue)
Production of Car A = 2.0
Production of Car B = 6.0
In [7]:
# Print our objective function value
print pulp.value(model.objective)
330000.0
benalexkeen.com/linear-programming-with-python-and-pulp-part-3/ 3/4
3/9/2021 Linear Programming with Python and PuLP – Part 3 – Ben Alex Keen
So that’s €330,000 monthly pro t, compared to their original monthly pro t of €300,000
By producing 2 cars of Car A and 4 cars of Car B, we bolster the pro ts at the factory by €30,000 per mon
We take our consultancy fee and leave the company with €360,000 extra pro t 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
© 2021 Ben Alex Keen All rights reserved
benalexkeen.com/linear-programming-with-python-and-pulp-part-3/ 4/4