## Supply Chain Analytics in Python

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 Pizz

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))*

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.

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

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

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

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

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

*#For Packer*

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

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

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

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

## Leave a reply