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
The Data Monk services
We are well known for our interview books and have 70+ e-book across Amazon and The Data Monk e-shop page . Following are best-seller combo packs and services that we are providing as of now
- YouTube channel covering all the interview-related important topics in SQL, Python, MS Excel, Machine Learning Algorithm, Statistics, and Direct Interview Questions
Link – The Data Monk Youtube Channel - Website – ~2000 completed solved Interview questions in SQL, Python, ML, and Case Study
Link – The Data Monk website - E-book shop – We have 70+ e-books available on our website and 3 bundles covering 2000+ solved interview questions. Do check it out
Link – The Data E-shop Page - Instagram Page – It covers only Most asked Questions and concepts (100+ posts). We have 100+ most asked interview topics explained in simple terms
Link – The Data Monk Instagram page - Mock Interviews/Career Guidance/Mentorship/Resume Making
Book a slot on Top Mate
The Data Monk e-books
We know that each domain requires a different type of preparation, so we have divided our books in the same way:
1. 2200 Interview Questions to become Full Stack Analytics Professional – 2200 Most Asked Interview Questions
2.Data Scientist and Machine Learning Engineer -> 23 e-books covering all the ML Algorithms Interview Questions
3. 30 Days Analytics Course – Most Asked Interview Questions from 30 crucial topics
You can check out all the other e-books on our e-shop page – Do not miss it
For any information related to courses or e-books, please send an email to [email protected]
Comment ( 1 )
I’m getting PulpSolveError on model.solve(). Any help why it is so