Problem Statement: Transportation Problem
A company needs to ship goods from two warehouses to three retail stores.
The goal is to minimize the total shipping cost, given the following constraints:
Supply at warehouses:
- Warehouse $1$: $20$ units
- Warehouse $2$: $30$ units
Demand at stores:
- Store $A$: $10$ units
- Store $B$: $25$ units
- Store $C$: $15$ units
Cost per unit shipped (in $):
| Store A | Store B | Store C | |
|---|---|---|---|
| Warehouse 1 | 8 | 6 | 10 |
| Warehouse 2 | 9 | 12 | 5 |
Objective
Minimize the total shipping cost while meeting supply and demand constraints.
Python Solution
We’ll use scipy.optimize.linprog to solve this transportation problem.
Code
1 | import numpy as np |
Explanation
Objective Function:
Minimize total shipping cost:
$$
Z = 8x_{11} + 6x_{12} + 10x_{13} + 9x_{21} + 12x_{22} + 5x_{23}
$$Constraints:
- Supply:
$$
x_{11} + x_{12} + x_{13} \leq 20 \quad \text{(Warehouse 1 supply)}
$$
$$
x_{21} + x_{22} + x_{23} \leq 30 \quad \text{(Warehouse 2 supply)}
$$ - Demand:
$$
x_{11} + x_{21} = 10 \quad \text{(Store A demand)}
$$
$$
x_{12} + x_{22} = 25 \quad \text{(Store B demand)}
$$
$$
x_{13} + x_{23} = 15 \quad \text{(Store C demand)}
$$
- Supply:
Result:
The solver finds the optimal shipping plan to minimize the cost.Visualization:
- The $heatmap$ shows shipping quantities from each warehouse to each store.
Example Output

- Optimal cost: $$345.00$
- Ship:
- $0.00$ units from Warehouse $1$ to Store $A$
- $20.00$ units from Warehouse $1$ to Store $B$
- $0.00$ units from Warehouse $1$ to Store $C$
- $10.00$ units from Warehouse $2$ to Store $A$
- $5.00$ units from Warehouse $2$ to Store $B$
- $15.00$ units from Warehouse $2$ to Store $C$
This demonstrates how optimization efficiently allocates resources while minimizing costs.








