Linear Sum Assignment: One-to-One Pairs and Total Cost
2026-11-19

Linear Sum Assignment: One-to-One Pairs and Total Cost

Linear sum assignment minimizes the total selected matrix cost while enforcing one-to-one pairing. Choosing the smallest value in each row independently can violate the column constraint, and greedily taking the cheapest still-available column can miss the best total. A small invented matrix makes both issues visible without assigning real people or resources.

The objective includes row and column constraints

The SciPy linear_sum_assignment reference describes a cost matrix for pairing two sets. In the square case, each row is assigned exactly one column and each column exactly one row. The objective is the sum of the costs at those selected row-column positions.

Use three fictional rows A, B, C and columns X, Y, Z. Their costs are A: one, two, one hundred; B: one, one hundred, one hundred; and C: one hundred, one, two. Every value is an invented dimensionless score to be minimized, with no market, employment or equipment data represented.

The row minima sum to three, but that is not a feasible assignment. Rows A and B both choose X when considered independently, while C chooses Y. The one-to-one constraint prevents X from being reused. A cheap total that violates the constraints is not an alternative optimum.

OptimalorangeA-Y2,B-X1,C-Z2usesallrowsandcolumnswithtotal5.
The matrix has no real people, prices or equipment resource assignments. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

A greedy row order can create an expensive later choice

Process A first and choose its cheapest column X for cost one. Row B must then choose an unused column, both of which cost one hundred. If it chooses Y, C receives Z for cost two. The total becomes one hundred three.

That procedure made a locally cheapest choice at every step in its stated order, but the early decision blocked B's only inexpensive column. Reordering the rows may happen to improve this particular greedy run, yet it does not provide a general optimality argument for every cost matrix.

The better assignment is A to Y for two, B to X for one and C to Z for two. Its total is five. Giving A its second-cheapest option protects B's much more consequential opportunity. The objective is global total cost, rather than requiring every individual row to receive its own minimum.

GreedyA-X1B-Y100C-Z2totals103whileA-Y2B-X1C-Z2totals5.
Independent enumeration verifies all six feasible permutations; no SciPy library run is claimed. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Enumerating six small possibilities verifies the example

There are six column permutations for three rows. An independent Python check enumerates all six feasible one-to-one assignments and sums their selected costs. The minimum is five at column order Y, X, Z. This verifies the stated toy optimum directly.

The enumeration is a convenient proof for this tiny matrix, not a claim that the SciPy routine enumerates every permutation. The public reference describes a modified Jonker-Volgenant implementation. This article does not replace that algorithm with a factorial-time procedure for larger problems.

The example was checked by independent enumeration rather than by executing SciPy. Keeping the verification method explicit distinguishes the mathematical objective and its toy result from a claim about a library run that did not occur.

The returned index arrays preserve paired positions

The interface returns row and corresponding column index arrays. Their entries must be read together, because each matched pair selects one matrix element. In the square example, sorted row indices zero, one, two correspond to column indices one, zero, two.

Summing matrix values at those paired positions gives five. Sorting the column indices independently would lose the matching and create another set of pairs. The row and column labels must also retain their original matrix identities if the result is displayed in another table.

The original SciPy interface source checks for a two-dimensional numeric matrix, allocates paired index outputs and delegates to the rectangular assignment solver. It translates infeasible or invalid numeric input states into errors. Reading this wrapper does not claim inspection of the delegated solver's internal search.

Rectangular assignment changes which side is fully covered

The documentation also permits rectangular matrices. When there are more rows than columns, not every row can be assigned, and the analogous statement holds for extra columns. A result's cardinality must therefore be interpreted with the matrix shape, rather than assuming every supplied label is always used.

The maximize option changes the objective to a maximum-weight assignment while retaining the pairing structure. That is a separate declared objective, not an instruction to reinterpret the minimum-cost toy result after calculation. The invented example here uses the ordinary minimization setting throughout.

This total-score problem is also distinct from stable matching based on separate preference orders. No blocking-pair condition appears in the objective used here. Preserve the matrix, label order, constraints and objective when reporting an assignment. Related explanations appear in the optimization methods section and the technical article collection.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

粤xxx

咨询 在线留言 电话:18028484626
微信 微信扫码添加我