Programming lesson
Optimizing Vaccine Distribution with OR: A Craft Beer Analogy
Learn how Operations Research techniques like linear programming and Gurobi optimization can solve complex distribution problems, using a fun craft beer analogy inspired by the 2410 US craft beers assignment.
From Craft Beer to Vaccines: How Operations Research Optimizes Distribution
Imagine you're running a craft brewery in Portland, Oregon, in May 2026. You have 2410 barrels of specialty IPA, each with a unique hop profile, and you need to distribute them to 50 bars across the city. Each bar has a demand, each delivery truck has a capacity, and you want to minimize transportation costs while ensuring every bar gets its favorite brew. This is essentially the same problem Pacific Paradise faces with vaccine distribution—except instead of IPAs, they're shipping life-saving doses. In this tutorial, we'll explore how Operations Research (OR) and linear programming can model such problems, using a craft beer twist to make the math more flavorful.
Understanding the Problem: Sets, Data, and Variables
In any OR problem, we start by defining the basic building blocks. Let's say we have a set of breweries (supply points) and a set of bars (demand points). For each brewery, we know how many barrels it can supply. For each bar, we know how many barrels it needs. We also have the cost to ship one barrel from each brewery to each bar. Our decision variables are the number of barrels shipped along each route. This is a classic transportation problem, and it's exactly the kind of model you'll build for the 2410 US craft beers assignment, but adapted for vaccine distribution.
# Python code snippet for Gurobi model
from gurobipy import *
# Sets
breweries = ['B1', 'B2', 'B3']
bars = ['Bar1', 'Bar2', 'Bar3']
# Data
supply = {'B1': 100, 'B2': 150, 'B3': 200}
demand = {'Bar1': 120, 'Bar2': 180, 'Bar3': 150}
cost = {('B1','Bar1'): 2, ('B1','Bar2'): 3, ...}
# Model
m = Model('beer_distribution')
# Variables
x = m.addVars(breweries, bars, name='ship')
# Objective: minimize total cost
m.setObjective(quicksum(cost[bw, br] * x[bw, br] for bw in breweries for br in bars), GRB.MINIMIZE)
# Supply constraints
for bw in breweries:
m.addConstr(quicksum(x[bw, br] for br in bars) <= supply[bw], name='supply_'+bw)
# Demand constraints
for br in bars:
m.addConstr(quicksum(x[bw, br] for bw in breweries) >= demand[br], name='demand_'+br)
m.optimize()This code sets up the optimization model using Gurobi. The objective function minimizes total shipping cost, subject to supply and demand constraints. In the vaccine context, the 'breweries' become distribution centers, and 'bars' become vaccination sites. The same mathematical structure applies.
Adding Real-World Constraints: Capacity and Time Windows
In practice, distribution problems often have extra constraints. For example, trucks have limited capacity, or vaccines must be delivered within a certain time window. Let's add a constraint that each truck can carry at most 50 barrels. We can model this by introducing a set of trucks and binary variables indicating which truck serves which route. This becomes a more complex mixed-integer linear programming (MILP) problem. For instance, if you're optimizing last-mile delivery for a pharmacy chain like CVS, you'd need to consider truck capacity and delivery windows.
# Adding truck capacity constraints
trucks = ['T1', 'T2', 'T3']
truck_cap = 50
# Binary variable: 1 if truck t serves route (bw, br)
y = m.addVars(trucks, breweries, bars, vtype=GRB.BINARY, name='assign')
# Each route can be served by at most one truck
for bw in breweries:
for br in bars:
m.addConstr(quicksum(y[t, bw, br] for t in trucks) <= 1)
# Capacity constraint: total barrels on truck t <= truck_cap
for t in trucks:
m.addConstr(quicksum(x[bw, br] * y[t, bw, br] for bw in breweries for br in bars) <= truck_cap)This type of model is used in real-world logistics for companies like Amazon or FedEx, where package delivery routes are optimized daily. In the vaccine distribution scenario, similar constraints ensure that doses are delivered efficiently without overloading any single vehicle.
Interpreting Results: Sensitivity Analysis and Insights
Once the model solves, you get optimal shipment quantities and total cost. But the real value comes from sensitivity analysis. For example, what if the demand at a particular bar increases by 10%? How much would total cost rise? Gurobi provides shadow prices and reduced costs that answer these questions. In the craft beer analogy, if a popular bar suddenly orders more IPA, the brewery might need to reroute shipments from other bars, increasing costs. Similarly, for vaccines, a sudden surge in demand at a clinic might require reallocating doses from other sites.
In your report to the client (Section B), you should highlight such insights. For instance, you might say: 'The most binding constraint is the supply at distribution center Seattle. If we increase supply there by 100 doses, total cost decreases by $500.' This kind of analysis helps decision-makers allocate resources effectively.
Connecting to Current Trends: AI and Real-Time Optimization
In 2026, AI-powered optimization is transforming supply chains. Companies like Uber use real-time routing algorithms to match drivers with riders. In vaccine distribution, similar AI models can adjust to traffic conditions, storage limitations, and population movement. For example, during a flu outbreak, the model could dynamically reroute vaccines to areas with rising infection rates. The same principles apply to craft beer distribution: if a heatwave increases demand for IPAs, the model can quickly shift supply.
Writing Your Report: Sections A and B
For Section A, you need a mathematical formulation and Python files. Your formulation should clearly define sets (e.g., I = set of supply points, J = set of demand points), parameters (supply_i, demand_j, cost_ij), variables (x_ij), objective (minimize sum cost_ij * x_ij), and constraints (supply, demand, non-negativity). Then, implement it in Python using Gurobi, making sure to comment your code so your boss can follow along.
For Section B, write a client-friendly summary of your results. Use plain language and visualizations (even if just in text) to explain the optimal distribution plan. For example, 'We recommend shipping 200 doses from Seattle to Portland, 150 from Seattle to Eugene, etc., at a total cost of $4,500.' Also, discuss any trade-offs, like if you had to prioritize certain sites due to limited supply.
Video Presentation Tips
Your 7-minute video should cover the problem, your approach, key results, and insights. Use slides with clear graphs. Focus on one or two constraints that had the biggest impact on cost. For instance, if a truck capacity constraint increased costs by 20%, explain why and suggest alternatives like using larger trucks. Practice your timing—7 minutes goes fast.
Final Thoughts
Whether you're distributing craft beer or vaccines, the underlying OR techniques are the same. By mastering linear programming and Gurobi, you can solve real-world problems efficiently. This assignment is your chance to shine—show your boss you can tackle complex logistics with mathematical rigor. And who knows? Maybe your optimized beer distribution plan will make you the hero of Portland's craft beer scene.
Remember: The key to a great OR model is clarity in formulation, correctness in code, and insight in interpretation. Good luck!