Interactive network algorithms chapter

Transportation and Assignment Problems

This page turns the chapter into an interactive model. Edit supplies, demands, and shipping costs; balance the instance; test for a zero-cost shipment by solving a max-flow problem on the zero-cost arcs; and then watch the cost matrix update until an optimal shipment is certified. The final section specializes the same idea to the assignment problem and the Hungarian method.

Motivation

Bananas are stored at warehouses and shipped to grocery stores. Each warehouse has a supply, each store has a demand, and each warehouse–store pair has a per-unit shipping cost.

The transportation problem asks for shipment amounts that meet all store demands, do not ship more than the available supply at any warehouse, and minimize total shipping cost.

Note on the chapter example. The TeX source contains an early table with demand d3=8, but the subsequent feasible shipment, total-demand calculation, and algorithm use d=(3,5,7). This webpage uses d=(3,5,7), the internally consistent value in the rest of the chapter.

Chapter example

SupplyStore 1
d=3
Store 2
d=5
Store 3
d=7
Warehouse 17832
Warehouse 28145
Warehouse 33867

The entries inside the store columns are the costs cij.

Mathematical model

Transportation problem

Input. Warehouses i=1,…,m, stores j=1,…,n, supplies si≥0, demands dj≥0, and costs cij≥0.

Output. Shipment amounts xij≥0 satisfying

j=1n xij ≤ si for each warehouse i,    ∑i=1m xij ≥ dj for each store j.

Goal. Minimize total shipping cost

i=1mj=1n cijxij.

Why demands can be met exactly

When all shipping costs are nonnegative, an optimal solution never needs to ship extra goods to a real store. If a store receives more than its demand, reducing some positive shipment into that store preserves feasibility and weakly decreases cost.

So for the cost-shift argument below, it is enough to focus on feasible solutions where each real store receives exactly its demand.

A feasible but nonoptimal shipment

Store 1Store 2Store 3
Warehouse 1060
Warehouse 2007
Warehouse 3300

This shipment has cost 3·6 + 5·7 + 8·3 = 77. Lowering x12 from 6 to 5 still meets demand at store 2 and lowers the cost by 3.

Cost shifts that preserve optimal solutions

If every cost in one store column j is changed by the same amount Δ, then every potentially optimal feasible solution changes by the same total amount djΔ. The ranking of feasible solutions is unchanged.

To also change whole warehouse rows safely, the input is made balanced. If total supply is larger than total real demand, add a dummy store with demand equal to the excess supply and cost 0 from every warehouse. Shipping to this dummy store means “not shipped to a real store.”

ddummy = ∑isi − ∑jdj.

After balancing, every feasible solution ships all supply somewhere, so changing every cost in warehouse row i by Δ changes every feasible solution by the same total amount siΔ.

Column reductions in the example

Subtract the minimum in each real store column: 1 from column 1, 3 from column 2, and 2 from column 3.

Store 1Store 2Store 3Dummy
Warehouse 17000
Warehouse 20130
Warehouse 37350

The dummy demand is 3 because total supply is 18 and total real demand is 15.

Testing for a zero-cost shipment with max flow

Given a balanced reduced-cost matrix, create a max-flow instance:

  1. Add a source, a node for each warehouse, a node for each store, and a sink.
  2. Add an arc from the source to warehouse i with capacity si.
  3. Add an arc from store j to the sink with capacity dj.
  4. Add an infinite-capacity arc from warehouse i to store j only when the current reduced cost cij is 0.

Transportation algorithm

  1. Balance the input by adding a dummy store if necessary.
  2. Solve the zero-cost max-flow instance.
  3. If the flow value equals total demand, the positive warehouse-to-store flows give an optimal transportation solution.
  4. If not, use the residual reachable set S as a minimum cut. Let SW be warehouses in S and SD be stores in S. Set Δ = min{cij : i∈SW, j∉SD}.
  5. Decrease every row in SW by Δ, increase every column in SD by Δ, and repeat.

Interactive transportation workbench

Edit the instance, initialize the balanced reduced-cost matrix, then step through the repeated max-flow and cost-update phases. The default data is the chapter example.

Input data

Reduced costs and zero-cost flow network

Algorithm state

Shipment / certificate

Step log

Special case: the assignment problem

When there are n workers and n jobs, with si=1 and dj=1 for all i,j, the transportation problem becomes the assignment problem. A shipment of one unit from worker i to job j means assigning that worker to that job.

The max-flow subproblem is now a bipartite matching problem on the zero entries of the cost matrix. A minimum cut becomes a collection of rows and columns that covers every zero. The hand algorithm is the Hungarian method.

Chapter assignment example

8107
10118
567

Rows are workers, columns are jobs. The optimal assignment has cost 22.

Assignment algorithm

  1. Subtract the minimum entry in each row from every entry in that row.
  2. Subtract the minimum entry in each column from every entry in that column.
  3. Look for a zero-cost assignment. Equivalently, find a matching using only zero entries.
  4. If no perfect zero matching exists, cover all zeros with as few rows and columns as possible.
  5. Let Δ be the smallest uncovered entry. Subtract Δ from uncovered entries and add Δ to entries covered twice. Repeat.

Interactive assignment workbench

Edit the worker-job cost matrix and step through row reduction, column reduction, zero matching, zero cover, and matrix update.

Input matrix

Current reduced matrix

Assignment state

Assignment

Step log

What the interactives certify

Feasibility

Shipments satisfy warehouse supplies and store demands. After balancing, every unit of supply is shipped either to a real store or to the dummy store.

Lower bound

The algorithm keeps all reduced costs nonnegative. A zero-cost solution in the reduced matrix therefore has the smallest possible reduced cost.

Original optimality

Every row or column cost shift changes all feasible balanced solutions by the same constant. So an optimum for the final reduced costs is also an optimum for the original costs.

Free Web Hosting