Linear Assignment Problem Solvers

0.9.4 · active · verified Wed Apr 15

lapx is a Python library providing efficient linear assignment problem solvers, including both single and batch solvers, based on the Jonker-Volgenant algorithm. It extends and enhances Tomas Kazmar's original `lap` library, offering improved stability, performance, and broader platform support (Windows, Linux, macOS) for Python 3.7+. The library is actively maintained, with the current version being 0.9.4, and receives frequent minor and patch releases.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the `lapjv` function to solve a basic linear assignment problem given a cost matrix. The function returns the optimal total cost and the assignments for rows and columns.

import lap
import numpy as np

# Example cost matrix
cost_matrix = np.array([[1, 2, 3],
                        [3, 1, 2],
                        [2, 3, 1]])

# Solve the linear assignment problem using lapjv
cost, x, y = lap.lapjv(cost_matrix)

print(f"Optimal assignment cost: {cost}")
print(f"Row assignments (x, maps row index to column index): {x}")
print(f"Column assignments (y, maps column index to row index): {y}")

view raw JSON →