Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lecture 9: Transportation and Transshipment

Open In Colab

This notebook covers the transportation problem and its generalization, the transshipment problem: how to ship goods between sources and destinations, or through intermediate nodes, at minimum cost. Both are LO problems, needing no integrality, and the same shape reappears in many assignment problems. Like every application in this lecture, the problem is introduced in the same steps: a practical motivation, the generic model built up with the four modeling steps, the model for a concrete example, its solution in pulp, and possible extensions.

Learning outcomes

On completion of this notebook, you will be able to:

  • recognize and formulate the transportation problem;

  • use decision variables with multiple indices, such as xijx_{ij}, in a model and in pulp;

  • extend a transportation model to transshipment with flow-conservation constraints.

The Transportation Problem

Practical Motivation

A company stores its product in a few warehouses and delivers it to many customers. Every week, each customer orders a certain amount, each warehouse has a limited stock, and shipping one unit from a warehouse to a customer has a cost that depends on the distance between them. Which warehouse should deliver how much to which customer, so that all orders are delivered at the lowest total transport cost? The same question comes up for factories supplying distribution centers, power plants supplying cities, and, as we will see, for assigning staff to tasks or students to rooms.

Modeling

Problem Definition and Example

A single good is shipped from nn sources to mm destinations. Source ii has a supply of aia_i units, destination jj has a demand of bjb_j units, and shipping one unit over the link i→ji \to j costs cijc_{ij}. The problem is to find the cheapest way to ship the goods such that every demand is met and no supply is exceeded.

As an example, two warehouses W1 and W2 supply three stores S1, S2 and S3, with the following transport costs per unit, supplies and demands:

source \ destinationS1S2S3supply aia_i
W146830
W253425
demand bjb_j201520

For example, shipping 10 units from W1 to S2 costs 10⋅6=6010 \cdot 6 = 60. Here the total supply, 55, equals the total demand, so every warehouse has to be emptied.

Decision Variables

What we have to decide is how much to ship over each link, so we define one decision variable per link:

xij=number of units shipped from source i to destination j,i=1,…,n, j=1,…,m.x_{ij} = \text{number of units shipped from source } i \text{ to destination } j, \quad i = 1, \dots, n,\ j = 1, \dots, m.

A good check for a choice of decision variables is whether their values tell you everything you need: given all xijx_{ij}, we can compute the total cost and check whether the supplies and demands are respected, so these variables suffice.

Objective

The cost of link i→ji \to j is cijxijc_{ij} x_{ij}, so we minimize the total cost

∑i=1n∑j=1mcijxij.\sum_{i=1}^{n} \sum_{j=1}^{m} c_{ij} x_{ij}.

If a link i→ji \to j does not exist, we can still use this formulation by giving that link a very large cost cijc_{ij}, so that the optimizer never uses it (or we simply leave the variable out, as the pulp code below does).

Constraints

The total amount shipped out of source ii cannot exceed its supply:

∑j=1mxij≤ai,i=1,…,n.\sum_{j=1}^{m} x_{ij} \le a_i, \quad i = 1, \dots, n.

We use “≤\le” rather than “==” because a source does not have to ship everything it has. The total amount shipped into destination jj must cover its demand:

∑i=1nxij≥bj,j=1,…,m.\sum_{i=1}^{n} x_{ij} \ge b_j, \quad j = 1, \dots, m.

Here “==” would also be correct, but it is not needed: shipping more than the demand only adds cost (assuming they are >0>0), so a minimizing optimizer never does it. Finally, we cannot ship negative amounts, so xij≥0x_{ij} \ge 0. A feasible solution only exists if the total supply is at least the total demand, ∑iai≥∑jbj\sum_i a_i \ge \sum_j b_j.

Complete LO Model

min⁡∑i=1n∑j=1mcijxijs.t.∑j=1mxij≤ai,i=1,…,n∑i=1nxij≥bj,j=1,…,mxij≥0,i=1,…,n, j=1,…,m.\begin{aligned} \min \quad & \sum_{i=1}^{n} \sum_{j=1}^{m} c_{ij} x_{ij} \\ \text{s.t.} \quad & \sum_{j=1}^{m} x_{ij} \le a_i, \quad i = 1, \dots, n \\ & \sum_{i=1}^{n} x_{ij} \ge b_j, \quad j = 1, \dots, m \\ & x_{ij} \ge 0, \quad i = 1, \dots, n,\ j = 1, \dots, m. \end{aligned}

This is an LO model: we did not require the xijx_{ij} to be integer. That is no loss here: when all supplies and demands are integer, the corner points of the feasible region of a transportation problem are integer, so the LO optimum found with the simplex method ships whole units anyway.

Modeling the Example

Number the warehouses i=1,2i = 1, 2 (W1, W2) and the stores j=1,2,3j = 1, 2, 3 (S1, S2, S3). Filling in the numbers from the table gives

min⁡4x11+6x12+8x13+5x21+3x22+4x23s.t.x11+x12+x13≤30(supply W1)x21+x22+x23≤25(supply W2)x11+x21≥20(demand S1)x12+x22≥15(demand S2)x13+x23≥20(demand S3)xij≥0,i=1,2, j=1,2,3.\begin{aligned} \min \quad & 4x_{11} + 6x_{12} + 8x_{13} + 5x_{21} + 3x_{22} + 4x_{23} \\ \text{s.t.} \quad & x_{11} + x_{12} + x_{13} \le 30 & \text{(supply W1)} \\ & x_{21} + x_{22} + x_{23} \le 25 & \text{(supply W2)} \\ & x_{11} + x_{21} \ge 20 & \text{(demand S1)} \\ & x_{12} + x_{22} \ge 15 & \text{(demand S2)} \\ & x_{13} + x_{23} \ge 20 & \text{(demand S3)} \\ & x_{ij} \ge 0, \quad i = 1, 2,\ j = 1, 2, 3. \end{aligned}

Solving the Example in pulp

We keep the data separate from the model, as in Separating Data from the Model. New here is that the decision variables are indexed by two things, a source and a destination, so we key the dictionary ship by (source, destination) tuples. The keys of cost also define which links exist: a variable is only created for a link that has a cost.

status: Optimal
shipments: {('W1', 'S1'): 20.0, ('W1', 'S2'): 10.0, ('W2', 'S2'): 5.0, ('W2', 'S3'): 20.0}
total cost: 235.0

Each constraint gets a name (supply_W1, demand_S3, ...), which makes the printed model and any solver messages readable. The optimal plan ships whole units, as expected, and uses only four of the six links: W1 serves S1 and part of S2, and W2, which is cheap for S2 and S3, serves the rest.

Extensions

Transshipment

If goods can pass through intermediate nodes on the way from sources to destinations (for example, a cross-dock or a distribution center), we have the transshipment problem. The decision variables are again the amounts xijx_{ij} on the links, now including links into and out of intermediate nodes. For every intermediate node kk we add a flow-conservation constraint: what comes in must go out:

∑ixik=∑jxkj.\sum_{i} x_{ik} = \sum_{j} x_{kj}.

This extends to a full network by stacking several layers of intermediate nodes, and it is the model behind the shortest path and maximum flow problems of Lecture 11.

References

  • Koole, G. (2019). An Introduction to Business Analytics. §6.3 “Example LO Problems” (transportation). Spreadsheet material replaced with pulp.