Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Transportation Problems and Analytics Solutions | Integer Programming & Discrete Decision Models
Applied Optimization for Analytics

bookTransportation Problems and Analytics Solutions

Transportation problems are a classic analytics challenge where you must decide how to distribute goods from multiple sources (such as warehouses) to multiple destinations (such as stores) while minimizing total shipping costs. In these problems, each source has a fixed supply of goods available, and each destination has a specific demand that must be met. The cost to ship a unit of goods from each source to each destination is known and may vary depending on the route or distance. The objective is to determine the quantity of goods shipped along each route so that all supply and demand constraints are satisfied, and the overall cost is minimized. This structure is common in logistics, inventory management, and retail analytics, where efficient distribution directly impacts profitability and service levels.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
import numpy as np from scipy.optimize import linprog # Supply at each warehouse supply = [20, 30, 25] # Demand at each store demand = [10, 25, 20, 20] # Cost matrix (warehouses x stores) costs = np.array([ [8, 6, 10, 9], [9, 12, 13, 7], [14, 9, 16, 5] ]) num_warehouses = len(supply) num_stores = len(demand) # Decision variables: x[i][j] is units shipped from warehouse i to store j # Flattened into a single vector for linprog c = costs.flatten() # Build constraints A_eq = [] b_eq = [] # Supply constraints: sum of shipments from each warehouse <= supply for i in range(num_warehouses): row = [0] * (num_warehouses * num_stores) for j in range(num_stores): row[i * num_stores + j] = 1 A_eq.append(row) b_eq.append(supply[i]) # Demand constraints: sum of shipments to each store >= demand for j in range(num_stores): row = [0] * (num_warehouses * num_stores) for i in range(num_warehouses): row[i * num_stores + j] = 1 A_eq.append(row) b_eq.append(demand[j]) # Bounds: variables must be integers >= 0 bounds = [(0, None) for _ in range(num_warehouses * num_stores)] # Solve as a linear program (relaxing integer constraints for demonstration) result = linprog( c, A_eq=A_eq, b_eq=b_eq, bounds=bounds, method='highs' ) # Reshape solution to warehouse x store grid shipment_plan = np.round(result.x).reshape((num_warehouses, num_stores)) print("Optimal shipment plan (units from each warehouse to each store):") print(shipment_plan) print("Total minimum shipping cost:", result.fun)
copy

The solution to this transportation model provides a shipment plan that specifies exactly how many units to send from each warehouse to each store. By satisfying both the supply constraints (not shipping more than each warehouse can provide) and the demand constraints (ensuring each store receives what it needs), the model guarantees that logistics requirements are met. The cost minimization objective ensures that the chosen shipment plan is the most economical possible, directly supporting analytics goals such as reducing operational expenses and improving supply chain efficiency. This approach allows you to make data-driven decisions that align with business objectives, ensuring resources are allocated optimally across your network.

question mark

Which constraint in a transportation model ensures that every store receives the amount of goods it requires?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain how the constraints are set up in the code?

What happens if supply and demand are not balanced?

How would I modify the model for different numbers of warehouses or stores?

bookTransportation Problems and Analytics Solutions

Swipe to show menu

Transportation problems are a classic analytics challenge where you must decide how to distribute goods from multiple sources (such as warehouses) to multiple destinations (such as stores) while minimizing total shipping costs. In these problems, each source has a fixed supply of goods available, and each destination has a specific demand that must be met. The cost to ship a unit of goods from each source to each destination is known and may vary depending on the route or distance. The objective is to determine the quantity of goods shipped along each route so that all supply and demand constraints are satisfied, and the overall cost is minimized. This structure is common in logistics, inventory management, and retail analytics, where efficient distribution directly impacts profitability and service levels.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
import numpy as np from scipy.optimize import linprog # Supply at each warehouse supply = [20, 30, 25] # Demand at each store demand = [10, 25, 20, 20] # Cost matrix (warehouses x stores) costs = np.array([ [8, 6, 10, 9], [9, 12, 13, 7], [14, 9, 16, 5] ]) num_warehouses = len(supply) num_stores = len(demand) # Decision variables: x[i][j] is units shipped from warehouse i to store j # Flattened into a single vector for linprog c = costs.flatten() # Build constraints A_eq = [] b_eq = [] # Supply constraints: sum of shipments from each warehouse <= supply for i in range(num_warehouses): row = [0] * (num_warehouses * num_stores) for j in range(num_stores): row[i * num_stores + j] = 1 A_eq.append(row) b_eq.append(supply[i]) # Demand constraints: sum of shipments to each store >= demand for j in range(num_stores): row = [0] * (num_warehouses * num_stores) for i in range(num_warehouses): row[i * num_stores + j] = 1 A_eq.append(row) b_eq.append(demand[j]) # Bounds: variables must be integers >= 0 bounds = [(0, None) for _ in range(num_warehouses * num_stores)] # Solve as a linear program (relaxing integer constraints for demonstration) result = linprog( c, A_eq=A_eq, b_eq=b_eq, bounds=bounds, method='highs' ) # Reshape solution to warehouse x store grid shipment_plan = np.round(result.x).reshape((num_warehouses, num_stores)) print("Optimal shipment plan (units from each warehouse to each store):") print(shipment_plan) print("Total minimum shipping cost:", result.fun)
copy

The solution to this transportation model provides a shipment plan that specifies exactly how many units to send from each warehouse to each store. By satisfying both the supply constraints (not shipping more than each warehouse can provide) and the demand constraints (ensuring each store receives what it needs), the model guarantees that logistics requirements are met. The cost minimization objective ensures that the chosen shipment plan is the most economical possible, directly supporting analytics goals such as reducing operational expenses and improving supply chain efficiency. This approach allows you to make data-driven decisions that align with business objectives, ensuring resources are allocated optimally across your network.

question mark

Which constraint in a transportation model ensures that every store receives the amount of goods it requires?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 3
some-alt