A warehouse can offer a cheap route to a major customer and still be too costly to keep open. Its rent, core staff and basic systems remain payable even when few loads pass through it, while another site may have higher freight rates but enough spare capacity to absorb those loads. The decision needs both costs in one model.
Capacitated facility location chooses which candidate sites to use and how much demand each will serve. It answers a different question from allocating shipments across a network whose sites are already fixed. The result is a set of open facilities, a feasible shipment plan and a cost for that plan.
This guide develops an original apparel distribution example. It compares every possible site combination, tests a rule against split deliveries and explores demand growth. All figures are teaching assumptions in cost units, not market rates or claims about a real company. The arithmetic is small enough to audit without trusting a solver display.
Define the location decision before building the model
Suppose an apparel distributor is reviewing three candidate depots for one planning month. Each depot can handle only a stated number of pallet-equivalent loads, and three customer zones need known quantities during that month. The distributor may open any combination of depots, provided it can serve all demand.
An open depot incurs a fixed monthly cost, while a shipment also incurs a cost per load that depends on its origin and destination. No site is mandatory, and loads can be split between depots in the first version. The model has no stock carryover, delivery calendar or vehicle routing decision.
These boundaries matter. A monthly shipment quantity does not specify which truck arrives on Tuesday. Nor does it prove that a new depot can obtain staff or permits in time. Here the candidate sites have already passed the basic suitability review, so the optimization selects among viable choices.
The SCIP book's facility-location chapter describes the core structure: shipment quantities, binary opening decisions, demand constraints and site capacity. The AMPL tutorial gives another explicit mixed-integer formulation. The notation below follows the decision in this example, rather than the letters in either source.
For an existing fixed network, ApparelDiary's fabric allocation transportation model provides related background. Facility location adds the choice to open or close an origin and pay its associated fixed cost.
Put capacity, demand and cost on matching units
Use one month as the planning period. Demand and capacity are both measured in pallet-equivalent loads per month. The equivalent load is a defined handling unit that need not be a whole physical pallet, which permits fractional quantities when testing percentage changes in demand.
Let one cost unit, written CU, be a consistent teaching currency unit. Fixed costs are CU per month, while variable rates are CU per load. Multiplying a rate by monthly loads gives monthly variable cost, which can then be added to fixed monthly cost.
Candidate depot | Capacity, loads/month | Fixed cost, CU/month |
North | 70 | 150 |
Central | 100 | 260 |
South | 80 | 170 |
Origin | Zone 1, CU/load | Zone 2, CU/load | Zone 3, CU/load |
North | 2 | 4 | 9 |
Central | 4 | 3 | 4 |
South | 9 | 7 | 2 |
Demand, loads/month | 40 | 35 | 45 |
Total demand is 40 + 35 + 45 = 120 loads per month. No single depot can handle that quantity, so at least two sites must open, but this fact alone does not choose the best pair.
The example assumes that the quoted variable rates include the relevant handling and transport costs. A real data sheet should state those boundaries. Adding a separate handling charge when it is already inside the rate would double-count it. Omitting a cost that changes by site can bias the choice just as much.
Capacity also needs a precise meaning. Storage positions, inbound handling capacity and outbound throughput are different measures. A depot with room for 100 pallets does not automatically have capacity to dispatch 100 loads each month. Choose the binding resource for this model, or add separate constraints for the resources that matter.
Build the opening and shipment variables
Let i identify a candidate depot and j identify a customer zone, with y(i) defined as 1 when depot i is open and 0 when it is closed. Define x(i,j) as the monthly loads sent from i to j. Shipment quantities cannot be negative.
The opening variable is binary because half of a depot opening is not a valid choice here. Shipment quantities are continuous because the base model allows demand to be divided. The model links these two decisions while preserving the different type of variable that each requires.
Let f(i) be the fixed monthly cost, c(i,j) the variable rate, K(i) the capacity and d(j) the demand. The objective adds the fixed cost of each open depot to the cost of all shipments.
Minimize total cost = Σ f(i)y(i) + ΣΣ c(i,j)x(i,j)
For each zone, incoming shipments must equal its demand. Equality is useful here because excess deliveries have no purpose. There is no disposal outlet or permitted advance stocking in the stated problem.
For each zone j: Σ x(i,j) = d(j)
For each depot, total shipments cannot exceed its available capacity. Multiplying capacity by the opening variable also prevents shipments from a closed site.
For each depot i: Σ x(i,j) ≤ K(i)y(i)
When y(i) is zero, the right side is zero. Nonnegative shipments must then all be zero. When y(i) is one, the depot can ship up to K(i) loads. The Gurobi facility example implements this same opening-to-capacity relationship.
An open site is allowed to be idle. Positive fixed costs make an unnecessary idle site unattractive in this example, but the constraints do not forbid one. A requirement to keep a strategic depot open would be a separate business rule, expressed by fixing its opening variable to one.
Work through the North–South plan
Open North and South and close Central. North has the lowest rate to Zone 1, so send all 40 loads there from North. South has the lowest rate to Zone 3, so send all 45 loads there from South.
North has 70 − 40 = 30 loads of capacity left. Sending those 30 loads to Zone 2 costs 4 CU each. Zone 2 still needs 35 − 30 = 5 loads, which South supplies at 7 CU each.
Shipment | Loads/month | Rate, CU/load | Cost, CU/month |
North to Zone 1 | 40 | 2 | 80 |
North to Zone 2 | 30 | 4 | 120 |
South to Zone 2 | 5 | 7 | 35 |
South to Zone 3 | 45 | 2 | 90 |
Total variable cost | 120 | — | 325 |
Fixed cost is 150 + 170 = 320 CU per month. Total cost is therefore 320 + 325 = 645 CU per month. North ships 70 loads and uses all its capacity, while South ships 50 loads and leaves 30 loads of unused capacity.
Check demand by column rather than by total alone. Zone 1 receives 40 loads. Zone 2 receives 30 + 5 = 35 loads. Zone 3 receives 45 loads. A grand total of 120 would not detect a plan that oversupplied one zone and missed another.
The route choice also has a useful economic explanation. With North and South open, using North for one load of Zone 1 saves 9 − 2 = 7 CU compared with South. Using it for Zone 2 saves 7 − 4 = 3 CU. North's scarce capacity should first support the larger saving. This is a check for this small case, not a general algorithm for complex networks.
Prove that the selected sites are cheapest
A feasible plan establishes a cost that can be achieved, but it does not prove that another site combination cannot do better. With three candidates, there are only eight opening patterns, including the pattern with no open sites.
The empty pattern and all three one-site patterns lack enough capacity. For each remaining pattern, minimize shipment cost while keeping that site's status fixed. Then add the fixed cost. The four feasible results are shown below.
Open depots | Lowest variable cost | Fixed cost | Total CU/month |
North and South | 325 | 320 | 645 |
North and Central | 365 | 410 | 775 |
Central and South | 355 | 430 | 785 |
All three | 275 | 580 | 855 |
Opening all three gives each zone access to its cheapest origin. Its variable cost falls to 275 CU, but fixed cost rises to 580 CU. The 50 CU reduction in shipment cost from the North–South plan cannot justify the extra 260 CU fixed cost of Central.
The complete comparison proves an optimum of 645 CU for the stated model. It also shows why minimizing freight alone fails. That approach would favor all three sites and produce a total cost 855 − 645 = 210 CU higher.
These results were checked in two ways: enumeration of all opening patterns with a linear shipment model, and a single mixed-integer model. The checks also verified each zone balance and each site capacity. Agreement is useful evidence, while the published table lets a reader inspect the economic logic directly.
Reproduce the small enumeration
Once opening decisions are fixed, this example becomes a linear program. The following Python uses NumPy and SciPy. Rows in the cost matrix are depots; columns are zones. The SciPy linprog documentation explains the equality, inequality and bound arguments.
from itertools import product
import numpy as np
from scipy.optimize import linprog
d = np.array([40., 35., 45.])
k = np.array([70., 100., 80.])
f = np.array([150., 260., 170.])
c = np.array([[2., 4., 9.],
[4., 3., 4.],
[9., 7., 2.]])
Aeq = np.zeros((3, 9))
Aub = np.zeros((3, 9))
for i in range(3):
for j in range(3):
Aeq[j, 3*i+j] = 1
Aub[i, 3*i+j] = 1
for state in product([0, 1], repeat=3):
y = np.array(state)
r = linprog(c.ravel(), A_ub=Aub,
b_ub=k*y, A_eq=Aeq, b_eq=d,
bounds=(0, None), method="highs")
if r.success:
print(state, round(r.fun + f@y, 2))
A printed state of (1, 0, 1) means North and South are open. The output for that state is 645.00. The code prints only feasible patterns; retain failed solver statuses in a production audit rather than treating a missing line as an explanation.
Enumeration grows quickly as candidates increase. Ten candidates have 1,024 opening patterns, before any expansion-level choices. For larger models, a mixed-integer solver avoids explicitly solving every possible pattern in this simple way. SciPy milp supports integer variables, bounds and linear constraints, and reports status, an objective bound and a relative gap.

