Match the boxes

In a linear assignment problem, each box on the left is matched to one box on the right. A pair can be matched only along an arc, and each arc has a cost. The goal is a complete matching of least total cost. It is “linear” because each pair’s cost stands alone, unlike the quadratic assignment problem, where the cost of one placement depends on all the others.

lap08 · 8 + 8 boxes, 26 arcs
Cost so far
0
Match every box on the left to one on the right. The best possible cost is 23.
Tap a box on one side and then a box on the other, or drag from one to the other. Dashed arcs show which pairs may be matched; select a box to see what each costs. Matching a pair again unmatches it. Buttons: random, greedy, optimal and clear.

Why the cheapest arc is a trap

Greedy () takes the cheapest arc whose two boxes are both free, and repeats. Here it starts with 3–D at 1, the only arc that cheap, then 2–F at 2 and 1–A at 3. Each of those took the one cheap partner of another box: D was box 4’s, F was box 7’s, and A was box 6’s. Those three boxes are left with arcs costing 8, and greedy finishes at 38, 65% above the optimum.

Optimal () costs 23. It pays a little more on box 3, matching it to C at 2 instead of D at 1, so that box 4 can take D at 2, and it gives up the cheap arcs from boxes 1 and 2 so that boxes 6 and 7 avoid their 8s. Of the 8! = 40,320 ways to pair the boxes, only 40 use arcs alone (the button deals one of them at random), and this is the only one that costs 23.

Easy, unlike its quadratic cousin

Despite the trap, the linear assignment problem is easy. Its linear programming relaxation always has a whole-number optimal solution (Birkhoff, 1946), and the Hungarian method solves an n by n instance in time proportional to n3. Better still, it is a building block for the hard problem: the QPB bound behind the recorded QAP runs solves a linear assignment problem at every Frank–Wolfe step, millions of them in a single run. The linear assignment series on this blog has more.

lap08 is made up for this page: 26 arcs with costs from 1 to 9.