1. Basics of PuLP modeling
In this lesson we discuss IP and LP modeling in PuLP.
2. What is 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.
3. PuLP example – resource scheduling
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.
4. PuLP example – resource scheduling
The amount of time needed with each resource is different for each type of cake. Additionally, the profit for the cakes are different.
5. PuLP example – resource scheduling
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 the 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 exist 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.
6. Common modeling process for PuLP
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 from the lesson on LP and IP modeling.
7. Initializing model - LpProblem()
Initializing the model is the first step in the modeling process and for that you will use the LpProblem 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.
8. PuLP example – resource scheduling
After importing the package, we initialize the model with LpProblem in our Python script and choose to maximize.
9. Define decision variables - LpVariable()
Next, we look at defining the decision variables. For this you will use the LpVariable class. This class has 5 inputs.
The first is the name of the variable.
The next two set the lower and upper bounds of the variable. Their default value is None which sets the bounds to negative infinity for the lower bound 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.
10. PuLP example – resource scheduling
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.
11. PuLP example – resource scheduling
Next, we define the objective function using our variables.
12. PuLP example – resource scheduling
Then, we define the constraints. PuLP is able to identify which equations are constraints because of the inequalities.
13. PuLP example – resource scheduling
Finally, solve the model. The optimized values are stored in varValue.
14. PuLP example – resource scheduling
Here is the full script.
15. Summary
In this lesson we discussed that PuLP is a LP and IP modeling framework.
We reviewed the common 5 steps in the PuLP modeling process.
Finally, we worked through a resource scheduling example.
16. Let's practice!
Alright! Let's practice.