{"id":6389,"library":"lapx","title":"Linear Assignment Problem Solvers","description":"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.","status":"active","version":"0.9.4","language":"en","source_language":"en","source_url":"https://github.com/rathaROG/lapx","tags":["linear assignment problem","optimization","numerical","solver","jonker-volgenant"],"install":[{"cmd":"pip install lapx","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for array manipulation and numerical operations as cost matrices are typically NumPy arrays.","package":"numpy","optional":false}],"imports":[{"note":"The installed package is `lapx`, but it is imported as `lap` to maintain compatibility with the original `lap` library on which it is based.","wrong":"import lapx","symbol":"lap","correct":"import lap"},{"note":"Primary function for dense linear assignment problems.","symbol":"lapjv","correct":"import lap\nresult = lap.lapjv(...)"},{"note":"Enhanced version of lapjv with specific optimizations.","symbol":"lapjvs","correct":"import lap\nresult = lap.lapjvs(...)"}],"quickstart":{"code":"import lap\nimport numpy as np\n\n# Example cost matrix\ncost_matrix = np.array([[1, 2, 3],\n                        [3, 1, 2],\n                        [2, 3, 1]])\n\n# Solve the linear assignment problem using lapjv\ncost, x, y = lap.lapjv(cost_matrix)\n\nprint(f\"Optimal assignment cost: {cost}\")\nprint(f\"Row assignments (x, maps row index to column index): {x}\")\nprint(f\"Column assignments (y, maps column index to row index): {y}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Always use `import lap` after installing `lapx`.","message":"The package `lapx` should be imported using `import lap`. Attempting to `import lapx` will result in an `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure only one of `lap` or `lapx` is installed in your environment. `lapx` is recommended for extended features and better performance.","message":"Installing both `lap` (original package) and `lapx` simultaneously will lead to conflicts, as both provide the `lap` import. The package installed last will override the other.","severity":"breaking","affected_versions":"All versions"},{"fix":"If specific float precision is required for `lapjvs()`, explicitly set the `prefer_float32` parameter (e.g., `lap.lapjvs(..., prefer_float32=False)`).","message":"Since v0.7.1, the `lapjvs()` function defaults `prefer_float32` to `True`. While this generally improves speed without altering return results, users expecting `float64` precision by default for intermediate calculations (as in older versions) should explicitly set `prefer_float32=False`.","severity":"gotcha","affected_versions":">=0.7.1"},{"fix":"For batch processing, transition to using the `_batch` variants of the assignment functions for clarity and performance.","message":"Starting from v0.8.0, dedicated batch processing functions (e.g., `lapjvx_batch`, `lapjvs_batch`) were introduced. While older single-assignment functions might still process batches in some contexts, using the explicit `_batch` functions is recommended for optimal performance and correct handling of batch inputs.","severity":"gotcha","affected_versions":">=0.8.0"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}