This project provides a Python implementation to solve the classical Transportation Problem, which aims to find the most cost-effective way to transport goods from multiple suppliers to multiple consumers, given supply capacities, demand requirements, and transportation costs.
The transportation problem is a special type of linear programming problem that minimizes the total cost of distributing a product from several suppliers to several consumers while meeting supply and demand constraints.
This solver uses:
- Minimum Cost Method to generate an initial feasible basic solution.
- Potential Method (MODI Method) for iteratively improving the solution by adjusting allocations along cycles until optimality conditions are satisfied.
- Supports arbitrary numbers of suppliers and consumers.
- Calculates an initial feasible solution automatically.
- Iteratively optimizes the solution to reach minimum transportation cost.
- Handles degeneracy by adding artificial zero allocations if necessary.
- Displays intermediate iterations and the final total transportation cost.
generator.py- containt a function that generates transport task input data example.show.py- provide visualization during optimization process.test.py- just a simple test case.transport.py- contains code that solves Transport task.
suppliers: List of integers representing the supply available at each supplier.consumers: List of integers representing the demand required at each consumer.costs: 2D list (matrix) representing the transportation cost from each supplier to each consumer.
| Suppliers \ Consumers | 86 | 103 | 177 | 46 | 1 | 16 | 30 | 20 |
|---|---|---|---|---|---|---|---|---|
| 31 | 41 | 1 | 96 | 37 | 33 | 80 | 27 | 68 |
| 50 | 88 | 22 | 94 | 90 | 29 | 87 | 74 | 19 |
| 93 | 6 | 12 | 88 | 21 | 29 | 83 | 88 | 82 |
| 11 | 73 | 94 | 17 | 77 | 13 | 95 | 94 | 77 |
| 122 | 0 | 71 | 93 | 21 | 52 | 61 | 99 | 37 |
| 172 | 21 | 23 | 24 | 44 | 54 | 29 | 50 | 97 |
suppliers = [31, 50, 93, 11, 122, 172]
consumers = [86, 103, 177, 46, 1, 16, 30, 20]
costs = [
[41, 1, 96, 37, 33, 80, 27, 68],
[88, 22, 94, 90, 29, 87, 74, 19],
[6, 12, 88, 21, 29, 83, 88, 82],
[73, 94, 17, 77, 13, 95, 94, 77],
[0, 71, 93, 21, 52, 61, 99, 37],
[21, 23, 24, 44, 54, 29, 50, 97]
]
total_cost = optimize_transport(suppliers, consumers, costs)
print(f"Minimum total transportation cost: {total_cost}")