There are many use cases of operations research (OR) where the decision problem is finding an optimal sequence over time. For instance, we may be interested in allocating a resource (e.g., a machine, a human, a facility, a plane, a cloud computer) overtime to conduct a set of tasks (e.g., manufacturing, project, order picking, flight, online learning). Therefore, many practitioners involved in airport management, project management, manufacturing, etc., are interested in creating high-quality schedules. In this article, I describe how one can code such a decision problem using Python programming language and PuLP as an optimization interface. In other words, the readers will learn scheduling in Python.
1. Modeling and solving the scheduling problem in Python
At first, I code the decision problem according to the following assumptions regarding the elements of the decision making environment:
- Can not conduct more than one task at a time. (No multi-tasking)
- Has a setup time before starting to conduct any task.
- Processes one job after another immediately.
- Have a specific processing time.
- Have a specific priority (weight).
- Are equivalent to a single job (i.e., all tasks consist of one job).
- Starts from zero.
- Is to minimize the total weighted completion time (TWCT).
Herein, I provide a code that models the decision problem, satisfying the mentioned assumptions:
Still, I need to solve the model, so I add the following piece of code:
Finally, the results after the implementation are as follows:
2. Visualization of the results
Even if the above piece of code has yielded the necessary results, understandable by an expert, it does not suffice the needs of a business. The results are usually hard to understand in this form. Accordingly, visualization of the obtained results matters. I add the following piece of code to make it easier to understand the results:
The above code creates a list representing the sequence suggested by the optimization model. What if we could have a Gantt chart to ease reviewing the results? As we all know, a figure is always worth more than a text. So I add the following code:
The code creates a Gantt chart, assigns random colors to each part, and annotates them. Accordingly, the following figure is made:
In this article, I introduced how a single machine scheduling problem is solved via PuLP, an interface for optimization, in the Python programming language. The interested readers can visit previous articles on interfaces and solvers to learn more about them. Finally, if you are interested in the content we publish, let us know by commenting below this article!
If this article is going to be used in research or other publishing methods, you can cite it as Tafakkori (2022) (in text) and refer to it as follows: Tafakkori, K. (2022). Single machine scheduling with PuLP in Python. Supply Chain Data Analytics. url: https://www.supplychaindataanalytics.com/single-machine-scheduling-with-pulp-in-python
Industrial engineer focusing on leveraging optimization methods and artificial intelligence technologies using multiple programming languages to empower a business to achieve its goals!