There are three types of programming which we can do in Supply Chain

**a. Linear Programming –** It involves creating a model on continuous variables

**b. Integer Programming –** It involves creating a model on only Discrete or Integer value

**c. Mixed Integer Programming –** It is a mix of continuous and discrete variables

**What is PuLP? **PuLP is a Python Library that enables users to describe mathematical programs. PuLP works entirely within the syntax and natural idioms of the Python language by providing Python objects that represent optimization problems and decision variables, and allowing constraints to be expressed in a way that is very similar to the original mathematical expression.

PuLP has focused on supporting linear and mixed-integer models.

We will be using PuLP to solve some Supply Chain Problems

Introduction to PuLP in Supply Chain Analytics

PuLP as you know is an Integer Programming/Linear Programming Modeler. There are three parts of creating a model in PuLP:-

**a. Decision Variables –** These are the variables which impacts the Supply Chain. For example, Number of pressure cooker is a decision variable to cook Rice. More number of Pressure cooker will help you in cooking more rice

**b. Objective Functions –** These are the mathematical equations to use Decision variables to optimize your process i.e. either maximize or minimize something. Example, You have 3 pressure cooker and 2 Stoves, and you have to cook Rice and Lentils. Now you need to figure out an objective function to cook maximum rice and lentils in 1 hour using the above utensils

**c. Constraints –** These are the things which limits our ideal or optimized solution.

Let’s take a case study of Supply Chain optimization.

There is a Restaurant which serves Mega Pizza (40”). It has one oven, 3 bakers, and 1 packer. Following is the time required by each Pizza

Number | Pizza A | Pizza B | Pizza C | Working Days | |

Oven | 1 Oven | 1 Day | 0.5 Day | 1 Day | 30 Days |

Baker | 3 Bakers | 1 Day | 2 Days | 2 Days | 30 Days |

Packer | 2 Packers | 1 Day | 1 Day | 1 Day | 20 Days |

Profit | $30 | $40 | $50 |

Now you have to maximize the Profit using PuLP library. Use decision variables, objective functions, and constraints.

How much pizza of each type should we make in 30 days.

First let’s look into the coding part in Python

**from pulp import ***

**model = LpProblem(“Maximize Pizza Profit”, LpMaximize)**

#Declare Decision Variable

**A = LpVariable(‘A’,lowbound=0,upbound = None,cat=’Integer’) B = LpVariable(‘B’,lowbound=0, upbound = None, cat=’Integer’) C = LpVariable(‘C’,lowbound=0,upbound = None, cat=’Integer’)**

#Define Objective function

#For Oven

**model += 1*A + 0.5*B + 1*C <= 30**

#For Baker

**model += 1*A+2*B+2*C <=90**

#For Packer

**model += 1*A+1*B+1*C <= 40**

#Solve Model

**model.solve()**

print(“Produce {} Pizza A”.format(A.varValue))

print(“Produce {} Pizza B”.format(B.varValue))

print(“Produce {} Pizza C”.format(C.varValue))

print(“Produce {} Pizza A”.format(A.varValue))

print(“Produce {} Pizza B”.format(B.varValue))

print(“Produce {} Pizza C”.format(C.varValue))

Now let’s understand the code

** ****from pulp import ***

Here you are importing the complete package

* model = LpProblem(“Maximize Pizza Profit”, LpMaximize) *Here you are defining the model using LpProblem function. The LpMaximize will look for maximizing the value i.e. Profit. If you want to get the minimum value from the model then use LpMinimize. We can use LpMinimize when we are talking about reducing the wastage.

*Here we define each Variable using LpVariable function. Lowbound refers to the lowest possible value of the variable.*

**A = LpVariable(‘A’,lowbound=0,upbound = None,cat=’Integer’)**Pizza can not be negative so we have given the value 0, Upbound is the maximum value of the variable.

None will ensure that the upbound could be anything

cat is the characteristic of the variable. It could be integer, categorical, or Binary

* model += 1*A + 0.5*B + 1*C <= 30 *This is the constraint for Oven. A requires 1 day, B requires 0.5 Day, and C requires 1 Day. The <=30 is the constraint which is because there is one oven which will work for 30 days

*Similar to the above, the Baker will need 1, 2, and 2 days for A,B, and C respectively. And there are 3 Bakers which work 30 days. Thus constraint is 30*3 = 90*

**model += 1*A+2*B+2*C <=90***#For Packer*

A packer takes 1,1,and 1 day for A,B, and C pizza. And there are 2 Packers who works 20 days each. Thus constraint is 40.

**model += 1*A+1*B+1*C <= 40**This is a simple example with fixed constraints. We will deal with variable components in the next article 🙂

Keep Learning 🙂

Tha Data Monk