def lsa_solve_munkres(costs):
    """Solves the LSA problem using the Munkres library."""
    from munkres import Munkres

    m = Munkres()
    # The munkres package may hang if the problem is not feasible.
    # Therefore, add expensive edges instead of using munkres.DISALLOWED.
    finite_costs = add_expensive_edges(costs)
    # Ensure that matrix is square.
    finite_costs = _zero_pad_to_square(finite_costs)
    indices = np.array(m.compute(finite_costs), dtype=int)
    # Exclude extra matches from extension to square matrix.
    indices = indices[(indices[:, 0] < costs.shape[0])
                      & (indices[:, 1] < costs.shape[1])]
    rids, cids = indices[:, 0], indices[:, 1]
    rids, cids = _exclude_missing_edges(costs, rids, cids)
    return rids, cids
Solves the LSA problem using the Munkres library.
motmetrics/lap.py