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.
pip install lapxVerified import paths — ran on the pinned version, not inferred.
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.
Always use `import lap` after installing `lapx`.
Ensure only one of `lap` or `lapx` is installed in your environment. `lapx` is recommended for extended features and better performance.
If specific float precision is required for `lapjvs()`, explicitly set the `prefer_float32` parameter (e.g., `lap.lapjvs(..., prefer_float32=False)`).
For batch processing, transition to using the `_batch` variants of the assignment functions for clarity and performance.
Use `import lap` instead of `import lapx` in your Python code.
First, ensure `lapx` is installed: `pip install lapx`. If the error persists, uninstall both `lap` and `lapx` then reinstall only `lapx`: `pip uninstall lap lapx` followed by `pip install lapx`. Ensure you are working in the correct Python environment.
On Windows, install 'Build Tools for Visual Studio' from Microsoft, ensuring C++ build tools are selected. On macOS, install Xcode Command Line Tools: `xcode-select --install`. On Linux, install `build-essential` (e.g., `sudo apt-get install build-essential`). It's also recommended to use a virtual environment and ensure `setuptools` and `wheel` are up-to-date: `pip install --upgrade pip setuptools wheel`.
Install `numpy` using pip: `pip install numpy`. It is good practice to install `numpy` before `lapx` or ensure it's a part of your environment's dependencies.
Try updating `numpy` to its latest stable version: `pip install --upgrade numpy`. If the issue persists, consider installing `lapx` using `pip install lapx --no-binary :all:` to force a source build, which might compile against your specific CPU architecture, assuming you have a C++ compiler set up.