Test the rule against split deliveries
The base plan sends Zone 2 loads from both North and South, but suppose the customer requires one depot to serve the entire zone for the month. This is a different feasible set, so it needs a different model.
Define z(i,j) as a binary assignment. Each zone has exactly one assigned depot. Assignment is allowed only to an open site. A depot's load becomes the sum of the full demands of its assigned zones, which must remain within capacity.
Do not enforce this rule by rounding the base shipments. Moving the five South loads to North would make North's load 75, above its limit of 70. Rounding a decision can break capacity even when total network capacity looks ample.
For North and South, the least-cost valid assignment sends Zone 1 to North and Zones 2 and 3 to South. North handles 40 loads; South handles 35 + 45 = 80. Variable cost is 40 × 2 + 35 × 7 + 45 × 2 = 415 CU.
Adding the same 320 CU fixed cost gives 735 CU per month. All 27 possible zone-to-site assignments were checked with their resulting site costs. This is the best single-source plan for the example, 90 CU above the split-delivery optimum.
That 90 CU is the modeled cost of the service rule under these inputs. It is not a reason to ignore the customer. It gives the commercial team a specific tradeoff to discuss, along with any benefits that the cost model omits. If simpler stock control or returns handling matters, define those effects before claiming the rule is wasteful.
Find the cost threshold that changes the choice
Suppose only Central's fixed cost is under review. Keep all capacities, demand and variable rates unchanged, and let its revised fixed cost be F. North–Central then costs 150 + F + 365 = 515 + F CU per month.
North–South remains at 645 CU. The two options tie when 515 + F = 645, so F = 130 CU per month. At that value, the other feasible patterns remain more expensive. A small difference near this threshold deserves attention because minor data changes could alter the preferred pair.
If Central's fixed cost falls to 50 CU, North–Central costs 565 CU. Central–South costs 575 CU, while North–South still costs 645 CU. North–Central becomes the cheapest choice. This is a clear switch caused by a specific input, not a claim that Central is inherently a poor location.
Use only costs that change with the decision. A charge that remains payable after closure cannot be counted as an immediate saving. Conversely, a one-time transition cost should not disappear from a comparison merely because the basic model uses monthly operating costs. Match the economic horizon and decision before entering either item.
The MOSEK modeling cookbook explains fixed-charge modeling with binary decisions. Its role here is precise: the charge occurs when the site is selected, rather than once for every load. Actual lease and transition assumptions still need evidence from the business.
Price a larger capacity option as a separate choice
If a depot proposal offers two sizes instead of one, model those as distinct options with their own capacity and fixed cost. The choices could be closed, standard or expanded. At most one size can be selected for that physical site, so the model cannot claim both capacities while paying only one charge.
Consider an expanded North depot with capacity of 90 loads per month. Keep base demand and every lane rate unchanged. North can now supply all 40 Zone 1 loads and all 35 Zone 2 loads. South supplies the 45 Zone 3 loads. North uses 75 of its 90 loads of capacity.
The revised variable cost is 40 × 2 + 35 × 4 + 45 × 2 = 310 CU. This saves 15 CU against the original variable cost of 325. Only five loads change origin, and each saves 7 − 4 = 3 CU. The other added capacity has no value in this specific shipment plan.
If expansion adds 20 CU to North's fixed monthly cost, the resulting total is 320 + 20 + 310 = 650 CU. Keep the standard North–South plan at 645 instead. If the added charge is 10 CU, the expanded plan costs 640 CU and becomes preferable. The expansion charge ties the two plans at 15 CU.
This comparison makes spare capacity easier to interpret. Buying 20 extra loads of capacity does not imply that all 20 will generate savings. Demand locations and the alternative routes determine how much useful work that capacity performs. Counting the whole expansion as a benefit would overstate its value.
In a larger model, give each site-size option its actual resource limits. More storage may leave dispatch capacity unchanged. An expansion that increases receiving capacity but not picking capacity cannot be entered as a uniform rise in every limit. Keep the proposed engineering change and the model coefficient connected.
Stress-test demand without promising future capacity
Increase every zone's demand by 10%. Demands become 44, 38.5 and 49.5 loads. North–South remains cheapest. North sends 44 loads to Zone 1 and 26 to Zone 2; South sends the remaining 12.5 Zone 2 loads and all 49.5 Zone 3 loads.
Variable cost becomes 44 × 2 + 26 × 4 + 12.5 × 7 + 49.5 × 2 = 378.5 CU. Add fixed cost of 320 CU to obtain 698.5 CU. North is still full, and South now handles 62 loads, so the remaining network capacity is concentrated at South rather than evenly spread.
At 50% higher demand, the best opening pattern changes. All three depots open, serving their cheapest zones with 60, 52.5 and 67.5 loads. Variable cost is 412.5 CU and fixed cost is 580 CU, giving 992.5 CU. Central–South can also meet demand, but its best total is 1,012.5 CU.
The Gurobi multi-scenario example illustrates changes to demand, fixed costs and site-status bounds. Such comparisons reveal which assumptions drive a network choice. They do not establish how likely a scenario is.
Also separate reoptimization from preparedness. The 50% case assumes that all three sites may be chosen for that case. It does not show that a closed site can open instantly after a demand surge. To test the chosen North–South network, hold those opening decisions fixed and check what that network can actually serve.
Add service restrictions where they belong
Capacity across the network is only one feasibility check. Suppose Zones 1 and 2 can be served only by North because of an approved delivery rule. Their combined demand is 75 loads, above North's 70-load limit. North–South now fails even though its total capacity is 150 against demand of 120.
Represent a prohibited lane by fixing its shipment to zero. Do not leave it available with a large artificial cost and assume the solver will never use it. If there is no other way to satisfy demand, it may choose the expensive lane and produce an operationally invalid plan.
If a lane is available but undesirable, a real incremental cost may be suitable. If it violates a hard service rule, it belongs outside the feasible choices. Those meanings must come from the service agreement or operating policy, not from whichever value makes the optimization run.
ApparelDiary's supplier lead-time guide helps define usable receipt milestones. A location model that uses transit time as an eligibility screen should align that screen with the actual required milestone. Arrival at a gate and stock ready for use may represent different service outcomes.
Read the solver result as a decision record
A report should identify open sites, assigned loads, unused capacities, cost components and the input version. Record the solver status as well. A feasible solution found before a time limit is not automatically a proven optimum.
For a minimization model, a feasible plan gives an upper bound on the minimum cost. A valid solver bound gives a lower bound. If a hypothetical run reports a feasible cost of 650 CU and a lower bound of 630 CU, the unresolved absolute difference is 20 CU.
Using the relative-gap definition in the Gurobi model-attribute reference, that example has a gap of 20 ÷ 650 = 3.08%. It does not mean every shipment is accurate within 3.08%, or that future realized cost has that uncertainty. The gap describes the solver's remaining objective guarantee for the stated model.
In our small case, exhaustive comparison closes that gap: the best plan costs 645 CU and no cheaper opening pattern exists. A larger deployment should preserve both the incumbent plan and its bound. That lets reviewers distinguish an operating proposal from the strength of its optimality evidence.
Common modeling faults and practical corrections
Symptom | Likely modeling issue | Useful correction |
Closed site still ships | Missing opening-capacity link | Check every site's capacity row |
Cheap result uses a banned lane | Rule represented only as a penalty | Fix that lane's flow to zero |
Network has capacity but fails | Capacity is in the wrong eligible locations | Check demand subsets and allowed lanes |
Every site opens | Fixed costs omitted or units mismatched | Reconcile monthly fixed and variable totals |
Rounded plan overloads a depot | Whole-zone assignment added after solving | Model binary assignments directly |
Before changing the mathematics, trace each surprising result back to a data row. A transposed cost matrix can reverse origins and destinations while leaving all numbers plausible. Use named site and zone identifiers when importing data, and reconcile one known lane by hand.
Do not mix service classes without checking resource use. A hanging-garment load may need different space and handling from a carton load. A single equivalent-load measure is defensible only when its conversion factors fit the modeled constraint. Otherwise, separate products or resources so the model cannot trade unlike quantities as if they were identical.
Finally, test the selected plan with the people who must operate it. Review receiving hours, labor coverage, dispatch limits and customer handoffs. These checks can reveal a missing constraint, but they do not justify silently changing the output while still presenting it as the model's optimum.
Frequently asked questions
Is the closest depot always the best choice?
No. Distance may influence transport cost, but fixed cost and capacity can change the decision. The example's Central depot offers the cheapest rate to Zone 2. Keeping it closed still saves money in the base case because the variable savings do not cover its fixed cost.
Can an existing depot be included?
Yes. Its opening variable can remain free if closure is a real option, or be fixed to one if it must stay open. Enter the costs that differ between those choices over the chosen horizon. A historic payment does not become avoidable merely because the optimization labels a site closed.
Does unused capacity prove that the plan is inefficient?
No. South has spare capacity in the cheapest base plan, while North is full. Capacity is tied to a location and its lane costs. Filling South simply to raise utilization could add freight expense without serving any extra demand or reducing fixed cost.
Should the model always include exactly two sites?
Only if that is a genuine requirement. In this example the optimizer chooses two for the base demand and three for the high-demand case. Fixing the count in advance would remove a decision that the cost and capacity data can help resolve.
Conclusion
A useful facility-location result explains both the selected depots and the shipment plan that makes them viable. The North–South example costs 645 CU per month because it balances route savings against fixed charges and capacity. Requiring one source per zone raises that cost to 735 CU; changing Central's fixed charge or demand can change the preferred network.
The practical value lies in making those tradeoffs inspectable. Keep units consistent, distinguish opening from assignment, verify each demand balance and compare realistic alternatives. Then preserve the assumptions behind the chosen network so that a later cost or service change triggers a deliberate review.
Location models share methods with other allocation problems, so see fabric allocation with a transportation model, route to market and decision tree analysis for capacity investment.
References
1. SCIP book: Facility location problems.
2. AMPL: Capacitated Facility Location Problem tutorial.
3. Gurobi: facility.py example.
4. SciPy: linprog documentation.
6. MOSEK Modeling Cookbook: Mixed integer optimization.




Discussion0
Loading the discussion…