An offline robot-tracking analysis may first compute a minimum-cost one-to-one assignment and then discard pairs above a threshold. That sequence does not generally produce the same result as restricting the allowed pairs before solving. A rejected pair may have affected which other pairs were selected in the first place.

An original two-by-two example makes the difference exact. Its costs are invented, dimensionless numbers for a software-model review. They are not calibrated tracking likelihoods, physical distances, or a recommended threshold for any robot.

Separate three questions

The first question is which pairs are permitted. The second is how many permitted pairs the model should try to match. The third is which cost objective selects among alternatives. A single printed list of retained pairs can hide differences in all three.

SciPy's linear_sum_assignment solves a cost-based assignment problem and returns paired row and column indices [1]. Its maximum_bipartite_matching function addresses cardinality over an explicit graph of permitted edges [2]. These provide different checks for the small fixture below; one does not automatically express every application policy of the other.

Let rows represent tentative tracks A and B, and columns represent detections X and Y. A–X costs 1, A–Y costs 6, B–X costs 6, and B–Y costs 10. Each row and each column may participate in at most one selected pair.

import numpy as np

from scipy.optimize import linear_sum_assignment

cost = np.array([[1.0, 6.0],

[6.0, 10.0]])

rows, columns = linear_sum_assignment(cost)

assert columns.tolist() == [0, 1]

assert cost[rows, columns].sum() == 11.0

With all four edges permitted and a complete assignment required, only two alternatives exist. The diagonal A–X plus B–Y costs 11. The crossed A–Y plus B–X costs 12. Thus the diagonal is the unique minimum for that unrestricted model.

Apply the threshold after the solution

Now declare that costs no greater than 6 are acceptable. Filtering the unrestricted result keeps A–X at cost 1 and rejects B–Y at cost 10. The retained output contains one pair. Track B and detection Y are unmatched.

This list passes a check that every retained cost meets the threshold. It also passes a check that no row or column is used twice. Those checks establish properties of the retained list, but they do not prove that no larger acceptable matching exists.

In fact, both crossed edges have cost 6. Selecting A–Y and B–X supplies two permitted pairs without repeating a row or column. The earlier assignment used the forbidden B–Y option when choosing its cheaper diagonal; deleting that option afterward does not reconsider the associated A–X commitment.

Solve the constrained fixture directly

For this local minimization test, replace disallowed costs with positive infinity before calling the dense assignment routine. The allowed complete crossed solution exists, so the constrained call returns it:

allowed = cost <= 6.0

gated_cost = np.where(allowed, cost, np.inf)

gated_rows, gated_columns = linear_sum_assignment(gated_cost)

assert gated_columns.tolist() == [1, 0]

assert cost[gated_rows, gated_columns].sum() == 12.0

The checks were executed with SciPy 1.18.1, NumPy 2.5.2, and Python 3.14.7. Positive infinity here is an explicitly tested representation for this minimization fixture, not a claim that all optimization interfaces or maximizing modes accept the same convention.

The total 12 should not be compared with the retained single-pair total 1 as if they described equivalent output. One covers both rows and columns with permitted edges; the other covers only one of each. Costs become comparable only after stating the relevant coverage and unmatched-item policy.

Check feasible cardinality independently

Construct a sparse adjacency graph from the Boolean allowed matrix. Store ones for permitted edges and leave forbidden edges absent. A maximum-cardinality calculation then confirms that two matches are possible:

from scipy.sparse import csr_array

from scipy.sparse.csgraph import maximum_bipartite_matching

graph = csr_array(allowed.astype(np.int8))

matched_column = maximum_bipartite_matching(

graph, perm_type='column')

assert matched_column.tolist() == [1, 0]

In this two-by-two graph the only complete permitted matching is crossed. In a larger graph, a maximum-cardinality result need not minimize cost among all matchings of that size. Conversely, an arbitrary penalty for leaving items unmatched may express a different tradeoff from maximizing cardinality first.

The sparse representation matters. The graph interface treats stored entries as edges, including explicitly stored zeros [2]. Building the graph above from a dense zero-and-one adjacency array leaves the zeros absent. A custom sparse constructor that stores a zero for a forbidden pair would encode a different graph.

Include a genuinely infeasible complete case

Change the costs to [[1,2],[8,9]] while keeping the threshold at 6. Both permitted edges now belong to row A. Row B has none, so a two-pair matching is impossible even though two acceptable individual edges exist.

In the executed constrained dense call, the solver raises ValueError with an infeasible-cost-matrix message. The graph calculation finds cardinality one. The difference between these outcomes reflects the requested coverage: the complete dense assignment cannot be formed, while a partial matching can still contain one edge.

An application must define what to do with unmatched tracks or detections. That decision is outside the arithmetic shown here. This example does not invent dummy penalties, delete track identities, or treat a software exception as evidence that a physical object disappeared.

Preserve identity in rectangular cases

A separate three-row, two-column cost matrix [[1,8],[8,1],[3,3]] returns row indices [0,1] and column indices [0,1] in the local check. The third row remains unused. The rectangular routine does not promise one returned pair for every original row.

Keep the returned row indices alongside the corresponding columns when mapping back to track identities. Detect unmatched rows by comparing the full original identity set with the returned row set. Do not infer complete coverage from the fact that a solver returned successfully.

For a reproducible association review, save the original costs, permitted-edge rule, coverage objective, unmatched-item policy, and returned identities before postprocessing. The key counterexample is small enough to inspect by hand: unrestricted minimum 11, post-filter cardinality one, permitted complete cost 12 with cardinality two. Those outcomes belong to different models, and their difference should remain visible in the report.

Sources

[1] SciPy, linear_sum_assignment: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linear_sum_assignment.html

[2] SciPy, maximum_bipartite_matching: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.maximum_bipartite_matching.html