Optimizing Supply Chain Transportation Costs with PuLP in Python
- Problem:
You have a network of factories and warehouses, and you need to minimize the total transportation cost while satisfying demand at different locations. - PuLP Solution:
Use $PuLP$ to formulate the transportation problem, where the objective is to minimize the transportation cost subject to supply and demand constraints.
1 | import pulp |
Explanation of the Code
num_factoriesandnum_warehousesare the number of factories and warehouses in the supply chain.costsis a 2D list where each entry represents the transportation cost from a factory to a warehouse.supplyis a list that defines the maximum amount of goods available at each factory.demandis a list that defines the required amount of goods at each warehouse.- The decision variables,
transport_vars, represent the amount transported from each factory to each warehouse. - The objective function minimizes the total transportation cost.
- Constraints ensure that the demand at each warehouse is met and that the supply at each factory is not exceeded.
With these changes, the code should run without errors and provide the optimal transportation plan.
Result
1 | Transport from factory 0 to warehouse 0: 20.0 |
The results describe the optimal transportation plan for minimizing costs in a supply chain. Here’s the breakdown:
Factory 0 sends:
- $20$ units to Warehouse 0.
- $0$ units to Warehouse 1 and Warehouse 2.
Factory 1 sends:
- $10$ units to Warehouse 0.
- $20$ units to Warehouse 1.
- $0$ units to Warehouse 2.
Factory 2 sends:
- $0$ units to Warehouse 0.
- $5$ units to Warehouse 1.
- $20$ units to Warehouse 2.
Explanation:
- Warehouse 0 receives a total of $30$ units
($20$ from Factory $0$ and $10$ from Factory $1$). - Warehouse 1 receives a total of $25$ units
($20$ from Factory $1$ and $5$ from Factory $2$). - Warehouse 2 receives a total of $20$ units
(all from Factory $2$).
The plan ensures that each warehouse’s demand is met while keeping the transportation costs as low as possible.
Factory $0$, with a relatively low cost to Warehouse $0$, is utilized for that route, while Factory $2$ is used to supply Warehouse $2$.












