In the past, we used to model a real-world optimization problem then solve it with an optimization solver and give the optimal result to managers and decision makers. Thus, optimization models were traditionally designed for use in strategic/tactical decisions rather than operational ones.
These days, however, many in industry want to plan and make optimal decisions regularly as a part of their hourly, daily, or weekly operations.
PuLP is arguably the easier module to learn from the three (PuLP, SciPy, Pyomo), however it can deal only with linear optimization problems. Pyomo seems to be more supported than PuLP, has support for nonlinear optimization problems, and last but not the least, can do multi-objective optimization.
Typical situation in real life
Let’s consider simplified transportation type problem. We have set of customers and set of factories . Each customer has some fixed product demand and each factory has fixed production capacity . There are also fixed transportation costs to deliver one unit of good from factory to customer .
Our task is to deliver necessary amount of goods to each customer (satisfy customer demand and factories production capacity) at minimal total transportation cost.
Mathematically this optimization problem can be described as follows.
To formulate this situation as optimization problem we must separate it into 3 main components:
- decision variables — quantities of goods to be sent from factory j to customer i (positive real numbers)
- constraints — total amount of goods must satisfy both customer demand and factory production capacity (equalities/inequalities that have linear expression on the left-hand side)
- objective function — find such values of decision variables that total transportation cost is the lowest (linear expression in this case)
My own experience
I encountered an interesting question from playing a game. I want to find the optimized combination of 3 types of battleships in a fleet which will satisfy these conditions:
- quantity of ship type 1:
- quantity of ship type 2:
- quantity of ship type 3:
- the max unit supply must be equal or less than 300:
- the output damage from this combinations is max:
Find below a solution using PuLP in GitHub Gist.
- Real Python | Hands-On Linear Programming: Optimization With Python
- Opex Analytics | Optimization Modeling in Python: PuLP, Gurobi, and CPLEX
- GeeksforGeeks | Python | Linear Programming in Pulp
- Analytics Vidhya | Optimization Modelling in Python: SciPy, PuLP, and Pyomo