• Abhinav Bangia

pip install PuLP : Getting started with Linear Optimization




Understanding Linear Programming

  • Linear programming (LP) is a method for engineers or data scientists to find the best outcome of a business problem i.e maximum profit, minimum cost in a linear mathematical model.

  • Each of the LP problem consist of following components : 1. Objective Function : Purpose behind LP i.e maximize profit, minimize loss , 2. Decision Variables : These are the controllable variables that influence the objective function, 3. Constraints : These are linear restrictions on decisions variables.


Case Example : XYZ Pharmaceuticals

  • XYZ Pharmaceuticals manufacturers two types of medicine with same salt : A and B. The manufacturer wants to maximize their weekly operational profit.

  • $1 of profit per medicine A.

  • $1.5 of profit per medicine B.

  • Medicine A requires 1 hour of manufacturing labor and 2 hours of packaging labor.

  • Medicine B requires 2 hours of manufacturing labor and 1 hour of packaging labor.

  • Each week, XYZ has only 100 hours of manufacturing labor and 100 hours of packaging labor available.


Lets Build the Objective Function, Decision Variables and Constraints

  1. Let x be the of medicine A produced and y be the medicine B product in the week

  2. Objective Function : Max(z) = 1x + 1.5y

  3. Decision Variables (Subject to) 1x + 2y <= 100 (Available Manufacturing Hours) 2x + 1y <=100 ( Available Packaging Hours)

  4. Constraints : x >= 0 & y >= 0


Loading & Solving the Problem Statement in PuLP


Discussing Solution


We see that the optimal solution for production of Medicine A & B to return maximum profit is 33.33 units weekly for both A & B to maximize the profit up to 83.33 units. We can even plot the illustrative graph using matplotlib library in python.



There are many commercial optimizer tools, but having hands-on experience with a programmatic way of doing optimization is invaluable.



60 views

Com Olho is a leading cloud-based machine learning as a service platform. We make it easy for CXO's to understand their consumers using behaviour analytics, machine learning and data science. 

e : contact@comolho.com

© 2019-2020 COM OLHO IT PRIVATE LIMITED

  • Facebook
  • Grey LinkedIn Icon

Made with      in India