Python Tutorial : Basics of PuLP modeling
Key Takeaways
This video tutorial covers the basics of PuLP modeling in Python, focusing on linear and integer programming problems using the PuLP library, which relies on a solver to compute a solution and works with many different solvers, including a resource scheduling example for a cake bakery.
Full Transcript
in this lesson we discussed IP and LP modeling in pole this course will focus on using the Python pulp library it is a framework for linear and integer programming problems the libraries maintained by the coin or our foundation pulp models the problems in Python but relies on a solver to compute a solution it works with many different solvers let's jump right into example that focuses on resource scheduling imagine that you are consulted for a cake bakery that sells only two types of cakes you are attempting the schedule of resources of the bakery for the next 30 days there is an oven to Baker's and a person who packages the cakes in this case we assume the person packaging will only work 22 in the next 30 days due to vacation the amount of time needed for each resource is different for each type of cake additionally the profit for the cakes are different we want to know how many of each type of cake we should make to maximize a profit remember that our profits are subject to the different constraints first the number of cakes produce must be greater than 0 the number of cakes of each type produce multiplied by the time needed on the oven gives a total number of days and this cannot exceed 30 days a similar situation exists for the Baker's however because there are two Baker's the total number of days should not exceed 60 days finally the worker packaging is only available 22 days this month to solve our example we will model it in Pulp a common modeling process involves initializing a model defining the decision variables defining the objective function defining the model constraints and finally we solve it these steps should feel familiar from the lesson on LP and IP modeling initializing the model is the first step in the modeling process and for that you will use the LP problem function it has two inputs the first is a text input for the type of problem you are modeling the second input tells if the model should look to maximize or minimize the objective function for example when modeling delivery times you will likely choose to minimize after importing the package we initialize a model with LP problem in our Python script and choose to maximize next we look at defining the decision variables for this you will use the LP variable class this class has five inputs the first is the name of the variable the next to set the lower and upper bounds of the variable their default value is none which sets the bounds to negative infinity for lower amount or positive infinity for the upper bound the cat input categorizes the variable as either an integer binary or continuous the last input is related to column based modeling which is outside the scope of this course in our example the variables are how many a and B cakes are produced we only set the lower bounds and force them to be an integer variable next we define the objective function using our variables then we define the constraints Pope is able to identify which equations are constraints because of the inequalities finally solve them all the optimized values are stored in var value here is a full script in this lesson we discussed that pulp is an LP and IP model II framework we review the five common steps in a pulp modeling process finally we worked through a resource scheduling example all right let's
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/supply-chain-analytics-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
In this lesson, we discuss IP and LP modeling in PuLP.
This course will focus on using the Python PuLP library. It is a framework for linear and integer programming problems. The library is maintained by the COIN-OR Foundation. PuLP models the problem in Python but relies on a solver to compute a solution. It works with many different solvers.
Let's jump right into an example that focuses on resource scheduling.
Imagine that you are a consultant for a cake bakery that sells only two types of cakes. You are attempting to schedule the resources of the bakery for the next 30 days. There is an oven, two bakers, and a person who packages the cakes. In this case, we assume the person packaging will only work 22 of the next 30 days, due to vacation.
The amount of time needed with each resource is different for each type of cake. Additionally, the profit for the cakes is different.
We want to know how many of each type of cake we should make to maximize our profits. Remember that our profits are subject to different constraints.
First, the number of cakes produced must be greater than zero.
The number of cakes of each type produced multiplied by the time needed on the oven gives the total number of days, and this cannot exceed 30 days.
A similar situation exists for the bakers. However, because there are 2 bakers the total number of days should not exceed 60 days.
Finally, the worker packing is only available 22 days this month.
To solve our example we will model it in PuLP. A common modeling process involves initializing the model, defining the decision variables, defining the objective function, defining the model constraints, and finally we solve it. These steps should feel familiar with the lesson on LP and IP modeling.
Initializing the mod
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
🎓
Tutor Explanation
DeepCamp AI