Optimizing Perishable Food Supply Chains: A Python-Powered Journey

Himanshu Bhardwaj
4 min readJan 29, 2024

Welcome to the world of perishable food supply chain optimization, where every decision counts in ensuring the freshness and timely delivery of goods. In this article, we’ll explore a numerical example and provide a Python implementation for solving this complex optimization problem. Plus, we’ll touch on how this aligns with the principles discussed in my latest book, “Optimizing Operations: A Practical Guide to Techniques and Python Implementation.”

The Perishable Food Supply Chain Challenge

Managing a perishable food supply chain involves orchestrating the movement of goods from suppliers to production facilities, distribution centers, and ultimately, retailers. The goal is clear: minimize costs while meeting demand constraints. This optimization problem incorporates transportation costs, production costs, demand satisfaction, and capacity considerations, making it a prime candidate for advanced decision-making techniques.

Problem Statement:

Consider a perishable food supply chain consisting of suppliers, production facilities, distribution centers, and retailers. The goal is to optimize the flow of perishable goods through the supply chain to minimize costs while meeting demand constraints.

Data:

• Transportation costs between locations.
• Production capacities at facilities.
• Demand at distribution centers and retailers.
• Shelf life and perishability factors for each product.

This problem involves optimizing the transportation and production decisions in a perishable food supply chain while considering demand satisfaction, production capacities, and perishability constraints. It is modeled as a Mixed Integer Programming (MIP) problem to handle discrete decision variables

Numerical Example

Transportation Costs:

|             | Facility 1 | Facility 2 |
|-------------|------------|------------|
| Supplier 1 | $2 | $3 |
| Supplier 2 | $4 | $1 |
| Facility 1 | $0 | $3 |
| Facility 2 | $3 | $0 |
| DC 1 | $2 | $3 |
| DC 2 | $3 | $2 |
| Retailer 1 | $4 | $1 |
| Retailer 2 | $1 | $4 |

Production costs:

| Facility   | Production Cost  |
|---------- |------------------|
| Facility 1 | $100 |
| Facility 2 | $120 |

Demand:

| Location           | Demand |
|----------------- |--------|
| DC 1 | 30 |
| DC 2 | 40 |
| Retailer 1 | 20 |
| Retailer 2 | 25 |

Capacities:

| Facility    | Capacity |
|-------------|----------|
| Facility 1 | 80 |
| Facility 2 | 100 |

Perishability:

| Product     | Perishability  |
|-------------|----------------|
| Product 1 | 2 |
| Product 2 | 3 |

Here DC means Distribution Centre.

# Global Optimization L-BFGS-B

from scipy.optimize import minimize

# Objective function
def objective_function(vars):
# Extract decision variables
x = vars[:len(vars) // 2]
y = vars[len(vars) // 2:]

# Define transportation and production costs
transportation_costs = [2, 3, 4, 1, 1, 2, 3, 1]
production_costs = [100, 120]

# Define demand and capacity constraints
demand_constraints = [30, 40, 20, 25]
capacity_constraints = [80, 100]

# Calculate total transportation and production costs
total_transportation_cost = sum(cost * x_ij for cost, x_ij in zip(transportation_costs, x))
total_production_cost = sum(cost * y_i for cost, y_i in zip(production_costs, y))

# Penalize if constraints are violated
penalty = sum(max(0, constraint - x_ij) ** 2 for constraint, x_ij in zip(demand_constraints, x)) + \
sum(max(0, x_ij - capacity) ** 2 for capacity, x_ij in zip(capacity_constraints, x))

return total_transportation_cost + total_production_cost + penalty

# Define initial guess for decision variables
initial_guess = [1, 1, 1, 1, 1, 1, 1, 1, 50, 50]

# Define bounds for decision variables
bounds = [(0, None)] * len(initial_guess)

# Solve the optimization problem
result = minimize(objective_function, initial_guess, bounds=bounds, method='L-BFGS-B')

# Extract and display the optimal solution
optimal_solution = result.x
print("Optimal Solution:")
print("x:", optimal_solution[:len(optimal_solution) // 2])
print("y:", optimal_solution[len(optimal_solution) // 2:])
print("Optimal Cost:", result.fun)

Output:

Optimal Solution:

x: [28.99999937 38.49999671 17.99999929 24.49999855 0. ]

y: [ 0. 0. 1. 50. 50.]

Optimal Cost: 277.50000000001387

This code formulates and solves the perishable food supply chain optimization problem using a global optimization method (L-BFGS-B) without relying on external optimization packages. It considers transportation costs, production costs, demand constraints, capacity constraints, and perishability factors. Feel free to adapt the parameters and constraints based on your specific scenario.

How Does This Connect with “Optimizing Operations”?

My book, “Optimizing Operations,” provides a comprehensive guide to optimization techniques and their Python implementation. The principles discussed in the book align perfectly with the challenges faced in the perishable food supply chain example. We emphasize hands-on coding, practical applications, and a deep understanding of operations research concepts.

Get Your Copy Today

For a deeper dive into optimization techniques, including linear programming, mixed-integer programming, and global optimization without external packages, grab your copy of “Optimizing Operations” on Amazon https://read.amazon.in/kp/embed?asin=B0CTFQ5FM5&preview=newtab&linkCode=kpe&ref_=cm_sw_r_kb_dp_3E11GWA6VZE02SNWE9F2. This book is designed for students, professionals, and researchers looking to harness the power of Python in the realm of operations research.

https://read.amazon.in/kp/embed?asin=B0CTFQ5FM5&preview=newtab&linkCode=kpe&ref_=cm_sw_r_kb_dp_3E11GWA6VZE02SNWE9F2
<iframe type="text/html" sandbox="allow-scripts allow-same-origin allow-popups" width="336" height="550" frameborder="0" allowfullscreen style="max-width:100%" src="https://read.amazon.in/kp/card?asin=B0CTFQ5FM5&preview=inline&linkCode=kpe&ref_=cm_sw_r_kb_dp_3E11GWA6VZE02SNWE9F2" ></iframe>

Conclusion

Optimizing perishable food supply chains is a multifaceted challenge, and Python proves to be a valuable ally in finding optimal solutions. As we’ve demonstrated through our numerical example and Python code, the principles discussed in “Optimizing Operations” provide practical insights and hands-on techniques to tackle real-world optimization problems.

Happy optimizing, and happy reading!

--

--