Spreadsheet Optimization for Facility Location and Transportation: Modeling the Lowest-Cost Supply Network

    This article explains how to model a joint facility-location and transportation optimization problem in a spreadsheet using mixed-integer linear programming. Using a three-factory, three-warehouse, three-market example, it covers data standardization, decision variables, the objective function, constraints, feasibility checks, solver setup, optimality verification, and small-scale enumeration. Readers will learn how to build a model that reflects business rules, avoid common modeling errors, and interpret solver results with appropriate validation.

    1. Clarify the Problem: Joint Location and Transportation, Not a Simple Shortest Path

    In supply chain planning, “which route is cheapest” and “how the entire network can operate at the lowest cost” are different questions.

    A standard shortest-path problem usually finds the path between two nodes with the lowest cumulative distance or cost in a given network. In this case, the model must decide not only which warehouse goods pass through, but also which factories and warehouses are activated. Once a facility is opened, it incurs a fixed cost. Demand in different markets also competes for limited production capacity. Therefore, choosing the cheapest route one by one does not necessarily produce the globally lowest cost.

    More precisely, this is a joint facility-location and transportation optimization problem with fixed activation costs. Transportation quantities can be continuous variables, while facility activation states must be binary variables. This makes mixed-integer linear programming a suitable modeling approach.

    The overall solution process should follow this order:

    Business scope confirmation → data preparation → variable definition → objective function → constraints → solver settings → result acceptance.

    The most error-prone part is often not the Solve button, but incomplete incorporation of business rules into the mathematical model.

    2. Standardize Data Units: Make Costs, Capacity, and Demand Directly Calculable

    The case includes three factories, three candidate warehouses, and three markets.

    Factory data:

    Factory location Fixed cost (10k CNY) Capacity (10k units)
    Eastern Europe 7800 22
    Southeast Asia 26571 75
    Latin America 34720 98

    Warehouse fixed costs:

    Warehouse location Fixed cost (10k CNY)
    Eastern Europe 1300
    Southeast Asia 44285
    Latin America 5787

    Market demand:

    • Eastern Europe market: 30 (10k units);
    • Southeast Asia market: 65 (10k units);
    • Latin America market: 98 (10k units).

    Each route consists of “factory—warehouse—market,” so there are:

    3 × 3 × 3 = 27 candidate routes.

    The variable cost of each route includes raw materials, production, transportation, tariffs, and similar expenses. If route cost is expressed as “10k CNY per 10k units” and transportation quantity is expressed as “10k units,” multiplying the two gives “10k CNY,” which can be added directly to facility fixed costs.

    One common confusion must be corrected: “10k CNY per 10k units” cannot be treated directly as a numerical “per-unit cost.” A model may use different units of measure, but the same calculation must remain internally consistent.

    Also confirm that fixed costs and demand belong to the same planning period. For example, do not compare a one-time factory investment directly with single-month logistics costs unless the model explicitly uses total project-cycle cost or converts fixed investment into a cost for the corresponding period.

    3. Define Variables: Separate Transportation Decisions from Facility Activation Decisions

    Let:

    • p denote a factory;
    • j denote a warehouse;
    • m denote a market.

    Define the transportation variable:

    x(p,j,m) ≥ 0

    It represents the quantity shipped from factory p through warehouse j to market m, in 10k units. With three options in each dimension, there are 27 transportation variables.

    Define the factory activation variable:

    y(p) ∈ {0,1}

    Define the warehouse activation variable:

    z(j) ∈ {0,1}

    Here, 1 means the facility is activated, and 0 means it is closed.

    In total, the model requires 33 decision variables: 27 transportation quantities, 3 factory activation states, and 3 warehouse activation states.

    Do not treat every “factory—warehouse” combination as an independent facility and charge factory or warehouse fixed costs separately. The same factory can ship through multiple warehouses, but its fixed cost should be counted only once. Likewise, when the same warehouse serves multiple factories, its activation cost should also be counted only once.

    If the business truly has a fixed fee for activating a specific transportation lane, then an additional lane-activation variable is required. Do not mistake nine rows of factory–warehouse combinations for nine independent location objects merely because the data is arranged that way.

    4. Objective Function: Minimize Total Network Cost

    Let:

    • c(p,j,m) be the unit variable cost of a route;
    • F(p) be the fixed cost of a factory;
    • W(j) be the fixed cost of a warehouse.

    The total cost is:

    min C = ΣpΣjΣm c(p,j,m)x(p,j,m)

    1. + Σp F(p)y(p)
    2. + Σj W(j)z(j)

    The three parts correspond to variable costs related to transportation and production, factory activation costs, and warehouse activation costs.

    In a spreadsheet, the 27 routes can be organized as a 9-row, 3-column matrix: each row represents a factory–warehouse combination, and each column represents a market. The transportation decision matrix should use exactly the same ordering.

    Suppose route costs are in D8:F16, transportation quantities are in D21:F29, factory switches are in D39:F39, and warehouse switches are in D40:F40. The total cost cell can then use:

    1. =SUMPRODUCT(D8:F16,D21:F29)
    2. +G8*D39+G11*E39+G14*F39
    3. +H8*D40+H9*E40+H10*F40

    The formula above applies only when fixed costs are actually stored in those cells. In practice, adjust the references to match the data layout.

    There are three key checkpoints:

    1. The cost matrix and the transportation matrix must have the same dimensions.
    2. The route order in both matrices must correspond exactly.
    3. Fixed costs must be multiplied by the correct facility switches.

    Having the same dimensions is necessary but not sufficient. If the first row of the cost matrix represents “Eastern Europe factory—Eastern Europe warehouse,” but the first row of the transportation matrix represents another combination, the formula may calculate a result, but that result has no business meaning.

    Avoid using entire-row ranges for multiplication instead of explicit data ranges. Otherwise, helper fields, summary values, or even the objective cell itself may be included in the calculation.

    5. Constraint Design: Make Low-Cost Plans Executable in Reality

    5.1 Market demand must be met

    For each market m, set:

    ΣpΣj x(p,j,m) = d(m)

    In the case, the three constraints require total arrivals to equal 30, 65, and 98 (10k units), respectively.

    If the business allows over-supply, the constraint can be changed to “greater than or equal to.” However, when demand represents firm orders, equality usually better matches the business meaning and avoids unnecessary extra shipments.

    If shortages are allowed, do not simply delete the demand constraints. Instead, add shortage variables and include a business-approved shortage penalty cost in the objective function.

    5.2 Factory output must neither exceed capacity nor bypass activation cost

    For each factory p, set:

    ΣjΣm x(p,j,m) ≤ U(p)y(p)

    This is a combined constraint that links capacity limitation with activation.

    When y(p)=0, the right-hand side is 0, and the factory cannot generate any transportation quantity. When y(p)=1, total transportation quantity can reach its capacity at most.

    If the model only sets “transportation quantity does not exceed capacity” without multiplying by the activation variable, the solver may allow a closed factory to continue producing without paying the fixed cost. This is not a solver failure; the model has allowed an unrealistic plan.

    5.3 Closed warehouses cannot handle goods flow

    For each warehouse j, set:

    ΣpΣm x(p,j,m) ≤ M(j)z(j)

    Here, M(j) should be a valid upper bound on the warehouse’s total transportation quantity.

    In this case, total demand is:

    30 + 65 + 98 = 193 (10k units).

    When demand uses equality constraints, all flows are nonnegative, and there are no additional outbound channels, M(j)=193 can be used. If the warehouse has an actual throughput capacity K(j), use:

    ΣpΣm x(p,j,m) ≤ min(K(j),193)z(j)

    Do not arbitrarily use an extremely large number as the upper bound. An excessively large linking coefficient weakens model relaxation quality and may increase numerical difficulty.

    5.4 Nonnegativity and binary conditions must not be omitted

    All transportation variables should satisfy nonnegativity constraints, and the six facility variables must be set as binary.

    Restricting switch variables to between 0 and 1 is not enough. Otherwise, the model may produce a fractional solution such as “open 0.4 warehouses and pay 40% of the fixed cost.” Such a result may be valid for a mathematical relaxation problem, but it cannot be executed directly.

    5.5 Whether flow conservation needs separate constraints depends on variable form

    This case uses complete path variables x(p,j,m). The same variable already represents goods passing through a warehouse and then reaching a market, so warehouse inflow and outflow are naturally consistent in the route definition.

    If the model instead records “factory-to-warehouse” and “warehouse-to-market” quantities separately, warehouse flow conservation must be added:

    Total warehouse inflow = total warehouse outflow.

    When inventory, loss, or cross-period carryover exists, these factors must also be reflected in the conservation relationship.

    6. Perform Feasibility Analysis Before Discussing Location Results

    The case’s total capacity is:

    22 + 75 + 98 = 195 (10k units).

    Total demand is 193 (10k units), so there is a 2 (10k units) margin at the aggregate level. However, this is only a necessary check; it does not alone prove that the complete network is feasible. If some routes are prohibited or warehouse throughput is insufficient, demand may still be impossible to meet.

    The case also leads to an important conclusion: under the conditions that all demand must be met by these three factories, no external purchasing is allowed, and no shortage is allowed, all three factories must be activated.

    Because:

    • Closing the Eastern Europe factory leaves capacity of 173 (10k units);
    • Closing the Southeast Asia factory leaves capacity of 120 (10k units);
    • Closing the Latin America factory leaves capacity of 97 (10k units).

    All three cases are below the 193 (10k units) demand.

    Therefore, the factory activation variables can be fixed to 1 in advance, and total factory fixed cost is:

    7800 + 26571 + 34720 = 69091 (10k CNY).

    This cost is the same across all feasible plans and does not affect the comparison between transportation and warehouse plans, but the final cost report should still list it completely.

    This conclusion shows that although the model includes factory location variables, the given data already locks the factory choice. The real optimization target is the warehouse activation combination and the flow allocation across the 27 routes.

    Because the original material does not provide complete costs for all 27 routes, it is impossible to calculate a unique optimal transportation plan or optimal total cost from it. Only the modeling method, feasibility conclusion, and validation path can be provided; numerical results must not be fabricated.

    7. Practical Solver Steps in a Spreadsheet

    Step 1: Organize the data area and decision area

    It is recommended to divide the worksheet into four blocks:

    • Raw parameter area: route costs, facility costs, capacity, and demand;
    • Decision variable area: transportation quantities and facility switches;
    • Helper summary area: factory shipments, warehouse flows, and market receipts;
    • Validation area: capacity margin, demand difference, and facility-linking difference.

    The variable area can be initialized to 0, but an initial value of 0 does not mean the model is feasible; it is only the starting state for solving.

    Step 2: Build helper summary formulas

    Summarize all routes for each factory, all routes passing through each warehouse, and all transportation quantities in the corresponding column for each market.

    It is advisable to list the route mapping table explicitly rather than relying entirely on row-number memory. Warehouse-related rows are often noncontiguous, making omissions likely during summarization.

    Step 3: Configure the objective and variables

    Set the total cost cell as the minimization objective.

    Add the 27 transportation quantities and the facility switches to be solved to the variable cell range. If capacity analysis has already proven that all three factories must open, the factory switches can be fixed to 1, and only warehouse switches need discrete decisions.

    Step 4: Add constraints one by one

    At minimum, include:

    • Three market demand constraints;
    • Three factory capacity-linking constraints;
    • Three warehouse activation-linking constraints;
    • Nonnegativity constraints for transportation quantities;
    • Binary constraints for facility switches.

    If the business has restrictions such as embargoed routes, maximum service distance, or warehouse throughput limits, these must also be added explicitly.

    Step 5: Choose a solver configuration that supports mixed-integer linear programming

    The cost coefficients in this model are constants, and all constraints are linear relationships. Use a solver configuration capable of handling linear models and integer variables, rather than treating it as a general nonlinear problem.

    Avoid expressing facility activation logic through rounding, conditional jumps, or formulas that dynamically look up prices by variable. Binary variables and linear linking constraints are usually clearer and make results easier to explain.

    8. How to Confirm You Have an Optimal Solution, Not Just a Feasible Plan

    “The solver produced numbers” does not equal “optimality has been proven.”

    After solving, first check the solver status and determine whether it is:

    • Proven optimal;
    • Optimal within the specified tolerance;
    • A feasible solution found but optimality not yet proven;
    • Model infeasible;
    • Time or computational resource limit reached.

    Mixed-integer solvers generally maintain the objective value of the current feasible plan and a theoretical lower bound. For a minimization problem, the gap between the two reflects how much improvement may remain. The exact definition of the gap may vary by solver implementation, so the report should state the definition and tolerance used.

    Result acceptance should include at least:

    1. Whether each market’s receipts meet demand.
    2. Whether each factory’s output does not exceed capacity.
    3. Whether closed facilities have no actual flow.
    4. Whether all switches are valid 0 or 1 values.
    5. Whether total cost can be independently recalculated from the original parameters.
    6. Whether there are extremely small negative values or residual flows caused by calculation tolerances.

    If the interface displays rounded numbers, check the underlying values. Do not judge whether constraints are satisfied solely from the displayed cell results.

    9. Cross-Validate Warehouse Selection with Small-Scale Enumeration

    This case has only three warehouses, so there are 2³ = 8 activation combinations.

    You can fix the warehouse switches one by one and then solve the corresponding continuous transportation problem. Exclude infeasible combinations and compare feasible combinations on:

    Transportation variable cost + warehouse fixed cost + factory fixed cost.

    When at least one warehouse is required to handle transportation and there is no direct shipping path, the combination with all warehouses closed is necessarily infeasible. Whether the remaining combinations are feasible still depends on route restrictions and warehouse capacity.

    This method is not suitable for problems with many facilities, but for three candidate warehouses it is a practical cross-check. It can verify whether the integer model results are consistent and help business users understand why a warehouse with a lower fixed cost may not be selected: its corresponding route costs may be higher, making its total cost less competitive.

    10. From Optimal Results to Executable Decisions

    The final output should not be only a total cost number. It should include:

    • Which warehouses are activated;
    • How much each factory produces;
    • How much is shipped on each route;
    • Which paths supply each market;
    • How much cost is fixed and how much is variable;
    • How much remaining capacity each factory has;
    • The solver status and optimality proof situation.

    Scenario analysis should also be performed on demand, route costs, and facility costs. In this case, the capacity margin is only 2 (10k units), indicating that the aggregate level is very close to full load. If demand rises or a factory experiences an outage, the original model may become infeasible immediately.

    If temporary outsourcing, overtime expansion, or emergency transportation is allowed, set realistic and explainable costs and upper limits for these measures. Do not “fix” infeasibility by arbitrarily inflating capacity.

    A reliable spreadsheet optimization plan is not primarily about quickly obtaining the lowest number. It is about clearly defining cost bases, fully expressing business constraints, and being able to explain and validate the final decision. Only when the model is correct, the data is credible, and the solver status is clear does an optimal solution have practical value.