3 April 2023
In the previous article, we built a staff scheduling optimization model in Excel, using OpenSolver. That model enumerates all possible shift patterns and then decides how many of each shift pattern to use so that we meet the various constraints at least cost.
Our focus in this article is on replicating the Excel model by translating it into Python, using the Pyomo library. That involves formalizing the mathematical formulation, creating appropriate data structures, and representing the formulation in Pyomo syntax. Both models use the CBC solver, so the differences between the models aren't in the solving process, but rather in the build process.
Excel can be a great tool for some types of optimization modelling, either for prototyping or as a production tool. Python offers a wider range of optimization options, and it is usually better for models that have varying data sizes or need to operate at a large scale. The advantages and disadvantages of modelling in Excel and Python are discussed in more detail in our article Optimization in Excel vs Python.
27 March 2023
A common application of optimization modelling is the scheduling of staff to meet demand. Scheduling problems can be difficult to solve, as there are often very specific requirements that need to be met, including staff availability, working hours, break times, etc.
One approach for formulating scheduling problems is to enumerate all possible shift patterns and then decide how many of each shift pattern to use so that we meet the various constraints at least cost.
Enumeration of all possible shift patterns is often not as difficult as it may sound. We used a similar technique in the model Green manufacturing via cutting patterns. In that situation, there were potentially thousands of possible patterns, requiring an automated process to generate them all. In the staff scheduling situation there is usually a much smaller number of possible patterns, so manual enumeration is often possible.
This article implements a staff scheduling model in Excel and solves it using the CBC solver via OpenSolver. The next article implements the same model in Python, solves it using the CBC solver via Pyomo, then compares the Excel and Python model versions.
16 March 2023
In this article we conclude the Python Production mix series. We provide a summary of the optimization libraries that we've used, including the advantages and disadvantages of each. We also indicate which library is our first choice for different types of modelling.
Our objective in this series has been to compare creating a simple linear programming model in a variety of Python libraries, using Pyomo as a baseline.
10 March 2023
In this article we continue the Python Production mix series. Specifically, we build Model 11 using the SciPy library.
SciPy is an open source Python package for a wide range of scientific computing applications, including optimization, integration, interpolation, eigenvalue problems, algebraic equations, differential equations, statistics and many other classes of problems.
Our objective is to compare a linear programming model built using SciPy with the same model built using Pyomo.
12 December 2022
In this article we continue the Python Production mix series. Specifically, we build Model 10 using the CVXPY library.
CVXPY is an open source Python package for representing and solving convex optimization problems.
Our objective is to compare a model built using CVXPY with the same model built using Pyomo.
22 November 2022
In this article we continue the Python Production mix series. Specifically, we build Model 9 using the Gekko library.
Gekko is a Python package for machine learning, optimization of mixed-integer, and differential algebraic equations.
Our objective is to compare a model built using Gekko with the same model built using Pyomo.
31 October 2022
In this article we continue the Python Production mix series. Specifically, we build Model 8 using the OR-Tools library.
OR-Tools is a project from Google. The library is freely available, the code is open source, and it is widely used.
Our objective is to compare a model built using OR-Tools with the same model built using Pyomo.
4 October 2022
In this article we continue the Python Production mix series. Specifically, we build Model 7 using the PuLP library.
PuLP, like Pyomo, is a COIN-OR project. The library is freely available, the code is open source, and it is widely used.
Our objective is to compare a model built using PuLP with the same model built using Pyomo.
21 September 2022
In this article we continue the Python Production mix series, using the Pyomo library. Specifically, we build Model 6, which changes Model 5 to:
- Declare the model as a Pyomo
pyo.AbstractModel
, rather than as apyo.ConcreteModel
. - Read the data from a
dat
file rather than ajson
file.
These changes show that, contrary to how abstract and concrete models are portrayed in most blogs, there is actually little difference between abstract and concrete Pyomo models.
5 September 2022
In this article we continue the Python Production mix series, using the Pyomo library. Specifically, we build Model 5, which changes Model 4 to:
- Define the constraints and objective function using
def
function blocks. - Output the slack values and dual prices (also known as shadow prices) for each constraint.
These changes give us more control over how the model is defined and provide more information about the solution.