Introduction to Linear Programming with Python and PuLP

Linear Programming, also sometimes called linear optimisation, involves maximising or minimising a linear objective function, subject to a set of linear inequality or equality constraints.

It has great applications in the field of operations management but can be used to solve a range of problems.

Leonard Kantrovich was awarded the 1975 Nobel Price in Economics for the optimal allocation of resources using linear programming.

Examples of problems that can be solved by linear programming include:

  • Scheduling – Rota or Factory scheduling to meet production/workload demands at lowest cost
  • Resourcing Problems – How best to allocate resources to maximise profits
  • Blending Problems – Cost effectively blending a mixture of components
  • Sudoku

In this series of posts, we explore some linear programming examples, starting with some very basic Mathematical theory behind the technique and moving on to some real world examples.

We will be using python and the PuLP linear programming package to solve these linear programming problems. PuLP largely uses python syntax and comes packaged with the CBC solver; it also integrates nicely with a range of open source and commercial LP solvers.

This tutorial should have you up and running and solving your own linear programming problems using python in no time.

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

If you’re interested in downloading the jupyter notebooks to have a go yourself with the examples I’ve written out here, they’re all available on Github here